奇怪的 OpenGL 块
我遇到一个问题,上面的代码间歇性地运行不正确。在大多数运行中,它将正确打印“成功初始化 OpenGL 设备”。但是,有时我只得到“L”成功初始化 GLEW。”然后应用程序停止/挂起/死锁。我不明白是什么导致了这种情况,是否有任何 OpenGL 调用在任何情况下都会阻塞?
if (glewInit() != GLEW_OK)
BOOST_THROW_EXCEPTION(ogl_exception() << msg_info("Failed to initialize GLEW."));
if(!GLEW_VERSION_3_0)
LOG(warning) << "Missing OpenGL 3.0 support.";
LOG(info) << L"Successfully initialized GLEW.";
GL(glGenFramebuffers(1, &fbo_));
GL(glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo_));
GL(glReadBuffer(GL_COLOR_ATTACHMENT0_EXT));
GL(glDisable(GL_MULTISAMPLE_ARB));
LOG(info) << L"Successfully initialized OpenGL Device.";
GL 只是一个宏调用并检查glGetError()
。
void GLCheckError(const std::string& expr, const std::string& File, unsigned int Line);
#define GL_EXPR_STR(expr) #expr
#define GL(expr) \
if(false){}else \
{ \
(expr); \
GLCheckError(GL_EXPR_STR(expr), __FILE__, __LINE__);\
}
void GLCheckError(const std::string& expr, const std::string& file, unsigned int line)
{
// Get the last error
GLenum ErrorCode = glGetError();
if (ErrorCode != GL_NO_ERROR)
{
// Decode the error code
switch (ErrorCode)
{
case GL_INVALID_ENUM :
BOOST_THROW_EXCEPTION(ogl_invalid_enum()
<< msg_info("an unacceptable value has been specified for an enumerated argument")
<< errorstr("GL_INVALID_ENUM")
<< line_info(line)
<< source_info(file));
case GL_INVALID_VALUE :
BOOST_THROW_EXCEPTION(ogl_invalid_value()
<< msg_info("a numeric argument is out of range")
<< errorstr("GL_INVALID_VALUE")
<< line_info(line)
<< source_info(file));
case GL_INVALID_OPERATION :
BOOST_THROW_EXCEPTION(ogl_invalid_operation()
<< msg_info("the specified operation is not allowed in the current state")
<< errorstr("GL_INVALID_OPERATION")
<< line_info(line)
<< source_info(file));
case GL_STACK_OVERFLOW :
BOOST_THROW_EXCEPTION(ogl_stack_overflow()
<< msg_info("this command would cause a stack overflow")
<< errorstr("GL_STACK_OVERFLOW")
<< line_info(line)
<< source_info(file));
case GL_STACK_UNDERFLOW :
BOOST_THROW_EXCEPTION(ogl_stack_underflow()
<< msg_info("this command would cause a stack underflow")
<< errorstr("GL_STACK_UNDERFLOW")
<< line_info(line)
<< source_info(file));
case GL_OUT_OF_MEMORY :
BOOST_THROW_EXCEPTION(ogl_out_of_memory()
<< msg_info("there is not enough memory left to execute the command")
<< errorstr("GL_OUT_OF_MEMORY")
<< line_info(line)
<< source_info(file));
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
BOOST_THROW_EXCEPTION(ogl_stack_underflow()
<< msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")
<< errorstr("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")
<< line_info(line)
<< source_info(file));
}
}
}
I have a problem where the code above intermittently runs incorrectly. In most runs it will correctly print "Successfully initialized OpenGL Device.". However, sometimes I only get "L"Successfully initialized GLEW." and then the application stops/hangs/deadlocks. I don't understand what could cause this, are any of the OpenGL calls blocking in any situation?
if (glewInit() != GLEW_OK)
BOOST_THROW_EXCEPTION(ogl_exception() << msg_info("Failed to initialize GLEW."));
if(!GLEW_VERSION_3_0)
LOG(warning) << "Missing OpenGL 3.0 support.";
LOG(info) << L"Successfully initialized GLEW.";
GL(glGenFramebuffers(1, &fbo_));
GL(glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo_));
GL(glReadBuffer(GL_COLOR_ATTACHMENT0_EXT));
GL(glDisable(GL_MULTISAMPLE_ARB));
LOG(info) << L"Successfully initialized OpenGL Device.";
GL is just a macro that calls and checks glGetError()
.
void GLCheckError(const std::string& expr, const std::string& File, unsigned int Line);
#define GL_EXPR_STR(expr) #expr
#define GL(expr) \
if(false){}else \
{ \
(expr); \
GLCheckError(GL_EXPR_STR(expr), __FILE__, __LINE__);\
}
void GLCheckError(const std::string& expr, const std::string& file, unsigned int line)
{
// Get the last error
GLenum ErrorCode = glGetError();
if (ErrorCode != GL_NO_ERROR)
{
// Decode the error code
switch (ErrorCode)
{
case GL_INVALID_ENUM :
BOOST_THROW_EXCEPTION(ogl_invalid_enum()
<< msg_info("an unacceptable value has been specified for an enumerated argument")
<< errorstr("GL_INVALID_ENUM")
<< line_info(line)
<< source_info(file));
case GL_INVALID_VALUE :
BOOST_THROW_EXCEPTION(ogl_invalid_value()
<< msg_info("a numeric argument is out of range")
<< errorstr("GL_INVALID_VALUE")
<< line_info(line)
<< source_info(file));
case GL_INVALID_OPERATION :
BOOST_THROW_EXCEPTION(ogl_invalid_operation()
<< msg_info("the specified operation is not allowed in the current state")
<< errorstr("GL_INVALID_OPERATION")
<< line_info(line)
<< source_info(file));
case GL_STACK_OVERFLOW :
BOOST_THROW_EXCEPTION(ogl_stack_overflow()
<< msg_info("this command would cause a stack overflow")
<< errorstr("GL_STACK_OVERFLOW")
<< line_info(line)
<< source_info(file));
case GL_STACK_UNDERFLOW :
BOOST_THROW_EXCEPTION(ogl_stack_underflow()
<< msg_info("this command would cause a stack underflow")
<< errorstr("GL_STACK_UNDERFLOW")
<< line_info(line)
<< source_info(file));
case GL_OUT_OF_MEMORY :
BOOST_THROW_EXCEPTION(ogl_out_of_memory()
<< msg_info("there is not enough memory left to execute the command")
<< errorstr("GL_OUT_OF_MEMORY")
<< line_info(line)
<< source_info(file));
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
BOOST_THROW_EXCEPTION(ogl_stack_underflow()
<< msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")
<< errorstr("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")
<< line_info(line)
<< source_info(file));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论