diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index 034f5684..3c6035c7 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -19,7 +19,6 @@ endif() target_link_libraries( NostalgiaCore PUBLIC - Keel Turbine ) diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 1d7c16ab..72e1640f 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -19,10 +19,8 @@ class Context; } namespace nostalgia::core::gl { +void drawMainView(core::Context*, ox::Size const&) noexcept; void drawMainView(core::Context*) noexcept; -void setRenderSize(core::Context*, int width, int height) noexcept; -ox::Size getRenderSize(core::Context*) noexcept; -void clearRenderSize(core::Context *ctx) noexcept; } namespace nostalgia::core { @@ -57,10 +55,8 @@ class Context { unsigned spriteSize, unsigned flipX) noexcept; friend void hideSprite(Context *ctx, unsigned idx) noexcept; + friend void gl::drawMainView(core::Context*, ox::Size const&) noexcept; friend void gl::drawMainView(core::Context*) noexcept; - friend void gl::setRenderSize(core::Context*, int width, int height) noexcept; - friend ox::Size gl::getRenderSize(core::Context*) noexcept; - friend void gl::clearRenderSize(core::Context *ctx) noexcept; public: turbine::Context *turbineCtx = nullptr; diff --git a/src/nostalgia/core/opengl/gfx.cpp b/src/nostalgia/core/opengl/gfx.cpp index 4c498b41..dd8a39c7 100644 --- a/src/nostalgia/core/opengl/gfx.cpp +++ b/src/nostalgia/core/opengl/gfx.cpp @@ -227,12 +227,12 @@ static void drawBackground(CBB *cbb) noexcept { glDrawElements(GL_TRIANGLES, static_cast(cbb->elements.size()), GL_UNSIGNED_INT, nullptr); } -static void drawBackgrounds(GlContext *gctx) noexcept { +static void drawBackgrounds(GlContext *gctx, ox::Size const&renderSz) noexcept { // load background shader and its uniforms glUseProgram(gctx->bgShader); const auto uniformXScale = static_cast(glGetUniformLocation(gctx->bgShader, "vXScale")); const auto uniformTileHeight = static_cast(glGetUniformLocation(gctx->bgShader, "vTileHeight")); - const auto [wi, hi] = gl::getRenderSize(gctx); + const auto [wi, hi] = renderSz; const auto wf = static_cast(wi); const auto hf = static_cast(hi); glUniform1f(uniformXScale, hf / wf); @@ -246,12 +246,12 @@ static void drawBackgrounds(GlContext *gctx) noexcept { } } -static void drawSprites(GlContext *gctx) noexcept { +static void drawSprites(GlContext *gctx, ox::Size const&renderSz) noexcept { glUseProgram(gctx->spriteShader); auto &sb = gctx->spriteBlocks; const auto uniformXScale = static_cast(glGetUniformLocation(gctx->bgShader, "vXScale")); const auto uniformTileHeight = static_cast(glGetUniformLocation(gctx->spriteShader, "vTileHeight")); - const auto [wi, hi] = gl::getRenderSize(gctx); + const auto [wi, hi] = renderSz; const auto wf = static_cast(wi); const auto hf = static_cast(hi); glUniform1f(uniformXScale, hf / wf); @@ -537,34 +537,19 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no namespace gl { -void drawMainView(core::Context *ctx) noexcept { +void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept { // clear screen glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); - const auto gctx = static_cast(ctx); - renderer::drawBackgrounds(gctx); - if (gctx->spriteBlocks.tex) { - renderer::drawSprites(gctx); + auto &gctx = static_cast(*ctx); + renderer::drawBackgrounds(&gctx, renderSz); + if (gctx.spriteBlocks.tex) { + renderer::drawSprites(&gctx, renderSz); } } -void setRenderSize(core::Context *ctx, int width, int height) noexcept { - const auto gctx = static_cast(ctx); - gctx->renderSize.emplace(width, height); -} - -void clearRenderSize(core::Context *ctx) noexcept { - const auto gctx = static_cast(ctx); - gctx->renderSize.reset(); -} - -ox::Size getRenderSize(core::Context *ctx) noexcept { - const auto gctx = static_cast(ctx); - if (gctx->renderSize.has_value()) { - return gctx->renderSize.value(); - } else { - return turbine::getScreenSize(*ctx->turbineCtx); - } +void drawMainView(core::Context *ctx) noexcept { + drawMainView(ctx, getScreenSize(*ctx->turbineCtx)); } } diff --git a/src/nostalgia/scene/studio/sceneeditorview.cpp b/src/nostalgia/scene/studio/sceneeditorview.cpp index 1121be11..5305c57a 100644 --- a/src/nostalgia/scene/studio/sceneeditorview.cpp +++ b/src/nostalgia/scene/studio/sceneeditorview.cpp @@ -23,8 +23,7 @@ void SceneEditorView::draw(int width, int height) noexcept { glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height); } glutils::bind(m_frameBuffer); - core::gl::setRenderSize(m_cctx.get(), width, height); - core::gl::drawMainView(m_cctx.get()); + core::gl::drawMainView(m_cctx.get(), {width, height}); glBindFramebuffer(GL_FRAMEBUFFER, 0); }