tags:

views:

368

answers:

2

I am trying to mimic the behavior of OpenGL glTexEnv with a shader. It is quite complex function but should be doable. The only problem is that the function works differently depending on the texture base internal format. How can I get that information out of a texture? The texture base internal format is given with glTexImage2D function so do I have to save it there to some variable and pass it to the shader with some uniform depending on bound texture, or can I get it somehow with OpenGL?

A: 

Hi,

It seems that texture blending values are not part of the built in uniforms.

http://www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf

generally there are two ways for mimic the FFP behavior:

  1. One big Shader, passing values to the shader...
  2. Creating shaders, for each behavior and internal format for example, dynamically as needed.

I prefer the second way, because it does not result in one big and slow allround shader. Instead of that, you get small specific shaders.

Additionally: This common problem is known as "Combinatorial Shader Explosion" problem.

SuperPro
Actually, you /can't/ implement everthing in a single shader. Say you have TEXTURE_3D and TEXTURE_2D targets enabled for texture unit 0. The fixed function spec says the 3D texture will be sampled. the programmable pipeline says the shader decides what will be sampled based on which sampler it uses. Which means you have to build a specific shader for each combination of texture targets. 1D/2D/3D/cube, with 8 Texture units, give you already 64K shader possibilites...
Bahbar
A: 

No, the texture base internal format is not available to the shader directly. If you don't want to store it yourself, you can always ask GL its value to pass it down to your shader.

glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &outFormat)`
Bahbar