Example #1
0
 private void RenderToTexture()
 {
     if (FrameSize.X > 0 && FrameSize.Y > 0)
     {
         RenderTexture.SetAsRenderTarget();
         Renderer.PushState(
             RenderState.Viewport |
             RenderState.World |
             RenderState.View |
             RenderState.Projection |
             RenderState.DepthState |
             RenderState.ScissorState |
             RenderState.StencilState |
             RenderState.CullMode |
             RenderState.Transform2);
         try {
             Renderer.ScissorState = ScissorState.ScissorDisabled;
             Renderer.StencilState = StencilState.Default;
             Renderer.Viewport     = new Viewport(0, 0, RenderTexture.ImageSize.Width, RenderTexture.ImageSize.Height);
             Renderer.Clear(new Color4(0, 0, 0, 0));
             Renderer.World = Renderer.View = Matrix44.Identity;
             Renderer.SetOrthogonalProjection(0, 0, FrameSize.X, FrameSize.Y);
             Renderer.DepthState = DepthState.DepthDisabled;
             Renderer.CullMode   = CullMode.None;
             Renderer.Transform2 = LocalToWorldTransform.CalcInversed();
             Objects.Render();
         } finally {
             RenderTexture.RestoreRenderTarget();
             Renderer.PopState();
         }
     }
 }
Example #2
0
 public void RestoreRenderTarget()
 {
     if (texture == null)
     {
         texture = LoadTexture();
     }
     texture.RestoreRenderTarget();
 }
Example #3
0
        internal void RenderToTexture(ITexture renderTargetTexture, ITexture sourceTexture, IMaterial material, Color4 color, Color4 backgroundColor, Size?customViewportSize = null, Vector2?customUV1 = null)
        {
            var vs  = customViewportSize ?? ViewportSize;
            var uv1 = customUV1 ?? ProcessedUV1;

            if (ProcessedViewport.Width != vs.Width || ProcessedViewport.Height != vs.Height)
            {
                Renderer.Viewport = ProcessedViewport = new Viewport(0, 0, vs.Width, vs.Height);
            }
            renderTargetTexture.SetAsRenderTarget();
            try {
                Renderer.Clear(backgroundColor);
                Renderer.DrawSprite(sourceTexture, null, material, color, Vector2.Zero, TextureSize, Vector2.Zero, uv1, Vector2.Zero, Vector2.Zero);
            } finally {
                renderTargetTexture.RestoreRenderTarget();
            }
        }
Example #4
0
 public static void RenderToTexture(this Widget widget, ITexture texture, RenderChain renderChain, bool clearRenderTarget = true)
 {
     if (widget.Width > 0 && widget.Height > 0)
     {
         texture.SetAsRenderTarget();
         Renderer.PushState(
             RenderState.ScissorState |
             RenderState.View |
             RenderState.World |
             RenderState.View |
             RenderState.Projection |
             RenderState.DepthState |
             RenderState.CullMode |
             RenderState.Transform2);
         Renderer.ScissorState = ScissorState.ScissorDisabled;
         Renderer.Viewport     = new Viewport(0, 0, texture.ImageSize.Width, texture.ImageSize.Height);
         if (clearRenderTarget)
         {
             Renderer.Clear(new Color4(0, 0, 0, 0));
         }
         Renderer.World = Matrix44.Identity;
         Renderer.View  = Matrix44.Identity;
         Renderer.SetOrthogonalProjection(0, 0, widget.Width, widget.Height);
         Renderer.DepthState = DepthState.DepthDisabled;
         Renderer.CullMode   = CullMode.None;
         Renderer.Transform2 = widget.LocalToWorldTransform.CalcInversed();
         try {
             for (var node = widget.FirstChild; node != null; node = node.NextSibling)
             {
                 node.RenderChainBuilder?.AddToRenderChain(renderChain);
             }
             renderChain.Render();
         } finally {
             renderChain.Clear();
         }
         Renderer.PopState();
         texture.RestoreRenderTarget();
     }
 }