From 540ed9b3f9a4e5ed3cba4ef18be95bc2cc259d38 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 25 Nov 2023 20:59:01 -0600 Subject: [PATCH] [keel,nostalgia,turbine] Change log channel delimiter from :: to . --- src/keel/pack.cpp | 2 +- src/keel/pack.hpp | 2 +- src/nostalgia/modules/core/src/opengl/gfx.cpp | 98 ++++++++++++++----- src/turbine/glfw/turbine.cpp | 2 +- 4 files changed, 75 insertions(+), 29 deletions(-) diff --git a/src/keel/pack.cpp b/src/keel/pack.cpp index dece9fa8..22e3a206 100644 --- a/src/keel/pack.cpp +++ b/src/keel/pack.cpp @@ -107,7 +107,7 @@ static ox::Error doTransformations( // transformations need to be done after the copy to the new FS is complete static ox::Error transformClaw(keel::Context *ctx, ox::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept { // copy - oxTracef("pack::transformClaw", "path: {}", path); + oxTracef("pack.transformClaw", "path: {}", path); oxRequire(fileList, dest->ls(path)); for (const auto &name : fileList) { const auto filePath = ox::sfmt("{}{}", path, name); diff --git a/src/keel/pack.hpp b/src/keel/pack.hpp index 5db6bb1e..e9c117ea 100644 --- a/src/keel/pack.hpp +++ b/src/keel/pack.hpp @@ -116,7 +116,7 @@ ox::Error preloadDir( ox::Preloader *pl, ox::CRStringView path) noexcept { // copy - oxTracef("pack::preload", "path: {}", path); + oxTracef("pack.preload", "path: {}", path); oxRequire(fileList, romFs->ls(path)); for (const auto &name : fileList) { const auto filePath = ox::sfmt("{}{}", path, name); diff --git a/src/nostalgia/modules/core/src/opengl/gfx.cpp b/src/nostalgia/modules/core/src/opengl/gfx.cpp index 1c49b6c1..1fac1b4b 100644 --- a/src/nostalgia/modules/core/src/opengl/gfx.cpp +++ b/src/nostalgia/modules/core/src/opengl/gfx.cpp @@ -27,6 +27,8 @@ inline GlContext &glctx(Context &ctx) noexcept { } } +constexpr auto Scale = 5; + namespace renderer { Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {} @@ -47,7 +49,7 @@ constexpr ox::StringView bgvshadTmpl = R"( gl_Position = vec4( vPosition.x * vXScale - xScaleInvert, vPosition.y, 0.0, 1.0); - fTexCoord = vTexCoord * vec2(1, vTileHeight); + fTexCoord = vTexCoord; })"; constexpr ox::StringView bgfshadTmpl = R"( @@ -55,10 +57,28 @@ constexpr ox::StringView bgfshadTmpl = R"( out vec4 outColor; in vec2 fTexCoord; uniform sampler2D image; + uniform vec2 fSrcImgSz; uniform vec4 fPalette[256]; + vec2 pixelSz; + vec4 getColor(vec2 offset) { + vec2 p = fTexCoord + pixelSz * offset; + int idx = int(texture(image, p).rgb.r * 256); + return fPalette[idx]; + } void main() { - int idx = int(texture(image, fTexCoord).rgb.r * 256); - outColor = fPalette[idx]; + pixelSz = vec2(1, 1) / (fSrcImgSz); + vec2 pixelCoord = floor(fTexCoord / pixelSz) * pixelSz; + vec4 c0 = getColor(pixelCoord + pixelSz * vec2(0, 0)); + vec4 c1 = getColor(pixelCoord + pixelSz * vec2(0.75, 0)); + vec4 c2 = getColor(pixelCoord + pixelSz * vec2(0, 0.75)); + vec4 c3 = getColor(pixelCoord + pixelSz * vec2(0.75, 0.75)); + float u = fTexCoord.x - fTexCoord.x / pixelSz.x; + float v = fTexCoord.y - fTexCoord.y / pixelSz.y; + vec4 b0 = (1.0 - u) * c0 + u * c1; + vec4 b1 = (1.0 - u) * c2 + u * c3; + outColor = (1.0 - v) * b0 + u * b1; + outColor = fPalette[int(texture(image, fTexCoord).rgb.r * 256)]; + //outColor = fPalette[int(texture(image, pixelCoord).rgb.r * 256)]; //outColor = vec4(0.0, 0.7, 1.0, 1.0); })"; @@ -118,11 +138,12 @@ static void setSpriteBufferObject( memcpy(ebo, elms.data(), sizeof(elms)); } -void setTileBufferObject( +static void setTileBufferObject( uint_t vi, float x, float y, - uint_t textureRow, + float textureYOffset, + float tileHeight, float *vbo, GLuint *ebo) noexcept { // don't worry, this memcpy gets optimized to something much more ideal @@ -132,12 +153,11 @@ void setTileBufferObject( y *= -ymod; x -= 1.0f; y += 1.0f - ymod; - const auto textureRowf = static_cast(textureRow); const ox::Array vertices { - x, y, 0, textureRowf + 1, // bottom left - x + xmod, y, 1, textureRowf + 1, // bottom right - x + xmod, y + ymod, 1, textureRowf + 0, // top right - x, y + ymod, 0, textureRowf + 0, // top left + x, y, 0, tileHeight + textureYOffset, // bottom left + x + xmod, y, 1, tileHeight + textureYOffset, // bottom right + x + xmod, y + ymod, 1, 0 + textureYOffset, // top right + x, y + ymod, 0, 0 + textureYOffset, // top left }; memcpy(vbo, vertices.data(), sizeof(vertices)); const ox::Array elms { @@ -166,6 +186,7 @@ static void initBackgroundBufferObjects(glutils::BufferSet &bg) noexcept { static_cast(x), static_cast(y), 0, + 0, vbo, ebo); } @@ -230,9 +251,9 @@ static glutils::GLTexture loadTexture( tex.height = h; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex.id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return tex; @@ -253,6 +274,7 @@ static void drawBackgrounds( ox::Size const&renderSz) noexcept { // load background shader and its uniforms glUseProgram(gctx.bgShader); + const auto uniformSrcImgSz = glGetUniformLocation(gctx.bgShader, "fSrcImgSz"); const auto uniformXScale = static_cast(glGetUniformLocation(gctx.bgShader, "vXScale")); const auto uniformTileHeight = static_cast(glGetUniformLocation(gctx.bgShader, "vTileHeight")); const auto [wi, hi] = renderSz; @@ -262,8 +284,12 @@ static void drawBackgrounds( for (const auto &bg : gctx.backgrounds) { if (bg.enabled) { auto &cbb = gctx.cbbs[bg.cbbIdx]; - const auto tileRows = cbb.tex.height / TileHeight; + const auto tileRows = cbb.tex.height / (TileHeight * Scale); glUniform1f(uniformTileHeight, 1.0f / static_cast(tileRows)); + glUniform2f( + uniformSrcImgSz, + static_cast(cbb.tex.width), + static_cast(cbb.tex.height)); drawBackground(cbb); } } @@ -272,8 +298,8 @@ static void drawBackgrounds( 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 uniformXScale = glGetUniformLocation(gctx.bgShader, "vXScale"); + const auto uniformTileHeight = glGetUniformLocation(gctx.spriteShader, "vTileHeight"); const auto [wi, hi] = renderSz; const auto wf = static_cast(wi); const auto hf = static_cast(hi); @@ -285,7 +311,7 @@ static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept { glutils::sendVbo(sb); } // set vTileHeight uniform - const auto tileRows = sb.tex.height / TileHeight; + const auto tileRows = sb.tex.height / (TileHeight * Scale); glUniform1f(uniformTileHeight, 1.0f / static_cast(tileRows)); // draw glBindTexture(GL_TEXTURE_2D, sb.tex); @@ -326,7 +352,7 @@ static void loadBgTexture( const void *pixels, int w, 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); } @@ -335,7 +361,7 @@ static void loadSpriteTexture( const void *pixels, int w, 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); } @@ -373,6 +399,10 @@ struct TileSheetData { ox::Vector pixels; int width = 0; int height = 0; + [[nodiscard]] + constexpr ox::Size size() const noexcept { + return {width, height}; + } }; static ox::Result loadTileSheet( @@ -408,7 +438,13 @@ ox::Error loadBgTileSheet( auto &kctx = gctx.turbineCtx.keelCtx; oxRequire(tilesheet, readObj(&kctx, tilesheetAddr)); oxRequire(palette, readObj(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette)); - oxRequire(tsd, loadTileSheet(*ctx, *tilesheet)); + oxRequire(tsd, loadTileSheet(*ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData { + return { + .pixels = resizeTileSheetData(t.pixels, t.size(), Scale), + .width = t.width * Scale, + .height = t.height * Scale, + }; + })); renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height); renderer::loadBgPalette(gctx, *palette); return {}; @@ -537,8 +573,15 @@ void setSprite( const auto cidx = idx + i; auto vbo = &gctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength]; auto ebo = &gctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength]; - renderer::setSpriteBufferObject(cidx * renderer::SpriteVertexVboRows, 1, - fX, fY, tileIdx + i, flipX, vbo, ebo); + renderer::setSpriteBufferObject( + cidx * renderer::SpriteVertexVboRows, + 1, + fX, + fY, + tileIdx + i, + flipX, + vbo, + ebo); ++i; }; if (!flipX) { @@ -564,7 +607,7 @@ void setTile( int row, uint8_t tile) noexcept { oxTracef( - "nostalgia::core::gfx::setTile", + "nostalgia.core.gfx.setTile", "bgIdx: {}, column: {}, row: {}, tile: {}", bgIdx, column, row, tile); auto &gctx = glctx(*ctx); @@ -573,13 +616,16 @@ void setTile( const auto x = static_cast(column); const auto i = renderer::bgVertexRow(x, y); auto &bg = gctx.cbbs[z]; - auto vbo = &bg.vertices[i * renderer::BgVertexVboLength]; - auto ebo = &bg.elements[i * renderer::BgVertexEboLength]; + const auto vbo = &bg.vertices[i * renderer::BgVertexVboLength]; + const auto ebo = &bg.elements[i * renderer::BgVertexEboLength]; + const auto tileHeight = static_cast(TileHeight * Scale) / static_cast(bg.tex.height); + const auto tileOffset = tileHeight * static_cast(tile); renderer::setTileBufferObject( static_cast(i * renderer::BgVertexVboRows), static_cast(x), static_cast(y), - tile, + tileOffset, + tileHeight, vbo, ebo); bg.updated = true; diff --git a/src/turbine/glfw/turbine.cpp b/src/turbine/glfw/turbine.cpp index 42ee93a5..fdc38598 100644 --- a/src/turbine/glfw/turbine.cpp +++ b/src/turbine/glfw/turbine.cpp @@ -56,7 +56,7 @@ static void tickFps(GlfwContext &gctx, uint64_t nowMs) noexcept { if constexpr(config::GlFpsPrint) { oxOutf("FPS: {}\n", fps); } - oxTracef("turbine::fps", "FPS: {}", fps); + oxTracef("turbine.fps", "FPS: {}", fps); gctx.prevFpsCheckTime = nowMs; gctx.draws = 0; }