Advanced OpenGL Vertex Buffer Object

Hi,

has anyone tried using VAOs in Processing?

I'm attempting to add a VAO to the Advanced OpenGL example from the Wiki, but I can't work out how to set it up.

My plan is to create and populate the VBOs and bind them to a VAO in setup(), then I just need to bind and draw the VAO in draw(), rather than having to bind the 3 VBOs individually before drawing. That's the plan, anyway.

So far, I've changed 'gl' to be an instance of the 'GL3', rather than 'GL2ES2' JOGL objects, as I think VAOs aren't part of the GL2ES2 spec.

I've changed gl = pgl.gl.getGL2ES2(); to gl = pgl.gl.getGL3(); to match.

I've also generated an extra IntBuffer in setup()

gl.glGenBuffers(4, intBuffer); vaoId = intBuffer.get(0); posVboId = intBuffer.get(1); colorVboId = intBuffer.get(2); indexVboId = intBuffer.get(3);

as according to the the jogamp docs for GL3, the glGenVertexArrays() function requires an IntBuffer as its 2nd argument.

What I can't work out is what should be in the IntBuffer that's passed in, and how to get the data into it.

Apologies if this is a stupid question. I have a basic concept of what VAOs are for, but have never tried implementing them before.

Any tips or pointers gratefully accepted.

a|x

Answers

  • edited June 2017

    @toneburst IntBuffer vao = GLBuffers.newDirectIntBuffer(1); gl3.glGenVertexArrays(1, vao); gl3.glBindVertexArray(vao.get(0));

    https://github.com/tolkanabroski/pshader-processing/blob/master/basics/iknowopengl.pde

  • Hi @nabr sorry for the late reply. I'll try that, thanks very much, once again!

    a|x

  • Unless I'm missing something, he doesn't seem to be using the VAO he created, in the draw method.

    Maybe I'm wrong, though...

    a|x

  • edited June 2017

    @toneburst yes. becourse the example use drawelements https://www.google.de/search?q=gldrawelements+vs+gldrawarrays
    you have to figure out, what works best in your project.

    glDrawArrays(enum mode, int first, sizei count)
    glDrawElements(enum mode, sizei count, enum type, const void *indices)
    glDrawRangeElements(enum mode, uint start, uint end, sizei count, enum type, const void *indices)
    glDrawArraysInstanced(enum mode, int first, sizei count, sizei primcount)
    glDrawElementsInstanced(enum mode, sizei count, enum type, const void *indices, sizei primcount)
    glDrawElementsBaseVertex(enum mode, sizei count, enum type, const void *indices, int basevertex)
    glDrawRangeElementsBaseVertex(enum mode, uint start, uint end, sizei count, enum type, ...
    glDrawArraysInstancedBaseInstance(enum mode, int first, sizei count, sizei primcount, uint baseinstance)
    glDrawArraysIndirect(enum mode, const void *indirect) // GL_DRAW_INDIRECT_BUFFER
    glDrawElementsInstancedBaseVertex(enum mode, sizei count, enum type, const void *indices, ...
    glDrawElementsInstancedBaseInstance(enum mode, sizei count, enum type, const void *indices, ...
    glDrawElementsInstancedBaseVertexBaseInstance(enum mode, sizei count, enum type, ...
    glDrawElementsIndirect(enum mode, enum type, const void *indirect) // GL_DRAW_INDIRECT_BUFFER
    glDrawTransformFeedback(enum mode, uint id)
    glDrawTransformFeedbackStream(enum mode, uint id, uint stream)
    glDrawTransformFeedbackInstanced(enum mode, uint id, sizei primcount)
    glDrawTransformFeedbackStreamInstanced(enum mode, uint id, uint stream, sizei primcount)

  • Ah, I see. Thanks @nabr.

    a|x

Sign In or Register to comment.