[nostalgia/core/opengl] Cleanup memcpys
This commit is contained in:
parent
f7a468ea1e
commit
ce9a0b1fdb
@ -118,8 +118,8 @@ static void setSpriteBufferObject(
|
|||||||
uint_t textureRow,
|
uint_t textureRow,
|
||||||
uint_t flipX,
|
uint_t flipX,
|
||||||
uint_t priority,
|
uint_t priority,
|
||||||
float *vbo,
|
ox::Span<float> vbo,
|
||||||
GLuint *ebo) noexcept {
|
ox::Span<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
|
||||||
constexpr float xmod = 0.1f;
|
constexpr float xmod = 0.1f;
|
||||||
constexpr float ymod = 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 + xmod, y + ymod, prif, R, textureRowf + 0, // top right
|
||||||
enabled, x, y + ymod, prif, L, textureRowf + 0, // top left
|
enabled, x, y + ymod, prif, L, textureRowf + 0, // top left
|
||||||
};
|
};
|
||||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
ox::spancpy<float>(vbo, vertices);
|
||||||
ox::Array<GLuint, SpriteVertexEboLength> const elms {
|
ox::Array<GLuint, SpriteVertexEboLength> const elms {
|
||||||
vi + 0, vi + 1, vi + 2,
|
vi + 0, vi + 1, vi + 2,
|
||||||
vi + 2, vi + 3, vi + 0,
|
vi + 2, vi + 3, vi + 0,
|
||||||
};
|
};
|
||||||
memcpy(ebo, elms.data(), sizeof(elms));
|
ox::spancpy<GLuint>(ebo, elms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTileBufferObject(
|
static void setTileBufferObject(
|
||||||
@ -155,8 +155,8 @@ static void setTileBufferObject(
|
|||||||
float palOffset,
|
float palOffset,
|
||||||
bool flipX,
|
bool flipX,
|
||||||
bool flipY,
|
bool flipY,
|
||||||
float *vbo,
|
ox::Span<float> vbo,
|
||||||
GLuint *ebo) noexcept {
|
ox::Span<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
|
||||||
constexpr float ymod = 0.1f;
|
constexpr float ymod = 0.1f;
|
||||||
constexpr float xmod = 0.1f;
|
constexpr float xmod = 0.1f;
|
||||||
@ -175,19 +175,30 @@ static void setTileBufferObject(
|
|||||||
x + xmod, y + ymod, prif, R, T, textureTileIdx, palOffset, // top right
|
x + xmod, y + ymod, prif, R, T, textureTileIdx, palOffset, // top right
|
||||||
x, y + ymod, prif, L, T, textureTileIdx, palOffset, // top left
|
x, y + ymod, prif, L, T, textureTileIdx, palOffset, // top left
|
||||||
};
|
};
|
||||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
ox::spancpy<float>(vbo, vertices);
|
||||||
ox::Array<GLuint, BgVertexEboLength> const elms {
|
ox::Array<GLuint, BgVertexEboLength> const elms {
|
||||||
vi + 0, vi + 1, vi + 2,
|
vi + 0, vi + 1, vi + 2,
|
||||||
vi + 2, vi + 3, vi + 0,
|
vi + 2, vi + 3, vi + 0,
|
||||||
};
|
};
|
||||||
memcpy(ebo, elms.data(), sizeof(elms));
|
ox::spancpy<GLuint>(ebo, elms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initSpriteBufferObjects(Context &ctx, glutils::BufferSet &bs) noexcept {
|
static void initSpriteBufferObjects(Context &ctx, glutils::BufferSet &bs) noexcept {
|
||||||
for (auto i = 0u; i < ctx.spriteCount; ++i) {
|
for (auto i = 0u; i < ctx.spriteCount; ++i) {
|
||||||
auto vbo = &bs.vertices[i * static_cast<std::size_t>(SpriteVertexVboLength)];
|
auto const vbo = ox::Span{bs.vertices}
|
||||||
auto ebo = &bs.elements[i * static_cast<std::size_t>(SpriteVertexEboLength)];
|
+ i * static_cast<std::size_t>(SpriteVertexVboLength);
|
||||||
setSpriteBufferObject(i * static_cast<uint_t>(SpriteVertexVboRows) * ctx.blocksPerSprite, 0, 0, 0, 0, false, 0, vbo, ebo);
|
auto const ebo = ox::Span{bs.elements}
|
||||||
|
+ i * static_cast<std::size_t>(SpriteVertexEboLength);
|
||||||
|
setSpriteBufferObject(
|
||||||
|
i * static_cast<uint_t>(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 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 = &bs.vertices[i * static_cast<std::size_t>(BgVertexVboLength)];
|
auto const vbo = ox::Span{bs.vertices}
|
||||||
auto ebo = &bs.elements[i * static_cast<std::size_t>(BgVertexEboLength)];
|
+ i * static_cast<std::size_t>(BgVertexVboLength);
|
||||||
|
auto const ebo = ox::Span{bs.elements}
|
||||||
|
+ i * static_cast<std::size_t>(BgVertexEboLength);
|
||||||
setTileBufferObject(
|
setTileBufferObject(
|
||||||
static_cast<uint_t>(i * BgVertexVboRows),
|
static_cast<uint_t>(i * BgVertexVboRows),
|
||||||
static_cast<float>(x),
|
static_cast<float>(x),
|
||||||
@ -421,8 +434,8 @@ static void setSprite(
|
|||||||
auto const eboIdx = eboBase + renderer::SpriteVertexEboLength * i;
|
auto const eboIdx = eboBase + renderer::SpriteVertexEboLength * i;
|
||||||
oxAssert(vboIdx < ctx.spriteBlocks.vertices.size(), "vbo overflow");
|
oxAssert(vboIdx < ctx.spriteBlocks.vertices.size(), "vbo overflow");
|
||||||
oxAssert(eboIdx < ctx.spriteBlocks.elements.size(), "ebo overflow");
|
oxAssert(eboIdx < ctx.spriteBlocks.elements.size(), "ebo overflow");
|
||||||
auto const vbo = &ctx.spriteBlocks.vertices[vboIdx];
|
auto const vbo = ox::Span{ctx.spriteBlocks.vertices} + vboIdx;
|
||||||
auto const ebo = &ctx.spriteBlocks.elements[eboIdx];
|
auto const ebo = ox::Span{ctx.spriteBlocks.elements} + eboIdx;
|
||||||
renderer::setSpriteBufferObject(
|
renderer::setSpriteBufferObject(
|
||||||
static_cast<uint_t>(vboIdx),
|
static_cast<uint_t>(vboIdx),
|
||||||
enabled,
|
enabled,
|
||||||
@ -556,7 +569,7 @@ static void copyPixels(
|
|||||||
CompactTileSheet const&ts,
|
CompactTileSheet const&ts,
|
||||||
ox::Span<uint32_t> dst,
|
ox::Span<uint32_t> dst,
|
||||||
size_t const srcPxIdx,
|
size_t const srcPxIdx,
|
||||||
size_t pxlCnt) noexcept {
|
size_t const pxlCnt) noexcept {
|
||||||
size_t idx{};
|
size_t idx{};
|
||||||
if (ts.bpp == 4) {
|
if (ts.bpp == 4) {
|
||||||
for (size_t i = 0; i < pxlCnt; i += 2) {
|
for (size_t i = 0; i < pxlCnt; i += 2) {
|
||||||
@ -656,8 +669,8 @@ void setBgTile(
|
|||||||
const auto x = static_cast<uint_t>(column);
|
const auto x = static_cast<uint_t>(column);
|
||||||
const auto i = renderer::bgVertexRow(x, y);
|
const auto i = renderer::bgVertexRow(x, y);
|
||||||
auto &cbb = ctx.cbbs[z];
|
auto &cbb = ctx.cbbs[z];
|
||||||
const auto vbo = &cbb.vertices[i * renderer::BgVertexVboLength];
|
const auto vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength;
|
||||||
const auto ebo = &cbb.elements[i * renderer::BgVertexEboLength];
|
const auto ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength;
|
||||||
auto &bg = ctx.backgrounds[bgIdx];
|
auto &bg = ctx.backgrounds[bgIdx];
|
||||||
renderer::setTileBufferObject(
|
renderer::setTileBufferObject(
|
||||||
static_cast<uint_t>(i * renderer::BgVertexVboRows),
|
static_cast<uint_t>(i * renderer::BgVertexVboRows),
|
||||||
|
Loading…
Reference in New Issue
Block a user