// Release a render target of a particular size
        public void Release(WrappedRenderTarget target)
        {
            // Entry logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Entering method for {0}", this.Name));
      #endif

            // Remove from list of unavailable targets
            this.UnavailableTargets[target.TargetIndex].Remove(target);
            // Add to list of available targets
            this.AvailableTargets[target.TargetIndex].Add(target);

            // Exit logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Exiting method for {0}", this.Name));
      #endif
        }
Exemplo n.º 2
0
        // =====
        #region Constructors

        // Default constructor
        public RenderTargetPair(WrappedRenderTarget target1, WrappedRenderTarget target2)
        {
            // Get unique instance ID
            RenderTargetPair.nextID++;
            this.id = RenderTargetPair.nextID;

            // Entry logging
      #if IS_LOGGING_METHODS
            Log.Write("Entering method for " + this.Name);
      #endif

            // Set instance variables
            this.targets = new WrappedRenderTarget[2] {
                target1, target2
            };
            this.isSwapped = false;

            // Exit logging
      #if IS_LOGGING_METHODS
            Log.Write("Exiting method for " + this.Name);
      #endif
        }
        // =====
        #region Methods

        // Allocate a render target of a particular size
        public WrappedRenderTarget Allocate(int size)
        {
            // Entry logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Entering method for {0}", this.Name));
      #endif

            // Declare result
            WrappedRenderTarget result;

            // Get the total number of available targets having this size
            int m = this.AvailableTargets[size].Count;

            // Check if there is an available target
            if (m > 0)
            {
                // If so, give it away
                result = this.AvailableTargets[size][m - 1];
                this.AvailableTargets[size].RemoveAt(m - 1);
                this.UnavailableTargets[size].Add(result);
            }
            else
            {
                // If not, create a new one
                int w = (int)(Globals.GraphicsDevice.BackBuffer.Width / Math.Pow(2, size));
                int h = (int)(Globals.GraphicsDevice.BackBuffer.Height / Math.Pow(2, size));
                result = new WrappedRenderTarget(w, h, size);
                this.UnavailableTargets[size].Add(result);
            }

            // Exit logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Exiting method for {0}", this.Name));
      #endif

            // Return result
            return(result);
        }
Exemplo n.º 4
0
 // Set a texture parameter
 public void SetParameter(String parameterName, WrappedRenderTarget value)
 {
     this.Effect.Parameters[parameterName].SetValue(value.RenderTarget);
 }
Exemplo n.º 5
0
        // Complicated blur draw
        public void Draw1()
        {
            // Entry logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Entering method for {0}", this.Name));
      #endif

            // REMEMBER BUFFER USAGE WRITE ONLY CHANGE!
            // VertexPositionColorTexture[] vertexArray = new VertexPositionColorTexture[4];
            // this.ActiveVertexBuffer.VertexBuffer.GetData<VertexPositionColorTexture>(vertexArray);
            // for (int i = 0; i < vertexArray.Length; i++) { Trace.WriteLine(String.Format("drawLayer\t{0}\tvertexArray[{1}] = {2}", Globals.Clock.TotalGameTime, i, vertexArray[i])); }

            // Initialization
            this.BeginDraw();

            int k = 2; // downsampling
            int n = 2; // iterations
            WrappedRenderTarget backBuffer           = this.BackBuffer;
            WrappedRenderTarget target1              = this.RenderTargetManager.Allocate(0);
            WrappedRenderTarget target2              = this.RenderTargetManager.Allocate(k);
            WrappedRenderTarget target3              = this.RenderTargetManager.Allocate(k);
            WrappedShader       defaultShader        = Globals.ShaderManager.DefaultShader;
            WrappedShader       horizontalBlurShader = WrappedHorizontalBlurShader.Gaussian(9, 2);
            WrappedShader       verticalBlurShader   = WrappedVerticalBlurShader.Gaussian(9, 2);

            this.ActiveRenderTarget = target1;
            this.Clear(this.BackgroundColor, true, false);

            // Loop through layers
            for (int i = 0; i < Globals.SpriteManager.Layers.Count - 1; i++)
            {
                // Get current layer
                SpriteLayer layer = Globals.SpriteManager.Layers[i];
                // Draw layer
                this.DrawLayer(layer);
            }

            // Loop through iterations
            for (int i = 0; i < n; i++)
            {
                // Apply horizontal blur
                this.ActiveRenderTarget = target2;
                if (i == 0)
                {
                    this.ActiveTexture = target1;
                }
                else
                {
                    this.ActiveTexture = target3;
                }
                this.ActiveShader = horizontalBlurShader;
                this.DrawBackBufferQuad();

                // Apply vertical blur
                this.ActiveRenderTarget = target3;
                this.ActiveTexture      = target2;
                this.ActiveShader       = verticalBlurShader;
                this.DrawBackBufferQuad();
            }

            // Draw blurred layers to back buffer
            this.ActiveRenderTarget = backBuffer;
            this.ActiveTexture      = target3;
            this.ActiveShader       = Globals.ShaderManager.DefaultShader;
            this.DrawBackBufferQuad();

            // Loop through remaining layers
            for (int i = 1; i < Globals.SpriteManager.Layers.Count; i++)
            {
                // Get current layer
                SpriteLayer layer = Globals.SpriteManager.Layers[i];
                // Draw layer
                this.DrawLayer(layer);
            }

            this.RenderTargetManager.Release(target3);
            this.RenderTargetManager.Release(target2);
            this.RenderTargetManager.Release(target1);

            if (Globals.Clock.TotalGameTime == 0 && !Globals.TestBool)
            {
                target1.Save(@"C:\Users\Chris\Desktop\GameLog\target1.png");
                target2.Save(@"C:\Users\Chris\Desktop\GameLog\target2.png");
                target3.Save(@"C:\Users\Chris\Desktop\GameLog\target3.png");
                Globals.TestBool = true;
            }

            // Exit logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Exiting method for {0}", this.Name));
      #endif
        }
Exemplo n.º 6
0
        // =====
        #region Constructors

        // Default constructor
        public WrappedGraphicsDevice()
        {
            // Get ID
            this.id = nextID++;

            // Entry logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Entering method for {0}", this.Name));
      #endif

            // Set screen size in pixels
            // WARNING:  ApplyChanges() will empty out all vertex and index buffers?!
            int w = 1280;
            int h = 720;
            Globals.Game1.Graphics.PreferredBackBufferWidth    = w;
            Globals.Game1.Graphics.PreferredBackBufferHeight   = h;
            Globals.Game1.Graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
            Globals.Game1.Graphics.ApplyChanges();
            Globals.Game1.IsMouseVisible           = true;
            Globals.Game1.Window.AllowUserResizing = true;


            // Set instance variables
            this.activeRenderTarget      = null;
            this.activeVertexBuffer      = null;
            this.activeIndexBuffer       = null;
            this.activeView              = Matrix.Identity;
            this.activeProjection        = Matrix.Identity;
            this.activeTexture           = null;
            this.activeShader            = null;
            this.activeBlendState        = null;
            this.activeDepthStencilState = null;

            this.backBuffer          = new WrappedBackBuffer();
            this.renderTargetManager = new RenderTargetManager();
            this.quadVertexBuffer    = new WrappedVertexBuffer(4);
            this.quadIndexBuffer     = new WrappedIndexBuffer(6);
            this.quadIndexBuffer.SetData(new int[6] {
                0, 1, 2, 0, 2, 3
            });
            this.backgroundColor = Color.White;
            this.drawCalls       = 0;

            this.device      = Globals.Game1.GraphicsDevice;
            this.spriteBatch = new SpriteBatch(this.device);
            // this.device.DepthStencilState = new DepthStencilState() { DepthBufferEnable = false };

            this.blendStateAlpha = new BlendState()
            {
                AlphaDestinationBlend = Blend.InverseSourceAlpha,
                ColorDestinationBlend = Blend.InverseSourceAlpha,
                ColorWriteChannels    = ColorWriteChannels.All
            };
            this.blendStateNone = new BlendState()
            {
                AlphaDestinationBlend = Blend.InverseSourceAlpha,
                ColorDestinationBlend = Blend.InverseSourceAlpha,
                ColorWriteChannels    = ColorWriteChannels.None
            };
            this.stencilStateIncrement = new DepthStencilState()
            {
                StencilEnable    = true,
                StencilFunction  = CompareFunction.LessEqual,
                ReferenceStencil = 0,
                StencilPass      = StencilOperation.Increment
            };
            this.stencilStateKeep = new DepthStencilState()
            {
                StencilEnable    = true,
                StencilFunction  = CompareFunction.LessEqual,
                ReferenceStencil = 0,
                StencilPass      = StencilOperation.Keep
            };

            // Exit logging
      #if IS_LOGGING_METHODS
            Log.Write(String.Format("Exiting method for {0}", this.Name));
      #endif
        }