Compare commits

..

No commits in common. "868adae0535ac613ea6076a8e37628b73d40f09e" and "4d09eecb0d5f3952792c60d85560a9fed6a4e33e" have entirely different histories.

11 changed files with 124 additions and 141 deletions

View File

@ -57,8 +57,6 @@ typedef uint32_t uintptr_t;
#endif #endif
using uint_t = unsigned;
namespace ox { namespace ox {
/** /**

View File

@ -5,11 +5,15 @@
#pragma once #pragma once
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/point.hpp>
#include <ox/std/size.hpp> #include <ox/std/size.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include "color.hpp"
#include "context.hpp" #include "context.hpp"
#include "ptidxconv.hpp"
#include "tilesheet.hpp"
namespace nostalgia::core { namespace nostalgia::core {
@ -78,6 +82,6 @@ void setSprite(Context *ctx, Sprite const&s) noexcept;
} }
namespace nostalgia::core::gl { namespace nostalgia::core::gl {
void drawMainView(core::Context&, ox::Size const&) noexcept; void drawMainView(core::Context*, ox::Size const&) noexcept;
} }

View File

@ -13,10 +13,8 @@
#include <keel/media.hpp> #include <keel/media.hpp>
#include <turbine/turbine.hpp> #include <turbine/turbine.hpp>
#include <nostalgia/core/color.hpp>
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/tilesheet.hpp>
#include "context.hpp" #include "context.hpp"

View File

@ -12,27 +12,17 @@
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/tilesheet.hpp>
#include "context.hpp" #include "context.hpp"
namespace nostalgia::core { namespace nostalgia::core {
[[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) {}
void Drawer::draw(turbine::Context &tctx) noexcept { void Drawer::draw(turbine::Context &tctx) noexcept {
core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx)); core::gl::drawMainView(&m_ctx, turbine::getScreenSize(tctx));
} }
constexpr ox::StringView bgvshadTmpl = R"( constexpr ox::StringView bgvshadTmpl = R"(
@ -81,17 +71,17 @@ constexpr ox::StringView spritevshadTmpl = R"(
constexpr ox::StringView spritefshadTmpl = bgfshadTmpl; constexpr ox::StringView spritefshadTmpl = bgfshadTmpl;
[[nodiscard]] [[nodiscard]]
static constexpr auto bgVertexRow(uint_t x, uint_t y) noexcept { static constexpr auto bgVertexRow(unsigned x, unsigned y) noexcept {
return y * TileRows + x; return y * TileRows + x;
} }
static void setSpriteBufferObject( static void setSpriteBufferObject(
uint_t vi, unsigned vi,
float enabled, float enabled,
float x, float x,
float y, float y,
uint_t textureRow, unsigned textureRow,
uint_t flipX, unsigned flipX,
float *vbo, float *vbo,
GLuint *ebo) noexcept { GLuint *ebo) noexcept {
// don't worry, this memcpy gets optimized to something much more ideal // don't worry, this memcpy gets optimized to something much more ideal
@ -119,10 +109,10 @@ static void setSpriteBufferObject(
} }
void setTileBufferObject( void setTileBufferObject(
uint_t vi, unsigned vi,
float x, float x,
float y, float y,
uint_t textureRow, unsigned textureRow,
float *vbo, float *vbo,
GLuint *ebo) noexcept { GLuint *ebo) noexcept {
// don't worry, this memcpy gets optimized to something much more ideal // don't worry, this memcpy gets optimized to something much more ideal
@ -147,22 +137,22 @@ void setTileBufferObject(
memcpy(ebo, elms.data(), sizeof(elms)); memcpy(ebo, elms.data(), sizeof(elms));
} }
static void initSpriteBufferObjects(glutils::BufferSet &bs) noexcept { static void initSpriteBufferObjects(glutils::BufferSet *bs) noexcept {
for (auto i = 0u; i < SpriteCount; ++i) { for (auto i = 0u; i < SpriteCount; ++i) {
auto vbo = &bs.vertices[i * static_cast<std::size_t>(SpriteVertexVboLength)]; auto vbo = &bs->vertices[i * static_cast<std::size_t>(SpriteVertexVboLength)];
auto ebo = &bs.elements[i * static_cast<std::size_t>(SpriteVertexEboLength)]; auto ebo = &bs->elements[i * static_cast<std::size_t>(SpriteVertexEboLength)];
setSpriteBufferObject(i * SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo); setSpriteBufferObject(i * SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo);
} }
} }
static void initBackgroundBufferObjects(glutils::BufferSet &bg) noexcept { static void initBackgroundBufferObjects(glutils::BufferSet *bg) noexcept {
for (auto x = 0u; x < TileColumns; ++x) { for (auto x = 0u; x < TileColumns; ++x) {
for (auto y = 0u; y < TileRows; ++y) { for (auto y = 0u; y < TileRows; ++y) {
const auto i = bgVertexRow(x, y); const auto i = bgVertexRow(x, y);
auto vbo = &bg.vertices[i * static_cast<std::size_t>(BgVertexVboLength)]; auto vbo = &bg->vertices[i * static_cast<std::size_t>(BgVertexVboLength)];
auto ebo = &bg.elements[i * static_cast<std::size_t>(BgVertexEboLength)]; auto ebo = &bg->elements[i * static_cast<std::size_t>(BgVertexEboLength)];
setTileBufferObject( setTileBufferObject(
static_cast<uint_t>(i * BgVertexVboRows), static_cast<unsigned>(i * BgVertexVboRows),
static_cast<float>(x), static_cast<float>(x),
static_cast<float>(y), static_cast<float>(y),
0, 0,
@ -172,25 +162,25 @@ static void initBackgroundBufferObjects(glutils::BufferSet &bg) noexcept {
} }
} }
static void initSpritesBufferset(GLuint shader, glutils::BufferSet &bs) noexcept { static void initSpritesBufferset(GLuint shader, glutils::BufferSet *bs) noexcept {
// vao // vao
bs.vao = glutils::generateVertexArrayObject(); bs->vao = glutils::generateVertexArrayObject();
glBindVertexArray(bs.vao); glBindVertexArray(bs->vao);
// vbo & ebo // vbo & ebo
bs.vbo = glutils::generateBuffer(); bs->vbo = glutils::generateBuffer();
bs.ebo = glutils::generateBuffer(); bs->ebo = glutils::generateBuffer();
initSpriteBufferObjects(bs); initSpriteBufferObjects(bs);
glutils::sendVbo(bs); glutils::sendVbo(*bs);
glutils::sendEbo(bs); glutils::sendEbo(*bs);
// vbo layout // vbo layout
auto const enabledAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vEnabled")); auto enabledAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vEnabled"));
glEnableVertexAttribArray(enabledAttr); glEnableVertexAttribArray(enabledAttr);
glVertexAttribPointer(enabledAttr, 1, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), nullptr); glVertexAttribPointer(enabledAttr, 1, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), nullptr);
auto const posAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vPosition")); auto posAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vPosition"));
glEnableVertexAttribArray(posAttr); glEnableVertexAttribArray(posAttr);
glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float),
reinterpret_cast<void*>(1 * sizeof(float))); reinterpret_cast<void*>(1 * sizeof(float)));
auto const texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord")); auto texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord"));
glEnableVertexAttribArray(texCoordAttr); glEnableVertexAttribArray(texCoordAttr);
glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float), glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float),
reinterpret_cast<void*>(3 * sizeof(float))); reinterpret_cast<void*>(3 * sizeof(float)));
@ -198,25 +188,25 @@ static void initSpritesBufferset(GLuint shader, glutils::BufferSet &bs) noexcept
static void initBackgroundBufferset( static void initBackgroundBufferset(
GLuint shader, GLuint shader,
glutils::BufferSet &bg) noexcept { glutils::BufferSet *bg) noexcept {
// vao // vao
bg.vao = glutils::generateVertexArrayObject(); bg->vao = glutils::generateVertexArrayObject();
glBindVertexArray(bg.vao); glBindVertexArray(bg->vao);
// vbo & ebo // vbo & ebo
bg.vbo = glutils::generateBuffer(); bg->vbo = glutils::generateBuffer();
bg.ebo = glutils::generateBuffer(); bg->ebo = glutils::generateBuffer();
initBackgroundBufferObjects(bg); initBackgroundBufferObjects(bg);
glutils::sendVbo(bg); glutils::sendVbo(*bg);
glutils::sendEbo(bg); glutils::sendEbo(*bg);
// vbo layout // vbo layout
auto const posAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vPosition")); auto posAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vPosition"));
glEnableVertexAttribArray(posAttr); glEnableVertexAttribArray(posAttr);
glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr); glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr);
auto const texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord")); auto texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord"));
glEnableVertexAttribArray(texCoordAttr); glEnableVertexAttribArray(texCoordAttr);
glVertexAttribPointer( glVertexAttribPointer(
texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(bg.vertices[0]), texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(bg->vertices[0]),
reinterpret_cast<void*>(2 * sizeof(bg.vertices[0]))); reinterpret_cast<void*>(2 * sizeof(bg->vertices[0])));
} }
static glutils::GLTexture loadTexture( static glutils::GLTexture loadTexture(
@ -238,42 +228,42 @@ static glutils::GLTexture loadTexture(
return tex; return tex;
} }
static void drawBackground(CBB &cbb) noexcept { static void drawBackground(CBB *cbb) noexcept {
glBindVertexArray(cbb.vao); glBindVertexArray(cbb->vao);
if (cbb.updated) { if (cbb->updated) {
cbb.updated = false; cbb->updated = false;
glutils::sendVbo(cbb); glutils::sendVbo(*cbb);
} }
glBindTexture(GL_TEXTURE_2D, cbb.tex); glBindTexture(GL_TEXTURE_2D, cbb->tex);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(cbb.elements.size()), GL_UNSIGNED_INT, nullptr); glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(cbb->elements.size()), GL_UNSIGNED_INT, nullptr);
} }
static void drawBackgrounds( static void drawBackgrounds(
GlContext &gctx, GlContext *gctx,
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(gctx->bgShader);
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale")); const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx->bgShader, "vXScale"));
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vTileHeight")); const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx->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 : gctx->backgrounds) {
if (bg.enabled) { if (bg.enabled) {
auto &cbb = gctx.cbbs[bg.cbbIdx]; auto &cbb = gctx->cbbs[bg.cbbIdx];
const auto tileRows = cbb.tex.height / TileHeight; const auto tileRows = cbb.tex.height / TileHeight;
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows)); glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
drawBackground(cbb); drawBackground(&cbb);
} }
} }
} }
static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept { static void drawSprites(GlContext *gctx, ox::Size const&renderSz) noexcept {
glUseProgram(gctx.spriteShader); glUseProgram(gctx->spriteShader);
auto &sb = gctx.spriteBlocks; auto &sb = gctx->spriteBlocks;
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale")); const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx->bgShader, "vXScale"));
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.spriteShader, "vTileHeight")); const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx->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);
@ -312,31 +302,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(GlContext *gctx, Palette const&pal) noexcept {
loadPalette(gctx.bgShader, pal); loadPalette(gctx->bgShader, pal);
} }
static void loadSpritePalette(GlContext &gctx, Palette const&pal) noexcept { static void loadSpritePalette(GlContext *gctx, Palette const&pal) noexcept {
loadPalette(gctx.spriteShader, pal, true); loadPalette(gctx->spriteShader, pal, true);
} }
static void loadBgTexture( static void loadBgTexture(
GlContext &gctx, GlContext *gctx,
uint_t cbbIdx, unsigned 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 = loadTexture(w, h, pixels); gctx->cbbs[cbbIdx].tex = loadTexture(w, h, pixels);
} }
static void loadSpriteTexture( static void loadSpriteTexture(
GlContext &gctx, GlContext *gctx,
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 = loadTexture(w, h, pixels); gctx->spriteBlocks.tex = loadTexture(w, h, pixels);
} }
} }
@ -350,22 +340,22 @@ ox::Error initGfx(
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion); const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion);
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion); const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion);
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion); const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion);
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx.bgShader)); oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx.bgShader));
oxReturnError( oxReturnError(
glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader)); glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader));
for (auto &bg : gctx.cbbs) { for (auto &bg : gctx.cbbs) {
initBackgroundBufferset(gctx.bgShader, bg); initBackgroundBufferset(gctx.bgShader, &bg);
} }
if (initParams.glInstallDrawer) { if (initParams.glInstallDrawer) {
turbine::gl::addDrawer(gctx.turbineCtx, &gctx.drawer); turbine::gl::addDrawer(gctx.turbineCtx, &gctx.drawer);
initSpritesBufferset(gctx.spriteShader, gctx.spriteBlocks); initSpritesBufferset(gctx.spriteShader, &gctx.spriteBlocks);
} }
return {}; return {};
} }
void shutdownGfx(Context &ctx) noexcept { void shutdownGfx(Context &ctx) noexcept {
auto &gctx = glctx(ctx); auto &gctx = static_cast<GlContext&>(ctx);
turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer); turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer);
} }
@ -376,9 +366,9 @@ struct TileSheetData {
}; };
static ox::Result<TileSheetData> loadTileSheet( static ox::Result<TileSheetData> loadTileSheet(
Context &ctx, CompactTileSheet const&tilesheet) noexcept { Context *ctx, CompactTileSheet const&tilesheet) noexcept {
auto &gctx = glctx(ctx); auto &gctx = static_cast<GlContext&>(*ctx);
const uint_t bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2; const unsigned 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;
const int height = 8 * static_cast<int>(tiles); const int height = 8 * static_cast<int>(tiles);
@ -395,22 +385,22 @@ 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(&gctx, pixels.data(), width, height);
return TileSheetData{std::move(pixels), width, height}; return TileSheetData{std::move(pixels), width, height};
} }
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context *ctx, Context *ctx,
uint_t cbb, unsigned cbb,
ox::FileAddress const&tilesheetAddr, ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx; auto &kctx = gctx.turbineCtx.keelCtx;
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::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height); renderer::loadBgTexture(&gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
renderer::loadBgPalette(gctx, *palette); renderer::loadBgPalette(&gctx, *palette);
return {}; return {};
} }
@ -418,13 +408,13 @@ 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 &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx; auto &kctx = gctx.turbineCtx.keelCtx;
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(&gctx, tsd.pixels.data(), tsd.width, tsd.height);
renderer::loadSpritePalette(gctx, *palette); renderer::loadSpritePalette(&gctx, *palette);
return {}; return {};
} }
@ -437,7 +427,7 @@ ox::Error initConsole(Context *ctx) noexcept {
} }
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept { void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
const auto col = static_cast<uint_t>(column); const auto col = static_cast<unsigned>(column);
for (auto i = 0u; i < str.bytes(); ++i) { for (auto i = 0u; i < str.bytes(); ++i) {
setTile( setTile(
ctx, ctx,
@ -448,48 +438,48 @@ 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, unsigned bgIdx, unsigned cbbIdx) noexcept {
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &bg = gctx.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 {
const auto &gctx = glctx(*ctx); const auto &gctx = static_cast<GlContext&>(*ctx);
uint8_t out = 0; uint8_t out = 0;
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) { for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
out |= static_cast<uint8_t>(static_cast<uint_t>(gctx.backgrounds[i].enabled) << i); out |= static_cast<uint8_t>(static_cast<unsigned>(gctx.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); auto &gctx = static_cast<GlContext&>(*ctx);
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) { for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
gctx.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, unsigned bg) noexcept {
const auto &gctx = glctx(*ctx); const auto &gctx = static_cast<GlContext&>(*ctx);
return gctx.backgrounds[bg].enabled; return gctx.backgrounds[bg].enabled;
} }
void setBgStatus(Context *ctx, uint_t bg, bool status) noexcept { void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
gctx.backgrounds[bg].enabled = status; gctx.backgrounds[bg].enabled = status;
} }
void clearTileLayer(Context *ctx, uint_t bgIdx) noexcept { void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &bg = gctx.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, unsigned idx) noexcept {
auto &gctx = glctx(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength]; auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength]; auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
renderer::setSpriteBufferObject(idx * renderer::SpriteVertexVboRows, 0, renderer::setSpriteBufferObject(idx * renderer::SpriteVertexVboRows, 0,
@ -499,17 +489,17 @@ void hideSprite(Context *ctx, uint_t idx) noexcept {
void setSprite( void setSprite(
Context *ctx, Context *ctx,
uint_t idx, unsigned idx,
int x, int x,
int y, int y,
uint_t tileIdx, unsigned tileIdx,
uint_t spriteShape, unsigned spriteShape,
uint_t spriteSize, unsigned spriteSize,
uint_t flipX) noexcept { unsigned flipX) noexcept {
//oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})", //oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})",
// idx, x, y, tileIdx, spriteShape, spriteSize, flipX); // idx, x, y, tileIdx, spriteShape, spriteSize, flipX);
// Tonc Table 8.4 // Tonc Table 8.4
static constexpr ox::Array<ox::Vec<uint_t>, 12> dimensions{ static constexpr ox::Array<ox::Vec<unsigned>, 12> dimensions{
// col 0 // col 0
{1, 1}, // 0, 0 {1, 1}, // 0, 0
{2, 2}, // 0, 1 {2, 2}, // 0, 1
@ -529,7 +519,7 @@ 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 &gctx = static_cast<GlContext&>(*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;
@ -559,7 +549,7 @@ void setSprite(
void setTile( void setTile(
Context *ctx, Context *ctx,
uint_t bgIdx, unsigned bgIdx,
int column, int column,
int row, int row,
uint8_t tile) noexcept { uint8_t tile) noexcept {
@ -567,16 +557,16 @@ 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); auto &gctx = static_cast<GlContext&>(*ctx);
const auto z = static_cast<uint_t>(bgIdx); const auto z = static_cast<unsigned>(bgIdx);
const auto y = static_cast<uint_t>(row); const auto y = static_cast<unsigned>(row);
const auto x = static_cast<uint_t>(column); const auto x = static_cast<unsigned>(column);
const auto i = renderer::bgVertexRow(x, y); 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 vbo = &bg.vertices[i * renderer::BgVertexVboLength];
auto ebo = &bg.elements[i * renderer::BgVertexEboLength]; auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
renderer::setTileBufferObject( renderer::setTileBufferObject(
static_cast<uint_t>(i * renderer::BgVertexVboRows), static_cast<unsigned>(i * renderer::BgVertexVboRows),
static_cast<float>(x), static_cast<float>(x),
static_cast<float>(y), static_cast<float>(y),
tile, tile,
@ -587,13 +577,13 @@ void setTile(
namespace gl { namespace gl {
void drawMainView(core::Context &ctx, ox::Size const&renderSz) noexcept { void drawMainView(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); auto &gctx = static_cast<GlContext&>(*ctx);
renderer::drawBackgrounds(gctx, renderSz); renderer::drawBackgrounds(&gctx, renderSz);
if (gctx.spriteBlocks.tex) { if (gctx.spriteBlocks.tex) {
renderer::drawSprites(gctx, renderSz); renderer::drawSprites(&gctx, renderSz);
} }
} }

View File

@ -7,7 +7,6 @@
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/palette.hpp>
namespace nostalgia::core { namespace nostalgia::core {

View File

@ -6,9 +6,7 @@
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/core/color.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/palette.hpp>
namespace nostalgia::core { namespace nostalgia::core {
@ -107,4 +105,4 @@ class MoveColorCommand: public studio::UndoCommand {
void moveColor(int idx, int offset) noexcept; void moveColor(int idx, int offset) noexcept;
}; };
} }

View File

@ -12,7 +12,6 @@
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/tilesheet.hpp>
namespace nostalgia::core { namespace nostalgia::core {

View File

@ -8,7 +8,6 @@
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/tilesheet.hpp>
namespace nostalgia::core { namespace nostalgia::core {

View File

@ -9,7 +9,6 @@
#include <glutils/glutils.hpp> #include <glutils/glutils.hpp>
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/core/color.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
namespace nostalgia::core { namespace nostalgia::core {

View File

@ -58,10 +58,9 @@ struct TileDoc {
}; };
oxModelBegin(TileDoc) oxModelBegin(TileDoc)
oxModelFieldRename(subsheet_id, subsheetId) oxModelFieldRename(subsheet_id, subsheetId);
oxModelFieldRename(subsheet_path, subsheetPath) oxModelFieldRename(subsheet_path, subsheetPath);
oxModelField(type) oxModelField(type);
oxModelFieldRename(layer_attachments, layerAttachments)
oxModelEnd() oxModelEnd()
struct SceneDoc { struct SceneDoc {

View File

@ -23,7 +23,7 @@ void SceneEditorView::draw(int width, int height) noexcept {
glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height); glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height);
} }
const glutils::FrameBufferBind frameBufferBind(m_frameBuffer); const glutils::FrameBufferBind frameBufferBind(m_frameBuffer);
core::gl::drawMainView(*m_cctx, {width, height}); core::gl::drawMainView(m_cctx.get(), {width, height});
} }
const glutils::FrameBuffer &SceneEditorView::framebuffer() const noexcept { const glutils::FrameBuffer &SceneEditorView::framebuffer() const noexcept {