mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 14:13:45 -04:00
minor gfx updates
This commit is contained in:
@@ -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<GfxDisplay> display) {
|
||||
// lg::debug("kill display #x{:x}", (uintptr_t)display);
|
||||
if (!display->is_active()) {
|
||||
@@ -118,8 +122,8 @@ void KillDisplay(std::shared_ptr<GfxDisplay> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::shared_ptr<GfxDisplay>> g_displays;
|
||||
|
||||
int InitMainDisplay(int width, int height, const char* title, GfxSettings& settings);
|
||||
void KillDisplay(std::shared_ptr<GfxDisplay> display);
|
||||
void KillMainDisplay();
|
||||
|
||||
std::shared_ptr<GfxDisplay> GetMainDisplay();
|
||||
|
||||
|
||||
+10
-5
@@ -3,8 +3,9 @@
|
||||
* Graphics component for the runtime. Abstraction layer for the main graphics routines.
|
||||
*/
|
||||
|
||||
#include "gfx.h"
|
||||
#include <functional>
|
||||
|
||||
#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<const GfxRendererModule*> 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<bool()> f) {
|
||||
|
||||
u32 Exit() {
|
||||
lg::info("GFX Exit");
|
||||
Display::KillDisplay(Display::GetMainDisplay());
|
||||
Display::KillMainDisplay();
|
||||
g_settings.renderer->exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-21
@@ -19,11 +19,11 @@ enum class GfxPipeline { Invalid = 0, OpenGL };
|
||||
|
||||
// module for the different rendering pipelines
|
||||
struct GfxRendererModule {
|
||||
std::function<int()> init;
|
||||
std::function<int(GfxSettings&)> init;
|
||||
std::function<std::shared_ptr<GfxDisplay>(int w, int h, const char* title, GfxSettings& settings)>
|
||||
make_main_display;
|
||||
std::function<void(GfxDisplay* display)> kill_display;
|
||||
std::function<void(GfxDisplay* display)> render_display;
|
||||
std::function<void(GfxDisplay*)> kill_display;
|
||||
std::function<void(GfxDisplay*)> render_display;
|
||||
std::function<void()> exit;
|
||||
std::function<u32()> vsync;
|
||||
std::function<u32()> 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<const GfxRendererModule*> renderers;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user