title: How to access automatic mipmap level in GLSL fragment shader texture?
body: <p>How do I determine what mipmap level was used when sampling a texture in a GLSL fragment shader?</p>
  
  <p>I understand that I can manually sample a particular mipmap level of a texture using the <code>textureLod(...)</code> method:</p>
  
  <pre><code>uniform sampler2D myTexture;
  
  void main()
  {
      float mipmapLevel = 1;
      vec2 textureCoord = vec2(0.5, 0.5);
      gl_FragColor = textureLod(myTexture, textureCoord, mipmapLevel);
  }
  </code></pre>
  
  <p>Or I could allow the mipmap level to be selected automatically using <code>texture(...)</code> like</p>
  
  <pre><code>uniform sampler2D myTexture;
  
  void main()
  {
      vec2 textureCoord = vec2(0.5, 0.5);
      gl_FragColor = texture(myTexture, textureCoord);
  }
  </code></pre>
  
  <p>I prefer the latter, because I trust the driver's judgment about appropriate mipmap level more than I do my own.</p>
  
  <p>But I'd like to know what mipmap level was used in the automatic sampling process, to help me rationally sample nearby pixels. Is there a way in GLSL to access the information about what mipmap level was used for an automatic texture sample?</p>