[LWJGL] Multiple textures on a VBO

Hello all!
Currently, when I want to have multiple textures for a VBO, I made a model compiler which compiles my models vertices (and UV coords) to a texture “atlas” of sorts. However, this causes the texture to be quite large if I want to have say 30 512x512 textures. On machines with low amounts of ram, the computer runs out of space to store this giant texture.

I have tried googling ways to have multiple textures on a VBO, but I only seem to come across texture splatting, which is not what I want to do.

Imagine a cube; I want each face of the cube (2 triangles per face) to have their own texture.

I saw an example which had this code:

[quote]glVertexPointer(3, GL_FLOAT, 64, BUFFER_OFFSET(0));
glNormalPointer(GL_FLOAT, 64, BUFFER_OFFSET(12));
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(24));
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(32));
glClientActiveTexture(GL_TEXTURE2);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(40));
[/quote]
As I am not on my own machine however, I do not know if this method is what I am looking for.

just split up the model.

Single 4096x4096 32-bit texture take only 64Mb memory and you can fit 64 512x512 texture regions there.

Another problem with the texture atlasing method I have been using, is that I can not fully use linear mipmapping; I can only use “GL_NEAREST_MIPMAP_LINEAR”.

The simplest solution by far is to use a 2D texture array. All other solutions will have problems with texture filtering unless you actually use 30 separate textures and 30 draw calls. Just load each texture into their own layer and give each face its own layer index. Mipmap generation and filtering work internally just as if you had an actual array of 2D textures (int[] textureHandles so to speak), so no bleeding over edges due to filtering. Might have to use shaders for that though, but I’m pretty sure it should work without them if you really want to.

I was thinking the same thing, but I haven’t a clue how to actually switch between the textures while drawing the VBO.

Well, you can’t for obvious reasons. Maybe look into glBufferSubData? I’ve never actually used it, but after browsing the internet for a while, that’s probably my best guess.

Also, why not use vertex array objects? They are more suited towards models because they are sent to the CPU, whereas vertex buffer objects need to pass through the bus to get to the GPU first. Therefore, constantly updated models that require lots of changing vertices would do better with array objects.

I hope I was correct about all that, I actually sounded smart for once :wink:

The vertices are never changing :wink:
It’s for the game map. It gets sent once at the beginning of the game, and doesn’t change at all throughout it.

Ah, never mind, don’t mind me :wink:

It’ll read the layer specified by the 3rd texture coordinate dimension. I believe you could do this with the fixed functionality pipeline if you use 3D texture coordinates where the first two work just as usual and the third is an (unnormalized) layer index. (0.5, 0.5, 3) would be mapped to the center of layer 3 (zero-indexed, so 0, 1, 2, 3 = the fourth layer so to speak). In other words, just add which layer to read from in your VBO’s texture coordinates for each vertex.

EDIT: To bitch a bit about your wording (sorry =P): You don’t “draw” a VBO. A VBO is just a memory buffer that contains arbitrary vertex data. The VBO is simply read based on your vertex attribute setup (gl****Pointer() calls) to construct vertices.

@opiop65 don’t mix up vertex arrays and vertex array objects they are totally different things. VAOs are OpenGL objects like(texture, buffer …) which safe the state of the used VBO. They are a OpenGL 3 feature, read it up if you like.

To be honest, at this point, I think it would just be easier to change my model importer so that it creates a new VBO for each texture.

@Danny02 Oh I know the difference, its just I forgot to say buffer after vertex array that first time.