我遇到上述代码间歇性运行错误的问题。在大多数运行中,它将正确打印“成功初始化的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));
}
}
}