[nostalgia] Add basic support for subsheets
This commit is contained in:
@@ -30,13 +30,13 @@ void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept {
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(m_bufferSet.vertices.size() / VertexVboRowLength));
|
||||
}
|
||||
|
||||
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img) noexcept {
|
||||
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept {
|
||||
// vao
|
||||
m_bufferSet.vao = glutils::generateVertexArrayObject();
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
// vbo
|
||||
m_bufferSet.vbo = glutils::generateBuffer();
|
||||
setBufferObjects(paneSize, img, &m_bufferSet);
|
||||
setBufferObjects(paneSize, subsheet, &m_bufferSet);
|
||||
glutils::sendVbo(m_bufferSet);
|
||||
// vbo layout
|
||||
const auto pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
||||
@@ -62,38 +62,38 @@ void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, f
|
||||
memcpy(vbo, vertices, sizeof(vertices));
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, glutils::BufferSet *bg) noexcept {
|
||||
void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet, glutils::BufferSet *bg) noexcept {
|
||||
const auto pixSize = pixelSize(paneSize);
|
||||
const auto set = [bg, pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) {
|
||||
const auto vbo = &bg->vertices[i * VertexVboLength];
|
||||
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
||||
};
|
||||
// set buffer length
|
||||
const auto width = img.columns() * TileWidth;
|
||||
const auto height = img.rows() * TileHeight;
|
||||
const auto pixelCnt = static_cast<unsigned>(width * height);
|
||||
const auto tileCnt = static_cast<unsigned>(img.columns() * img.rows());
|
||||
m_bufferSet.vertices.resize((tileCnt + pixelCnt) * VertexVboLength);
|
||||
const auto width = subsheet.columns * TileWidth;
|
||||
const auto height = subsheet.rows * TileHeight;
|
||||
const auto tileCnt = static_cast<unsigned>(subsheet.columns + subsheet.rows);
|
||||
const auto pixelCnt = static_cast<unsigned>(width + height);
|
||||
m_bufferSet.vertices.resize((tileCnt + pixelCnt + 4) * VertexVboLength);
|
||||
// set buffer
|
||||
auto i = 0ull;
|
||||
// pixel outlines
|
||||
constexpr auto pixOutlineColor = color32(0.4431f, 0.4901f, 0.4941f);
|
||||
for (auto x = 0; x < img.columns() * TileWidth + 1; ++x) {
|
||||
set(i, {x, 0}, {x, img.rows() * TileHeight}, pixOutlineColor);
|
||||
for (auto x = 0; x < subsheet.columns * TileWidth + 1; ++x) {
|
||||
set(i, {x, 0}, {x, subsheet.rows * TileHeight}, pixOutlineColor);
|
||||
++i;
|
||||
}
|
||||
for (auto y = 0; y < img.rows() * TileHeight + 1; ++y) {
|
||||
set(i, {0, y}, {img.columns() * TileWidth, y}, pixOutlineColor);
|
||||
for (auto y = 0; y < subsheet.rows * TileHeight + 1; ++y) {
|
||||
set(i, {0, y}, {subsheet.columns * TileWidth, y}, pixOutlineColor);
|
||||
++i;
|
||||
}
|
||||
// tile outlines
|
||||
constexpr auto tileOutlineColor = color32(0.f, 0.f, 0.f);
|
||||
for (auto x = 0; x < img.columns() * TileWidth + 1; x += TileWidth) {
|
||||
set(i, {x, 0}, {x, img.rows() * TileHeight}, tileOutlineColor);
|
||||
for (auto x = 0; x < subsheet.columns * TileWidth + 1; x += TileWidth) {
|
||||
set(i, {x, 0}, {x, subsheet.rows * TileHeight}, tileOutlineColor);
|
||||
++i;
|
||||
}
|
||||
for (auto y = 0; y < img.rows() * TileHeight + 1; y += TileHeight) {
|
||||
set(i, {0, y}, {img.columns() * TileWidth, y}, tileOutlineColor);
|
||||
for (auto y = 0; y < subsheet.rows * TileHeight + 1; y += TileHeight) {
|
||||
set(i, {0, y}, {subsheet.columns * TileWidth, y}, tileOutlineColor);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user