Change gl extension loader from gl3w to glad since gl3w was loading incorrect addresses and causing segfaults. Also add opengl context debugging output
This commit is contained in:
parent
c13bf59949
commit
96de779f55
@ -20,15 +20,7 @@
|
||||
#ifndef OUR_DICK_GRAPHICS_GL_INCLUDE_HPP
|
||||
#define OUR_DICK_GRAPHICS_GL_INCLUDE_HPP
|
||||
|
||||
//gl3w can install itself in 2 locations depending on the build environment
|
||||
//gl3w must be included before any other GL related headers
|
||||
#if __has_include(<gl3w/GL/gl3w.h>)
|
||||
#include <gl3w/GL/gl3w.h>
|
||||
#elif __has_include(<GL/gl3w.h>)
|
||||
#include <GL/gl3w.h>
|
||||
#else
|
||||
#error "Missing gl3w.h"
|
||||
#endif
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif
|
||||
|
||||
4
makefile
4
makefile
@ -40,7 +40,7 @@ ifneq ($(WINDOWS),1)
|
||||
CC::=gcc
|
||||
CXX::=g++
|
||||
LDLIBS::=
|
||||
LDFLAGS::= -lglfw -lgl3w -ldl -lm -lportaudio -lasound -lsndfile -lpthread
|
||||
LDFLAGS::= -lglfw -lglad -ldl -lm -lportaudio -lasound -lsndfile -lpthread
|
||||
STRIP::=strip
|
||||
RANLIB::=ranlib
|
||||
AR::=ar
|
||||
@ -51,7 +51,7 @@ else #windows
|
||||
MINGW_PREFIX::=x86_64-w64-mingw32-
|
||||
CC::=$(MINGW_PREFIX)gcc
|
||||
CXX::=$(MINGW_PREFIX)g++
|
||||
LDLIBS::=-lglfw -lgl3w -ldl -lm -lportaudio
|
||||
LDLIBS::=-lglfw -lglad -ldl -lm -lportaudio
|
||||
LDFLAGS::=
|
||||
STRIP::=$(MINGW_PREFIX)strip
|
||||
RANLIB::=$(MINGW_PREFIX)ranlib
|
||||
|
||||
@ -25,6 +25,101 @@
|
||||
|
||||
namespace gfx{
|
||||
|
||||
#ifdef OUR_DICK_DEBUG
|
||||
static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsigned int /*id*/, GLenum severity,
|
||||
GLsizei /*length*/, const char* message, const void* /*user_ptr*/)
|
||||
{
|
||||
const char* src = "API";
|
||||
const char* typ = "Other";
|
||||
const char* sev = "Notification";
|
||||
|
||||
#if OUR_DICK_DEBUG < 2
|
||||
if(type != GL_DEBUG_TYPE_ERROR &&
|
||||
type != GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR &&
|
||||
(severity == GL_DEBUG_SEVERITY_LOW ||
|
||||
severity == GL_DEBUG_SEVERITY_NOTIFICATION))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
switch(source){
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
src = "Window System";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
src = "Shader Compiler";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
src = "Third Party";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
src = "Application";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_OTHER:
|
||||
src = "Other";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(type){
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
typ = "Error";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
typ = "Deprecated Behaviour";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
typ = "Undefined Behaviour";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
typ = "Portability";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
typ = "Performance";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_MARKER:
|
||||
typ = "Marker";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PUSH_GROUP:
|
||||
typ = "Push Group";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_POP_GROUP:
|
||||
typ = "Pop Group";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(severity){
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
sev = "High";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
sev = "Medium";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
sev = "Low";
|
||||
break;
|
||||
}
|
||||
if(type == GL_DEBUG_TYPE_ERROR || type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR)
|
||||
debug_print_error("%s:%s:%s:%s\n", src, typ, sev, message);
|
||||
else if(severity == GL_DEBUG_SEVERITY_MEDIUM || severity == GL_DEBUG_SEVERITY_HIGH)
|
||||
debug_print_warn("%s:%s:%s:%s\n", src, typ, sev, message);
|
||||
else
|
||||
debug_print("%s:%s:%s:%s\n", src, typ, sev, message);
|
||||
}
|
||||
static void enable_opengl_debug_context(){
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
if(GLAD_GL_VERSION_4_3){
|
||||
debug_print("Debug output enabled using core opengl profile\n");
|
||||
glDebugMessageCallback(our_dick_gl_debug_output, nullptr);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
}else if(GLAD_GL_ARB_debug_output){
|
||||
debug_print("Debug output enabled using opengl extensions\n");
|
||||
glDebugMessageCallbackARB(our_dick_gl_debug_output, nullptr);
|
||||
glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int initialize_global_glfw(){
|
||||
glfw_system& system = glfw_system::instance();
|
||||
return system.status();
|
||||
@ -48,6 +143,11 @@ namespace gfx{
|
||||
|
||||
GLFWwindow* current_context = glfwGetCurrentContext();
|
||||
|
||||
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
#else
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
|
||||
@ -59,11 +159,22 @@ namespace gfx{
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||
if(!m_window){
|
||||
debug_print_error("Unable to create a GLFW window!\n");
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
make_current();
|
||||
if(gl3wInit() != GL3W_OK){
|
||||
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
|
||||
debug_print_error("Unable to initialize OpenGL context!\n");
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
|
||||
|
||||
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
|
||||
enable_opengl_debug_context();
|
||||
#endif
|
||||
set_swap_interval(m_swap_interval);
|
||||
|
||||
glfwMakeContextCurrent(current_context);
|
||||
@ -79,6 +190,11 @@ namespace gfx{
|
||||
|
||||
GLFWwindow* current_context = glfwGetCurrentContext();
|
||||
|
||||
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
#else
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, w.get_context_vmaj());
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, w.get_context_vmin());
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
@ -92,11 +208,22 @@ namespace gfx{
|
||||
|
||||
auto size = w.get_size();
|
||||
m_window = glfwCreateWindow(size.x(), size.y(), m_title, nullptr, nullptr);
|
||||
if(!m_window){
|
||||
debug_print_error("Unable to create a GLFW window!\n");
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
make_current();
|
||||
if(gl3wInit() != GL3W_OK){
|
||||
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
|
||||
debug_print_error("Unable to initialize OpenGL context!\n");
|
||||
destroy();
|
||||
}
|
||||
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
|
||||
|
||||
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
|
||||
enable_opengl_debug_context();
|
||||
#endif
|
||||
|
||||
set_swap_interval(w.m_swap_interval);
|
||||
set_pos(w.get_pos());
|
||||
set_visible(w.is_visible());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user