Exemplo n.º 1
0
        private void DrawWithCombineMaterial(DrawingContext context, IList <IDrawableObject> drawables)
        {
            RenderTargetPool.Lock(InputTexture as RenderTarget2D);

            int i, p;

            for (p = 0; p < passes.Count; p++)
            {
                passes[p].GetActivePasses(workingPasses);

                RenderTarget2D intermediate = InputTexture as RenderTarget2D;
                for (i = 0; i < workingPasses.Count; ++i)
                {
                    var workingPass = (PostEffect)workingPasses[i];

                    RenderTarget2D previous = intermediate;
                    RenderTargetPool.Lock(previous);
                    intermediate = workingPass.PrepareRenderTarget(context.graphics, intermediate, null);
                    intermediate.Begin();

                    workingPass.InputTexture = previous;
                    workingPass.Draw(context, drawables);

                    intermediate.End();
                    RenderTargetPool.Unlock(previous);
                }

                passResults.Add(intermediate);
                workingPasses.Clear();
            }

            RenderTargetPool.Unlock(InputTexture as RenderTarget2D);

            if (fullScreenQuad == null)
            {
                fullScreenQuad = new FullScreenQuad(context.graphics);
            }

            context.graphics.BlendState = BlendState.Opaque;
            Material.texture            = InputTexture;

            for (i = 0, p = 0; p < passes.Count; p++)
            {
                if (passes[p].Enabled)
                {
                    Material.SetTexture(passes[p].TextureUsage, passResults[i]);
                    i++;
                }
            }

            fullScreenQuad.Draw(context, Material);

            lastEffects.Clear();
            passResults.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws this pass using the specified drawing context.
        /// </summary>
        public override void Draw(DrawingContext context, IList <IDrawableObject> drawables)
        {
            RenderTargetPool.Lock(InputTexture as RenderTarget2D);

            if (fullScreenQuad == null)
            {
                fullScreenQuad = new FullScreenQuad(context.graphics);
            }

            context.graphics.BlendState        = BlendState;
            context.graphics.DepthStencilState = DepthStencilState.None;

            Material.texture = InputTexture;
            fullScreenQuad.Draw(context, Material);

            RenderTargetPool.Unlock(InputTexture as RenderTarget2D);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draws the specified scene.
        /// </summary>
        public void Draw(float elapsedTime, Matrix view, Matrix projection)
        {
            if (isDrawing)
            {
                throw new InvalidOperationException("Cannot trigger another drawing of the scene while it's still been drawn");
            }

            this.matrices.View          = view;
            this.matrices.Projection    = projection;
            this.isDrawing              = true;
            this.VertexOffset           = 0;
            this.VertexBuffer           = null;
            this.PreviousMaterial       = null;
            this.elapsedTime            = elapsedTime;
            this.totalTime             += TimeSpan.FromSeconds(elapsedTime);
            this.totalSeconds           = (float)totalTime.TotalSeconds;
            this.boundingBoxNeedsUpdate = true;

            if (rootPass == null)
            {
                return;
            }

            graphics.SetVertexBuffer(null);
            graphics.Textures[0] = null;

            UpdateDefaultSamplerStates();

            AddDrawablesToView(matrices.ViewFrustum);

            UpdatePassGraph();
            UpdateActivePasses();

            RenderTarget2D lastRenderTarget            = null;
            RenderTarget2D intermediate                = null;
            bool           overrideViewFrustumLastPass = false;

            for (int i = 0; i < activePasses.Count; ++i)
            {
                var pass = activePasses[i];
                var overrideViewFrustum = false;

                // Query the drawables in the current view frustum only when the view frustum changed
                // or the pass overrides the frustum.
                Matrix passView, passProjection;
                if (pass.TryGetViewFrustum(out passView, out passProjection))
                {
                    matrices.View       = passView;
                    matrices.Projection = passProjection;
                    overrideViewFrustum = true;
                }

                if (overrideViewFrustum || overrideViewFrustumLastPass)
                {
                    AddDrawablesToView(matrices.ViewFrustum);
                    overrideViewFrustumLastPass = overrideViewFrustum;
                }

                if ((pass.PassOperation & PassOperation.EndRenderTarget) != 0)
                {
                    intermediate.End();
                    lastRenderTarget = intermediate;
                }

                if ((pass.PassOperation & PassOperation.BeginRenderTarget) != 0)
                {
                    intermediate = pass.PrepareRenderTarget(graphics, intermediate, pass.PassFormat);
                    intermediate.Begin();
                    RenderTargetPool.Lock(intermediate);
                }

                var postEffect = pass as IPostEffect;
                if (postEffect != null)
                {
                    postEffect.InputTexture = lastRenderTarget;
                    pass.Draw(this, drawablesInViewFrustum);
                    RenderTargetPool.Unlock(lastRenderTarget);
                }
                else
                {
                    pass.Draw(this, drawablesInViewFrustum);
                }
            }

            currentFrame++;
            isDrawing = false;
        }
Exemplo n.º 4
0
        private void DrawWithoutCombineMaterial(DrawingContext context, IList <IDrawableObject> drawables)
        {
            RenderTargetPool.Lock(InputTexture as RenderTarget2D);

            int i, p;

            for (p = 0; p < passes.Count; p++)
            {
                passes[p].GetActivePasses(workingPasses);

                RenderTarget2D intermediate = InputTexture as RenderTarget2D;
                for (i = 0; i < workingPasses.Count - 1; ++i)
                {
                    var workingPass = (PostEffect)workingPasses[i];

                    RenderTarget2D previous = intermediate;
                    RenderTargetPool.Lock(previous);
                    intermediate = workingPass.PrepareRenderTarget(context.graphics, intermediate, null);
                    intermediate.Begin();

                    workingPass.InputTexture = previous;
                    workingPass.Draw(context, drawables);

                    intermediate.End();
                    RenderTargetPool.Unlock(previous);
                }

                PostEffect lastEffect;
                RenderTargetPool.Lock(intermediate);

                if (workingPasses.Count > 0)
                {
                    lastEffect = (PostEffect)workingPasses[workingPasses.Count - 1];
                }
                else
                {
                    if (basicPostEffect == null)
                    {
                        basicPostEffect          = new PostEffect();
                        basicPostEffect.Material = new TextureMaterial(context.graphics);
                    }
                    lastEffect = basicPostEffect;
                }

                lastEffects.Add(lastEffect);
                passResults.Add(intermediate);

                workingPasses.Clear();
            }

            RenderTargetPool.Unlock(InputTexture as RenderTarget2D);

            for (i = 0, p = 0; p < passes.Count; p++)
            {
                if (passes[p].Enabled)
                {
                    lastEffects[i].BlendState   = passes[p].BlendState;
                    lastEffects[i].InputTexture = passResults[i];
                    lastEffects[i].Draw(context, drawables);

                    RenderTargetPool.Unlock(passResults[i]);
                    i++;
                }
            }

            lastEffects.Clear();
            passResults.Clear();
        }
Exemplo n.º 5
0
 public override RenderTarget2D PrepareRenderTarget(GraphicsDevice graphics, Texture2D input, SurfaceFormat?preferredFormat)
 {
     currentFrame = base.PrepareRenderTarget(graphics, input, preferredFormat);
     RenderTargetPool.Lock(currentFrame);
     return(currentFrame);
 }