using UnityEngine.Rendering.RenderGraphModule;
namespace UnityEngine.Rendering.Universal
{
///
/// Base class for URP texture data.
///
public abstract class UniversalResourceDataBase : ContextItem
{
///
/// Options for the active color & depth target texture.
///
internal enum ActiveID
{
/// The camera buffer.
Camera,
/// The backbuffer.
BackBuffer
}
internal bool isAccessible { get; set; }
internal void InitFrame()
{
isAccessible = true;
}
internal void EndFrame()
{
isAccessible = false;
}
///
/// Updates the texture handle if the texture is accessible.
///
/// Handle to update.
/// Handle of the new data.
protected void CheckAndSetTextureHandle(ref TextureHandle handle, TextureHandle newHandle)
{
if (!CheckAndWarnAboutAccessibility())
return;
handle = newHandle;
}
///
/// Fetches the texture handle if the texture is accessible.
///
/// Handle to the texture you want to retrieve
/// Returns the handle if the texture is accessible and a null handle otherwise.
protected TextureHandle CheckAndGetTextureHandle(ref TextureHandle handle)
{
if (!CheckAndWarnAboutAccessibility())
return TextureHandle.nullHandle;
return handle;
}
///
/// Updates the texture handles if the texture is accessible. The current and new handles needs to be of the same size.
///
/// Handles to update.
/// Handles of the new data.
protected void CheckAndSetTextureHandle(ref TextureHandle[] handle, TextureHandle[] newHandle)
{
if (!CheckAndWarnAboutAccessibility())
return;
if (handle == null || handle.Length != newHandle.Length)
handle = new TextureHandle[newHandle.Length];
for (int i = 0; i < newHandle.Length; i++)
handle[i] = newHandle[i];
}
///
/// Fetches the texture handles if the texture is accessible.
///
/// Handles to the texture you want to retrieve
/// Returns the handles if the texture is accessible and a null handle otherwise.
protected TextureHandle[] CheckAndGetTextureHandle(ref TextureHandle[] handle)
{
if (!CheckAndWarnAboutAccessibility())
return new []{TextureHandle.nullHandle};
return handle;
}
///
/// Check if the texture is accessible.
///
/// Returns true if the texture is accessible and false otherwise.
protected bool CheckAndWarnAboutAccessibility()
{
if (!isAccessible)
Debug.LogError("Trying to access Universal Resources outside of the current frame setup.");
return isAccessible;
}
}
}