예제 #1
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, VRTextureUsage.None, false));
 }
예제 #2
0
 public static bool GetTemporaryImpl(ref RenderTexture __result, int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     if (allThreads2.TryGetValue(CurrentThread, out ThreadInfo threadInfo))
     {
         threadInfo.safeFunctionRequest = new object[] { safeFunction, new object[] { width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale } };
         mainThreadWaitHandle.Set();
         threadInfo.eventWaitStart.WaitOne();
         __result = (RenderTexture)threadInfo.safeFunctionResult;
         return(false);
     }
     return(true);
 }
예제 #3
0
 private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, format, depthBuffer)
     {
         sRGB = (readWrite != RenderTextureReadWrite.Linear),
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         vrUsage = vrUsage,
         useDynamicScale = useDynamicScale
     }));
 }
예제 #4
0
 public static RenderTexture GetTemporary(int width, int height, [UnityEngine.Internal.DefaultValue("0")] int depthBuffer, [UnityEngine.Internal.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [UnityEngine.Internal.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [UnityEngine.Internal.DefaultValue("1")] int antiAliasing, [UnityEngine.Internal.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode, [UnityEngine.Internal.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [UnityEngine.Internal.DefaultValue("false")] bool useDynamicScale)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, useDynamicScale));
 }
예제 #5
0
 public void GetTemporaryRT(int nameID, int width, int height, int depthBuffer, FilterMode filter, GraphicsFormat format, int antiAliasing, bool enableRandomWrite, RenderTextureMemoryless memorylessMode)
 {
     GetTemporaryRT(nameID, width, height, depthBuffer, filter, format, antiAliasing, enableRandomWrite, memorylessMode, false);
 }
예제 #6
0
        public void GetTemporaryRT(int nameID, int width, int height, int depthBuffer, FilterMode filter, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, bool enableRandomWrite)
        {
            RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None;

            this.GetTemporaryRT(nameID, width, height, depthBuffer, filter, format, readWrite, antiAliasing, enableRandomWrite, memorylessMode);
        }
예제 #7
0
 private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, format, depthBuffer)
     {
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         vrUsage = vrUsage,
         useDynamicScale = useDynamicScale
     }));
 }
예제 #8
0
        // Internal function
        RTHandle AllocAutoSizedRenderTexture(
            int width,
            int height,
            int slices,
            DepthBits depthBufferBits,
            GraphicsFormat colorFormat,
            FilterMode filterMode,
            TextureWrapMode wrapMode,
            TextureDimension dimension,
            bool enableRandomWrite,
            bool useMipMap,
            bool autoGenerateMips,
            bool isShadowMap,
            int anisoLevel,
            float mipMapBias,
            bool enableMSAA,
            bool bindTextureMS,
            bool useDynamicScale,
            RenderTextureMemoryless memoryless,
            string name
            )
        {
            // Here user made a mistake in setting up msaa/bindMS, hence the warning
            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;

            // Here we purposefully disable MSAA so we just force the bindMS param to false.
            if (!allocForMSAA)
            {
                bindTextureMS = false;
            }

            // MSAA Does not support random read/write.
            bool UAV = enableRandomWrite;

            if (allocForMSAA && (UAV == true))
            {
                Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'.");
                UAV = false;
            }

            int        msaaSamples = allocForMSAA ? (int)m_ScaledRTCurrentMSAASamples : 1;
            RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }

            rt.Create();

            var rth = new RTHandle(this);

            rth.SetRenderTexture(rt, category);
            rth.m_EnableMSAA           = enableMSAA;
            rth.m_EnableRandomWrite    = enableRandomWrite;
            rth.useScaling             = true;
            rth.m_EnableHWDynamicScale = useDynamicScale;
            rth.m_Name = name;
            m_AutoSizedRTs.Add(rth);
            return(rth);
        }
예제 #9
0
 public static RenderTexture GetTemporary(int width, int height, [DefaultValue("0")] int depthBuffer, [DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [DefaultValue("1")] int antiAliasing, [DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode, [DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [DefaultValue("false")] bool useDynamicScale)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height)
     {
         depthBufferBits = depthBuffer,
         vrUsage = vrUsage,
         colorFormat = format,
         sRGB = (readWrite != RenderTextureReadWrite.Linear),
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         useDynamicScale = useDynamicScale
     }));
 }
예제 #10
0
        public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
        {
            bool useDynamicScale = false;

            return(RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, useDynamicScale));
        }
예제 #11
0
        public static bool GetTemporaryImpl(ref RenderTexture __result, int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
        {
            int tID = Thread.CurrentThread.ManagedThreadId;

            if (RimThreaded.mainRequestWaits.TryGetValue(tID, out EventWaitHandle eventWaitStart))
            {
                object[] functionAndParameters = new object[] { safeFunction, new object[] { width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale } };
                lock (RimThreaded.safeFunctionRequests)
                {
                    RimThreaded.safeFunctionRequests[tID] = functionAndParameters;
                }
                RimThreaded.mainThreadWaitHandle.Set();
                eventWaitStart.WaitOne();
                RimThreaded.safeFunctionResults.TryGetValue(tID, out object safeFunctionResult);
                __result = (RenderTexture)safeFunctionResult;
                return(false);
            }
            return(true);
        }
예제 #12
0
    static int GetTemporary(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            RenderTextureDescriptor arg0 = (RenderTextureDescriptor)LuaScriptMgr.GetNetObject(L, 1, typeof(RenderTextureDescriptor));
            RenderTexture           o    = RenderTexture.GetTemporary(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2)
        {
            int           arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int           arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            RenderTexture o    = RenderTexture.GetTemporary(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 3)
        {
            int           arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int           arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int           arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTexture o    = RenderTexture.GetTemporary(arg0, arg1, arg2);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 4)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTexture       o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 5)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            RenderTexture          o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 6)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int           arg5          = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTexture o             = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 7)
        {
            int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
            int arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            int arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
            RenderTextureFormat    arg3 = (RenderTextureFormat)LuaScriptMgr.GetNetObject(L, 4, typeof(RenderTextureFormat));
            RenderTextureReadWrite arg4 = (RenderTextureReadWrite)LuaScriptMgr.GetNetObject(L, 5, typeof(RenderTextureReadWrite));
            int arg5 = (int)LuaScriptMgr.GetNumber(L, 6);
            RenderTextureMemoryless arg6 = (RenderTextureMemoryless)LuaScriptMgr.GetNetObject(L, 7, typeof(RenderTextureMemoryless));
            RenderTexture           o    = RenderTexture.GetTemporary(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: RenderTexture.GetTemporary");
        }

        return(0);
    }
예제 #13
0
 public void GetTemporaryRT(int nameID, int width, int height, int depthBuffer, FilterMode filter, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, bool enableRandomWrite, RenderTextureMemoryless memorylessMode, bool useDynamicScale)
 {
     GetTemporaryRT(nameID, width, height, depthBuffer, filter, GraphicsFormatUtility.GetGraphicsFormat(format, readWrite), antiAliasing, enableRandomWrite, memorylessMode, useDynamicScale);
 }
예제 #14
0
        // This method wraps around regular RenderTexture creation.
        // There is no specific logic applied to RenderTextures created this way.
        public RTHandle Alloc(
            int width,
            int height,
            int slices = 1,
            DepthBits depthBufferBits       = DepthBits.None,
            RenderTextureFormat colorFormat = RenderTextureFormat.Default,
            FilterMode filterMode           = FilterMode.Point,
            TextureWrapMode wrapMode        = TextureWrapMode.Repeat,
            TextureDimension dimension      = TextureDimension.Tex2D,
            bool sRGB = true,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            VRTextureUsage vrUsage             = VRTextureUsage.None,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            bool enableMSAA = msaaSamples != MSAASamples.None;

            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = enableRandomWrite,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = (int)msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = useDynamicScale,
                vrUsage           = vrUsage,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, colorFormat, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
            };

            rt.Create();

            RTCategory category = enableMSAA ? RTCategory.MSAA : RTCategory.Regular;
            var        newRT    = new RTHandle(this);

            newRT.SetRenderTexture(rt, category);
            newRT.useScaling          = false;
            newRT.m_EnableRandomWrite = enableRandomWrite;
            newRT.m_EnableMSAA        = enableMSAA;
            newRT.m_Name = name;

            newRT.referenceSize = new Vector2Int(width, height);

            return(newRT);
        }
예제 #15
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, false));
 }
예제 #16
0
        // Internal function
        RTHandle AllocAutoSizedRenderTexture(
            int width,
            int height,
            int slices,
            DepthBits depthBufferBits,
            RenderTextureFormat colorFormat,
            FilterMode filterMode,
            TextureWrapMode wrapMode,
            TextureDimension dimension,
            bool sRGB,
            bool enableRandomWrite,
            bool useMipMap,
            bool autoGenerateMips,
            int anisoLevel,
            float mipMapBias,
            bool enableMSAA,
            bool bindTextureMS,
            bool useDynamicScale,
            VRTextureUsage vrUsage,
            RenderTextureMemoryless memoryless,
            string name
            )
        {
            // Here user made a mistake in setting up msaa/bindMS, hence the warning
            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;

            // Here we purposefully disable MSAA so we just force the bindMS param to false.
            if (!allocForMSAA)
            {
                bindTextureMS = false;
            }

            // MSAA Does not support random read/write.
            bool UAV = enableRandomWrite;

            if (allocForMSAA && (UAV == true))
            {
                Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'.");
                UAV = false;
            }

            int        msaaSamples = allocForMSAA ? (int)m_ScaledRTCurrentMSAASamples : 1;
            RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            var rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat, sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = UAV,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = useDynamicScale,
                vrUsage           = vrUsage,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
            };

            rt.Create();

            var rth = new RTHandle(this);

            rth.SetRenderTexture(rt, category);
            rth.m_EnableMSAA        = enableMSAA;
            rth.m_EnableRandomWrite = enableRandomWrite;
            rth.useScaling          = true;
            rth.m_Name = name;
            m_AutoSizedRTs.Add(rth);
            return(rth);
        }
예제 #17
0
 public extern void GetTemporaryRT(int nameID, int width, int height, [DefaultValue("0")] int depthBuffer, [DefaultValue("FilterMode.Point")] FilterMode filter, [DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [DefaultValue("1")] int antiAliasing, [DefaultValue("false")] bool enableRandomWrite, [DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode);
예제 #18
0
        /// <summary>
        /// Allocate a new fixed sized RTHandle.
        /// </summary>
        /// <param name="width">With of the RTHandle.</param>
        /// <param name="height">Heigh of the RTHandle.</param>
        /// <param name="slices">Number of slices of the RTHandle.</param>
        /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
        /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
        /// <param name="filterMode">Filtering mode of the RTHandle.</param>
        /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
        /// <param name="dimension">Texture dimension of the RTHandle.</param>
        /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
        /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
        /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
        /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
        /// <param name="anisoLevel">Anisotropic filtering level.</param>
        /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
        /// <param name="msaaSamples">Number of MSAA samples for the RTHandle.</param>
        /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
        /// <param name="useDynamicScale">Set to true to use hardware dynamic scaling.</param>
        /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
        /// <param name="name">Name of the RTHandle.</param>
        /// <returns></returns>
        public 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                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            bool enableMSAA = msaaSamples != MSAASamples.None;

            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, format, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }

            rt.Create();

            var newRT = new RTHandle(this);

            newRT.SetRenderTexture(rt);
            newRT.useScaling             = false;
            newRT.m_EnableRandomWrite    = enableRandomWrite;
            newRT.m_EnableMSAA           = enableMSAA;
            newRT.m_EnableHWDynamicScale = useDynamicScale;
            newRT.m_Name = name;

            newRT.referenceSize = new Vector2Int(width, height);

            return(newRT);
        }
예제 #19
0
 extern public void GetTemporaryRT(int nameID, int width, int height, int depthBuffer, FilterMode filter, GraphicsFormat format, int antiAliasing, bool enableRandomWrite, RenderTextureMemoryless memorylessMode, bool useDynamicScale);