How do you create a VAO object in JOGL (java) to use with shaders

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How do you create a VAO object in JOGL (java) to use with shaders

ElvJOGL
Hi,

since I am using a textbook that is written in C and/or C++, I cannot visualize how the create this lines:

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

So where does the vao come from.

I found an Example online showing how to create the VAO in JOGL: http://stackoverflow.com/questions/17450373/jogl-simple-example-with-shaders-vao-and-index-array

But my question is, in JOGL, is VAOs as in the example shader program in the link above, is always dimension 1

like so: private int[] VAOs = new int[1];

So is there different representation of VAOs depending on the type of shader that will use it?

Can someone elaborate on this please?
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

elect
In jogl, you usually have two possibilities:

- use int/float/long arrays
- use int/float/double buffers

You can see it <a href="http:// http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GL2ES3.html#glGenVertexArrays(int,%20int[],%20int)">here

where for the C function

glGenVertexArrays(1, &vao);

you have

void glGenVertexArrays(int n, IntBuffer arrays)

or

void glGenVertexArrays(int n, int[] arrays, int arrays_offset)

I'd suggest you to always go with the arrays, they are faster and easier to manipulate

the sample you saw

private int[] VAOs = new int[1];

it's a simple sample allocating an int array with just one dimension for tutorial purpouses, nothing else

you should, instead, allocating an int as big as all your objects, like here and then you manage it via final variables

In this way you decrease the possibility to have errors regarding binding illegal objects, since you when you use them, you can't confuse one with another, because it is clear by its name what you are using, like here

        gl4.glGenVertexArrays(1, objects, Semantic.Object.VAO);
        gl4.glBindVertexArray(objects[Semantic.Object.VAO]);

Where you generate one VAO and you bind it

In general, when you have a complex program, every mesh having geometry should have an array like this
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

ElvJOGL
Thank you, that is so much clearer now.

and very interesting.
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

gouessej
Administrator
In reply to this post by elect
elect wrote
I'd suggest you to always go with the arrays, they are faster and easier to manipulate
Rather always use direct NIO buffers because JOGL is forced to create them under the hood when you pass arrays or indirected NIO buffers and using NIO buffers isn't very difficult. Java arrays aren't faster than NIO buffers but the creation of a direct NIO buffer takes much time than the creation of an array. The methods accepting arrays are there only for compatibility, it's just some syntactic sugar.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

elect
gouessej wrote
Rather always use direct NIO buffers because JOGL is forced to create them under the hood when you pass arrays or indirected NIO buffers
I didn't know that..

gouessej wrote
 and using NIO buffers isn't very difficult.
Well, I had a lot of trouble with positions, view buffer and so on.. I am gonna write a wiki about it
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

elect
In reply to this post by gouessej
This includes also all the glGet*, right?
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

gouessej
Administrator
Yes but take care of reusing direct NIO buffers as much as possible.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

elect
gouessej wrote
Yes but take care of reusing direct NIO buffers as much as possible.
What about this?
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

gouessej
Administrator
GlueGen has evolved a lot in ten years. What Kenneth wrote was right in 2006.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How do you create a VAO object in JOGL (java) to use with shaders

elect
Ok, thanks