[nostalgia/core] Make Context::turbineCtx private
This commit is contained in:
@@ -17,12 +17,16 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
void draw(Context *ctx) noexcept;
|
||||
namespace gl {
|
||||
|
||||
void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept;
|
||||
|
||||
}
|
||||
|
||||
namespace renderer {
|
||||
|
||||
void Drawer::draw(turbine::Context&) noexcept {
|
||||
core::draw(m_ctx);
|
||||
void Drawer::draw(turbine::Context &tctx) noexcept {
|
||||
core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx));
|
||||
}
|
||||
|
||||
constexpr ox::StringView bgvshadTmpl = R"(
|
||||
@@ -311,23 +315,23 @@ ox::Error initGfx(Context *ctx, const InitParams &initParams) noexcept {
|
||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion);
|
||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion);
|
||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion);
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx->bgShader));
|
||||
oxReturnError(glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx->spriteShader));
|
||||
for (auto &bg : gctx->cbbs) {
|
||||
initBackgroundBufferset(ctx, gctx->bgShader, &bg);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx.bgShader));
|
||||
oxReturnError(glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader));
|
||||
for (auto &bg : gctx.cbbs) {
|
||||
initBackgroundBufferset(ctx, gctx.bgShader, &bg);
|
||||
}
|
||||
gctx->drawer.m_ctx = ctx;
|
||||
gctx.drawer.m_ctx = ctx;
|
||||
if (initParams.glInstallDrawer) {
|
||||
turbine::gl::addDrawer(*ctx->turbineCtx, &gctx->drawer);
|
||||
initSpritesBufferset(ctx, gctx->spriteShader, &gctx->spriteBlocks);
|
||||
turbine::gl::addDrawer(*gctx.turbineCtx, &gctx.drawer);
|
||||
initSpritesBufferset(ctx, gctx.spriteShader, &gctx.spriteBlocks);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void shutdownGfx(Context *ctx) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
turbine::gl::removeDrawer(*ctx->turbineCtx, &gctx->drawer);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
turbine::gl::removeDrawer(*gctx.turbineCtx, &gctx.drawer);
|
||||
}
|
||||
|
||||
ox::Error initConsole(Context *ctx) noexcept {
|
||||
@@ -345,7 +349,7 @@ struct TileSheetData {
|
||||
};
|
||||
|
||||
ox::Result<TileSheetData> loadTileSheet(Context *ctx, const CompactTileSheet &tilesheet) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
const unsigned bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
|
||||
const auto tiles = tilesheet.pixels.size() / bytesPerTile;
|
||||
constexpr int width = 8;
|
||||
@@ -363,7 +367,7 @@ ox::Result<TileSheetData> loadTileSheet(Context *ctx, const CompactTileSheet &ti
|
||||
pixels[i * 2 + 1] = tilesheet.pixels[i] >> 4;
|
||||
}
|
||||
}
|
||||
renderer::loadSpriteTexture(gctx, pixels.data(), width, height);
|
||||
renderer::loadSpriteTexture(&gctx, pixels.data(), width, height);
|
||||
return TileSheetData{std::move(pixels), width, height};
|
||||
}
|
||||
|
||||
@@ -371,26 +375,26 @@ ox::Error loadBgTileSheet(Context *ctx,
|
||||
unsigned cbb,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &kctx = *ctx->turbineCtx;
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &kctx = *gctx.turbineCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
||||
renderer::loadBgPalette(gctx, *palette);
|
||||
renderer::loadBgTexture(&gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
||||
renderer::loadBgPalette(&gctx, *palette);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error loadSpriteTileSheet(Context *ctx,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &kctx = *ctx->turbineCtx;
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &kctx = *gctx.turbineCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
renderer::loadSpriteTexture(gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
||||
renderer::loadSpritePalette(gctx, *palette);
|
||||
renderer::loadSpriteTexture(&gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
||||
renderer::loadSpritePalette(&gctx, *palette);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -401,51 +405,47 @@ void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||
}
|
||||
}
|
||||
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbbIdx) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &bg = gctx->backgrounds[bgIdx];
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &bg = gctx.backgrounds[bgIdx];
|
||||
bg.cbbIdx = cbbIdx;
|
||||
}
|
||||
|
||||
uint8_t bgStatus(Context *ctx) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
const auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
uint8_t out = 0;
|
||||
for (unsigned i = 0; i < gctx->cbbs.size(); ++i) {
|
||||
out |= gctx->backgrounds[i].enabled << i;
|
||||
for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
|
||||
out |= gctx.backgrounds[i].enabled << i;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void setBgStatus(Context *ctx, uint32_t status) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
for (unsigned i = 0; i < gctx->cbbs.size(); ++i) {
|
||||
gctx->backgrounds[i].enabled = (status >> i) & 1;
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
|
||||
gctx.backgrounds[i].enabled = (status >> i) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool bgStatus(Context *ctx, unsigned bg) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
return gctx->backgrounds[bg].enabled;
|
||||
const auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
return gctx.backgrounds[bg].enabled;
|
||||
}
|
||||
|
||||
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
gctx->backgrounds[bg].enabled = status;
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
gctx.backgrounds[bg].enabled = status;
|
||||
}
|
||||
|
||||
|
||||
void draw(Context *ctx) noexcept {
|
||||
gl::drawMainView(ctx);
|
||||
}
|
||||
|
||||
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &bg = gctx->cbbs[static_cast<std::size_t>(bgIdx)];
|
||||
initBackgroundBufferObjects(ctx, &bg);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||
initBackgroundBufferObjects(&gctx, &bg);
|
||||
bg.updated = true;
|
||||
}
|
||||
|
||||
void hideSprite(Context *ctx, unsigned idx) noexcept {
|
||||
auto &gctx = *static_cast<GlContext*>(ctx);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||
renderer::setSpriteBufferObject(ctx, idx * renderer::SpriteVertexVboRows, 0,
|
||||
@@ -517,12 +517,12 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no
|
||||
"nostalgia::core::gfx::setTile",
|
||||
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
||||
bgIdx, column, row, tile);
|
||||
const auto gctx = static_cast<GlContext*>(ctx);
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
const auto z = static_cast<unsigned>(bgIdx);
|
||||
const auto y = static_cast<unsigned>(row);
|
||||
const auto x = static_cast<unsigned>(column);
|
||||
const auto i = renderer::bgVertexRow(x, y);
|
||||
auto &bg = gctx->cbbs[z];
|
||||
auto &bg = gctx.cbbs[z];
|
||||
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
||||
auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
||||
renderer::setTileBufferObject(
|
||||
@@ -545,10 +545,6 @@ void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void drawMainView(core::Context *ctx) noexcept {
|
||||
drawMainView(ctx, getScreenSize(*ctx->turbineCtx));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user