Skip to content

Commit

Permalink
refactor(rendering): replace enableScreenPicking with nullptr check
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas7770 committed Jan 25, 2024
1 parent 8e42689 commit 6193c05
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
3 changes: 1 addition & 2 deletions engine/include/cubos/engine/renderer/deferred_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions engine/include/cubos/engine/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions engine/src/cubos/engine/renderer/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions engine/src/cubos/engine/renderer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cubos/engine/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 6193c05

Please sign in to comment.