我正在尝试将帧大小(X,Y)传递给片段着色器。当我执行GLAD函数glUniformMatrix2fv
时,出现以下错误:
总帐回调:**总帐错误**类型=“ 0x824c”,严重性=“ 0x9146”,消息=已生成错误。 GL错误GL_INVALID_OPERATION
我使用此方法为许多其他着色器传递了glm::vec4
数据类型(使用glUniformMatrix4fv
),没有问题。我查找了错误类型0x824c
,它似乎是DEBUG_TYPE_ERROR。我已经检查了relevant documention中的函数调用,它似乎是正确的。我想念什么?
绘图代码:
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))));
片段着色器:
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);
}
答案 0 :(得分:1)
glUniformMatrix2fv
传递 2x2 矩阵。但是在着色器中,您使用uniform vec2 uFrameSize;
,它是一对浮点。您必须使用glUniform2fv
,或更简单的glUniform2f
:
uFrameSizeID = glGetUniformLocation(shader->id(), "uFrameSize");
glUniform2f(uFrameSizeID, static_cast<float>(X_RESOLUTION), static_cast<float>(Y_RESOLUTION));