From f9dffcd1b08892d7c4053ce384ef609f7c5daa8f Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Tue, 18 Oct 2022 11:45:33 +0100
Subject: [PATCH] cleanup rendering code a little

---
 demo/data/packs/rollball/scene.yml | 65 ------------------------------
 fggl/gfx/ogl/renderer.cpp          | 15 +++----
 fggl/gfx/ogl4/setup.cpp            |  2 +-
 include/fggl/gfx/ogl/renderer.hpp  |  6 ++-
 4 files changed, 13 insertions(+), 75 deletions(-)
 delete mode 100644 demo/data/packs/rollball/scene.yml

diff --git a/demo/data/packs/rollball/scene.yml b/demo/data/packs/rollball/scene.yml
deleted file mode 100644
index 7746947..0000000
--- a/demo/data/packs/rollball/scene.yml
+++ /dev/null
@@ -1,65 +0,0 @@
----
-# This currently isn't functional, it's an experiment in how this
-# might be defined in a user-friendly(ish) way.
-
-prefabs:
-  wallX:
-    transform:
-    staticMesh:
-      pipeline: phong
-      shape: # TODO
-    rigidBody:
-      type: static
-      shape:
-        type: box
-        extents: [0.5, 2.5, 20.5]
-  wallZ:
-    transform:
-    staticMesh:
-      pipeline: phong
-    rigidBody:
-      type: static
-      shape:
-        type: box
-        extents: [39.0, 2.5, 0.5]
-    floor:
-      transform:
-      staticMesh:
-        pipeline: phong
-        shape: # TODO
-      rigidBody:
-        type: static
-        shape: box
-        extents: [20, 0.5, 20.0]
-    player:
-      transform:
-      rigidBody:
-        mass: 1
-        shape:
-          type: sphere
-          extents: [0.5, 0.5, 0.5]
-      dynamics:
-      staticMesh:
-        pipeline: phong
-        shape: # TODO
-    collectable:
-      transform:
-      staticMesh:
-        shader: phong
-        shape: # TODO
-      callbacks:
-scene:
-  entities:
-    - prefab: wallX
-      transform:
-        origin: [20, 0, 0]
-    - prefab: wallX
-      transform:
-        origin: [-20, 0, 0]
-    - prefab: wallZ
-      transform: [0, 0, -20]
-    - prefab: wallZ
-      transform: [0, 0, 20]
-    - prefab: floor
-      transform: [0, -2.5, 0]
-    - prefab: player
\ No newline at end of file
diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index 8a9b1fe..d1d024c 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -92,7 +92,7 @@ PRAGMA_DIAGNOSTIC_PUSH
 
 constexpr const char *OGL_LOG_FMT{"[GL] {}, {}: [{}]: {}"};
 
-void static GLAPIENTRY fggl_ogl_to_spdlog(GLenum source,
+void static GLAPIENTRY fggl_ogl_log(GLenum source,
 										  GLenum type,
 										  unsigned int msgId,
 										  GLenum severity,
@@ -139,13 +139,14 @@ namespace fggl::gfx {
 	using data::Mesh2D;
 	using data::Vertex2D;
 
-	OpenGL4Backend::OpenGL4Backend(data::Storage *storage, gui::FontLibrary *fonts, assets::AssetManager *assets)
+	OpenGL4Backend::OpenGL4Backend(data::Storage *storage, gui::FontLibrary *fonts, assets::AssetManager *assets, GlFunctionLoader loader)
 		: fggl::gfx::Graphics(), m_canvasPipeline(nullptr), m_storage(storage) {
-		// initialise GLEW, or fail
-		// FIXME this binds the graphics stack to GLFW :'(
-		int version = gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
+
+		// load OpenGL context, or fail.
+		int version = gladLoadGLLoader(loader);
 		if (version == 0) {
-			printf("Failed to initialize OpenGL context\n");
+			debug::error("Failed to initialize OpenGL context\n");
+			return;
 		}
 
 		// OpenGL debug Support
@@ -155,7 +156,7 @@ namespace fggl::gfx {
 			debug::info("enabling OpenGL debug output");
 			glEnable(GL_DEBUG_OUTPUT);
 			glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
-			glDebugMessageCallback(fggl_ogl_to_spdlog, nullptr);
+			glDebugMessageCallback(fggl_ogl_log, nullptr);
 			glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
 		}
 
diff --git a/fggl/gfx/ogl4/setup.cpp b/fggl/gfx/ogl4/setup.cpp
index ba1a948..85fbde7 100644
--- a/fggl/gfx/ogl4/setup.cpp
+++ b/fggl/gfx/ogl4/setup.cpp
@@ -21,7 +21,7 @@
 namespace fggl::gfx::ogl4 {
 
 	Graphics *WindowGraphics::create(display::Window &window) {
-		return new OpenGL4Backend(m_storage, m_fonts, m_assets);
+		return new OpenGL4Backend(m_storage, m_fonts, m_assets, (GlFunctionLoader)glfwGetProcAddress);
 	}
 
 }
\ No newline at end of file
diff --git a/include/fggl/gfx/ogl/renderer.hpp b/include/fggl/gfx/ogl/renderer.hpp
index fd88e2d..c0d8d06 100644
--- a/include/fggl/gfx/ogl/renderer.hpp
+++ b/include/fggl/gfx/ogl/renderer.hpp
@@ -30,6 +30,8 @@
 
 namespace fggl::gfx {
 
+	using GlFunctionLoader = GLADloadproc;
+
 	enum GlRenderType {
 		triangles = GL_TRIANGLES,
 		triangle_strip = GL_TRIANGLE_STRIP
@@ -55,7 +57,7 @@ namespace fggl::gfx {
 	 */
 	class OpenGL4Backend : public Graphics {
 		public:
-			explicit OpenGL4Backend(data::Storage *storage, gui::FontLibrary *fonts, assets::AssetManager *assets);
+			explicit OpenGL4Backend(data::Storage *storage, gui::FontLibrary *fonts, assets::AssetManager *assets, GlFunctionLoader loader);
 			~OpenGL4Backend() override = default;
 
 			// copy bad
@@ -96,7 +98,7 @@ namespace fggl::gfx {
 			/**
 			 * Get the 2D canvas bounds.
 			 *
-			 * @return
+			 * @return the canvas bounds
 			 */
 			inline Bounds canvasBounds() override {
 				return m_canvasRenderer->bounds();
-- 
GitLab