2026-04-19 00:05:29 +08:00
|
|
|
using System.Collections.Generic;
|
2026-04-19 02:38:48 +08:00
|
|
|
using XCEngine;
|
|
|
|
|
using XCEngine.Rendering;
|
2026-04-19 00:05:29 +08:00
|
|
|
|
2026-04-19 14:11:25 +08:00
|
|
|
namespace XCEngine.Rendering.Universal
|
2026-04-19 00:05:29 +08:00
|
|
|
{
|
|
|
|
|
public abstract class ScriptableRenderer
|
|
|
|
|
{
|
|
|
|
|
private readonly List<ScriptableRendererFeature> m_features =
|
|
|
|
|
new List<ScriptableRendererFeature>();
|
|
|
|
|
private readonly List<ScriptableRenderPass> m_activePassQueue =
|
|
|
|
|
new List<ScriptableRenderPass>();
|
2026-04-20 01:14:37 +08:00
|
|
|
private bool m_disposed;
|
2026-04-19 00:05:29 +08:00
|
|
|
|
|
|
|
|
protected ScriptableRenderer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 01:14:37 +08:00
|
|
|
internal void ReleaseRuntimeResourcesInstance()
|
|
|
|
|
{
|
|
|
|
|
if (m_disposed)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReleaseRuntimeResources();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_features.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
ScriptableRendererFeature feature = m_features[i];
|
|
|
|
|
if (feature != null)
|
|
|
|
|
{
|
|
|
|
|
feature.ReleaseRuntimeResourcesInstance();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_features.Clear();
|
|
|
|
|
m_activePassQueue.Clear();
|
|
|
|
|
m_disposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 00:05:29 +08:00
|
|
|
public void EnqueuePass(
|
|
|
|
|
ScriptableRenderPass renderPass)
|
|
|
|
|
{
|
|
|
|
|
if (renderPass == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int insertIndex = m_activePassQueue.Count;
|
|
|
|
|
while (insertIndex > 0 &&
|
|
|
|
|
m_activePassQueue[insertIndex - 1].renderPassEvent >
|
|
|
|
|
renderPass.renderPassEvent)
|
|
|
|
|
{
|
|
|
|
|
insertIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_activePassQueue.Insert(
|
|
|
|
|
insertIndex,
|
|
|
|
|
renderPass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void AddFeature(
|
|
|
|
|
ScriptableRendererFeature feature)
|
|
|
|
|
{
|
|
|
|
|
if (feature == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_features.Add(feature);
|
|
|
|
|
feature.Create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void AddRenderPasses(
|
|
|
|
|
RenderingData renderingData)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 17:00:48 +08:00
|
|
|
protected internal virtual bool SupportsStageRenderGraph(
|
2026-04-19 00:05:29 +08:00
|
|
|
CameraFrameStage stage)
|
|
|
|
|
{
|
|
|
|
|
RenderingData renderingData = new RenderingData(stage);
|
|
|
|
|
BuildPassQueue(renderingData);
|
|
|
|
|
for (int i = 0; i < m_activePassQueue.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
ScriptableRenderPass renderPass = m_activePassQueue[i];
|
|
|
|
|
if (renderPass != null &&
|
|
|
|
|
renderPass.SupportsStage(stage))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 17:00:48 +08:00
|
|
|
protected internal virtual bool RecordStageRenderGraph(
|
2026-04-19 00:05:29 +08:00
|
|
|
ScriptableRenderContext context)
|
|
|
|
|
{
|
|
|
|
|
if (context == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderingData renderingData =
|
|
|
|
|
new RenderingData(context);
|
|
|
|
|
BuildPassQueue(renderingData);
|
|
|
|
|
|
|
|
|
|
bool recordedAnyPass = false;
|
|
|
|
|
for (int i = 0; i < m_activePassQueue.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
ScriptableRenderPass renderPass = m_activePassQueue[i];
|
|
|
|
|
if (renderPass == null ||
|
|
|
|
|
!renderPass.SupportsStage(renderingData.stage))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!renderPass.Record(
|
2026-04-19 13:05:57 +08:00
|
|
|
context,
|
2026-04-19 00:05:29 +08:00
|
|
|
renderingData))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recordedAnyPass = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return recordedAnyPass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BuildPassQueue(
|
|
|
|
|
RenderingData renderingData)
|
|
|
|
|
{
|
|
|
|
|
m_activePassQueue.Clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_features.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
ScriptableRendererFeature feature = m_features[i];
|
|
|
|
|
if (feature == null || !feature.isActive)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
feature.AddRenderPasses(
|
|
|
|
|
this,
|
|
|
|
|
renderingData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddRenderPasses(renderingData);
|
|
|
|
|
}
|
2026-04-20 01:14:37 +08:00
|
|
|
|
|
|
|
|
protected virtual void ReleaseRuntimeResources()
|
|
|
|
|
{
|
|
|
|
|
}
|
2026-04-19 00:05:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 02:38:48 +08:00
|
|
|
|