From 7b8ddc189afe1a2ab6d236b42f08b9a521a5dacc Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 17 May 2025 17:12:25 -0500 Subject: [PATCH] [nostalgia/gfx] Consolidate implementations into single files, remove unnecessary function exports --- .../modules/gfx/include/nostalgia/gfx/gfx.hpp | 2 - src/nostalgia/modules/gfx/src/CMakeLists.txt | 40 ++++- .../modules/gfx/src/gba/CMakeLists.txt | 21 --- src/nostalgia/modules/gfx/src/gba/context.cpp | 34 ---- src/nostalgia/modules/gfx/src/gba/context.hpp | 34 ---- src/nostalgia/modules/gfx/src/gba/gfx.hpp | 11 -- src/nostalgia/modules/gfx/src/gba/panic.cpp | 58 ------- .../gfx/src/{gba/gfx.cpp => gfx-gba.cpp} | 84 ++++++++- .../src/{opengl/gfx.cpp => gfx-opengl.cpp} | 159 ++++++++++++++---- .../modules/gfx/src/opengl/CMakeLists.txt | 9 - .../modules/gfx/src/opengl/context.cpp | 40 ----- .../modules/gfx/src/opengl/context.hpp | 40 ----- src/nostalgia/modules/gfx/src/opengl/gfx.hpp | 65 ------- 13 files changed, 245 insertions(+), 352 deletions(-) delete mode 100644 src/nostalgia/modules/gfx/src/gba/CMakeLists.txt delete mode 100644 src/nostalgia/modules/gfx/src/gba/context.cpp delete mode 100644 src/nostalgia/modules/gfx/src/gba/context.hpp delete mode 100644 src/nostalgia/modules/gfx/src/gba/gfx.hpp delete mode 100644 src/nostalgia/modules/gfx/src/gba/panic.cpp rename src/nostalgia/modules/gfx/src/{gba/gfx.cpp => gfx-gba.cpp} (78%) rename src/nostalgia/modules/gfx/src/{opengl/gfx.cpp => gfx-opengl.cpp} (86%) delete mode 100644 src/nostalgia/modules/gfx/src/opengl/CMakeLists.txt delete mode 100644 src/nostalgia/modules/gfx/src/opengl/context.cpp delete mode 100644 src/nostalgia/modules/gfx/src/opengl/context.hpp delete mode 100644 src/nostalgia/modules/gfx/src/opengl/gfx.hpp diff --git a/src/nostalgia/modules/gfx/include/nostalgia/gfx/gfx.hpp b/src/nostalgia/modules/gfx/include/nostalgia/gfx/gfx.hpp index 69e00eae..8f265d8c 100644 --- a/src/nostalgia/modules/gfx/include/nostalgia/gfx/gfx.hpp +++ b/src/nostalgia/modules/gfx/include/nostalgia/gfx/gfx.hpp @@ -11,11 +11,9 @@ #include "color.hpp" #include "context.hpp" -#include "context.hpp" #include "initparams.hpp" #include "keelmodule.hpp" #include "palette.hpp" -#include "palette.hpp" #include "ptidxconv.hpp" #include "tilesheet.hpp" diff --git a/src/nostalgia/modules/gfx/src/CMakeLists.txt b/src/nostalgia/modules/gfx/src/CMakeLists.txt index 20630a7f..7c8bb5ee 100644 --- a/src/nostalgia/modules/gfx/src/CMakeLists.txt +++ b/src/nostalgia/modules/gfx/src/CMakeLists.txt @@ -4,11 +4,6 @@ add_library( tilesheet.cpp ) -add_subdirectory(gba) -if(NOT BUILDCORE_TARGET STREQUAL "gba") - add_subdirectory(opengl) -endif() - target_include_directories( NostalgiaGfx PUBLIC ../include @@ -31,3 +26,38 @@ install( LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) + +# OpenGL + +if(NOT BUILDCORE_TARGET STREQUAL "gba") + target_sources( + NostalgiaGfx PRIVATE + gfx-opengl.cpp + ) + target_link_libraries( + NostalgiaGfx PUBLIC + GlUtils + ) +endif() + +# GBA + +add_library( + NostalgiaGfx-GBA OBJECT + gfx-gba.cpp +) +target_include_directories( + NostalgiaGfx-GBA PUBLIC + ../include +) +target_link_libraries( + NostalgiaGfx-GBA PUBLIC + TeaGBA + Keel + Turbine +) + +if(BUILDCORE_TARGET STREQUAL "gba") + set_source_files_properties(gfx-gba.cpp PROPERTIES COMPILE_FLAGS -marm) + target_link_libraries(NostalgiaGfx PUBLIC NostalgiaGfx-GBA) +endif() diff --git a/src/nostalgia/modules/gfx/src/gba/CMakeLists.txt b/src/nostalgia/modules/gfx/src/gba/CMakeLists.txt deleted file mode 100644 index 24c64c5c..00000000 --- a/src/nostalgia/modules/gfx/src/gba/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -add_library( - NostalgiaGfx-GBA OBJECT - context.cpp - gfx.cpp - panic.cpp -) -target_include_directories( - NostalgiaGfx-GBA PUBLIC - ../../include -) -target_link_libraries( - NostalgiaGfx-GBA PUBLIC - TeaGBA - Keel - Turbine -) - -if(BUILDCORE_TARGET STREQUAL "gba") - set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm) - target_link_libraries(NostalgiaGfx PUBLIC NostalgiaGfx-GBA) -endif() diff --git a/src/nostalgia/modules/gfx/src/gba/context.cpp b/src/nostalgia/modules/gfx/src/gba/context.cpp deleted file mode 100644 index af1b9880..00000000 --- a/src/nostalgia/modules/gfx/src/gba/context.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include - -#include "context.hpp" - -namespace nostalgia::gfx { - -void safeDelete(Context *ctx) noexcept { - delete ctx; -} - -Context::Context(turbine::Context &tctx) noexcept: turbineCtx(tctx) { -} - -ox::Error initGfx(Context &ctx, InitParams const&) noexcept; - -ox::Result> init(turbine::Context &tctx, InitParams const¶ms) noexcept { - auto ctx = ox::make_unique(tctx); - OX_RETURN_ERROR(initGfx(*ctx, params)); - return ctx; -} - -keel::Context &keelCtx(Context &ctx) noexcept { - return turbine::keelCtx(ctx.turbineCtx); -} - -turbine::Context &turbineCtx(Context &ctx) noexcept { - return ctx.turbineCtx; -} - -} diff --git a/src/nostalgia/modules/gfx/src/gba/context.hpp b/src/nostalgia/modules/gfx/src/gba/context.hpp deleted file mode 100644 index c748d2d4..00000000 --- a/src/nostalgia/modules/gfx/src/gba/context.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::gfx { - -struct BgCbbData { - unsigned bpp = 4; -}; - -class Context { - - public: - turbine::Context &turbineCtx; - ox::Array cbbData; - - explicit Context(turbine::Context &tctx) noexcept; - Context(Context &other) noexcept = delete; - Context(Context const&other) noexcept = delete; - Context(Context const&&other) noexcept = delete; - virtual ~Context() noexcept = default; - - [[nodiscard]] - ox::MemFS const&rom() const noexcept { - return static_cast(*turbine::rom(turbineCtx)); - } - -}; - -} \ No newline at end of file diff --git a/src/nostalgia/modules/gfx/src/gba/gfx.hpp b/src/nostalgia/modules/gfx/src/gba/gfx.hpp deleted file mode 100644 index ea7aee73..00000000 --- a/src/nostalgia/modules/gfx/src/gba/gfx.hpp +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::gfx { -ox::Error initGfx(Context &ctx, InitParams const&) noexcept; -} diff --git a/src/nostalgia/modules/gfx/src/gba/panic.cpp b/src/nostalgia/modules/gfx/src/gba/panic.cpp deleted file mode 100644 index 29553d81..00000000 --- a/src/nostalgia/modules/gfx/src/gba/panic.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - - -#include -#include - -#include -#include - -#include -#include - -#include - -#include "gfx.hpp" - -#define HEAP_BEGIN (reinterpret_cast(MEM_EWRAM_BEGIN)) -#define HEAP_SIZE ((MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2) -#define HEAP_END (reinterpret_cast(MEM_EWRAM_BEGIN + HEAP_SIZE)) - -namespace ox { - -using namespace nostalgia::gfx; - -void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept { - // reset heap to make sure we have enough memory to allocate context data -OX_ALLOW_UNSAFE_BUFFERS_BEGIN - ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END); -OX_ALLOW_UNSAFE_BUFFERS_END - auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap(); - auto ctx = init(*tctx).unwrap(); - std::ignore = initGfx(*ctx, {}); - std::ignore = initConsole(*ctx); - setBgStatus(*ctx, 0, true); - clearBg(*ctx, 0); - auto const serr = ox::sfmt>("Error code: {}", static_cast(err)); - consoleWrite(*ctx, 32 + 1, 1, "SADNESS..."); - consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:"); - consoleWrite(*ctx, 32 + 2, 6, panicMsg); - if (err) { - consoleWrite(*ctx, 32 + 2, 8, serr); - } - consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM"); - // print to terminal if in mGBA - oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg); - if (err.msg) { - oxErrf("\tError Message:\t{}\n", err.msg); - } - oxErrf("\tError Code:\t{}\n", static_cast(err)); - if (err.src.file_name() != nullptr) { - oxErrf("\tError Location:\t{}:{}\n", err.src.file_name(), err.src.line()); - } - abort(); -} - -} diff --git a/src/nostalgia/modules/gfx/src/gba/gfx.cpp b/src/nostalgia/modules/gfx/src/gfx-gba.cpp similarity index 78% rename from src/nostalgia/modules/gfx/src/gba/gfx.cpp rename to src/nostalgia/modules/gfx/src/gfx-gba.cpp index e9f33f92..169933d3 100644 --- a/src/nostalgia/modules/gfx/src/gba/gfx.cpp +++ b/src/nostalgia/modules/gfx/src/gfx-gba.cpp @@ -15,15 +15,48 @@ #include #include -#include "context.hpp" - OX_ALLOW_UNSAFE_BUFFERS_BEGIN namespace nostalgia::gfx { +struct BgCbbData { + unsigned bpp = 4; +}; + +class Context { + + public: + turbine::Context &turbineCtx; + ox::Array cbbData; + + explicit Context(turbine::Context &tctx) noexcept: turbineCtx{tctx} {} + Context(Context &other) noexcept = delete; + Context(Context const&other) noexcept = delete; + Context(Context const&&other) noexcept = delete; + virtual ~Context() noexcept = default; + + [[nodiscard]] + ox::MemFS const&rom() const noexcept { + return static_cast(*turbine::rom(turbineCtx)); + } + +}; + +void safeDelete(Context *ctx) noexcept { + delete ctx; +} + +keel::Context &keelCtx(Context &ctx) noexcept { + return turbine::keelCtx(ctx.turbineCtx); +} + +turbine::Context &turbineCtx(Context &ctx) noexcept { + return ctx.turbineCtx; +} + static constexpr auto SpriteCount = 128; -ox::Error initGfx(Context&, InitParams const&) noexcept { +static ox::Error initGfx() noexcept { for (auto bgCtl = ®_BG0CTL; bgCtl <= ®_BG3CTL; bgCtl += 2) { teagba::bgSetSbb(*bgCtl, 28); } @@ -34,6 +67,12 @@ ox::Error initGfx(Context&, InitParams const&) noexcept { return {}; } +ox::Result> init(turbine::Context &tctx, InitParams const&) noexcept { + auto ctx = ox::make_unique(tctx); + OX_RETURN_ERROR(initGfx()); + return ctx; +} + ox::Error loadBgPalette( Context&, size_t const palBank, @@ -300,4 +339,43 @@ uint_t spriteCount(Context const&) noexcept { } +namespace ox { + +void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept { + using namespace nostalgia::gfx; + // reset heap to make sure we have enough memory to allocate context data + OX_ALLOW_UNSAFE_BUFFERS_BEGIN + const auto heapBegin = reinterpret_cast(MEM_EWRAM_BEGIN); + const auto heapSz = (MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2; + const auto heapEnd = reinterpret_cast(MEM_EWRAM_BEGIN + heapSz); + ox::heapmgr::initHeap(heapBegin, heapEnd); + OX_ALLOW_UNSAFE_BUFFERS_END + auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap(); + auto ctx = init(*tctx).unwrap(); + std::ignore = initGfx(); + std::ignore = initConsole(*ctx); + setBgStatus(*ctx, 0, true); + clearBg(*ctx, 0); + auto const serr = ox::sfmt>("Error code: {}", static_cast(err)); + consoleWrite(*ctx, 32 + 1, 1, "SADNESS..."); + consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:"); + consoleWrite(*ctx, 32 + 2, 6, panicMsg); + if (err) { + consoleWrite(*ctx, 32 + 2, 8, serr); + } + consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM"); + // print to terminal if in mGBA + oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg); + if (err.msg) { + oxErrf("\tError Message:\t{}\n", err.msg); + } + oxErrf("\tError Code:\t{}\n", static_cast(err)); + if (err.src.file_name() != nullptr) { + oxErrf("\tError Location:\t{}:{}\n", err.src.file_name(), err.src.line()); + } + abort(); +} + +} + OX_ALLOW_UNSAFE_BUFFERS_END diff --git a/src/nostalgia/modules/gfx/src/opengl/gfx.cpp b/src/nostalgia/modules/gfx/src/gfx-opengl.cpp similarity index 86% rename from src/nostalgia/modules/gfx/src/opengl/gfx.cpp rename to src/nostalgia/modules/gfx/src/gfx-opengl.cpp index efbe6868..182d09bc 100644 --- a/src/nostalgia/modules/gfx/src/opengl/gfx.cpp +++ b/src/nostalgia/modules/gfx/src/gfx-opengl.cpp @@ -4,7 +4,6 @@ #include #include -#include #include @@ -15,22 +14,105 @@ #include #include -#include "context.hpp" -#include "gfx.hpp" - namespace nostalgia::gfx { +namespace renderer { + +constexpr uint64_t TileRows = 128; +constexpr uint64_t TileColumns = 128; +constexpr uint64_t TileCount = TileRows * TileColumns; +constexpr uint64_t BgVertexVboRows = 4; +constexpr uint64_t BgVertexVboRowLength = 7; +constexpr uint64_t BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength; +constexpr uint64_t BgVertexEboLength = 6; +constexpr uint64_t SpriteVertexVboRows = 4; +constexpr uint64_t SpriteVertexVboRowLength = 6; +constexpr uint64_t SpriteVertexVboLength = SpriteVertexVboRows * SpriteVertexVboRowLength; +constexpr uint64_t SpriteVertexEboLength = 6; + +struct CBB: glutils::BufferSet { + bool updated = false; + ox::Array pixels; + constexpr CBB() noexcept { + vertices.resize(TileCount * BgVertexVboLength); + elements.resize(TileCount * BgVertexEboLength); + } +}; + +struct SpriteBlockset: glutils::BufferSet { + bool updated = false; + constexpr SpriteBlockset(uint64_t spriteCount, uint64_t blocksPerSprite) noexcept { + vertices.resize(spriteCount * SpriteVertexVboLength * blocksPerSprite); + elements.resize(spriteCount * SpriteVertexEboLength * blocksPerSprite); + } +}; + +struct Background { + float priority = 0; + bool enabled = false; + unsigned cbbIdx = 0; +}; + +} + +class Context { + public: + class Drawer final: public turbine::gl::Drawer { + private: + Context &m_ctx; + public: + explicit Drawer(Context &ctx) noexcept: m_ctx{ctx} {} + void draw(turbine::Context &tctx) noexcept override { + gl::draw(m_ctx, turbine::getScreenSize(tctx)); + } + }; + + turbine::Context &turbineCtx; + glutils::GLProgram bgShader; + glutils::GLProgram spriteShader; + ox::Array cbbs; + renderer::SpriteBlockset spriteBlocks; + ox::Array spriteStates; + ox::Array bgPalette; + ox::Array backgrounds; + Drawer drawer; + uint_t spriteCount = 0; + uint_t blocksPerSprite = 0; + + explicit Context(turbine::Context &tctx, InitParams const ¶ms) noexcept: + turbineCtx{tctx}, + spriteBlocks{params.glSpriteCount, params.glBlocksPerSprite}, + drawer{*this}, + spriteCount{params.glSpriteCount}, + blocksPerSprite{params.glBlocksPerSprite} { + } + Context(Context const&) = delete; + Context(Context&&) = delete; + Context &operator=(Context const&) = delete; + Context &operator=(Context&&) = delete; + ~Context() noexcept { + turbine::gl::removeDrawer(turbineCtx, &drawer); + } +}; + +void safeDelete(Context *ctx) noexcept { + delete ctx; +} + +keel::Context &keelCtx(Context &ctx) noexcept { + return turbine::keelCtx(ctx.turbineCtx); +} + +turbine::Context &turbineCtx(Context &ctx) noexcept { + return ctx.turbineCtx; +} + + namespace renderer { static constexpr auto Scale = 1; static constexpr auto PriorityScale = 0.01f; -Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {} - -void Drawer::draw(turbine::Context &tctx) noexcept { - gl::draw(m_ctx, turbine::getScreenSize(tctx)); -} - static constexpr ox::CStringView bgvshadTmpl = R"glsl( {} in vec2 vTexCoord; @@ -241,7 +323,13 @@ static void initSpritesBufferset(Context &ctx) noexcept { // in float vEnabled; auto const enabledAttr = static_cast(glGetAttribLocation(shader, "vEnabled")); glEnableVertexAttribArray(enabledAttr); - glVertexAttribPointer(enabledAttr, 1, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), nullptr); + glVertexAttribPointer( + enabledAttr, + 1, + GL_FLOAT, + GL_FALSE, + SpriteVertexVboRowLength * sizeof(float), + nullptr); // in vec3 vPosition; auto const posAttr = static_cast(glGetAttribLocation(shader, "vPosition")); glEnableVertexAttribArray(posAttr); @@ -250,8 +338,9 @@ static void initSpritesBufferset(Context &ctx) noexcept { // in vec2 vTexCoord; auto const texCoordAttr = static_cast(glGetAttribLocation(shader, "vTexCoord")); glEnableVertexAttribArray(texCoordAttr); - glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), - std::bit_cast(uintptr_t{4 * sizeof(float)})); + glVertexAttribPointer( + texCoordAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), + std::bit_cast(uintptr_t{4 * sizeof(float)})); glBindVertexArray(0); } @@ -270,7 +359,13 @@ static void initBackgroundBufferset( // vbo layout auto const posAttr = static_cast(glGetAttribLocation(shader, "vPosition")); glEnableVertexAttribArray(posAttr); - glVertexAttribPointer(posAttr, 3, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr); + glVertexAttribPointer( + posAttr, + 3, + GL_FLOAT, + GL_FALSE, + BgVertexVboRowLength * sizeof(float), + nullptr); auto const texCoordAttr = static_cast(glGetAttribLocation(shader, "vTexCoord")); glEnableVertexAttribArray(texCoordAttr); glVertexAttribPointer( @@ -300,7 +395,16 @@ static glutils::GLTexture createTexture( tex.height = h; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex.id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA, + tex.width, + tex.height, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -470,28 +574,23 @@ static void setSprite( } -ox::Error initGfx( - Context &ctx, - InitParams const&initParams) noexcept { +ox::Result> init(turbine::Context &tctx, InitParams const¶ms) noexcept { + auto ctx = ox::make_unique(tctx, params); const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, gl::GlslVersion); const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion); const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion); const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion); - OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx.bgShader)); + OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx->bgShader)); OX_RETURN_ERROR( - glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx.spriteShader)); - for (auto &cbb : ctx.cbbs) { - initBackgroundBufferset(ctx.bgShader, cbb); + glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx->spriteShader)); + for (auto &cbb : ctx->cbbs) { + initBackgroundBufferset(ctx->bgShader, cbb); } - renderer::initSpritesBufferset(ctx); - if (initParams.glInstallDrawer) { - turbine::gl::addDrawer(ctx.turbineCtx, &ctx.drawer); + renderer::initSpritesBufferset(*ctx); + if (params.glInstallDrawer) { + turbine::gl::addDrawer(ctx->turbineCtx, &ctx->drawer); } - return {}; -} - -void shutdownGfx(Context &ctx) noexcept { - turbine::gl::removeDrawer(ctx.turbineCtx, &ctx.drawer); + return ctx; } struct TileSheetData { diff --git a/src/nostalgia/modules/gfx/src/opengl/CMakeLists.txt b/src/nostalgia/modules/gfx/src/opengl/CMakeLists.txt deleted file mode 100644 index f3a72af3..00000000 --- a/src/nostalgia/modules/gfx/src/opengl/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -target_sources( - NostalgiaGfx PRIVATE - context.cpp - gfx.cpp -) -target_link_libraries( - NostalgiaGfx PUBLIC - GlUtils -) diff --git a/src/nostalgia/modules/gfx/src/opengl/context.cpp b/src/nostalgia/modules/gfx/src/opengl/context.cpp deleted file mode 100644 index 3bb6486b..00000000 --- a/src/nostalgia/modules/gfx/src/opengl/context.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include "context.hpp" -#include "gfx.hpp" - -namespace nostalgia::gfx { - -void safeDelete(Context *ctx) noexcept { - delete ctx; -} - -Context::Context(turbine::Context &tctx, InitParams const¶ms) noexcept: - turbineCtx(tctx), - spriteBlocks(params.glSpriteCount, params.glBlocksPerSprite), - drawer(*this), - spriteCount(params.glSpriteCount), - blocksPerSprite(params.glBlocksPerSprite) { -} - -Context::~Context() noexcept { - shutdownGfx(*this); -} - -ox::Result> init(turbine::Context &tctx, InitParams const¶ms) noexcept { - auto ctx = ox::make_unique(tctx, params); - OX_RETURN_ERROR(initGfx(*ctx, params)); - return ctx; -} - -keel::Context &keelCtx(Context &ctx) noexcept { - return turbine::keelCtx(ctx.turbineCtx); -} - -turbine::Context &turbineCtx(Context &ctx) noexcept { - return ctx.turbineCtx; -} - -} diff --git a/src/nostalgia/modules/gfx/src/opengl/context.hpp b/src/nostalgia/modules/gfx/src/opengl/context.hpp deleted file mode 100644 index be93bf0c..00000000 --- a/src/nostalgia/modules/gfx/src/opengl/context.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -#include - -#include -#include - -#include "gfx.hpp" - -namespace nostalgia::gfx { - -class Context { - - public: - turbine::Context &turbineCtx; - glutils::GLProgram bgShader; - glutils::GLProgram spriteShader; - ox::Array cbbs; - renderer::SpriteBlockset spriteBlocks; - ox::Array spriteStates; - ox::Array bgPalette; - ox::Array backgrounds; - renderer::Drawer drawer; - uint_t spriteCount = 0; - uint_t blocksPerSprite = 0; - explicit Context(turbine::Context &tctx, InitParams const¶ms) noexcept; - Context(Context const&) = delete; - Context(Context&&) = delete; - Context &operator=(Context const&) = delete; - Context &operator=(Context&&) = delete; - ~Context() noexcept; -}; - -} diff --git a/src/nostalgia/modules/gfx/src/opengl/gfx.hpp b/src/nostalgia/modules/gfx/src/opengl/gfx.hpp deleted file mode 100644 index b852a2c3..00000000 --- a/src/nostalgia/modules/gfx/src/opengl/gfx.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -#include - -#include - -#include - -namespace nostalgia::gfx::renderer { - -constexpr uint64_t TileRows = 128; -constexpr uint64_t TileColumns = 128; -constexpr uint64_t TileCount = TileRows * TileColumns; -constexpr uint64_t BgVertexVboRows = 4; -constexpr uint64_t BgVertexVboRowLength = 7; -constexpr uint64_t BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength; -constexpr uint64_t BgVertexEboLength = 6; -constexpr uint64_t SpriteVertexVboRows = 4; -constexpr uint64_t SpriteVertexVboRowLength = 6; -constexpr uint64_t SpriteVertexVboLength = SpriteVertexVboRows * SpriteVertexVboRowLength; -constexpr uint64_t SpriteVertexEboLength = 6; - -struct CBB: public glutils::BufferSet { - bool updated = false; - ox::Array pixels; - constexpr CBB() noexcept { - vertices.resize(TileCount * BgVertexVboLength); - elements.resize(TileCount * BgVertexEboLength); - } -}; - -struct SpriteBlockset: public glutils::BufferSet { - bool updated = false; - constexpr SpriteBlockset(uint64_t spriteCount, uint64_t blocksPerSprite) noexcept { - vertices.resize(spriteCount * SpriteVertexVboLength * blocksPerSprite); - elements.resize(spriteCount * SpriteVertexEboLength * blocksPerSprite); - } -}; - -struct Background { - float priority = 0; - bool enabled = false; - unsigned cbbIdx = 0; -}; - -class Drawer: public turbine::gl::Drawer { - private: - Context &m_ctx; - public: - explicit Drawer(Context &ctx) noexcept; - void draw(turbine::Context&) noexcept final; -}; - -} - -namespace nostalgia::gfx { -ox::Error initGfx(Context &ctx, InitParams const&) noexcept; -void shutdownGfx(Context &ctx) noexcept; -}