我正试图从使用glGetProgramResourceName()
的着色器句柄中获得统一的块名称。
然而它在std::vector<GLchar> blockName
上抛出(0xC0000005: Access violation execution location 0x0000000000000000),我不知道为什么。
GLint numUniformBlocks = 0;
GLint maxLength;
GLsizei size;
glGetProgramiv(handle_, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
glGetProgramInterfaceiv(handle_, GL_UNIFORM_BLOCK, GL_ACTIVE_RESOURCES, &numUniformBlocks);
std::array<GLenum, 3> blockProperties{GL_NAME_LENGTH, GL_NUM_ACTIVE_VARIABLES, GL_BUFFER_DATA_SIZE};
std::array<GLint, 3> blockData{};
for (int blockIx = 0; blockIx < numUniformBlocks; ++blockIx) {
glGetProgramResourceiv(handle_,GL_UNIFORM_BLOCK,blockIx,blockProperties.size(), blockProperties.data(), blockData.size(),nullptr,blockData.data()
);
//Retrieve name
//std::string blockName(blockData[0], ' ');
//std::vector<char> blockName(blockData[0]);
std::vector<GLchar> blockName; //Yes, not std::string. There's a reason for that.
blockName.resize(blockData[0]);
//GLchar* blockName = static_cast<GLchar*>(malloc(maxLength));
glGetProgramResourceName(handle_, GL_UNIFORM_BLOCK, blockIx, blockName.size(), &size, blockName.data());
}
这是我的着色器
#version 400
layout (location = 0) in vec4 VertexPosition;
out vec2 TexCoords;
layout(std140) uniform Matrices_XY{
mat4 cameraToClipMatrix;
mat4 worldToCameraMatrix;
mat4 modelToWorldMatrix;
mat4 NormalMatrix;
};
void main(){
gl_Position = cameraToClipMatrix * worldToCameraMatrix * modelToWorldMatrix * vec4(VertexPosition.xy, 0.0, 1.0);
TexCoords = VertexPosition.zw;
}
我试过std::string
,std::vector<char>
,GLchar* name = static_cast<GLchar*>(malloc(maxLength))
和所有扔。我试过附加' '
并调整发送到函数调用的大小,但所有抛出。我希望得到唯一UBO的名称,即" matries_xy">
我在OpenGL 4.6, c++ 20, MSVC 2022/17.3.6, Windows Pro10, x64, MFC
我没有定义函数;一旦我添加,一切都很好
glGetProgramResourceName = (PFNGLGETPROGRAMRESOURCENAMEPROC)wglGetProcAddress("glGetProgramResourceName");