PDA

View Full Version : vertexarray object, performance



john_connor
07-26-2016, 01:49 PM
hi, i'm asking myself how many different vertex array objects i should use to accomplish my (current) goal to create a renderer for a simple 3D game / scene

currently i can only render models, therefore i use 2 buffers and 1 vertex array:
1 instance buffer for instanced rendering infos (model transformation matrix + integer as "object identifier")
1 vertex buffer with ALL models vertices / texcoords / normals in it

so the only verex array i have is for models, and streams to the shader:
// per vertex
in vec3 position
in vec2 texcoords
in vec3 normal
in int material
// per instance
in mat4 modelmatrix
in int objectID

i'm rendering all models deferred, the first pass to populate a "G-buffer" (textures), the second pass i render a [-1;+1]x[-1;+1] screen sized rectangle (to cover all pixels) and do some lighting calculations, or discarting if (pixelmaterial == -1)

now i want to implement simple (dynamic) 2D text rendering, in previous days i did that using a font texture (16 x 16 for all chars possible) and 1 extra vertex array:


struct TextVertex {
vec2 position;
vec2 texcoords;
};

each frame i created the vertices for the textured rectangles representing a char in a string which i wanted to render at a certain position
the width / height for each char i read from a separate file (once at initialization)
as described here: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-11-2d-text/

i could simply "fit" this type of textvertex in the current vertexarray for models, but is this a good idea ??
the models vertices are all in one GL_STATIC_DRAW buffer, for the text vertices i have to use a GL_DYNAMIC_DRAW buffer
should i just use another vertex array ? if not, i would only have to call glBindVertexArray(VAO);only once at initialization
but wit more different VAOs, that not true anymore ...
if i should use only 1 VAO: should i disable each frame the unused attrib arrays for the text rendering program (and re-enable them when rendering models) ??
(in other words: are those kind of VAO state changes expensive ?)

thanks for your advice(s)!

Harvey_Birdman
07-27-2016, 01:48 PM
I have a graphic (a bar graph) from NVidia that shows relative costs of state changes, but I can't find it at their site at the moment. It compares generic types of changes, but doesn't put numeric figures on all types - you have to sort of extrapolate from the given data. And it's a rough indication, at best. Still, it's useful, so I'll do a rough job of transcribing the data:

In order of ascending cost:

Uniform Updates ~ approx. 10M/sec (actual data point on graph)
Vertex Bindings ~ 7M/sec (extrapolating...)
UBO Bindings ~ 4M/sec
Vertex Format ~ 2M/sec
Texture Bindings ~ 1.5M/sec (actual data point)
ROP ~ let's say 1M/sec (extrapolating)
Program ~ 300K/sec (data point)
Render Target ~ 60K/sec (data point)

So, I'd say based on this and my limited experience, that switching VAO's is relatively inexpensive. Others will probably contest that, but that's my take on it.

Harvey_Birdman
07-31-2016, 10:13 PM
... and you're welcome.

Grognard
07-31-2016, 11:39 PM
http://i.stack.imgur.com/JgrSc.jpg

Here is that image.

I would make a quad VAO for your text. It is just too much insanity to try and go crazy keeping from making a new one ever.

Looking at the graph, since you probably have to change your shader program several times then who really cares about changing your VAO?

You can always add in such an optimization later when you are sure all the functionality works properly.