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 4 of 4

Thread: Why is glGetActiveUniform() misbehaving?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2017
    Posts
    5

    Why is glGetActiveUniform() misbehaving?

    I just learned about glGetActiveUniform(), so naturally I introduced a uniform in my vertex shader
    Code :
    uniform int sup;
    and in my code, I wrote
    Code :
    GLuint supUniformLocation = glGetUniformLocation(<program_ID>, "sup");
    glUniform1i(supUniformLocation, 1);    // just in case being uninitialized messes things up
    GLint supSize;
    GLchar supName[100];
    glGetActiveUniform(programID, supUniformLocation, sizeof(supName) - 1, NULL, &supSize, NULL, supName);
    std::cout << supName << " " << supSize << std::endl;
    All of this compiles fine, and spits out the following garbage:
    Code :
    supName: ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠****╠╠╠╠╠╠╠╠, supSize: -858993460

    I cannot figure out what is wrong. :/

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    Any errors returned by OpenGL ?
    Is your uniform used in your shader or just declared ?

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,407
    Quote Originally Posted by nikoniko View Post
    Code :
    GLuint supUniformLocation = glGetUniformLocation(<program_ID>, "sup");
    The return value of glGetUniformLocation() is GLint, not GLuint; the return value will be -1 if the name doesn't identify an active uniform. But the index parameter to glGetActiveUniform() is GLuint, and
    GL_INVALID_VALUE is generated if index is greater than or equal to the number of active uniform variables in program.
    So you need to check that the location isn't negative prior to casting.

    The uniform variable will be eliminated by the compiler if its value isn't required to compute the program's outputs (this is why there's a concept of "active" uniforms).

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2017
    Posts
    5
    Silence and GClements: I used the uniform in the shader, and now it outputs the uniform name and size fine. Thanks!

Posting Permissions

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