protected void CreateCopyMaterial(bool offscreen)
        {
            if (!copyMaterial || dirty)
            {
                if (copyMaterial)
                {
                    UnityObject.Destroy(copyMaterial);
                }

                Shader   shader   = copyShader ? copyShader : LoadDefaultShader();
                Material material = new Material(shader);

                copyMaterial = DisposalHelper.Mark(material);

                dirty = false;
            }

            if (offscreen)
            {
                copyMaterial.EnableKeyword(OffscreenShaderKeyword);
            }
            else
            {
                copyMaterial.DisableKeyword(OffscreenShaderKeyword);
            }
        }
 protected void CreateQuadMesh()
 {
     if (!quad)
     {
         quad = DisposalHelper.Mark(ResourceHelper.CreateFullscreenQuad());
     }
 }
Example #3
0
        private void UpdateScratchBuffer()
        {
            int captureWidth  = encoder.Settings.ResolutionWidth;
            int captureHeight = encoder.Settings.ResolutionHeight;

            if (scratchBuffer != null)
            {
                bool created = scratchBuffer.IsCreated();
                bool resized = (scratchBuffer.width != captureWidth || scratchBuffer.height != captureHeight);

                if (created && !resized)
                {
                    // update is not needed
                    return;
                }

                ReleaseScratchBuffer();
            }

            RenderTexture texture = new RenderTexture(captureWidth, captureHeight, 0, RenderTextureFormat.ARGB32);

            texture.wrapMode = TextureWrapMode.Repeat;
            texture.Create();

            scratchBuffer = DisposalHelper.Mark(texture);
        }
        private void UpdatePreviewTexture()
        {
            RenderTexture buffer = m_Recorder.RecordingUnit.ScratchBuffer;

            if (buffer != null)
            {
                if (previewTexture != null)
                {
                    bool created = previewTexture.IsCreated();
                    bool resized = (previewTexture.width != buffer.width || previewTexture.height != buffer.height);

                    if (created && !resized)
                    {
                        return;
                    }

                    DisposalHelper.Dispose(ref previewTexture);
                }

                RenderTexture texture = new RenderTexture(buffer.width, buffer.height, 0, RenderTextureFormat.ARGB32);
                texture.wrapMode = TextureWrapMode.Repeat;
                texture.Create();

                previewTexture = DisposalHelper.Mark(texture);
            }
        }
Example #5
0
        private void ReleaseAllBuffers()
        {
            if (scratchBuffers != null)
            {
                for (int i = 0; i < scratchBuffers.Length; i++)
                {
                    DisposalHelper.Dispose(ref scratchBuffers[i]);
                }

                scratchBuffers = null;
            }
        }
Example #6
0
        private void ReleaseAllBuffers()
        {
            DisposalHelper.Dispose(ref buffer);

            if (gbuffer != null)
            {
                for (int i = 0; i < gbuffer.Length; i++)
                {
                    DisposalHelper.Dispose(ref gbuffer[i]);
                }

                gbuffer = null;
            }
        }
Example #7
0
        private void UpdateFrameBuffer()
        {
            if (!encoder.CaptureFrameBuffer)
            {
                return;
            }

            int captureWidth  = camera.pixelWidth;
            int captureHeight = camera.pixelHeight;

            if (RequireRegeneration(ref buffer, captureWidth, captureHeight))
            {
                buffer = DisposalHelper.Mark(CreateFrameBuffer(captureWidth, captureHeight));
            }
        }
Example #8
0
        private static bool RequireRegeneration(ref RenderTexture texture, int width, int height)
        {
            if (texture != null)
            {
                bool created = texture.IsCreated();
                bool resized = (texture.width != width || texture.height != height);

                if (created && !resized)
                {
                    return(false);
                }

                DisposalHelper.Dispose(ref texture);
            }

            return(true);
        }
Example #9
0
        private static bool RequireRegeneration(ref RenderTexture texture, RenderTexture target)
        {
            if (texture != null)
            {
                bool created       = texture.IsCreated();
                bool resized       = (texture.width != target.width || texture.height != target.height);
                bool formatChanged = (texture.format != target.format);

                if (created && !resized && !formatChanged)
                {
                    return(false);
                }

                DisposalHelper.Dispose(ref texture);
            }

            return(true);
        }
Example #10
0
        private void UpdateGBuffer()
        {
            if (!encoder.CaptureGBuffer)
            {
                return;
            }

            int captureWidth  = camera.pixelWidth;
            int captureHeight = camera.pixelHeight;

            if (gbuffer == null)
            {
                gbuffer = new RenderTexture[GBufferSize];
            }

            for (int i = 0; i < gbuffer.Length; i++)
            {
                if (RequireRegeneration(ref gbuffer[i], captureWidth, captureHeight))
                {
                    gbuffer[i] = DisposalHelper.Mark(CreateGBuffer(i, captureWidth, captureHeight));
                }
            }
        }
Example #11
0
        private void UpdateScratchBuffers()
        {
            if (!encoder.CaptureOffscreenBuffer)
            {
                return;
            }

            if (scratchBuffers == null)
            {
                scratchBuffers = new RenderTexture[targets.Length];
            }

            for (int i = 0; i < scratchBuffers.Length; i++)
            {
                RenderTexture target = targets[i];
                if (target)
                {
                    if (RequireRegeneration(ref scratchBuffers[i], target))
                    {
                        scratchBuffers[i] = DisposalHelper.Mark(CreateScratchBuffer(target));
                    }
                }
            }
        }
 public virtual void ReleaseResources()
 {
     DisposalHelper.Dispose(ref quad);
     DisposalHelper.Dispose(ref copyMaterial);
 }
Example #13
0
 private void ReleaseScratchBuffer()
 {
     DisposalHelper.Dispose(ref scratchBuffer);
 }
 protected void OnDisable()
 {
     DisposalHelper.Dispose(ref previewTexture);
 }