From 133165ef9ba28cd9bfdcb5fd62d0c4d3aeac0191 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 31 Oct 2021 16:41:21 +0100 Subject: [PATCH] Minor cleanup, improved OpenGL error reporting. --- src/vissim.cc | 64 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/vissim.cc b/src/vissim.cc index 0991657..ad599ee 100644 --- a/src/vissim.cc +++ b/src/vissim.cc @@ -86,11 +86,46 @@ static void opengl_error_callback( GLsizei length, const GLchar* message, const void* userParam) { + const char* source_str; + switch (source) + { + case GL_DEBUG_SOURCE_API: source_str = "API"; break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: source_str = "Window System"; break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: source_str = "Shader Compiler"; break; + case GL_DEBUG_SOURCE_THIRD_PARTY: source_str = "3rd Party"; break; + case GL_DEBUG_SOURCE_APPLICATION: source_str = "Application"; break; + default: source_str = "Other"; break; + } + + const char* type_str; + switch (type) + { + case GL_DEBUG_TYPE_ERROR: type_str = "Error"; break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: type_str = "Deprecated Behaviour"; break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: type_str = "Undefined Behaviour"; break; + case GL_DEBUG_TYPE_PORTABILITY: type_str = "Portability"; break; + case GL_DEBUG_TYPE_PERFORMANCE: type_str = "Performance"; break; + case GL_DEBUG_TYPE_MARKER: type_str = "Marker"; break; + case GL_DEBUG_TYPE_PUSH_GROUP: type_str = "Push Group"; break; + case GL_DEBUG_TYPE_POP_GROUP: type_str = "Pop Group"; break; + default: type_str = "Other"; break; + } + + const char* severity_str; + switch (severity) + { + case GL_DEBUG_SEVERITY_HIGH: severity_str = "high"; break; + case GL_DEBUG_SEVERITY_MEDIUM: severity_str = "medium"; break; + case GL_DEBUG_SEVERITY_LOW: severity_str = "low"; break; + case GL_DEBUG_SEVERITY_NOTIFICATION: severity_str = "notification"; break; + default: severity_str = "unknown"; + } + gLog( - "OpenGL Error: %s type %0x%x, severity = 0x%x, message = %s", - (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), - type, - severity, + "OpenGL Error (%s, type %s, severity = %s): %s", + source_str, + type_str, + severity_str, message); } @@ -116,15 +151,15 @@ void handle_mouse() { glfwGetCursorPos(gWindow, &mouse_x, &mouse_y); if (gGuiInputState->mouseButton) { - gGuiInputState->mousedX = mouse_x - gGuiInputState->mouseX; - gGuiInputState->mousedY = mouse_y - gGuiInputState->mouseY; + gGuiInputState->mousedX = int32_t (mouse_x) - gGuiInputState->mouseX; + gGuiInputState->mousedY = int32_t (mouse_y) - gGuiInputState->mouseY; } else { gGuiInputState->mousedX = 0; gGuiInputState->mousedY = 0; } - gGuiInputState->mouseX = mouse_x; - gGuiInputState->mouseY = mouse_y; - gGuiInputState->mouseScroll = mouse_scroll_y; + gGuiInputState->mouseX = int32_t(mouse_x); + gGuiInputState->mouseY = int32_t(mouse_y); + gGuiInputState->mouseScroll = int32_t(mouse_scroll_y); gGuiInputState->mouseButton = glfwGetMouseButton(gWindow, 0) + (glfwGetMouseButton(gWindow, 1) << 1) @@ -186,8 +221,6 @@ void ShowDockspace(bool open) { } static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::TRANSLATE); -int gizmoCount = 1; -float camDistance = 8.f; void RenderGuizmoTest(srcmdbuf* cmdbuf) { srcmd rcmd; @@ -219,7 +252,7 @@ void ShowViewManip() { windowHeight); float viewManipulateRight = ImGui::GetWindowPos().x + windowWidth; - int title_height = ImGui::GetFontSize() + imgui_style.FramePadding.y * 2; + float title_height = ImGui::GetFontSize() + imgui_style.FramePadding.y * 2.f; ImVec2 window_pos = ImGui::GetWindowPos(); ImVec2 view_manip_widget_size(128, 128); @@ -254,7 +287,7 @@ void ShowTransformManip( ImVec2 window_pos = ImGui::GetWindowPos(); ImGuiStyle imgui_style = ImGui::GetStyle(); - int title_height = ImGui::GetFontSize() + imgui_style.FramePadding.y * 2; + float title_height = ImGui::GetFontSize() + imgui_style.FramePadding.y * 2.f; window_pos.x += imgui_style.WindowPadding.x; window_pos.y += imgui_style.WindowPadding.y + title_height; @@ -324,6 +357,7 @@ void ShowTransformManip( case ImGuizmo::SCALE: ImGui::InputFloat("Scale Snap", &snap[0]); break; + default: break; } ImGui::Checkbox("Bound Sizing", &boundSizing); if (boundSizing) { @@ -386,7 +420,7 @@ void DoRender() { // Update the gCameraState->mtxView const ImVec2 content_avail = ImGui::GetContentRegionAvail(); - srview_set_size(gView, content_avail.x, content_avail.y); + srview_set_size(gView, int(content_avail.x), int(content_avail.y)); float view_width = content_avail.x / 50.f; float view_height = content_avail.y / 50.f; @@ -451,7 +485,7 @@ void DoRender() { ImGui::End(); } -int main(void) { +int main() { gTimerInit(); LoggingInit();