diff --git a/Assets/Shaders/lastpass.fs b/Assets/Shaders/lastpass.fs new file mode 100644 index 00000000..7d9406c1 --- /dev/null +++ b/Assets/Shaders/lastpass.fs @@ -0,0 +1,10 @@ +#version 330 core + +out vec4 fragColor; + +in vec2 fUV; +uniform sampler2D uTexture; + +void main() { + fragColor = texture(uTexture, fUV); +} \ No newline at end of file diff --git a/Assets/Shaders/lastpass.vs b/Assets/Shaders/lastpass.vs new file mode 100644 index 00000000..8fc78f1c --- /dev/null +++ b/Assets/Shaders/lastpass.vs @@ -0,0 +1,10 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aUV; + +out vec2 fUV; + +void main() { + gl_Position = vec4(aPos, 1.0); + fUV = aUV; +} \ No newline at end of file diff --git a/ICE/Core/include/ICEEngine.h b/ICE/Core/include/ICEEngine.h index 54015d02..e486d165 100644 --- a/ICE/Core/include/ICEEngine.h +++ b/ICE/Core/include/ICEEngine.h @@ -2,8 +2,7 @@ // Created by Thomas Ibanez on 25.11.20. // -#ifndef ICE_ICEENGINE_H -#define ICE_ICEENGINE_H +#pragma once #include #include @@ -63,6 +62,7 @@ class ICEEngine { std::shared_ptr api; std::shared_ptr internalFB; std::shared_ptr m_target_fb = nullptr; + std::shared_ptr m_window; std::shared_ptr camera; std::shared_ptr project = nullptr; @@ -71,5 +71,3 @@ class ICEEngine { Registry registry; }; } // namespace ICE - -#endif //ICE_ICEENGINE_H diff --git a/ICE/Core/src/ICEEngine.cpp b/ICE/Core/src/ICEEngine.cpp index ca0cf3ae..5d69acb8 100644 --- a/ICE/Core/src/ICEEngine.cpp +++ b/ICE/Core/src/ICEEngine.cpp @@ -15,19 +15,25 @@ ICEEngine::ICEEngine() : camera(std::make_shared(60, 16.f / 9 void ICEEngine::initialize(const std::shared_ptr &graphics_factory, const std::shared_ptr &window) { Logger::Log(Logger::INFO, "Core", "Engine starting up..."); - m_graphics_factory = graphics_factory; - ctx = graphics_factory->createContext(window); + m_window = window; + m_window->setSwapInterval(1); + m_window->setResizeCallback([this](int w, int h) { + if (project) { + project->getCurrentScene()->getRegistry()->getSystem()->setViewport(0, 0, w, h); + } + }); + ctx = graphics_factory->createContext(m_window); ctx->initialize(); api = graphics_factory->createRendererAPI(); - window->setSwapInterval(1); api->initialize(); internalFB = graphics_factory->createFramebuffer({720, 720, 1}); } void ICEEngine::step(const std::shared_ptr &scene) { - project->getCurrentScene()->getRegistry()->getSystem()->setTarget(m_target_fb); - + auto render_system = project->getCurrentScene()->getRegistry()->getSystem(); + render_system->setTarget(m_target_fb); + render_system->setCamera(camera); project->getCurrentScene()->getRegistry()->updateSystems(0.0); } @@ -89,13 +95,15 @@ void ICEEngine::setProject(const std::shared_ptr &project) { this->camera->getPosition() = project->getCameraPosition(); this->camera->getRotation() = project->getCameraRotation(); - auto renderer = std::make_shared(api, project->getCurrentScene()->getRegistry(), project->getAssetBank()); + auto renderer = std::make_shared(api, m_graphics_factory, project->getCurrentScene()->getRegistry(), project->getAssetBank()); m_rendersystem = std::make_shared(); m_rendersystem->setCamera(camera); m_rendersystem->setRenderer(renderer); systems.push_back(m_rendersystem); project->getCurrentScene()->getRegistry()->addSystem(m_rendersystem); - //Skybox::Initialize(); + + auto [w, h] = m_window->getSize(); + renderer->resize(w, h); } EngineConfig &ICEEngine::getConfig() { diff --git a/ICE/Graphics/CMakeLists.txt b/ICE/Graphics/CMakeLists.txt index 887762e2..dc528bba 100644 --- a/ICE/Graphics/CMakeLists.txt +++ b/ICE/Graphics/CMakeLists.txt @@ -11,7 +11,7 @@ target_sources(${PROJECT_NAME} PRIVATE src/ForwardRenderer.cpp src/Material.cpp src/Mesh.cpp - ) + src/GeometryPass.cpp "include/RenderData.h") target_link_libraries(${PROJECT_NAME} PUBLIC diff --git a/ICE/Graphics/include/ForwardRenderer.h b/ICE/Graphics/include/ForwardRenderer.h index 8b4c2989..62d9a4be 100644 --- a/ICE/Graphics/include/ForwardRenderer.h +++ b/ICE/Graphics/include/ForwardRenderer.h @@ -13,13 +13,16 @@ #include "Camera.h" #include "Framebuffer.h" +#include "GeometryPass.h" +#include "RenderCommand.h" #include "Renderer.h" #include "RendererConfig.h" namespace ICE { class ForwardRenderer : public Renderer { public: - ForwardRenderer(const std::shared_ptr& api, const std::shared_ptr& registry, const std::shared_ptr& assetBank); + ForwardRenderer(const std::shared_ptr& api, const std::shared_ptr& factory, + const std::shared_ptr& registry, const std::shared_ptr& assetBank); void submit(Entity e) override; void remove(Entity e) override; @@ -35,6 +38,7 @@ class ForwardRenderer : public Renderer { void resize(uint32_t width, uint32_t height) override; void setClearColor(Eigen::Vector4f clearColor) override; + void setViewport(int x, int y, int w, int h) override; private: std::shared_ptr m_api; @@ -42,15 +46,14 @@ class ForwardRenderer : public Renderer { std::shared_ptr m_asset_bank; std::shared_ptr target = nullptr; - std::vector> m_render_commands; + std::vector m_render_commands; std::vector m_render_queue; std::vector m_lights; AssetUID m_skybox = NO_ASSET_ID; - //State - AssetUID m_current_shader = 0; - AssetUID m_current_material = 0; - AssetUID m_current_mesh = 0; + GeometryPass m_geometry_pass; + + std::shared_ptr m_quad_vao; RendererConfig config; }; diff --git a/ICE/Graphics/include/Framebuffer.h b/ICE/Graphics/include/Framebuffer.h index ef37b72d..a837feef 100644 --- a/ICE/Graphics/include/Framebuffer.h +++ b/ICE/Graphics/include/Framebuffer.h @@ -16,7 +16,8 @@ class Framebuffer { virtual void bind() = 0; virtual void unbind() = 0; virtual void resize(int width, int height) = 0; - virtual void* getTexture() = 0; + virtual int getTexture() = 0; + virtual void bindAttachment(int slot) const = 0; virtual Eigen::Vector4i readPixel(int x, int y) = 0; FrameBufferFormat getFormat() const { return format; } diff --git a/ICE/Graphics/include/GeometryPass.h b/ICE/Graphics/include/GeometryPass.h new file mode 100644 index 00000000..19597911 --- /dev/null +++ b/ICE/Graphics/include/GeometryPass.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Framebuffer.h" +#include "GraphicsFactory.h" +#include "RenderCommand.h" +#include "RenderPass.h" + +namespace ICE { +class GeometryPass : public RenderPass { + public: + GeometryPass(const std::shared_ptr& api, const std::shared_ptr& factory, const FrameBufferFormat& format); + void submit(std::vector* commands) { m_render_queue = commands; } + void execute() override; + std::shared_ptr getResult() const; + void resize(int w, int h); + + private: + std::shared_ptr m_api; + std::shared_ptr m_framebuffer; + std::vector* m_render_queue; +}; +} // namespace ICE \ No newline at end of file diff --git a/ICE/Graphics/include/GraphicsFactory.h b/ICE/Graphics/include/GraphicsFactory.h index 504c126e..ef11a962 100644 --- a/ICE/Graphics/include/GraphicsFactory.h +++ b/ICE/Graphics/include/GraphicsFactory.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -10,30 +11,29 @@ #include "Shader.h" #include "Texture.h" #include "VertexArray.h" -#include -#include namespace ICE { class GraphicsFactory { public: - virtual std::shared_ptr createContext(const std::shared_ptr &window) = 0; + virtual std::shared_ptr createContext(const std::shared_ptr& window) const = 0; - virtual std::shared_ptr createFramebuffer(const FrameBufferFormat& format) = 0; + virtual std::shared_ptr createFramebuffer(const FrameBufferFormat& format) const = 0; - virtual std::shared_ptr createRendererAPI() = 0; + virtual std::shared_ptr createRendererAPI() const = 0; - virtual std::shared_ptr createVertexArray() = 0; + virtual std::shared_ptr createVertexArray() const = 0; - virtual std::shared_ptr createVertexBuffer() = 0; + virtual std::shared_ptr createVertexBuffer() const = 0; - virtual std::shared_ptr createIndexBuffer() = 0; + virtual std::shared_ptr createIndexBuffer() const = 0; - virtual std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) = 0; + virtual std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) const = 0; - virtual std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, const std::string& fragmentFile) = 0; + virtual std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, + const std::string& fragmentFile) const = 0; - virtual std::shared_ptr createTexture2D(const std::string& file) = 0; + virtual std::shared_ptr createTexture2D(const std::string& file) const = 0; - virtual std::shared_ptr createTextureCube(const std::string& file) = 0; + virtual std::shared_ptr createTextureCube(const std::string& file) const = 0; }; } // namespace ICE \ No newline at end of file diff --git a/ICE/Graphics/include/RenderCommand.h b/ICE/Graphics/include/RenderCommand.h index b06f6459..e04383dc 100644 --- a/ICE/Graphics/include/RenderCommand.h +++ b/ICE/Graphics/include/RenderCommand.h @@ -2,11 +2,24 @@ // Created by Thomas Ibanez on 19.11.20. // -#ifndef ICE_RENDERCOMMAND_H -#define ICE_RENDERCOMMAND_H +#pragma once -namespace ICE { +#include +#include + +#include "Material.h" +#include "Mesh.h" +#include "Shader.h" -} +namespace ICE { +struct RenderCommand { + std::shared_ptr mesh; + std::shared_ptr material; + std::shared_ptr shader; + std::unordered_map> textures; + Eigen::Matrix4f model_matrix; -#endif //ICE_RENDERCOMMAND_H + bool faceCulling = true; + bool depthTest = true; +}; +} // namespace ICE diff --git a/ICE/Graphics/include/RenderData.h b/ICE/Graphics/include/RenderData.h new file mode 100644 index 00000000..093b3a3b --- /dev/null +++ b/ICE/Graphics/include/RenderData.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +static std::vector full_quad_v = { + -1.0f, -1.0f, 0.0f, // TOP LEFT + 1.0, -1.0f, 0.0f, // TOP RIGHT + -1.0f, 1.0, 0.0f, // BOTTOM LEFT + 1.0, 1.0, 0.0f, // BOTTOM RIGHT +}; + +static std::vector full_quad_idx = { + 0, 1, 2, 2, 1, 3 +}; + + +static std::vector full_quad_tx = { + 0, 0, // TOP LEFT + 1, 0, // TOP RIGHT + 0, 1, // BOTTOM LEFT + 1, 1, // BOTTOM RIGHT + 1, 0, // TOP RIGHT + 0, 1 // BOTTOM LEFT +}; diff --git a/ICE/Graphics/include/RenderPass.h b/ICE/Graphics/include/RenderPass.h new file mode 100644 index 00000000..ff538a93 --- /dev/null +++ b/ICE/Graphics/include/RenderPass.h @@ -0,0 +1,9 @@ +#pragma once + +namespace ICE { +class RenderPass { + public: + virtual ~RenderPass() = default; + virtual void execute() = 0; +}; +} // namespace ICE \ No newline at end of file diff --git a/ICE/Graphics/include/Renderer.h b/ICE/Graphics/include/Renderer.h index eb4450ec..1022c4eb 100644 --- a/ICE/Graphics/include/Renderer.h +++ b/ICE/Graphics/include/Renderer.h @@ -27,5 +27,6 @@ class Renderer { virtual void setTarget(const std::shared_ptr &target) = 0; virtual void resize(uint32_t width, uint32_t height) = 0; virtual void setClearColor(Eigen::Vector4f clearColor) = 0; + virtual void setViewport(int x, int y, int w, int h) = 0; }; } // namespace ICE diff --git a/ICE/Graphics/include/VertexArray.h b/ICE/Graphics/include/VertexArray.h index bc339b8b..9999fc92 100644 --- a/ICE/Graphics/include/VertexArray.h +++ b/ICE/Graphics/include/VertexArray.h @@ -24,6 +24,7 @@ class VertexArray { virtual std::shared_ptr getIndexBuffer() const = 0; virtual int getIndexCount() const = 0; virtual uint32_t getID() const = 0; + }; } // namespace ICE diff --git a/ICE/Graphics/src/ForwardRenderer.cpp b/ICE/Graphics/src/ForwardRenderer.cpp index 09e0b9e0..1bffe5b3 100644 --- a/ICE/Graphics/src/ForwardRenderer.cpp +++ b/ICE/Graphics/src/ForwardRenderer.cpp @@ -14,13 +14,27 @@ #include +#include "RenderData.h" + namespace ICE { -ForwardRenderer::ForwardRenderer(const std::shared_ptr& api, const std::shared_ptr& registry, - const std::shared_ptr& assetBank) +ForwardRenderer::ForwardRenderer(const std::shared_ptr& api, const std::shared_ptr& factory, + const std::shared_ptr& registry, const std::shared_ptr& assetBank) : m_api(api), m_registry(registry), - m_asset_bank(assetBank) { + m_asset_bank(assetBank), + m_geometry_pass(api, factory, {1, 1, 1}) { + + m_quad_vao = factory->createVertexArray(); + auto quad_vertex_vbo = factory->createVertexBuffer(); + quad_vertex_vbo->putData(full_quad_v.data(), full_quad_v.size() * sizeof(float)); + m_quad_vao->pushVertexBuffer(quad_vertex_vbo, 3); + auto quad_uv_vbo = factory->createVertexBuffer(); + quad_uv_vbo->putData(full_quad_tx.data(), full_quad_tx.size() * sizeof(float)); + m_quad_vao->pushVertexBuffer(quad_uv_vbo, 2); + auto quad_ibo = factory->createIndexBuffer(); + quad_ibo->putData(full_quad_idx.data(), full_quad_idx.size() * sizeof(int)); + m_quad_vao->setIndexBuffer(quad_ibo); } void ForwardRenderer::submit(Entity e) { @@ -50,14 +64,7 @@ void ForwardRenderer::remove(Entity e) { } void ForwardRenderer::prepareFrame(Camera& camera) { - if (this->target != nullptr) { - this->target->bind(); - m_api->setViewport(0, 0, target->getFormat().width, target->getFormat().height); - } else { - m_api->bindDefaultFramebuffer(); - } //TODO: Sort entities, make shader list, batch, make instances, set uniforms, etc.. - std::sort(m_render_queue.begin(), m_render_queue.end(), [this](Entity a, Entity b) { auto rc_a = m_registry->getComponent(a); auto material_a = m_asset_bank->getAsset(rc_a->material); @@ -71,8 +78,6 @@ void ForwardRenderer::prepareFrame(Camera& camera) { } }); - m_api->clear(); - if (m_skybox != NO_ASSET_ID) { auto shader = m_asset_bank->getAsset("__ice_skybox_shader"); shader->bind(); @@ -83,6 +88,16 @@ void ForwardRenderer::prepareFrame(Camera& camera) { view(2, 3) = 0; shader->loadMat4("view", view); shader->loadInt("skybox", 0); + + auto skybox = m_registry->getComponent(m_skybox); + auto mesh = m_asset_bank->getAsset("cube"); + auto tex = m_asset_bank->getAsset(skybox->texture); + m_render_commands.push_back(RenderCommand{.mesh = mesh, + .material = nullptr, + .shader = shader, + .textures = {{skybox->texture, tex}}, + .faceCulling = false, + .depthTest = false}); } std::unordered_set prepared_shaders; @@ -120,101 +135,60 @@ void ForwardRenderer::prepareFrame(Camera& camera) { shader->loadInt("light_count", i); prepared_shaders.emplace(material->getShader()); } - m_render_commands.push_back([this, rc = rc, tc = tc] { - auto material = m_asset_bank->getAsset(rc->material); - auto shader = m_asset_bank->getAsset(material->getShader()); - auto mesh = m_asset_bank->getAsset(rc->mesh); - if (!mesh) { - return; - } - if (material->getShader() != m_current_shader) { - shader->bind(); - m_current_shader = material->getShader(); - } + auto mesh = m_asset_bank->getAsset(rc->mesh); + if (!mesh) { + return; + } - int texture_count = 0; - - shader->loadMat4("model", tc->getModelMatrix()); - - if (rc->material != m_current_material) { - - m_current_material = rc->material; - - //TODO: Can we do better ? - for (const auto& [name, value] : material->getAllUniforms()) { - if (std::holds_alternative(value)) { - auto v = std::get(value); - shader->loadFloat(name, v); - } else if (!std::holds_alternative(value) && std::holds_alternative(value)) { - auto v = std::get(value); - shader->loadInt(name, v); - } else if (std::holds_alternative(value)) { - auto v = std::get(value); - if (auto tex = m_asset_bank->getAsset(v); tex) { - tex->bind(texture_count); - shader->loadInt(name, texture_count); - texture_count++; - } - } else if (std::holds_alternative(value)) { - auto& v = std::get(value); - shader->loadFloat2(name, v); - } else if (std::holds_alternative(value)) { - auto& v = std::get(value); - shader->loadFloat3(name, v); - } else if (std::holds_alternative(value)) { - auto& v = std::get(value); - shader->loadFloat4(name, v); - } else if (std::holds_alternative(value)) { - auto& v = std::get(value); - shader->loadMat4(name, v); - } else { - throw std::runtime_error("Uniform type not implemented"); - } + std::unordered_map> texs; + for (const auto& [name, value] : material->getAllUniforms()) { + if (std::holds_alternative(value)) { + auto v = std::get(value); + if (auto tex = m_asset_bank->getAsset(v); tex) { + texs.try_emplace(v, tex); } } + } - if (m_current_mesh != rc->mesh) { - m_current_mesh = rc->mesh; - auto va = mesh->getVertexArray(); - va->bind(); - va->getIndexBuffer()->bind(); - } - - m_api->renderVertexArray(mesh->getVertexArray()); - }); + m_render_commands.push_back(RenderCommand{.mesh = mesh, + .material = material, + .shader = shader, + .textures = texs, + .model_matrix = tc->getModelMatrix(), + .faceCulling = true, + .depthTest = true}); } + + m_geometry_pass.submit(&m_render_commands); } void ForwardRenderer::render() { - if (m_skybox != NO_ASSET_ID) { - m_api->setBackfaceCulling(false); - m_api->setDepthMask(false); - auto skybox = m_registry->getComponent(m_skybox); - auto shader = m_asset_bank->getAsset("__ice_skybox_shader"); - shader->bind(); - if (skybox->texture != NO_ASSET_ID) { - m_asset_bank->getAsset(skybox->texture)->bind(0); - } - auto vao = m_asset_bank->getAsset("cube")->getVertexArray(); - vao->bind(); - vao->getIndexBuffer()->bind(); - m_api->renderVertexArray(vao); - } - m_api->setBackfaceCulling(true); - m_api->setDepthMask(true); - for (const auto& cmd : m_render_commands) { - cmd(); + m_geometry_pass.execute(); + auto result = m_geometry_pass.getResult(); + + //Final pass, render the last result to the screen + if (!this->target) { + m_api->bindDefaultFramebuffer(); + } else { + this->target->bind(); } + m_api->clear(); + auto shader = m_asset_bank->getAsset(AssetPath::WithTypePrefix("lastpass")); + + shader->bind(); + result->bindAttachment(0); + shader->loadInt("uTexture", 0); + m_quad_vao->bind(); + m_quad_vao->getIndexBuffer()->bind(); + m_api->renderVertexArray(m_quad_vao); } void ForwardRenderer::endFrame() { m_api->checkAndLogErrors(); //TODO: Cleanup and restore state m_render_commands.clear(); - m_current_material = 0; - m_current_mesh = 0; - m_current_shader = 0; + if (this->target != nullptr) this->target->unbind(); } @@ -229,9 +203,15 @@ void ForwardRenderer::resize(uint32_t width, uint32_t height) { target->resize(width, height); } m_api->setViewport(0, 0, width, height); + m_geometry_pass.resize(width, height); } void ForwardRenderer::setClearColor(Eigen::Vector4f clearColor) { m_api->setClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); } + +void ForwardRenderer::setViewport(int x, int y, int w, int h) { + m_api->setViewport(x, y, w, h); +} + } // namespace ICE diff --git a/ICE/Graphics/src/GeometryPass.cpp b/ICE/Graphics/src/GeometryPass.cpp new file mode 100644 index 00000000..c912c22b --- /dev/null +++ b/ICE/Graphics/src/GeometryPass.cpp @@ -0,0 +1,85 @@ +#include "GeometryPass.h" + +namespace ICE { +GeometryPass::GeometryPass(const std::shared_ptr& api, const std::shared_ptr& factory, const FrameBufferFormat& format) + : m_api(api) { + m_framebuffer = factory->createFramebuffer(format); +} + +void GeometryPass::execute() { + m_framebuffer->bind(); + m_api->setViewport(0, 0, m_framebuffer->getFormat().width, m_framebuffer->getFormat().height); + m_api->clear(); + std::shared_ptr current_shader; + std::shared_ptr current_material; + std::shared_ptr current_mesh; + for (const auto& command : *m_render_queue) { + auto& shader = command.shader; + auto& material = command.material; + auto& mesh = command.mesh; + + m_api->setBackfaceCulling(command.faceCulling); + m_api->setDepthTest(command.depthTest); + + if (shader != current_shader) { + shader->bind(); + current_shader = shader; + } + if (material != current_material) { + auto& textures = command.textures; + current_material = material; + int texture_count = 0; + + //TODO: Can we do better ? + for (const auto& [name, value] : material->getAllUniforms()) { + if (std::holds_alternative(value)) { + auto v = std::get(value); + shader->loadFloat(name, v); + } else if (!std::holds_alternative(value) && std::holds_alternative(value)) { + auto v = std::get(value); + shader->loadInt(name, v); + } else if (std::holds_alternative(value)) { + auto v = std::get(value); + auto& tex = textures.at(v); + tex->bind(texture_count); + shader->loadInt(name, texture_count); + texture_count++; + } else if (std::holds_alternative(value)) { + auto& v = std::get(value); + shader->loadFloat2(name, v); + } else if (std::holds_alternative(value)) { + auto& v = std::get(value); + shader->loadFloat3(name, v); + } else if (std::holds_alternative(value)) { + auto& v = std::get(value); + shader->loadFloat4(name, v); + } else if (std::holds_alternative(value)) { + auto& v = std::get(value); + shader->loadMat4(name, v); + } else { + throw std::runtime_error("Uniform type not implemented"); + } + } + } + + if (current_mesh != mesh) { + current_mesh = mesh; + auto va = mesh->getVertexArray(); + va->bind(); + va->getIndexBuffer()->bind(); + } + + shader->loadMat4("model", command.model_matrix); + m_api->renderVertexArray(mesh->getVertexArray()); + } +} + +std::shared_ptr GeometryPass::getResult() const { + return m_framebuffer; +} + +void GeometryPass::resize(int w, int h) { + m_framebuffer->resize(w, h); +} + +} // namespace ICE \ No newline at end of file diff --git a/ICE/GraphicsAPI/None/NoneGraphics.h b/ICE/GraphicsAPI/None/NoneGraphics.h index c23cd4b6..d9ff1e7e 100644 --- a/ICE/GraphicsAPI/None/NoneGraphics.h +++ b/ICE/GraphicsAPI/None/NoneGraphics.h @@ -41,7 +41,8 @@ class NoneFramebuffer : public Framebuffer { void bind() override {} void unbind() override {} void resize(int width, int height) override {} - void *getTexture() override { return nullptr; } + int getTexture() override { return 0; } + void bindAttachment(int slot) const override{}; Eigen::Vector4i readPixel(int x, int y) override { return Eigen::Vector4i(); } }; diff --git a/ICE/GraphicsAPI/None/NoneGraphicsFactory.h b/ICE/GraphicsAPI/None/NoneGraphicsFactory.h index 232a1052..2f940027 100644 --- a/ICE/GraphicsAPI/None/NoneGraphicsFactory.h +++ b/ICE/GraphicsAPI/None/NoneGraphicsFactory.h @@ -14,26 +14,29 @@ namespace ICE { class NoneGraphicsFactory : public GraphicsFactory { public: - std::shared_ptr createContext(const std::shared_ptr &window) { return std::make_shared(); } + std::shared_ptr createContext(const std::shared_ptr& window) const override { return std::make_shared(); } - std::shared_ptr createFramebuffer(const FrameBufferFormat& format) { return std::make_shared(); } + std::shared_ptr createFramebuffer(const FrameBufferFormat& format) const override { return std::make_shared(); } - std::shared_ptr createRendererAPI() { return std::make_shared(); } + std::shared_ptr createRendererAPI() const override { return std::make_shared(); } - std::shared_ptr createVertexArray() { return std::make_shared(); } + std::shared_ptr createVertexArray() const override { return std::make_shared(); } - std::shared_ptr createVertexBuffer() { return std::make_shared(); } + std::shared_ptr createVertexBuffer() const override { return std::make_shared(); } - std::shared_ptr createIndexBuffer() { return std::make_shared(); } + std::shared_ptr createIndexBuffer() const override { return std::make_shared(); } - std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) { return createShader(vertexFile, "", fragmentFile); } + std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) const override { + return createShader(vertexFile, "", fragmentFile); + } - std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, const std::string& fragmentFile) { + std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, + const std::string& fragmentFile) const override { return std::make_shared(); } - std::shared_ptr createTexture2D(const std::string& file) { return std::make_shared(); } + std::shared_ptr createTexture2D(const std::string& file) const override { return std::make_shared(); } - std::shared_ptr createTextureCube(const std::string& file) { return std::make_shared(); } + std::shared_ptr createTextureCube(const std::string& file) const override { return std::make_shared(); } }; } // namespace ICE \ No newline at end of file diff --git a/ICE/GraphicsAPI/OpenGL/include/OpenGLFactory.h b/ICE/GraphicsAPI/OpenGL/include/OpenGLFactory.h index d4e92985..ba4198e7 100644 --- a/ICE/GraphicsAPI/OpenGL/include/OpenGLFactory.h +++ b/ICE/GraphicsAPI/OpenGL/include/OpenGLFactory.h @@ -19,27 +19,32 @@ namespace ICE { class OpenGLFactory : public GraphicsFactory { -public: - std::shared_ptr createContext(const std::shared_ptr &window) { return std::make_shared(window); } + public: + std::shared_ptr createContext(const std::shared_ptr& window) const override { return std::make_shared(window); } - std::shared_ptr createFramebuffer(const FrameBufferFormat& format) { return std::make_shared(format); } + std::shared_ptr createFramebuffer(const FrameBufferFormat& format) const override { + return std::make_shared(format); + } - std::shared_ptr createRendererAPI() { return std::make_shared(); } + std::shared_ptr createRendererAPI() const override { return std::make_shared(); } - std::shared_ptr createVertexArray() { return std::make_shared(); } + std::shared_ptr createVertexArray() const override { return std::make_shared(); } - std::shared_ptr createVertexBuffer() { return std::make_shared(); } + std::shared_ptr createVertexBuffer() const override { return std::make_shared(); } - std::shared_ptr createIndexBuffer() { return std::make_shared(); } + std::shared_ptr createIndexBuffer() const override { return std::make_shared(); } - std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) { return createShader(vertexFile, "", fragmentFile); } + std::shared_ptr createShader(const std::string& vertexFile, const std::string& fragmentFile) const override { + return createShader(vertexFile, "", fragmentFile); + } - std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, const std::string& fragmentFile) { + std::shared_ptr createShader(const std::string& vertexFile, const std::string& geometryFile, + const std::string& fragmentFile) const override { return std::make_shared(vertexFile, geometryFile, fragmentFile); } - std::shared_ptr createTexture2D(const std::string& file) { return std::make_shared(file); } + std::shared_ptr createTexture2D(const std::string& file) const override { return std::make_shared(file); } - std::shared_ptr createTextureCube(const std::string& file) { return std::make_shared(file); } + std::shared_ptr createTextureCube(const std::string& file) const override { return std::make_shared(file); } }; } // namespace ICE \ No newline at end of file diff --git a/ICE/GraphicsAPI/OpenGL/include/OpenGLFramebuffer.h b/ICE/GraphicsAPI/OpenGL/include/OpenGLFramebuffer.h index 9f90adba..b8bbc03d 100644 --- a/ICE/GraphicsAPI/OpenGL/include/OpenGLFramebuffer.h +++ b/ICE/GraphicsAPI/OpenGL/include/OpenGLFramebuffer.h @@ -2,35 +2,33 @@ // Created by Thomas Ibanez on 27.11.20. // -#ifndef ICE_OPENGLFRAMEBUFFER_H -#define ICE_OPENGLFRAMEBUFFER_H +#pragma once +#include +#include #include #include -#include -#include namespace ICE { - class OpenGLFramebuffer : public Framebuffer { - public: - OpenGLFramebuffer(FrameBufferFormat fmt); - - void bind() override; +class OpenGLFramebuffer : public Framebuffer { + public: + OpenGLFramebuffer(FrameBufferFormat fmt); - void unbind() override; + void bind() override; - void resize(int width, int height) override; + void unbind() override; - void *getTexture() override; + void resize(int width, int height) override; - Eigen::Vector4i readPixel(int x, int y) override; + int getTexture() override; - private: - GLuint uid; - GLuint texture; - GLuint depth; - }; -} + void bindAttachment(int slot) const override; + Eigen::Vector4i readPixel(int x, int y) override; -#endif //ICE_OPENGLFRAMEBUFFER_H + private: + GLuint uid; + GLuint texture; + GLuint depth; +}; +} // namespace ICE \ No newline at end of file diff --git a/ICE/GraphicsAPI/OpenGL/src/OpenGLFramebuffer.cpp b/ICE/GraphicsAPI/OpenGL/src/OpenGLFramebuffer.cpp index 1efc2731..664977cf 100644 --- a/ICE/GraphicsAPI/OpenGL/src/OpenGLFramebuffer.cpp +++ b/ICE/GraphicsAPI/OpenGL/src/OpenGLFramebuffer.cpp @@ -3,79 +3,83 @@ // #include "OpenGLFramebuffer.h" -#include + #include +#include + #include namespace ICE { - void OpenGLFramebuffer::bind() { - glBindFramebuffer(GL_FRAMEBUFFER, uid); - } +void OpenGLFramebuffer::bind() { + glBindFramebuffer(GL_FRAMEBUFFER, uid); +} - void OpenGLFramebuffer::unbind() { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } +void OpenGLFramebuffer::unbind() { + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} - void OpenGLFramebuffer::resize(int width, int height) { - if(width <= 0) width = 1; - if(height<= 0) height = 1; - format.width = width; - format.height = height; - glBindFramebuffer(GL_FRAMEBUFFER, uid); - glBindTexture(GL_TEXTURE_2D, texture); +void OpenGLFramebuffer::resize(int width, int height) { + if (width <= 0) + width = 1; + if (height <= 0) + height = 1; + format.width = width; + format.height = height; + glBindFramebuffer(GL_FRAMEBUFFER, uid); + glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - glBindRenderbuffer(GL_RENDERBUFFER, depth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); + glBindRenderbuffer(GL_RENDERBUFFER, depth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); - glFramebufferRenderbuffer( - GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth - ); - } - - void *OpenGLFramebuffer::getTexture() { - return static_cast(0)+texture; - } + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth); +} - OpenGLFramebuffer::OpenGLFramebuffer(FrameBufferFormat fmt) : Framebuffer(fmt) { - glGenFramebuffers(1, &uid); - glBindFramebuffer(GL_FRAMEBUFFER, uid); - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); +int OpenGLFramebuffer::getTexture() { + return texture; +} - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fmt.width, fmt.height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); +OpenGLFramebuffer::OpenGLFramebuffer(FrameBufferFormat fmt) : Framebuffer(fmt) { + glGenFramebuffers(1, &uid); + glBindFramebuffer(GL_FRAMEBUFFER, uid); + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fmt.width, fmt.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - glGenRenderbuffers(1, &depth); - glBindRenderbuffer(GL_RENDERBUFFER, depth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, fmt.width, fmt.height); + glGenRenderbuffers(1, &depth); + glBindRenderbuffer(GL_RENDERBUFFER, depth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, fmt.width, fmt.height); - glFramebufferRenderbuffer( - GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth - ); - - GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - Logger::Log(Logger::FATAL, "Graphics", "Couldn't create framebuffer object ! (%d)", status); - } - unbind(); - } + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth); - Eigen::Vector4i OpenGLFramebuffer::readPixel(int x, int y) { - glFlush(); - glFinish(); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - auto pixels = Eigen::Vector4i(); - glReadPixels(x, format.height-y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); - return pixels; + GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + Logger::Log(Logger::FATAL, "Graphics", "Couldn't create framebuffer object ! (%d)", status); } -} \ No newline at end of file + unbind(); +} + +void OpenGLFramebuffer::bindAttachment(int slot) const { + glActiveTexture(GL_TEXTURE0 + slot); + glBindTexture(GL_TEXTURE_2D, texture); +} + +Eigen::Vector4i OpenGLFramebuffer::readPixel(int x, int y) { + glFlush(); + glFinish(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + auto pixels = Eigen::Vector4i(); + glReadPixels(x, format.height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); + return pixels; +} +} // namespace ICE \ No newline at end of file diff --git a/ICE/IO/src/Project.cpp b/ICE/IO/src/Project.cpp index 0100d6b9..71c9c2a3 100644 --- a/ICE/IO/src/Project.cpp +++ b/ICE/IO/src/Project.cpp @@ -51,6 +51,8 @@ bool Project::CreateDirectories() { copyAssetFile("Shaders", "normal", "Assets/Shaders/normal.fs"); copyAssetFile("Shaders", "picking", "Assets/Shaders/picking.vs"); copyAssetFile("Shaders", "picking", "Assets/Shaders/picking.fs"); + copyAssetFile("Shaders", "lastpass", "Assets/Shaders/lastpass.vs"); + copyAssetFile("Shaders", "lastpass", "Assets/Shaders/lastpass.fs"); copyAssetFile("Cubemaps", "skybox", "Assets/Textures/skybox.png"); copyAssetFile("Materials", "base_mat", "Assets/Materials/base_mat.icm"); @@ -59,6 +61,7 @@ bool Project::CreateDirectories() { assetBank->addAsset("solid", {m_shaders_directory / "solid.vs", m_shaders_directory / "solid.fs"}); assetBank->addAsset("phong", {m_shaders_directory / "phong.vs", m_shaders_directory / "phong.fs"}); assetBank->addAsset("normal", {m_shaders_directory / "normal.vs", m_shaders_directory / "normal.fs"}); + assetBank->addAsset("lastpass", {m_shaders_directory / "lastpass.vs", m_shaders_directory / "lastpass.fs"}); assetBank->addAsset("__ice__picking_shader", {m_shaders_directory / "picking.vs", m_shaders_directory / "picking.fs"}); assetBank->addAsset("skybox", {m_cubemaps_directory / "skybox.png"}); assetBank->addAsset("base_mat", {m_materials_directory / "base_mat.icm"}); diff --git a/ICE/System/include/RenderSystem.h b/ICE/System/include/RenderSystem.h index a2ed60eb..f6d18aa4 100644 --- a/ICE/System/include/RenderSystem.h +++ b/ICE/System/include/RenderSystem.h @@ -25,6 +25,7 @@ class RenderSystem : public System { void setCamera(const std::shared_ptr &camera); void setTarget(const std::shared_ptr &fb); + void setViewport(int x, int y, int w, int h); private: std::shared_ptr m_renderer; diff --git a/ICE/System/src/RenderSystem.cpp b/ICE/System/src/RenderSystem.cpp index f6500a46..b28ed8bb 100644 --- a/ICE/System/src/RenderSystem.cpp +++ b/ICE/System/src/RenderSystem.cpp @@ -45,4 +45,11 @@ void RenderSystem::setCamera(const std::shared_ptr &camera) { void RenderSystem::setTarget(const std::shared_ptr &fb) { m_renderer->setTarget(fb); } + +void RenderSystem::setViewport(int x, int y, int w, int h) { + if (w > 0 && h > 0) { + m_renderer->resize(w, h); + } +} + } // namespace ICE \ No newline at end of file diff --git a/ICE/Util/include/GLFWWindow.h b/ICE/Util/include/GLFWWindow.h index defe6ba8..0f163936 100644 --- a/ICE/Util/include/GLFWWindow.h +++ b/ICE/Util/include/GLFWWindow.h @@ -19,10 +19,19 @@ class GLFWWindow : public Window { void getFramebufferSize(int* width, int* height) override; void setSwapInterval(int interval) override; void makeContextCurrent() override; + void setResizeCallback(const WindowResizeCallback& callback) override; + std::pair getSize() const override; + + void windowResized(int w, int h); private: GLFWwindow* m_handle; + int m_width; + int m_height; std::shared_ptr m_mouse_handler; std::shared_ptr m_keyboard_handler; + WindowResizeCallback m_resize_callback = [](int, int) { + }; + }; } // namespace ICE \ No newline at end of file diff --git a/ICE/Util/include/Window.h b/ICE/Util/include/Window.h index 167bac89..60a07346 100644 --- a/ICE/Util/include/Window.h +++ b/ICE/Util/include/Window.h @@ -7,6 +7,8 @@ #include "MouseHandler.h" namespace ICE { +using WindowResizeCallback = std::function; + class Window { public: virtual ~Window() {} @@ -19,5 +21,7 @@ class Window { virtual void getFramebufferSize(int* width, int* height) = 0; virtual void setSwapInterval(int interval) = 0; virtual void makeContextCurrent() = 0; + virtual void setResizeCallback(const WindowResizeCallback &callback) = 0; + virtual std::pair getSize() const = 0; }; } // namespace ICE \ No newline at end of file diff --git a/ICE/Util/src/GLFWWindow.cpp b/ICE/Util/src/GLFWWindow.cpp index 87b3eaae..6cfa534a 100644 --- a/ICE/Util/src/GLFWWindow.cpp +++ b/ICE/Util/src/GLFWWindow.cpp @@ -8,7 +8,7 @@ namespace ICE { -GLFWWindow::GLFWWindow(int width, int height, const std::string& title) { +GLFWWindow::GLFWWindow(int width, int height, const std::string& title) : m_width(width), m_height(height) { if (!glfwInit()) throw ICEException("Couldn't init GLFW"); // Decide GL+GLSL versions @@ -34,6 +34,11 @@ GLFWWindow::GLFWWindow(int width, int height, const std::string& title) { m_keyboard_handler = std::make_shared(*this); glfwSetWindowUserPointer(m_handle, this); + + glfwSetWindowSizeCallback(m_handle, [](GLFWwindow* w, int width, int height) { + GLFWWindow* self = (GLFWWindow*) glfwGetWindowUserPointer(w); + self->windowResized(width, height); + }); } std::pair, std::shared_ptr> GLFWWindow::getInputHandlers() const { @@ -66,4 +71,19 @@ void GLFWWindow::setSwapInterval(int interval) { void GLFWWindow::makeContextCurrent() { glfwMakeContextCurrent(m_handle); } + +void GLFWWindow::setResizeCallback(const WindowResizeCallback& callback) { + m_resize_callback = callback; +} + +std::pair GLFWWindow::getSize() const { + return {m_width, m_height}; +} + +void GLFWWindow::windowResized(int w, int h) { + m_width = w; + m_height = h; + m_resize_callback(w, h); +} + } // namespace ICE \ No newline at end of file diff --git a/ICEBERG/UI/NewMaterialWidget.h b/ICEBERG/UI/NewMaterialWidget.h index f82166b2..d4819891 100644 --- a/ICEBERG/UI/NewMaterialWidget.h +++ b/ICEBERG/UI/NewMaterialWidget.h @@ -166,7 +166,8 @@ class NewMaterialWidget : public Widget { ICE::Scene s("preview_scene"); auto render_system = std::make_shared(); - render_system->setRenderer(std::make_shared(m_engine->getApi(), s.getRegistry(), m_engine->getAssetBank())); + render_system->setRenderer( + std::make_shared(m_engine->getApi(), m_engine->getGraphicsFactory(), s.getRegistry(), m_engine->getAssetBank())); auto camera = std::make_shared(60.0, 1.0, 0.01, 10000.0); camera->backward(2); @@ -184,7 +185,7 @@ class NewMaterialWidget : public Widget { render_system->setTarget(preview_framebuffer); render_system->update(1.0f); - return preview_framebuffer->getTexture(); + return static_cast(0) + preview_framebuffer->getTexture(); } bool accepted() { diff --git a/ICEBERG/UI/ViewportWidget.h b/ICEBERG/UI/ViewportWidget.h index 059a85ff..ace88e6a 100644 --- a/ICEBERG/UI/ViewportWidget.h +++ b/ICEBERG/UI/ViewportWidget.h @@ -28,11 +28,8 @@ class ViewportWidget : public Widget { ImVec2 pos = ImGui::GetCursorScreenPos(); const float window_width = ImGui::GetContentRegionAvail().x; const float window_height = ImGui::GetContentRegionAvail().y; + ImGui::Image(texture_ptr, {window_width, window_height}, ImVec2(0, 1), ImVec2(1, 0)); - ImGui::GetWindowDrawList()->AddImage((void *) texture_ptr, ImVec2(pos.x, pos.y), ImVec2(pos.x + window_width, pos.y + window_height), - ImVec2(0, 1), ImVec2(1, 0)); - - //ImGuizmo::SetRect(pos.x, pos.y, window_width, window_height); auto drag = ImGui::GetMouseDragDelta(0); if (ImGui::IsWindowHovered()) { if (ImGui::IsMouseDragging(0)) { @@ -58,9 +55,8 @@ class ViewportWidget : public Widget { callback("lc_pressed"); } } - ImVec2 view = ImGui::GetContentRegionAvail(); - callback("resize", view.x, view.y); - ImGuizmo::SetRect(pos.x, pos.y, view.x, view.y); + callback("resize", window_width, window_height); + ImGuizmo::SetRect(pos.x, pos.y, window_width, window_height); ImGuizmo::SetDrawlist(ImGui::GetWindowDrawList()); ImGui::End(); } diff --git a/ICEBERG/src/Assets.cpp b/ICEBERG/src/Assets.cpp index 09731120..cf302c80 100644 --- a/ICEBERG/src/Assets.cpp +++ b/ICEBERG/src/Assets.cpp @@ -31,14 +31,14 @@ void* Assets::createThumbnail(const ICE::AssetBankEntry& entry) { ICE::Scene s("preview_scene"); auto render_system = std::make_shared(); - render_system->setRenderer(std::make_shared(m_engine->getApi(), s.getRegistry(), m_engine->getAssetBank())); + render_system->setRenderer(std::make_shared(m_engine->getApi(), m_g_factory, s.getRegistry(), m_engine->getAssetBank())); auto camera = std::make_shared(60.0, 1.0, 0.01, 10000.0); camera->backward(2); camera->up(1); camera->pitch(-30); render_system->setCamera(camera); - + render_system->setViewport(0, 0, 256, 256); s.getRegistry()->addSystem(render_system); auto entity = s.createEntity(); @@ -60,7 +60,7 @@ void* Assets::createThumbnail(const ICE::AssetBankEntry& entry) { render_system->setTarget(preview_framebuffer); render_system->update(1.0f); - return preview_framebuffer->getTexture(); + return static_cast(0) + preview_framebuffer->getTexture(); } void Assets::rebuildViewer() { diff --git a/ICEBERG/src/Iceberg.cpp b/ICEBERG/src/Iceberg.cpp index 7a8d342c..43ddccd6 100644 --- a/ICEBERG/src/Iceberg.cpp +++ b/ICEBERG/src/Iceberg.cpp @@ -47,8 +47,10 @@ class Iceberg { m_engine->step(m_engine->getProject()->getCurrentScene()); } ImGui::ShowDemoWindow(); + ImGui::Render(); + m_engine->getApi()->bindDefaultFramebuffer(); int display_w, display_h; m_window->getFramebufferSize(&display_w, &display_h); glViewport(0, 0, display_w, display_h); diff --git a/ICEBERG/src/Viewport.cpp b/ICEBERG/src/Viewport.cpp index 6f9ba6c8..15bfede2 100644 --- a/ICEBERG/src/Viewport.cpp +++ b/ICEBERG/src/Viewport.cpp @@ -20,8 +20,8 @@ Viewport::Viewport(const std::shared_ptr &engine) : m_engine(eng } }); ui.registerCallback("resize", [this](float width, float height) { - m_engine->getInternalFramebuffer()->resize(width, height); m_engine->getCamera()->resize(width, height); + m_engine->getProject()->getCurrentScene()->getRegistry()->getSystem()->setViewport(0, 0, width, height); }); ui.registerCallback("translate_clicked", [this] { m_guizmo_mode = ImGuizmo::OPERATION::TRANSLATE; }); ui.registerCallback("rotate_clicked", [this] { m_guizmo_mode = ImGuizmo::OPERATION::ROTATE; }); @@ -29,7 +29,7 @@ Viewport::Viewport(const std::shared_ptr &engine) : m_engine(eng } bool Viewport::update() { - ui.setTexture(m_engine->getInternalFramebuffer()->getTexture()); + ui.setTexture(static_cast(0) + m_engine->getInternalFramebuffer()->getTexture()); ui.render(); ImGuizmo::Enable(true);