Floating point and mipmapping and filtering

From OpenGL.org
Jump to: navigation, search

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

Any hardware that supports GL 3.0 and above has floating-point texture support built in. All of this hardware support mipmaps, filtering, blending, etc, just like for regular textures. The rest of this article concerns pre-3.x-class hardware.

For 2.x-class hardware, the GL_ARB_texture_float extension exists. NVIDIA GeForce 5xxx to 7xxx cards support this, as well as the Radeon 9500+, Radeon X*** (like X700, X300), and Radeon X1*** (X1700, etc) lines (ie: before their HD-2000 class cards).

Though the extension specification specifically requires mipmapping and filtering, some cards lie about support for these. Radeon GL 2.x cards, for example, do not support mipmapping or filtering.

To detect the difference, you can use glGetString with GL_VENDOR​ to test whether it is an NVIDIA or ATI driver. Alternatively, you can check for certain extensions. GL_NV_fragment_program_3 is an NVIDIA extension supported on GeForce 6+ hardware, which can do filtering, mipmapping, and blending, but only on 16F image formats (not 32F).

The presence of GL_ATI_shader_texture_lod represents Radeon X***-class hardware. This hardware can perform blending with only 16F image formats, but not filtering or mipmapping.

Are Values Clamped from 0.0 to 1.0

No, you can use the full range supported.

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);