JTalton's picture

VertexArrayUtility

I have been working on my base library for Vertex Arrays. I am planning on putting it out for people to use. It is very dynamic and works well. I am at the point where I am looking at the feature set that OpenGL provides and trying to determine what else it should support. The main question is about glMultiDrawElements and glMultiDrawArrays. Has anyone tried these out with OpenTK? I can see their use in certain settings. I am worried about the pinning of the memory and how to specify the arrays that go into this call. Any thoughts would be welcome.

Example of the VertexArrayUtility:

    VertexArray vertexArray;
 
    public override void OnLoad(EventArgs e)
    {
        vertexArray = new VertexArray(BeginMode.Triangles);
 
        vertexArray.Vertices = new VertexBuffer();
        vertexArray.Vertices.Add(new Vector3(-1, -1, 0));
        vertexArray.Vertices.Add(new Vector3(1, -1, 0));
        vertexArray.Vertices.Add(new Vector3(1, 1, 0));
        vertexArray.Vertices.Add(new Vector3(-1, 1, 0));
 
        vertexArray.Colors = new ColorBuffer();
        vertexArray.Colors.Add(((uint)255 << 24) | ((uint)255 << 16) | ((uint)255 << 8) | (uint)255); // WHITE
        vertexArray.Colors.Add(((uint)255 << 24) | ((uint)0 << 16) | ((uint)0 << 8) | (uint)255); // RED
        vertexArray.Colors.Add(((uint)255 << 24) | ((uint)0 << 16) | ((uint)255 << 8) | (uint)0); // GREEN
        vertexArray.Colors.Add(((uint)255 << 24) | ((uint)255 << 16) | ((uint)0 << 8) | (uint)0); // BLUE
 
        vertexArray.Elements = new ElementBuffer();
        vertexArray.Elements.Add(0);
        vertexArray.Elements.Add(1);
        vertexArray.Elements.Add(2);
        vertexArray.Elements.Add(2);
        vertexArray.Elements.Add(0);
        vertexArray.Elements.Add(3);
    }
 
    public override void OnRenderFrame(RenderFrameEventArgs e)
    {
        GL.Clear(ClearBufferMask.ColorBufferBit);
        vertexArray.Render(); // Updates any buffers and then renders
        SwapBuffers();
    }

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JTalton's picture

@Fiddler - Thanks for the info on BlittableValueType. I'll have to add checks for that.

VertexArrayUtility is the first of the Utility classes I have been working on. I have some others that I am polishing.

VertexArrayUtility is for using buffers that are not interleaved. I found this useful since I could modify one buffer and not the others. It seems that many developers are using interleaved buffers. What are the thoughts on this?

JTalton's picture

I read up on VertexAttributes and now know more than I did.

So for OpenGL 2.0 or greater:
Instead of using glVertexPointer, glTexCoordPointer, glNormalPointer, etc...
You could use glVertexAttribPointer and then use glBindAttribLocation to bind to variables in a GLSL program.

This allows you to pass in what ever data you want, not limited to just the glXXXXPointer functions available.
So beyond removing the fixed function functionality, this removes the boundaries on the fixed data functionality allowing you to send whatever data you want to a GLSL program.

Example: You could send two more more sets of Vertices to a GLSL program and using a Uniform variable specify the amount to blend from one set of vertices to the other.

That is something I missed that last time I took a look at this. I will have to update my code. :)