Skip to content

Commit

Permalink
Updated the code responsible for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Isti01 committed Jan 1, 2022
1 parent 79a18d2 commit 3dc7640
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/Application/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Gui::Gui() {
const auto context = Window::instance().getContext();
if (context == nullptr) return;
std::cout << "initialized the gui" << std::endl;
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();
Expand All @@ -25,7 +24,6 @@ void Gui::finalizeFrame() {
}

Gui::~Gui() {
std::cout << "gui destroyed" << std::endl;
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
Expand Down
122 changes: 102 additions & 20 deletions src/Application/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
#include "Application.h"

Window::Window() {
std::cout << "initialized the window" << std::endl;
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
glfwSwapInterval(1);

window = glfwCreateWindow(windowWidth, windowHeight, name, nullptr, nullptr);
glfwMakeContextCurrent(window);

if (window == nullptr) {
std::cout << "Failed to create GLFW window" << std::endl;
std::cerr << "Failed to create GLFW window" << std::endl;
return;
}

if (!setupGlad()) {
std::cout << "Failed to initialize OpenGL context" << std::endl;
std::cerr << "Failed to initialize OpenGL context" << std::endl;
window = nullptr;
return;
}
Expand All @@ -29,21 +28,12 @@ Window::Window() {
setupCallbacks(window);
}

void GLAPIENTRY Window::onOpenGlMessage(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar *message,
const void *userParam) {
std::cerr << "GL CALLBACK: " << (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "") << "type = " << type
<< ", severity = " << severity << ", message = " << message << std::endl;
void Window::onWindowError(int errorCode, const char *description) {
std::cerr << "GLFW: **ERROR** error=" << errorCode << " description=" << description << std::endl;
}

void Window::onKeyEvent(GLFWwindow *window, int32_t key, int32_t scancode, int32_t action, int32_t mode) {
Application::instance().onKeyEvent(key, scancode, action, mode);
// std::cout << key << std::endl;
// if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);
}

void Window::onResized(GLFWwindow *_, int32_t width, int32_t height) {
Expand All @@ -57,7 +47,6 @@ void Window::onResized(GLFWwindow *_, int32_t width, int32_t height) {

void Window::onMouseButtonEvent(GLFWwindow *window, int32_t button, int32_t action, int32_t mods) {
Application::instance().onMouseButtonEvent(button, action, mods);
// std::cout << button << " " << action << " " << mods << std::endl;
}

void Window::setupCallbacks(GLFWwindow *window) {
Expand All @@ -66,12 +55,17 @@ void Window::setupCallbacks(GLFWwindow *window) {
glfwSetFramebufferSizeCallback(window, onResized);

glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(onOpenGlMessage, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
glfwSwapInterval(2); // note: maybe change this later

glfwSetErrorCallback(Window::onWindowError);
}

bool Window::setupGlad() {
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
std::cout << "Failed to initialize OpenGL context" << std::endl;
std::cerr << "Failed to initialize OpenGL context" << std::endl;
return false;
}

Expand All @@ -80,6 +74,7 @@ bool Window::setupGlad() {

return true;
}

void Window::update() {
glfwPollEvents();
glViewport(0, 0, windowWidth, windowHeight);
Expand All @@ -90,8 +85,95 @@ void Window::finalizeFrame() {
glfwSwapBuffers(window);
}


Window::~Window() {
std::cout << "window destroyed" << std::endl;
glfwTerminate();
}

void GLAPIENTRY Window::onOpenGlMessage(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar *message,
const void *userParam) {
if (id == 131169 || id == 131185 || id == 131218 || id == 131204) return;

std::cerr << "---------------" << std::endl;
std::cerr << "Debug message (" << id << "): " << message << std::endl;

switch (source) {
case GL_DEBUG_SOURCE_API:
std::cerr << "Source: API";
break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
std::cerr << "Source: Window System";
break;
case GL_DEBUG_SOURCE_SHADER_COMPILER:
std::cerr << "Source: Shader Compiler";
break;
case GL_DEBUG_SOURCE_THIRD_PARTY:
std::cerr << "Source: Third Party";
break;
case GL_DEBUG_SOURCE_APPLICATION:
std::cerr << "Source: Application";
break;
case GL_DEBUG_SOURCE_OTHER:
std::cerr << "Source: Other";
break;
default:
break;
}
std::cerr << std::endl;

switch (type) {
case GL_DEBUG_TYPE_ERROR:
std::cerr << "Type: Error";
break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
std::cerr << "Type: Deprecated Behaviour";
break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
std::cerr << "Type: Undefined Behaviour";
break;
case GL_DEBUG_TYPE_PORTABILITY:
std::cerr << "Type: Portability";
break;
case GL_DEBUG_TYPE_PERFORMANCE:
std::cerr << "Type: Performance";
break;
case GL_DEBUG_TYPE_MARKER:
std::cerr << "Type: Marker";
break;
case GL_DEBUG_TYPE_PUSH_GROUP:
std::cerr << "Type: Push Group";
break;
case GL_DEBUG_TYPE_POP_GROUP:
std::cerr << "Type: Pop Group";
break;
case GL_DEBUG_TYPE_OTHER:
std::cerr << "Type: Other";
break;
default:
break;
}
std::cerr << std::endl;

switch (severity) {
case GL_DEBUG_SEVERITY_HIGH:
std::cerr << "Severity: high";
break;
case GL_DEBUG_SEVERITY_MEDIUM:
std::cerr << "Severity: medium";
break;
case GL_DEBUG_SEVERITY_LOW:
std::cerr << "Severity: low";
break;
case GL_DEBUG_SEVERITY_NOTIFICATION:
std::cerr << "Severity: notification";
break;
default:
break;
}
std::cerr << std::endl;
std::cerr << std::endl;
}
1 change: 1 addition & 0 deletions src/Application/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Window {
static void onKeyEvent(GLFWwindow *window, int32_t key, int32_t scancode, int32_t action, int32_t mode);
static void onResized(GLFWwindow *window, int32_t width, int32_t height);
static void onMouseButtonEvent(GLFWwindow *window, int32_t button, int32_t action, int32_t mods);
static void onWindowError(int errorCode, const char *description);
static void onOpenGlMessage(GLenum source,
GLenum type,
GLuint id,
Expand Down

0 comments on commit 3dc7640

Please sign in to comment.