1 VBO - multiple textures?

Started by
11 comments, last by V-man 12 years, 10 months ago

Im interested in knowing more on how to use this approach

should I add the corresponding "Select" value to my buffer object then? can you give any more guidance on how should I implement this at the code level?

It's actually not really that useful, at least not with the Select being a uniform. If you have to issue multiple draw calls (which you do, for setting the uniform), then you could just as well sort by texture and switch a standard sampler2D uniform. My snippet is much more useful if you have to switch textures per pixel or per-primitive. The Select variable would then be either calculated in the pixel shader or supplied as a varying through vertex attributes. The latter method allows the drawing of a mesh with many different textures using only a single draw call. It doesn't have to be faster though, since although you gain on draw call overhead, you can easily thrash the GPU texture caches, unless you presort the mesh faces per material.
Advertisement
Okay I think Im gonna sort my draw calls by texture and then just render subsets of the vbo

the only problem (I can think of) is that I will lose a way to arrange what goes in front or back of my scene

Any ideas on how to solve this?

[quote name='EvilNando' timestamp='1307402246' post='4820293']
Im interested in knowing more on how to use this approach

should I add the corresponding "Select" value to my buffer object then? can you give any more guidance on how should I implement this at the code level?

It's actually not really that useful, at least not with the Select being a uniform. If you have to issue multiple draw calls (which you do, for setting the uniform), then you could just as well sort by texture and switch a standard sampler2D uniform. My snippet is much more useful if you have to switch textures per pixel or per-primitive. The Select variable would then be either calculated in the pixel shader or supplied as a varying through vertex attributes. The latter method allows the drawing of a mesh with many different textures using only a single draw call. It doesn't have to be faster though, since although you gain on draw call overhead, you can easily thrash the GPU texture caches, unless you presort the mesh faces per material.
[/quote]

can u provide an brief example on how to pass the select variable inside a vertex attribute array?
http://www.opengl.org/wiki/GlVertexAttribPointer
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement