|
|
|
|
|
|
public static int s_MaxWidthMSAAA { get { return s_MaxWidths[(int)RTCategory.MSAA]; } } |
|
|
|
public static int s_MaxHeightMSAA { get { return s_MaxHeights[(int)RTCategory.MSAA]; } } |
|
|
|
|
|
|
|
private static int GetMaxWith(RTCategory category) { return s_MaxWidths[(int)category]; } |
|
|
|
private static int GetMaxWidth(RTCategory category) { return s_MaxWidths[(int)category]; } |
|
|
|
private static int GetMaxHeight(RTCategory category) { return s_MaxHeights[(int)category]; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int[] s_MaxWidths = new int[(int)RTCategory.Count]; |
|
|
|
static int[] s_MaxHeights = new int[(int)RTCategory.Count]; |
|
|
|
|
|
|
|
public static int maxWidth { get { return GetMaxWith(s_ScaledRTCurrentCategory); } } |
|
|
|
public static int maxWidth { get { return GetMaxWidth(s_ScaledRTCurrentCategory); } } |
|
|
|
public static int maxHeight { get { return GetMaxHeight(s_ScaledRTCurrentCategory); } } |
|
|
|
|
|
|
|
static RTHandle() |
|
|
|
|
|
|
height = Mathf.Max(height, 1); |
|
|
|
|
|
|
|
bool msaaSamplesChanged = msaa && (msaaSamples != s_ScaledRTCurrentMSAASamples); |
|
|
|
if (width > GetMaxWith(category) || height > GetMaxHeight(category) || msaaSamplesChanged) |
|
|
|
if (width > GetMaxWidth(category) || height > GetMaxHeight(category) || msaaSamplesChanged) |
|
|
|
Resize(width, height, category, msaaSamples); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
height = Mathf.Max(height, 1); |
|
|
|
|
|
|
|
bool msaaSamplesChanged = msaa && (msaaSamples != s_ScaledRTCurrentMSAASamples); |
|
|
|
if (width != GetMaxWith(category) || height != GetMaxHeight(category) || msaaSamplesChanged) |
|
|
|
if (width != GetMaxWidth(category) || height != GetMaxHeight(category) || msaaSamplesChanged) |
|
|
|
Resize(width, height, category, msaaSamples); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
bool allocForMSAA = s_ScaledRTSupportsMSAA ? enableMSAA : false; |
|
|
|
RTCategory category = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular; |
|
|
|
|
|
|
|
int width = Mathf.Max(Mathf.RoundToInt(scaleFactor.x * GetMaxWith(category)), 1); |
|
|
|
int width = Mathf.Max(Mathf.RoundToInt(scaleFactor.x * GetMaxWidth(category)), 1); |
|
|
|
int height = Mathf.Max(Mathf.RoundToInt(scaleFactor.y * GetMaxHeight(category)), 1); |
|
|
|
|
|
|
|
var rth = AllocAutoSizedRenderTexture(width, |
|
|
|
|
|
|
bool allocForMSAA = s_ScaledRTSupportsMSAA ? enableMSAA : false; |
|
|
|
RTCategory category = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular; |
|
|
|
|
|
|
|
var scaleFactor = scaleFunc(new Vector2Int(GetMaxWith(category), GetMaxHeight(category))); |
|
|
|
var scaleFactor = scaleFunc(new Vector2Int(GetMaxWidth(category), GetMaxHeight(category))); |
|
|
|
int width = Mathf.Max(scaleFactor.x, 1); |
|
|
|
int height = Mathf.Max(scaleFactor.y, 1); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// MSAA Does not support random read/write.
|
|
|
|
if (allocForMSAA && enableRandomWrite == true) |
|
|
|
bool UAV = enableRandomWrite; |
|
|
|
if (allocForMSAA && (UAV == true)) |
|
|
|
Debug.LogWarning("RTHandle allocated with MSAA can't be enableRandomWrite."); |
|
|
|
enableRandomWrite = false; |
|
|
|
Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'."); |
|
|
|
UAV = false; |
|
|
|
bool UAV = enableRandomWrite; |
|
|
|
RTCategory category = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular; |
|
|
|
|
|
|
|
var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear) |
|
|
|
|
|
|
anisoLevel = refRT.anisoLevel, |
|
|
|
mipMapBias = refRT.mipMapBias, |
|
|
|
antiAliasing = 1, // No MSAA for the regular version of the texture.
|
|
|
|
bindTextureMS = refRT.bindTextureMS, |
|
|
|
bindTextureMS = false, // Somehow, this can be true even if antiAliasing == 1. Leads to Unity-internal binding errors.
|
|
|
|
useDynamicScale = refRT.useDynamicScale, |
|
|
|
vrUsage = refRT.vrUsage, |
|
|
|
memorylessMode = refRT.memorylessMode |
|
|
|