PDA

View Full Version : [Texture] Type, range and sampler



Kiwaiii
05-11-2009, 01:52 AM
Hi!

I would like some help to understand more correctly OpenGL and GLSL specifications about texture managment.

Focus is on 2D texture and basic/normal format (keep away compressed or other funny formats). So :

(External) Type : (Use to describe CPU data, right ?)
(32bits)
GL_FLOAT
GL_INT
GL_UNSIGNED_INT
(16bits)
GL_HALF_FLOAT_ARB
GL_SHORT
GL_UNSIGNED_SHORT
(8bits)
GL_BYTE
GL_UNSIGNED_BYTE


(External) Format : (Use to describe CPU data, right ?)
GL_RED GL_RG GL_RGB GL_RGBA GL_DEPTH_COMPONENT

Internal format : (Use to describe GPU data, right?)
So possible direct (any conversion is done) internal formats are :

http://img6.imageshack.us/img6/2064/internalformat.png
Rmq : NINT, NSHORT and NCHAR are actually stored as unsigned type on CPU side.

Right?

Sampler
According to GLSL 1.4 specifications there are three sampler for basic 2D texture :
GL_SAMPLER_2D GL_INT_SAMPLER_2D_EXT GL_UNSIGNED_INT_SAMPLER_2D_EXT

So compatible sampler/texture are :

http://img90.imageshack.us/img90/53/sampler.png

Right?

Range
Range of values at submitting time (CPU value)
FLOAT, HALF : [0,1] INT, SHORT, CHAR : [-2^(N-1),2^(N-1)-1] UINT, USHORT, UCHAR : [0,2^N-1] NINT, NSHORT, NCHAR : [0,2^N-1]
Right?

Range of values at sampling time (GPU value)
FLOAT, HALF : [0,1] INT, SHORT, CHAR : [-2^31,2^31-1] UINT, USHORT, UCHAR : [0,2^32-1] NINT, NSHORT, NCHAR : [0,1]
Right?

So how do you create a float texture with value above 1.0 ? Is it possible ?

Framebuffer : Render to texture
When you bind a float texture to a framebuffer (for instance a GL_R32F texture) and you write float value above 1.0, are they clamped ?

Other
What is real differences between normal texture and depth texture? For instance is there a difference between a GL_R32F texture and a GL_DEPTH_COMPONENT32F texture?

Thank in advance.

Kiwi.

Nighthawk
05-11-2009, 05:08 AM
Nice overview, i think you are correct about the ranges/formats for the most part except the float range:



So how do you create a float texture with value above 1.0 ? Is it possible ?

Yes. All float values can be uploaded to a float texture. I use a texture to store 3D vertex positions in a current project, for example.



When you bind a float texture to a framebuffer (for instance a GL_R32F texture) and you write float value above 1.0, are they clamped ?

By default, output is not clamped for float buffers, see: http://www.opengl.org/registry/specs/ARB/color_buffer_float.txt



What is real differences between normal texture and depth texture? For instance is there a difference between a GL_R32F texture and a GL_DEPTH_COMPONENT32F texture?


Hmm, i think you always need a depth texture for the shadow sampler for example. There might be more differences, maybe this helps:
http://www.opengl.org/registry/specs/ARB/depth_buffer_float.txt

Kiwaiii
05-12-2009, 10:42 PM
Thanks you for all of your answers ! :)