Skip to content

Commit

Permalink
[Render/RenderSystem] The copied frame is the last executed pass'
Browse files Browse the repository at this point in the history
- The render pass having been executed last is stored in the render graph and used afterward

- This is something that will be extremely useful later, e.g. for gamma correction, although it may be a bit too naïve at the moment
  - The last executed pass may not be the one the user wants to be displayed: there may be several final passes, one debug detached pass that's executed after the main ones, etc
  • Loading branch information
Razakhel committed Nov 13, 2024
1 parent 8bd98cb commit 53750df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/xrDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int main() {
const auto colorBuffer = Raz::Texture2D::create(2468, 2584, Raz::TextureColorspace::RGBA);
const auto depthBuffer = Raz::Texture2D::create(2468, 2584, Raz::TextureColorspace::DEPTH);

// The last executed pass *MUST* have a write color buffer, and at least the geometry pass *MUST* have a write depth buffer
Raz::RenderPass& geomPass = render.getGeometryPass();
geomPass.addWriteColorTexture(colorBuffer, 0);
geomPass.setWriteDepthTexture(depthBuffer);
Expand Down
1 change: 1 addition & 0 deletions include/RaZ/Render/RenderGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RenderGraph : public Graph<RenderPass> {
RenderPass m_geometryPass {};
std::vector<std::unique_ptr<RenderProcess>> m_renderProcesses {};
std::unordered_set<const RenderPass*> m_executedPasses {};
const RenderPass* m_lastExecutedPass {};
};

} // namespace Raz
Expand Down
2 changes: 2 additions & 0 deletions src/RaZ/Render/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void RenderGraph::execute(RenderSystem& renderSystem) {
}

executeGeometryPass(renderSystem);
m_lastExecutedPass = &m_geometryPass;

m_executedPasses.reserve(m_nodes.size() + 1);
m_executedPasses.emplace(&m_geometryPass);
Expand Down Expand Up @@ -110,6 +111,7 @@ void RenderGraph::executePass(const RenderPass& renderPass) {
executePass(*parentPass);

renderPass.execute();
m_lastExecutedPass = &renderPass;

m_executedPasses.emplace(&renderPass);
}
Expand Down
19 changes: 13 additions & 6 deletions src/RaZ/Render/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,25 @@ void RenderSystem::renderXrFrame() {

m_renderGraph.execute(*this);

// TODO: the returned color buffer must be the one from the render pass executed last
const Framebuffer& geomFramebuffer = m_renderGraph.m_geometryPass.getFramebuffer();
return std::make_pair(std::cref(geomFramebuffer.getColorBuffer(0)), std::cref(geomFramebuffer.getDepthBuffer()));
assert("Error: There is no valid last executed pass." && m_renderGraph.m_lastExecutedPass);
const Framebuffer& finalFramebuffer = m_renderGraph.m_lastExecutedPass->getFramebuffer();
assert("Error: The last executed pass must have at least one write color buffer." && finalFramebuffer.getColorBufferCount() >= 1);
assert("Error: Either the last executed pass or the geometry pass must have a write depth buffer."
&& (finalFramebuffer.hasDepthBuffer() || m_renderGraph.m_geometryPass.getFramebuffer().hasDepthBuffer()));

const Texture2D& depthBuffer = (finalFramebuffer.hasDepthBuffer() ? finalFramebuffer.getDepthBuffer()
: m_renderGraph.m_geometryPass.getFramebuffer().getDepthBuffer());
return std::make_pair(std::cref(finalFramebuffer.getColorBuffer(0)), std::cref(depthBuffer));
});

#if !defined(RAZ_NO_WINDOW)
if (!hasRendered)
return;

// TODO: the copied color buffer must be the one from the render pass executed last
const Framebuffer& geomFramebuffer = m_renderGraph.m_geometryPass.getFramebuffer();
copyToWindow(geomFramebuffer.getColorBuffer(0), geomFramebuffer.getDepthBuffer(), m_window->getWidth(), m_window->getHeight());
const Framebuffer& finalFramebuffer = m_renderGraph.m_lastExecutedPass->getFramebuffer();
const Texture2D& depthBuffer = (finalFramebuffer.hasDepthBuffer() ? finalFramebuffer.getDepthBuffer()
: m_renderGraph.m_geometryPass.getFramebuffer().getDepthBuffer());
copyToWindow(finalFramebuffer.getColorBuffer(0), depthBuffer, m_window->getWidth(), m_window->getHeight());
#endif
}
#endif
Expand Down

0 comments on commit 53750df

Please sign in to comment.