bool initDebugOutput() { bool Validated(true); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(&glf::debugOutput, NULL); GLuint MessageId(4); glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_FALSE); glDebugMessageControlARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageControlARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, GL_DONT_CARE, 1, &MessageId, GL_FALSE); std::string Message1("Message 1"); glDebugMessageInsertARB( GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 1, GL_DEBUG_SEVERITY_MEDIUM_ARB, GLsizei(Message1.size()), Message1.c_str()); std::string Message2("Message 2"); glDebugMessageInsertARB( GL_DEBUG_SOURCE_THIRD_PARTY_ARB, GL_DEBUG_TYPE_OTHER_ARB, 2, GL_DEBUG_SEVERITY_MEDIUM_ARB, GLsizei(Message2.size()), Message2.c_str()); glDebugMessageInsertARB( GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 2, GL_DEBUG_SEVERITY_MEDIUM_ARB, -1, "Message 3"); glDebugMessageInsertARB( GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, MessageId, GL_DEBUG_SEVERITY_MEDIUM_ARB, -1, "Message 4"); return Validated; }
void initialize() { if(!isEnabled()) { return; } if(!GLEW_ARB_debug_output) { LogWarning << "OpenGL debug output disabled"; return; } glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); // GLEW versions before 1.11.0 define GLDEBUGPROCARB with a non-const user pointer #if defined(GLEW_VERSION_4_5) glDebugMessageCallbackARB(gldebug::callback, NULL); #else glDebugMessageCallbackARB((GLDEBUGPROCARB)gldebug::callback, NULL); #endif // Forward messages with high severity level glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); // Forward messages with medium severity level glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM_ARB, 0, NULL, GL_TRUE); // Forward messages from the application glDebugMessageControlARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); std::string strInitialized("OpenGL debug output enabled"); glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 1, GL_DEBUG_SEVERITY_LOW_ARB, GLsizei(strInitialized.size()), strInitialized.c_str()); }
void Context::emitDebugMessage( DebugEventSource source, DebugEventType type, int id, DebugEventSeverity severity, const char* message ) { FatalError("emitDebugMessage() does not work properly."); glDebugMessageInsertARB( ConvertToGL(source), ConvertToGL(type), id, ConvertToGL(severity), std::strlen(message), message ); }
// Adds a third party event void VSDebugLib::addThirdPartyMessage(GLuint id, GLenum type, GLenum severity, std::string message) { glDebugMessageInsertARB(GL_DEBUG_SOURCE_THIRD_PARTY_ARB, type, id, severity, -1, message.c_str()); }
// Adds an application event void VSDebugLib::addApplicationMessage(GLuint id, GLenum type, GLenum severity, std::string message) { glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, type, id, severity, -1, message.c_str()); }
void Debug::EmitGLError(unsigned int id, char* message, int length) { glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, id, GL_DEBUG_SEVERITY_HIGH_ARB, length, message); }
void CApplication::OpenWindow(size_t iWidth, size_t iHeight, bool bFullscreen, bool bResizeable) { glfwInit(); m_bFullscreen = bFullscreen; if (HasCommandLineSwitch("--fullscreen")) m_bFullscreen = true; if (HasCommandLineSwitch("--windowed")) m_bFullscreen = false; m_iWindowWidth = iWidth; m_iWindowHeight = iHeight; glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); glfwOpenWindowHint(GLFW_WINDOW_RESIZABLE, bResizeable?GL_TRUE:GL_FALSE); if (m_bMultisampling) glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); if (HasCommandLineSwitch("--debug-gl")) { glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (!glDebugMessageCallbackARB) TMsg("Your drivers do not support GL_ARB_debug_output, so no GL debug output will be shown.\n"); } glfwOpenWindowHint(GLFW_DEPTH_BITS, 16); glfwOpenWindowHint(GLFW_RED_BITS, 8); glfwOpenWindowHint(GLFW_GREEN_BITS, 8); glfwOpenWindowHint(GLFW_BLUE_BITS, 8); glfwOpenWindowHint(GLFW_ALPHA_BITS, 8); TMsg(sprintf(tstring("Opening %dx%d %s %s window.\n"), iWidth, iHeight, bFullscreen?"fullscreen":"windowed", bResizeable?"resizeable":"fixed-size")); if (!(m_pWindow = (size_t)glfwOpenWindow(iWidth, iHeight, m_bFullscreen?GLFW_FULLSCREEN:GLFW_WINDOWED, WindowTitle().c_str(), NULL))) { glfwTerminate(); return; } int iScreenWidth; int iScreenHeight; GetScreenSize(iScreenWidth, iScreenHeight); if (!m_bFullscreen) { // The taskbar is at the bottom of the screen. Pretend the screen is smaller so the window doesn't clip down into it. // Also the window's title bar at the top takes up space. iScreenHeight -= 70; int iWindowX = (int)(iScreenWidth/2-m_iWindowWidth/2); int iWindowY = (int)(iScreenHeight/2-m_iWindowHeight/2); glfwSetWindowPos((GLFWwindow)m_pWindow, iWindowX, iWindowY); } glfwSetWindowCloseCallback(&CApplication::WindowCloseCallback); glfwSetWindowSizeCallback(&CApplication::WindowResizeCallback); glfwSetKeyCallback(&CApplication::KeyEventCallback); glfwSetCharCallback(&CApplication::CharEventCallback); glfwSetMousePosCallback(&CApplication::MouseMotionCallback); glfwSetMouseButtonCallback(&CApplication::MouseInputCallback); glfwSetScrollCallback(&CApplication::MouseWheelCallback); glfwSwapInterval( 1 ); glfwSetTime( 0.0 ); InitJoystickInput(); SetMouseCursorEnabled(true); GLenum err = gl3wInit(); if (0 != err) exit(0); DumpGLInfo(); if (glDebugMessageCallbackARB) { glDebugMessageCallbackARB(GLDebugCallback, nullptr); tstring sMessage("OpenGL Debug Output Activated"); glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, sMessage.length(), sMessage.c_str()); } glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glLineWidth(1.0); m_bIsOpen = true; m_pRenderer = CreateRenderer(); m_pRenderer->Initialize(); glgui::RootPanel()->SetSize((float)m_iWindowWidth, (float)m_iWindowHeight); }
bool validate(GLuint const & ProgramName) { bool Error = false; // Pipeline object validation { GLint Status(0); GLint LengthMax(0); glValidateProgramPipeline(PipelineName); glGetProgramPipelineiv(PipelineName, GL_VALIDATE_STATUS, &Status); glGetProgramPipelineiv(PipelineName, GL_INFO_LOG_LENGTH, &LengthMax); GLsizei LengthQuery(0); std::vector<GLchar> InfoLog(LengthMax + 1, '\0'); glGetProgramPipelineInfoLog(PipelineName, GLsizei(InfoLog.size()), &LengthQuery, &InfoLog[0]); glDebugMessageInsertARB( GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 76, GL_DEBUG_SEVERITY_LOW_ARB, LengthQuery, &InfoLog[0]); } GLint ActiveAttributeMaxLength(0); GLint ActiveAttribute(0); glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &ActiveAttributeMaxLength); glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTES, &ActiveAttribute); GLsizei AttribLength(0); GLint AttribSize(0); GLenum AttribType(0); std::vector<GLchar> AttribName(ActiveAttributeMaxLength, '\0'); for(GLint i = 0; i < ActiveAttribute; ++i) { glGetActiveAttrib(ProgramName, GLuint(i), GLsizei(ActiveAttributeMaxLength), &AttribLength, &AttribSize, &AttribType, &AttribName[0]); std::string NameString; NameString.insert(NameString.begin(), AttribName.begin(), AttribName.end()); std::vector<GLchar> NameSwap(ActiveAttributeMaxLength, '\0'); std::swap(AttribName, NameSwap); GLint AttribLocation = glGetAttribLocation(ProgramName, NameString.c_str()); vertexattrib VertexAttrib; glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &VertexAttrib.Enabled); //glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &VertexAttrib.Binding); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_SIZE, &VertexAttrib.Size); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &VertexAttrib.Stride); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_TYPE, &VertexAttrib.Type); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &VertexAttrib.Normalized); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_INTEGER, &VertexAttrib.Integer); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &VertexAttrib.Divisor); glGetVertexAttribPointerv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_POINTER, &VertexAttrib.Pointer); if(GL_VERTEX_ATTRIB_ARRAY_INTEGER == GL_TRUE) { if(!( VertexAttrib.Type == GL_INT || VertexAttrib.Type == GL_INT_VEC2 || VertexAttrib.Type == GL_INT_VEC3 || VertexAttrib.Type == GL_INT_VEC4 || VertexAttrib.Type == GL_UNSIGNED_INT || VertexAttrib.Type == GL_UNSIGNED_INT_VEC2 || VertexAttrib.Type == GL_UNSIGNED_INT_VEC3 || VertexAttrib.Type == GL_UNSIGNED_INT_VEC4)) return true; if(!( VertexAttrib.Type == GL_BYTE || VertexAttrib.Type == GL_UNSIGNED_BYTE || VertexAttrib.Type == GL_SHORT || VertexAttrib.Type == GL_UNSIGNED_SHORT || VertexAttrib.Type == GL_INT || VertexAttrib.Type == GL_UNSIGNED_INT)) return true; //if(AttribSize > 1) //GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, and GL_DOUBLE } else if(VertexAttrib.Long == GL_TRUE) // OpenGL Spec bug { if( VertexAttrib.Type == GL_DOUBLE || VertexAttrib.Type == GL_DOUBLE_VEC2 || VertexAttrib.Type == GL_DOUBLE_VEC3 || VertexAttrib.Type == GL_DOUBLE_VEC4 || VertexAttrib.Type == GL_DOUBLE_MAT2 || VertexAttrib.Type == GL_DOUBLE_MAT3 || VertexAttrib.Type == GL_DOUBLE_MAT4 || VertexAttrib.Type == GL_DOUBLE_MAT2x3 || VertexAttrib.Type == GL_DOUBLE_MAT2x4 || VertexAttrib.Type == GL_DOUBLE_MAT3x2 || VertexAttrib.Type == GL_DOUBLE_MAT3x4 || VertexAttrib.Type == GL_DOUBLE_MAT4x2 || VertexAttrib.Type == GL_DOUBLE_MAT4x3) { if(VertexAttrib.Type != GL_DOUBLE) return true; } else// if((VertexAttrib.Normalized == GL_TRUE) || (GL_VERTEX_ATTRIB_ARRAY_FLOAT == GL_TRUE)) { if(!( VertexAttrib.Type == GL_FLOAT || VertexAttrib.Type == GL_FLOAT_VEC2 || VertexAttrib.Type == GL_FLOAT_VEC3 || VertexAttrib.Type == GL_FLOAT_VEC4 || VertexAttrib.Type == GL_FLOAT_MAT2 || VertexAttrib.Type == GL_FLOAT_MAT3 || VertexAttrib.Type == GL_FLOAT_MAT4 || VertexAttrib.Type == GL_FLOAT_MAT2x3 || VertexAttrib.Type == GL_FLOAT_MAT2x4 || VertexAttrib.Type == GL_FLOAT_MAT3x2 || VertexAttrib.Type == GL_FLOAT_MAT3x4 || VertexAttrib.Type == GL_FLOAT_MAT4x2 || VertexAttrib.Type == GL_FLOAT_MAT4x3)) return true; // It could be any vertex array attribute type } } printf("glGetActiveAttrib(\n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%s)\n", i, AttribLocation, AttribLength, AttribSize, AttribType, NameString.c_str()); } return Error; }
static void GLAPIENTRY arbDebugMessageInsert(GLsizei length, const GLchar *buf) { glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, length, buf); }