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); } } }