Closed TheAIBot closed 5 years ago
Alright i believe all the issues have been addressed. I believe the high level wrapppers(VBO and VAO) should throw exceptions with descriptive messages. It's not like it's performance intensive to do so and the only effective change is a happier user. In the future i may try to add additional exceptions in cases where it's cheap to check simply to make it more user friendly. Littering the code wit hexception checks is probably a bad idea but i don't see a downside to adding more descriptive exceptions where an exception would've been thrown anyway.
I think it might be possible to replace GetStructSize
with a call to System.Runtime.InteropServices.Marshal.SizeOf<T>() / 4
. I tried it out with a few different types and it seems to return the right results. That would have the added benefit of not requiring us to come up with a list of supported types ahead of time. What do you think?
That would work for the currently supported types but it won't work for byte and short. I would like to add support for those types in the future. I think we are both getting away from what size is really meant to represent. The Size property is mainly used to provide glVertexAttribPointer with its size argument. This is the documentation for the size argument that glVertexAttribPointer uses.
"Specifies the number of components per generic vertex attribute."
So yeah it works right now but only because dividing by four gives the correct result. That will not be the case for byte and short. I will change my comments describing the StructSize dictionary and the function GetStructSize to be more in line with the correct definition of size. Then adding support for byte and short should be easier. How about it?
Ah fair enough, I didn't think of support for smaller types, but that makes sense. It might be worth doing some thinking on whether it is possible to use some sort of approach to build up the correct size based on T alone, allowing the library to support types that we haven't thought of yet. However, that can be for another issue/pr in the future.
Alright i changed the documentation and the name of GetStructSize so it correctly refers to size as the respective number of components per generic vertex attribute
Added divisor as a default argument to all
VBO
constructors except the one which only takes an array of data. ModifiesGenericVBO
to include a divisor so i could pass the divisor from theVBO
to theGenericVBO
. Added a method calledDrawInstanced
which takes an int which indicates how many instances it should draw. Just like with the methodDraw
,DrawInstanced
has a method for both OGL3 and OGL2. It chooses the correct one in theInit
method, just likeDraw
does.I stumbled upon an interesting issue. Apparently the necessary draw call glDrawElementsInstanced was first supported in OGL3.1. Unfortunately
Gl.Version()
only returns the major version and not also the minor version, so for now it's not possible to differentiate between version 3.0 and 3.1. Due to this, it's possible that the code won't throw an error if the methods isn't supported. Currently the code throws an error if you try to callDrawInstanced
while using OGL2 but i would prefer if it happened if the user was using a version lower than 3.1. It's probably not trivial to change the behavior ofGl.Version()
as code may depend on it functioning in this way. Maybe another function should be added that returns both the major and minor OGL version.