#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2022 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;
}
}
///
IntPtr IRenderTarget.DepthStencilBuffer
{
get
{
return glDepthStencilBuffer;
}
}
///
IntPtr IRenderTarget.ColorBuffer
{
get
{
return glColorBuffer;
}
}
#endregion
#region Private FNA3D Variables
private IntPtr glDepthStencilBuffer;
private IntPtr 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 = FNA3D.FNA3D_GetMaxMultiSampleCount(
graphicsDevice.GLDevice,
Format,
MathHelper.ClosestMSAAPower(preferredMultiSampleCount)
);
RenderTargetUsage = usage;
if (MultiSampleCount > 0)
{
glColorBuffer = FNA3D.FNA3D_GenColorRenderbuffer(
graphicsDevice.GLDevice,
Size,
Size,
Format,
MultiSampleCount,
texture
);
}
// If we don't need a depth buffer then we're done.
if (DepthStencilFormat == DepthFormat.None)
{
return;
}
glDepthStencilBuffer = FNA3D.FNA3D_GenDepthStencilRenderbuffer(
graphicsDevice.GLDevice,
Size,
Size,
DepthStencilFormat,
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 (glColorBuffer != IntPtr.Zero)
{
FNA3D.FNA3D_AddDisposeRenderbuffer(
GraphicsDevice.GLDevice,
glColorBuffer
);
}
if (glDepthStencilBuffer != IntPtr.Zero)
{
FNA3D.FNA3D_AddDisposeRenderbuffer(
GraphicsDevice.GLDevice,
glDepthStencilBuffer
);
}
}
base.Dispose(disposing);
}
#endregion
}
}