diff --git a/engine/include/cubos/engine/renderer/deferred_renderer.hpp b/engine/include/cubos/engine/renderer/deferred_renderer.hpp index 8f9e078d71..97f6c1951c 100644 --- a/engine/include/cubos/engine/renderer/deferred_renderer.hpp +++ b/engine/include/cubos/engine/renderer/deferred_renderer.hpp @@ -48,8 +48,7 @@ namespace cubos::engine void onResize(glm::uvec2 size) override; void onRender(const glm::mat4& view, const Viewport& viewport, const Camera& camera, const RendererFrame& frame, - core::gl::Framebuffer target, core::gl::Framebuffer pickingBuffer, - bool enableScreenPicking) override; + core::gl::Framebuffer target, core::gl::Framebuffer pickingBuffer) override; private: void createSSAOTextures(); diff --git a/engine/include/cubos/engine/renderer/renderer.hpp b/engine/include/cubos/engine/renderer/renderer.hpp index c5148ef262..b55578deaa 100644 --- a/engine/include/cubos/engine/renderer/renderer.hpp +++ b/engine/include/cubos/engine/renderer/renderer.hpp @@ -94,11 +94,10 @@ namespace cubos::engine /// @param camera Camera to use. /// @param frame Frame to draw. /// @param pickingBuffer Screen picking framebuffer. - /// @param enableScreenPicking Whether to draw to the screen picking buffer. /// @param usePostProcessing Whether to use post processing. /// @param target Target framebuffer to draw to. void render(const glm::mat4& view, const Viewport& viewport, const engine::Camera& camera, - const RendererFrame& frame, const core::gl::Framebuffer& pickingBuffer, bool enableScreenPicking, + const RendererFrame& frame, const core::gl::Framebuffer& pickingBuffer = nullptr, bool usePostProcessing = true, const core::gl::Framebuffer& target = nullptr); /// @brief Gets a reference to the post processing manager. @@ -127,10 +126,9 @@ namespace cubos::engine /// @param frame Frame to draw. /// @param target Target framebuffer. /// @param pickingBuffer Screen picking framebuffer. - /// @param enableScreenPicking Whether to draw to the screen picking buffer. virtual void onRender(const glm::mat4& view, const Viewport& viewport, const Camera& camera, const RendererFrame& frame, core::gl::Framebuffer target, - core::gl::Framebuffer pickingBuffer, bool enableScreenPicking) = 0; + core::gl::Framebuffer pickingBuffer) = 0; private: /// @brief Called when the internal texture used for post processing needs to be resized. diff --git a/engine/src/cubos/engine/renderer/deferred_renderer.cpp b/engine/src/cubos/engine/renderer/deferred_renderer.cpp index e50b2921f7..e20757dddc 100644 --- a/engine/src/cubos/engine/renderer/deferred_renderer.cpp +++ b/engine/src/cubos/engine/renderer/deferred_renderer.cpp @@ -658,8 +658,7 @@ void DeferredRenderer::onResize(glm::uvec2 size) } void DeferredRenderer::onRender(const glm::mat4& view, const Viewport& viewport, const Camera& camera, - const RendererFrame& frame, Framebuffer target, core::gl::Framebuffer pickingBuffer, - bool enableScreenPicking) + const RendererFrame& frame, Framebuffer target, core::gl::Framebuffer pickingBuffer) { // Steps: // 1. Prepare the MVP matrix. @@ -787,7 +786,7 @@ void DeferredRenderer::onRender(const glm::mat4& view, const Viewport& viewport, mRenderDevice.drawTrianglesIndexed(0, grid->indexCount); } - if (enableScreenPicking) + if (pickingBuffer) { // 5. Picking pass: // 5.1. Set the picking pass state. diff --git a/engine/src/cubos/engine/renderer/plugin.cpp b/engine/src/cubos/engine/renderer/plugin.cpp index ab2f38b3ab..bb6551ffee 100644 --- a/engine/src/cubos/engine/renderer/plugin.cpp +++ b/engine/src/cubos/engine/renderer/plugin.cpp @@ -123,6 +123,8 @@ static void draw(Renderer& renderer, const ActiveCameras& activeCameras, Rendere glm::mat4 views[4]{}; BaseRenderer::Viewport viewports[4]{}; + bool screenPickingEnabled = settings.getBool("cubos.renderer.screenpicking.enabled", true); + int cameraCount = 0; for (int i = 0; i < 4; ++i) // NOLINT(modernize-loop-convert) @@ -160,8 +162,8 @@ static void draw(Renderer& renderer, const ActiveCameras& activeCameras, Rendere for (int i = 0; i < cameraCount; ++i) { - renderer->render(views[i], viewports[i], cameras[i], frame, screenPicker.framebuffer(), - settings.getBool("cubos.renderer.screenpicking.enabled", true)); + renderer->render(views[i], viewports[i], cameras[i], frame, + screenPickingEnabled ? screenPicker.framebuffer() : nullptr); } frame.clear(); diff --git a/engine/src/cubos/engine/renderer/renderer.cpp b/engine/src/cubos/engine/renderer/renderer.cpp index b471608c2e..c9193bfb27 100644 --- a/engine/src/cubos/engine/renderer/renderer.cpp +++ b/engine/src/cubos/engine/renderer/renderer.cpp @@ -26,17 +26,17 @@ glm::uvec2 BaseRenderer::size() const void BaseRenderer::render(const glm::mat4& view, const Viewport& viewport, const engine::Camera& camera, const RendererFrame& frame, const core::gl::Framebuffer& pickingBuffer, - bool enableScreenPicking, bool usePostProcessing, const core::gl::Framebuffer& target) + bool usePostProcessing, const core::gl::Framebuffer& target) { if (usePostProcessing && mPpsManager.passCount() > 0) { - this->onRender(view, viewport, camera, frame, mFramebuffer, pickingBuffer, enableScreenPicking); + this->onRender(view, viewport, camera, frame, mFramebuffer, pickingBuffer); mPpsManager.provideInput(PostProcessingInput::Lighting, mTexture); mPpsManager.execute(target); } else { - this->onRender(view, viewport, camera, frame, target, pickingBuffer, enableScreenPicking); + this->onRender(view, viewport, camera, frame, target, pickingBuffer); } }