Difference between revisions of "Floating point and mipmapping and filtering"

From OpenGL Wiki
Jump to navigation Jump to search
Line 5: Line 5:
  
 
=== GPUs and What is supported ===
 
=== GPUs and What is supported ===
Some GPUs support floating point textures but don't support mipmapping or filtering.<br>
+
GL_ARB_texture_float is supported on all GPUs that also support GL 2.0. GL_ARB_texture_float is not a core feature in GL 2.0 and also 2.1. It became core in GL 3.0. GPUs that support it are Radeon 9500 and up, Gf FX 5200 and up and these have existed since 2002.<br>
How to detect if a GPU supports mipmapping and filtering?<br>
+
<br>
 +
Some GPUs support floating point textures but don't support mipmapping or filtering (linear) such as the Radeon 9700.<br>
 +
How to detect if a GPU supports mipmapping and/or filtering?<br>
 
<br>
 
<br>
 
If you want a simple approach then you can do the following.<br>
 
If you want a simple approach then you can do the following.<br>
For FP16 textures check for GL_NV_fragment_program_3 - on NVIDIA this extension is supported since GeForce 6 and this GPU can filter/blend FP16 textures.<br>
+
For FP16 textures check for GL_NV_fragment_program_3 - on NVIDIA this extension is supported since Geforce 6 and this GPU can filter/blend FP16 textures.<br>
 
<br>
 
<br>
 
On ATI you need to check for GL_ATI_shader_texture_lod.<br>
 
On ATI you need to check for GL_ATI_shader_texture_lod.<br>

Revision as of 12:04, 13 March 2009

The information here is in regards to GL_ARB_texture_float and GL_ARB_half_float_pixel.
These extension became core in GL 3.0
http://www.opengl.org/registry/specs/ARB/texture_float.txt
http://www.opengl.org/registry/specs/ARB/half_float_pixel.txt

GPUs and What is supported

GL_ARB_texture_float is supported on all GPUs that also support GL 2.0. GL_ARB_texture_float is not a core feature in GL 2.0 and also 2.1. It became core in GL 3.0. GPUs that support it are Radeon 9500 and up, Gf FX 5200 and up and these have existed since 2002.

Some GPUs support floating point textures but don't support mipmapping or filtering (linear) such as the Radeon 9700.
How to detect if a GPU supports mipmapping and/or filtering?

If you want a simple approach then you can do the following.
For FP16 textures check for GL_NV_fragment_program_3 - on NVIDIA this extension is supported since Geforce 6 and this GPU can filter/blend FP16 textures.

On ATI you need to check for GL_ATI_shader_texture_lod.
This should be available on X300 and above. FB16 blending is supported but mipmapping and filtering is not
X2k should support it mipmapping and filtering. You could check what glGetString(GL_RENDERER) returns or test by rendering and readback with glReadPixels and analyze the pixels.
Unfortunately, both ATI and nVidia haven't made feature detection easy.

This information comes from http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015278
The link is dead now.

Also, when this extension is present or when GL 3.0 is present, in principle the GPU supports 1D, 2D, 3D, CUBEMAP float textures.

Are Values Clamped from 0.0 to 1.0

No, you can use the full range supported. GL_RGBA32F_ARB, GL_RGB32F_ARB, GL_ALPHA32F_ARB, GL_INTENSITY32F_ARB, GL_LUMINANCE32F_ARB, GL_LUMINANCE_ALPHA32F_ARB for 32 bit floats.
GL_RGBA16F_ARB, GL_RGB16F_ARB, GL_ALPHA16F_ARB, GL_INTENSITY16F_ARB, GL_LUMINANCE16F_ARB, GL_LUMINANCE_ALPHA16F_ARB for 16 bit floats.
For GL 3.0, you can drop the _ARB postfix since float textures are a requirement.

Example

 //2D RGBA32 float
 uint textureID;
 glGenTextures(1, &textureID);
 glBindTexture(GL_TEXTURE_2D, textureID);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_BGRA, GL_FLOAT, ptexels);
 //3D RGBA32 float
 uint textureID;
 glGenTextures(1, &textureID);
 glBindTexture(GL_TEXTURE_3D, textureID);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_BGRA, GL_FLOAT, ptexels);
 //2D RGBA16 float
 uint textureID;
 glGenTextures(1, &textureID);
 glBindTexture(GL_TEXTURE_2D, textureID);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 //In this case, the driver will convert your 32 bit float to 16 bit float
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_BGRA, GL_FLOAT, ptexels);
 //If you have 16 bit float and you want to submit directly to your GPU, you need GL_ARB_half_float_pixel
 //This extension is also core in GL 3.0
 //Example :
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_BGRA, GL_HALF_FLOAT, ptexels_half_float);
 //3D RGBA16 float
 uint textureID;
 glGenTextures(1, &textureID);
 glBindTexture(GL_TEXTURE_3D, textureID);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 //In this case, the driver will convert your 32 bit float to 16 bit float
 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, width, height, depth, 0, GL_BGRA, GL_FLOAT, ptexels);
 //If you have 16 bit float and you want to submit directly to your GPU, you need GL_ARB_half_float_pixel
 //This extension is also core in GL 3.0
 //Example :
 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, width, height, depth, 0, GL_BGRA, GL_HALF_FLOAT, ptexels_half_float);