#region License /* FNA - XNA4 Reimplementation for Desktop Platforms * Copyright 2009-2016 Ethan Lee and the MonoGame Team * * Released under the Microsoft Public License. * See LICENSE for details. */ #endregion #region Using Statements using System; #endregion namespace Microsoft.Xna.Framework.Graphics { /// /// Represents a texture cube that can be used as a render target. /// public class RenderTargetCube : TextureCube, IRenderTarget { #region Public Properties /// /// Gets the depth-stencil buffer format of this render target. /// /// The format of the depth-stencil buffer. public DepthFormat DepthStencilFormat { get; private set; } /// /// Gets the number of multisample locations. /// /// The number of multisample locations. public int MultiSampleCount { get; private set; } /// /// Gets the usage mode of this render target. /// /// The usage mode of the render target. public RenderTargetUsage RenderTargetUsage { get; private set; } public bool IsContentLost { get { return false; } } #endregion #region IRenderTarget Properties /// int IRenderTarget.Width { get { return Size; } } /// int IRenderTarget.Height { get { return Size; } } /// IGLRenderbuffer IRenderTarget.DepthStencilBuffer { get { return glDepthStencilBuffer; } } /// IGLRenderbuffer IRenderTarget.ColorBuffer { get { return glColorBuffer; } } #endregion #region Private Variables private IGLRenderbuffer glDepthStencilBuffer; private IGLRenderbuffer glColorBuffer; #endregion #region ContentLost Event #pragma warning disable 0067 // We never lose data, but lol XNA4 compliance -flibit public event EventHandler ContentLost; #pragma warning restore 0067 #endregion #region Public Constructors /// /// Initializes a new instance of the class. /// /// The graphics device. /// The width and height of a texture cube face in pixels. /// /// to generate a full mipmap chain; otherwise . /// /// The preferred format of the surface. /// The preferred format of the depth-stencil buffer. public RenderTargetCube( GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat ) : this( graphicsDevice, size, mipMap, preferredFormat, preferredDepthFormat, 0, RenderTargetUsage.DiscardContents ) { } /// /// Initializes a new instance of the class. /// /// The graphics device. /// The width and height of a texture cube face in pixels. /// /// to generate a full mipmap chain; otherwise . /// /// The preferred format of the surface. /// The preferred format of the depth-stencil buffer. /// The preferred number of multisample locations. /// The usage mode of the render target. public RenderTargetCube( GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage ) : base( graphicsDevice, size, mipMap, preferredFormat ) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = Math.Min( MathHelper.ClosestMSAAPower(preferredMultiSampleCount), graphicsDevice.GLDevice.MaxMultiSampleCount ); RenderTargetUsage = usage; if (MultiSampleCount > 0) { glColorBuffer = graphicsDevice.GLDevice.GenRenderbuffer( size, size, Format, MultiSampleCount ); } // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } glDepthStencilBuffer = graphicsDevice.GLDevice.GenRenderbuffer( size, size, preferredDepthFormat, MultiSampleCount ); } #endregion #region Protected Dispose Method /// /// Releases the unmanaged resources used by an instance of the /// class and optionally releases the managed /// resources. /// /// /// to release both managed and unmanaged resources; /// to release only unmanaged resources. /// protected override void Dispose(bool disposing) { if (!IsDisposed) { if (glDepthStencilBuffer != null) { GraphicsDevice.GLDevice.AddDisposeRenderbuffer(glDepthStencilBuffer); } base.Dispose(disposing); } } #endregion } }