From 23e7707122b3cbb924404c6f653163db7b787cb0c27ef97c3cfc8e614c255289 Mon Sep 17 00:00:00 2001 From: Mexpert_PRO Date: Sun, 18 Jan 2026 16:49:45 +0100 Subject: [PATCH] made the editor work by debugging on windows --- TSE_Core/src/elements/Texture.cpp | 2 +- TSE_Editor/src/EditorSubsystem.cpp | 8 +++---- TSE_Editor/src/EditorSubsystem.hpp | 2 +- TSE_Editor/src/UI/ViewportController.cpp | 2 +- TSE_Editor/src/UI/windows/CameraView.cpp | 13 ++++++----- TSE_Editor/src/UI/windows/CameraView.hpp | 2 +- .../src/OpenGLRenderingBackend.cpp | 17 ++++++++++++-- TSE_GlfwOpenGlImpl/src/RenderTexture.cpp | 2 +- TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp | 22 ++++++++----------- TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.hpp | 1 - .../src/shader/basicTextureShader.cpp | 2 +- 11 files changed, 41 insertions(+), 32 deletions(-) diff --git a/TSE_Core/src/elements/Texture.cpp b/TSE_Core/src/elements/Texture.cpp index c1b0961..ab675cf 100644 --- a/TSE_Core/src/elements/Texture.cpp +++ b/TSE_Core/src/elements/Texture.cpp @@ -163,7 +163,7 @@ void TSE::Texture::SetChanels(const byte &ch) chanels = ch; } -uint TSE::Texture::GetTextureId() const +TSE::uint TSE::Texture::GetTextureId() const { return TextureID; } diff --git a/TSE_Editor/src/EditorSubsystem.cpp b/TSE_Editor/src/EditorSubsystem.cpp index b243f7f..db43674 100644 --- a/TSE_Editor/src/EditorSubsystem.cpp +++ b/TSE_Editor/src/EditorSubsystem.cpp @@ -2,10 +2,10 @@ #include "BehaviourScriptRegistry.hpp" -TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), rt({10,10}), editorLayer("") +TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("") { - rt = TSE::GLFW::RenderTexture({100,100}); - sv = SceneView(&rt); + rt = new TSE::GLFW::RenderTexture({100,100}); + sv = SceneView(rt); controller.AddGuiElement("Scene", &sv); controller.AddGuiElement("Consol", &cv); @@ -27,7 +27,7 @@ TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), rt({10,10}), edit Transformable* editorCamera = new Transformable(".EditorCamera"); Camera* editorCam = new Camera(); - editorCam->SetRenderTarget(&rt); + editorCam->SetRenderTarget(rt); editorCamera->AddBehaviourScript(editorCam); // basicCameraControls controls = basicCameraControls(); diff --git a/TSE_Editor/src/EditorSubsystem.hpp b/TSE_Editor/src/EditorSubsystem.hpp index 5a8e204..a3f9ac4 100644 --- a/TSE_Editor/src/EditorSubsystem.hpp +++ b/TSE_Editor/src/EditorSubsystem.hpp @@ -20,7 +20,7 @@ namespace TSE::EDITOR HirearchieView hv = HirearchieView(nullptr); PropertiesView pv; CameraView camv; - TSE::GLFW::RenderTexture rt; + TSE::GLFW::RenderTexture* rt; SceneView sv; Layer editorLayer; diff --git a/TSE_Editor/src/UI/ViewportController.cpp b/TSE_Editor/src/UI/ViewportController.cpp index b8ec4f2..ae906ba 100644 --- a/TSE_Editor/src/UI/ViewportController.cpp +++ b/TSE_Editor/src/UI/ViewportController.cpp @@ -1,6 +1,6 @@ #include "ViewportController.hpp" #include "imgui/imgui.h" - +#include extern "C" { #include "tinyfiledialogs.h" diff --git a/TSE_Editor/src/UI/windows/CameraView.cpp b/TSE_Editor/src/UI/windows/CameraView.cpp index 0731902..cad53c8 100644 --- a/TSE_Editor/src/UI/windows/CameraView.cpp +++ b/TSE_Editor/src/UI/windows/CameraView.cpp @@ -1,7 +1,9 @@ #include "CameraView.hpp" TSE::EDITOR::CameraView::CameraView() : GuiWindow("Camera", ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar) -, fb({100,100}) { } +{ + fb = new TSE::GLFW::RenderTexture({100,100}); +} void TSE::EDITOR::CameraView::Define() { @@ -11,18 +13,17 @@ void TSE::EDITOR::CameraView::Define() currentCamera->SetRenderTarget(nullptr); currentCamera = Camera::mainCamera; if(currentCamera != nullptr) - currentCamera->SetRenderTarget(&fb); + currentCamera->SetRenderTarget(fb); } ImGuiWindowFlags flags2 = ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; if(ImGui::BeginChild("##SceneChild", {0,0}, ImGuiChildFlags_None, flags2)) { - float w = fb.width(); - 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}); + fb->SetSize({vec2.x, vec2.y}); } } ImGui::EndChild(); diff --git a/TSE_Editor/src/UI/windows/CameraView.hpp b/TSE_Editor/src/UI/windows/CameraView.hpp index fa20b1b..e352923 100644 --- a/TSE_Editor/src/UI/windows/CameraView.hpp +++ b/TSE_Editor/src/UI/windows/CameraView.hpp @@ -10,7 +10,7 @@ namespace TSE::EDITOR { private: Camera* currentCamera = nullptr; - TSE::GLFW::RenderTexture fb; + TSE::GLFW::RenderTexture* fb; public: CameraView(); void Define() override; diff --git a/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp b/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp index 577528e..e2ccb87 100644 --- a/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp +++ b/TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp @@ -10,6 +10,8 @@ #include "PathHelper.hpp" #include "elements/Texture.hpp" #include "TextureHelperOpenGL.hpp" +#include "interfaces/IRenderer.hpp" +#include "BehaviourScripts/Camera.hpp" TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync) : OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ } @@ -140,7 +142,13 @@ void TSE::GLFW::OpenGLRenderingBackend::onUpdate() const void TSE::GLFW::OpenGLRenderingBackend::onClear() const { - //cameras + for (int i = 0; i < IRenderer::camerasToRenderWith.size(); i++) + { + IRenderer::camerasToRenderWith[i]->Bind(); + IRenderer::camerasToRenderWith[i]->UpdateRenderTarget(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + IRenderer::camerasToRenderWith[i]->Unbind(); + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(useseImGui) @@ -153,7 +161,12 @@ void TSE::GLFW::OpenGLRenderingBackend::onClear() const void TSE::GLFW::OpenGLRenderingBackend::onClearDepthBuffer() const { - //cameras + for (int i = 0; i < IRenderer::camerasToRenderWith.size(); i++) + { + IRenderer::camerasToRenderWith[i]->Bind(); + glClear(GL_DEPTH_BUFFER_BIT); + IRenderer::camerasToRenderWith[i]->Unbind(); + } glClear(GL_DEPTH_BUFFER_BIT); } diff --git a/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp b/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp index 264f9a1..058ba64 100644 --- a/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp +++ b/TSE_GlfwOpenGlImpl/src/RenderTexture.cpp @@ -25,7 +25,7 @@ float TSE::GLFW::RenderTexture::height() const return buffer.GetSize().y; } -uint TSE::GLFW::RenderTexture::GetTextureId() const +TSE::uint TSE::GLFW::RenderTexture::GetTextureId() const { return buffer.GetTextureId(); } diff --git a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp index 59fe2bf..a4b2d37 100644 --- a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp +++ b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp @@ -3,7 +3,8 @@ TSE::GLFW::FrameBuffer::FrameBuffer(const Vector2 &size) { - this->size = size; + width = size.x; + height = size.y; CreateFBTexture(); for (auto const& i : objectsToResize) { @@ -14,16 +15,12 @@ TSE::GLFW::FrameBuffer::FrameBuffer(const Vector2 &size) void TSE::GLFW::FrameBuffer::Bind() { - glBindRenderbuffer(GL_RENDERBUFFER, depthRboID); - glBindTexture(GL_TEXTURE_2D, textureID); glBindFramebuffer(GL_FRAMEBUFFER, bufferID); } void TSE::GLFW::FrameBuffer::Unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); - glBindTexture(GL_TEXTURE_2D, 0); - glBindRenderbuffer(GL_RENDERBUFFER, 0); } TSE::GLFW::FrameBuffer::~FrameBuffer() @@ -35,7 +32,8 @@ TSE::GLFW::FrameBuffer::~FrameBuffer() void TSE::GLFW::FrameBuffer::Resize(Vector2 size) { - this->size = size; + width = size.x; + height = size.y; shouldResize = true; } @@ -46,7 +44,7 @@ void TSE::GLFW::FrameBuffer::Update() CreateFBTexture(); for (auto const& i : objectsToResize) { - i->OnResize(size.x, size.y, this); + i->OnResize(width, height, this); } } @@ -57,7 +55,7 @@ TSE::uint TSE::GLFW::FrameBuffer::GetTextureId() const TSE::Vector2 TSE::GLFW::FrameBuffer::GetSize() const { - return size; + return {width, height}; } void TSE::GLFW::FrameBuffer::Initialize() @@ -73,14 +71,12 @@ void TSE::GLFW::FrameBuffer::Initialize() TSE_LOG(std::to_string(glGetError())); } Unbind(); - glBindTexture(GL_TEXTURE_2D, 0); - glBindRenderbuffer(GL_RENDERBUFFER, 0); } void TSE::GLFW::FrameBuffer::LoadFBTexture() { glBindTexture(GL_TEXTURE_2D, textureID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -88,12 +84,12 @@ void TSE::GLFW::FrameBuffer::LoadFBTexture() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindRenderbuffer(GL_RENDERBUFFER, depthRboID); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size.x, size.y); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); } void TSE::GLFW::FrameBuffer::CreateFBTexture() { - glViewport(0,0, size.x, size.y); + glViewport(0,0, width, height); //resize if(textureID == 0) glGenTextures(1, &textureID); diff --git a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.hpp b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.hpp index eec9cf2..7d99909 100644 --- a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.hpp +++ b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.hpp @@ -11,7 +11,6 @@ namespace TSE::GLFW private: uint textureID = 0; uint depthRboID = 0; - Vector2 size; bool shouldResize = false; public: diff --git a/TSE_GlfwOpenGlImpl/src/shader/basicTextureShader.cpp b/TSE_GlfwOpenGlImpl/src/shader/basicTextureShader.cpp index 4f41423..6f75a49 100644 --- a/TSE_GlfwOpenGlImpl/src/shader/basicTextureShader.cpp +++ b/TSE_GlfwOpenGlImpl/src/shader/basicTextureShader.cpp @@ -14,7 +14,7 @@ #define SHADER_PACKAGE_SIZE (sizeof(float) * (3 + 4 + 2 + 1)) TSE::GLFW::BasicTextureShader* TSE::GLFW::BasicTextureShader::instance = nullptr; -std::map TSE::GLFW::BasicTextureShader::textureSlots; +std::map TSE::GLFW::BasicTextureShader::textureSlots; TSE::GLFW::BasicTextureShader *TSE::GLFW::BasicTextureShader::Instance() {