[nostalgia/core/opengl] Implement flip X and flip Y for BG tiles
All checks were successful
Build / build (push) Successful in 2m4s
All checks were successful
Build / build (push) Successful in 2m4s
This commit is contained in:
parent
e7a663901a
commit
2bdc3def74
@ -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)
|
||||
|
@ -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<uint16_t>(tile.tileIdx & 0b1'1111'1111) |
|
||||
static_cast<uint16_t>(tile.horizontalFlip << 0xa) |
|
||||
static_cast<uint16_t>(tile.verticalFlip << 0xb) |
|
||||
static_cast<uint16_t>(tile.flipX << 0xa) |
|
||||
static_cast<uint16_t>(tile.flipY << 0xb) |
|
||||
static_cast<uint16_t>(tile.palBank << 0xc);
|
||||
}
|
||||
|
||||
|
@ -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<float, BgVertexVboLength> 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<GLuint, BgVertexEboLength> 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<float>(tile.tileIdx),
|
||||
bg.priority,
|
||||
static_cast<float>(tile.palBank * 16),
|
||||
tile.flipX,
|
||||
tile.flipY,
|
||||
vbo,
|
||||
ebo);
|
||||
cbb.updated = true;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user