简体   繁体   中英

Bind the same “texture memory” to textures with different dimensionalities

How can I bind the same "texture memory" to textures with different dimensionalities.

For example, I need to access an array of 2D images using a sampler2DArray in a shader, and a sampler3D in another shader, without having to load and store the data on the graphics card memory twice.

I'd like to do something like this:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
glTexImage3D(GL_TEXTURE_2D_ARRAY, ...);    // allocate & store pixel data

and then:

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_3D, tex);    // "reuse" the texture storage with a
                                      // different dimensionality in another 
                                      // texture unit

But the last line is obviously invalid.

Is there any method to do something like that?

OpenGL (4.3+) has a concept called view textures . If you create a texture with immutable storage , then you can create a texture that references that immutable storage. Or part of that immutable storage. You can change things like image formats (if they're compatible) and even texture targets. You can extract a single element of a 2D array and use it as a regular 2D texture. Or you can turn a 2D texture into a 2D array of 1 layer.

However, you cannot view a 2D array texture's storage as a 3D texture. Or vice-versa. Their mipmaps don't work the same way. In a 3D texture, mipmaps decrease in X, Y and Z. In 2D array textures, they only get smaller in X and Y.

Even Vulkan doesn't let you create a VkImageView that is a 3D image view from a VkImage that was allocated as an arrayed 2D image (or vice-versa).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM