diff --git a/src/nostalgia/core/studio/consts.hpp b/src/nostalgia/core/studio/consts.hpp deleted file mode 100644 index a5c3f190..00000000 --- a/src/nostalgia/core/studio/consts.hpp +++ /dev/null @@ -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/"; - -} diff --git a/src/nostalgia/core/studio/module.cpp b/src/nostalgia/core/studio/module.cpp index 044cc507..e7f2e0b4 100644 --- a/src/nostalgia/core/studio/module.cpp +++ b/src/nostalgia/core/studio/module.cpp @@ -14,7 +14,7 @@ namespace nostalgia::core { ox::Vector StudioModule::editors(core::Context *ctx) noexcept { return { { - {"ng"}, + {FileExt_ng}, [ctx](ox::CRStringView path) -> ox::Result { try { return ox::make(ctx, path); @@ -24,7 +24,7 @@ ox::Vector StudioModule::editors(core::Context *ctx) noexce } }, { - {"npal"}, + {FileExt_npal}, [ctx](ox::CRStringView path) -> ox::Result { return PaletteEditorImGui::make(ctx, path); } diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index 72971ed1..191b12f7 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -46,7 +46,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(Context *ctx, ox::CRStringView path): // init palette idx const auto &palPath = model()->palPath(); auto sctx = applicationData(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(fbSize.x), static_cast(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(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)) { diff --git a/src/nostalgia/core/studio/tilesheeteditorview.cpp b/src/nostalgia/core/studio/tilesheeteditorview.cpp index 4b301197..e22ad785 100644 --- a/src/nostalgia/core/studio/tilesheeteditorview.cpp +++ b/src/nostalgia/core/studio/tilesheeteditorview.cpp @@ -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(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 {}; } } diff --git a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp index 10b05999..a67a5fa1 100644 --- a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp +++ b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp @@ -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(m_bufferSet.vertices.size() / VertexVboRowLength)); + glBindVertexArray(0); + glUseProgram(0); } void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept { diff --git a/src/nostalgia/core/studio/tilesheetpixels.cpp b/src/nostalgia/core/studio/tilesheetpixels.cpp index f6d759b5..3ad0e6cf 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.cpp +++ b/src/nostalgia/core/studio/tilesheetpixels.cpp @@ -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(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(glGetAttribLocation(m_shader, "vPosition")); glEnableVertexAttribArray(posAttr); @@ -53,6 +50,13 @@ void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize) noexcept { reinterpret_cast(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 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 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 { diff --git a/src/nostalgia/core/studio/tilesheetpixels.hpp b/src/nostalgia/core/studio/tilesheetpixels.hpp index 738c9eb9..d09ceea5 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.hpp +++ b/src/nostalgia/core/studio/tilesheetpixels.hpp @@ -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;