1

I am rendering textured quads (in screen space) and I want to specify the texture in the vertex data, send as a flat output to the fragment shader, and use to select the texture. The value is being changed during this process. In RenderDoc the VS input is 2 and output is 1073741824 (for every vertex). anyone have any idea why? (4.6 core context, shaders #version 460). I am uploading 6 vertices per quad and using glDrawArrays(). Texture stage 0 works, but any non-zero value is transformed.

layout(location=0) in vec3 coord3d;
layout(location=1) in vec2 uvIn;
layout(location=2) in vec3 colorIn;
layout(location=3) in unsigned int textureStageIn;

out vec4 color;
out vec2 uv;
flat out unsigned int textureStage;

void main(void)
{
    gl_Position = vec4( coord3d, 1.0 );
    color = vec4(colorIn,1.0); 
    uv = uvIn;
    textureStage = textureStageIn;
}
in vec4 color;
in vec2 uv;
flat in unsigned int textureStage;

uniform sampler2D tex00;
uniform sampler2D tex01;
uniform sampler2D tex02;

out vec4 outpColor;

void main(void)
{
    vec2 uvDx = dFdx(uv);
    vec2 uvDy = dFdy(uv);

    switch ( textureStage )
    {
        case 0:
            outpColor = textureGrad(tex00, uv, uvDx, uvDy );
            break;
        case 1:
            outpColor = textureGrad(tex01, uv, uvDx, uvDy );
            break;
        case 2:
            outpColor = textureGrad(tex02, uv, uvDx, uvDy );
            break;
        default:
            outpColor = color;
            break;
    }
} 
1
  • You have to us glVertexAttribIPointer (focus on I) for the specification of integral attributes. In compare to glVertexAttribPointer for floating point attributes. See glVertexAttribPointer Commented Jan 16, 2020 at 12:08

1 Answer 1

2

You have to use glVertexAttribIPointer (focus on I) for the specification of integral attributes. In compare to glVertexAttribPointer for floating point attributes. See glVertexAttribPointer.

Note, the type parameter of this functions specifies the type of the source data only, but it doesn't say anything about the type of the attribute. For each attribute base type (float point, integral, 64-bit double precision float), there is a different function.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that was it. I guess I was misled by the docs when it said "type Specifies the data type of each component in the array. The symbolic constants GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, and GL_UNSIGNED_INT are accepted by glVertexAttribPointer and glVertexAttribIPointer."
@MarkL Note, the type parameter of this functions specifies the type of the source data only, but id doesn't say anything about the type of the attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.