-2

I am trying to get the uniform block name from a shader handle using glGetProgramResourceName().

Yet it throws (0xC0000005: Access violation executing location 0x0000000000000000) on std::vector<GLchar> blockName and I can't figure out why.

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());
}

Here is my shader

#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;
}

I've tried std::string, std::vector<char>, GLchar* name = static_cast<GLchar*>(malloc(maxLength)) and all throw. I've tried appending '\0' and adjusting the size sent into function called but all throws. I am expecting to get the name of the lone UBO which is "Matrices_XY"

I'm on OpenGL 4.6, C++20, MSVC 2022/17.3.6, Windows Pro10, x64, MFC

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

-2

I did not have function defined; once I added, all is well

glGetProgramResourceName = (PFNGLGETPROGRAMRESOURCENAMEPROC)wglGetProcAddress("glGetProgramResourceName");