Several Textures applied to 1 Vertex Buffer Object

Hello, I have a fairly simple question.

I’m trying to figure out whether or not I can use several different texture objects on different faces within a vertex buffer object.
I want to make a 3D-Modeling program, and I need to decide the most flexible and best way of creating geometry. So I figured I have two reasonable options:

  1. Pack all of the vertices under one vertex buffer object (along with corresponding indices/normals) to render the whole model.
  2. Use several vertex buffer objects (all triangles) that combine to form the model. (This is not a Triangle Strip)

I do know that it is possible to put all of the desired textures into a texture atlas, and specify texture coordinates accordingly. However, I wanted to know if it was possible to have many texture objects, each applying to different triangles, or being reused.

Thanks in advance, Nick.


you can use multiple textures on one object. For this you have two options:
A) store the texture-unit to use per vertex as an additional user defined attribute and use this to select the texture to sample from in the fragment shader (you will be limited by the total number of textures == #of texture units)
B) render the VBO with multiple draw calls and switch the texture units in between. the same idea as you might had when describing your multiple VBO approach, but you can use one buffer and only draw some parts of it.

If all textures have the same dimensions, you could also use texture arrays.

Please correct me if I’m wrong. Does this mean that I should use an array as an attribute to send to the fragment shader that contains values that describe which texture to use?

The array would have as many elements as there are vertices, each specifying a different active texture to use.

It’s an additional array with one value per vertex, you would have to sent this information from the vertex shader to the fragment shader and bind all possible textures at the same time. That may be a lot of extra data for switching between 16 textures but its possible. (this technique might become more interesting if nearly each triangle has a different texture and you can bind thousands of textures (e.g. bindless textures) but that’s not very relevant right now).
Note: you can’t set the sampler as a vertex attribute, so you will have to make sure you bound the correct samplers!