/// <summary>
        /// Creates a new instance of the resource factory
        /// </summary>
        /// <param name="canvas">The DirectCanvasFactory this factory belongs to</param>
        public ResourceFactory(DirectCanvasFactory canvas)
        {
            m_directCanvasFactory = canvas;
            m_textureResourceOwner = new RenderTargetTexture(m_directCanvasFactory.DeviceContext.Device, 
                                                             MINIMUM_RENDERTARGET_WIDTH, 
                                                             MINIMUM_RENDERTARGET_HEIGHT);

            m_renderTargetResourceOwner = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext, 
                                                                   m_textureResourceOwner.InternalDxgiSurface);
        }
Example #2
0
        /// <summary>
        /// Applys a shader effect
        /// </summary>
        /// <param name="effect">The shader effect to apply</param>
        /// <param name="inTexture">The DrawingLayer to be used as input</param>
        /// <param name="outTexture">The DrawingLayer to be used as output</param>
        /// <param name="clearOutput">Clear the output before writing</param>
        public void Apply(ShaderEffect effect, RenderTargetTexture inTexture, RenderTargetTexture outTexture, bool clearOutput)
        {
            var device = m_directCanvasFactory.DeviceContext.Device;

            if(clearOutput)
                outTexture.Clear(new Color4(0, 0, 0, 0));

            outTexture.SetRenderTarget();

            device.PixelShader.SetShaderResource(inTexture.InternalShaderResourceView, 0);
            if (effect.Filter == ShaderEffectFilter.Linear)
                device.PixelShader.SetSampler(m_linearSamplerState, 0);
            else if (effect.Filter == ShaderEffectFilter.Point)
                device.PixelShader.SetSampler(m_pointSamplerState, 0);
            device.OutputMerger.BlendState = m_alphaBlendState;

            effect.Draw();
        }
Example #3
0
 /// <summary>
 /// Begin our composition process
 /// </summary>
 /// <param name="renderTargetTexture">The render target to write to</param>
 /// <param name="blendStateMode">The blend state to use</param>
 public void BeginDraw(RenderTargetTexture renderTargetTexture, BlendStateMode blendStateMode)
 {
     m_drawStateManagement.BeginDrawState();
     m_spriteRenderer.BeginDraw(FilterMode.Linear, renderTargetTexture, blendStateMode);
 }
Example #4
0
        public virtual void Dispose()
        {
            if(SystemMemoryTexture != null)
            {
                SystemMemoryTexture.Dispose();
                SystemMemoryTexture = null;
            }

            if(m_d2DRenderTarget != null)
            {
                m_d2DRenderTarget.Dispose();
                m_d2DRenderTarget = null;
            }

            if (m_renderTargetTexture != null)
            {
                m_renderTargetTexture.Dispose();
                m_renderTargetTexture = null;
            }

            if (m_textFormat != null)
            {
                m_textFormat.Dispose();
                m_textFormat = null;
            }

            if(m_directWriteFactory != null)
            {
                m_directWriteFactory.Dispose();
                m_directWriteFactory = null;
            }

            foreach (var stateBlock in m_stateStack)
            {
                stateBlock.Dispose();
            }

            m_stateStack.Clear();
        }
Example #5
0
        /// <summary>
        /// Creates a new instance of the DrawingLayer
        /// </summary>
        /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param>
        /// <param name="renderTargetTexture">The Direct3D texture to use</param>
        internal DrawingLayer(DirectCanvasFactory directCanvasFactory, RenderTargetTexture renderTargetTexture)
        {
            m_directCanvasFactory = directCanvasFactory;
            m_format = renderTargetTexture.Description.Format;

            m_drawStateManagement = new DrawStateManagement();

            /* Set our Direct3D texture */
            RenderTargetTexture = renderTargetTexture;

            /* Create the Direct2D render target, using our Direct3D texture we were passed */
            D2DRenderTarget = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext,
                                                       m_renderTargetTexture.InternalDxgiSurface, 
                                                       m_format);
        }
Example #6
0
        /// <summary>
        /// Creates a new instance of the DrawingLayer
        /// </summary>
        /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param>
        /// <param name="width">The pixel size in width to make the D3D texture</param>
        /// <param name="height">The pixel size in height to make the D3D texture</param>
        /// <param name="format">The color format to make the D3D texture</param>
        /// <param name="optionFlags">Option flags to use on the creation of the D3D texture</param>
        internal DrawingLayer(DirectCanvasFactory directCanvasFactory, 
                              int width, 
                              int height, 
                              Format format = Format.B8G8R8A8_UNorm, 
                              ResourceOptionFlags optionFlags = ResourceOptionFlags.None)
        {
            m_directCanvasFactory = directCanvasFactory;
            m_format = format;

            m_drawStateManagement = new DrawStateManagement();

            var device = m_directCanvasFactory.DeviceContext.Device;

            /* Create our Direct3D texture */
            RenderTargetTexture = new RenderTargetTexture(device, width, height, m_format, optionFlags);

            /* Create the Direct2D render target, using our Direct3D texture we just created */
            D2DRenderTarget = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext,
                                                       m_renderTargetTexture.InternalDxgiSurface, 
                                                       m_format);
        }
        public void Dispose()
        {
           if(m_renderTargetResourceOwner != null)
           {
               m_renderTargetResourceOwner.Dispose();
               m_renderTargetResourceOwner = null;
           }

            if(m_textureResourceOwner != null)
            {
                m_textureResourceOwner.Dispose();
                m_textureResourceOwner = null;
            }
        }
Example #8
0
        /// <summary>
        /// Ends the batch process and flushes any remaining batched commands.
        /// </summary>
        public void EndDraw()
        {
            if (m_drawDataPosition == 0)
                return;

            Flush();
            m_outputTexture = null;
        }
Example #9
0
        /// <summary>
        /// Begins the batch process.
        /// </summary>
        /// <param name="filterMode">The filter mode to use</param>
        /// <param name="outputTexture">The texture to render to</param>
        /// <param name="blendStateMode">The blend state to use</param>
        public void BeginDraw(FilterMode filterMode, RenderTargetTexture outputTexture, BlendStateMode blendStateMode)
        {
            m_blendStateMode = blendStateMode;
            m_outputTexture = outputTexture;
            m_drawDataPosition = 0;

            m_filterMode = filterMode;
            BeginDrawSetup();
        }
Example #10
0
 /// <summary>
 /// Begins the composition process.  BeingCompose always needs 
 /// to be eventually followed by an EndCompose.
 /// </summary>
 /// <param name="renderTarget">The RenderTargetTexture to begin composition on.</param>
 /// <param name="blendStateMode">The blend state to use</param>
 internal void BeginCompose(RenderTargetTexture renderTarget, BlendStateMode blendStateMode)
 {
     m_composeStateManagement.BeginDrawState();
     m_composer.BeginDraw(renderTarget, blendStateMode);
 }
Example #11
0
        /// <summary>
        /// Applys a shader effect
        /// </summary>
        /// <param name="effect">The shader effect to apply</param>
        /// <param name="inTexture">The DrawingLayer to be used as input</param>
        /// <param name="outTexture">The DrawingLayer to be used as output</param>
        /// <param name="targetRect"></param>
        /// <param name="clearOutput">Clear the output before writing</param>
        public void Apply(ShaderEffect effect, RenderTargetTexture inTexture, RenderTargetTexture outTexture, Rectangle targetRect, bool clearOutput)
        {
            var device = m_directCanvasFactory.DeviceContext.Device;

            if (clearOutput)
                outTexture.Clear(new Color4(0, 0, 0, 0));

            outTexture.SetRenderTarget(new Viewport(targetRect.X, targetRect.Y, targetRect.Width, targetRect.Height, 0, 1));

            device.PixelShader.SetShaderResource(inTexture.InternalShaderResourceView, 0);
            if (effect.Filter == ShaderEffectFilter.Linear)
                device.PixelShader.SetSampler(m_linearSamplerState, 0);
            else if (effect.Filter == ShaderEffectFilter.Point)
                device.PixelShader.SetSampler(m_pointSamplerState, 0);

            effect.Draw();
        }