将数据从std :: vector传递到glsl中的统一数组

时间:2021-01-12 04:22:19

I have a uniform in a shader like this:

我在这样的着色器中有一件制服:

uniform vec3 origins[10];

and a std::vector in my code like this:

和我的代码中的std :: vector如下:

std::vector<glm::vec3> origins;

that is filled with ten glm::vec3 elements.

它充满了十个glm :: vec3元素。

Does anyone know how do I pass that to the shader? I thought:

有谁知道如何将其传递给着色器?我想:

GLint originsLoc = glGetUniformLocation(programID, "origins");
glUniform3fv(originsLoc, 10, origins.data());

would do it, but it wont compile. The error says there is no matching function for call to 'glUniform3fv'. How do I pass the data in the std::vector in a way that satisfies the glUniform3fv function?

会这样做,但它不会编译。该错误表示调用'glUniform3fv'没有匹配函数。如何以满足glUniform3fv函数的方式传递std :: vector中的数据?

1 个解决方案

#1


you should use a GLfloat and note a glm::vec3. but here it is a any way:

你应该使用GLfloat并注意glm :: vec3。但这是一种方式:

for (int i = 0; i != 10; i++) {
 GLint originsLoc = glGetUniformLocation(programID, "origins[i]");
 glUniform3f(originsLoc, origins[i].x, origins[i].y, origins[i].z);
}

#1


you should use a GLfloat and note a glm::vec3. but here it is a any way:

你应该使用GLfloat并注意glm :: vec3。但这是一种方式:

for (int i = 0; i != 10; i++) {
 GLint originsLoc = glGetUniformLocation(programID, "origins[i]");
 glUniform3f(originsLoc, origins[i].x, origins[i].y, origins[i].z);
}