Show More
Commit Description:
Add basic infrastructure to store and display visitor count....
Commit Description:
Add basic infrastructure to store and display visitor count.
May eventually move to simulating visitors as entities. We'll see.
References:
File last commit:
Show/Diff file:
Action:
FNA/src/Graphics/RenderTarget2D.cs
212 lines | 3.6 KiB | text/x-csharp | CSharpLexer
212 lines | 3.6 KiB | text/x-csharp | CSharpLexer
r0 | #region License | |||
/* FNA - XNA4 Reimplementation for Desktop Platforms | ||||
r690 | * Copyright 2009-2022 Ethan Lee and the MonoGame Team | |||
r0 | * | |||
* Released under the Microsoft Public License. | ||||
* See LICENSE for details. | ||||
*/ | ||||
#endregion | ||||
#region Using Statements | ||||
using System; | ||||
#endregion | ||||
namespace Microsoft.Xna.Framework.Graphics | ||||
{ | ||||
public class RenderTarget2D : Texture2D, IRenderTarget | ||||
{ | ||||
#region Public Properties | ||||
public DepthFormat DepthStencilFormat | ||||
{ | ||||
get; | ||||
private set; | ||||
} | ||||
public int MultiSampleCount | ||||
{ | ||||
get; | ||||
private set; | ||||
} | ||||
public RenderTargetUsage RenderTargetUsage | ||||
{ | ||||
get; | ||||
private set; | ||||
} | ||||
public bool IsContentLost | ||||
{ | ||||
get | ||||
{ | ||||
return false; | ||||
} | ||||
} | ||||
#endregion | ||||
#region IRenderTarget Properties | ||||
/// <inheritdoc/> | ||||
r690 | IntPtr IRenderTarget.DepthStencilBuffer | |||
r0 | { | |||
get | ||||
{ | ||||
return glDepthStencilBuffer; | ||||
} | ||||
} | ||||
/// <inheritdoc/> | ||||
r690 | IntPtr IRenderTarget.ColorBuffer | |||
r0 | { | |||
get | ||||
{ | ||||
return glColorBuffer; | ||||
} | ||||
} | ||||
#endregion | ||||
r690 | #region Private FNA3D Variables | |||
r0 | ||||
r690 | private IntPtr glDepthStencilBuffer; | |||
private IntPtr glColorBuffer; | ||||
r0 | ||||
#endregion | ||||
#region ContentLost Event | ||||
#pragma warning disable 0067 | ||||
// We never lose data, but lol XNA4 compliance -flibit | ||||
public event EventHandler<EventArgs> ContentLost; | ||||
#pragma warning restore 0067 | ||||
#endregion | ||||
#region Public Constructors | ||||
public RenderTarget2D( | ||||
GraphicsDevice graphicsDevice, | ||||
int width, | ||||
int height | ||||
) : this( | ||||
graphicsDevice, | ||||
width, | ||||
height, | ||||
false, | ||||
SurfaceFormat.Color, | ||||
DepthFormat.None, | ||||
0, | ||||
RenderTargetUsage.DiscardContents | ||||
) { | ||||
} | ||||
public RenderTarget2D( | ||||
GraphicsDevice graphicsDevice, | ||||
int width, | ||||
int height, | ||||
bool mipMap, | ||||
SurfaceFormat preferredFormat, | ||||
DepthFormat preferredDepthFormat | ||||
) : this( | ||||
graphicsDevice, | ||||
width, | ||||
height, | ||||
mipMap, | ||||
preferredFormat, | ||||
preferredDepthFormat, | ||||
0, | ||||
RenderTargetUsage.DiscardContents | ||||
) { | ||||
} | ||||
public RenderTarget2D( | ||||
GraphicsDevice graphicsDevice, | ||||
int width, | ||||
int height, | ||||
bool mipMap, | ||||
SurfaceFormat preferredFormat, | ||||
DepthFormat preferredDepthFormat, | ||||
int preferredMultiSampleCount, | ||||
RenderTargetUsage usage | ||||
) : base( | ||||
graphicsDevice, | ||||
width, | ||||
height, | ||||
mipMap, | ||||
preferredFormat | ||||
) { | ||||
DepthStencilFormat = preferredDepthFormat; | ||||
r690 | MultiSampleCount = FNA3D.FNA3D_GetMaxMultiSampleCount( | |||
graphicsDevice.GLDevice, | ||||
Format, | ||||
MathHelper.ClosestMSAAPower(preferredMultiSampleCount) | ||||
r0 | ); | |||
RenderTargetUsage = usage; | ||||
if (MultiSampleCount > 0) | ||||
{ | ||||
r690 | glColorBuffer = FNA3D.FNA3D_GenColorRenderbuffer( | |||
graphicsDevice.GLDevice, | ||||
r0 | Width, | |||
Height, | ||||
Format, | ||||
MultiSampleCount, | ||||
texture | ||||
); | ||||
} | ||||
// If we don't need a depth buffer then we're done. | ||||
if (DepthStencilFormat == DepthFormat.None) | ||||
{ | ||||
return; | ||||
} | ||||
r690 | glDepthStencilBuffer = FNA3D.FNA3D_GenDepthStencilRenderbuffer( | |||
graphicsDevice.GLDevice, | ||||
r0 | Width, | |||
Height, | ||||
DepthStencilFormat, | ||||
MultiSampleCount | ||||
); | ||||
} | ||||
#endregion | ||||
#region Protected Dispose Method | ||||
protected override void Dispose(bool disposing) | ||||
{ | ||||
if (!IsDisposed) | ||||
{ | ||||
r690 | if (glColorBuffer != IntPtr.Zero) | |||
r0 | { | |||
r690 | FNA3D.FNA3D_AddDisposeRenderbuffer( | |||
GraphicsDevice.GLDevice, | ||||
glColorBuffer | ||||
); | ||||
r0 | } | |||
r690 | if (glDepthStencilBuffer != IntPtr.Zero) | |||
r0 | { | |||
r690 | FNA3D.FNA3D_AddDisposeRenderbuffer( | |||
GraphicsDevice.GLDevice, | ||||
glDepthStencilBuffer | ||||
); | ||||
r0 | } | |||
} | ||||
base.Dispose(disposing); | ||||
} | ||||
#endregion | ||||
#region Internal Context Reset Method | ||||
protected internal override void GraphicsDeviceResetting() | ||||
{ | ||||
base.GraphicsDeviceResetting(); | ||||
} | ||||
#endregion | ||||
} | ||||
} | ||||