Exemple #1
0
 /// <summary>
 /// Called to process the specified <see cref="RenderStep"/>.
 /// </summary>
 /// <param name="step"></param>
 /// <param name="drawDevice"></param>
 protected virtual void OnRenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     drawDevice.PrepareForDrawcalls();
     if (step.Input == null)
     {
         this.CollectDrawcalls(step, scene, drawDevice);
     }
     else
     {
         drawDevice.AddFullscreenQuad(step.Input, step.InputResize);
     }
     drawDevice.Render();
 }
Exemple #2
0
 /// <summary>
 /// Collects drawcalls that are submitted by external sources which are
 /// subscribed to <see cref="EventCollectDrawcalls"/>.
 /// </summary>
 protected void CollectExternalDrawcalls(RenderStep step, DrawDevice drawDevice)
 {
     try
     {
         if (this.eventCollectDrawcalls != null)
         {
             this.eventCollectDrawcalls(this, new CollectDrawcallEventArgs(step.Id, drawDevice));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("There was an error while {0} was collecting external drawcalls: {1}", this, /*LogFormat.Exception(*/ e /*)*/);
     }
 }
Exemple #3
0
 /// <summary>
 /// Collects drawcalls that are submitted by external sources which are
 /// subscribed to <see cref="EventCollectDrawcalls"/>.
 /// </summary>
 protected void CollectExternalDrawcalls(RenderStep step, DrawDevice drawDevice)
 {
     Profile.TimeCollectDrawcalls.BeginMeasure();
     try
     {
         if (this.eventCollectDrawcalls != null)
         {
             this.eventCollectDrawcalls(this, new CollectDrawcallEventArgs(step.Id, drawDevice));
         }
     }
     catch (Exception e)
     {
         Logs.Core.WriteError("There was an error while {0} was collecting external drawcalls: {1}", this, LogFormat.Exception(e));
     }
     Profile.TimeCollectDrawcalls.EndMeasure();
 }
Exemple #4
0
        /// <summary>
        /// Adds an additional rendering step to <see cref="Steps"/>.
        /// </summary>
        /// <param name="anchorId">Id of the existing rendering step to which the new step will be anchored.</param>
        /// <param name="anchorPos">Position of the new rendering step relative to the one it is anchored to.</param>
        /// <param name="step">The new rendering step that should be inserted into the rendering step sequence.</param>
        public void AddRenderStep(string anchorId, RenderStepPosition anchorPos, RenderStep step)
        {
            int anchorIndex = -1;

            switch (anchorPos)
            {
            case RenderStepPosition.Before:
                anchorIndex = this.steps.FindIndex(existingStep => existingStep.Id == anchorId);
                if (anchorIndex == -1)
                {
                    anchorIndex = 0;
                }
                break;

            case RenderStepPosition.After:
                anchorIndex = this.steps.FindIndex(existingStep => existingStep.Id == anchorId);
                if (anchorIndex == -1)
                {
                    anchorIndex = this.steps.Count;
                }
                else
                {
                    anchorIndex++;
                }
                break;

            case RenderStepPosition.First:
                anchorIndex = 0;
                break;

            case RenderStepPosition.Last:
                anchorIndex = this.steps.Count;
                break;
            }
            if (anchorIndex != -1)
            {
                this.steps.Insert(anchorIndex, step);
            }
        }
Exemple #5
0
 /// <summary>
 /// Collects all drawcalls from both external sources and renderers in the scene.
 /// </summary>
 /// <param name="step"></param>
 /// <param name="scene"></param>
 /// <param name="drawDevice"></param>
 protected void CollectDrawcalls(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     this.CollectRendererDrawcalls(scene, drawDevice);
     this.CollectExternalDrawcalls(step, drawDevice);
 }
Exemple #6
0
        /// <summary>
        /// Performs the specified <see cref="RenderStep"/>. This method will do some basic, localized configuration on
        /// the drawing device and then invoke <see cref="OnRenderSingleStep"/> for running the actual rendering operations.
        /// </summary>
        /// <param name="step"></param>
        /// <param name="scene"></param>
        /// <param name="drawDevice"></param>
        /// <param name="viewportRect"></param>
        /// <param name="imageSize"></param>
        /// <param name="outputTargetRect"></param>
        protected void RenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize)
        {
            // Memorize old draw device settings to reset them later
            VisibilityFlag            oldDeviceMask       = drawDevice.VisibilityMask;
            ColorRgba                 oldDeviceClearColor = drawDevice.ClearColor;
            ContentRef <RenderTarget> oldDeviceTarget     = drawDevice.Target;

            Rect    localViewport;
            Vector2 localTargetSize;
            ContentRef <RenderTarget> renderTarget;

            // If this step is using a custom render target, override image and viewport sizes
            if (step.Output.IsAvailable)
            {
                renderTarget    = step.Output;
                localTargetSize = step.Output.Res.Size;
                localViewport   = new Rect(step.Output.Res.Size);
            }
            // Otherwise, use the provided parameter values
            else
            {
                renderTarget    = oldDeviceTarget;
                localTargetSize = imageSize;
                localViewport   = viewportRect;
            }

            // Regardless of rendering targets, adjust the local render size and viewport
            // according to the rendering step target rect
            localViewport.Pos  += localViewport.Size * step.TargetRect.Pos;
            localViewport.Size *= step.TargetRect.Size;
            localTargetSize    *= step.TargetRect.Size;

            // Set up the draw device with rendering step settings
            drawDevice.RenderMode   = step.MatrixMode;
            drawDevice.Target       = renderTarget;
            drawDevice.TargetSize   = localTargetSize;
            drawDevice.ViewportRect = localViewport;
            drawDevice.ClearFlags   = step.ClearFlags;
            drawDevice.ClearColor   = step.DefaultClearColor ? oldDeviceClearColor : step.ClearColor;
            drawDevice.ClearDepth   = step.ClearDepth;

            // ScreenOverlay is a special flag that is set on a per-rendering-step basis
            // and that shouldn't be affected by overall device settings. Keep it separate.
            drawDevice.VisibilityMask =
                (drawDevice.VisibilityMask & step.VisibilityMask & ~VisibilityFlag.ScreenOverlay) |
                (step.VisibilityMask & VisibilityFlag.ScreenOverlay);

            try
            {
                this.OnRenderSingleStep(step, scene, drawDevice);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error while {0} was processing rendering step '{1}': {2}", this, step.Id, /*LogFormat.Exception(*/ e /*)*/);
            }

            // Restore old draw device state
            drawDevice.VisibilityMask = oldDeviceMask;
            drawDevice.ClearColor     = oldDeviceClearColor;
            drawDevice.Target         = oldDeviceTarget;
        }
Exemple #7
0
 /// <summary>
 /// Adds an additional rendering step to <see cref="Steps"/>.
 /// </summary>
 /// <param name="anchorPos">Position of the new rendering step relative to the one it is anchored to.</param>
 /// <param name="step">The new rendering step that should be inserted into the rendering step sequence.</param>
 public void AddRenderStep(RenderStepPosition anchorPos, RenderStep step)
 {
     this.AddRenderStep(null, anchorPos, step);
 }