From db91ea6a6358bfeafd081613ff6706a7528107a6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 6 Dec 2023 23:56:49 -0600 Subject: [PATCH] [glutils,nostalgia] Ptr to ref changes --- src/glutils/glutils.cpp | 28 +++++++++++-------- src/glutils/glutils.hpp | 8 +++--- .../core/src/studio/tilesheeteditor-imgui.cpp | 11 +++++--- .../scene/src/studio/sceneeditorview.cpp | 4 +-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/glutils/glutils.cpp b/src/glutils/glutils.cpp index a5a2e95e..7c077bf0 100644 --- a/src/glutils/glutils.cpp +++ b/src/glutils/glutils.cpp @@ -129,8 +129,9 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept { glGenTextures(1, &fb.color.id); glBindTexture(GL_TEXTURE_2D, fb.color); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0); // depth texture glGenRenderbuffers(1, &fb.depth.id); @@ -146,21 +147,24 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept { return fb; } -void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept { - if (!*fb) { - *fb = generateFrameBuffer(width, height); +void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept { + if (!fb) { + fb = generateFrameBuffer(width, height); return; } width = ox::max(1, width); height = ox::max(1, height); - fb->width = width; - fb->height = height; - glBindFramebuffer(GL_FRAMEBUFFER, *fb); + fb.width = width; + fb.height = height; + glBindFramebuffer(GL_FRAMEBUFFER, fb); // color texture - glBindTexture(GL_TEXTURE_2D, fb->color); + glBindTexture(GL_TEXTURE_2D, fb.color); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); // depth texture - glBindRenderbuffer(GL_RENDERBUFFER, fb->depth); + glBindRenderbuffer(GL_RENDERBUFFER, fb.depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); // restore primary FB glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -168,13 +172,13 @@ void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept { glBindRenderbuffer(GL_RENDERBUFFER, 0); } -void sendVbo(const BufferSet &bs) noexcept { +void sendVbo(BufferSet const&bs) noexcept { const auto bufferSize = static_cast(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size()); glBindBuffer(GL_ARRAY_BUFFER, bs.vbo); glBufferData(GL_ARRAY_BUFFER, bufferSize, bs.vertices.data(), GL_DYNAMIC_DRAW); } -void sendEbo(const BufferSet &bs) noexcept { +void sendEbo(BufferSet const&bs) noexcept { const auto bufferSize = static_cast(sizeof(decltype(bs.elements)::value_type) * bs.elements.size()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bs.ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, bs.elements.data(), GL_STATIC_DRAW); diff --git a/src/glutils/glutils.hpp b/src/glutils/glutils.hpp index 3fe28631..c7a57d71 100644 --- a/src/glutils/glutils.hpp +++ b/src/glutils/glutils.hpp @@ -162,7 +162,7 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept; /** * Resizes a FrameBuffer, and creates if it does not already exist. */ -void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept; +void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept; struct BufferSet { glutils::GLVertexArray vao; @@ -173,9 +173,9 @@ struct BufferSet { ox::Vector elements; }; -void sendVbo(const BufferSet &bs) noexcept; - -void sendEbo(const BufferSet &bs) noexcept; +void sendVbo(BufferSet const&bs) noexcept; + +void sendEbo(BufferSet const&bs) noexcept; void clearScreen() noexcept; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp index 450023b3..b8531567 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp @@ -13,10 +13,12 @@ namespace nostalgia::core { template -ox::Error toPngFile(ox::CStringView const&path, TileSheet::SubSheet const&s, Palette const&pal, int8_t bpp) noexcept { +ox::Error toPngFile( + ox::CStringView const&path, TileSheet::SubSheet const&s, Palette const&pal, int8_t bpp) noexcept { ox::Vector pixels; s.readPixelsTo(&pixels, bpp); - const unsigned rows = s.rows == -1 ? static_cast(pixels.size()) / PixelsPerTile : static_cast(s.rows); + const unsigned rows = s.rows == -1 ? + static_cast(pixels.size()) / PixelsPerTile : static_cast(s.rows); const unsigned cols = s.columns == -1 ? 1 : static_cast(s.columns); const auto width = cols * TileWidth; const auto height = rows * TileHeight; @@ -35,7 +37,8 @@ ox::Error toPngFile(ox::CStringView const&path, TileSheet::SubSheet const&s, Pal ++idx; } constexpr auto fmt = alpha ? LCT_RGBA : LCT_RGB; - return OxError(static_cast(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8))); + return OxError(static_cast( + lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8))); } TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path): @@ -280,7 +283,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { const auto winPos = ImGui::GetWindowPos(); const auto fbSizei = ox::Size(static_cast(fbSize.x), static_cast(fbSize.y)); if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) { - glutils::resizeInitFrameBuffer(&m_framebuffer, fbSizei.width, fbSizei.height); + glutils::resizeInitFrameBuffer(m_framebuffer, fbSizei.width, fbSizei.height); m_tileSheetEditor.resizeView(fbSize); } else if (m_tileSheetEditor.updated()) { m_tileSheetEditor.ackUpdate(); diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp index 2aec80b3..e215678f 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp @@ -20,9 +20,9 @@ ox::Error SceneEditorView::setupScene() noexcept { void SceneEditorView::draw(int width, int height) noexcept { if (width != m_frameBuffer.width || height != m_frameBuffer.height) { - glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height); + glutils::resizeInitFrameBuffer(m_frameBuffer, width, height); } - const glutils::FrameBufferBind frameBufferBind(m_frameBuffer); + glutils::FrameBufferBind const frameBufferBind(m_frameBuffer); core::gl::draw(*m_cctx, {width, height}); }