using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering
{
///
/// Default instance of a RTHandleSystem
///
public static class RTHandles
{
static RTHandleSystem s_DefaultInstance = new RTHandleSystem();
///
/// Maximum allocated width of the default RTHandle System
///
public static int maxWidth { get { return s_DefaultInstance.GetMaxWidth(); } }
///
/// Maximum allocated height of the default RTHandle System
///
public static int maxHeight { get { return s_DefaultInstance.GetMaxHeight(); } }
///
/// Current properties of the default RTHandle System
///
public static RTHandleProperties rtHandleProperties { get { return s_DefaultInstance.rtHandleProperties; } }
///
/// Allocate a new fixed sized RTHandle with the default RTHandle System.
///
/// With of the RTHandle.
/// Heigh of the RTHandle.
/// Number of slices of the RTHandle.
/// Bit depths of a depth buffer.
/// GraphicsFormat of a color buffer.
/// Filtering mode of the RTHandle.
/// Addressing mode of the RTHandle.
/// Texture dimension of the RTHandle.
/// Set to true to enable UAV random read writes on the texture.
/// Set to true if the texture should have mipmaps.
/// Set to true to automatically generate mipmaps.
/// Set to true if the depth buffer should be used as a shadow map.
/// Anisotropic filtering level.
/// Bias applied to mipmaps during filtering.
/// Number of MSAA samples for the RTHandle.
/// Set to true if the texture needs to be bound as a multisampled texture in the shader.
/// Set to true to use hardware dynamic scaling.
/// Use this property to set the render texture memoryless modes.
/// Name of the RTHandle.
///
public static RTHandle Alloc(
int width,
int height,
int slices = 1,
DepthBits depthBufferBits = DepthBits.None,
GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
FilterMode filterMode = FilterMode.Point,
TextureWrapMode wrapMode = TextureWrapMode.Repeat,
TextureDimension dimension = TextureDimension.Tex2D,
bool enableRandomWrite = false,
bool useMipMap = false,
bool autoGenerateMips = true,
bool isShadowMap = false,
int anisoLevel = 1,
float mipMapBias = 0,
MSAASamples msaaSamples = MSAASamples.None,
bool bindTextureMS = false,
bool useDynamicScale = false,
RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
string name = ""
)
{
return s_DefaultInstance.Alloc(
width,
height,
slices,
depthBufferBits,
colorFormat,
filterMode,
wrapMode,
dimension,
enableRandomWrite,
useMipMap,
autoGenerateMips,
isShadowMap,
anisoLevel,
mipMapBias,
msaaSamples,
bindTextureMS,
useDynamicScale,
memoryless,
name
);
}
///
/// Allocate a new automatically sized RTHandle for the default RTHandle System.
///
/// Constant scale for the RTHandle size computation.
/// Number of slices of the RTHandle.
/// Bit depths of a depth buffer.
/// GraphicsFormat of a color buffer.
/// Filtering mode of the RTHandle.
/// Addressing mode of the RTHandle.
/// Texture dimension of the RTHandle.
/// Set to true to enable UAV random read writes on the texture.
/// Set to true if the texture should have mipmaps.
/// Set to true to automatically generate mipmaps.
/// Set to true if the depth buffer should be used as a shadow map.
/// Anisotropic filtering level.
/// Bias applied to mipmaps during filtering.
/// Enable MSAA for this RTHandle.
/// Set to true if the texture needs to be bound as a multisampled texture in the shader.
/// Set to true to use hardware dynamic scaling.
/// Use this property to set the render texture memoryless modes.
/// Name of the RTHandle.
///
public static RTHandle Alloc(
Vector2 scaleFactor,
int slices = 1,
DepthBits depthBufferBits = DepthBits.None,
GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
FilterMode filterMode = FilterMode.Point,
TextureWrapMode wrapMode = TextureWrapMode.Repeat,
TextureDimension dimension = TextureDimension.Tex2D,
bool enableRandomWrite = false,
bool useMipMap = false,
bool autoGenerateMips = true,
bool isShadowMap = false,
int anisoLevel = 1,
float mipMapBias = 0,
bool enableMSAA = false,
bool bindTextureMS = false,
bool useDynamicScale = false,
RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
string name = ""
)
{
return s_DefaultInstance.Alloc(
scaleFactor,
slices,
depthBufferBits,
colorFormat,
filterMode,
wrapMode,
dimension,
enableRandomWrite,
useMipMap,
autoGenerateMips,
isShadowMap,
anisoLevel,
mipMapBias,
enableMSAA,
bindTextureMS,
useDynamicScale,
memoryless,
name
);
}
///
/// Allocate a new automatically sized RTHandle for the default RTHandle System.
///
/// Function used for the RTHandle size computation.
/// Number of slices of the RTHandle.
/// Bit depths of a depth buffer.
/// GraphicsFormat of a color buffer.
/// Filtering mode of the RTHandle.
/// Addressing mode of the RTHandle.
/// Texture dimension of the RTHandle.
/// Set to true to enable UAV random read writes on the texture.
/// Set to true if the texture should have mipmaps.
/// Set to true to automatically generate mipmaps.
/// Set to true if the depth buffer should be used as a shadow map.
/// Anisotropic filtering level.
/// Bias applied to mipmaps during filtering.
/// Enable MSAA for this RTHandle.
/// Set to true if the texture needs to be bound as a multisampled texture in the shader.
/// Set to true to use hardware dynamic scaling.
/// Use this property to set the render texture memoryless modes.
/// Name of the RTHandle.
///
public static RTHandle Alloc(
ScaleFunc scaleFunc,
int slices = 1,
DepthBits depthBufferBits = DepthBits.None,
GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
FilterMode filterMode = FilterMode.Point,
TextureWrapMode wrapMode = TextureWrapMode.Repeat,
TextureDimension dimension = TextureDimension.Tex2D,
bool enableRandomWrite = false,
bool useMipMap = false,
bool autoGenerateMips = true,
bool isShadowMap = false,
int anisoLevel = 1,
float mipMapBias = 0,
bool enableMSAA = false,
bool bindTextureMS = false,
bool useDynamicScale = false,
RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
string name = ""
)
{
return s_DefaultInstance.Alloc(
scaleFunc,
slices,
depthBufferBits,
colorFormat,
filterMode,
wrapMode,
dimension,
enableRandomWrite,
useMipMap,
autoGenerateMips,
isShadowMap,
anisoLevel,
mipMapBias,
enableMSAA,
bindTextureMS,
useDynamicScale,
memoryless,
name
);
}
///
/// Allocate a RTHandle from a regular Texture for the default RTHandle system.
///
/// Input texture
/// A new RTHandle referencing the input texture.
public static RTHandle Alloc(Texture tex)
{
return s_DefaultInstance.Alloc(tex);
}
///
/// Allocate a RTHandle from a regular RenderTexture for the default RTHandle system.
///
/// Input texture
/// A new RTHandle referencing the input texture.
public static RTHandle Alloc(RenderTexture tex)
{
return s_DefaultInstance.Alloc(tex);
}
///
/// Allocate a RTHandle from a regular render target identifier for the default RTHandle system.
///
/// Input render target identifier.
/// A new RTHandle referencing the input render target identifier.
public static RTHandle Alloc(RenderTargetIdentifier tex)
{
return s_DefaultInstance.Alloc(tex);
}
///
/// Allocate a RTHandle from a regular render target identifier for the default RTHandle system.
///
/// Input render target identifier.
/// Name of the render target.
/// A new RTHandle referencing the input render target identifier.
public static RTHandle Alloc(RenderTargetIdentifier tex, string name)
{
return s_DefaultInstance.Alloc(tex, name);
}
private static RTHandle Alloc(RTHandle tex)
{
Debug.LogError("Allocation a RTHandle from another one is forbidden.");
return null;
}
///
/// Initialize the default RTHandle system.
///
/// Initial reference rendering width.
/// Initial reference rendering height.
/// Set to true if automatically scaled RTHandles should support MSAA
/// Number of MSAA samples for automatically scaled RTHandles.
public static void Initialize(
int width,
int height,
bool scaledRTsupportsMSAA,
MSAASamples scaledRTMSAASamples
)
{
s_DefaultInstance.Initialize(
width,
height,
scaledRTsupportsMSAA,
scaledRTMSAASamples
);
}
///
/// Release memory of a RTHandle from the default RTHandle System
///
/// RTHandle that should be released.
public static void Release(RTHandle rth)
{
s_DefaultInstance.Release(rth);
}
///
/// Enable or disable hardware dynamic resolution for the default RTHandle System
///
/// State of hardware dynamic resolution.
public static void SetHardwareDynamicResolutionState(bool hwDynamicResRequested)
{
s_DefaultInstance.SetHardwareDynamicResolutionState(hwDynamicResRequested);
}
///
/// Sets the reference rendering size for subsequent rendering for the default RTHandle System
///
/// Reference rendering width for subsequent rendering.
/// Reference rendering height for subsequent rendering.
/// Number of MSAA samples for multisampled textures for subsequent rendering.
public static void SetReferenceSize(
int width,
int height,
MSAASamples msaaSamples
)
{
s_DefaultInstance.SetReferenceSize(
width,
height,
msaaSamples
);
}
///
/// Reset the reference size of the system and reallocate all textures.
///
/// New width.
/// New height.
public static void ResetReferenceSize(int width, int height)
{
s_DefaultInstance.ResetReferenceSize(width, height);
}
}
}