2026-04-18 13:51:09 +08:00
|
|
|
using System;
|
2026-04-19 02:38:48 +08:00
|
|
|
using XCEngine;
|
2026-04-18 13:51:09 +08:00
|
|
|
|
2026-04-19 02:38:48 +08:00
|
|
|
namespace XCEngine.Rendering
|
2026-04-17 21:53:52 +08:00
|
|
|
{
|
|
|
|
|
public sealed class ScriptableRenderContext
|
|
|
|
|
{
|
2026-04-19 02:38:48 +08:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 21:53:52 +08:00
|
|
|
private readonly ulong m_nativeHandle;
|
|
|
|
|
|
|
|
|
|
internal ScriptableRenderContext(ulong nativeHandle)
|
|
|
|
|
{
|
|
|
|
|
m_nativeHandle = nativeHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CameraFrameStage stage =>
|
|
|
|
|
(CameraFrameStage)InternalCalls.Rendering_ScriptableRenderContext_GetStage(
|
|
|
|
|
m_nativeHandle);
|
|
|
|
|
|
2026-04-19 14:19:57 +08:00
|
|
|
internal ulong nativeHandle =>
|
|
|
|
|
m_nativeHandle;
|
2026-04-19 00:05:29 +08:00
|
|
|
|
2026-04-19 05:03:56 +08:00
|
|
|
public bool RecordScene()
|
2026-04-17 21:53:52 +08:00
|
|
|
{
|
|
|
|
|
return InternalCalls
|
2026-04-18 13:30:45 +08:00
|
|
|
.Rendering_ScriptableRenderContext_RecordScene(
|
2026-04-17 21:53:52 +08:00
|
|
|
m_nativeHandle);
|
|
|
|
|
}
|
2026-04-17 22:26:51 +08:00
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordOpaqueScenePhase()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordScenePhaseInternal(
|
|
|
|
|
RecordedScenePhase.Opaque);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordSkyboxScenePhase()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordScenePhaseInternal(
|
|
|
|
|
RecordedScenePhase.Skybox);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordTransparentScenePhase()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordScenePhaseInternal(
|
|
|
|
|
RecordedScenePhase.Transparent);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordBeforeOpaqueInjection()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.BeforeOpaque);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordAfterOpaqueInjection()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.AfterOpaque);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordBeforeSkyboxInjection()
|
2026-04-17 22:26:51 +08:00
|
|
|
{
|
2026-04-19 02:38:48 +08:00
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.BeforeSkybox);
|
2026-04-17 22:26:51 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordAfterSkyboxInjection()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.AfterSkybox);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordBeforeTransparentInjection()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.BeforeTransparent);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordAfterTransparentInjection()
|
2026-04-19 02:38:48 +08:00
|
|
|
{
|
|
|
|
|
return RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint.AfterTransparent);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordColorScaleFullscreenPass(
|
2026-04-19 02:38:48 +08:00
|
|
|
Vector4 colorScale)
|
|
|
|
|
{
|
|
|
|
|
return RecordFullscreenPassInternal(
|
|
|
|
|
RecordedFullscreenPassType.ColorScale,
|
|
|
|
|
string.Empty,
|
|
|
|
|
string.Empty,
|
|
|
|
|
colorScale);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 13:05:57 +08:00
|
|
|
public bool RecordShaderVectorFullscreenPass(
|
2026-04-19 02:38:48 +08:00
|
|
|
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)
|
2026-04-17 22:26:51 +08:00
|
|
|
{
|
|
|
|
|
return InternalCalls
|
2026-04-18 13:30:45 +08:00
|
|
|
.Rendering_ScriptableRenderContext_RecordScenePhase(
|
2026-04-17 22:26:51 +08:00
|
|
|
m_nativeHandle,
|
|
|
|
|
(int)scenePhase);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 02:38:48 +08:00
|
|
|
private bool RecordSceneInjectionPointInternal(
|
|
|
|
|
RecordedSceneInjectionPoint injectionPoint)
|
2026-04-17 22:26:51 +08:00
|
|
|
{
|
|
|
|
|
return InternalCalls
|
2026-04-18 13:30:45 +08:00
|
|
|
.Rendering_ScriptableRenderContext_RecordSceneInjectionPoint(
|
2026-04-17 22:26:51 +08:00
|
|
|
m_nativeHandle,
|
|
|
|
|
(int)injectionPoint);
|
|
|
|
|
}
|
2026-04-17 22:58:39 +08:00
|
|
|
|
2026-04-19 02:38:48 +08:00
|
|
|
private bool RecordFullscreenPassInternal(
|
|
|
|
|
RecordedFullscreenPassType passType,
|
|
|
|
|
string shaderPath,
|
|
|
|
|
string passName,
|
|
|
|
|
Vector4 vectorPayload)
|
2026-04-17 22:58:39 +08:00
|
|
|
{
|
|
|
|
|
return InternalCalls
|
2026-04-18 13:51:09 +08:00
|
|
|
.Rendering_ScriptableRenderContext_RecordFullscreenPass(
|
2026-04-17 22:58:39 +08:00
|
|
|
m_nativeHandle,
|
2026-04-19 02:38:48 +08:00
|
|
|
(int)passType,
|
2026-04-18 16:08:01 +08:00
|
|
|
shaderPath,
|
|
|
|
|
passName,
|
2026-04-18 13:51:09 +08:00
|
|
|
ref vectorPayload);
|
2026-04-17 22:58:39 +08:00
|
|
|
}
|
2026-04-19 00:05:29 +08:00
|
|
|
|
2026-04-17 21:53:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 02:38:48 +08:00
|
|
|
|