Reputation: 193
I'm working with OpenGL and in my program, drawing various geometric shapes (squares, triangles, etc.) each object with different textures.
I tested perform rendering with VBO and shaders and this worked well creating a VBO per object. The problem occurs when a large amount of objects (between 150 and 200) ... this means very many calls to function glDrawElements()
:
glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
I found that the best way is to create a single VBO which contains all vertices to draw (vertices, texture coordinates, indices, etc.).
The problem with this is that I can not use a different texture for each of the objects as the VBO draw all geometry once.
The question is .. what is the best way (most optimal) to perform what I need? without using functions or methods that were already deprecated as glBegin ()
/ glEnd ()
or glDrawArrays ()
(I'm working with open GL 3.0 and higher).
PD: I use OpenGL with C++.
Upvotes: 3
Views: 3415
Reputation: 1211
If you want to render a VBO first with one texture then with another:
If you want to draw part of a VBO with one texture and part of it with another texture you have a couple options:
Upvotes: 4
Reputation: 51845
use tiled textures
meaning in one texture image You have textures for more objects. Sometimes it is also called Texture atlas. So change texture coordinates accordingly.
If you use 4x4 textures in single image you can have 16 different objects in single VBO. Of course you are limited by max size of texture image and texture quality you wanna to use.
3D textures and Texture arrays
as gfx HW progresses now also 3D textures and texture arrays are available so you can have one slice of texture per object now ... without the need to switch between textures ...
Upvotes: 2