refactor(srp): move recording helpers into universal extensions

This commit is contained in:
2026-04-19 14:42:57 +08:00
parent f4d4112e2f
commit 8edc68f02b
9 changed files with 309 additions and 167 deletions

View File

@@ -1,33 +1,9 @@
using System;
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class ScriptableRenderContext
{
private enum RecordedScenePhase
{
Opaque = 0,
Skybox = 1,
Transparent = 3
}
private enum RecordedSceneInjectionPoint
{
BeforeOpaque = 0,
AfterOpaque = 1,
BeforeSkybox = 2,
AfterSkybox = 3,
BeforeTransparent = 4,
AfterTransparent = 5
}
private enum RecordedFullscreenPassType
{
ColorScale = 0,
ShaderVector = 1
}
private readonly ulong m_nativeHandle;
internal ScriptableRenderContext(ulong nativeHandle)
@@ -41,130 +17,6 @@ namespace XCEngine.Rendering
internal ulong nativeHandle =>
m_nativeHandle;
public bool RecordScene()
{
return InternalCalls
.Rendering_ScriptableRenderContext_RecordScene(
m_nativeHandle);
}
public bool RecordOpaqueScenePhase()
{
return RecordScenePhaseInternal(
RecordedScenePhase.Opaque);
}
public bool RecordSkyboxScenePhase()
{
return RecordScenePhaseInternal(
RecordedScenePhase.Skybox);
}
public bool RecordTransparentScenePhase()
{
return RecordScenePhaseInternal(
RecordedScenePhase.Transparent);
}
public bool RecordBeforeOpaqueInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.BeforeOpaque);
}
public bool RecordAfterOpaqueInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.AfterOpaque);
}
public bool RecordBeforeSkyboxInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.BeforeSkybox);
}
public bool RecordAfterSkyboxInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.AfterSkybox);
}
public bool RecordBeforeTransparentInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.BeforeTransparent);
}
public bool RecordAfterTransparentInjection()
{
return RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint.AfterTransparent);
}
public bool RecordColorScaleFullscreenPass(
Vector4 colorScale)
{
return RecordFullscreenPassInternal(
RecordedFullscreenPassType.ColorScale,
string.Empty,
string.Empty,
colorScale);
}
public bool RecordShaderVectorFullscreenPass(
string shaderPath,
Vector4 vectorPayload,
string passName = null)
{
if (string.IsNullOrEmpty(shaderPath))
{
throw new ArgumentException(
"Fullscreen shader path cannot be null or empty.",
nameof(shaderPath));
}
return RecordFullscreenPassInternal(
RecordedFullscreenPassType.ShaderVector,
shaderPath,
passName ?? string.Empty,
vectorPayload);
}
private bool RecordScenePhaseInternal(
RecordedScenePhase scenePhase)
{
return InternalCalls
.Rendering_ScriptableRenderContext_RecordScenePhase(
m_nativeHandle,
(int)scenePhase);
}
private bool RecordSceneInjectionPointInternal(
RecordedSceneInjectionPoint injectionPoint)
{
return InternalCalls
.Rendering_ScriptableRenderContext_RecordSceneInjectionPoint(
m_nativeHandle,
(int)injectionPoint);
}
private bool RecordFullscreenPassInternal(
RecordedFullscreenPassType passType,
string shaderPath,
string passName,
Vector4 vectorPayload)
{
return InternalCalls
.Rendering_ScriptableRenderContext_RecordFullscreenPass(
m_nativeHandle,
(int)passType,
shaderPath,
passName,
ref vectorPayload);
}
}
}

View File

@@ -21,17 +21,8 @@ namespace XCEngine.Rendering
.Rendering_ScriptableRenderPipelineCameraRequestContext_GetRenderedRequestCount(
m_nativeHandle);
public bool hasDirectionalShadow =>
InternalCalls
.Rendering_ScriptableRenderPipelineCameraRequestContext_GetHasDirectionalShadow(
m_nativeHandle);
public void ClearDirectionalShadow()
{
InternalCalls
.Rendering_ScriptableRenderPipelineCameraRequestContext_ClearDirectionalShadow(
m_nativeHandle);
}
internal ulong nativeHandle =>
m_nativeHandle;
}
}

View File

@@ -10,7 +10,7 @@ namespace XCEngine.Rendering.Universal
ScriptableRenderPipelineCameraRequestContext context)
{
if (context != null &&
context.hasDirectionalShadow)
context.HasDirectionalShadow())
{
context.ClearDirectionalShadow();
}

View File

@@ -0,0 +1,185 @@
using System;
using XCEngine;
using XCEngine.Rendering;
namespace XCEngine.Rendering.Universal
{
public static class ScriptableRenderContextExtensions
{
private enum RecordedScenePhase
{
Opaque = 0,
Skybox = 1,
Transparent = 3
}
private enum RecordedSceneInjectionPoint
{
BeforeOpaque = 0,
AfterOpaque = 1,
BeforeSkybox = 2,
AfterSkybox = 3,
BeforeTransparent = 4,
AfterTransparent = 5
}
private enum RecordedFullscreenPassType
{
ColorScale = 0,
ShaderVector = 1
}
public static bool RecordScene(
this ScriptableRenderContext context)
{
return context != null &&
InternalCalls
.Rendering_ScriptableRenderContext_RecordScene(
context.nativeHandle);
}
public static bool RecordOpaqueScenePhase(
this ScriptableRenderContext context)
{
return RecordScenePhaseInternal(
context,
RecordedScenePhase.Opaque);
}
public static bool RecordSkyboxScenePhase(
this ScriptableRenderContext context)
{
return RecordScenePhaseInternal(
context,
RecordedScenePhase.Skybox);
}
public static bool RecordTransparentScenePhase(
this ScriptableRenderContext context)
{
return RecordScenePhaseInternal(
context,
RecordedScenePhase.Transparent);
}
public static bool RecordBeforeOpaqueInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.BeforeOpaque);
}
public static bool RecordAfterOpaqueInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.AfterOpaque);
}
public static bool RecordBeforeSkyboxInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.BeforeSkybox);
}
public static bool RecordAfterSkyboxInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.AfterSkybox);
}
public static bool RecordBeforeTransparentInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.BeforeTransparent);
}
public static bool RecordAfterTransparentInjection(
this ScriptableRenderContext context)
{
return RecordSceneInjectionPointInternal(
context,
RecordedSceneInjectionPoint.AfterTransparent);
}
public static bool RecordColorScaleFullscreenPass(
this ScriptableRenderContext context,
Vector4 colorScale)
{
return RecordFullscreenPassInternal(
context,
RecordedFullscreenPassType.ColorScale,
string.Empty,
string.Empty,
colorScale);
}
public static bool RecordShaderVectorFullscreenPass(
this ScriptableRenderContext context,
string shaderPath,
Vector4 vectorPayload,
string passName = null)
{
if (string.IsNullOrEmpty(shaderPath))
{
throw new ArgumentException(
"Fullscreen shader path cannot be null or empty.",
nameof(shaderPath));
}
return RecordFullscreenPassInternal(
context,
RecordedFullscreenPassType.ShaderVector,
shaderPath,
passName ?? string.Empty,
vectorPayload);
}
private static bool RecordScenePhaseInternal(
ScriptableRenderContext context,
RecordedScenePhase scenePhase)
{
return context != null &&
InternalCalls
.Rendering_ScriptableRenderContext_RecordScenePhase(
context.nativeHandle,
(int)scenePhase);
}
private static bool RecordSceneInjectionPointInternal(
ScriptableRenderContext context,
RecordedSceneInjectionPoint injectionPoint)
{
return context != null &&
InternalCalls
.Rendering_ScriptableRenderContext_RecordSceneInjectionPoint(
context.nativeHandle,
(int)injectionPoint);
}
private static bool RecordFullscreenPassInternal(
ScriptableRenderContext context,
RecordedFullscreenPassType passType,
string shaderPath,
string passName,
Vector4 vectorPayload)
{
return context != null &&
InternalCalls
.Rendering_ScriptableRenderContext_RecordFullscreenPass(
context.nativeHandle,
(int)passType,
shaderPath,
passName,
ref vectorPayload);
}
}
}

View File

@@ -0,0 +1,30 @@
using XCEngine;
using XCEngine.Rendering;
namespace XCEngine.Rendering.Universal
{
public static class ScriptableRenderPipelineCameraRequestContextExtensions
{
public static bool HasDirectionalShadow(
this ScriptableRenderPipelineCameraRequestContext context)
{
return context != null &&
InternalCalls
.Rendering_ScriptableRenderPipelineCameraRequestContext_GetHasDirectionalShadow(
context.nativeHandle);
}
public static void ClearDirectionalShadow(
this ScriptableRenderPipelineCameraRequestContext context)
{
if (context == null)
{
return;
}
InternalCalls
.Rendering_ScriptableRenderPipelineCameraRequestContext_ClearDirectionalShadow(
context.nativeHandle);
}
}
}