1
votes

Is there a way in OpenGL to render a vertex buffer using multiple independent textures in VRAM without manually binding them (i.e. returning control to the CPU) in between?

Edit: So I'm currently rendering objects with multiple textures by rendering with a single texture, binding a new texture, and repeating, until everything is done. This is slow and requires returning control to CPU and making syscalls for every texture. Is there a way to avoid this switching, and make multiple textures available to the shaders to choose based on vertex data?

1
Can you clarify the question? What exactly are you trying to do here? You cann have multiple textures bound for a single draw call. You might also want to use a texture atlas or array to reduce the need for switching textures. And finally, on modern GPUs, there are also bindless textures. Hard to tell what of this (if at all) you might want.derhass
Done, thanks. Texture atlas is definitely an option, but it seems, well, sketchy.. Ultimately, if all my textures are in VRAM independently, why can't I use them independently? My understanding of texture arrays is that all the textures need to be the same size, which, again, sort of violates the independence between the textures. Bindless textures sound like the best option so far; I might have to start getting nonstandard =(.bfops
derhass isn't talking about texture arrays. He's referring to glActiveTexture. Bind several textures at once to different units. No need for there to be any correlation between them, size or otherwise.Tommy
oops, my mistake. How can I refer to multiple active textures from within a shader? As far as I've found, switching active textures is the same as switching bound textures, no?bfops
*same in that I still have to return control to the CPU and make syscalls in order to refer to a different texture.bfops

1 Answers

1
votes

As mentioned in the comments on the question, glActiveTexture is the key - samplers in GLSL bind to texture units (e.g. GL_TEXTURE0), not specific texture targets (e.g. GL_TEXTURE2D), so you can bind a GL_TEXTURE2D texture under glActiveTexture(GL_TEXTURE0), another under glActiveTexture(GL_TEXTURE1), and then bind your GLSL sampler2D values to be 0, 1, etc. (NB: do not make your sampler2D values GL_TEXTURE0, GL_TEXTURE1, etc. - they are offsets from GL_TEXTURE0).