Jump to content
  • Advertisement
Sign in to follow this  
weeska

OpenGL GLSL - Reading Textures

This topic is 2534 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!