mirror of
https://github.com/open-goal/jak-project
synced 2026-09-09 20:21:28 -04:00
revamp the gfx+display systems a bit (#739)
* revamp gfx and display systems a bit * Use some fancy c++ pointers instead of just raw pointers * Tidy some things up. * clang * clang 2 * fixes * fixesss * error detection when making display
This commit is contained in:
+48
-31
@@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* @file gfx.cpp
|
||||
* Graphics component for the runtime. Handles some low-level routines.
|
||||
* Graphics component for the runtime. Abstraction layer for the main graphics routines.
|
||||
*/
|
||||
|
||||
#include "gfx.h"
|
||||
@@ -9,62 +9,79 @@
|
||||
#include "game/runtime.h"
|
||||
#include "display.h"
|
||||
|
||||
#include "opengl.h"
|
||||
#include "pipelines/opengl.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// initializes a gfx settings.
|
||||
// TODO save and load from file
|
||||
void InitSettings(GfxSettings& settings) {
|
||||
// use opengl by default for now
|
||||
settings.renderer = Gfx::GetRenderer(GfxPipeline::OpenGL); // Gfx::renderers[0];
|
||||
|
||||
// 1 screen update per frame
|
||||
settings.vsync = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
void GlfwErrorCallback(int err, const char* msg) {
|
||||
lg::error("GLFW ERR {}: " + std::string(msg), err);
|
||||
GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP];
|
||||
|
||||
GfxSettings g_settings;
|
||||
// const std::vector<const GfxRendererModule*> renderers = {&moduleOpenGL};
|
||||
|
||||
const GfxRendererModule* GetRenderer(GfxPipeline pipeline) {
|
||||
switch (pipeline) {
|
||||
case GfxPipeline::Invalid:
|
||||
lg::error("Requested invalid graphics pipeline!");
|
||||
return NULL;
|
||||
break;
|
||||
case GfxPipeline::OpenGL:
|
||||
return &moduleOpenGL;
|
||||
default:
|
||||
lg::error("Unknown graphics pipeline {}", (u64)pipeline);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
u32 Init() {
|
||||
if (glfwSetErrorCallback(GlfwErrorCallback) != NULL) {
|
||||
lg::warn("glfwSetErrorCallback has been re-set!");
|
||||
}
|
||||
lg::info("GFX Init");
|
||||
// initialize settings
|
||||
InitSettings(g_settings);
|
||||
|
||||
if (!glfwInit()) {
|
||||
lg::error("glfwInit error");
|
||||
if (g_settings.renderer->init()) {
|
||||
lg::error("Gfx::Init error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_main_thread_id != std::this_thread::get_id()) {
|
||||
lg::warn("ran Gfx::Init outside main thread. Init display elsewhere?");
|
||||
} else {
|
||||
Display::InitDisplay(640, 480, "testy", Display::display);
|
||||
Display::InitMainDisplay(640, 480, "testy", g_settings);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Loop(std::function<bool()> f) {
|
||||
lg::info("GFX Loop");
|
||||
while (f()) {
|
||||
// run display-specific things
|
||||
if (Display::display) {
|
||||
// check if we have a display
|
||||
if (Display::GetMainDisplay()) {
|
||||
// lg::debug("run display");
|
||||
glfwMakeContextCurrent(Display::display);
|
||||
|
||||
// render graphics
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(Display::display);
|
||||
|
||||
// poll events TODO integrate input with cpad
|
||||
glfwPollEvents();
|
||||
|
||||
// exit if display window was closed
|
||||
if (glfwWindowShouldClose(Display::display)) {
|
||||
// Display::KillDisplay(Display::display);
|
||||
MasterExit = 2;
|
||||
}
|
||||
Display::GetMainDisplay()->render_graphics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 Exit() {
|
||||
lg::debug("gfx exit");
|
||||
Display::KillDisplay(Display::display);
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(NULL);
|
||||
lg::info("GFX Exit");
|
||||
Display::KillDisplay(Display::GetMainDisplay());
|
||||
g_settings.renderer->exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user