Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL - Reading Textures

Started by weeska Jan 5, 2012 at 10:42 PM 1 replies 2k views
Original Post
weeska
weeska
Hi everyone,

i'm a bit confused about how i can read textures of specific formats in opengl. Normally, you would use texture2D or texelFetch or something like that, and get a vec4 as a result. It's possible to declare output variables like

out vec2 data;

and write to it. Now i wonder how you can read some vec2 value. Can one just use the same function and only use vec4.xy? If that's the case, what will be vec4.zw? Will they be zero because of some "pipeline-magic", or are they just filled with the data of the next texel?

I'd be glad if someone could point me to some source where i can read what happens there and how i can access such vec2-textures.

I didn't post code because it's not a code-related problem, it's more like that i don't find these things explained in the docs.

greetings,
weeska
V-man
V-man
It depends on the GL specification, and the texture format.

EXAMPLE
http://www.opengl.org/sdk/docs/man/
for glteximage2d portion, it says if you use luminance format, GL assembles it in a RGB and sets alpha to 1.
So that's what happens in GLSL as well. In other words, that how the GPU is wired.
weeska
weeska
Thank you!

So from OpenGL's side, there's just the specification of the internal data format. In GLSL i need to set the appropriate output-format to write it, or there will be some conversion depending on the data type.

The manual says for GL_LUMINANCE: "...The GL converts it to floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue and attaching 1 for alpha..."

So it's not important if i access r,g or b in GLSL because they all give me the same result, and displaying a luminance texture would automatically result in a grey rgba texture?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.