diff --git a/game/graphics/display.cpp b/game/graphics/display.cpp index 273641e2d1..a737485381 100644 --- a/game/graphics/display.cpp +++ b/game/graphics/display.cpp @@ -109,6 +109,10 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti return 0; } +void KillMainDisplay() { + KillDisplay(GetMainDisplay()); +} + void KillDisplay(std::shared_ptr display) { // lg::debug("kill display #x{:x}", (uintptr_t)display); if (!display->is_active()) { @@ -118,8 +122,8 @@ void KillDisplay(std::shared_ptr display) { if (GetMainDisplay() == display) { // killing the main display, kill all children displays too! - for (size_t i = 1; i < g_displays.size(); ++i) { - KillDisplay(g_displays.at(i)); + while (g_displays.size() > 1) { + KillDisplay(g_displays.at(1)); } } diff --git a/game/graphics/display.h b/game/graphics/display.h index da338e324d..d559ff6df2 100644 --- a/game/graphics/display.h +++ b/game/graphics/display.h @@ -33,7 +33,7 @@ class GfxDisplay { void set_renderer(GfxPipeline pipeline); void set_window(GLFWwindow* window); void set_title(const char* title); - const char* get_title() const { return m_title; } + const char* title() const { return m_title; } void render_graphics(); }; @@ -46,6 +46,7 @@ extern std::vector> g_displays; int InitMainDisplay(int width, int height, const char* title, GfxSettings& settings); void KillDisplay(std::shared_ptr display); +void KillMainDisplay(); std::shared_ptr GetMainDisplay(); diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index f266554709..0c9c830ecb 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -3,8 +3,9 @@ * Graphics component for the runtime. Abstraction layer for the main graphics routines. */ -#include "gfx.h" #include + +#include "gfx.h" #include "common/log/log.h" #include "game/runtime.h" #include "display.h" @@ -16,12 +17,18 @@ namespace { // initializes a gfx settings. // TODO save and load from file void InitSettings(GfxSettings& settings) { + // set the current settings version + settings.version = GfxSettings::CURRENT_VERSION; + // use opengl by default for now settings.renderer = Gfx::GetRenderer(GfxPipeline::OpenGL); // Gfx::renderers[0]; // 1 screen update per frame settings.vsync = 1; + // debug for now + settings.debug = true; + return; } @@ -29,8 +36,6 @@ void InitSettings(GfxSettings& settings) { namespace Gfx { -GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP]; - GfxSettings g_settings; // const std::vector renderers = {&moduleOpenGL}; @@ -53,7 +58,7 @@ u32 Init() { // initialize settings InitSettings(g_settings); - if (g_settings.renderer->init()) { + if (g_settings.renderer->init(g_settings)) { lg::error("Gfx::Init error"); return 1; } @@ -80,7 +85,7 @@ void Loop(std::function f) { u32 Exit() { lg::info("GFX Exit"); - Display::KillDisplay(Display::GetMainDisplay()); + Display::KillMainDisplay(); g_settings.renderer->exit(); return 0; } diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 985ed182c3..54e2e7c077 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -19,11 +19,11 @@ enum class GfxPipeline { Invalid = 0, OpenGL }; // module for the different rendering pipelines struct GfxRendererModule { - std::function init; + std::function init; std::function(int w, int h, const char* title, GfxSettings& settings)> make_main_display; - std::function kill_display; - std::function render_display; + std::function kill_display; + std::function render_display; std::function exit; std::function vsync; std::function sync_path; @@ -37,30 +37,18 @@ struct GfxRendererModule { // store settings related to the gfx systems struct GfxSettings { + // current version of the settings. this should be set up so that newer versions are always higher + // than older versions + static constexpr u64 CURRENT_VERSION = 0x0000'0000'00001'0001; + + u64 version; // the version of this settings struct const GfxRendererModule* renderer; // which rendering pipeline to use. - int vsync; // (temp) number of screen update per frame -}; - -// struct for a single vertex. this should in theory be renderer-agnostic -struct GfxVertex { - // x y z - float x, y, z; - - // rgba or the full u32 thing. - union { - u32 rgba; - struct { - u8 r, g, b, a; - }; - }; + bool debug; // graphics debugging }; namespace Gfx { -static constexpr int VERTEX_BUFFER_LENGTH_TEMP = 4096; -extern GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP]; - extern GfxSettings g_settings; // extern const std::vector renderers; diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 6fbc44b28d..0c5d81dcc6 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -67,7 +67,7 @@ bool HasError() { } // namespace static bool gl_inited = false; -static int gl_init() { +static int gl_init(GfxSettings& settings) { if (glfwSetErrorCallback(ErrorCallback) != NULL) { lg::warn("glfwSetErrorCallback has been re-set!"); } @@ -77,11 +77,16 @@ static int gl_init() { return 1; } - // request Debug OpenGL 3.3 Core + // request an OpenGL 3.3 Core glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - // glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // debug glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // core profile, not compat + // debug check + if (settings.debug) { + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); + } else { + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE); + } return 0; }