made Editor non reliant on GLFW aka i added an IRenderTexture interface of use in non renderer specific aplications

This commit is contained in:
2026-01-18 18:49:15 +01:00
parent 23e7707122
commit a453612b9a
17 changed files with 87 additions and 49 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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});

View File

@@ -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});
}

View File

@@ -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;

View File

@@ -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});
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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);