Binding a single TEXTURE_2D_ARRAY layer to a sampler2D

With glFramebufferTextureLayer you can attach a single layer of a texture array to a framebuffer. In the same way I’d like to be able to bind a single layer to a sampler2D in a shader. This would allow existing shaders to function with either TEXTURE_2D or TEXTURE_2D_ARRAY as input, just the same way as a shader may now render to a framebuffer with either attached for output. I guess you could supply both sampler2D and sampler2DArray, use a branch to select and pass in the layer index as an alternative, but this just wouldn’t be clean.

I haven’t come across anything in the API that looks like it’d provide this binding. Am I right in assuming it doesn’t exist? Would it make sense to include the feature in OpenGL?

Take a look at glTextureView.

Just what I’m after. Thanks!

I guess I’ll have to experiment with creating many texture handles for each layer or call glTextureView many times.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.