From b622c4b8cb77e64fa8a8a5baeb11ff1bd311bc53 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sun, 30 Oct 2022 16:24:35 +0000
Subject: [PATCH] cleanup unused structs

---
 fggl/gfx/ogl/renderer.cpp          | 61 ++++++++++++++++++------------
 include/fggl/data/model.hpp        | 47 +++++++++--------------
 include/fggl/gfx/ogl/renderer.hpp  | 16 --------
 include/fggl/gfx/ogl4/fallback.hpp |  6 ++-
 4 files changed, 57 insertions(+), 73 deletions(-)

diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index a2caa21..91e4168 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -152,40 +152,51 @@ namespace fggl::gfx {
 
 	static void splat_checkerboard(GLuint* memory) {
 		for (int i = 0; i < 128 * 128; ++i) {
-			GLubyte* colours = (GLubyte*)&memory[i];
-			if( i / 128 & 16 ^ i % 128 & 16 )
-        	{
-            	//Set pixel to white
-	            colours[ 0 ] = 0xFF;
-    	        colours[ 1 ] = 0xFF;
-        	    colours[ 2 ] = 0xFF;
-            	colours[ 3 ] = 0xFF;
-	        }
-    	    else
-       	 	{
-        	    //Set pixel to red
-           		colours[ 0 ] = 0xFF;
-            	colours[ 1 ] = 0x00;
-            	colours[ 2 ] = 0xFF;
-            	colours[ 3 ] = 0xFF;
+			if( i / 128 & 16 ^ i % 128 & 16 ) {
+				memory[i] = ogl4::TEX_WHITE;
+	        } else {
+				memory[i] = ogl4::TEX_CHECKER;
         	}
 		}
 	}
 
-	static void setup_fallback_texture(assets::AssetManager* assets) {
-		auto* fallback2D = new ogl::Texture(ogl::TextureType::Tex2D);
+	static ogl::Image make_solid(uint8_t width, uint8_t height, GLuint colour) {
 
-		GLuint myData[128 * 128];
-		splat_checkerboard(myData);
+		GLuint *texData = new GLuint[width * height];
+		for (int i = 0; i < width * height; ++i) {
+			texData[i] = colour;
+		}
 
-		ogl::Image image{
+		return {
 			.type = ogl::PixelFormat::UNSIGNED_BYTE,
 			.format = ogl::ImageFormat::RGBA,
-			.size = {128, 128},
-			.data = myData
+			.size = {width, height},
+			.data = texData
 		};
-		fallback2D->setData(ogl::InternalImageFormat::RedGreenBlueAlpha, image);
-		assets->set(ogl4::FALLBACK_TEX, fallback2D);
+	}
+
+	static void setup_fallback_texture(assets::AssetManager* assets) {
+		{
+			auto *fallback2D = new ogl::Texture(ogl::TextureType::Tex2D);
+			GLuint myData[128 * 128];
+			splat_checkerboard(myData);
+			ogl::Image image{
+				.type = ogl::PixelFormat::UNSIGNED_BYTE,
+				.format = ogl::ImageFormat::RGBA,
+				.size = {128, 128},
+				.data = myData
+			};
+			fallback2D->setData(ogl::InternalImageFormat::RedGreenBlueAlpha, image);
+			assets->set(ogl4::FALLBACK_TEX, fallback2D);
+		}
+
+		{
+			ogl::Image image = make_solid(128, 128, ogl4::TEX_WHITE);
+			auto *solid2D = new ogl::Texture(ogl::TextureType::Tex2D);
+			solid2D->setData(ogl::InternalImageFormat::RedGreenBlueAlpha, image);
+			assets->set(ogl4::SOLID_TEX, solid2D);
+		}
+
 	}
 
 	OpenGL4Backend::OpenGL4Backend(data::Storage *storage, gui::FontLibrary *fonts, assets::AssetManager *assets, GlFunctionLoader loader)
diff --git a/include/fggl/data/model.hpp b/include/fggl/data/model.hpp
index d11a03a..9cd5842 100644
--- a/include/fggl/data/model.hpp
+++ b/include/fggl/data/model.hpp
@@ -27,6 +27,7 @@ namespace fggl::data {
 	constexpr math::vec3 ILLEGAL_NORMAL{0.0F, 0.0F, 0.F};
 	constexpr math::vec3 DEFAULT_COLOUR{1.0F, 1.0F, 1.0F};
 
+
 	struct Vertex {
 		math::vec3 posititon;
 		math::vec3 normal = ILLEGAL_NORMAL;
@@ -43,6 +44,22 @@ namespace fggl::data {
 		}
 	};
 
+	// comparison operators
+	inline bool operator<(const Vertex &lhs, const Vertex &rhs) {
+		return std::tie(lhs.posititon, lhs.normal, lhs.colour)
+			< std::tie(rhs.posititon, rhs.normal, rhs.colour);
+	}
+
+	inline bool operator==(const Vertex &lhs, const Vertex &rhs) {
+		return lhs.posititon == rhs.posititon
+			&& lhs.colour == rhs.colour
+			&& lhs.normal == rhs.normal;
+	}
+
+	inline bool operator!=(const Vertex &lhs, const Vertex &rhs) {
+		return !(lhs == rhs);
+	}
+
 	struct Vertex2D {
 		fggl::math::vec2 position;
 		fggl::math::vec3 colour;
@@ -64,23 +81,6 @@ namespace fggl::data {
 	};
 
 
-	// comparison operators
-
-	inline bool operator<(const Vertex &lhs, const Vertex &rhs) {
-		return std::tie(lhs.posititon, lhs.normal, lhs.colour)
-			< std::tie(rhs.posititon, rhs.normal, rhs.colour);
-	}
-
-	inline bool operator==(const Vertex &lhs, const Vertex &rhs) {
-		return lhs.posititon == rhs.posititon
-			&& lhs.colour == rhs.colour
-			&& lhs.normal == rhs.normal;
-	}
-
-	inline bool operator!=(const Vertex &lhs, const Vertex &rhs) {
-		return !(lhs == rhs);
-	}
-
 	class Mesh {
 		public:
 			using IndexType = unsigned int;
@@ -172,19 +172,6 @@ namespace fggl::data {
 			mesh(aMesh), pipeline(std::move(aPipeline)) {}
 	};
 
-	class Model {
-		public:
-			Model() = default;
-			~Model() = default;
-
-			inline void append(const Mesh &mesh) {
-				m_meshes.push_back(mesh);
-			}
-
-		private:
-			std::vector<Mesh> m_meshes;
-	};
-
 }
 
 #endif
diff --git a/include/fggl/gfx/ogl/renderer.hpp b/include/fggl/gfx/ogl/renderer.hpp
index 39cb5ba..20ec8e6 100644
--- a/include/fggl/gfx/ogl/renderer.hpp
+++ b/include/fggl/gfx/ogl/renderer.hpp
@@ -32,22 +32,6 @@ namespace fggl::gfx {
 
 	using GlFunctionLoader = GLADloadproc;
 
-	enum GlRenderType {
-		triangles = GL_TRIANGLES,
-		triangle_strip = GL_TRIANGLE_STRIP
-	};
-
-	struct GlRenderToken {
-		constexpr static const char name[] = "RenderToken";
-		GLuint vao;
-		GLuint buffs[2];
-		GLuint idxOffset;
-		GLsizei idxSize;
-		GLuint pipeline;
-		GLuint restartVertex;
-		GlRenderType renderType = triangles;
-	};
-
 	/**
 	 * Class responsible for managing the OpenGL context.
 	 *
diff --git a/include/fggl/gfx/ogl4/fallback.hpp b/include/fggl/gfx/ogl4/fallback.hpp
index 27479b9..4efd49b 100644
--- a/include/fggl/gfx/ogl4/fallback.hpp
+++ b/include/fggl/gfx/ogl4/fallback.hpp
@@ -58,10 +58,12 @@ namespace fggl::gfx::ogl4 {
 			fragColour = vec4(colour.xyz, texture(tex, texPos).r);
 		})glsl";
 
-	constexpr const std::array<uint32_t, 4> TEX_WHITE{ 0xFF, 0xFF, 0xFF, 0xFF };
-	constexpr const std::array<uint32_t, 4> TEX_CHECKER{ 0xFF, 0x00, 0x00, 0xFF };
+	constexpr const GLuint TEX_WHITE = 0xFFFFFFFF;
+	constexpr const GLuint TEX_CHECKER = 0x00FF00FF; //FIXME pixel order is reversed?!
+
 	constexpr const char* FALLBACK_TEX = "FALLBACK_TEX";
 	constexpr const char* FALLBACK_MAT = "FALLBACK_MAT";
+	constexpr const char* SOLID_TEX = "SOLID_TEX";
 
 } // namespace fggl::gfx::ogl4
 
-- 
GitLab