Files
XCEngine/engine/src/Rendering/SceneRenderFeaturePass.cpp

63 lines
2.3 KiB
C++

#include "Rendering/SceneRenderFeaturePass.h"
#include <XCEngine/Rendering/Graph/RenderGraphRecordingContext.h>
#include <XCEngine/Rendering/RenderPassGraphContract.h>
#include <algorithm>
namespace XCEngine {
namespace Rendering {
bool SceneRenderFeaturePass::RecordRenderGraph(
const SceneRenderFeaturePassRenderGraphContext& context) {
const bool usesSourceColor = context.sourceColorTexture.IsValid();
const bool writesColor =
std::any_of(
context.colorTargets.begin(),
context.colorTargets.end(),
[](RenderGraphTextureHandle handle) {
return handle.IsValid();
});
const RenderGraphRecordingContext baseRecordingContext =
BuildRenderGraphRecordingContext(context);
const RenderSurface sourceSurfaceTemplate =
baseRecordingContext.sourceSurface != nullptr
? *baseRecordingContext.sourceSurface
: (usesSourceColor ? context.surface : RenderSurface());
RenderGraphRecordingContextOverrides overrides = {};
overrides.overrideSourceSurface =
baseRecordingContext.sourceSurface == nullptr && usesSourceColor;
overrides.sourceSurface =
overrides.overrideSourceSurface ? &sourceSurfaceTemplate : nullptr;
const RenderGraphRecordingContext recordingContext =
CloneRenderGraphRecordingContext(
baseRecordingContext,
overrides);
const RenderPassGraphBeginCallback beginPassCallback =
context.beginPassCallback
? RenderPassGraphBeginCallback(
[beginPass = context.beginPassCallback,
clearAttachments = context.clearAttachments](
const RenderPassContext& passContext) {
return beginPass(passContext, clearAttachments);
})
: RenderPassGraphBeginCallback();
const RenderPassRenderGraphContext passContext =
BuildRenderPassRenderGraphContext(
recordingContext,
beginPassCallback,
context.endPassCallback);
return RecordRasterRenderPass(
*this,
passContext,
{
usesSourceColor,
writesColor,
context.depthTarget.IsValid()
});
}
} // namespace Rendering
} // namespace XCEngine