PDA

View Full Version : Binding a single TEXTURE_2D_ARRAY layer to a sampler2D



sleap
08-28-2014, 04:53 AM
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?

carsten neumann
08-28-2014, 05:39 AM
Take a look at glTextureView (http://www.opengl.org/sdk/docs/man/html/glTextureView.xhtml).

sleap
08-28-2014, 06:49 AM
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.