Login  Register

Re: VAO and VBO creation

Posted by Xerxes Rånby on May 29, 2015; 10:38am
URL: https://forum.jogamp.org/VAO-and-VBO-creation-tp4034542p4034543.html

PedDavid wrote
 lwjgl uses static methods to create/bind/changeAtributes etc... VAOs and VBOs and JOGL uses instance methods that need to be refered from a context, so instead of calling the "GL'X'"."method()" (If I wanted to do this in a separate class like this guy) I would need a contructor that would be called in the "public void init(GLAutoDrawable drawable)" and would pass drawable so these class would have a field "GL2 gl = drawable.getGL().getGL2();" right? And after this I would call gl."methods"?.
Yes, this is a very common question with a simple answer; "OpenGL's implementation is not static".
Q: Why does JOGL use Instances of GLContext / GL* instead of exposing a Static API?
A: http://forum.jogamp.org/Why-does-JOGL-use-Instances-of-GLContext-GL-instead-of-exposing-a-Static-API-td4034144.html

PedDavid wrote
The next question is about this method:

    private int createVAO() {
        int vaoID = GL30.glGenVertexArrays();
        vaos.add(vaoID);
        GL30.glBindVertexArray(vaoID);
        return vaoID;
    }


So, i try to call gl.glGenVertexArrays()... It needs two parameters (or three), a size (of what?), a buffer(which buffer?) or an array plus offset(which array and offset?) and it doesn't return a int so I can't reference it later
OpenGL have defined glGenVertexArrays as a void function.
void glGenVertexArrays(GLsizei n,  GLuint *arrays);
n Specifies the number of vertex array object names to generate.
arrays Specifies an array in which the generated vertex array object names are stored.        
https://www.opengl.org/sdk/docs/man3/xhtml/glGenVertexArrays.xml

LWJGL uses syntactic sugar to create a simplified API but this simplification makes it impossible for the users to generate more than 1 array in one call despite that the name is glGenVertexArrays.
OpenGL glGenVertexArrays is designed to allows multiple GPU arrays creation, the function returns multiple ints, one int for each VAO id.

JOGL exposes this function to JVM users without limiting the functionality.
Java do not support passing a * pointer like in C instead Java has to pass an array [] + an integer offset, or passing an IntBuffer object, in order to give the user the same functionality as passing a * pointer in C.
http://jogamp.org/deployment/jogamp-current/javadoc/jogl/javadoc/com/jogamp/opengl/GL2ES3.html#glGenVertexArrays%28int,%20java.nio.IntBuffer%29

PedDavid wrote
Same with VBOs:
...
int vboID = GL15.glGenBuffers();
Yes same with VBO, see the answer to VAO above.

PedDavid wrote
Edit: Wait! Don't tell me those parameters are filled "as I wish" to give "specific references" instead of "generating random ones and saving them" in lwjgl

I mean: gl.glGenVertexArrays("put here the int I was asking for",  my "array" of VAO's? )
No you have misunderstood the glGenVertexArrays arguments;
the int you pass is the number of VAO you want to generate,
the passed array will be filled with the returned VAO int id's, just like in OpenGL!