From cdad90a93df1cf6b4d3b52e12a1a0b364e8cae8c Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 13 May 2013 18:56:13 +0200 Subject: [PATCH] Renamed texture members to more appropriate ones --- Vocaluxe/Lib/Draw/CDirect3D.cs | 44 +++++++++---------- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 22 +++++----- Vocaluxe/Lib/Draw/COpenGL.cs | 71 +++++++++++++++---------------- VocaluxeLib/Draw/CTexture.cs | 5 ++- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 9b8bb989..83df21fc 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -678,8 +678,8 @@ namespace Vocaluxe.Lib.Draw backbufferSurface.Dispose(); lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _D3DTextures.Add(texture.Index, tex); + texture.ID = _IDs.Dequeue(); + _D3DTextures.Add(texture.ID, tex); return texture; } @@ -700,7 +700,7 @@ namespace Vocaluxe.Lib.Draw else { Surface backbufferSurface = _Device.GetBackBuffer(0, 0); - Surface textureSurface = _D3DTextures[texture.Index].GetSurfaceLevel(0); + Surface textureSurface = _D3DTextures[texture.ID].GetSurfaceLevel(0); Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0); } } @@ -894,8 +894,8 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _D3DTextures.Add(texture.Index, t); + texture.ID = _IDs.Dequeue(); + _D3DTextures.Add(texture.ID, t); } return texture; } @@ -935,9 +935,9 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _D3DTextures.Add(texture.Index, null); - STextureQueue queue = new STextureQueue(texture.Index, texture.W2, texture.H2, w, h, data); + texture.ID = _IDs.Dequeue(); + _D3DTextures.Add(texture.ID, null); + STextureQueue queue = new STextureQueue(texture.ID, texture.W2, texture.H2, w, h, data); _Queue.Add(queue); } return texture; @@ -965,7 +965,7 @@ namespace Vocaluxe.Lib.Draw return false; lock (_MutexTexture) { - _WriteDataToTexture(_D3DTextures[texture.Index], w, data); + _WriteDataToTexture(_D3DTextures[texture.ID], w, data); } return true; } @@ -990,7 +990,7 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - return texture != null && _D3DTextures.ContainsKey(texture.Index); + return texture != null && _D3DTextures.ContainsKey(texture.ID); } } @@ -1004,9 +1004,9 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - _D3DTextures[texture.Index].Dispose(); - _D3DTextures.Remove(texture.Index); - _IDs.Enqueue(texture.Index); + _D3DTextures[texture.ID].Dispose(); + _D3DTextures.Remove(texture.ID); + _IDs.Enqueue(texture.ID); } } texture = null; @@ -1060,7 +1060,7 @@ namespace Vocaluxe.Lib.Draw { if (!_TextureExists(texture)) return; - if (_D3DTextures[texture.Index] == null) + if (_D3DTextures[texture.ID] == null) return; //Calculate the position @@ -1125,7 +1125,7 @@ namespace Vocaluxe.Lib.Draw 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); + _AddToVertexBuffer(vert, _D3DTextures[texture.ID], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } else { @@ -1134,7 +1134,7 @@ namespace Vocaluxe.Lib.Draw 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); + _AddToVertexBuffer(vert, _D3DTextures[texture.ID], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } } @@ -1150,7 +1150,7 @@ namespace Vocaluxe.Lib.Draw { if (!_TextureExists(texture)) return; - if (_D3DTextures[texture.Index] == null) + if (_D3DTextures[texture.ID] == null) return; float x1 = 0f + begin * texture.WidthRatio; @@ -1178,7 +1178,7 @@ namespace Vocaluxe.Lib.Draw 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); + _AddToVertexBuffer(vert, _D3DTextures[texture.ID], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } /// @@ -1194,7 +1194,7 @@ namespace Vocaluxe.Lib.Draw { if (!_TextureExists(texture)) return; - if (_D3DTextures[texture.Index] == null) + if (_D3DTextures[texture.ID] == null) return; if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || @@ -1261,7 +1261,7 @@ namespace Vocaluxe.Lib.Draw 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); + _AddToVertexBuffer(vert, _D3DTextures[texture.ID], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } #endregion drawing @@ -1274,11 +1274,11 @@ namespace Vocaluxe.Lib.Draw STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); Texture t; - if (_D3DTextures.TryGetValue(q.Index, out t) && t != null) + if (_D3DTextures.TryGetValue(q.ID, out t) && t != null) continue; t = _CreateTexture(q.TextureWidth, q.TextureHeight, q.DataWidth, q.Data); - _D3DTextures[q.Index] = t; + _D3DTextures[q.ID] = t; } } } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index ff52c50d..2f9cda14 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -294,7 +294,7 @@ namespace Vocaluxe.Lib.Draw CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List - _Textures[texture.Index] = texture; + _Textures[texture.ID] = texture; return texture; } @@ -307,7 +307,7 @@ namespace Vocaluxe.Lib.Draw texture = CopyScreen(); } else - _Bitmaps[texture.Index] = new Bitmap(_Backbuffer); + _Bitmaps[texture.ID] = new Bitmap(_Backbuffer); } public void MakeScreenShot() @@ -338,14 +338,14 @@ namespace Vocaluxe.Lib.Draw CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List - _Textures[texture.Index] = texture; + _Textures[texture.ID] = texture; return texture; } private CTexture _GetNewTexture(int w, int h) { - return new CTexture(w, h) {Index = _Bitmaps.Count - 1}; + return new CTexture(w, h) {ID = _Bitmaps.Count - 1}; } public CTexture AddTexture(string texturePath) @@ -369,15 +369,15 @@ namespace Vocaluxe.Lib.Draw private bool _TextureExists(CTexture texture) { - return texture != null && _Textures.ContainsKey(texture.Index); + return texture != null && _Textures.ContainsKey(texture.ID); } public void RemoveTexture(ref CTexture texture) { if (_TextureExists(texture)) { - _Bitmaps[texture.Index].Dispose(); - _Textures.Remove(texture.Index); + _Bitmaps[texture.ID].Dispose(); + _Textures.Remove(texture.ID); } texture = null; } @@ -402,10 +402,10 @@ namespace Vocaluxe.Lib.Draw { if (_TextureExists(texture)) { - BitmapData bmpData = _Bitmaps[texture.Index].LockBits(new Rectangle(0, 0, _Bitmaps[texture.Index].Width, _Bitmaps[texture.Index].Height), - ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); + BitmapData bmpData = _Bitmaps[texture.ID].LockBits(new Rectangle(0, 0, _Bitmaps[texture.ID].Width, _Bitmaps[texture.ID].Height), + ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(data, 0, bmpData.Scan0, data.Length); - _Bitmaps[texture.Index].UnlockBits(bmpData); + _Bitmaps[texture.ID].UnlockBits(bmpData); return true; } return false; @@ -443,7 +443,7 @@ namespace Vocaluxe.Lib.Draw { if (!_TextureExists(texture)) return; - Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color); + Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.ID], color); _G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H)); coloredBitmap.Dispose(); } diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index db0308fd..c46c5f27 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -65,16 +65,16 @@ namespace Vocaluxe.Lib.Draw struct STextureQueue { - public int Index; - public int TextureWidth; - public int TextureHeight; - public int DataWidth; - public int DataHeight; - public byte[] Data; + public readonly int ID; + public readonly int TextureWidth; + public readonly int TextureHeight; + public readonly int DataWidth; + public readonly int DataHeight; + public readonly byte[] Data; - public STextureQueue(int index, int textureWidth, int textureHeight, int dataWidth, int dataHeight, byte[] data) + public STextureQueue(int id, int textureWidth, int textureHeight, int dataWidth, int dataHeight, byte[] data) { - Index = index; + ID = id; TextureWidth = textureWidth; TextureHeight = textureHeight; DataWidth = dataWidth; @@ -502,8 +502,8 @@ namespace Vocaluxe.Lib.Draw { CTexture texture = _GetNewTexture(_W, _H); - texture.ID = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + texture.Name = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, _X, _Y, _W, _H); @@ -517,8 +517,8 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _Textures[texture.Index] = texture; + texture.ID = _IDs.Dequeue(); + _Textures[texture.ID] = texture; } return texture; @@ -534,7 +534,7 @@ namespace Vocaluxe.Lib.Draw } else { - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, GetScreenWidth(), GetScreenHeight()); @@ -709,10 +709,9 @@ namespace Vocaluxe.Lib.Draw w = MathHelper.NextPowerOfTwo(w); h = MathHelper.NextPowerOfTwo(h); - CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true); + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true) {Name = GL.GenTexture()}; - texture.ID = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); Bitmap bmp2 = null; try { @@ -754,8 +753,8 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _Textures[texture.Index] = texture; + texture.ID = _IDs.Dequeue(); + _Textures[texture.ID] = texture; } return texture; @@ -769,8 +768,8 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - _Textures[texture.Index] = texture; + texture.ID = _IDs.Dequeue(); + _Textures[texture.ID] = texture; } return texture; @@ -794,8 +793,8 @@ namespace Vocaluxe.Lib.Draw } } - texture.ID = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + texture.Name = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, data); @@ -815,10 +814,10 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { - texture.Index = _IDs.Dequeue(); - STextureQueue queue = new STextureQueue(texture.Index, texture.W2, texture.H2, w, h, data); + texture.ID = _IDs.Dequeue(); + STextureQueue queue = new STextureQueue(texture.ID, texture.W2, texture.H2, w, h, data); _Queue.Add(queue); - _Textures[texture.Index] = texture; + _Textures[texture.ID] = texture; } return texture; @@ -845,7 +844,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); @@ -857,7 +856,7 @@ namespace Vocaluxe.Lib.Draw return true; } - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, data); @@ -885,11 +884,11 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - _IDs.Enqueue(texture.Index); - GL.DeleteTexture(texture.ID); + _IDs.Enqueue(texture.ID); + GL.DeleteTexture(texture.Name); if (texture.PBO > 0) GL.DeleteBuffers(1, ref texture.PBO); - _Textures.Remove(texture.Index); + _Textures.Remove(texture.ID); } } texture = null; @@ -899,9 +898,9 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - if (texture != null && _Textures.ContainsKey(texture.Index)) + if (texture != null && _Textures.ContainsKey(texture.ID)) { - if (!checkIfLoaded || _Textures[texture.Index].ID > 0) + if (!checkIfLoaded || _Textures[texture.ID].Name > 0) return true; } } @@ -943,7 +942,7 @@ namespace Vocaluxe.Lib.Draw if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) return; - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + 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; @@ -1040,7 +1039,7 @@ namespace Vocaluxe.Lib.Draw { if (!_TextureExists(texture)) return; - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.Enable(EnableCap.Blend); GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); @@ -1085,7 +1084,7 @@ namespace Vocaluxe.Lib.Draw if (height > bounds.H) height = bounds.H; - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + 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; @@ -1177,7 +1176,7 @@ namespace Vocaluxe.Lib.Draw STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); CTexture texture; - if (!_Textures.TryGetValue(q.Index, out texture)) + if (!_Textures.TryGetValue(q.ID, out texture)) continue; _CreateTexture(texture, q.DataWidth, q.DataHeight, q.Data); diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index 841a4c55..7382351f 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -5,9 +5,10 @@ namespace VocaluxeLib.Draw { public class CTexture { - public int Index = -1; - public int PBO; 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 = "";