public static void FreeRenderTarget(RenderTargetAsset Asset) { if (Asset != null) { Asset.InUse = false; } }
public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture) { base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture); _visualTexture = ContentManager.Instance.GetRenderTexture(_renderTextureKey); _visualSurface = ContentManager.Instance.GetRenderTarget(_renderSurfaceKey); _screen = parent.Screen; PrepareVisual(); }
public override void BeginRender() { // Remember current backbuffer and set internal surface as new render target. _backbuffer = GraphicsDevice.Device.GetRenderTarget(0); _renderTarget = ContentManager.Instance.GetRenderTarget(GLOBAL_RENDER_SURFACE_ASSET_KEY); _renderTarget.AllocateRenderTarget(GraphicsDevice.Width, GraphicsDevice.Height); _renderRect = new Rectangle(0, 0, GraphicsDevice.Width, GraphicsDevice.Height); GraphicsDevice.Device.SetRenderTarget(0, _renderTarget.Surface); GraphicsDevice.RenderPass = RenderPassType.SingleOrFirstPass; GraphicsDevice.Device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0); GraphicsDevice.Device.BeginScene(); }
/// <summary> /// Renders the <see cref="FrameworkElement"/> to the given <paramref name="renderTarget"/>. This method works with /// surfaces that are created as render target, which do support multisampling. /// </summary> /// <param name="renderTarget">Render target.</param> /// <param name="renderContext">Render context.</param> public void RenderToSurface(RenderTargetAsset renderTarget, RenderContext renderContext) { RenderToSurfaceInternal(renderTarget.Surface, renderContext); }
public void RenderToSurface(RenderTargetAsset renderTarget, RenderContext renderContext) { // We do the following here: // 1. Set the transformation matrix to match the render surface's size // 2. Set the rendertarget to the given surface // 3. Clear the surface with an alpha value of 0 // 4. Render the control (into the surface) // 5. Restore the rendertarget to the backbuffer // 6. Restore previous transformation matrix // Set transformation matrix Matrix? oldTransform = null; if (renderTarget.Width != GraphicsDevice.Width || renderTarget.Height != GraphicsDevice.Height) { oldTransform = GraphicsDevice.FinalTransform; GraphicsDevice.SetCameraProjection(renderTarget.Width, renderTarget.Height); } // Get the current backbuffer using (Surface backBuffer = GraphicsDevice.Device.GetRenderTarget(0)) { // Change the rendertarget to the render texture GraphicsDevice.Device.SetRenderTarget(0, renderTarget.Surface); // Fill the background of the texture with an alpha value of 0 GraphicsDevice.Device.Clear(ClearFlags.Target, Color.FromArgb(0, Color.Black), 1.0f, 0); // Render the control into the given texture DoRender(renderContext); // Restore the backbuffer GraphicsDevice.Device.SetRenderTarget(0, backBuffer); } // Restore standard transformation matrix if (oldTransform.HasValue) GraphicsDevice.FinalTransform = oldTransform.Value; }