[nostalgia/core/studio] Fix subsheet editor to allocate correct number of pixels
This commit is contained in:
parent
2f7c62f2ef
commit
20a61de9fd
@ -198,6 +198,19 @@ struct TileSheet {
|
|||||||
setPixel(bpp, idx, palIdx);
|
setPixel(bpp, idx, palIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr auto setPixelCount(int8_t bpp, std::size_t cnt) noexcept {
|
||||||
|
switch (bpp) {
|
||||||
|
case 4:
|
||||||
|
pixels.resize(cnt * 2);
|
||||||
|
return OxError(0);
|
||||||
|
case 8:
|
||||||
|
pixels.resize(cnt);
|
||||||
|
return OxError(0);
|
||||||
|
default:
|
||||||
|
return OxError(1, "Invalid bpp used for TileSheet::SubSheet::setPixelCount");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a count of the pixels in this sheet, and not that of its children.
|
* Gets a count of the pixels in this sheet, and not that of its children.
|
||||||
* @param bpp bits per pixel, need for knowing how to count the pixels
|
* @param bpp bits per pixel, need for knowing how to count the pixels
|
||||||
|
@ -102,7 +102,6 @@ void TileSheetEditorImGui::draw(core::Context*) noexcept {
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
m_subsheetEditor.draw();
|
m_subsheetEditor.draw();
|
||||||
ImGui::ShowDemoWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet *subsheet, TileSheet::SubSheetIdx *path) noexcept {
|
void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet *subsheet, TileSheet::SubSheetIdx *path) noexcept {
|
||||||
@ -241,10 +240,11 @@ ox::Error TileSheetEditorImGui::markUnsavedChanges(int) noexcept {
|
|||||||
void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
|
void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
|
||||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||||
constexpr auto popupName = "Edit SubSheet";
|
constexpr auto popupName = "Edit SubSheet";
|
||||||
if (m_show) {
|
if (!m_show) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ImGui::OpenPopup(popupName);
|
ImGui::OpenPopup(popupName);
|
||||||
ImGui::SetNextWindowSize(ImVec2(235, 125));
|
ImGui::SetNextWindowSize(ImVec2(235, 125));
|
||||||
}
|
|
||||||
if (ImGui::BeginPopupModal(popupName, &m_show, modalFlags)) {
|
if (ImGui::BeginPopupModal(popupName, &m_show, modalFlags)) {
|
||||||
ImGui::InputText("Name", m_name.data(), m_name.cap());
|
ImGui::InputText("Name", m_name.data(), m_name.cap());
|
||||||
if (m_cols != -1) {
|
if (m_cols != -1) {
|
||||||
|
@ -206,7 +206,7 @@ struct UpdateSubSheetCommand: public studio::UndoCommand {
|
|||||||
sheet.name = m_newName;
|
sheet.name = m_newName;
|
||||||
sheet.columns = m_newCols;
|
sheet.columns = m_newCols;
|
||||||
sheet.rows = m_newRows;
|
sheet.rows = m_newRows;
|
||||||
sheet.pixels.resize(static_cast<std::size_t>(m_newCols * m_newRows * PixelsPerTile));
|
oxLogError(sheet.setPixelCount(m_img->bpp, static_cast<std::size_t>(m_newCols * m_newRows)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void undo() noexcept final {
|
void undo() noexcept final {
|
||||||
|
@ -36,7 +36,7 @@ void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::Su
|
|||||||
glBindVertexArray(m_bufferSet.vao);
|
glBindVertexArray(m_bufferSet.vao);
|
||||||
// vbo
|
// vbo
|
||||||
m_bufferSet.vbo = glutils::generateBuffer();
|
m_bufferSet.vbo = glutils::generateBuffer();
|
||||||
setBufferObjects(paneSize, subsheet, &m_bufferSet);
|
setBufferObjects(paneSize, subsheet);
|
||||||
glutils::sendVbo(m_bufferSet);
|
glutils::sendVbo(m_bufferSet);
|
||||||
// vbo layout
|
// vbo layout
|
||||||
const auto pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
const auto pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
||||||
@ -62,10 +62,10 @@ void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, f
|
|||||||
memcpy(vbo, vertices, sizeof(vertices));
|
memcpy(vbo, vertices, sizeof(vertices));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet, glutils::BufferSet *bg) noexcept {
|
void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept {
|
||||||
const auto pixSize = pixelSize(paneSize);
|
const auto pixSize = pixelSize(paneSize);
|
||||||
const auto set = [&bg, &pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) {
|
const auto set = [&](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) {
|
||||||
const auto vbo = &bg->vertices[i * VertexVboLength];
|
const auto vbo = &m_bufferSet.vertices[i * VertexVboLength];
|
||||||
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
||||||
};
|
};
|
||||||
// set buffer length
|
// set buffer length
|
||||||
|
@ -74,7 +74,7 @@ class TileSheetGrid {
|
|||||||
private:
|
private:
|
||||||
static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept;
|
static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept;
|
||||||
|
|
||||||
void setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet, glutils::BufferSet *bg) noexcept;
|
void setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
|
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
|
||||||
|
@ -36,7 +36,7 @@ void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &
|
|||||||
// vbo & ebo
|
// vbo & ebo
|
||||||
m_bufferSet.vbo = glutils::generateBuffer();
|
m_bufferSet.vbo = glutils::generateBuffer();
|
||||||
m_bufferSet.ebo = glutils::generateBuffer();
|
m_bufferSet.ebo = glutils::generateBuffer();
|
||||||
setBufferObjects(paneSize, img, subSheet, pal, &m_bufferSet);
|
setBufferObjects(paneSize, img, subSheet, pal);
|
||||||
glutils::sendVbo(m_bufferSet);
|
glutils::sendVbo(m_bufferSet);
|
||||||
glutils::sendEbo(m_bufferSet);
|
glutils::sendEbo(m_bufferSet);
|
||||||
// vbo layout
|
// vbo layout
|
||||||
@ -78,22 +78,23 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
|
|||||||
memcpy(ebo, elms, sizeof(elms));
|
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 {
|
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal) noexcept {
|
||||||
const auto setPixel = [this, &paneSize, &bg, &subSheet, &pal](std::size_t i, uint8_t p) {
|
const auto setPixel = [&](std::size_t i, uint8_t p) {
|
||||||
const auto color = pal.colors[p];
|
const auto color = pal.colors[p];
|
||||||
const auto pt = idxToPt(static_cast<int>(i), subSheet.columns);
|
const auto pt = idxToPt(static_cast<int>(i), subSheet.columns);
|
||||||
const auto fx = static_cast<float>(pt.x);
|
const auto fx = static_cast<float>(pt.x);
|
||||||
const auto fy = static_cast<float>(pt.y);
|
const auto fy = static_cast<float>(pt.y);
|
||||||
const auto vbo = &bg->vertices[i * VertexVboLength];
|
const auto vbo = &m_bufferSet.vertices[i * VertexVboLength];
|
||||||
const auto ebo = &bg->elements[i * VertexEboLength];
|
const auto ebo = &m_bufferSet.elements[i * VertexEboLength];
|
||||||
setPixelBufferObject(paneSize, i * VertexVboRows, fx, fy, color, vbo, ebo);
|
setPixelBufferObject(paneSize, i * VertexVboRows, fx, fy, color, vbo, ebo);
|
||||||
};
|
};
|
||||||
// set buffer lengths
|
// set buffer lengths
|
||||||
const auto width = subSheet.columns * TileWidth;
|
const auto width = subSheet.columns * TileWidth;
|
||||||
const auto height = subSheet.rows * TileHeight;
|
const auto height = subSheet.rows * TileHeight;
|
||||||
const auto tiles = static_cast<unsigned>(width * height);
|
oxDebugf("rows: {}", subSheet.rows);
|
||||||
m_bufferSet.vertices.resize(tiles * VertexVboLength);
|
const auto pixels = static_cast<unsigned>(width * height);
|
||||||
m_bufferSet.elements.resize(tiles * VertexEboLength);
|
m_bufferSet.vertices.resize(pixels * VertexVboLength);
|
||||||
|
m_bufferSet.elements.resize(pixels * VertexEboLength);
|
||||||
// set pixels
|
// set pixels
|
||||||
if (img.bpp == 4) {
|
if (img.bpp == 4) {
|
||||||
for (std::size_t i = 0; i < subSheet.pixels.size(); ++i) {
|
for (std::size_t i = 0; i < subSheet.pixels.size(); ++i) {
|
||||||
|
@ -56,7 +56,7 @@ class TileSheetPixels {
|
|||||||
private:
|
private:
|
||||||
void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept;
|
void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept;
|
||||||
|
|
||||||
void setBufferObjects(const geo::Vec2 &paneS, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal, glutils::BufferSet *bg) noexcept;
|
void setBufferObjects(const geo::Vec2 &paneS, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal) noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user