问题
I've got a problem with 3d texture mapping. If I have several 2d textures, and I want to build a 3d texture with these 2d textures. What can I do to put all these data together? The function glTexImage3D ends with a parameter const GLvoid *texels which leads to the data of the texture. But now I have 32 2D textures and want to get a 3D texture. How to do that?
The second question is about image space filtering method. Is there anyone who knows what it is? I should use this method to determine texture coordinate.
回答1:
Do you really need 3D textures? maybe the better way is to have texture Arrays?
here is a good info: http://www.opengl.org/wiki/Array_Texture
it is a bit simpler than 3D textures to use I think. They are very useful for instance in cascaded shadow mapping where each cascade goes to different element in the array of textures.
回答2:
But now I have 32 2D textures and want to get a 3D texture. How to do that?
At some point in your program you upload the textures. From your question I presume you already did upload them using glTexImage2D. It's difficult, cumbersome and not very robust to transfer texture data between texture objects, so asking how to combine 2D textures into a 3D texture is a bit off.
But what you can do perfectly well is building your 3D texture from slices of 2D data uploaded one after another to the block of 3D votexels. Just replace every call to glTexImage2D with a call of glTexSubImage3D. Before uploading any data you can initialize the texture using a call to glTexImage3D and a NULL pointer as data parameter (you can also use glTexStorage3D if you're using OpenGL-4).
来源:https://stackoverflow.com/questions/10617810/how-to-use-3d-texture-in-opengl-and-cg-shaders