giawa / opengl4csharp

OpenGL 4 Bindings (partially based on OpenTK) for C#
Other
234 stars 61 forks source link

Added readonly OffsetInBytes and ElementType variables to GenericVAO #31

Closed TheRealNOIG closed 4 years ago

TheRealNOIG commented 4 years ago

Ran into "System.TypeAccessException" error when creating costume VAO's

giawa commented 4 years ago

Same thing here, is this a good candidate for either a public or protected property instead of an exposed field?

TheRealNOIG commented 4 years ago

I don't remember what I was using this for but looking at the changes I think setting offset to private should be fine because there is already a exposed variable Offset. Than we can set offsetInBytes to readonly. As for allowIntAsElementType I don't remember but looking through the comments my guess is that the child class would need to read and write access. Let me know if these changes sound good to you.

giawa commented 4 years ago

It doesn't look like you ever edited allowIntAsElementType, at least not in the commits for this PR. Is that modification really needed? I think it might even be worth pulling all that code out in a future commit/PR since it really shouldn't be supported (even if it works in practice). offsetInBytes as read-only sounds fine to me.

TheRealNOIG commented 4 years ago

Ok I did a real fast search over one of my projects that I think was the reason this PR was made.

foreach (KeyValuePair<GenericVAO, List<ModelEntity>> item in entityDictionary)
{
    GenericVAO model = item.Key;
    PrepareModel(model);
    foreach (Entity entity in item.Value)
    {
        shader.LoadTransformationMatrix(Maths.CreateTransformationMatrix(entity));
        Gl.DrawElements(model.DrawMode, model.VertexCount, model.elementType, model.offsetInBytes);
    }
    UnBindModel();
}

Because of this, it looks like it should be fine to set offsetInBytes and elementType to readonly