diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp index a2caa21e55a5640355541f91ffa6d1fd34259f8f..91e4168d4e34876e89ff00bb8157e10a98f15235 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 d11a03aa76145dc6153887ec9dad3edb935ea089..9cd584237c3c6f0a42326358abcef3f49fc665ab 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 39cb5ba84e31d3ffcbf78ce05e7d7e4ce43e6c52..20ec8e60eef14ab8ab625212161ec0401b67af4c 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 27479b922a8c7f9311474277a48b43fc60636ee0..4efd49bd66500cd4bbc834f7b7762f692f4adbd0 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