1
\$\begingroup\$

I'm trying to send an integer attribute to my GLSL shader. The shader receives the attribute as follows:

layout (location = 3) in int integer_value;

I'm creating the attribute as follows:

glBindBuffer(GL_ARRAY_BUFFER, this.integerValueVboId);
glBufferData(GL_ARRAY_BUFFER, integer_values_buffer, GL_STATIC_DRAW);
glVertexAttribPointer(3, 1, GL_INT, false, 0, 0);

this.integerValueVboId is a valid ID generated with all the other VBOs. integer_values_buffer is an IntBuffer confirmed to contain the correct integer values.

When I set one of the integer values to 1, the shader receives the integer value 1065353216, which I have found to be the value obtained when one interprets a float 1.0f as an integer value.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

When specifying an integer attribute you need to use glVertexAttribIPointer:

For glVertexAttribPointer, if normalized is set to GL_TRUE, it indicates that values stored in an integer format are to be mapped to the range [-1,1] (for signed values) or [0,1] (for unsigned values) when they are accessed and converted to floating point. Otherwise, values will be converted to floats directly without normalization.

For glVertexAttribIPointer, only the integer types GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT are accepted. Values are always left as integer values.

(My emphasis)

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .