diff --git a/TSE_Core/src/elements/Texture.cpp b/TSE_Core/src/elements/Texture.cpp index ab675cf..2e24ad1 100644 --- a/TSE_Core/src/elements/Texture.cpp +++ b/TSE_Core/src/elements/Texture.cpp @@ -118,12 +118,12 @@ TSE::Vector2 TSE::Texture::size() const return Size; } -float TSE::Texture::width() const +float TSE::Texture::Width() const { return Size.x; } -float TSE::Texture::height() const +float TSE::Texture::Height() const { return Size.y; } @@ -181,9 +181,9 @@ void TSE::Texture::SetPixel(const int &x, const int &y, const Color &c) void TSE::Texture::GetPixel(const int &x, const int &y, Color &c) const { - if(x >= width() || x < 0 ||y >= height() || y < 0) + if(x >= Width() || x < 0 ||y >= Height() || y < 0) { - TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) ); + TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(Width()) + ";" + std::to_string(Height()) ); return; } byte* pixel = getPixelPointer(x,y); @@ -201,9 +201,9 @@ void TSE::Texture::GetPixel(const int &x, const int &y, Color &c) const void TSE::Texture::Fill(const Color &c) { - for (int x = 0; x < width(); x++) + for (int x = 0; x < Width(); x++) { - for (int y = 0; y < height(); y++) + for (int y = 0; y < Height(); y++) { SetPixelNoApply(x,y,c); } @@ -214,9 +214,9 @@ void TSE::Texture::Fill(const Color &c) void TSE::Texture::SetPixelNoApply(const int &x, const int &y, const Color &c) { - if(x >= width() || x < 0 ||y >= height() || y < 0) + if(x >= Width() || x < 0 ||y >= Height() || y < 0) { - TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) ); + TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(Width()) + ";" + std::to_string(Height()) ); return; } @@ -244,9 +244,9 @@ void TSE::Texture::SetPixelNoApply(const int &x, const int &y, const Color &c) void TSE::Texture::AddPixelNoApply(const int &x, const int &y, const Color &c) { - if(x >= width() || x < 0 ||y >= height() || y < 0) + if(x >= Width() || x < 0 ||y >= Height() || y < 0) { - TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) ); + TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(Width()) + ";" + std::to_string(Height()) ); return; } @@ -307,7 +307,7 @@ TSE::byte *TSE::Texture::getPixelPointer(const int &x, const int &y) const int alphaoffset = y * 2; if(bpp() > 24) alphaoffset = 0; - int offset = ((y * width() + x) * (bpp() / 8) + alphaoffset); + int offset = ((y * Width() + x) * (bpp() / 8) + alphaoffset); return imagePtr + offset; } diff --git a/TSE_Core/src/elements/Texture.hpp b/TSE_Core/src/elements/Texture.hpp index 6b29792..8ad3426 100644 --- a/TSE_Core/src/elements/Texture.hpp +++ b/TSE_Core/src/elements/Texture.hpp @@ -32,8 +32,8 @@ namespace TSE uint bpp() const; Vector2 size() const override; - float width() const override; - float height() const override; + float Width() const override; + float Height() const override; byte Chanels() const; byte* GetImagePtr() const; void SetPixel(const Vector2& pos, const Color& c); diff --git a/TSE_Core/src/interfaces/IRenderTexture.hpp b/TSE_Core/src/interfaces/IRenderTexture.hpp new file mode 100644 index 0000000..30db441 --- /dev/null +++ b/TSE_Core/src/interfaces/IRenderTexture.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "IResizeNotifiable.hpp" +#include "IRenderTarget.hpp" +#include "ITexture.hpp" + +namespace TSE +{ + class IRenderTextureCreator; + + class IRenderTexture : public IRenderTarget, public ITexture, public IResizeNotifiable + { + public: + inline static IRenderTextureCreator* factory = nullptr; + virtual void SetSize(Vector2 v) = 0; + }; + + class IRenderTextureCreator + { + public: + virtual IRenderTexture* CreateTextureHeap(Vector2 v) = 0; + }; +} // namespace TSE diff --git a/TSE_Core/src/interfaces/ITexture.hpp b/TSE_Core/src/interfaces/ITexture.hpp index 2794bba..3d9c760 100644 --- a/TSE_Core/src/interfaces/ITexture.hpp +++ b/TSE_Core/src/interfaces/ITexture.hpp @@ -9,8 +9,8 @@ namespace TSE public: virtual ~ITexture() = default; virtual Vector2 size() const = 0; - virtual float width() const = 0; - virtual float height() const = 0; + virtual float Width() const = 0; + virtual float Height() const = 0; virtual uint GetTextureId() const = 0; }; } // namespace TSE diff --git a/TSE_Editor/CMakeLists.txt b/TSE_Editor/CMakeLists.txt index 7e9b77e..f8f4598 100644 --- a/TSE_Editor/CMakeLists.txt +++ b/TSE_Editor/CMakeLists.txt @@ -46,10 +46,6 @@ include_directories(${PROJECT_SOURCE_DIR}/../TSE_Base/include) include_directories(${PROJECT_SOURCE_DIR}/../TSE_Math/src) include_directories(${PROJECT_SOURCE_DIR}/../TSE_Core/src) include_directories(${PROJECT_SOURCE_DIR}/../TSE_Core/include) -include_directories(${PROJECT_SOURCE_DIR}/../TSE_GlfwImpl/src) -include_directories(${PROJECT_SOURCE_DIR}/../TSE_GlfwImpl/include) -include_directories(${PROJECT_SOURCE_DIR}/../TSE_GlfwOpenGlImpl/src) -include_directories(${PROJECT_SOURCE_DIR}/../TSE_GlfwOpenGlImpl/include) #project def if(Lib) diff --git a/TSE_Editor/src/EditorSubsystem.cpp b/TSE_Editor/src/EditorSubsystem.cpp index db43674..9a5df0c 100644 --- a/TSE_Editor/src/EditorSubsystem.cpp +++ b/TSE_Editor/src/EditorSubsystem.cpp @@ -4,7 +4,7 @@ TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("") { - rt = new TSE::GLFW::RenderTexture({100,100}); + rt = IRenderTexture::factory->CreateTextureHeap({100,100}); sv = SceneView(rt); controller.AddGuiElement("Scene", &sv); diff --git a/TSE_Editor/src/EditorSubsystem.hpp b/TSE_Editor/src/EditorSubsystem.hpp index a3f9ac4..861c4d0 100644 --- a/TSE_Editor/src/EditorSubsystem.hpp +++ b/TSE_Editor/src/EditorSubsystem.hpp @@ -7,7 +7,7 @@ #include "UI/windows/HirearchieView.hpp" #include "UI/windows/PropertiesView.hpp" #include "UI/windows/SceneView.hpp" -#include "RenderTexture.hpp" +#include "interfaces/IRenderTexture.hpp" namespace TSE::EDITOR { @@ -20,7 +20,7 @@ namespace TSE::EDITOR HirearchieView hv = HirearchieView(nullptr); PropertiesView pv; CameraView camv; - TSE::GLFW::RenderTexture* rt; + TSE::IRenderTexture* rt; SceneView sv; Layer editorLayer; diff --git a/TSE_Editor/src/UI/ElementDrawer.cpp b/TSE_Editor/src/UI/ElementDrawer.cpp index 32bf2fb..307cc15 100644 --- a/TSE_Editor/src/UI/ElementDrawer.cpp +++ b/TSE_Editor/src/UI/ElementDrawer.cpp @@ -882,7 +882,7 @@ namespace TSE::EDITOR ImVec2 field_size = ImVec2(field_width, 60); Rect r = element->GetUVRect(); - float ymultiplyer = (element->GetTexture()->height() * r.height()) / (element->GetTexture()->width() * r.width()); + float ymultiplyer = (element->GetTexture()->Height() * r.height()) / (element->GetTexture()->Width() * r.width()); ImVec2 texSize (field_size.y - 2, (field_size.y - 2) * ymultiplyer); @@ -916,7 +916,7 @@ namespace TSE::EDITOR } ImGui::Separator(); float available_width = ImGui::GetContentRegionAvail().x; - float ymultiplyer = (element->GetTexture()->height() * r.height()) / (element->GetTexture()->width() * r.width()); + float ymultiplyer = (element->GetTexture()->Height() * r.height()) / (element->GetTexture()->Width() * r.width()); ImVec2 texSize (available_width, (available_width) * ymultiplyer); ImGui::Image(element->GetTexture()->GetTextureId(), texSize, {r.p1.x,r.p2.y}, {r.p2.x,r.p1.y}); @@ -931,7 +931,7 @@ namespace TSE::EDITOR ImVec2 field_size = ImVec2(field_width, 60); - float ymultiplyer = element->height() / element->width(); + float ymultiplyer = element->Height() / element->Width(); ImVec2 texSize (field_size.y - 2, (field_size.y - 2) * ymultiplyer); @@ -963,8 +963,8 @@ namespace TSE::EDITOR if(debug) { ImGui::Separator(); - ImGui::TextDisabled(("Width: " + std::to_string(element->width())).c_str()); - ImGui::TextDisabled(("Height: " + std::to_string(element->height())).c_str()); + ImGui::TextDisabled(("Width: " + std::to_string(element->Width())).c_str()); + ImGui::TextDisabled(("Height: " + std::to_string(element->Height())).c_str()); ImGui::TextDisabled(("BPP: " + std::to_string(element->bpp())).c_str()); ImGui::TextDisabled(("Chanels: " + std::to_string(element->Chanels())).c_str()); ImGui::Separator(); @@ -972,7 +972,7 @@ namespace TSE::EDITOR } ImGui::Separator(); float available_width = ImGui::GetContentRegionAvail().x; - float ymultiplyer = element->height() / element->width(); + float ymultiplyer = element->Height() / element->Width(); ImVec2 texSize (available_width, (available_width) * ymultiplyer); ImGui::Image(element->GetTextureId(), texSize, {0,1}, {1,0}); diff --git a/TSE_Editor/src/UI/windows/CameraView.cpp b/TSE_Editor/src/UI/windows/CameraView.cpp index cad53c8..58fdf9b 100644 --- a/TSE_Editor/src/UI/windows/CameraView.cpp +++ b/TSE_Editor/src/UI/windows/CameraView.cpp @@ -2,7 +2,7 @@ TSE::EDITOR::CameraView::CameraView() : GuiWindow("Camera", ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar) { - fb = new TSE::GLFW::RenderTexture({100,100}); + fb = IRenderTexture::factory->CreateTextureHeap({100,100}); } void TSE::EDITOR::CameraView::Define() @@ -19,9 +19,9 @@ void TSE::EDITOR::CameraView::Define() ImGuiWindowFlags flags2 = ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; if(ImGui::BeginChild("##SceneChild", {0,0}, ImGuiChildFlags_None, flags2)) { - ImGui::Image(fb->GetTextureId(), {fb->width(), fb->height()},{0,1}, {1,0}); + ImGui::Image(fb->GetTextureId(), {fb->Width(), fb->Height()},{0,1}, {1,0}); auto vec2 = ImGui::GetWindowSize(); - if(fb->width() != vec2.x || fb->height() != vec2.y) + if(fb->Width() != vec2.x || fb->Height() != vec2.y) { fb->SetSize({vec2.x, vec2.y}); } diff --git a/TSE_Editor/src/UI/windows/CameraView.hpp b/TSE_Editor/src/UI/windows/CameraView.hpp index e352923..936a144 100644 --- a/TSE_Editor/src/UI/windows/CameraView.hpp +++ b/TSE_Editor/src/UI/windows/CameraView.hpp @@ -1,7 +1,7 @@ #pragma once #include "UI/base/GuiWindow.h" -#include "RenderTexture.hpp" +#include "interfaces/IRenderTexture.hpp" #include "BehaviourScripts/Camera.hpp" namespace TSE::EDITOR @@ -10,7 +10,7 @@ namespace TSE::EDITOR { private: Camera* currentCamera = nullptr; - TSE::GLFW::RenderTexture* fb; + TSE::IRenderTexture* fb; public: CameraView(); void Define() override; diff --git a/TSE_Editor/src/UI/windows/SceneView.cpp b/TSE_Editor/src/UI/windows/SceneView.cpp index 596c0b6..93cb4a4 100644 --- a/TSE_Editor/src/UI/windows/SceneView.cpp +++ b/TSE_Editor/src/UI/windows/SceneView.cpp @@ -1,6 +1,6 @@ #include "SceneView.hpp" -TSE::EDITOR::SceneView::SceneView(TSE::GLFW::RenderTexture *frameBuffer) : GuiWindow("Scene", ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar) +TSE::EDITOR::SceneView::SceneView(TSE::IRenderTexture *frameBuffer) : GuiWindow("Scene", ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar) { fb = frameBuffer; } @@ -10,9 +10,9 @@ void TSE::EDITOR::SceneView::Define() ImGuiWindowFlags flags2 = ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; if(ImGui::BeginChild("##SceneChild", {0,0}, ImGuiChildFlags_None, flags2)) { - ImGui::Image(fb->GetTextureId(), {fb->width(), fb->height()},{0,1}, {1,0}); + ImGui::Image(fb->GetTextureId(), {fb->Width(), fb->Height()},{0,1}, {1,0}); auto vec2 = ImGui::GetWindowSize(); - if(fb->width() != vec2.x || fb->height() != vec2.y) + if(fb->Width() != vec2.x || fb->Height() != vec2.y) { fb->SetSize({vec2.x, vec2.y}); } diff --git a/TSE_Editor/src/UI/windows/SceneView.hpp b/TSE_Editor/src/UI/windows/SceneView.hpp index aa249af..40c2886 100644 --- a/TSE_Editor/src/UI/windows/SceneView.hpp +++ b/TSE_Editor/src/UI/windows/SceneView.hpp @@ -1,16 +1,16 @@ #pragma once #include "UI/base/GuiWindow.h" -#include "RenderTexture.hpp" +#include "interfaces/IRenderTexture.hpp" namespace TSE::EDITOR { class SceneView : public GuiWindow { private: - TSE::GLFW::RenderTexture* fb; + TSE::IRenderTexture* fb; public: - SceneView(TSE::GLFW::RenderTexture* frameBuffer); + SceneView(TSE::IRenderTexture* frameBuffer); void Define() override; }; } // namespace TSE::EDITOR diff --git a/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp b/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp index e2ccb87..76f2d9c 100644 --- a/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp +++ b/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp @@ -12,6 +12,7 @@ #include "TextureHelperOpenGL.hpp" #include "interfaces/IRenderer.hpp" #include "BehaviourScripts/Camera.hpp" +#include "RenderTextureCreatorOpenGL.hpp" TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync) : OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ } @@ -36,6 +37,7 @@ TSE::GLFW::OpenGLRenderingBackend::~OpenGLRenderingBackend() void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow() { + IRenderTexture::factory = new RenderTextureCreatorOpenGL(); Texture::helper = new TextureHelperOpenGL(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR); diff --git a/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp b/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp index 058ba64..b223e2d 100644 --- a/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp +++ b/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp @@ -15,12 +15,12 @@ void TSE::GLFW::RenderTexture::SetSize(Vector2 v) buffer.Resize(v); } -float TSE::GLFW::RenderTexture::width() const +float TSE::GLFW::RenderTexture::Width() const { return buffer.GetSize().x; } -float TSE::GLFW::RenderTexture::height() const +float TSE::GLFW::RenderTexture::Height() const { return buffer.GetSize().y; } diff --git a/TSE_GlfwOpenGlImpl/src/RenderTexture.hpp b/TSE_GlfwOpenGlImpl/src/RenderTexture.hpp index 46eb852..7091c31 100644 --- a/TSE_GlfwOpenGlImpl/src/RenderTexture.hpp +++ b/TSE_GlfwOpenGlImpl/src/RenderTexture.hpp @@ -4,10 +4,11 @@ #include "interfaces/IRenderTarget.hpp" #include "interfaces/ITexture.hpp" #include "interfaces/IResizeNotifiable.hpp" +#include "interfaces/IRenderTexture.hpp" namespace TSE::GLFW { - class RenderTexture : public IRenderTarget, public ITexture, public IResizeNotifiable + class RenderTexture : public IRenderTexture { public: FrameBuffer buffer; @@ -15,9 +16,9 @@ namespace TSE::GLFW RenderTexture(Vector2 v); Vector2 size() const override; - void SetSize(Vector2 v); - float width() const override; - float height() const override; + void SetSize(Vector2 v) override; + float Width() const override; + float Height() const override; uint GetTextureId() const override; void Update() override; diff --git a/TSE_GlfwOpenGlImpl/src/RenderTextureCreatorOpenGL.hpp b/TSE_GlfwOpenGlImpl/src/RenderTextureCreatorOpenGL.hpp new file mode 100644 index 0000000..449fccf --- /dev/null +++ b/TSE_GlfwOpenGlImpl/src/RenderTextureCreatorOpenGL.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "interfaces/IRenderTexture.hpp" +#include "RenderTexture.hpp" + +namespace TSE::GLFW +{ + class RenderTextureCreatorOpenGL : public IRenderTextureCreator + { + public: + inline IRenderTexture* CreateTextureHeap(Vector2 v) override + { + return new RenderTexture(v); + }; + }; +} // namespace name diff --git a/TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp b/TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp index e26a0d7..9dc9818 100644 --- a/TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp +++ b/TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp @@ -18,19 +18,19 @@ void TSE::GLFW::TextureHelperOpenGL::Apply(Texture *tex) if(tex->Chanels() == 1) { if (tex->bpp() == 8) - glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr()); + glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->Width(), tex->Height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr()); } if(tex->Chanels() == 3) { if(tex->bpp() == 24) - glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGR, GL_UNSIGNED_BYTE, tex->GetImagePtr()); + glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->Width(), tex->Height(), 0, GL_BGR, GL_UNSIGNED_BYTE, tex->GetImagePtr()); } else if(tex->Chanels() == 4) { if(tex->bpp() == 32) - glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, tex->GetImagePtr()); + glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->Width(), tex->Height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, tex->GetImagePtr()); if (tex->bpp() == 8) //need to decode it with bitwise operations in shader - glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr()); + glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->Width(), tex->Height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr()); } glGenerateMipmap(GL_TEXTURE_2D);