[nostalgia/core/studio] Fix subsheet editor to allocate correct number of pixels

This commit is contained in:
2022-03-05 15:51:39 -06:00
parent 2f7c62f2ef
commit 20a61de9fd
7 changed files with 33 additions and 19 deletions
@@ -36,7 +36,7 @@ void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &
// vbo & ebo
m_bufferSet.vbo = glutils::generateBuffer();
m_bufferSet.ebo = glutils::generateBuffer();
setBufferObjects(paneSize, img, subSheet, pal, &m_bufferSet);
setBufferObjects(paneSize, img, subSheet, pal);
glutils::sendVbo(m_bufferSet);
glutils::sendEbo(m_bufferSet);
// vbo layout
@@ -78,22 +78,23 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
memcpy(ebo, elms, sizeof(elms));
}
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal, glutils::BufferSet *bg) noexcept {
const auto setPixel = [this, &paneSize, &bg, &subSheet, &pal](std::size_t i, uint8_t p) {
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal) noexcept {
const auto setPixel = [&](std::size_t i, uint8_t p) {
const auto color = pal.colors[p];
const auto pt = idxToPt(static_cast<int>(i), subSheet.columns);
const auto fx = static_cast<float>(pt.x);
const auto fy = static_cast<float>(pt.y);
const auto vbo = &bg->vertices[i * VertexVboLength];
const auto ebo = &bg->elements[i * VertexEboLength];
const auto vbo = &m_bufferSet.vertices[i * VertexVboLength];
const auto ebo = &m_bufferSet.elements[i * VertexEboLength];
setPixelBufferObject(paneSize, i * VertexVboRows, fx, fy, color, vbo, ebo);
};
// set buffer lengths
const auto width = subSheet.columns * TileWidth;
const auto height = subSheet.rows * TileHeight;
const auto tiles = static_cast<unsigned>(width * height);
m_bufferSet.vertices.resize(tiles * VertexVboLength);
m_bufferSet.elements.resize(tiles * VertexEboLength);
oxDebugf("rows: {}", subSheet.rows);
const auto pixels = static_cast<unsigned>(width * height);
m_bufferSet.vertices.resize(pixels * VertexVboLength);
m_bufferSet.elements.resize(pixels * VertexEboLength);
// set pixels
if (img.bpp == 4) {
for (std::size_t i = 0; i < subSheet.pixels.size(); ++i) {