# OpenGL Always use VAO or no?

## Recommended Posts

melbow    221
I'm sure there has to be a similar thread somewhere, but I can't find it. I was wondering, is there any reason not to use a VAO? And in the latest version of OpenGL, are all other forms of rendering deprecated?

##### Share on other sites
irreversible    2860

Yes, to comply with what's been standard in OpenGL since 3.0 pretty much deprecated the fixed function pipeline, it's good to be always using a VAOs. Furthermore, VAOs have been around in OpenGL forever, so there really is no other excuse to not use them than laziness. The fixed function pipeline is useful for quick-and-dirty mockups and testing, but not really for any kind of serious work.

I personally wrote a fixed-allocation wrapper for objects with up to a few thousand vertices that is filled up in software using emulated fixed function notation and then render it as a VAO. It follows the same notational paradigm as OpenGL, but provides a number of benefits:

1) it's cross-compatible with D3D once you fill in the buffers

2) it's easy for QnD testing

3) it's both forward-compatible and backwards-compatible

4) it's transparent to the application

5) it's object-oriented so it provides functionality encapsulation

6) it's far easier to write debug code for than horrible GL fixed function calls

7) it can do tessellation on the fly (in particular stuff like quad->triangle conversions)

8) state changes and streams are handled internally (eg no texture coord stream is written or enabled if the first vertex doesn't have a texture coordinate - you don't need to worry about any of this when using it)

9) it's easily extensible to support TNB or any other streams you may need using good old fixed function style notation

An example of its use looks like:

drv->Begin(GD_QUADS);
drv->TexCoord(0, 0);
drv->Binormal(bn0);
drv->Vertex(v0);
...
drv->End();

The only drawback is that you have to write it.

For actual time-critical rendering you should always use VBO-s that you keep on the chip at all times. Moreover, once you have your data in a VAO, you can potentially use stuff like transform feedback to cut the CPU out of the loop altogether.

Think of it this way: fixed function is a toy. When you want to play, you get your toys. When you want to get work done, you bring out the tools.

Edited by irreversible

##### Share on other sites
melbow    221
Thanks Irreversible. I know fixed-function is dead (as it should be), but wasn't sure if there was some scenerio where it might be better to call glVertexAttribPointer and not use a vertex array object.

I'm writing a wrapper for GL ES (for educational as well as practical applications) and was considering forcing the usage of VAOs. I guess I will go ahead with my plan then. Thanks again.

##### Share on other sites
Aks9    1499
I'm sure there has to be a similar thread somewhere, but I can't find it. I was wondering, is there any reason not to use a VAO? And in the latest version of OpenGL, are all other forms of rendering deprecated?

In core profile VAO is mandatory. But it can be created, selected and forgotten. It is the way I'm using VAO.

VAO is not always the best way to do things. Try to make several VAOs and select them and compare to changing just one attribute in a single VAO. If you have to change many attributes at once, than just selecting a VAO is better. For a single attribute, or few of them... hm, I wouldn't bet. Also, mixing VAO and NVIDIA bindless is not a good idea.

##### Share on other sites
melbow    221
<blockquote class='ipsBlockquote'data-author="Aks9" data-cid="5022808" data-time="1358498689"><p>
<blockquote class='ipsBlockquote'data-author="melbow" data-cid="5022767" data-time="1358482777"><p>I'm sure there has to be a similar thread somewhere, but I can't find it. I was wondering, is there any reason not to use a VAO? And in the latest version of OpenGL, are all other forms of rendering deprecated?</p></blockquote>
<br />
In core profile VAO is mandatory. But it can be created, selected and forgotten. It is the way I'm using VAO. <span rel='lightbox'><img src='http://public.gamedev.net//public/style_emoticons/default/smile.png' alt='Posted Image' class='bbc_img' /></span><br />
VAO is not always the best way to do things. Try to make several VAOs and select them and compare to changing just one attribute in a single VAO. If you have to change many attributes at once, than just selecting a VAO is better. For a single attribute, or few of them... hm, I wouldn't bet. Also, mixing VAO and NVIDIA bindless is not a good idea.</p></blockquote>

Thank you! That is exactly what I needed to know.

##### Share on other sites
melbow    221
OFF TOPIC: And gamedev.net desperately needs to update the mobile site. It has some very annoying design flaws and bugs...

##### Share on other sites
tanzanite7    1410
OT: The quick reply is broken from where-ever one uses it - not specific to modile site. It has been that way for ages (years?) so, do not hold your breath.

##### Share on other sites
swiftcoder    18432

[quote name='tanzanite7' timestamp='1358520299' post='5022905']
It has been that way for ages (years?)[/quote]

Months, if that. It seems to be a bug in the most recent version of IP.Board.

## Create an account

Register a new account

• ### Similar Content

• Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).

• Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
Skype: Mangodoor408
• By tyhender
Hello, my name is Mark. I'm hobby programmer.
So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine).
And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
Sorry for late replies.
I mostly give more information when people PM me,but this post is REALLY short,even for me =D
So here's few more points:
Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me.

• By Zaphyk
I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?

• I'm trying to get some legacy OpenGL code to run with a shader pipeline,
The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
I've got a version 330 vertex shader to somewhat work:
#version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
Question:
What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?

Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.

• 11
• 14
• 25
• 16
• 19