Пример #1
0
        /// <summary>
        /// Function to render the initial scene to the initial render target.
        /// </summary>
        /// <param name="lastTargetTexture">The last texture used as a target.</param>
        private void CopyToFinal(GorgonTexture2DView lastTargetTexture)
        {
            if (Graphics.RenderTargets[0] != _final)
            {
                Graphics.SetRenderTarget(_final);
            }

            if (_finalClear != null)
            {
                _final.Clear(_finalClear.Value);
            }

            // Copy the composited output into the final render target specified by the user.
            Renderer.Begin(_finalBatchState, _camera);
            Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, lastTargetTexture.Width, lastTargetTexture.Height),
                                         GorgonColor.White,
                                         lastTargetTexture,
                                         new DX.RectangleF(0, 0, 1, 1));
            Renderer.End();
        }
Пример #2
0
        /// <summary>
        /// Function to render the scene for the compositor effects.
        /// </summary>
        /// <param name="output">The final output render target for the compositor.</param>
        /// <param name="renderMethod">The method used to render the initial scene.</param>
        /// <returns>The fluent interface for the effects processor.</returns>
        public Gorgon2DCompositor Render(GorgonRenderTargetView output,
                                         Action renderMethod)
        {
            output.ValidateObject(nameof(output));
            renderMethod.ValidateObject(nameof(renderMethod));

            // Create or update our resources
            if ((_final != output) || (NeedsResourceUpdate(output)))
            {
                FreeResources();
                CreateResources(output);
            }

            // Create the batch state that we'll use for our initial scene.
            if (_hasBatchStateChanged)
            {
                _batchState           = _batchStateBuilder.Build();
                _hasBatchStateChanged = false;
            }

            if (_hasFinalBatchStateChanged)
            {
                _finalBatchState           = _finalBatchStateBuilder.Build();
                _hasFinalBatchStateChanged = false;
            }

            RenderInitalScene(renderMethod);

            // If we have no effects, then, just output the scene to the render target as-is.
            if (_effects.Count == 0)
            {
                CopyToFinal(_originalTexture);
                return(this);
            }

            (GorgonRenderTargetView target, GorgonTexture2DView texture)current = (_pingTarget, _originalTexture);

            // Iterate through our items.
            for (int i = 0; i < _effectList.Count; ++i)
            {
                Gorgon2DCompositionPass pass = _effectList[i];

                if (!pass.Enabled)
                {
                    continue;
                }

                GorgonRenderTargetView   currentTarget  = current.target;
                GorgonTexture2DView      currentTexture = current.texture;
                GorgonTexture2DView      nextTexture    = ((currentTexture == _originalTexture) || (currentTexture == _pongTexture)) ? _pingTexture : _pongTexture;
                GorgonRenderTarget2DView nextTarget     = current.target == _pingTarget ? _pongTarget : _pingTarget;

                if (pass.ClearColor != null)
                {
                    currentTarget.Clear(pass.ClearColor.Value);
                }

                if (pass.Effect != null)
                {
                    RenderEffectPass(pass, currentTarget, currentTexture);
                }
                else
                {
                    RenderNoEffectPass(pass, currentTarget, currentTexture);
                }

                current = (nextTarget, nextTexture);
            }

            CopyToFinal(current.texture);

            return(this);
        }