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

From OpenGL Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
<p>
+
The information here is in regards to GL_ARB_texture_float and GL_ARB_half_float_pixel.<br>
 +
These extension became core in GL 3.0<br>
 +
http://www.opengl.org/registry/specs/ARB/texture_float.txt<br>
 +
http://www.opengl.org/registry/specs/ARB/half_float_pixel.txt<br>
 +
 
 +
=== GPUs and What is supported ===
 
Some GPUs support floating point textures but don't support mipmapping or filtering.<br>
 
Some GPUs support floating point textures but don't support mipmapping or filtering.<br>
 
How to detect if a GPU supports mipmapping and filtering?<br>
 
How to detect if a GPU supports mipmapping and filtering?<br>
 
<br>
 
<br>
If you want a simpler approach then 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>
+
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>
 
<br>
 
<br>
On ATI you need to check for GL_ATI_shader_texture_lod. That's FP16 blending.
+
On ATI you need to check for GL_ATI_shader_texture_lod.<br>
As for filtering it wasn't supported on Radeon X1k and below. X2k should support it - check for geometry shaders or some other SM4.0 feature.<br>
+
This should be available on X300 and above. FB16 blending is supported but mipmapping and filtering is not<br>
 +
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.<br>
 +
Unfortunately, both ATI and nVidia haven't made feature detection easy.<br>
 
<br>
 
<br>
 
This information comes from http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015278<br>
 
This information comes from http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015278<br>
 +
The link is dead now.<br>
 
<br>
 
<br>
</p>
+
Also, when this extension is present or when GL 3.0 is present, in principle the GPU supports 1D, 2D, 3D, CUBEMAP float textures.<br>
 +
 
 +
=== 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.<br>
 +
GL_RGBA16F_ARB, GL_RGB16F_ARB, GL_ALPHA16F_ARB, GL_INTENSITY16F_ARB, GL_LUMINANCE16F_ARB, GL_LUMINANCE_ALPHA16F_ARB for 16 bit floats.<br>
 +
For GL 3.0, you can drop the _ARB postfix since float textures are a requirement.<br>
 +
 
 +
=== 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);

Revision as of 18:19, 19 October 2008

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

Some GPUs support floating point textures but don't support mipmapping or filtering.
How to detect if a GPU supports mipmapping and 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);