[nostalgia/core/studio] Cleanup, make FrameBuffer resize use resizeInitFrameBuffer
This commit is contained in:
parent
a5547487f8
commit
488f73f60f
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
constexpr auto ModuleName = "NostalgiaCore";
|
||||
constexpr auto TileSheetDir = "/TileSheets/";
|
||||
constexpr auto PaletteDir = "/Palettes/";
|
||||
|
||||
}
|
@ -14,7 +14,7 @@ namespace nostalgia::core {
|
||||
ox::Vector<studio::EditorMaker> StudioModule::editors(core::Context *ctx) noexcept {
|
||||
return {
|
||||
{
|
||||
{"ng"},
|
||||
{FileExt_ng},
|
||||
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
||||
try {
|
||||
return ox::make<TileSheetEditorImGui>(ctx, path);
|
||||
@ -24,7 +24,7 @@ ox::Vector<studio::EditorMaker> StudioModule::editors(core::Context *ctx) noexce
|
||||
}
|
||||
},
|
||||
{
|
||||
{"npal"},
|
||||
{FileExt_npal},
|
||||
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
||||
return PaletteEditorImGui::make(ctx, path);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(Context *ctx, ox::CRStringView path):
|
||||
// init palette idx
|
||||
const auto &palPath = model()->palPath();
|
||||
auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
const auto &palList = sctx->project->fileList(core::FileExt_npal + 1);
|
||||
const auto &palList = sctx->project->fileList(core::FileExt_npal);
|
||||
for (std::size_t i = 0; const auto &pal : palList) {
|
||||
if (palPath == pal) {
|
||||
m_selectedPaletteIdx = i;
|
||||
@ -278,10 +278,9 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
|
||||
const auto winPos = ImGui::GetWindowPos();
|
||||
const auto fbSizei = geo::Size(static_cast<int>(fbSize.x), static_cast<int>(fbSize.y));
|
||||
if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) {
|
||||
m_framebuffer = glutils::generateFrameBuffer(fbSizei.width, fbSizei.height);
|
||||
glutils::resizeInitFrameBuffer(&m_framebuffer, fbSizei.width, fbSizei.height);
|
||||
m_tileSheetEditor.resizeView(fbSize);
|
||||
} else if (m_tileSheetEditor.updated()) {
|
||||
m_tileSheetEditor.resizeView(fbSize);
|
||||
m_tileSheetEditor.ackUpdate();
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
@ -344,7 +343,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
|
||||
|
||||
void TileSheetEditorImGui::drawPaletteSelector() noexcept {
|
||||
auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
const auto &files = sctx->project->fileList(core::FileExt_npal + 1);
|
||||
const auto &files = sctx->project->fileList(core::FileExt_npal);
|
||||
const auto first = m_selectedPaletteIdx < files.size() ?
|
||||
files[m_selectedPaletteIdx].c_str() : "";
|
||||
if (ImGui::BeginCombo("Palette", first, 0)) {
|
||||
|
@ -76,7 +76,7 @@ void TileSheetEditorView::clickSelect(const geo::Vec2 &paneSize, const geo::Vec2
|
||||
|
||||
void TileSheetEditorView::clickFill(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept {
|
||||
const auto pt = clickPoint(paneSize, clickPos);
|
||||
m_model.fill(pt, m_palIdx);
|
||||
m_model.fill(pt, static_cast<int>(m_palIdx));
|
||||
}
|
||||
|
||||
void TileSheetEditorView::releaseMouseButton() noexcept {
|
||||
@ -100,6 +100,7 @@ ox::Error TileSheetEditorView::markUpdated() noexcept {
|
||||
|
||||
void TileSheetEditorView::ackUpdate() noexcept {
|
||||
m_updated = false;
|
||||
m_pixelsDrawer.update(m_viewSize);
|
||||
m_model.ackUpdate();
|
||||
}
|
||||
|
||||
@ -122,7 +123,7 @@ geo::Point TileSheetEditorView::clickPoint(const geo::Vec2 &paneSize, const geo:
|
||||
|
||||
ox::Error TileSheetEditorView::setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept {
|
||||
initView();
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept {
|
||||
const auto uniformScroll = glGetUniformLocation(m_shader, "gScroll");
|
||||
glUniform2f(uniformScroll, scroll.x, scroll.y);
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(m_bufferSet.vertices.size() / VertexVboRowLength));
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept {
|
||||
|
@ -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 {
|
||||
|
@ -51,7 +51,9 @@ class TileSheetPixels {
|
||||
|
||||
void draw(bool update, const geo::Vec2 &scroll) noexcept;
|
||||
|
||||
void initBufferSet(const geo::Vec2 &paneSize) noexcept;
|
||||
void initBufferSet(geo::Vec2 const&paneSize) noexcept;
|
||||
|
||||
void update(geo::Vec2 const&paneSize) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
|
||||
|
Loading…
x
Reference in New Issue
Block a user