Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:34:59+00:00 2026-06-12T03:34:59+00:00

I need the maximum length of a uniform name. ie: given a used program

  • 0

I need the maximum length of a uniform name. ie: given a used program with uniforms uniform test and uniform myuniform, glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, outParam) should get output of 10 (for “myuniform”).

I have a very simple test shader set up with 1 defined uniform: uniform float time

glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, outParam) returns 5, the length of time. If I change “time” to something else, it returns the changed length (ex: change to “timer” it returns 6).

glGetProgramiv with GL_ACTIVE_UNIFORMS tells me that there are 2 uniforms.
The second uniform that it is reporting is gl_ModelViewProjectionMatrix.

I am fine with it including gl_ModelViewProjectionMatrix in the list – I am using it in the shader, but this brings up a problem when combined with the other return value. Why doesn’t glGetProgramiv return the length of “gl_ModelViewProjectionMatrix” if it is including it in the list? I need the full names of attributes and variables for my application, but since I am getting a max length of 5, glGetActiveUniform is returning a uniform name of “gl_M” which is not acceptable.

Either the max name length should include the MVP matrix, or the list of names should not. It does not make sense to include the name in the list but not in the max name length calculation.

Is this happening only for me? I could not find anything else about it using Google. I could abandon a query for max length and always use very big buffers, but I’ve seen some very long variable names before, so the buffers would have to be huge to guarantee no errors. That’s not a real fix anyway.

This test is working correctly for attributes. I use gl_Vertex and have no other attributes. The system reports 1 current attribute with a length of 10 and a name of gl_Vertex correctly. If I remove my time uniform entirely, that leaves the MVP matrix as the only used uniform, the system reports 1 current uniform, max name length of 0, so getting its name with the returned max length gets nothing.

For completeness, I include the code below. The code is in Java and uses JOGL to access OpenGL bindings. To highlight the relevant areas, I have deleted lines not relevant to this issue, which was mostly the GUI updating, including the GUI part that actually shows the values obtained in here. I also deleted the part that gets the attributes since that works fine, as stated above.

FYI for the C people who are wary of the Java-isms: think of a Buffer (IntBuffer, ByteBuffer, FloatBuffer) like a pointer, buffer.get() like buffer[n++], and buffer = IntBuffer.allocate(n) like a malloc(). I also use OpenGL in C and C++, so I can rewrite this in C if the GLSL gurus here prefer that.

Any suggestions?

// add options to panelShaderParameters
public void updateShaderParameters(GLAutoDrawable surface)
{
    GL2 gl = surface.getGL().getGL2();

    IntBuffer outParam = IntBuffer.allocate(1);
    int numParameters = 0,
        maxNameLength = 0;

    IntBuffer size = null,
        type = null;
    ByteBuffer name = null;

    gl.glGetProgramiv(shader.getName(), GL2.GL_ACTIVE_UNIFORMS, outParam);
    numParameters = outParam.get();
    outParam = IntBuffer.allocate(1);
    gl.glGetProgramiv(shader.getName(), GL2.GL_ACTIVE_UNIFORM_MAX_LENGTH, outParam);
    maxNameLength = outParam.get();

    for(int i = 0; i < numParameters; i += 1)
    {
        size = IntBuffer.allocate(1);
        type = IntBuffer.allocate(1);
        name = ByteBuffer.allocate(maxNameLength);
        gl.glGetActiveUniform(shader.getName(), i, maxNameLength, (IntBuffer)null, size, type, name);
        byte[] nameBuffer = new byte[maxNameLength];
        name.position(0);
        name.get(nameBuffer);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:35:00+00:00Added an answer on June 12, 2026 at 3:35 am

    You have found a driver bug. You can attempt to report it (this forum is a place where it may be seen), but there’s nothing you can do to make it work correctly. So just work around it.

    Rather than having a single max-size, just ask each uniform in turn what it’s length is. In C/C++, you do this by passing NULL for the buffer to glGetActiveUniformName:

    GLsizei length;
    glGetActiveUniformName(program, index, 1000 /*large number*/, &length, NULL);
    //Use length to allocate a buffer of the appropriate size.
    

    I don’t know how this would work using JOGL. Perhaps you should switch to LWJGL, which has a much more reasonable Java implementation of this function.

    Also, stop storing the strings as byte arrays. Convert them into proper Java strings (another reason to use LWJGL).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m in need of some clarification of the maximum length of a varchar field
I need to know the maximum length of a textbox in ssrs. How much
I need to set a maximum widht to a label tag and avoid the
I need to get the maximum value out of this code, but it's really
I need to find the maximum route of a triangle. I earlier posted this
I need to adjust the minimum and maximum values of the X axis of
I need to find out the maximum and minimum value in a line by
I need to get the minimum and maximum values in a collection of floating
I need a component/class that throttles execution of some method to maximum M calls
what's the maximum number of characters generated by the following statement? i need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.