[nostalgia/core/studio] Cleanup, make FrameBuffer resize use resizeInitFrameBuffer

This commit is contained in:
2023-03-11 15:00:04 -06:00
parent a5547487f8
commit 488f73f60f
7 changed files with 35 additions and 34 deletions
+22 -12
View File
@@ -31,18 +31,15 @@ void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept {
const auto uniformScroll = glGetUniformLocation(m_shader, "vScroll");
glUniform2f(uniformScroll, scroll.x, scroll.y);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
glUseProgram(0);
}
void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize) noexcept {
// vao
void TileSheetPixels::initBufferSet(geo::Vec2 const&paneSize) noexcept {
m_bufferSet.vao = glutils::generateVertexArrayObject();
glBindVertexArray(m_bufferSet.vao);
// vbo & ebo
m_bufferSet.vbo = glutils::generateBuffer();
m_bufferSet.ebo = glutils::generateBuffer();
setBufferObjects(paneSize);
glutils::sendVbo(m_bufferSet);
glutils::sendEbo(m_bufferSet);
update(paneSize);
// vbo layout
const auto posAttr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPosition"));
glEnableVertexAttribArray(posAttr);
@@ -53,6 +50,13 @@ void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize) noexcept {
reinterpret_cast<void*>(2 * sizeof(float)));
}
void TileSheetPixels::update(geo::Vec2 const&paneSize) noexcept {
glBindVertexArray(m_bufferSet.vao);
setBufferObjects(paneSize);
glutils::sendVbo(m_bufferSet);
glutils::sendEbo(m_bufferSet);
}
geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept {
const auto [sw, sh] = paneSize;
constexpr float ymod = 0.35f / 10.0f;
@@ -60,7 +64,13 @@ geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept {
return {xmod * m_pixelSizeMod, ymod * m_pixelSizeMod};
}
void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept {
void TileSheetPixels::setPixelBufferObject(
geo::Vec2 const&paneSize,
unsigned vertexRow,
float x, float y,
Color16 color,
float *vbo,
GLuint *ebo) const noexcept {
const auto [xmod, ymod] = pixelSize(paneSize);
x *= xmod;
y *= -ymod;
@@ -68,18 +78,18 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
y += 1.0f - ymod;
const auto r = redf(color), g = greenf(color), b = bluef(color);
// don't worry, these memcpys gets optimized to something much more ideal
const float vertices[VertexVboLength] = {
const ox::Array<float, VertexVboLength> vertices = {
x, y, r, g, b, // bottom left
x + xmod, y, r, g, b, // bottom right
x + xmod, y + ymod, r, g, b, // top right
x, y + ymod, r, g, b, // top left
};
memcpy(vbo, vertices, sizeof(vertices));
const GLuint elms[VertexEboLength] = {
memcpy(vbo, vertices.data(), sizeof(vertices));
const ox::Array<GLuint, VertexEboLength> elms = {
vertexRow + 0, vertexRow + 1, vertexRow + 2,
vertexRow + 2, vertexRow + 3, vertexRow + 0,
};
memcpy(ebo, elms, sizeof(elms));
memcpy(ebo, elms.data(), sizeof(elms));
}
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize) noexcept {