Merge branch 'Better_Graphics_Handling' into develop

Conflicts:
	Vocaluxe/Base/Fonts/CFontStyle.cs
This commit is contained in:
Flamefire committed 2014-10-02 20:46:04 +02:00
commit 2e25bf6610
21 files changed
+338 -510

No files matched your search

+3 -2
View File
@@ -392,11 +392,12 @@ namespace Vocaluxe.Base
/// <param name="textureRef"></param>
/// <param name="rect">(Original) rectangle to draw the reflection for</param>
/// <param name="color"></param>
/// <param name="bounds"></param>
/// <param name="space">Spacing between the rect and the reflection</param>
/// <param name="height">Height of the reflection</param>
public static void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, float space, float height)
public static void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{
_Draw.DrawTextureReflection(textureRef, rect, color, space, height);
_Draw.DrawTextureReflection(textureRef, rect, color, bounds, space, height);
}
}
}
+7 -2
View File
@@ -174,6 +174,11 @@ namespace Vocaluxe.Base
return CSettings.RenderH;
}
public SRectF GetRenderRect()
{
return CSettings.RenderRect;
}
public bool IsTabNavigation()
{
return CSettings.TabNavigation;
@@ -438,9 +443,9 @@ namespace Vocaluxe.Base
CDraw.DrawTexture(textureRef, bounds, aspect, color);
}
public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight)
public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight)
{
CDraw.DrawTextureReflection(texture, rect, color, reflectionSpace, reflectionHeight);
CDraw.DrawTextureReflection(texture, rect, color, bounds, reflectionSpace, reflectionHeight);
}
public CTextureRef AddTexture(string fileName)
+1
View File
@@ -65,6 +65,7 @@ namespace Vocaluxe.Base
public const int RenderW = 1280;
public const int RenderH = 720;
public static readonly SRectF RenderRect = new SRectF(0, 0, RenderW, RenderH, 0);
public const int ZNear = -100;
public const int ZFar = 100;
+1 -2
View File
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Drawing;
using VocaluxeLib;
using VocaluxeLib.Draw;
@@ -63,7 +62,7 @@ namespace Vocaluxe.Base
if (_VideoTexture == null)
return;
CDraw.DrawTexture(_VideoTexture, new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, CSettings.ZFar / 4), EAspect.Crop);
CDraw.DrawTexture(_VideoTexture, CSettings.RenderRect, EAspect.Crop);
}
public void PreLoad()
+1 -1
View File
@@ -120,7 +120,7 @@ namespace Vocaluxe.Base.Fonts
CTextureRef texture;
SRectF rect;
GetOrAddGlyph(chr, fontHeight).GetTextureAndRect(fontHeight, x, y, z, out texture, out rect);
CDraw.DrawTextureReflection(texture, rect, color, rspace, rheight);
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
}
public float GetWidth(char chr, float height)
+35 -218
View File
@@ -420,6 +420,40 @@ namespace Vocaluxe.Lib.Draw
return _Device.Viewport.Height;
}
/// <summary>
/// Adds a texture to the vertext buffer
/// </summary>
/// <param name="texture">Texture to draw</param>
/// <param name="dc">Coordinates to draw on</param>
/// <param name="color">Color to use</param>
/// <param name="isReflection">If true, then color is faded out in y direction</param>
protected override void _DrawTexture(CD3DTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
{
//Align the pixels because Direct3D expects the pixels to be the left top corner
dc.Wx1 -= 0.5f;
dc.Wy1 -= 0.5f;
dc.Wx2 -= 0.5f;
dc.Wy2 -= 0.5f;
color.A *= CGraphics.GlobalAlpha;
int c = color.AsColor().ToArgb();
int c2;
if (isReflection)
{
color.A = 0;
c2 = color.AsColor().ToArgb();
}
else
c2 = c;
var vert = new STexturedColoredVertex[4];
vert[0] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy1, dc.Wz), new Vector2(dc.Tx1, dc.Ty1), c);
vert[1] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy2, dc.Wz), new Vector2(dc.Tx1, dc.Ty2), c2);
vert[2] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy2, dc.Wz), new Vector2(dc.Tx2, dc.Ty2), c2);
vert[3] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy1, dc.Wz), new Vector2(dc.Tx2, dc.Ty1), c);
_AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(dc.Rotation, dc.Wx1, dc.Wx2, dc.Wy1, dc.Wy2));
}
/// <summary>
/// Adds a quad a list which will be added and rendered to the vertexbuffer when calling RenderToVertexBuffer to reduce vertexbuffer calls each frame to a minimum
/// </summary>
@@ -552,7 +586,7 @@ namespace Vocaluxe.Lib.Draw
/// <param name="height">The height of the reflection</param>
public void DrawRectReflection(SColorF color, SRectF rect, float space, float height)
{
DrawTextureReflection(_BlankTexture, rect, color, space, height);
DrawTextureReflection(_BlankTexture, rect, color, rect, space, height);
}
#endregion Basic Draw Methods
@@ -582,223 +616,6 @@ namespace Vocaluxe.Lib.Draw
}
texture.D3DTexture.UnlockRectangle(0);
}
#region drawing
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false)
{
if (rect.W < 1 || rect.H < 1)
return;
CD3DTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
//Calculate the position
const float x1 = 0;
float x2 = texture.WidthRatio;
float y1 = 0;
float y2 = texture.HeightRatio;
//Calculate the size
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y;
float ry2 = rect.Y + rect.H;
color.A *= CGraphics.GlobalAlpha;
Color c = color.AsColor();
if (mirrored)
{
float tmp = y2;
y2 = y1;
y1 = tmp;
}
var vert = new STexturedColoredVertex[4];
vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb());
vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb());
_AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false)
{
if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1 || Math.Abs(bounds.H) < 1 || Math.Abs(bounds.W) < 1 ||
Math.Abs(color.A) < 0.01)
return;
if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X)
return;
if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y)
return;
CD3DTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
//Calculate the position
float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio;
float y1 = (bounds.Y - rect.Y) / rect.H * texture.HeightRatio;
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio;
if (x1 < 0)
x1 = 0f;
if (x2 > texture.WidthRatio)
x2 = texture.WidthRatio;
if (y1 < 0)
y1 = 0f;
if (y2 > texture.HeightRatio)
y2 = texture.HeightRatio;
//Calculate the size
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y;
float ry2 = rect.Y + rect.H;
if (rx1 < bounds.X)
rx1 = bounds.X;
if (rx2 > bounds.X + bounds.W)
rx2 = bounds.X + bounds.W;
if (ry1 < bounds.Y)
ry1 = bounds.Y;
if (ry2 > bounds.Y + bounds.H)
ry2 = bounds.Y + bounds.H;
color.A *= CGraphics.GlobalAlpha;
Color c = color.AsColor();
if (mirrored)
{
y1 = -y1;
y2 = -y2;
}
var vert = new STexturedColoredVertex[4];
vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb());
vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb());
_AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end)
{
CD3DTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
float x1 = 0f + begin * texture.WidthRatio;
float x2 = texture.WidthRatio * end;
const float y1 = 0f;
float y2 = texture.HeightRatio;
float rx1 = rect.X + begin * rect.W;
float rx2 = rect.X + end * rect.W;
float ry1 = rect.Y;
float ry2 = rect.Y + rect.H;
//Align the pixels because Direct3D expects the pixels to be the left top corner
rx1 -= 0.5f;
ry1 -= 0.5f;
rx2 -= 0.5f;
ry2 -= 0.5f;
color.A *= CGraphics.GlobalAlpha;
Color c = color.AsColor();
var vert = new STexturedColoredVertex[4];
vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb());
vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb());
_AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
}
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="textureRef">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, float space, float height)
{
CD3DTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(color.A) < float.Epsilon || height <= 0f)
return;
if (height > rect.H)
height = rect.H;
const float x1 = 0;
float x2 = texture.WidthRatio;
float y1 = (rect.H - height) / rect.H * texture.HeightRatio;
float y2 = texture.HeightRatio;
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y + rect.H + space;
float ry2 = rect.Y + rect.H + space + height;
//Align the pixels because Direct3D expects the pixels to be the left top corner
rx1 -= 0.5f;
ry1 -= 0.5f;
rx2 -= 0.5f;
ry2 -= 0.5f;
color.A *= CGraphics.GlobalAlpha;
Color c = color.AsColor();
color.A = 0;
Color transparent = color.AsColor();
var vert = new STexturedColoredVertex[4];
vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb());
vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb());
vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
_AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
}
#endregion drawing
#endregion Textures
private static Matrix _CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2)
+224 -2
View File
@@ -212,6 +212,210 @@ namespace Vocaluxe.Lib.Draw
#region Textures
#region drawing
/// <summary>
/// Struct that contains texture and world coordinates for drawing
/// </summary>
protected struct SDrawCoords
{
/// <summary>
/// Texture coordinates
/// </summary>
public float Tx1, Tx2, Ty1, Ty2;
/// <summary>
/// World coordinates
/// </summary>
public float Wx1, Wx2, Wy1, Wy2, Wz;
public float Rotation;
}
/// <summary>
/// Adds a texture to the vertext buffer
/// </summary>
/// <param name="texture">Texture to draw</param>
/// <param name="dc">Coordinates to draw on</param>
/// <param name="color">Color to use</param>
/// <param name="isReflection">If true, then color is faded out in y direction</param>
protected abstract void _DrawTexture(TTextureType texture, SDrawCoords dc, SColorF color, bool isReflection = false);
/// <summary>
/// Calculates the texture and world coordinates for drawing the texture in the rect cropping at the the bounds
/// </summary>
/// <param name="texture"></param>
/// <param name="rect">Rect to draw the texture (might stretch the texture)</param>
/// <param name="bounds">Rect to stay in (might crop the texture)</param>
/// <param name="drawCoords">Struct for the coordinates</param>
/// <param name="mirrored">Mirror on y-axis</param>
/// <returns>True if anything will be dawn</returns>
protected bool _CalcDrawCoords(TTextureType texture, SRectF rect, SRectF bounds, out SDrawCoords drawCoords, bool mirrored = false)
{
drawCoords = new SDrawCoords();
if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1 || Math.Abs(bounds.H) < 1 || Math.Abs(bounds.W) < 1)
return false;
if (bounds.X >= rect.Right || bounds.Right <= rect.X)
return false;
if (bounds.Y >= rect.Bottom || bounds.Bottom <= rect.Y)
return false;
drawCoords.Tx1 = Math.Max(0, (bounds.X - rect.X) / rect.W * texture.WidthRatio);
drawCoords.Wx1 = Math.Max(rect.X, bounds.X);
drawCoords.Tx2 = Math.Min(1, (bounds.Right - rect.X) / rect.W) * texture.WidthRatio;
drawCoords.Wx2 = Math.Min(rect.Right, bounds.Right);
drawCoords.Ty1 = Math.Max(0, (bounds.Y - rect.Y) / rect.H * texture.HeightRatio);
drawCoords.Wy1 = Math.Max(rect.Y, bounds.Y);
drawCoords.Ty2 = Math.Min(1, (bounds.Bottom - rect.Y) / rect.H) * texture.HeightRatio;
drawCoords.Wy2 = Math.Min(rect.Bottom, bounds.Bottom);
if (mirrored)
{
float tmp = drawCoords.Ty1;
drawCoords.Ty1 = drawCoords.Ty2;
drawCoords.Ty2 = tmp;
}
drawCoords.Wz = rect.Z + CGraphics.ZOffset;
drawCoords.Rotation = rect.Rotation;
return true;
}
/// <summary>
/// Calculates the texture and world coordinates for drawing (a part of) the texture in the rect
/// </summary>
/// <param name="texture">Texture to draw</param>
/// <param name="rect">Rect to draw in (might stretch the texture)</param>
/// <param name="drawCoords">Struct for the coordinates</param>
/// <param name="mirrored">Mirror on y axis</param>
/// <param name="begin">Position of the texture to begin drawing (0 &lt;=x&lt;=1)</param>
/// <param name="end">Position of the texture to end drawing (0 &lt;=x&lt;=1)</param>
/// <returns>True if anything will be dawn</returns>
protected bool _CalcDrawCoords(TTextureType texture, SRectF rect, out SDrawCoords drawCoords, bool mirrored = false, float begin = 0, float end = 1)
{
drawCoords = new SDrawCoords();
if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1)
return false;
if (begin >= 1 || begin >= end)
return false;
Debug.Assert(begin.IsInRange(0, 1) && end.IsInRange(0, 1));
drawCoords.Tx1 = begin * texture.WidthRatio;
drawCoords.Wx1 = rect.X + begin * rect.W;
drawCoords.Tx2 = end * texture.WidthRatio;
drawCoords.Wx2 = rect.X + end * rect.W;
drawCoords.Ty1 = 0;
drawCoords.Wy1 = rect.Y;
drawCoords.Ty2 = texture.HeightRatio;
drawCoords.Wy2 = rect.Bottom;
if (mirrored)
{
float tmp = drawCoords.Ty1;
drawCoords.Ty1 = drawCoords.Ty2;
drawCoords.Ty2 = tmp;
}
drawCoords.Wz = rect.Z + CGraphics.ZOffset;
drawCoords.Rotation = rect.Rotation;
return true;
}
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false)
{
if (Math.Abs(color.A) < 0.01)
return;
SDrawCoords dc;
TTextureType texture;
if (!_GetTexture(textureRef, out texture))
return;
if (!_CalcDrawCoords(texture, rect, out dc, mirrored))
return;
_DrawTexture(texture, dc, color);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false)
{
if (Math.Abs(color.A) < 0.01)
return;
SDrawCoords dc;
TTextureType texture;
if (!_GetTexture(textureRef, out texture))
return;
if (!_CalcDrawCoords(texture, rect, bounds, out dc))
return;
_DrawTexture(texture, dc, color);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end)
{
if (Math.Abs(color.A) < 0.01)
return;
SDrawCoords dc;
TTextureType texture;
if (!_GetTexture(textureRef, out texture))
return;
if (!_CalcDrawCoords(texture, rect, out dc, false, begin, end))
return;
_DrawTexture(texture, dc, color);
}
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="textureRef">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{
Debug.Assert(height >= 0);
if (Math.Abs(color.A) < 0.01 || height < 1)
return;
SDrawCoords dc;
TTextureType texture;
if (!_GetTexture(textureRef, out texture))
return;
if (!_CalcDrawCoords(texture, rect, bounds, out dc, true))
return;
if (height > rect.H)
height = rect.H;
dc.Wy1 += rect.H + space; // Move from start of rect to end of rect with spacing
dc.Wy2 += space + height; // Move from end of rect
dc.Ty2 += (rect.H - height) / rect.H; // Adjust so not all of the start of the texture is drawn (mirrored--> Ty1>Ty2)
if (dc.Ty2 < dc.Ty1) // Make sure we actually draw something
_DrawTexture(texture, dc, color, true);
}
#endregion drawing
#region private/protected
/// <summary>
/// Returns the maximum area allowed for a texture based on the current quality
@@ -508,11 +712,20 @@ namespace Vocaluxe.Lib.Draw
Debug.Assert(oldTexture != null, "Queued type is wrong");
Debug.Assert(!oldTexture.IsLoaded);
if (oldTexture.RefCount <= 0)
{
Bitmap bmp = q.Data as Bitmap;
if (bmp != null)
bmp.Dispose();
continue;
}
TTextureType texture = null;
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
if (q.Data is Bitmap)
_WriteBitmapToTexture(ref texture, (Bitmap)q.Data);
{
Bitmap bmp = (Bitmap)q.Data;
_WriteBitmapToTexture(ref texture, bmp);
bmp.Dispose();
}
else if (q.Data is byte[])
texture = _CreateAndFillTexture(q.DataSize, (byte[])q.Data);
else
@@ -525,12 +738,21 @@ namespace Vocaluxe.Lib.Draw
CTextureRef textureRef = q.TextureOrRef as CTextureRef;
Debug.Assert(textureRef != null, "Queued type is wrong");
if (!_Textures.ContainsKey(textureRef.ID))
{
Bitmap bmp = q.Data as Bitmap;
if (bmp != null)
bmp.Dispose();
continue;
}
if (q.Action == EQueueAction.Update)
{
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
if (q.Data is Bitmap)
UpdateTexture(textureRef, (Bitmap)q.Data);
{
Bitmap bmp = (Bitmap)q.Data;
UpdateTexture(textureRef, bmp);
bmp.Dispose();
}
else if (q.Data is byte[])
UpdateTexture(textureRef, q.DataSize.Width, q.DataSize.Height, (byte[])q.Data);
else
+1 -1
View File
@@ -435,7 +435,7 @@ namespace Vocaluxe.Lib.Draw
public void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, float begin, float end) {}
public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float space, float height) {}
public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) {}
public int GetTextureCount()
{
+21 -228
View File
@@ -436,61 +436,46 @@ namespace Vocaluxe.Lib.Draw
GL.BindTexture(TextureTarget.Texture2D, 0);
}
#region drawing
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false)
protected override void _DrawTexture(COGLTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
{
COGLTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1 || Math.Abs(color.A) < 0.01)
return;
// Align textures to full pixels to reduce artefacts
dc.Wx1 = (float)Math.Round(dc.Wx1);
dc.Wy1 = (float)Math.Round(dc.Wy1);
dc.Wx2 = (float)Math.Round(dc.Wx2);
dc.Wy2 = (float)Math.Round(dc.Wy2);
GL.BindTexture(TextureTarget.Texture2D, texture.Name);
const float x1 = 0;
float x2 = texture.WidthRatio;
float y1 = 0;
float y2 = texture.HeightRatio;
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y;
float ry2 = rect.Y + rect.H;
GL.Enable(EnableCap.Blend);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.MatrixMode(MatrixMode.Texture);
GL.PushMatrix();
if (Math.Abs(rect.Rotation) > float.Epsilon)
if (Math.Abs(dc.Rotation) > float.Epsilon)
{
GL.Translate(0.5f, 0.5f, 0);
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
GL.Rotate(-dc.Rotation, 0f, 0f, 1f);
GL.Translate(-0.5f, -0.5f, 0);
}
if (mirrored)
{
float tmp = y2;
y2 = y1;
y1 = tmp;
}
GL.Begin(BeginMode.Quads);
GL.TexCoord2(x1, y1);
GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.TexCoord2(dc.Tx1, dc.Ty1);
GL.Vertex3(dc.Wx1, dc.Wy1, dc.Wz);
GL.TexCoord2(x1, y2);
GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
if (isReflection)
GL.Color4(color.R, color.G, color.B, 0);
GL.TexCoord2(dc.Tx1, dc.Ty2);
GL.Vertex3(dc.Wx1, dc.Wy2, dc.Wz);
GL.TexCoord2(x2, y2);
GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(dc.Tx2, dc.Ty2);
GL.Vertex3(dc.Wx2, dc.Wy2, dc.Wz);
GL.TexCoord2(x2, y1);
GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);
if (isReflection)
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.TexCoord2(dc.Tx2, dc.Ty1);
GL.Vertex3(dc.Wx2, dc.Wy1, dc.Wz);
GL.End();
@@ -499,198 +484,6 @@ namespace Vocaluxe.Lib.Draw
GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false)
{
COGLTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1 || Math.Abs(bounds.H) < 1 || Math.Abs(bounds.W) < 1 ||
Math.Abs(color.A) < 0.01)
return;
if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X)
return;
if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y)
return;
GL.BindTexture(TextureTarget.Texture2D, texture.Name);
float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio;
float y1 = (bounds.Y - rect.Y) / rect.H * texture.HeightRatio;
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio;
if (x1 < 0)
x1 = 0f;
if (x2 > texture.WidthRatio)
x2 = texture.WidthRatio;
if (y1 < 0)
y1 = 0f;
if (y2 > texture.HeightRatio)
y2 = texture.HeightRatio;
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y;
float ry2 = rect.Y + rect.H;
if (rx1 < bounds.X)
rx1 = bounds.X;
if (rx2 > bounds.X + bounds.W)
rx2 = bounds.X + bounds.W;
if (ry1 < bounds.Y)
ry1 = bounds.Y;
if (ry2 > bounds.Y + bounds.H)
ry2 = bounds.Y + bounds.H;
GL.Enable(EnableCap.Blend);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.MatrixMode(MatrixMode.Texture);
GL.PushMatrix();
if (Math.Abs(rect.Rotation) > float.Epsilon)
{
GL.Translate(0.5f, 0.5f, 0);
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
GL.Translate(-0.5f, -0.5f, 0);
}
if (mirrored)
{
float tmp = y2;
y2 = y1;
y1 = tmp;
}
GL.Begin(BeginMode.Quads);
GL.TexCoord2(x1, y1);
GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(x1, y2);
GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(x2, y2);
GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(x2, y1);
GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);
GL.End();
GL.PopMatrix();
GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end)
{
COGLTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
GL.BindTexture(TextureTarget.Texture2D, texture.Name);
GL.Enable(EnableCap.Blend);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.Begin(BeginMode.Quads);
GL.TexCoord2(0f + begin * texture.WidthRatio, 0f);
GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(0f + begin * texture.WidthRatio, texture.HeightRatio);
GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(texture.WidthRatio * end, texture.HeightRatio);
GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
GL.TexCoord2(texture.WidthRatio * end, 0f);
GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
GL.End();
GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, float space, float height)
{
COGLTexture texture;
if (!_GetTexture(textureRef, out texture))
return;
if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(color.A) < float.Epsilon || height <= float.Epsilon)
return;
if (height > rect.H)
height = rect.H;
GL.BindTexture(TextureTarget.Texture2D, texture.Name);
const float x1 = 0;
float x2 = texture.WidthRatio;
float y1 = (rect.H - height) / rect.H * texture.HeightRatio;
float y2 = texture.HeightRatio;
float rx1 = rect.X;
float rx2 = rect.X + rect.W;
float ry1 = rect.Y + rect.H + space;
float ry2 = rect.Y + rect.H + space + height;
GL.Enable(EnableCap.Blend);
GL.MatrixMode(MatrixMode.Texture);
GL.PushMatrix();
if (Math.Abs(rect.Rotation) > float.Epsilon)
{
GL.Translate(0.5f, 0.5f, 0);
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
GL.Translate(-0.5f, -0.5f, 0);
}
GL.Begin(BeginMode.Quads);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.TexCoord2(x2, y2);
GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);
GL.Color4(color.R, color.G, color.B, 0f);
GL.TexCoord2(x2, y1);
GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
GL.Color4(color.R, color.G, color.B, 0f);
GL.TexCoord2(x1, y1);
GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
GL.TexCoord2(x1, y2);
GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset);
GL.End();
GL.PopMatrix();
GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
#endregion drawing
#endregion Textures
#endregion implementation
+1 -1
View File
@@ -62,11 +62,11 @@ namespace Vocaluxe.Lib.Draw
private void _CalcRatios()
{
// OpenGL has a problem with partial (NPOT) textures, so we remove 1 pixel
if (_DataSize.Width == W2)
WidthRatio = 1f;
else
{
// OpenGL has a problem with partial (NPOT) textures, so we remove 1 pixel
int mod = 0;
if (_DataSize.Width > 1)
mod = -1;
+1 -1
View File
@@ -56,6 +56,6 @@ namespace Vocaluxe.Lib.Draw
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false);
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, float begin, float end);
void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float space, float height);
void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, float space, float height);
}
}
+3 -1
View File
@@ -142,6 +142,8 @@ namespace Vocaluxe.Screens
private CTextureRef _TexNamePantero;
private CTextureRef _TexNamePinky007;
private static SColorF _BGColor = new SColorF(0, 0.18f, 0.474f, 1);
public override void Init()
{
base.Init();
@@ -360,7 +362,7 @@ namespace Vocaluxe.Screens
base.Draw();
//Draw background
CDraw.DrawRect(new SColorF(0, 0.18f, 0.474f, 1), new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, 0));
CDraw.DrawRect(_BGColor, CSettings.RenderRect);
//Draw stars
_StarsBlue.Draw();
+3 -2
View File
@@ -479,8 +479,9 @@ namespace Vocaluxe.Screens
background = _Background;
if (background != null)
{
var bounds = new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, 0);
CDraw.DrawTexture(background, bounds, aspect, background.Color);
SRectF bounds = CSettings.RenderRect;
SRectF rect = CHelper.FitInBounds(bounds, background.OrigAspect, aspect);
CDraw.DrawTexture(background, rect, background.Color, bounds);
}
else if (_SlideShow != null)
_SlideShow.Draw();
+1 -1
View File
@@ -84,7 +84,7 @@ namespace VocaluxeLib
/// <param name="bounds">Bounds to fit the rect in</param>
/// <param name="aspectRatio">The original aspectRatio of the rect/image/...</param>
/// <param name="aspect">
/// Crop: Fit fully in bounds cutting off overhanging parts (same on both sides)<br />
/// Crop: No empty space in bounds but has overhanging parts (same on both sides)<br />
/// LetterBox: Fit the long side possibly leaving some space on the other (rect will be centered)<br />
/// StretcH: Just fit the rect in the bounds (rect=bounds)
/// </param>
+2 -1
View File
@@ -70,6 +70,7 @@ namespace VocaluxeLib
{
int GetRenderW();
int GetRenderH();
SRectF GetRenderRect();
bool IsTabNavigation();
float GetZFar();
@@ -147,7 +148,7 @@ namespace VocaluxeLib
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false);
void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect);
void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect, SColorF color);
void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight);
void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight);
CTextureRef AddTexture(string fileName);
void RemoveTexture(ref CTextureRef texture);
+3 -1
View File
@@ -221,7 +221,9 @@ namespace VocaluxeLib.Menu
#region internal
private static SRectF _GetDrawRect()
{
return new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), CBase.Settings.GetZFar() / 4);
SRectF rect = CBase.Settings.GetRenderRect();
rect.Z = CBase.Settings.GetZFar() / 4;
return rect;
}
private void _DrawColor()
+3 -3
View File
@@ -264,7 +264,7 @@ namespace VocaluxeLib.Menu
if (_Reflection)
{
CBase.Drawing.DrawTextureReflection(texture, Rect, Color, _ReflectionSpace, _ReflectionHeight);
CBase.Drawing.DrawTextureReflection(texture, Rect, Color, Rect, _ReflectionSpace, _ReflectionHeight);
Text.DrawRelative(Rect.X, Rect.Y, _ReflectionHeight, _ReflectionSpace, Rect.H);
}
else
@@ -278,7 +278,7 @@ namespace VocaluxeLib.Menu
if (_Reflection)
{
CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, _ReflectionSpace, _ReflectionHeight);
CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, _ReflectionSpace, _ReflectionHeight);
Text.DrawRelative(Rect.X, Rect.Y, _ReflectionHeight, _ReflectionSpace, Rect.H);
}
else
@@ -292,7 +292,7 @@ namespace VocaluxeLib.Menu
if (_Reflection)
{
CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, _ReflectionSpace, _ReflectionHeight);
CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, _ReflectionSpace, _ReflectionHeight);
_SelText.DrawRelative(Rect.X, Rect.Y, _ReflectionHeight, _ReflectionSpace, Rect.H);
}
else
+18 -31
View File
@@ -34,37 +34,24 @@ namespace VocaluxeLib.Menu
public string ScreenName;
public int ScreenVersion;
}
[XmlType("Screen")]
public struct STheme
{
[XmlElement("Informations")]
public SScreenInformation ScreenInformation;
[XmlArray("Backgrounds")]
public List<SThemeBackground> Backgrounds;
[XmlArray("Statics")]
public List<SThemeStatic> Statics;
[XmlArray("Texts")]
public List<SThemeText> Texts;
[XmlArray("Buttons")]
public List<SThemeButton> Buttons;
[XmlArray("SongMenus")]
public List<SThemeSongMenu> SongMenus;
[XmlArray("Lyrics")]
public List<SThemeLyrics> Lyrics;
[XmlArray("SelectSlides")]
public List<SThemeSelectSlide> SelectSlides;
[XmlArray("SingNotes")]
public List<SThemeSingBar> SingNotes;
[XmlArray("NameSelections")]
public List<SThemeNameSelection> NameSelections;
[XmlArray("Equalizers")]
public List<SThemeEqualizer> Equalizers;
[XmlArray("Playlists")]
public List<SThemePlaylist> Playlists;
[XmlArray("ParticleEffects")]
public List<SThemeParticleEffect> ParticleEffects;
[XmlArray("ScreenSettings")]
public List<SScreenSetting> ScreenSettings;
[XmlElement("Informations")] public SScreenInformation ScreenInformation;
[XmlArray("Backgrounds")] public List<SThemeBackground> Backgrounds;
[XmlArray("Statics")] public List<SThemeStatic> Statics;
[XmlArray("Texts")] public List<SThemeText> Texts;
[XmlArray("Buttons")] public List<SThemeButton> Buttons;
[XmlArray("SongMenus")] public List<SThemeSongMenu> SongMenus;
[XmlArray("Lyrics")] public List<SThemeLyrics> Lyrics;
[XmlArray("SelectSlides")] public List<SThemeSelectSlide> SelectSlides;
[XmlArray("SingNotes")] public List<SThemeSingBar> SingNotes;
[XmlArray("NameSelections")] public List<SThemeNameSelection> NameSelections;
[XmlArray("Equalizers")] public List<SThemeEqualizer> Equalizers;
[XmlArray("Playlists")] public List<SThemePlaylist> Playlists;
[XmlArray("ParticleEffects")] public List<SThemeParticleEffect> ParticleEffects;
[XmlArray("ScreenSettings")] public List<SScreenSetting> ScreenSettings;
}
struct SZSort
@@ -158,7 +145,7 @@ namespace VocaluxeLib.Menu
_MouseDY = 0;
_Active = false;
_ScreenArea = new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), 0f);
_ScreenArea = CBase.Settings.GetRenderRect();
_ThemeBackgrounds = null;
_ThemeStatics = null;
@@ -250,7 +237,7 @@ namespace VocaluxeLib.Menu
foreach (SThemeParticleEffect pe in Theme.ParticleEffects)
_AddParticleEffect(new CParticleEffect(pe, _PartyModeID), pe.Name);
foreach(SThemePlaylist pl in Theme.Playlists)
foreach (SThemePlaylist pl in Theme.Playlists)
_AddPlaylist(new CPlaylist(pl, _PartyModeID), pl.Name);
foreach (SScreenSetting ss in Theme.ScreenSettings)
@@ -269,7 +256,7 @@ namespace VocaluxeLib.Menu
_AddStatic(new CStatic(st, _PartyModeID), st.Name);
foreach (SThemeText te in Theme.Texts)
_AddText(new CText(te, _PartyModeID), te.Name);
_AddText(new CText(te, _PartyModeID), te.Name);
}
catch (InvalidOperationException e)
{
+1 -1
View File
@@ -69,7 +69,7 @@ namespace VocaluxeLib.Menu
_MouseDY = 0;
Active = false;
_ScreenArea = new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), 0f);
_ScreenArea = CBase.Settings.GetRenderRect();
}
public void Clear()
+5 -7
View File
@@ -176,19 +176,17 @@ namespace VocaluxeLib.Menu
public void Draw(EAspect aspect, float scale = 1f, float zModify = 0f, bool forceDraw = false)
{
CTextureRef texture = Texture;
SRectF rect = Rect.Scale(scale);
rect.Z += zModify;
if (texture != null)
rect = CHelper.FitInBounds(rect, texture.OrigAspect, aspect);
SRectF bounds = Rect.Scale(scale);
bounds.Z += zModify;
SRectF rect = texture == null ? bounds : CHelper.FitInBounds(bounds, texture.OrigAspect, aspect);
var color = new SColorF(Color.R, Color.G, Color.B, Color.A * Alpha);
if (Visible || forceDraw || (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
{
if (texture != null)
{
CBase.Drawing.DrawTexture(texture, rect, color);
CBase.Drawing.DrawTexture(texture, rect, color, bounds);
if (Reflection)
CBase.Drawing.DrawTextureReflection(texture, rect, color, ReflectionSpace, ReflectionHeight);
CBase.Drawing.DrawTextureReflection(texture, rect, color, bounds, ReflectionSpace, ReflectionHeight);
}
else
CBase.Drawing.DrawRect(color, rect);
@@ -200,7 +200,7 @@ namespace VocaluxeLib.Menu.SongMenu
_Tiles.Add(tile);
}
}
_ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), Rect.Z);
_ScrollRect = CBase.Settings.GetRenderRect();
}
public override void Update(SScreenSongOptions songOptions)
@@ -501,9 +501,8 @@ namespace VocaluxeLib.Menu.SongMenu
if (vidtex.Color.A < 1)
_CoverBig.Draw(EAspect.Crop);
SRectF rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(vidtex, rect);
CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
CBase.Drawing.DrawTexture(vidtex, rect, vidtex.Color, _CoverBig.Rect);
CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.Rect, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
}
else
_CoverBig.Draw(EAspect.Crop);