Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: find the location of texture uniform

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Question find the location of texture uniform

    Hi ,here is my glsl code

    Code :
    #version 400
     
    in vec4 ex_Color;
    in vec4 ex_Pos;
    out vec4 FragColor;
     
     
    uniform sampler2D RayStartPoint;
    uniform sampler2D RayStopPoint;
     
    void main()
    {
      vec4 temp = ex_Color;
      vec2 texc = ((ex_Pos.xy / ex_Pos.w) + 1.0f )/2.0f ;  
     
      vec4 startPosition  = texture(RayStartPoint, texc) ;
      vec4 stopPosition  = texture2D(RayStopPoint, texc);
       temp.w = 1 ;   
     
     // FragColor = startPosition ;
    	FragColor = stopPosition ;
     // FragColor = temp ;
     
     //  FragColor = stopPosition -  startPosition ;
     
    }
    my program could find the first uniform location,but can't find the second. the function "glGetUniformLocation" just return -1
    anyone had encountered similar problem?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Of course it couldn't; you never used it.

    The compiler can plainly see that you never use `startPosition` to generate the fragment shader output in any way. So it is optimized out; it doesn't access the RayStartPoint texture. And since you never access the texture, the sampler uniform is itself optimized out. It is not an active uniform, so the compiler doesn't have to provide a uniform location for it.

    You should not consider getting a -1 back from `glGetUniformLocation` to be an error.

  3. #3
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Thanks

    Quote Originally Posted by Alfonse Reinheart View Post
    Of course it couldn't; you never used it.

    The compiler can plainly see that you never use `startPosition` to generate the fragment shader output in any way. So it is optimized out; it doesn't access the RayStartPoint texture. And since you never access the texture, the sampler uniform is itself optimized out. It is not an active uniform, so the compiler doesn't have to provide a uniform location for it.

    You should not consider getting a -1 back from `glGetUniformLocation` to be an error.
    Thank you very much ! problem got solved。

    and can you tell me where to find the infromation about the "shader complier"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •