title: How to find out a texture's format in GLSL
body: <p>I am working on a shader for different image bit depths and a lookup table.
  So what I have works nicely but for the lookup I need to know the internal format of the texture. Actually that is only indirectly the truth, but it would serve me completely. So this is what I have:</p>
  
  <pre><code>        #version 150
          precision highp float;
  
          uniform samplerBuffer LutData; 
          uniform sampler2D Texture;     
          void main() 
          { 
              color = texture(Texture, fragTexCoord);
              // R16 grayscale texture - handle 16bit wise mono
              float primaryLvl = color.r;
              int index = int(primaryLvl * 65535);
              float gray = texelFetch(LutData, index).r;
              finalColor = vec4(gray, gray, gray, 1);
          }
  </code></pre>
  
  <p>Shortened version (so may not work)</p>
  
  <p>What I need is this (pseudocode + only main):</p>
  
  <pre><code>        void main() 
          { 
              // need follows here:
              int lutspread = gettextureparam(Texture, MaxRange);
  
              color = texture(Texture, fragTexCoord);
              // R16 grayscale texture - handle 16bit wise mono
              float primaryLvl = color.r;
              int index = int(primaryLvl * lutspread);
              float gray = texelFetch(LutData, index).r;
              finalColor = vec4(gray, gray, gray, 1);
          }
  </code></pre>
  
  <p>Does such a thing exist?</p>
  
  <p>So that <code>lutspread</code> is either 255 or 65535. Because what "normal" samplers do is: They inperpret texture integers as normalized integers which results in 32-bit float values between 0.0-1.0. And it does not make a difference whether the texture format is RED8 or RED16 it only is more or less granular! However if a LUT is part of the game this feature is contra productive because a LUT wants raw data.</p>
  
  <p>BTW: I already had my less successful tries using <code>GL_REDui</code> and <code>GL_RED_INTEGER</code> as texture generating parameters. I fear it makes me more problems than my current approach using <code>GL_RED8</code>/<code>GL_RED16</code> + <code>GL_LUMINANCE</code></p>
  
  <p>You can tell me to go that path but I will be very scared to loose things I have so far. Ultimately I'll introduce a uniform and use that as my factor.</p>