"Wrong Component Type or Count" GLSL shader error

Hello!
I am working on a small side project, and am experimenting with a 24-but depth buffer shader.

Vertex:

out vec3 vNormal;
out vec3 vPosition;
out vec2 vTexCoords;
out vec4 vColour;
out float depth_space;

void main() {
    vec4 object_space_pos = vec4(in_Position, 1.0);
    
	vPosition = vec3(MATRIX_VIEW * MATRIX_OBJECT_POSITION) * in_Position;
	vNormal = MATRIX_NORMAL * in_Normal;
	
	vTexCoords = in_TextureCoord;
	vColour = in_Colour * VECTOR_OBJECT_COLOUR;
	
	// Set the correct vertex position
	gl_Position = MATRIX_PROJECTION_VIEW * MATRIX_OBJECT_POSITION * object_space_pos;
	
	vec4 viewSpacePos = MATRIX_VIEW * MATRIX_OBJECT_POSITION * object_space_pos;
	depth_space = viewSpacePos.z / 300.0;
}

Fragment:

in vec3 vNormal;
in vec2 vTexCoords;
in vec4 vColour;
in vec3 vPosition;
in float depth_space;

vec3 floatToColor(float f) {
    return vec3(floor(f*255.0)/255.0,fract(f*255.0),fract(f*255.0*255.0));
}

void main() {
    vec4 textureSample = texture(sampler, vTexCoords);
    if(textureSample.a <= 0){
		discard;
	}

    out_Colour = vec4( floatToColor(depth_space), 1.0);
}

When running this shader in my game I run into this error:

[LWJGL] ARB_debug_output message
	ID: 1282
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_OPERATION error generated. Wrong component type or count.

What’s weird is that the shader seems to actually work… Here is the output:

What could be the issue?

Setup breakpoints on every GL function you call in the IDE and step through them, you will know which function is generating that error. Without knowing the function that’s generating the issue, we can’t help.

Well if I change the frag shader to:

in vec3 vNormal;
in vec2 vTexCoords;
in vec4 vColour;
in vec3 vPosition;
in float depth_space;

vec3 floatToColor(float f) {
    return vec3(floor(f*255.0)/255.0,fract(f*255.0),fract(f*255.0*255.0));
}

void main() {
    vec4 textureSample = texture(sampler, vTexCoords);
    if(textureSample.a <= 0){
      discard;
   }

    out_Colour = textureSample * vColour;
}

It doesn’t error. So how could it be related to a function called in Java?

it’s not. “Wrong component type or count” indicates a glsl-error … which happens if you do things like [icode]vec3 foo = vec3(bar.xy)[/icode] or similar. it’s not clear what’s going on from your code snip, there are too many things defined somewhere we cannot see.

Actually I agree with @SHC. I think you are calling one of the glUniformXX() variants with the wrong number / type of arguments which if you read the docs:

[quote]GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command.

GL_INVALID_OPERATION is generated if one of the integer variants of this function is used to load a uniform variable of type float, vec2, vec3, vec4, or an array of these, or if one of the floating-point variants of this function is used to load a uniform variable of type int, ivec2, ivec3, or ivec4, or an array of these.
[/quote]
I can’t see any shader creation/compiling/linking functions that will generate a GL_INVALID_OPERATION if the shader compilation failed. And if it fails, the shader definitely should not work. But a uniform set fail can still work if the default value works or it is set elsewhere.

Also wrong data supplied to sampler.

Cas :slight_smile:

Can you explain this?

Ah ignore me, I’m wrong. I was just speculating that a sampler that was sampling RGB values instead of, say RGBA, would return a vec3 but I don’t think that’s the case.

Cas :slight_smile:

It may be that you need to specify the glsl version at the top of your files because there are different functions available in different spec versions.

I figured out the issue. I had a setup where I had two shaders; The normal render shader, and my test shader. When I switched to the test shader, I didn’t set all of the uniforms (projection, telling all objects that the shader changed, ect).

All is well now :wink: