diff --git a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp index 8cc6882a..3c8a45cc 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp @@ -48,8 +48,8 @@ struct BgTile { static constexpr auto TypeVersion = 1; unsigned tileIdx = 0; unsigned palBank = 0; - unsigned horizontalFlip = false; - unsigned verticalFlip = false; + unsigned flipX = false; + unsigned flipY = false; }; oxModelBegin(BgTile) diff --git a/src/nostalgia/modules/core/src/gba/gfx.cpp b/src/nostalgia/modules/core/src/gba/gfx.cpp index dcd33ba2..ec0153ee 100644 --- a/src/nostalgia/modules/core/src/gba/gfx.cpp +++ b/src/nostalgia/modules/core/src/gba/gfx.cpp @@ -289,8 +289,8 @@ void setBgTile(Context&, uint_t bgIdx, int column, int row, BgTile const&tile) n // see Tonc 9.3 MEM_BG_MAP[bgIdx][tileIdx] = static_cast(tile.tileIdx & 0b1'1111'1111) | - static_cast(tile.horizontalFlip << 0xa) | - static_cast(tile.verticalFlip << 0xb) | + static_cast(tile.flipX << 0xa) | + static_cast(tile.flipY << 0xb) | static_cast(tile.palBank << 0xc); } diff --git a/src/nostalgia/modules/core/src/opengl/gfx.cpp b/src/nostalgia/modules/core/src/opengl/gfx.cpp index 3dd9dc88..19005172 100644 --- a/src/nostalgia/modules/core/src/opengl/gfx.cpp +++ b/src/nostalgia/modules/core/src/opengl/gfx.cpp @@ -152,6 +152,8 @@ static void setTileBufferObject( float textureTileIdx, float priority, float palOffset, + bool flipX, + bool flipY, float *vbo, GLuint *ebo) noexcept { // don't worry, this memcpy gets optimized to something much more ideal @@ -162,11 +164,15 @@ static void setTileBufferObject( x -= 1.0f; y += 1.0f - ymod; auto const prif = priority * PriorityScale; + float const L = flipX ? 1 : 0; + float const R = flipX ? 0 : 1; + float const T = flipY ? 1 : 0; + float const B = flipY ? 0 : 1; ox::Array const vertices { - x, y, prif, 0, 1, textureTileIdx, palOffset, // bottom left - x + xmod, y, prif, 1, 1, textureTileIdx, palOffset, // bottom right - x + xmod, y + ymod, prif, 1, 0, textureTileIdx, palOffset, // top right - x, y + ymod, prif, 0, 0, textureTileIdx, palOffset, // top left + x, y, prif, L, B, textureTileIdx, palOffset, // bottom left + x + xmod, y, prif, R, B, textureTileIdx, palOffset, // bottom right + x + xmod, y + ymod, prif, R, T, textureTileIdx, palOffset, // top right + x, y + ymod, prif, L, T, textureTileIdx, palOffset, // top left }; memcpy(vbo, vertices.data(), sizeof(vertices)); ox::Array const elms { @@ -197,6 +203,8 @@ static void initBackgroundBufferObjects(glutils::BufferSet &bs) noexcept { 0, 0, 0, + false, + false, vbo, ebo); } @@ -612,6 +620,8 @@ void setBgTile( static_cast(tile.tileIdx), bg.priority, static_cast(tile.palBank * 16), + tile.flipX, + tile.flipY, vbo, ebo); cbb.updated = true; diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index acf26912..da4a6ad9 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -82,7 +82,8 @@ static ox::Error runTest(turbine::Context &tctx) { [[maybe_unused]] static ox::Error runTileSheetSetTest(turbine::Context &tctx) { - // this should make the screen display 'ABCDB' + // this should make the screen display 'ABCDB', with the A being upside down + // and the first B being backwards constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal"); oxRequireM(cctx, core::init(tctx)); turbine::setApplicationData(tctx, cctx.get()); @@ -103,9 +104,9 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) { oxReturnError(core::loadBgPalette(*cctx, 0, ox::StringLiteral("/Palettes/Chester.npal"))); oxReturnError(core::loadSpritePalette(*cctx, PaletteAddr)); core::setBgStatus(*cctx, 0, true); - core::setBgTile(*cctx, 0, 10, 9, 1, bgPalBank); - core::setBgTile(*cctx, 0, 11, 9, 2, bgPalBank); - core::setBgTile(*cctx, 0, 13, 9, 4, bgPalBank); + core::setBgTile(*cctx, 0, 10, 9, { .tileIdx = 1, .palBank = bgPalBank, .flipX = 0, .flipY = 1 }); + core::setBgTile(*cctx, 0, 11, 9, { .tileIdx = 2, .palBank = bgPalBank, .flipX = 1, .flipY = 0 }); + core::setBgTile(*cctx, 0, 13, 9, { .tileIdx = 4, .palBank = bgPalBank, .flipX = 0, .flipY = 0 }); core::setSprite(*cctx, 16, { .enabled = true, .x = 12 * 8,