#region license
// /*
// This file is part of Vocaluxe.
//
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see .
// */
#endregion
using System.Drawing;
namespace VocaluxeLib.Draw
{
public class CTexture
{
public int ID = -1;
public int PBO;
//Only used by OpenGL (the texture "name" according to the specs)
public int Name = -1;
public string TexturePath = "";
///
/// Original size (e.g. of bmp)
///
public readonly Size OrigSize;
public float OrigAspect
{
get { return (float)OrigSize.Width / OrigSize.Height; }
}
///
/// Current size when drawn
///
public SRectF Rect;
public SColorF Color = new SColorF(1f, 1f, 1f, 1f);
private int _W2, _H2;
private readonly bool _UseFullTexture;
///
/// Internal texture width (on device), a power of 2 if necessary
///
public int W2
{
get { return _W2; }
set
{
_W2 = value;
if (_UseFullTexture)
WidthRatio = 1;
else
WidthRatio = (float)OrigSize.Width / _W2;
}
}
///
/// Internal texture height (on device), a power of 2 if necessary
///
public int H2
{
get { return _H2; }
set
{
_H2 = value;
if (_UseFullTexture)
HeightRatio = 1;
else
HeightRatio = (float)OrigSize.Height / _H2;
}
}
///
/// Internal use. Specifies which part of texture memory is actually used
///
public float WidthRatio { get; private set; }
///
/// Internal use. Specifies which part of texture memory is actually used
///
public float HeightRatio { get; private set; }
///
/// Actual texture space used in x direction
///
public int UsedWidth
{
get { return (int)(_W2 * WidthRatio); }
}
///
/// Actual texture space used in y direction
///
public int UsedHeight
{
get { return (int)(_H2 * HeightRatio); }
}
/*
///
/// Internal use. Specifies if full texture memory should be used
/// Set to true if you resized the original image to the maximum
///
public bool UseFullTexture
{
get { return _UseFullTexture; }
set
{
_UseFullTexture = value;
if (value)
{
WidthRatio = 1;
HeightRatio = 1;
}
else
{
WidthRatio = (float)OrigSize.Width / _W2;
HeightRatio = (float)OrigSize.Height / _H2;
}
}
}
*/
///
/// Creates a new texture reference
///
/// Original width (Bitmap size)
/// Original height (Bitmap size)
/// Width in video memory
/// Height in video memory
/// True if it is using the full size of the video memory (no blank parts due to Pow-2-Issue)
public CTexture(int origWidth, int origHeight, int texWidth = 0, int texHeight = 0, bool useFullTexture = false)
{
OrigSize = new Size(origWidth, origHeight);
Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f);
_UseFullTexture = useFullTexture;
//IMPORTANT: Use setter here to calculate ratios!
W2 = (texWidth > 0) ? texWidth : origWidth;
H2 = (texHeight > 0) ? texHeight : origHeight;
}
}
}