#region License
#endregion
#region Using Statements
using
System;
#endregion
namespace
Microsoft.Xna.Framework.Graphics
{
public
abstract
class
Texture : GraphicsResource
{
#region Public Properties
public
SurfaceFormat Format
{
get
;
protected
set
;
}
public
int
LevelCount
{
get
;
protected
set
;
}
#endregion
#region Internal Variables
internal
IGLTexture texture;
#endregion
#region Protected Dispose Method
protected
override
void
Dispose(
bool
disposing)
{
if
(!IsDisposed)
{
GraphicsDevice.GLDevice.AddDisposeTexture(texture);
}
base
.Dispose(disposing);
}
#endregion
#region Internal Context Reset Method
internal
protected
override
void
GraphicsDeviceResetting()
{
}
#endregion
#region Static SurfaceFormat Size Method
internal
static
int
GetFormatSize(SurfaceFormat format)
{
switch
(format)
{
case
SurfaceFormat.Dxt1:
return
8;
case
SurfaceFormat.Dxt3:
case
SurfaceFormat.Dxt5:
return
16;
case
SurfaceFormat.Alpha8:
return
1;
case
SurfaceFormat.Bgr565:
case
SurfaceFormat.Bgra4444:
case
SurfaceFormat.Bgra5551:
case
SurfaceFormat.HalfSingle:
case
SurfaceFormat.NormalizedByte2:
return
2;
case
SurfaceFormat.Color:
case
SurfaceFormat.Single:
case
SurfaceFormat.Rg32:
case
SurfaceFormat.HalfVector2:
case
SurfaceFormat.NormalizedByte4:
case
SurfaceFormat.Rgba1010102:
return
4;
case
SurfaceFormat.HalfVector4:
case
SurfaceFormat.Rgba64:
case
SurfaceFormat.Vector2:
return
8;
case
SurfaceFormat.Vector4:
return
16;
default
:
throw
new
ArgumentException(
"Should be a value defined in SurfaceFormat"
,
"Format"
);
}
}
#endregion
#region Static Mipmap Level Calculator
internal
static
int
CalculateMipLevels(
int
width,
int
height = 0,
int
depth = 0
) {
int
levels = 1;
for
(
int
size = Math.Max(Math.Max(width, height), depth);
size > 1;
levels += 1
) {
size /= 2;
}
return
levels;
}
#endregion
}
}