use display lists in opengl
This commit is contained in:
1 parent
0ea6a9043b
commit
a78b61bbe7
1 file changed
+224
-188
+224
-188
@@ -40,13 +40,14 @@ namespace Vocaluxe.Lib.Draw
|
||||
private bool _fullscreen = false;
|
||||
|
||||
private List<STexture> _Textures;
|
||||
private List<int> _GLList;
|
||||
|
||||
private int h = 1;
|
||||
private int w = 1;
|
||||
private int y = 0;
|
||||
private int x = 0;
|
||||
|
||||
private bool _UsePBO = false;
|
||||
private bool _UsePBO = true;
|
||||
|
||||
#endregion private vars
|
||||
|
||||
@@ -55,6 +56,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
|
||||
|
||||
_Textures = new List<STexture>();
|
||||
_GLList = new List<int>();
|
||||
|
||||
//Check AA Mode
|
||||
CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode);
|
||||
@@ -440,6 +442,12 @@ namespace Vocaluxe.Lib.Draw
|
||||
ClearScreen();
|
||||
|
||||
_Run = _Run && CGraphics.Draw();
|
||||
foreach (int list in _GLList)
|
||||
{
|
||||
GL.CallList(list);
|
||||
}
|
||||
_GLList.Clear();
|
||||
|
||||
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
|
||||
control.SwapBuffers();
|
||||
|
||||
@@ -595,17 +603,24 @@ namespace Vocaluxe.Lib.Draw
|
||||
|
||||
public void DrawColor(SColorF color, SRectF rect)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
|
||||
int list = GL.GenLists(1);
|
||||
_GLList.Add(list);
|
||||
|
||||
GL.Begin(BeginMode.Quads);
|
||||
GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.End();
|
||||
GL.NewList(list, ListMode.Compile);
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
|
||||
|
||||
GL.Disable(EnableCap.Blend);
|
||||
GL.Begin(BeginMode.Quads);
|
||||
GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.End();
|
||||
|
||||
GL.Disable(EnableCap.Blend);
|
||||
}
|
||||
GL.EndList();
|
||||
}
|
||||
|
||||
#endregion Basic Draw Methods
|
||||
@@ -1031,97 +1046,104 @@ namespace Vocaluxe.Lib.Draw
|
||||
|
||||
if (_TextureExists(Texture))
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
|
||||
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
|
||||
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
|
||||
float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio;
|
||||
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;
|
||||
int list = GL.GenLists(1);
|
||||
_GLList.Add(list);
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0f;
|
||||
|
||||
if (x2 > Texture.width_ratio)
|
||||
x2 = Texture.width_ratio;
|
||||
|
||||
if (y1 < 0)
|
||||
y1 = 0f;
|
||||
|
||||
if (y2 > Texture.height_ratio)
|
||||
y2 = Texture.height_ratio;
|
||||
|
||||
|
||||
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 (rect.Rotation != 0f)
|
||||
GL.NewList(list, ListMode.Compile);
|
||||
{
|
||||
GL.Translate(0.5f, 0.5f, 0);
|
||||
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
|
||||
GL.Translate(-0.5f, -0.5f, 0);
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
|
||||
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
|
||||
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
|
||||
float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio;
|
||||
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0f;
|
||||
|
||||
if (x2 > Texture.width_ratio)
|
||||
x2 = Texture.width_ratio;
|
||||
|
||||
if (y1 < 0)
|
||||
y1 = 0f;
|
||||
|
||||
if (y2 > Texture.height_ratio)
|
||||
y2 = Texture.height_ratio;
|
||||
|
||||
|
||||
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 (rect.Rotation != 0f)
|
||||
{
|
||||
GL.Translate(0.5f, 0.5f, 0);
|
||||
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
|
||||
GL.Translate(-0.5f, -0.5f, 0);
|
||||
}
|
||||
|
||||
if (!mirrored)
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.Begin(BeginMode.Quads);
|
||||
|
||||
GL.TexCoord2(x2, y2);
|
||||
GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(x2, y1);
|
||||
GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(x1, y1);
|
||||
GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (!mirrored)
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.Begin(BeginMode.Quads);
|
||||
|
||||
GL.TexCoord2(x2, y2);
|
||||
GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(x2, y1);
|
||||
GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(x1, y1);
|
||||
GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
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);
|
||||
GL.EndList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1129,31 +1151,38 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
if (_TextureExists(Texture))
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
|
||||
int list = GL.GenLists(1);
|
||||
_GLList.Add(list);
|
||||
|
||||
|
||||
GL.Begin(BeginMode.Quads);
|
||||
GL.NewList(list, ListMode.Compile);
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
|
||||
GL.TexCoord2(0f + begin * Texture.width_ratio, 0f);
|
||||
GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
|
||||
|
||||
GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio);
|
||||
GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio);
|
||||
GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
GL.Begin(BeginMode.Quads);
|
||||
|
||||
GL.TexCoord2(Texture.width_ratio * end, 0f);
|
||||
GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
GL.TexCoord2(0f + begin * Texture.width_ratio, 0f);
|
||||
GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.End();
|
||||
|
||||
GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio);
|
||||
GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.Disable(EnableCap.Blend);
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio);
|
||||
GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
|
||||
|
||||
GL.TexCoord2(Texture.width_ratio * 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);
|
||||
}
|
||||
GL.EndList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1173,81 +1202,88 @@ namespace Vocaluxe.Lib.Draw
|
||||
|
||||
if (_TextureExists(Texture))
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
int list = GL.GenLists(1);
|
||||
_GLList.Add(list);
|
||||
|
||||
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
|
||||
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
|
||||
float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio;
|
||||
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0f;
|
||||
|
||||
if (x2 > Texture.width_ratio)
|
||||
x2 = Texture.width_ratio;
|
||||
|
||||
if (y1 < 0)
|
||||
y1 = 0f;
|
||||
|
||||
if (y2 > Texture.height_ratio)
|
||||
y2 = Texture.height_ratio;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (rx1 < bounds.X)
|
||||
rx1 = bounds.X;
|
||||
|
||||
if (rx2 > bounds.X + bounds.W)
|
||||
rx2 = bounds.X + bounds.W;
|
||||
|
||||
if (ry1 < bounds.Y + space)
|
||||
ry1 = bounds.Y + space;
|
||||
|
||||
if (ry2 > bounds.Y + bounds.H + space + height)
|
||||
ry2 = bounds.Y + bounds.H + space + height;
|
||||
|
||||
GL.Enable(EnableCap.Blend);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Texture);
|
||||
GL.PushMatrix();
|
||||
|
||||
if (rect.Rotation != 0f)
|
||||
GL.NewList(list, ListMode.Compile);
|
||||
{
|
||||
GL.Translate(0.5f, 0.5f, 0);
|
||||
GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
|
||||
GL.Translate(-0.5f, -0.5f, 0);
|
||||
GL.BindTexture(TextureTarget.Texture2D, Texture.index);
|
||||
|
||||
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
|
||||
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
|
||||
float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio;
|
||||
float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0f;
|
||||
|
||||
if (x2 > Texture.width_ratio)
|
||||
x2 = Texture.width_ratio;
|
||||
|
||||
if (y1 < 0)
|
||||
y1 = 0f;
|
||||
|
||||
if (y2 > Texture.height_ratio)
|
||||
y2 = Texture.height_ratio;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (rx1 < bounds.X)
|
||||
rx1 = bounds.X;
|
||||
|
||||
if (rx2 > bounds.X + bounds.W)
|
||||
rx2 = bounds.X + bounds.W;
|
||||
|
||||
if (ry1 < bounds.Y + space)
|
||||
ry1 = bounds.Y + space;
|
||||
|
||||
if (ry2 > bounds.Y + bounds.H + space + height)
|
||||
ry2 = bounds.Y + bounds.H + space + height;
|
||||
|
||||
GL.Enable(EnableCap.Blend);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Texture);
|
||||
GL.PushMatrix();
|
||||
|
||||
if (rect.Rotation != 0f)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
GL.EndList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user