protected bool UpdateTempRenderTexture(ref CustomRenderTexture target, bool hasMips = false, bool autoGenerateMips = false, CustomRenderTextureUpdateMode updateMode = CustomRenderTextureUpdateMode.OnDemand, bool depthBuffer = false, GraphicsFormat overrideGraphicsFormat = GraphicsFormat.None) { if (graph.mainOutputTexture == null) { return(false); } bool changed = false; int outputWidth = rtSettings.GetWidth(graph); int outputHeight = rtSettings.GetHeight(graph); int outputDepth = rtSettings.GetDepth(graph); GraphicsFormat targetFormat = overrideGraphicsFormat != GraphicsFormat.None ? overrideGraphicsFormat : rtSettings.GetGraphicsFormat(graph); TextureDimension dimension = GetTempTextureDimension(); outputWidth = Mathf.Max(outputWidth, 1); outputHeight = Mathf.Max(outputHeight, 1); outputDepth = Mathf.Max(outputDepth, 1); if (dimension == TextureDimension.Cube) { outputHeight = outputDepth = outputWidth; // we only use the width for cubemaps } if (targetFormat == GraphicsFormat.None) { targetFormat = graph.mainOutputTexture.graphicsFormat; } if (dimension == TextureDimension.None) { dimension = TextureDimension.Tex2D; } if (target == null) { target = new CustomRenderTexture(outputWidth, outputHeight, targetFormat) { volumeDepth = Math.Max(1, outputDepth), depth = depthBuffer ? 32 : 0, dimension = dimension, name = $"Mixture Temp {name}", updateMode = CustomRenderTextureUpdateMode.OnDemand, doubleBuffered = rtSettings.doubleBuffered, wrapMode = rtSettings.wrapMode, filterMode = rtSettings.filterMode, useMipMap = hasMips, autoGenerateMips = autoGenerateMips, enableRandomWrite = true, hideFlags = HideFlags.HideAndDontSave, updatePeriod = GetUpdatePeriod(), }; target.Create(); target.material = MixtureUtils.dummyCustomRenderTextureMaterial; return(true); } // TODO: check if format is supported by current system // Warning: here we use directly the settings from the if (target.width != Math.Max(1, outputWidth) || target.height != Math.Max(1, outputHeight) || target.graphicsFormat != targetFormat || target.dimension != dimension || target.volumeDepth != outputDepth || target.filterMode != rtSettings.filterMode || target.doubleBuffered != rtSettings.doubleBuffered || target.wrapMode != rtSettings.wrapMode || target.useMipMap != hasMips || target.autoGenerateMips != autoGenerateMips || target.updatePeriod != GetUpdatePeriod()) { target.Release(); target.width = Math.Max(1, outputWidth); target.height = Math.Max(1, outputHeight); target.graphicsFormat = (GraphicsFormat)targetFormat; target.dimension = dimension; target.volumeDepth = outputDepth; target.doubleBuffered = rtSettings.doubleBuffered; target.wrapMode = rtSettings.wrapMode; target.filterMode = rtSettings.filterMode; target.useMipMap = hasMips; target.autoGenerateMips = autoGenerateMips; target.enableRandomWrite = true; target.updatePeriod = GetUpdatePeriod(); target.hideFlags = HideFlags.HideAndDontSave; target.Create(); if (target.material == null) { target.material = MixtureUtils.dummyCustomRenderTextureMaterial; } changed = true; } // Patch update mode based on graph type target.updateMode = updateMode; if (target.doubleBuffered) { target.EnsureDoubleBufferConsistency(); var rt = target.GetDoubleBufferRenderTexture(); if (rt.enableRandomWrite != true) { rt.Release(); rt.enableRandomWrite = true; rt.Create(); } } if (target.IsCreated()) { target.Create(); } return(changed); }
protected bool UpdateTempRenderTexture(ref CustomRenderTexture target, bool hasMips = false, bool autoGenerateMips = false) { if (graph.outputTexture == null) { return(false); } int outputWidth = rtSettings.GetWidth(graph); int outputHeight = rtSettings.GetHeight(graph); int outputDepth = rtSettings.GetDepth(graph); GraphicsFormat targetFormat = rtSettings.GetGraphicsFormat(graph); TextureDimension dimension = rtSettings.GetTextureDimension(graph); if (dimension == TextureDimension.Cube) { outputHeight = outputDepth = outputWidth; // we only use the width for cubemaps } if (targetFormat == GraphicsFormat.None) { targetFormat = graph.outputTexture.graphicsFormat; } if (dimension == TextureDimension.None) { dimension = TextureDimension.Tex2D; } if (target == null) { target = new CustomRenderTexture(outputWidth, outputHeight, targetFormat) { volumeDepth = Math.Max(1, outputDepth), dimension = dimension, name = $"Mixture Temp {name}", updateMode = CustomRenderTextureUpdateMode.OnDemand, doubleBuffered = rtSettings.doubleBuffered, wrapMode = rtSettings.wrapMode, filterMode = rtSettings.filterMode, useMipMap = hasMips, autoGenerateMips = autoGenerateMips, }; target.Create(); return(true); } // TODO: check if format is supported by current system // Warning: here we use directly the settings from the if (target.width != outputWidth || target.height != outputHeight || target.graphicsFormat != targetFormat || target.dimension != dimension || target.volumeDepth != outputDepth || target.filterMode != graph.outputTexture.filterMode || target.doubleBuffered != rtSettings.doubleBuffered || target.wrapMode != rtSettings.wrapMode || target.filterMode != rtSettings.filterMode || target.useMipMap != hasMips || target.autoGenerateMips != autoGenerateMips) { target.Release(); target.width = Math.Max(1, outputWidth); target.height = Math.Max(1, outputHeight); target.graphicsFormat = (GraphicsFormat)targetFormat; target.dimension = (TextureDimension)dimension; target.volumeDepth = outputDepth; target.doubleBuffered = rtSettings.doubleBuffered; target.wrapMode = rtSettings.wrapMode; target.filterMode = rtSettings.filterMode; target.useMipMap = hasMips; target.autoGenerateMips = autoGenerateMips; target.Create(); } return(false); }