开发者

OpenGL 3.3, GLSL 1.5: How to setup a Texture Buffer Object containing various texture2D?

I've been wondering whether it is possible to have an array of sampler2D in a GLSL 1.5 vertex shader.

I need to access 30 different 2d-textures from my vertex shader. I read that it is not possible to have a structure like:

uniform sampler2d texture[30];

However, having 30 different uniforms is a bit exaggerated and fairly hard to manage...

So, that brought me to the idea of having a texture buffer object. TBO's are supported since OpenGL 3.0. However, I couldn't find a good tutorial or example, respectively, which shows how to initialize a TBO with not only one texture, but several textures.

This website shows an example on how to initialize a TBO with a single texture. No big deal at all. I think the most important method is

void createTBO(GLuint* tbo, GLuint* tex)

By executing the method

glTexBufferEXT(GL_TEXTURE_BUFFER_EXT, GL_RGBA32F_ARB, *tbo);  

one can actually attach the texture to the buffer. This is also mentioned here. I assume calling glTexBuffer 30 times one after the other wouldn't do the trick.

So, I've been thinking if there might be another way of getting the very same result. I came up with two ideas:

  • Adding the 30 2d-textures to a 3d-texture and attach that directly to the vertex shader. However, that would be a big waste of memory since most of the 3d-texture's layers wouldn't be used.
  • Using a structure called sampler2DArray. It is mentioned in the specs. However, I searched the web and couldn't find any valuable information about how to implement that.

So, my questions are:

  • How do I setup a T开发者_运维技巧BO containing more than only 1 texture?
  • Is that possible at all?
  • Do you know sources where I could find information about adding 2d-textures to a 3d-texture?
  • Do you know websites where I could find information about the initializing, binding and usage of sampler2DArray?

I'd be grateful if you could advice me. I'm really a newbie in terms of OpenGL.

Thanks Walter


I believe you misunderstood what a Texture Buffer Object (TBO) is. A TBO is used to access a buffer object inside a shader, nothing more. It doesn't hold multiple textures or anything like that.

If the textures are of the same size, you can use a 3D texture or a Texture array. A TBO is no use for your problem.


You could use sampler2DArray uniforms. You can use them to pass multiple textures to your shader.

http://www.opengl.org/registry/specs/EXT/texture_array.txt

An alternative solution would be to use a very large tbo and store all textures within the tbo. A Texture can be as large as 11585x11585 texels (2^27)

texture_buffer_object.txt


As Jotschi suggested use one very large texture and adjust texture coordinates accordingly. (or: write a shader that maps standard coordinates to the right place) This is what's called a texture atlas. I'd guess you can find some implementations by searching for the term.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜