tags:

views:

100

answers:

3

My game renders lots of cubes which randomly have 1 of 12 textures. I already Z order the geometry so therefore I cant just render all the cubes with texture1 then 2 then 3 etc... because that would defeat z ordering. I already keep track of the previous texture and in they are == then I do not call glbindtexture, but its still way too many calls to this. What else can I do?

Thanks

+1  A: 

You can pack your textures into one texture and offset the texture coordinates accordingly

glMatrixMode(GL_TEXTURE) will also allow you to perform transformations on the texture space (to avoid changing all the texture coords)

wybiral
Yea I thought of that except, that means either lots of vbos = lots of ram, or giving 48 floats for each object, kinda defeats the purpose...
Milo
Would it be better to value texture order over Z order? How do major game engines do it?
Milo
For cubes, could you use display lists, one for each of the 12 cube styles? Unless you're changing the individual vertices on the cubes...
wybiral
Why "lots of VBOs" ? only 12 cubes...
Calvin1602
"Would it be better to value texture order over Z order?" -> This is a hard problem, and you see only 2 variables (z and tex), but they are plenty more : shaders combinations, uniforms, optimisations on the geometry itself...
Calvin1602
+1  A: 

Ultimate and fastest way would be to have an array of textures (normal ones or cubemaps). Then dynamically fetch the texture slice according to an id stored in each cube instance data/ or cube face data (if you want a different texture on a per cube face basis) using GLSL built-in gl_InstanceID or gl_PrimitiveID.

With this implementation you would bind your texture array just once.

This would of course required used of gpu_shader4 and texture_array extensions:

I have used this mechanism (using D3D10, but principle applies too) and it worked very well.

I had to map on sprites (3D points of a constant screen size of 9x9 or 15x15 pixels IIRC) differents textures indicating each a different meaning for the user.

Edit:

If you don't feel comfy with all shader stuff, I would simply sort cubes by textures, and don't Z order the geometry. Then measure performances gains.

Also I would try to add a pre-Z pass where you render all your cubes in Z buffer only, then render normal scene, and see if it speed up things (if fragments bound, it could help).

Stringer Bell
I upvote because it's ultimately the way to go, but I don't think it's adapted to OP's requirements (no shaders...)
Calvin1602
A: 

Also from NVIDIA: Bindless Graphics

Oskar N.
This is way too hardware specific, NV G80 and up
Milo