mat3x3的缓冲区问题

时间:2014-03-15 20:23:05

标签: c++ opengl

当我尝试将mat3x3s的缓冲区上传到存储缓冲区时,矩阵无法正常工作。

layout(packed, binding = 0) readonly buffer matrix_buffer
{
    mat3x3 matrix[];
};

...

gl_Position = vec4(vec3(pos, 0.0f) * matrix[gl_InstanceID], 1.0);
//doesn't work (nothing rendered)

gl_Position = vec4(vec3(pos, 0.0f) * mat3(1.0), 1.0);
//works

但是,使用mat4x4时没有问题。

layout(packed, binding = 0) readonly buffer matrix_buffer
{
    mat4x4 matrix[];
};

...

gl_Position = vec4(pos, 0.0f, 1.0) * matrix[gl_InstanceID];
//works

我的GL代码基本上是这样的:

std::vector<glm::mat3> matrix(8192, glm::mat3(1.0f));
glNamedBufferStorageEXT(buffer, sizeof(matrix[0]) * matrix.size(), matrix.data(), 0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);

//example2

std::vector<glm::mat4> matrix(8192, glm::mat4(1.0f));
glNamedBufferStorageEXT(buffer, sizeof(matrix[0]) * matrix.size(), matrix.data(), 0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);

我也尝试过std140和std430布局。

0 个答案:

没有答案