diff --git a/src/nostalgia/modules/core/src/opengl/gfx.cpp b/src/nostalgia/modules/core/src/opengl/gfx.cpp index 41a1413a..686b8782 100644 --- a/src/nostalgia/modules/core/src/opengl/gfx.cpp +++ b/src/nostalgia/modules/core/src/opengl/gfx.cpp @@ -118,8 +118,8 @@ static void setSpriteBufferObject( uint_t textureRow, uint_t flipX, uint_t priority, - float *vbo, - GLuint *ebo) noexcept { + ox::Span vbo, + ox::Span ebo) noexcept { // don't worry, this memcpy gets optimized to something much more ideal constexpr float xmod = 0.1f; constexpr float ymod = 0.1f; @@ -138,12 +138,12 @@ static void setSpriteBufferObject( enabled, x + xmod, y + ymod, prif, R, textureRowf + 0, // top right enabled, x, y + ymod, prif, L, textureRowf + 0, // top left }; - memcpy(vbo, vertices.data(), sizeof(vertices)); + ox::spancpy(vbo, vertices); ox::Array const elms { - vi + 0, vi + 1, vi + 2, - vi + 2, vi + 3, vi + 0, + vi + 0, vi + 1, vi + 2, + vi + 2, vi + 3, vi + 0, }; - memcpy(ebo, elms.data(), sizeof(elms)); + ox::spancpy(ebo, elms); } static void setTileBufferObject( @@ -155,8 +155,8 @@ static void setTileBufferObject( float palOffset, bool flipX, bool flipY, - float *vbo, - GLuint *ebo) noexcept { + ox::Span vbo, + ox::Span ebo) noexcept { // don't worry, this memcpy gets optimized to something much more ideal constexpr float ymod = 0.1f; constexpr float xmod = 0.1f; @@ -170,24 +170,35 @@ static void setTileBufferObject( float const T = flipY ? 1 : 0; float const B = flipY ? 0 : 1; ox::Array const vertices { - 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 + 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::spancpy(vbo, vertices); ox::Array const elms { - vi + 0, vi + 1, vi + 2, - vi + 2, vi + 3, vi + 0, + vi + 0, vi + 1, vi + 2, + vi + 2, vi + 3, vi + 0, }; - memcpy(ebo, elms.data(), sizeof(elms)); + ox::spancpy(ebo, elms); } static void initSpriteBufferObjects(Context &ctx, glutils::BufferSet &bs) noexcept { for (auto i = 0u; i < ctx.spriteCount; ++i) { - auto vbo = &bs.vertices[i * static_cast(SpriteVertexVboLength)]; - auto ebo = &bs.elements[i * static_cast(SpriteVertexEboLength)]; - setSpriteBufferObject(i * static_cast(SpriteVertexVboRows) * ctx.blocksPerSprite, 0, 0, 0, 0, false, 0, vbo, ebo); + auto const vbo = ox::Span{bs.vertices} + + i * static_cast(SpriteVertexVboLength); + auto const ebo = ox::Span{bs.elements} + + i * static_cast(SpriteVertexEboLength); + setSpriteBufferObject( + i * static_cast(SpriteVertexVboRows) * ctx.blocksPerSprite, + 0, + 0, + 0, + 0, + false, + 0, + vbo, + ebo); } } @@ -195,8 +206,10 @@ static void initBackgroundBufferObjects(glutils::BufferSet &bs) noexcept { for (auto x = 0u; x < TileColumns; ++x) { for (auto y = 0u; y < TileRows; ++y) { const auto i = bgVertexRow(x, y); - auto vbo = &bs.vertices[i * static_cast(BgVertexVboLength)]; - auto ebo = &bs.elements[i * static_cast(BgVertexEboLength)]; + auto const vbo = ox::Span{bs.vertices} + + i * static_cast(BgVertexVboLength); + auto const ebo = ox::Span{bs.elements} + + i * static_cast(BgVertexEboLength); setTileBufferObject( static_cast(i * BgVertexVboRows), static_cast(x), @@ -421,8 +434,8 @@ static void setSprite( auto const eboIdx = eboBase + renderer::SpriteVertexEboLength * i; oxAssert(vboIdx < ctx.spriteBlocks.vertices.size(), "vbo overflow"); oxAssert(eboIdx < ctx.spriteBlocks.elements.size(), "ebo overflow"); - auto const vbo = &ctx.spriteBlocks.vertices[vboIdx]; - auto const ebo = &ctx.spriteBlocks.elements[eboIdx]; + auto const vbo = ox::Span{ctx.spriteBlocks.vertices} + vboIdx; + auto const ebo = ox::Span{ctx.spriteBlocks.elements} + eboIdx; renderer::setSpriteBufferObject( static_cast(vboIdx), enabled, @@ -556,7 +569,7 @@ static void copyPixels( CompactTileSheet const&ts, ox::Span dst, size_t const srcPxIdx, - size_t pxlCnt) noexcept { + size_t const pxlCnt) noexcept { size_t idx{}; if (ts.bpp == 4) { for (size_t i = 0; i < pxlCnt; i += 2) { @@ -656,8 +669,8 @@ void setBgTile( const auto x = static_cast(column); const auto i = renderer::bgVertexRow(x, y); auto &cbb = ctx.cbbs[z]; - const auto vbo = &cbb.vertices[i * renderer::BgVertexVboLength]; - const auto ebo = &cbb.elements[i * renderer::BgVertexEboLength]; + const auto vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength; + const auto ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength; auto &bg = ctx.backgrounds[bgIdx]; renderer::setTileBufferObject( static_cast(i * renderer::BgVertexVboRows),