/// <summary> /// Creates a new instance of <see cref="RenderFrame"/> from the specified parameters. /// </summary> /// <param name="graphicsDevice">The graphics device.</param> /// <param name="frameDescriptor">The frame descriptor.</param> /// <param name="referenceFrame">The reference frame, when using relative mode for <see cref="RenderFrameDescriptor.Mode"/>.</param> /// <returns>A new instance of <see cref="RenderFrame"/>.</returns> /// <exception cref="System.ArgumentNullException"> /// graphicsDevice /// or /// frameDescriptor /// </exception> public static RenderFrame New(GraphicsDevice graphicsDevice, RenderFrameDescriptor frameDescriptor, RenderFrame referenceFrame = null) { // Just return null if no render frame is defined if (frameDescriptor.DepthFormat == RenderFrameDepthFormat.None && frameDescriptor.Format == RenderFrameFormat.None) { return(null); } var renderFrame = new RenderFrame(); renderFrame.InitializeFrom(graphicsDevice, frameDescriptor, referenceFrame); return(renderFrame); }
/// <summary> /// Recover a <see cref="RenderFrame" /> from a texture that has been created for a render frame. /// </summary> /// <param name="renderTextures">The texture.</param> /// <param name="depthStencilTexture">The depth stencil texture.</param> /// <returns>The instance of RenderFrame or null if no render frame was used to create this texture.</returns> /// <exception cref="System.InvalidOperationException">The texture must be a render target</exception> public static RenderFrame FromTexture(Texture[] renderTextures, Texture depthStencilTexture = null) { Texture referenceTexture = null; if (renderTextures != null) { foreach (var renderTexture in renderTextures) { if (renderTexture != null && !renderTexture.IsRenderTarget) { throw new ArgumentException("The texture must be a render target", "renderTextures"); } if (referenceTexture == null && renderTexture != null) { referenceTexture = renderTexture; } else if (renderTexture != null) { if (referenceTexture.Width != renderTexture.Width || referenceTexture.Height != renderTexture.Height) { throw new ArgumentException("Invalid textures. The textures must have the same width/height", "renderTextures"); } } } } if (depthStencilTexture != null && !depthStencilTexture.IsDepthStencil) { throw new ArgumentException("The texture must be a depth stencil texture", "depthStencilTexture"); } if (referenceTexture == null && depthStencilTexture != null) { referenceTexture = depthStencilTexture; } else if (depthStencilTexture != null) { if (referenceTexture.Width != depthStencilTexture.Width || referenceTexture.Height != depthStencilTexture.Height) { throw new ArgumentException("Invalid textures/depthstencil. The textures must have the same width/height", "depthStencilTexture"); } } // If no relevant textures, than return null if (referenceTexture == null) { return(null); } var descriptor = RenderFrameDescriptor.Default(); // TODO: Check for formats? var renderFrameFormat = RenderFrameFormat.LDR; if (referenceTexture.Format == PixelFormat.R16G16B16A16_Float) { renderFrameFormat = RenderFrameFormat.HDR; } var depthFrameFormat = RenderFrameDepthFormat.None; if (depthStencilTexture != null) { depthFrameFormat = depthStencilTexture.HasStencil ? RenderFrameDepthFormat.DepthAndStencil : RenderFrameDepthFormat.Depth; } descriptor.Format = renderFrameFormat; descriptor.DepthFormat = depthFrameFormat; descriptor.Mode = RenderFrameSizeMode.Fixed; descriptor.Width = referenceTexture.Width; descriptor.Height = referenceTexture.Height; var renderFrame = new RenderFrame(); renderFrame.InitializeFrom(descriptor, renderTextures, depthStencilTexture, false); return(renderFrame); }