gpt4 book ai didi

glsl - glGetProgramBinary 导致 GL_INVALID_OPERATION

转载 作者:行者123 更新时间:2023-12-05 00:56:18 29 4
gpt4 key购买 nike

我正在尝试从已有效编译和链接的程序中检索二进制文件。我已经通过 GL_PROGRAM_BINARY_LENGTH 收到了它的长度。该文档说有两个实例可能会发生 GL_INVALID_OPERATION - 一个失败的链接和 bufSize 小于程序的大小。我读到有些人在链接之前未能提供 GL_PROGRAM_BINARY_RETRIEVABLE_HINT 时出现此错误,但对我而言并非如此。我还验证了该程序,可以肯定...并验证了 GL_ARB_get_program_binary 受支持。

我们连接了一个 glDebugMessageCallbackARB,它提供了一些额外的信息:“生成了 GL_INVALID_OPERATION 错误。对象不是程序或着色器对象。”通过在错误消息中搜索该额外位,我一无所获。

OGL 版本 4.2,glsl 1.5。这是在带有最新驱动程序的 nVidia GeForce GTX 660 上。 Windows 7。

相关代码如下:

GLuint compileShaderBlock(GLenum type, const char* shaderCode, const int shaderSize) 
{
GLuint shaderId = 0;

if (shaderCode != NULL)
{
shaderId= glCreateShader(type);
glShaderSource(shaderId, 1, &shaderCode, &shaderSize);
glCompileShader(shaderId);
}

return shaderId;
};

static GLchar errBuff[4096];
bool validateShader(GLuint shaderID)
{
GLint compiled;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compiled);

GLsizei length = 0;

glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &length);

char* buffer = new char[length];

if (!compiled && length > 0)
{
GLsizei outputlen;
glGetShaderInfoLog(shaderID, length, &outputlen, buffer);
GLsizei size = 0;
glGetShaderSource(shaderID, 4096, &size, errBuff);
}

assert(compiled == GL_TRUE, "Shader compile error: \n%s", buffer);
delete[] buffer;

return compiled == GL_TRUE;
}

bool validateLink(GLuint programID)
{
GLint linkResult = GL_TRUE;
glGetProgramiv(programID, GL_LINK_STATUS, &linkResult);

if (linkResult == GL_FALSE)
{
GLsizei outputlen, length = 0;
glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &length);

char* buffer = new char[length];
glGetProgramInfoLog(programID, length, &outputlen, buffer);

assert(linkResult == GL_TRUE, "Program %d link error %s", programID, buffer);
delete[] buffer;
return GL_FALSE;
}

return GL_TRUE;
}

....

shader->vertexShaderId = compileShaderBlock(GL_VERTEX_SHADER, vsDataString.ToChar(), vsDataString.Length());
shader->fragmentShaderId = compileShaderBlock(GL_FRAGMENT_SHADER, fsDataString.ToChar(), fsDataString.Length());

validateShader(shader->vertexShaderId, "");
validateShader(shader->fragmentShaderId, "");

shader->programId = glCreateProgram();
glAttachShader(shader->programId, shader->vertexShaderId);
glAttachShader(shader->programId, shader->fragmentShaderId);

//Care about outputs
glBindFragDataLocation(shader->programId, 0, "outColor0");
glBindFragDataLocation(shader->programId, 1, "outColor1");
glBindFragDataLocation(shader->programId, 2, "outColor2");
glBindFragDataLocation(shader->programId, 3, "outColor3");

// let it know we plan on retrieving a binary
glProgramParameteri(shader->programId, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);

glLinkProgram(shader->programId);

... set attributes and uniforms (removing this doesn't change anything)
... do mock render (removing this doesn't change anything)

validateLink(shader->programId);

glValidateProgram((shader->programID);
GLint validateStatus;
glGetProgramiv((shader->programID, GL_VALIDATE_STATUS, &validateStatus);

glUseProgram(shader->programId);

GLint len = 0;
glGetProgramiv(shader->programId, GL_PROGRAM_BINARY_LENGTH, &len);

if (len > 0)
{
uint8* binary = new uint8[len];
GLenum binaryFormat;
**ERROR** --> glGetProgramBinary(shader->programId, len, NULL, &binaryFormat, binary);
}

我觉得这没有任何意义,是不是我遗漏了什么???

最佳答案

所以这是一个非常愚蠢的复制/粘贴错误,但它可能对将来的某人有用的可能性很小...

glGetProgramBinary 被设置为另一个 gl 函数...

关于glsl - glGetProgramBinary 导致 GL_INVALID_OPERATION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27456189/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com