Add URP RenderGraph API compatibility surface

This commit is contained in:
2026-04-25 15:51:05 +08:00
parent c0c0bbdfa3
commit 5f73b35c0f
8 changed files with 246 additions and 20 deletions

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
namespace XCEngine.Rendering
{
public sealed class ContextContainer : IDisposable
{
private readonly Dictionary<Type, ContextItem> m_items =
new Dictionary<Type, ContextItem>();
private bool m_disposed;
public bool Contains<T>()
where T : ContextItem
{
return m_items.ContainsKey(typeof(T));
}
public T Create<T>()
where T : ContextItem, new()
{
ThrowIfDisposed();
T item = new T();
m_items[typeof(T)] = item;
return item;
}
public T Get<T>()
where T : ContextItem
{
ThrowIfDisposed();
ContextItem item;
if (!m_items.TryGetValue(
typeof(T),
out item))
{
throw new InvalidOperationException(
"Context item is not available: " +
typeof(T).FullName);
}
return (T)item;
}
public T GetOrCreate<T>()
where T : ContextItem, new()
{
ThrowIfDisposed();
ContextItem item;
if (m_items.TryGetValue(
typeof(T),
out item))
{
return (T)item;
}
return Create<T>();
}
public void Dispose()
{
if (m_disposed)
{
return;
}
foreach (ContextItem item in m_items.Values)
{
if (item != null)
{
item.Reset();
}
}
m_items.Clear();
m_disposed = true;
}
private void ThrowIfDisposed()
{
if (m_disposed)
{
throw new ObjectDisposedException(
nameof(ContextContainer));
}
}
}
}

View File

@@ -0,0 +1,9 @@
namespace XCEngine.Rendering
{
public abstract class ContextItem
{
public virtual void Reset()
{
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
namespace XCEngine.Rendering.RenderGraphModule
{
public sealed class RenderGraph
{
private readonly XCEngine.Rendering.ScriptableRenderContext
m_context;
public RenderGraph()
: this(null)
{
}
public RenderGraph(
XCEngine.Rendering.ScriptableRenderContext context)
{
m_context = context;
}
public XCEngine.Rendering.RenderGraphRasterPassBuilder
AddRasterPass(
string passName)
{
if (m_context == null)
{
throw new InvalidOperationException(
"RenderGraph is not bound to a recording context.");
}
return m_context.AddRasterPass(passName);
}
}
}