Reputation: 46
I am trying to pass the frame size (X, Y) to my fragment shader. When I execute the GLAD function glUniformMatrix2fv
, I get the following error:
GL CALLBACK: ** GL ERROR ** type = "0x824c", severity = "0x9146", message = Error has been generated. GL error GL_INVALID_OPERATION
I use this method to pass glm::vec4
datatypes (using glUniformMatrix4fv
) for many other shaders without issue. I've looked up the error type, 0x824c
, and it appears to be a DEBUG_TYPE_ERROR. I have checked the function call in the relevant documention, and it appears to be correct. What am I missing?
Drawing code:
uFrameSizeID = glGetUniformLocation(shader->id(), "uFrameSize");
glUniformMatrix2fv(uFrameSizeID, 1, GL_FALSE, glm::value_ptr(
glm::vec2(static_cast<float>(X_RESOLUTION), static_cast<float>(Y_RESOLUTION))));
Fragment Shader:
layout(location = 0) out vec4 FragColor;
in VertexData
{
vec4 color;
vec2 texCoords;
} fs_in;
uniform sampler2D uTexture;
uniform sampler2D uDistortionMapX;
uniform sampler2D uDistortionMapY;
uniform vec4 uWindow; // = [x0, y0, dx, dy]
uniform vec2 uFrameSize; // = [X, Y] float
void main()
{
vec2 v2_dist_vec;
v2_dist_vec.x = texture(uDistortionMapX, fs_in.texCoords).r;
v2_dist_vec.y = texture(uDistortionMapY, fs_in.texCoords).r;
FragColor = texture(uTexture, fs_in.texCoords + v2_corr_vec);
}
Upvotes: 1
Views: 304
Reputation: 7198
glUniformMatrix2fv
passes a 2x2 matrix. But in your shader you use uniform vec2 uFrameSize;
which is a pair of floats. You must use glUniform2fv
, or even simpler glUniform2f
:
uFrameSizeID = glGetUniformLocation(shader->id(), "uFrameSize");
glUniform2f(uFrameSizeID, static_cast<float>(X_RESOLUTION), static_cast<float>(Y_RESOLUTION));
Upvotes: 1