Use better references to a single texture and unify more stuff

Also encapsulate everything graphic related in the Texture classes and not in the references
This commit is contained in:
Flamefire committed 2014-09-20 00:50:04 +02:00
1 parent cfb6d09d06
commit 1ce085b49f
8 files changed
+364 -298

No files matched your search

+1 -84
View File
@@ -25,9 +25,6 @@ namespace VocaluxeLib.Draw
public class CTextureRef
{
public int ID;
public int RefCount = 1;
public string TexturePath = "";
/// <summary>
/// Size of original image (e.g. of bmp)
@@ -39,20 +36,6 @@ namespace VocaluxeLib.Draw
get { return (float)OrigSize.Width / OrigSize.Height; }
}
private Size _DataSize;
/// <summary>
/// Size of data used (mostly equal to OrigSize but due to resizing this might change)
/// </summary>
public Size DataSize
{
get { return _DataSize; }
set
{
_DataSize = value;
_CalcRatios();
}
}
/// <summary>
/// Current size when drawn
/// </summary>
@@ -60,60 +43,17 @@ namespace VocaluxeLib.Draw
public SColorF Color = new SColorF(1f, 1f, 1f, 1f);
private int _W2, _H2;
/// <summary>
/// Internal texture width (on device), a power of 2 if necessary
/// </summary>
public int W2
{
get { return _W2; }
set
{
_W2 = value;
_CalcRatios();
}
}
/// <summary>
/// Internal texture height (on device), a power of 2 if necessary
/// </summary>
public int H2
{
get { return _H2; }
set
{
_H2 = value;
_CalcRatios();
}
}
/// <summary>
/// Internal use. Specifies which part of texture memory is actually used
/// </summary>
public float WidthRatio { get; private set; }
/// <summary>
/// Internal use. Specifies which part of texture memory is actually used
/// </summary>
public float HeightRatio { get; private set; }
/// <summary>
/// Creates a new texture reference
/// </summary>
/// <param name="id">ID of the texture</param>
/// <param name="origSize">Original size (Bitmap size)</param>
/// <param name="dataSize">Size of the data used</param>
/// <param name="texWidth">Width in video memory</param>
/// <param name="texHeight">Height in video memory</param>
public CTextureRef(int id, Size origSize, Size dataSize, int texWidth = 0, int texHeight = 0)
public CTextureRef(int id, Size origSize)
{
ID = id;
_DataSize = dataSize;
OrigSize = origSize;
_W2 = (texWidth > 0) ? texWidth : dataSize.Width;
_H2 = (texHeight > 0) ? texHeight : dataSize.Height;
Rect = new SRectF(0f, 0f, origSize.Width, origSize.Height, 0f);
_CalcRatios();
}
~CTextureRef()
@@ -125,28 +65,5 @@ namespace VocaluxeLib.Draw
CBase.Drawing.RemoveTexture(ref tmp);
}
}
private void _CalcRatios()
{
// OpenGL has a problem with partial (NPOT) textures, so we remove 1 pixel
if (_DataSize.Width == _W2)
WidthRatio = 1f;
else
{
int mod = 0;
if (_DataSize.Width > 1)
mod = -1;
WidthRatio = (float)(_DataSize.Width + mod) / _W2;
}
if (_DataSize.Height == _H2)
HeightRatio = 1f;
else
{
int mod = 0;
if (_DataSize.Height > 1)
mod = -1;
HeightRatio = (float)(_DataSize.Height + mod) / _H2;
}
}
}
}