refactor(srp): move rendering data ownership into universal package

This commit is contained in:
2026-04-19 14:19:57 +08:00
parent a7cda9375a
commit f4d4112e2f
14 changed files with 325 additions and 298 deletions

View File

@@ -0,0 +1,296 @@
using XCEngine;
using XCEngine.Rendering;
namespace XCEngine.Rendering.Universal
{
internal static class RenderingDataResolver
{
public static CameraData ResolveCameraData(
ScriptableRenderContext context)
{
if (context == null)
{
return CameraData.Default;
}
ulong nativeHandle = context.nativeHandle;
Matrix4x4 view;
Matrix4x4 projection;
Matrix4x4 viewProjection;
Vector3 worldPosition;
Vector3 worldRight;
Vector3 worldUp;
Vector3 worldForward;
Color clearColor;
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraView(
nativeHandle,
out view);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraProjection(
nativeHandle,
out projection);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraViewProjection(
nativeHandle,
out viewProjection);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraWorldPosition(
nativeHandle,
out worldPosition);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraWorldRight(
nativeHandle,
out worldRight);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraWorldUp(
nativeHandle,
out worldUp);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraWorldForward(
nativeHandle,
out worldForward);
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraClearColor(
nativeHandle,
out clearColor);
return new CameraData(
view,
projection,
viewProjection,
worldPosition,
worldRight,
worldUp,
worldForward,
clearColor,
(RenderClearFlags)InternalCalls
.Rendering_ScriptableRenderContext_GetCameraClearFlags(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraPerspectiveProjection(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraVerticalFovRadians(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraOrthographicSize(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraAspectRatio(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraNearClipPlane(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraFarClipPlane(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraViewportWidth(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetCameraViewportHeight(
nativeHandle));
}
public static LightingData ResolveLightingData(
ScriptableRenderContext context)
{
if (context == null)
{
return LightingData.Default;
}
ulong nativeHandle = context.nativeHandle;
Vector3 mainDirectionalLightDirection;
Color mainDirectionalLightColor;
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalLightDirection(
nativeHandle,
out mainDirectionalLightDirection);
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalLightColor(
nativeHandle,
out mainDirectionalLightColor);
return new LightingData(
new DirectionalLightData(
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalLightEnabled(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalLightCastsShadows(
nativeHandle),
mainDirectionalLightDirection,
mainDirectionalLightColor,
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalLightIntensity(
nativeHandle)),
InternalCalls
.Rendering_ScriptableRenderContext_GetHasMainDirectionalShadow(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetAdditionalLightCount(
nativeHandle));
}
public static ShadowData ResolveShadowData(
ScriptableRenderContext context)
{
if (context == null)
{
return ShadowData.Default;
}
ulong nativeHandle = context.nativeHandle;
Matrix4x4 viewProjection;
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowViewProjection(
nativeHandle,
out viewProjection);
return new ShadowData(
new DirectionalShadowData(
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowEnabled(
nativeHandle),
viewProjection,
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowOrthographicHalfExtent(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowNearClipPlane(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowFarClipPlane(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapWidth(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapHeight(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowWorldTexelSize(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowReceiverDepthBias(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowNormalBiasScale(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowStrength(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasFactor(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasUnits(
nativeHandle)));
}
public static EnvironmentData ResolveEnvironmentData(
ScriptableRenderContext context)
{
if (context == null)
{
return EnvironmentData.Default;
}
ulong nativeHandle = context.nativeHandle;
Color skyboxTopColor;
Color skyboxHorizonColor;
Color skyboxBottomColor;
InternalCalls
.Rendering_ScriptableRenderContext_GetEnvironmentSkyboxTopColor(
nativeHandle,
out skyboxTopColor);
InternalCalls
.Rendering_ScriptableRenderContext_GetEnvironmentSkyboxHorizonColor(
nativeHandle,
out skyboxHorizonColor);
InternalCalls
.Rendering_ScriptableRenderContext_GetEnvironmentSkyboxBottomColor(
nativeHandle,
out skyboxBottomColor);
return new EnvironmentData(
(RenderEnvironmentMode)InternalCalls
.Rendering_ScriptableRenderContext_GetEnvironmentMode(
nativeHandle),
skyboxTopColor,
skyboxHorizonColor,
skyboxBottomColor);
}
public static FinalColorData ResolveFinalColorData(
ScriptableRenderContext context)
{
if (context == null)
{
return FinalColorData.Default;
}
ulong nativeHandle = context.nativeHandle;
Vector4 finalColorScale;
InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorScale(
nativeHandle,
out finalColorScale);
FinalColorSettings settings =
FinalColorSettings.CreateDefault();
settings.outputTransferMode =
(FinalColorOutputTransferMode)InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorOutputTransferMode(
nativeHandle);
settings.exposureMode =
(FinalColorExposureMode)InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorExposureMode(
nativeHandle);
settings.exposureValue =
InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorExposureValue(
nativeHandle);
settings.toneMappingMode =
(FinalColorToneMappingMode)InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorToneMappingMode(
nativeHandle);
settings.finalColorScale =
finalColorScale;
return new FinalColorData(
settings,
InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorHasPipelineDefaults(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetFinalColorHasCameraOverrides(
nativeHandle));
}
public static StageColorData ResolveStageColorData(
ScriptableRenderContext context)
{
if (context == null)
{
return StageColorData.Default;
}
ulong nativeHandle = context.nativeHandle;
return new StageColorData(
(CameraFrameColorSource)InternalCalls
.Rendering_ScriptableRenderContext_GetStageColorSource(
nativeHandle),
InternalCalls
.Rendering_ScriptableRenderContext_GetStageUsesGraphManagedOutputColor(
nativeHandle));
}
}
}