[nostalgia/core] Make Context definition private
This commit is contained in:
parent
8804819e17
commit
9a80196fa6
@ -15,19 +15,15 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
// User Input Output
|
class Context;
|
||||||
class Context {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Context() noexcept = default;
|
|
||||||
Context(Context &other) noexcept = delete;
|
|
||||||
Context(Context const&other) noexcept = delete;
|
|
||||||
Context(Context const&&other) noexcept = delete;
|
|
||||||
virtual ~Context() noexcept = default;
|
|
||||||
|
|
||||||
|
struct ContextDeleter {
|
||||||
|
void operator()(Context *p) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
using ContextUPtr = ox::UPtr<Context, ContextDeleter>;
|
||||||
|
|
||||||
|
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,15 +8,19 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
GbaContext::GbaContext(turbine::Context &tctx) noexcept: turbineCtx(tctx) {
|
void ContextDeleter::operator()(Context *p) noexcept {
|
||||||
|
ox::safeDelete(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
Context::Context(turbine::Context &tctx) noexcept: turbineCtx(tctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<GbaContext>(tctx);
|
auto ctx = ox::make_unique<Context>(tctx);
|
||||||
oxReturnError(initGfx(*ctx, params));
|
oxReturnError(initGfx(*ctx, params));
|
||||||
return ox::UPtr<Context>(std::move(ctx));
|
return ContextUPtr(std::move(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,11 +8,16 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
struct GbaContext: public core::Context {
|
class Context {
|
||||||
|
|
||||||
|
public:
|
||||||
turbine::Context &turbineCtx;
|
turbine::Context &turbineCtx;
|
||||||
|
|
||||||
explicit GbaContext(turbine::Context &tctx) noexcept;
|
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]]
|
[[nodiscard]]
|
||||||
ox::MemFS const&rom() const noexcept {
|
ox::MemFS const&rom() const noexcept {
|
||||||
|
@ -141,8 +141,7 @@ ox::Error loadBgTileSheet(
|
|||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
auto &rom = ctx.rom();
|
||||||
auto &rom = gctx.rom();
|
|
||||||
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +149,8 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
auto &rom = ctx.rom();
|
||||||
auto &rom = gctx.rom();
|
oxRequire(tsStat, ctx.rom().stat(tilesheetAddr));
|
||||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
|
||||||
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||||
GbaTileMapTarget target;
|
GbaTileMapTarget target;
|
||||||
target.pal.palette = MEM_SPRITE_PALETTE;
|
target.pal.palette = MEM_SPRITE_PALETTE;
|
||||||
@ -160,7 +158,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
|
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
|
||||||
// load external palette if available
|
// load external palette if available
|
||||||
if (paletteAddr) {
|
if (paletteAddr) {
|
||||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
oxRequire(palStat, ctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, rom.directAccess(paletteAddr));
|
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
|
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
|
||||||
}
|
}
|
||||||
@ -168,19 +166,17 @@ ox::Error loadSpriteTileSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadBgPalette(Context &ctx, unsigned, ox::FileAddress const&paletteAddr) noexcept {
|
ox::Error loadBgPalette(Context &ctx, unsigned, ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
auto &rom = ctx.rom();
|
||||||
auto &rom = gctx.rom();
|
|
||||||
GbaPaletteTarget target;
|
GbaPaletteTarget target;
|
||||||
target.palette = MEM_BG_PALETTE;
|
target.palette = MEM_BG_PALETTE;
|
||||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
oxRequire(palStat, ctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, rom.directAccess(paletteAddr));
|
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
|
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadSpritePalette(Context &ctx, unsigned cbb, ox::FileAddress const&paletteAddr) noexcept {
|
ox::Error loadSpritePalette(Context &ctx, unsigned cbb, ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
auto &rom = ctx.rom();
|
||||||
auto &rom = gctx.rom();
|
|
||||||
GbaPaletteTarget target;
|
GbaPaletteTarget target;
|
||||||
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
||||||
oxRequire(palStat, rom.stat(paletteAddr));
|
oxRequire(palStat, rom.stat(paletteAddr));
|
||||||
|
@ -6,4 +6,5 @@ target_sources(
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaCore PUBLIC
|
NostalgiaCore PUBLIC
|
||||||
GlUtils
|
GlUtils
|
||||||
|
lodepng
|
||||||
)
|
)
|
||||||
|
@ -7,19 +7,23 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
GlContext::GlContext(turbine::Context &tctx) noexcept:
|
void ContextDeleter::operator()(Context *p) noexcept {
|
||||||
|
ox::safeDelete(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
Context::Context(turbine::Context &tctx) noexcept:
|
||||||
turbineCtx(tctx),
|
turbineCtx(tctx),
|
||||||
drawer(*this) {
|
drawer(*this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GlContext::~GlContext() noexcept {
|
Context::~Context() noexcept {
|
||||||
shutdownGfx(*this);
|
shutdownGfx(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<GlContext>(tctx);
|
auto ctx = ox::make_unique<Context>(tctx);
|
||||||
oxReturnError(initGfx(*ctx, params));
|
oxReturnError(initGfx(*ctx, params));
|
||||||
return ox::UPtr<Context>(ctx.release());
|
return ContextUPtr(ctx.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
struct GlContext: public core::Context {
|
class Context {
|
||||||
|
|
||||||
|
public:
|
||||||
turbine::Context &turbineCtx;
|
turbine::Context &turbineCtx;
|
||||||
glutils::GLProgram bgShader;
|
glutils::GLProgram bgShader;
|
||||||
glutils::GLProgram spriteShader;
|
glutils::GLProgram spriteShader;
|
||||||
@ -24,8 +26,8 @@ struct GlContext: public core::Context {
|
|||||||
ox::Array<Sprite, 128> spriteStates;
|
ox::Array<Sprite, 128> spriteStates;
|
||||||
ox::Array<renderer::Background, 4> backgrounds;
|
ox::Array<renderer::Background, 4> backgrounds;
|
||||||
renderer::Drawer drawer;
|
renderer::Drawer drawer;
|
||||||
explicit GlContext(turbine::Context &tctx) noexcept;
|
explicit Context(turbine::Context &tctx) noexcept;
|
||||||
~GlContext() noexcept override;
|
~Context() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <lodepng.h>
|
||||||
|
|
||||||
#include <ox/std/array.hpp>
|
#include <ox/std/array.hpp>
|
||||||
#include <ox/std/fmt.hpp>
|
#include <ox/std/fmt.hpp>
|
||||||
#include <ox/std/vec.hpp>
|
#include <ox/std/vec.hpp>
|
||||||
@ -21,15 +23,6 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
constexpr auto Scale = 10;
|
constexpr auto Scale = 10;
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
inline GlContext &glctx(Context &ctx) noexcept {
|
|
||||||
if constexpr(ox::defines::Debug) {
|
|
||||||
return dynamic_cast<GlContext&>(ctx);
|
|
||||||
} else {
|
|
||||||
return static_cast<GlContext&>(ctx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace renderer {
|
namespace renderer {
|
||||||
|
|
||||||
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
||||||
@ -267,20 +260,20 @@ static void drawBackground(CBB &cbb) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void drawBackgrounds(
|
static void drawBackgrounds(
|
||||||
GlContext &gctx,
|
Context &ctx,
|
||||||
ox::Size const&renderSz) noexcept {
|
ox::Size const&renderSz) noexcept {
|
||||||
// load background shader and its uniforms
|
// load background shader and its uniforms
|
||||||
glUseProgram(gctx.bgShader);
|
glUseProgram(ctx.bgShader);
|
||||||
const auto uniformSrcImgSz = glGetUniformLocation(gctx.bgShader, "fSrcImgSz");
|
const auto uniformSrcImgSz = glGetUniformLocation(ctx.bgShader, "fSrcImgSz");
|
||||||
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale"));
|
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vXScale"));
|
||||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vTileHeight"));
|
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vTileHeight"));
|
||||||
const auto [wi, hi] = renderSz;
|
const auto [wi, hi] = renderSz;
|
||||||
const auto wf = static_cast<float>(wi);
|
const auto wf = static_cast<float>(wi);
|
||||||
const auto hf = static_cast<float>(hi);
|
const auto hf = static_cast<float>(hi);
|
||||||
glUniform1f(uniformXScale, hf / wf);
|
glUniform1f(uniformXScale, hf / wf);
|
||||||
for (const auto &bg : gctx.backgrounds) {
|
for (const auto &bg : ctx.backgrounds) {
|
||||||
if (bg.enabled) {
|
if (bg.enabled) {
|
||||||
auto &cbb = gctx.cbbs[bg.cbbIdx];
|
auto &cbb = ctx.cbbs[bg.cbbIdx];
|
||||||
const auto tileRows = cbb.tex.height / (TileHeight * Scale);
|
const auto tileRows = cbb.tex.height / (TileHeight * Scale);
|
||||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
||||||
glUniform2f(
|
glUniform2f(
|
||||||
@ -292,11 +285,11 @@ static void drawBackgrounds(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept {
|
static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
|
||||||
glUseProgram(gctx.spriteShader);
|
glUseProgram(ctx.spriteShader);
|
||||||
auto &sb = gctx.spriteBlocks;
|
auto &sb = ctx.spriteBlocks;
|
||||||
const auto uniformXScale = glGetUniformLocation(gctx.bgShader, "vXScale");
|
const auto uniformXScale = glGetUniformLocation(ctx.bgShader, "vXScale");
|
||||||
const auto uniformTileHeight = glGetUniformLocation(gctx.spriteShader, "vTileHeight");
|
const auto uniformTileHeight = glGetUniformLocation(ctx.spriteShader, "vTileHeight");
|
||||||
const auto [wi, hi] = renderSz;
|
const auto [wi, hi] = renderSz;
|
||||||
const auto wf = static_cast<float>(wi);
|
const auto wf = static_cast<float>(wi);
|
||||||
const auto hf = static_cast<float>(hi);
|
const auto hf = static_cast<float>(hi);
|
||||||
@ -335,31 +328,31 @@ static void loadPalette(
|
|||||||
glUniform4fv(uniformPalette, ColorCnt, palette.data());
|
glUniform4fv(uniformPalette, ColorCnt, palette.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadBgPalette(GlContext &gctx, Palette const&pal) noexcept {
|
static void loadBgPalette(Context &ctx, Palette const&pal) noexcept {
|
||||||
loadPalette(gctx.bgShader, pal);
|
loadPalette(ctx.bgShader, pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadSpritePalette(GlContext &gctx, Palette const&pal) noexcept {
|
static void loadSpritePalette(Context &ctx, Palette const&pal) noexcept {
|
||||||
loadPalette(gctx.spriteShader, pal, true);
|
loadPalette(ctx.spriteShader, pal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadBgTexture(
|
static void loadBgTexture(
|
||||||
GlContext &gctx,
|
Context &ctx,
|
||||||
uint_t cbbIdx,
|
uint_t cbbIdx,
|
||||||
const void *pixels,
|
const void *pixels,
|
||||||
int w,
|
int w,
|
||||||
int h) noexcept {
|
int h) noexcept {
|
||||||
oxTracef("nostalgia.core.gfx.gl", "loadBgTexture: { cbbIdx: {}, w: {}, h: {} }", cbbIdx, w, h);
|
oxTracef("nostalgia.core.gfx.gl", "loadBgTexture: { cbbIdx: {}, w: {}, h: {} }", cbbIdx, w, h);
|
||||||
gctx.cbbs[cbbIdx].tex = createTexture(w, h, pixels);
|
ctx.cbbs[cbbIdx].tex = createTexture(w, h, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadSpriteTexture(
|
static void loadSpriteTexture(
|
||||||
GlContext &gctx,
|
Context &ctx,
|
||||||
const void *pixels,
|
const void *pixels,
|
||||||
int w,
|
int w,
|
||||||
int h) noexcept {
|
int h) noexcept {
|
||||||
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", w, h);
|
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", w, h);
|
||||||
gctx.spriteBlocks.tex = createTexture(w, h, pixels);
|
ctx.spriteBlocks.tex = createTexture(w, h, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -373,23 +366,21 @@ ox::Error initGfx(
|
|||||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
||||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
||||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
||||||
auto &gctx = glctx(ctx);
|
oxReturnError(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(&ctx.bgShader));
|
||||||
oxReturnError(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(&gctx.bgShader));
|
|
||||||
oxReturnError(
|
oxReturnError(
|
||||||
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(&gctx.spriteShader));
|
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(&ctx.spriteShader));
|
||||||
for (auto &bg : gctx.cbbs) {
|
for (auto &bg : ctx.cbbs) {
|
||||||
initBackgroundBufferset(gctx.bgShader, bg);
|
initBackgroundBufferset(ctx.bgShader, bg);
|
||||||
}
|
}
|
||||||
initSpritesBufferset(gctx.spriteShader, gctx.spriteBlocks);
|
initSpritesBufferset(ctx.spriteShader, ctx.spriteBlocks);
|
||||||
if (initParams.glInstallDrawer) {
|
if (initParams.glInstallDrawer) {
|
||||||
turbine::gl::addDrawer(gctx.turbineCtx, &gctx.drawer);
|
turbine::gl::addDrawer(ctx.turbineCtx, &ctx.drawer);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdownGfx(Context &ctx) noexcept {
|
void shutdownGfx(Context &ctx) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
turbine::gl::removeDrawer(ctx.turbineCtx, &ctx.drawer);
|
||||||
turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TileSheetData {
|
struct TileSheetData {
|
||||||
@ -405,7 +396,6 @@ struct TileSheetData {
|
|||||||
static ox::Result<TileSheetData> loadTileSheet(
|
static ox::Result<TileSheetData> loadTileSheet(
|
||||||
Context &ctx,
|
Context &ctx,
|
||||||
CompactTileSheet const&tilesheet) noexcept {
|
CompactTileSheet const&tilesheet) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
|
||||||
const uint_t bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
|
const uint_t bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
|
||||||
const auto tiles = tilesheet.pixels.size() / bytesPerTile;
|
const auto tiles = tilesheet.pixels.size() / bytesPerTile;
|
||||||
constexpr int width = 8;
|
constexpr int width = 8;
|
||||||
@ -423,7 +413,7 @@ static ox::Result<TileSheetData> loadTileSheet(
|
|||||||
pixels[i * 2 + 1] = tilesheet.pixels[i] >> 4;
|
pixels[i * 2 + 1] = tilesheet.pixels[i] >> 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderer::loadSpriteTexture(gctx, pixels.data(), width, height);
|
renderer::loadSpriteTexture(ctx, pixels.data(), width, height);
|
||||||
return TileSheetData{std::move(pixels), width, height};
|
return TileSheetData{std::move(pixels), width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,8 +422,7 @@ ox::Error loadBgTileSheet(
|
|||||||
uint_t cbb,
|
uint_t cbb,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
auto &kctx = keelCtx(ctx.turbineCtx);
|
||||||
auto &kctx = keelCtx(gctx.turbineCtx);
|
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
oxRequire(tsd, loadTileSheet(ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
||||||
@ -443,8 +432,8 @@ ox::Error loadBgTileSheet(
|
|||||||
.height = t.height * Scale,
|
.height = t.height * Scale,
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
renderer::loadBgTexture(ctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
||||||
renderer::loadBgPalette(gctx, *palette);
|
renderer::loadBgPalette(ctx, *palette);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,13 +441,12 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
auto &kctx = keelCtx(ctx.turbineCtx);
|
||||||
auto &kctx = keelCtx(gctx.turbineCtx);
|
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||||
renderer::loadSpriteTexture(gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
renderer::loadSpriteTexture(ctx, tsd.pixels.data(), tsd.width, tsd.height);
|
||||||
renderer::loadSpritePalette(gctx, *palette);
|
renderer::loadSpritePalette(ctx, *palette);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,52 +471,45 @@ void puts(Context &ctx, int column, int row, ox::CRStringView str) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setBgCbb(Context &ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
|
void setBgCbb(Context &ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
auto &bg = ctx.backgrounds[bgIdx];
|
||||||
auto &bg = gctx.backgrounds[bgIdx];
|
|
||||||
bg.cbbIdx = cbbIdx;
|
bg.cbbIdx = cbbIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t bgStatus(Context &ctx) noexcept {
|
uint8_t bgStatus(Context &ctx) noexcept {
|
||||||
auto const&gctx = glctx(ctx);
|
|
||||||
uint8_t out = 0;
|
uint8_t out = 0;
|
||||||
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) {
|
for (uint_t i = 0; i < ctx.cbbs.size(); ++i) {
|
||||||
out |= static_cast<uint8_t>(static_cast<uint_t>(gctx.backgrounds[i].enabled) << i);
|
out |= static_cast<uint8_t>(static_cast<uint_t>(ctx.backgrounds[i].enabled) << i);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgStatus(Context &ctx, uint32_t status) noexcept {
|
void setBgStatus(Context &ctx, uint32_t status) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
for (uint_t i = 0; i < ctx.cbbs.size(); ++i) {
|
||||||
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) {
|
ctx.backgrounds[i].enabled = (status >> i) & 1;
|
||||||
gctx.backgrounds[i].enabled = (status >> i) & 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bgStatus(Context &ctx, uint_t bg) noexcept {
|
bool bgStatus(Context &ctx, uint_t bg) noexcept {
|
||||||
auto const&gctx = glctx(ctx);
|
return ctx.backgrounds[bg].enabled;
|
||||||
return gctx.backgrounds[bg].enabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgStatus(Context &ctx, uint_t bg, bool status) noexcept {
|
void setBgStatus(Context &ctx, uint_t bg, bool status) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
ctx.backgrounds[bg].enabled = status;
|
||||||
gctx.backgrounds[bg].enabled = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void clearTileLayer(Context &ctx, uint_t bgIdx) noexcept {
|
void clearTileLayer(Context &ctx, uint_t bgIdx) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
auto &bg = ctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||||
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
|
||||||
initBackgroundBufferObjects(bg);
|
initBackgroundBufferObjects(bg);
|
||||||
bg.updated = true;
|
bg.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hideSprite(Context &ctx, uint_t idx) noexcept {
|
void hideSprite(Context &ctx, uint_t idx) noexcept {
|
||||||
auto &gctx = glctx(ctx);
|
auto vbo = &ctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||||
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
auto ebo = &ctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||||
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
|
||||||
renderer::setSpriteBufferObject(
|
renderer::setSpriteBufferObject(
|
||||||
idx * renderer::SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo);
|
idx * renderer::SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo);
|
||||||
gctx.spriteBlocks.updated = true;
|
ctx.spriteBlocks.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSprite(
|
void setSprite(
|
||||||
@ -563,14 +544,13 @@ void setSprite(
|
|||||||
const auto dim = dimensions[(spriteShape << 2) | spriteSize];
|
const auto dim = dimensions[(spriteShape << 2) | spriteSize];
|
||||||
const auto uX = static_cast<int>(x) % 255;
|
const auto uX = static_cast<int>(x) % 255;
|
||||||
const auto uY = static_cast<int>(y + 8) % 255 - 8;
|
const auto uY = static_cast<int>(y + 8) % 255 - 8;
|
||||||
auto &gctx = glctx(ctx);
|
|
||||||
auto i = 0u;
|
auto i = 0u;
|
||||||
const auto set = [&](int xIt, int yIt) {
|
const auto set = [&](int xIt, int yIt) {
|
||||||
const auto fX = static_cast<float>(uX + xIt * 8) / 8;
|
const auto fX = static_cast<float>(uX + xIt * 8) / 8;
|
||||||
const auto fY = static_cast<float>(uY + yIt * 8) / 8;
|
const auto fY = static_cast<float>(uY + yIt * 8) / 8;
|
||||||
const auto cidx = idx + i;
|
const auto cidx = idx + i;
|
||||||
auto vbo = &gctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
auto vbo = &ctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
||||||
auto ebo = &gctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
auto ebo = &ctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
||||||
renderer::setSpriteBufferObject(
|
renderer::setSpriteBufferObject(
|
||||||
cidx * renderer::SpriteVertexVboRows,
|
cidx * renderer::SpriteVertexVboRows,
|
||||||
1,
|
1,
|
||||||
@ -595,7 +575,7 @@ void setSprite(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gctx.spriteBlocks.updated = true;
|
ctx.spriteBlocks.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTile(
|
void setTile(
|
||||||
@ -608,12 +588,11 @@ void setTile(
|
|||||||
"nostalgia.core.gfx.setTile",
|
"nostalgia.core.gfx.setTile",
|
||||||
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
||||||
bgIdx, column, row, tile);
|
bgIdx, column, row, tile);
|
||||||
auto &gctx = glctx(ctx);
|
|
||||||
const auto z = static_cast<uint_t>(bgIdx);
|
const auto z = static_cast<uint_t>(bgIdx);
|
||||||
const auto y = static_cast<uint_t>(row);
|
const auto y = static_cast<uint_t>(row);
|
||||||
const auto x = static_cast<uint_t>(column);
|
const auto x = static_cast<uint_t>(column);
|
||||||
const auto i = renderer::bgVertexRow(x, y);
|
const auto i = renderer::bgVertexRow(x, y);
|
||||||
auto &bg = gctx.cbbs[z];
|
auto &bg = ctx.cbbs[z];
|
||||||
const auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
const auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
||||||
const auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
const auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
||||||
renderer::setTileBufferObject(
|
renderer::setTileBufferObject(
|
||||||
@ -631,10 +610,9 @@ namespace gl {
|
|||||||
void draw(core::Context &ctx, ox::Size const&renderSz) noexcept {
|
void draw(core::Context &ctx, ox::Size const&renderSz) noexcept {
|
||||||
glViewport(0, 0, renderSz.width, renderSz.height);
|
glViewport(0, 0, renderSz.width, renderSz.height);
|
||||||
glutils::clearScreen();
|
glutils::clearScreen();
|
||||||
auto &gctx = glctx(ctx);
|
renderer::drawBackgrounds(ctx, renderSz);
|
||||||
renderer::drawBackgrounds(gctx, renderSz);
|
if (ctx.spriteBlocks.tex) {
|
||||||
if (gctx.spriteBlocks.tex) {
|
renderer::drawSprites(ctx, renderSz);
|
||||||
renderer::drawSprites(gctx, renderSz);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace nostalgia::scene {
|
|||||||
class SceneEditorView {
|
class SceneEditorView {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ox::UPtr<core::Context> m_cctx;
|
core::ContextUPtr m_cctx;
|
||||||
SceneStatic const&m_sceneStatic;
|
SceneStatic const&m_sceneStatic;
|
||||||
Scene m_scene;
|
Scene m_scene;
|
||||||
glutils::FrameBuffer m_frameBuffer;
|
glutils::FrameBuffer m_frameBuffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user