From 43ac2d1d067aacea67ba5c37a723585ecdbf130f Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 30 Aug 2022 15:59:38 -0400 Subject: [PATCH] Editor builds with some render code removed --- docs/tasks/refactoring.todo | 7 ++++ src/core/run_mode.h | 2 +- src/run_modes/editor/contents/tile_map.cpp | 30 ++++++------- src/run_modes/editor/contents/tile_map.h | 4 +- src/run_modes/editor/contents/tile_set.cpp | 39 ++++++++--------- src/run_modes/editor/contents/tile_set.h | 10 ++--- src/run_modes/editor/editor.cpp | 2 +- src/run_modes/editor/editor.h | 2 +- src/run_modes/editor/panels/asset_browser.cpp | 6 +-- src/run_modes/editor/panels/world_view.cpp | 25 +++++++---- src/run_modes/editor/panels/world_view.h | 11 +++-- .../editor/tools/map_editor/map_editor.cpp | 4 +- .../editor/tools/map_editor/map_editor.h | 4 +- .../tools/map_editor/panels/map_canvas.cpp | 22 +++++----- .../tools/map_editor/panels/map_canvas.h | 4 +- .../tools/map_editor/panels/tile_set_view.cpp | 42 ++++++++++--------- .../tools/map_editor/panels/tile_set_view.h | 6 +-- src/world/world.cpp | 3 +- src/world/world.h | 4 +- test_data/engine_state.json | 2 +- 20 files changed, 126 insertions(+), 103 deletions(-) diff --git a/docs/tasks/refactoring.todo b/docs/tasks/refactoring.todo index 4593327..2e9a9d3 100644 --- a/docs/tasks/refactoring.todo +++ b/docs/tasks/refactoring.todo @@ -6,6 +6,13 @@ Renderer rewrite: ☐ Re-integrate the new renderer into the editor + ✔ Clean up class name differences @done(22-08-30 15:58) + ☐ Hook up update and render calls between the core and the editor + ☐ Re-write render code in map tools and assets + ☐ Tilemap + ☐ TileSet + ☐ MapCanvas + ☐ TileSetView ✔ Add double buffer to the VertexBuffer class with a Flush method to send the verts to the gpu @high @done(22-08-29 15:14) ✔ Add Draw method to the VertexBuffer class @high @done(22-08-29 15:06) ✔ Batch rendering minimally working @done(22-08-12 19:19) diff --git a/src/core/run_mode.h b/src/core/run_mode.h index 55fbf26..c8c8e55 100644 --- a/src/core/run_mode.h +++ b/src/core/run_mode.h @@ -15,7 +15,7 @@ namespace lunarium { - class IGraphics; + class Renderer2D; class iRunMode { public: diff --git a/src/run_modes/editor/contents/tile_map.cpp b/src/run_modes/editor/contents/tile_map.cpp index 3b008b0..4765f0a 100644 --- a/src/run_modes/editor/contents/tile_map.cpp +++ b/src/run_modes/editor/contents/tile_map.cpp @@ -9,7 +9,7 @@ #include "tile_map.h" #include "tile_set.h" #include -#include +#include #include #include @@ -142,7 +142,7 @@ namespace lunarium { namespace editor } - void TileMap::Render(lunarium::IGraphics* g) + void TileMap::Render(lunarium::Renderer2D* g) { if (!mpMap) return; @@ -177,7 +177,9 @@ namespace lunarium { namespace editor Rectangle dest = Rectangle::MakeFromTopLeft(i * mTileSize.Width, j * mTileSize.Height, mTileSize.Width, mTileSize.Height); Rectangle src = set->GetTileRect(mpMap[i][j].TileIndex); - g->DrawImage(*set->GetImage(), src, dest, Color::White()); + //g->DrawImage(*set->GetImage(), src, dest, Color::White()); + + // DEBUG //g->DrawImage(*set->GetImage(), glm::vec2(dest.left(), dest.top()), Color::White()); //g->DrawImage(*set->GetImage(), Rectangle::MakeFromTopLeft(0, 0, 1024, 1024), dest, Color::White()); //g->DrawImage(*set->GetImage(), Rectangle::MakeFromTopLeft(16, 0, 16, 16), Rectangle::MakeFromTopLeft(0, 0, 500, 500), Color::White()); @@ -185,16 +187,16 @@ namespace lunarium { namespace editor } // Draw grid - for (int i = 0; i < mSizeInTiles.Width; i++) - { - g->DrawLine(glm::vec2(i * mTileSize.Width, 0), glm::vec2(i * mTileSize.Width, map_size_pixels.Height), Color::Black(), 1.0f); - } - g->DrawLine(glm::vec2(map_size_pixels.Width, 0), glm::vec2(map_size_pixels.Width, map_size_pixels.Height), Color::Black(), 1.0f); - - for (int j = 0; j < mSizeInTiles.Height; j++) - { - g->DrawLine(glm::vec2(0, j * mTileSize.Height), glm::vec2(map_size_pixels.Width, j * mTileSize.Height), Color::Black(), 1.0f); - } - g->DrawLine(glm::vec2(0, map_size_pixels.Height), glm::vec2(map_size_pixels.Width, map_size_pixels.Height), Color::Black(), 1.0f); + // for (int i = 0; i < mSizeInTiles.Width; i++) + // { + // g->DrawLine(glm::vec2(i * mTileSize.Width, 0), glm::vec2(i * mTileSize.Width, map_size_pixels.Height), Color::Black(), 1.0f); + // } + // g->DrawLine(glm::vec2(map_size_pixels.Width, 0), glm::vec2(map_size_pixels.Width, map_size_pixels.Height), Color::Black(), 1.0f); + + // for (int j = 0; j < mSizeInTiles.Height; j++) + // { + // g->DrawLine(glm::vec2(0, j * mTileSize.Height), glm::vec2(map_size_pixels.Width, j * mTileSize.Height), Color::Black(), 1.0f); + // } + // g->DrawLine(glm::vec2(0, map_size_pixels.Height), glm::vec2(map_size_pixels.Width, map_size_pixels.Height), Color::Black(), 1.0f); } }} diff --git a/src/run_modes/editor/contents/tile_map.h b/src/run_modes/editor/contents/tile_map.h index ac5a952..1b95504 100644 --- a/src/run_modes/editor/contents/tile_map.h +++ b/src/run_modes/editor/contents/tile_map.h @@ -14,7 +14,7 @@ #include #include -namespace lunarium { class IGraphics; } +namespace lunarium { class Renderer2D; } namespace lunarium { namespace editor { @@ -40,7 +40,7 @@ namespace lunarium { namespace editor Sizei GetTileSize(); // Call during render to texture phase - void Render(lunarium::IGraphics* g); + void Render(lunarium::Renderer2D* g); private: TileRef** mpMap; diff --git a/src/run_modes/editor/contents/tile_set.cpp b/src/run_modes/editor/contents/tile_set.cpp index b140d74..89a6df6 100644 --- a/src/run_modes/editor/contents/tile_set.cpp +++ b/src/run_modes/editor/contents/tile_set.cpp @@ -9,7 +9,8 @@ #include "tile_set.h" #include #include -#include +#include +#include #include #include #include @@ -32,7 +33,7 @@ namespace lunarium { namespace editor // Set some default values mTileSize = { 16, 16 }; - mNumTiles = { mSetImage->GetWidth() / 16, mSetImage->GetHeight() / 16 }; + mNumTiles = { (int)mSetImage->GetWidth() / 16, (int)mSetImage->GetHeight() / 16 }; return OpRes::OK(); } @@ -123,7 +124,7 @@ namespace lunarium { namespace editor return mTileSetID; } - void TileSet::SetImage(Image* image) + void TileSet::SetImage(lunarium::Texture* image) { mSetImage = image; } @@ -135,7 +136,7 @@ namespace lunarium { namespace editor mNumTiles.Height = mSetImage->GetHeight() / mTileSize.Height; } - Image* TileSet::GetImage() + lunarium::Texture* TileSet::GetImage() { return mSetImage; } @@ -150,21 +151,21 @@ namespace lunarium { namespace editor return Rectangle::MakeFromTopLeft(index.X * mTileSize.Width, index.Y * mTileSize.Height, mTileSize.Width, mTileSize.Height); } - void TileSet::Render(lunarium::IGraphics* g) + void TileSet::Render(lunarium::Renderer2D* g) { - g->DrawImage(*mSetImage, glm::vec2(0, 0), Color::White()); - - // Draw grid - for (int i = 0; i < mNumTiles.Width; i++) - { - g->DrawLine(glm::vec2(i * mTileSize.Width, 0), glm::vec2(i * mTileSize.Width, mSetImage->GetHeight()), Color::Black(), 1.0f); - } - g->DrawLine(glm::vec2(mSetImage->GetWidth(), 0), glm::vec2(mSetImage->GetWidth(), mSetImage->GetHeight()), Color::Black(), 1.0f); - - for (int j = 0; j < mNumTiles.Height; j++) - { - g->DrawLine(glm::vec2(0, j * mTileSize.Height), glm::vec2(mSetImage->GetWidth(), j * mTileSize.Height), Color::Black(), 1.0f); - } - g->DrawLine(glm::vec2(0, mSetImage->GetHeight()), glm::vec2(mSetImage->GetWidth(), mSetImage->GetHeight()), Color::Black(), 1.0f); + // g->DrawImage(*mSetImage, glm::vec2(0, 0), Color::White()); + + // // Draw grid + // for (int i = 0; i < mNumTiles.Width; i++) + // { + // g->DrawLine(glm::vec2(i * mTileSize.Width, 0), glm::vec2(i * mTileSize.Width, mSetImage->GetHeight()), Color::Black(), 1.0f); + // } + // g->DrawLine(glm::vec2(mSetImage->GetWidth(), 0), glm::vec2(mSetImage->GetWidth(), mSetImage->GetHeight()), Color::Black(), 1.0f); + + // for (int j = 0; j < mNumTiles.Height; j++) + // { + // g->DrawLine(glm::vec2(0, j * mTileSize.Height), glm::vec2(mSetImage->GetWidth(), j * mTileSize.Height), Color::Black(), 1.0f); + // } + // g->DrawLine(glm::vec2(0, mSetImage->GetHeight()), glm::vec2(mSetImage->GetWidth(), mSetImage->GetHeight()), Color::Black(), 1.0f); } }} \ No newline at end of file diff --git a/src/run_modes/editor/contents/tile_set.h b/src/run_modes/editor/contents/tile_set.h index f1a28c5..d7b377f 100644 --- a/src/run_modes/editor/contents/tile_set.h +++ b/src/run_modes/editor/contents/tile_set.h @@ -13,7 +13,7 @@ #include #include -namespace lunarium { class Image; class IGraphics; } +namespace lunarium { class Texture; class Renderer2D; } namespace lunarium { namespace editor { @@ -32,17 +32,17 @@ namespace lunarium { namespace editor void SetTileSetID(int id); int GetTileSetID() const; - void SetImage(Image* image); + void SetImage(lunarium::Texture* image); void SetTileSize(Sizei size); - Image* GetImage(); + lunarium::Texture* GetImage(); Sizei GetTileSize(); Rectangle GetTileRect(Vec2i index); - void Render(lunarium::IGraphics* g); + void Render(lunarium::Renderer2D* g); private: - Image* mSetImage; + lunarium::Texture* mSetImage; Sizei mTileSize; // in pixels, must be a square power of 2 Sizei mNumTiles; int mTileSetID; diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index d2d7ecb..d76f2b6 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -99,7 +99,7 @@ namespace editor HandleMenuEvents(); } - void Editor::OnRender(lunarium::IGraphics* g) + void Editor::OnRender(lunarium::Renderer2D* g) { DoMainMenu(); //DoStatusBar(); diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index 5e47fe1..eb21ce5 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -46,7 +46,7 @@ namespace lunarium { namespace editor [[nodiscard]] OpRes Initialize(); void Shutdown(); void OnUpdate(double delta); - void OnRender(lunarium::IGraphics* g); + void OnRender(lunarium::Renderer2D* g); bool IsToolOpen(ToolType type) const; diff --git a/src/run_modes/editor/panels/asset_browser.cpp b/src/run_modes/editor/panels/asset_browser.cpp index 8db7ccd..bdaceb6 100644 --- a/src/run_modes/editor/panels/asset_browser.cpp +++ b/src/run_modes/editor/panels/asset_browser.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include namespace lunarium { @@ -158,7 +158,7 @@ namespace editor } ImGui::SameLine(); - if (ImGui::ImageButton((ImTextureID)DataManager::mNewFolderIcon->GetGLTextureID64(), + if (ImGui::ImageButton((ImTextureID)DataManager::mNewFolderIcon->GetGLID64(), ImVec2(DataManager::mNewFolderIcon->GetWidth(), DataManager::mNewFolderIcon->GetHeight()), ImVec2(0, 0), ImVec2(1, 1), 4)) { @@ -175,7 +175,7 @@ namespace editor { if (dir_entry.is_directory()) { - ImGui::Image((ImTextureID)DataManager::mFolderIcon->GetGLTextureID64(), + ImGui::Image((ImTextureID)DataManager::mFolderIcon->GetGLID64(), ImVec2(DataManager::mFolderIcon->GetWidth(), DataManager::mFolderIcon->GetHeight())); ImGui::SameLine(); ImGui::Selectable(dir_entry.path().filename().string().c_str()); diff --git a/src/run_modes/editor/panels/world_view.cpp b/src/run_modes/editor/panels/world_view.cpp index cc32621..23c9e6d 100644 --- a/src/run_modes/editor/panels/world_view.cpp +++ b/src/run_modes/editor/panels/world_view.cpp @@ -8,8 +8,10 @@ #include "world_view.h" #include -#include -#include +#include +#include +#include +#include #include #include #include @@ -20,7 +22,7 @@ namespace lunarium { namespace editor { WorldView::WorldView() : Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr), - mFrameBuffer(-1), mPrevWidth(0), mPrevHeight(0), mpCanvasImage(nullptr) + mFrameBuffer(nullptr), mPrevWidth(0), mPrevHeight(0), mpCanvasImage(nullptr), mCamera(nullptr) { } @@ -36,12 +38,14 @@ namespace lunarium { namespace editor mPrevWidth = width; mPrevHeight = height; - if (mFrameBuffer > -1) + if (mFrameBuffer) { - Core::Graphics().DestroyRenderTexture(mFrameBuffer); + FrameBuffer::Destroy(&mFrameBuffer); + delete mCamera; } - mFrameBuffer = Core::Graphics().CreateRenderTexture(width, height, 4); + mFrameBuffer = FrameBuffer::Create(width, height); + mCamera = new OrthographicCamera({ 0.0f, 0.0f }, { (float)width, (float)height }); } // TODO: Handle view navigation input @@ -49,9 +53,12 @@ namespace lunarium { namespace editor // Render the current state of the world if (mpWorld) { - Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); + mFrameBuffer->Bind(); + Core::Graphics().BeginDraw(mCamera); mpWorld->Render(&Core::Graphics()); - mpCanvasImage = Core::GetInstance().EndRenderToTexture(); + Core::Graphics().EndDraw(); + mFrameBuffer->Unbind(); + mpCanvasImage = mFrameBuffer->GetTexture(); } } @@ -62,7 +69,7 @@ namespace lunarium { namespace editor // Draw world render if (mpCanvasImage) { - ImGui::Image((ImTextureID)mpCanvasImage->GetGLTextureID64(), + ImGui::Image((ImTextureID)mpCanvasImage->GetGLID64(), ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); } } diff --git a/src/run_modes/editor/panels/world_view.h b/src/run_modes/editor/panels/world_view.h index e471e4c..4997dde 100644 --- a/src/run_modes/editor/panels/world_view.h +++ b/src/run_modes/editor/panels/world_view.h @@ -13,8 +13,10 @@ namespace lunarium { - class Image; - class World; + class Texture; + class World; + class FrameBuffer; + class OrthographicCamera; namespace editor { @@ -35,8 +37,9 @@ namespace editor Editor* mpEditor; int mPrevWidth; int mPrevHeight; - int mFrameBuffer; - Image* mpCanvasImage; + lunarium::FrameBuffer* mFrameBuffer; + lunarium::OrthographicCamera* mCamera; + lunarium::Texture* mpCanvasImage; }; }} // lunarium::editor diff --git a/src/run_modes/editor/tools/map_editor/map_editor.cpp b/src/run_modes/editor/tools/map_editor/map_editor.cpp index e12cd05..bf46f0c 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.cpp +++ b/src/run_modes/editor/tools/map_editor/map_editor.cpp @@ -9,7 +9,7 @@ #include "map_editor.h" #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ namespace lunarium { namespace editor mPanelManager.OnTick(delta); } - bool MapEditor::OnRender(lunarium::IGraphics* g) + bool MapEditor::OnRender(lunarium::Renderer2D* g) { if (!mIsOpen) { diff --git a/src/run_modes/editor/tools/map_editor/map_editor.h b/src/run_modes/editor/tools/map_editor/map_editor.h index 798d235..02d883c 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.h +++ b/src/run_modes/editor/tools/map_editor/map_editor.h @@ -17,7 +17,7 @@ #include namespace lunarium { - class IGraphics; + class Renderer2D; namespace gui { class Panel; @@ -36,7 +36,7 @@ namespace editor OpRes Initialize(Editor* editor); void Shutdown(); void OnTick(double delta); - bool OnRender(lunarium::IGraphics* g); + bool OnRender(lunarium::Renderer2D* g); void Open(); void Close(); diff --git a/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp b/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp index b3ae5aa..adbb621 100644 --- a/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp +++ b/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -109,22 +109,22 @@ namespace lunarium { namespace editor { if (mMapSizeChanged) { - Core::Graphics().DestroyRenderTexture(mFrameBuffer); + //Core::Graphics().DestroyRenderTexture(mFrameBuffer); mFrameBuffer = -1; mMapSizeChanged = false; } if (mFrameBuffer == -1) { - mFrameBuffer = Core::Graphics().CreateRenderTexture(mMap->GetSizeInPixels().Width, mMap->GetSizeInPixels().Height, 4); + //mFrameBuffer = Core::Graphics().CreateRenderTexture(mMap->GetSizeInPixels().Width, mMap->GetSizeInPixels().Height, 4); } - Color prev = Core::Graphics().GetClearColor(); - Core::Graphics().SetClearColor(Color::Transparent()); - Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); - mMap->Render(&Core::Graphics()); - mpCanvasImage = Core::GetInstance().EndRenderToTexture(); - Core::Graphics().SetClearColor(prev); + // Color prev = Core::Graphics().GetClearColor(); + // Core::Graphics().SetClearColor(Color::Transparent()); + // Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); + // mMap->Render(&Core::Graphics()); + // mpCanvasImage = Core::GetInstance().EndRenderToTexture(); + // Core::Graphics().SetClearColor(prev); } } } @@ -178,7 +178,7 @@ namespace lunarium { namespace editor //ImGui::Text(mMouseStatusInfo.c_str()); if (mpCanvasImage) { - ImGui::Image((ImTextureID)mpCanvasImage->GetGLTextureID64(), + ImGui::Image((ImTextureID)mpCanvasImage->GetGLID64(), ImVec2(mpCanvasImage->GetWidth() * mZoomFactor, mpCanvasImage->GetHeight() * mZoomFactor), ImVec2(0, 1), ImVec2(1, 0)); } diff --git a/src/run_modes/editor/tools/map_editor/panels/map_canvas.h b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h index 7e517f8..8606c09 100644 --- a/src/run_modes/editor/tools/map_editor/panels/map_canvas.h +++ b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h @@ -13,7 +13,7 @@ #include #include -namespace lunarium { class Image; class IGraphics; } +namespace lunarium { class Texture; class Renderer2D; } namespace lunarium { namespace editor { @@ -46,7 +46,7 @@ namespace lunarium { namespace editor float mZoomFactor; std::string mMouseStatusInfo; int mFrameBuffer; - Image* mpCanvasImage; + lunarium::Texture* mpCanvasImage; TileMap* mMap; // TODO: Replace with a World TileRef mSelectedTile; bool mMapSizeChanged; diff --git a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp index 942d34c..ccebbca 100644 --- a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp +++ b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include @@ -21,7 +22,7 @@ namespace lunarium { namespace editor { TileSetView::TileSetView(MapEditor* editor) : Panel("Tile Set View", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_HorizontalScrollbar), - mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1), + mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(nullptr), mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false) { @@ -68,26 +69,28 @@ namespace lunarium { namespace editor { if (mpSelectedTileSet) { - if (mFrameBuffer == -1) + if (!mFrameBuffer) { - mFrameBuffer = Core::Graphics().CreateRenderTexture(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight(), 4); + mFrameBuffer = FrameBuffer::Create(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight()); } - Color prev = Core::Graphics().GetClearColor(); - Core::Graphics().SetClearColor(Color::Transparent()); - Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); + // Color prev = Core::Graphics().GetClearColor(); + // Core::Graphics().SetClearColor(Color::Transparent()); + // Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); - mpSelectedTileSet->Render(&Core::Graphics()); + // mpSelectedTileSet->Render(&Core::Graphics()); - // Draw selected tile highlight - if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0) - { - Rectangle selection = mpSelectedTileSet->GetTileRect(mSelectedTile); - Core::Graphics().DrawBox(selection, Color::Red(), 1.5f); - } + // // Draw selected tile highlight + // if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0) + // { + // Rectangle selection = mpSelectedTileSet->GetTileRect(mSelectedTile); + // Core::Graphics().DrawBox(selection, Color::Red(), 1.5f); + // } + + // mpViewImage = Core::GetInstance().EndRenderToTexture(); + // Core::Graphics().SetClearColor(prev); + - mpViewImage = Core::GetInstance().EndRenderToTexture(); - Core::Graphics().SetClearColor(prev); // //stbi_flip_vertically_on_write(1); // stbi_write_png("tileset_test_image.png", mpViewImage->GetWidth(), mpViewImage->GetHeight(), 4, @@ -150,7 +153,7 @@ namespace lunarium { namespace editor if (mpViewImage) { - ImGui::Image((ImTextureID)mpViewImage->GetGLTextureID64(), + ImGui::Image((ImTextureID)mpViewImage->GetGLID64(), ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y } } @@ -188,10 +191,9 @@ namespace lunarium { namespace editor void TileSetView::Invalidate(bool remake_frame_buffer) { mInvalidate = true; - if (remake_frame_buffer && mFrameBuffer != -1) + if (remake_frame_buffer && mFrameBuffer) { - Core::Graphics().DestroyRenderTexture(mFrameBuffer); - mFrameBuffer = -1; + FrameBuffer::Destroy(&mFrameBuffer); } } }} \ No newline at end of file diff --git a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h index d4d267d..5c03b8d 100644 --- a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h +++ b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h @@ -14,7 +14,7 @@ #include #include -namespace lunarium { class Image; } +namespace lunarium { class Texture; class FrameBuffer; } namespace lunarium { namespace editor { @@ -41,9 +41,9 @@ namespace lunarium { namespace editor MapEditor* mpEditor; std::map mTileSets; TileSet* mpSelectedTileSet; - int mFrameBuffer; + lunarium::FrameBuffer* mFrameBuffer; bool mInvalidate; - Image* mpViewImage; + lunarium::Texture* mpViewImage; Vec2i mViewOffset; float mViewZoom; Vec2i mSelectedTile; diff --git a/src/world/world.cpp b/src/world/world.cpp index 2c85624..20489aa 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "entity.h" @@ -45,7 +46,7 @@ namespace lunarium // TODO: Update all entities } - void World::Render(lunarium::IGraphics* pGraphics) const + void World::Render(lunarium::Renderer2D* pGraphics) const { OrthographicCamera* pCam = mpActiveCamera; diff --git a/src/world/world.h b/src/world/world.h index 7d0e553..1b09011 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -23,7 +23,7 @@ namespace lunarium { - class IGraphics; + class Renderer2D; class Image; class Script; class OrthographicCamera; @@ -59,7 +59,7 @@ namespace lunarium void OnLoad(); void OnUnload(); void Update(float dt); - void Render(lunarium::IGraphics* pGraphics) const; + void Render(lunarium::Renderer2D* pGraphics) const; void SetActiveCamera(OrthographicCamera* pCam); diff --git a/test_data/engine_state.json b/test_data/engine_state.json index a338efe..5004d9f 100644 --- a/test_data/engine_state.json +++ b/test_data/engine_state.json @@ -2,7 +2,7 @@ "State": { "DataDirectory": "data/", - "Mode": "test", + "Mode": "editor", "Display": {