Skip to main content
Bumped by Community user
deleted 5 characters in body
Source Link
BadZen
  • 143
  • 5

I have a sampler variable in a shader:

 uniform sampler2DArray tiles;

Which I am trying to bind to a texture unit in GL:

    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
    System.out.println("tiles: "+tilesUniformIndex);
    glUseProgram(shaderProgramId);
    glok();  // <- This calls glGetError() and throws exception if not-ok
    glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
    glok();

TILE_TEXTURE_UNIT_INDEX is a constant defined to be zero.

The location is being correctly introspected, output is:

 tiles: 7

which is the correct binding location I expect in context of the shader source.

The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.

According to the documentation, this can only happen if the count parameter is less than zero. But glUniform1i /doesn't have a count parameter/!

I've tried:

glUniform1iv(tilesUniformIndex, 1, new int[]{GL31.GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});

as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value).

So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?

I have a sampler variable in a shader:

 uniform sampler2DArray tiles;

Which I am trying to bind to a texture unit in GL:

    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
    System.out.println("tiles: "+tilesUniformIndex);
    glUseProgram(shaderProgramId);
    glok();  // <- This calls glGetError() and throws exception if not-ok
    glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
    glok();

TILE_TEXTURE_UNIT_INDEX is a constant defined to be zero.

The location is being correctly introspected, output is:

 tiles: 7

which is the correct binding location I expect in context of the shader source.

The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.

According to the documentation, this can only happen if the count parameter is less than zero. But glUniform1i /doesn't have a count parameter/!

I've tried:

glUniform1iv(tilesUniformIndex, 1, new int[]{GL31.GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});

as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value).

So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?

I have a sampler variable in a shader:

 uniform sampler2DArray tiles;

Which I am trying to bind to a texture unit in GL:

    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
    System.out.println("tiles: "+tilesUniformIndex);
    glUseProgram(shaderProgramId);
    glok();  // <- This calls glGetError() and throws exception if not-ok
    glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
    glok();

TILE_TEXTURE_UNIT_INDEX is a constant defined to be zero.

The location is being correctly introspected, output is:

 tiles: 7

which is the correct binding location I expect in context of the shader source.

The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.

According to the documentation, this can only happen if the count parameter is less than zero. But glUniform1i /doesn't have a count parameter/!

I've tried:

glUniform1iv(tilesUniformIndex, 1, new int[]{GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});

as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value).

So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?

Source Link
BadZen
  • 143
  • 5

Why is glUniform1i() returning GL_INVALID_VALUE?

I have a sampler variable in a shader:

 uniform sampler2DArray tiles;

Which I am trying to bind to a texture unit in GL:

    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
    System.out.println("tiles: "+tilesUniformIndex);
    glUseProgram(shaderProgramId);
    glok();  // <- This calls glGetError() and throws exception if not-ok
    glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
    glok();

TILE_TEXTURE_UNIT_INDEX is a constant defined to be zero.

The location is being correctly introspected, output is:

 tiles: 7

which is the correct binding location I expect in context of the shader source.

The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.

According to the documentation, this can only happen if the count parameter is less than zero. But glUniform1i /doesn't have a count parameter/!

I've tried:

glUniform1iv(tilesUniformIndex, 1, new int[]{GL31.GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});

as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value).

So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?