From e36b123b33e9198d3c9d27a6d6ac30d67b22b2ac Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 18 Mar 2021 20:19:37 -0500 Subject: [PATCH] [nostalgia/core/userland] Add bg control functions for GL --- src/nostalgia/core/userland/gfx.cpp | 1 + src/nostalgia/core/userland/gfx_opengl.cpp | 43 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/nostalgia/core/userland/gfx.cpp b/src/nostalgia/core/userland/gfx.cpp index 20741830..2b20a7e6 100644 --- a/src/nostalgia/core/userland/gfx.cpp +++ b/src/nostalgia/core/userland/gfx.cpp @@ -31,6 +31,7 @@ ox::Result readObj(Context *ctx, const ox::FileAddress &file) { ox::Error initConsole(Context *ctx) { constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; + setBgStatus(ctx, 0b0001); return loadBgTileSheet(ctx, 0, TilesheetAddr); } diff --git a/src/nostalgia/core/userland/gfx_opengl.cpp b/src/nostalgia/core/userland/gfx_opengl.cpp index 2d00edc0..de1d62c2 100644 --- a/src/nostalgia/core/userland/gfx_opengl.cpp +++ b/src/nostalgia/core/userland/gfx_opengl.cpp @@ -33,6 +33,7 @@ constexpr auto BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength; constexpr auto BgVertexEboLength = 6; struct Background: public Bufferset { + bool enabled = false; bool updated = false; std::array bgVertices; std::array bgEbos; @@ -185,6 +186,32 @@ ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) { } +uint8_t bgStatus(Context *ctx) { + const auto &id = ctx->rendererData(); + uint8_t out = 0; + for (unsigned i = 0; i < id->backgrounds.size(); ++i) { + out |= id->backgrounds[i].enabled << i; + } + return out; +} + +void setBgStatus(Context *ctx, uint32_t status) { + const auto &id = ctx->rendererData(); + for (unsigned i = 0; i < id->backgrounds.size(); ++i) { + id->backgrounds[i].enabled = (status >> i) & 1; + } +} + +bool bgStatus(Context *ctx, unsigned bg) { + const auto &id = ctx->rendererData(); + return id->backgrounds[bg].enabled; +} + +void setBgStatus(Context *ctx, unsigned bg, bool status) { + const auto &id = ctx->rendererData(); + id->backgrounds[bg].enabled = status; +} + void draw(Context *ctx) { const auto id = ctx->rendererData(); @@ -208,14 +235,16 @@ void draw(Context *ctx) { glUseProgram(id->bgShader); const auto uniformTileHeight = static_cast(glGetUniformLocation(id->bgShader, "vTileHeight")); for (auto &bg : id->backgrounds) { - glBindVertexArray(bg.vao); - if (bg.updated) { - bg.updated = false; - renderer::sendVbo(bg); + if (bg.enabled) { + glBindVertexArray(bg.vao); + if (bg.updated) { + bg.updated = false; + renderer::sendVbo(bg); + } + glBindTexture(GL_TEXTURE_2D, bg.tex); + glUniform1f(uniformTileHeight, 1.0f / static_cast(bg.tex.height / 8)); + glDrawElements(GL_TRIANGLES, bg.bgEbos.size(), GL_UNSIGNED_INT, 0); } - glBindTexture(GL_TEXTURE_2D, bg.tex); - glUniform1f(uniformTileHeight, 1.0f / static_cast(bg.tex.height / 8)); - glDrawElements(GL_TRIANGLES, bg.bgEbos.size(), GL_UNSIGNED_INT, 0); } }