From 142a690cc6d94b900642bf7813c7fb1deff8b27b Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 5 May 2013 20:02:28 +0200 Subject: [PATCH] Using null instead of CTexture(-1) for "no texture" --- Vocaluxe/Base/CBackgroundMusic.cs | 4 +- Vocaluxe/Base/CCover.cs | 44 +-- Vocaluxe/Base/CDraw.cs | 6 +- Vocaluxe/Base/CTheme.cs | 6 +- Vocaluxe/Base/CVideo.cs | 21 +- Vocaluxe/Base/CWebcam.cs | 3 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 356 +++++++++--------- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 26 +- Vocaluxe/Lib/Draw/COpenGL.cs | 330 ++++++++-------- Vocaluxe/Lib/Draw/IDraw.cs | 2 +- Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 4 +- Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 4 +- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 4 +- Vocaluxe/Screens/CScreenOptionsVideo.cs | 2 +- Vocaluxe/Screens/CScreenProfiles.cs | 6 +- Vocaluxe/Screens/CScreenScore.cs | 2 +- Vocaluxe/Screens/CScreenSing.cs | 26 +- VocaluxeLib/Draw/CTexture.cs | 29 +- VocaluxeLib/Menu/CButton.cs | 25 +- VocaluxeLib/Menu/CParticle.cs | 18 +- VocaluxeLib/Menu/CSelectSlide.cs | 11 +- VocaluxeLib/Menu/CStatic.cs | 44 +-- VocaluxeLib/Menu/SongMenu/CCategory.cs | 8 +- VocaluxeLib/Menu/SongMenu/CSong.cs | 28 +- .../Menu/SongMenu/CSongMenuFramework.cs | 4 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 3 +- VocaluxeLib/Menu/Structs.cs | 2 +- 27 files changed, 430 insertions(+), 588 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index b898514d..d227c7c0 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -40,7 +40,7 @@ namespace Vocaluxe.Base private static readonly List _PreviousFileNames = new List(); private static int _Video = -1; - private static CTexture _CurrentVideoTexture = new CTexture(-1); + private static CTexture _CurrentVideoTexture; private static readonly Stopwatch _FadeTimer = new Stopwatch(); private static bool _VideoEnabled; @@ -473,7 +473,7 @@ namespace Vocaluxe.Base } return _CurrentVideoTexture; } - return new CTexture(-1); + return null; } private static bool _IsBackgroundFile(CPlaylistElement element) diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index c39928f5..3f69813a 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -31,7 +31,6 @@ namespace Vocaluxe.Base struct SCover { public string Name; - public string Value; public CTexture Texture; } @@ -47,14 +46,10 @@ namespace Vocaluxe.Base private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); private static readonly List _Cover = new List(); private static readonly List _CoverThemes = new List(); - private static CTexture _NoCover = new CTexture(-1); private static readonly Object _MutexCover = new Object(); - public static CTexture NoCover - { - get { return _NoCover; } - } + public static CTexture NoCover { get; private set; } public static void Init() { @@ -100,19 +95,15 @@ namespace Vocaluxe.Base /// public static CTexture Cover(string name) { - CTexture cov = _NoCover; lock (_MutexCover) { foreach (SCover cover in _Cover) { if (cover.Name == name) - { - cov = cover.Texture; - break; - } + return cover.Texture; } } - return cov; + return NoCover; } /// @@ -207,31 +198,30 @@ namespace Vocaluxe.Base List cover = xmlReader.GetValues("Cover"); foreach (string coverName in cover) { - SCover sk = new SCover(); string name; - string value; + string filePath; xmlReader.GetValue("//root/Cover/" + coverName + "/Name", out name, String.Empty); - xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out value, String.Empty); - sk.Name = name; - sk.Value = Path.Combine(coverTheme.Folder, value); - sk.Texture = File.Exists(Path.Combine(CSettings.FolderCover, sk.Value)) - ? CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, value))) : _NoCover; + xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out filePath, String.Empty); + string coverFilePath = Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, filePath)); + if (!File.Exists(coverFilePath)) + continue; + SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(coverFilePath)}; _Cover.Add(sk); if (sk.Name == "NoCover") - _NoCover = sk.Texture; + NoCover = sk.Texture; } } } List files = new List(); - string path = Path.Combine(CSettings.FolderCover, coverTheme.Folder); - files.AddRange(CHelper.ListFiles(path, "*.png", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.bmp", true, true)); + string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder); + files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true)); + files.AddRange(CHelper.ListFiles(coverPath, "*.jpg", true, true)); + files.AddRange(CHelper.ListFiles(coverPath, "*.jpeg", true, true)); + files.AddRange(CHelper.ListFiles(coverPath, "*.bmp", true, true)); foreach (string file in files) @@ -241,11 +231,9 @@ namespace Vocaluxe.Base if (_CoverExists(name)) continue; // ReSharper disable AssignNullToNotNullAttribute - SCover sk = new SCover {Name = name, Value = Path.Combine(coverTheme.Folder, Path.GetFileName(file))}; + SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.GetFileName(file)))}; // ReSharper restore AssignNullToNotNullAttribute - sk.Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, sk.Value)); - _Cover.Add(sk); } } diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 921c772a..6f377402 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -160,9 +160,9 @@ namespace Vocaluxe.Base return _Draw.EnqueueTexture(w, h, data); } - public static bool UpdateTexture(ref CTexture texture, byte[] data) + public static bool UpdateTexture(CTexture texture, byte[] data) { - return _Draw.UpdateTexture(ref texture, data); + return _Draw.UpdateTexture(texture, data); } public static void RemoveTexture(ref CTexture texture) @@ -197,7 +197,7 @@ namespace Vocaluxe.Base public static void DrawTexture(CStatic staticBounds, CTexture texture, EAspect aspect) { - if (texture.OrigSize.Height <= 0) + if (texture == null) return; RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index ac5a5862..5995e024 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -203,7 +203,7 @@ namespace Vocaluxe.Base sk.VideoIndex = CVideo.Load(Path.Combine(_Skins[skinIndex].Path, sk.Value)); CVideo.SetLoop(sk.VideoIndex, true); CVideo.Pause(sk.VideoIndex); - sk.Texture = new CTexture(-1); + sk.Texture = null; _Skins[skinIndex].VideoList[i] = sk; } catch (Exception e) @@ -585,7 +585,7 @@ namespace Vocaluxe.Base int skinIndex = GetSkinIndex(partyModeID); if (skinIndex != -1 && textureName != null && _Skins[skinIndex].SkinList.ContainsKey(textureName)) return _Skins[skinIndex].SkinList[textureName].Texture; - return new CTexture(-1); + return null; } public static string GetSkinFilePath(string skinName, int partyModeID) @@ -627,7 +627,7 @@ namespace Vocaluxe.Base } } } - return new CTexture(-1); + return null; } public static void SkinVideoPause(string videoName, int partyModeID) diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 743d54d2..597a0f22 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -119,7 +119,7 @@ namespace Vocaluxe.Base { private CTexture _VideoTexture; private int _VideoStream; - private readonly Stopwatch _VideoTimer; + private readonly Stopwatch _VideoTimer = new Stopwatch(); private bool _Finished; private bool _Loaded; @@ -133,14 +133,6 @@ namespace Vocaluxe.Base set { CVideo.SetLoop(_VideoStream, value); } } - public CVideoPlayer() - { - _VideoTimer = new Stopwatch(); - _VideoTexture = new CTexture(-1); - _Finished = false; - _Loaded = false; - } - public void Load(string videoName) { _VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1)); @@ -172,14 +164,7 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.Finished(_VideoStream); - CTexture tex = new CTexture(-1); - CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime); - - if (tex.Index > 0) - { - CDraw.RemoveTexture(ref _VideoTexture); - _VideoTexture = tex; - } + CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); } RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect; @@ -191,7 +176,7 @@ namespace Vocaluxe.Base public void PreLoad() { float videoTime = 0f; - while (_VideoTexture.Index == -1 && videoTime < 1f) + while (_VideoTexture == null && videoTime < 1f) { float dummy; CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); diff --git a/Vocaluxe/Base/CWebcam.cs b/Vocaluxe/Base/CWebcam.cs index 677a2e36..6dc5f4fc 100644 --- a/Vocaluxe/Base/CWebcam.cs +++ b/Vocaluxe/Base/CWebcam.cs @@ -49,8 +49,7 @@ namespace Vocaluxe.Base public static bool GetFrame(ref CTexture tex) { - _Webcam.GetFrame(ref tex); - return true; + return _Webcam.GetFrame(ref tex); } public static Bitmap GetBitmap() diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index ce51146d..6d8e5df2 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -679,9 +679,7 @@ namespace Vocaluxe.Lib.Draw /// public CTexture CopyScreen() { - CTexture texture = new CTexture(-1, _W, _H); - texture.W2 = _CheckForNextPowerOf2(_W); - texture.H2 = _CheckForNextPowerOf2(_H); + CTexture texture = new CTexture(-1, _W, _H) {W2 = _CheckForNextPowerOf2(_W), H2 = _CheckForNextPowerOf2(_H)}; Surface backbufferSurface = _Device.GetBackBuffer(0, 0); Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); @@ -705,7 +703,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref CTexture texture) { //Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize - if (!_TextureExists(ref texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) + if (!_TextureExists(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -798,31 +796,31 @@ namespace Vocaluxe.Lib.Draw /// A STexture object containing the added texture public CTexture AddTexture(string texturePath) { - if (File.Exists(texturePath)) + if (!File.Exists(texturePath)) { - Bitmap bmp; - try - { - bmp = new Bitmap(texturePath); - } - catch (Exception) - { - CLog.LogError("Error loading Texture: " + texturePath); - return new CTexture(-1); - } - CTexture s; - try - { - s = AddTexture(bmp); - } - finally - { - bmp.Dispose(); - } - return s; + CLog.LogError("Can't find File: " + texturePath); + return null; } - CLog.LogError("Can't find File: " + texturePath); - return new CTexture(-1); + Bitmap bmp; + try + { + bmp = new Bitmap(texturePath); + } + catch (Exception) + { + CLog.LogError("Error loading Texture: " + texturePath); + return null; + } + CTexture s; + try + { + s = AddTexture(bmp); + } + finally + { + bmp.Dispose(); + } + return s; } /// @@ -833,7 +831,7 @@ namespace Vocaluxe.Lib.Draw public CTexture AddTexture(Bitmap bmp) { if (bmp.Height == 0 || bmp.Width == 0) - return new CTexture(-1); + return null; int maxSize; //Apply the right max size switch (CConfig.TextureQuality) @@ -909,7 +907,7 @@ namespace Vocaluxe.Lib.Draw private CTexture _AddTexture(CTexture texture, int w, byte[] data) { - Texture t = _CreateTexture(ref texture, w, data); + Texture t = _CreateTexture(texture, w, data); lock (_MutexTexture) { @@ -920,7 +918,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - private Texture _CreateTexture(ref CTexture texture, int w, byte[] data) + private Texture _CreateTexture(CTexture texture, int w, byte[] data) { //Create a new texture in the managed pool, which does not need to be recreated on a lost device //because a copy of the texture is hold in the Ram @@ -959,7 +957,7 @@ namespace Vocaluxe.Lib.Draw { _D3DTextures.Add(_IDs.Peek(), null); texture.Index = _IDs.Dequeue(); - queue.ID = texture.Index; + queue.Index = texture.Index; _Queue.Add(queue); _Textures[texture.Index] = texture; } @@ -974,26 +972,24 @@ namespace Vocaluxe.Lib.Draw /// The texture to update /// A byte array containing the new texture's data /// True if succeeded - public bool UpdateTexture(ref CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, byte[] data) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && _TextureExists(ref texture)) + if (!_TextureExists(texture)) + return false; + lock (_MutexTexture) { - lock (_MutexTexture) + DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); + int w = texture.OrigSize.Width; + int rowWidth = 4 * texture.W2; + for (int i = 0; i + rowWidth <= data.Length; i += 4 * w) { - DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); - int w = texture.OrigSize.Width; - int rowWidth = 4 * texture.W2; - for (int i = 0; i + rowWidth <= data.Length; i += 4 * w) - { - rect.Data.Write(data, i, 4 * w); - rect.Data.Position = rect.Data.Position - rowWidth; - rect.Data.Position += rect.Pitch; - } - _D3DTextures[texture.Index].UnlockRectangle(0); + rect.Data.Write(data, i, 4 * w); + rect.Data.Position = rect.Data.Position - rowWidth; + rect.Data.Position += rect.Pitch; } - return true; + _D3DTextures[texture.Index].UnlockRectangle(0); } - return false; + return true; } #endregion updating @@ -1002,17 +998,14 @@ namespace Vocaluxe.Lib.Draw /// /// The texture to check /// True if the texture exists - private bool _TextureExists(ref CTexture texture) + private bool _TextureExists(CTexture texture) { lock (_MutexTexture) { - if (_Textures.ContainsKey(texture.Index)) + if (texture != null && _Textures.ContainsKey(texture.Index)) { - if (_Textures[texture.Index].Index >= 0) - { - texture = _Textures[texture.Index]; + if (_Textures[texture.Index].ID > 0) return true; - } } } return false; @@ -1024,18 +1017,17 @@ namespace Vocaluxe.Lib.Draw /// The texture to be removed public void RemoveTexture(ref CTexture texture) { - lock (_MutexTexture) + if (texture != null && texture.Index >= 0) { - if ((texture.Index >= 0) && (_Textures.Count > 0)) + lock (_MutexTexture) { _D3DTextures[texture.Index].Dispose(); _D3DTextures.Remove(texture.Index); _Textures.Remove(texture.Index); _IDs.Enqueue(texture.Index); - texture.Index = -1; - texture.ID = -1; } } + texture = null; } #region drawing @@ -1045,6 +1037,8 @@ namespace Vocaluxe.Lib.Draw /// The texture to be drawn public void DrawTexture(CTexture texture) { + if (texture == null) + return; DrawTexture(texture, texture.Rect, texture.Color); } @@ -1055,6 +1049,8 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing the destination coordinates public void DrawTexture(CTexture texture, SRectF rect) { + if (texture == null) + return; DrawTexture(texture, rect, texture.Color); } @@ -1080,84 +1076,83 @@ namespace Vocaluxe.Lib.Draw /// True if the texture should be mirrored public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { - if (_TextureExists(ref texture)) + if (!_TextureExists(texture)) + return; + if (_D3DTextures[texture.Index] == null) + 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; + + //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; + + if (color.A > 1) + color.A = 1; + if (color.R > 1) + color.R = 1; + if (color.G > 1) + color.G = 1; + if (color.B > 1) + color.B = 1; + + Color c = color.AsColor(); + + if (!mirrored) { - if (_D3DTextures[texture.Index] == null) - 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; - - //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; - - if (color.A > 1) - color.A = 1; - if (color.R > 1) - color.R = 1; - if (color.G > 1) - color.G = 1; - if (color.B > 1) - color.B = 1; - - Color c = color.AsColor(); - - if (!mirrored) - { - STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); - } - else - { - STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); - } + STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); + } + else + { + STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } } @@ -1171,7 +1166,7 @@ namespace Vocaluxe.Lib.Draw /// A Value ranging from 0 to 1 containing the ending of the texture public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) { - if (!_TextureExists(ref texture)) + if (!_TextureExists(texture)) return; if (_D3DTextures[texture.Index] == null) return; @@ -1215,7 +1210,7 @@ namespace Vocaluxe.Lib.Draw /// The height of the reflection public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { - if (!_TextureExists(ref texture)) + if (!_TextureExists(texture)) return; if (_D3DTextures[texture.Index] == null) return; @@ -1233,61 +1228,58 @@ namespace Vocaluxe.Lib.Draw if (height > bounds.H) height = bounds.H; - if (_TextureExists(ref texture)) - { - 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 - height) / rect.H * texture.HeightRatio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; + 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 - height) / rect.H * texture.HeightRatio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; - if (x1 < 0) - x1 = 0f; + if (x1 < 0) + x1 = 0f; - if (x2 > texture.WidthRatio) - x2 = texture.WidthRatio; + if (x2 > texture.WidthRatio) + x2 = texture.WidthRatio; - if (y1 < 0) - y1 = 0f; + if (y1 < 0) + y1 = 0f; - if (y2 > texture.HeightRatio) - y2 = texture.HeightRatio; + if (y2 > texture.HeightRatio) + 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; + 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 (rx1 < bounds.X) + rx1 = bounds.X; - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.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; + //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(); + color.A *= CGraphics.GlobalAlpha; + Color c = color.AsColor(); + color.A = 0; + Color transparent = color.AsColor(); - STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); - } + STexturedColoredVertex[] 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, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } #endregion drawing @@ -1299,17 +1291,15 @@ namespace Vocaluxe.Lib.Draw { STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); - if (!_Textures.ContainsKey(q.ID)) + CTexture texture; + if (!_Textures.TryGetValue(q.Index, out texture)) continue; - CTexture texture = _Textures[q.ID]; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) { texture.W2 = _CheckForNextPowerOf2(texture.OrigSize.Width); texture.H2 = _CheckForNextPowerOf2(texture.OrigSize.Height); - Texture t = _CreateTexture(ref texture, q.Width, q.Data); - _D3DTextures[q.ID] = t; - - _Textures[texture.Index] = texture; + Texture t = _CreateTexture(texture, q.Width, q.Data); + _D3DTextures[q.Index] = t; } else CLog.LogError("Wrong texture size in queue!"); diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index ab765c21..065170d3 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -350,33 +350,26 @@ namespace Vocaluxe.Lib.Draw public CTexture AddTexture(string texturePath) { - CTexture texture = new CTexture(); if (File.Exists(texturePath)) { - bool found = false; foreach (CTexture tex in _Textures) { if (tex.TexturePath == texturePath) - { - texture = tex; - found = true; - break; - } + return tex; } - - if (!found) + using (Bitmap bmp = new Bitmap(texturePath)) { - using (Bitmap bmp = new Bitmap(texturePath)) - return AddTexture(bmp); + CTexture texture = AddTexture(bmp); + texture.TexturePath = texturePath; } } - return texture; + return null; } public void RemoveTexture(ref CTexture texture) { - if ((texture.Index >= 0) && (_Textures.Count > 0)) + if (texture != null && texture.Index >= 0) { for (int i = 0; i < _Textures.Count; i++) { @@ -384,11 +377,11 @@ namespace Vocaluxe.Lib.Draw { _Bitmaps[texture.Index].Dispose(); _Textures.RemoveAt(i); - texture.Index = -1; break; } } } + texture = null; } public CTexture EnqueueTexture(int w, int h, byte[] data) @@ -407,7 +400,7 @@ namespace Vocaluxe.Lib.Draw } } - public bool UpdateTexture(ref CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, byte[] data) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) { @@ -415,8 +408,9 @@ namespace Vocaluxe.Lib.Draw ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(data, 0, bmpData.Scan0, data.Length); _Bitmaps[texture.Index].UnlockBits(bmpData); + return true; } - return true; + return false; } public void DrawTexture(CTexture texture) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index f460d4fa..f3aa39b4 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -65,7 +65,7 @@ namespace Vocaluxe.Lib.Draw struct STextureQueue { - public int ID; + public int Index; public int Width; public int Height; public byte[] Data; @@ -522,7 +522,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref CTexture texture) { //Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize - if (!_TextureExists(ref texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) + if (!_TextureExists(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -646,35 +646,35 @@ namespace Vocaluxe.Lib.Draw #region adding public CTexture AddTexture(string texturePath) { - if (File.Exists(texturePath)) + if (!File.Exists(texturePath)) { - Bitmap bmp; - try - { - bmp = new Bitmap(texturePath); - } - catch (Exception) - { - CLog.LogError("Error loading Texture: " + texturePath); - return new CTexture(-1); - } - try - { - return AddTexture(bmp); - } - finally - { - bmp.Dispose(); - } + CLog.LogError("Can't find File: " + texturePath); + return null; + } + Bitmap bmp; + try + { + bmp = new Bitmap(texturePath); + } + catch (Exception) + { + CLog.LogError("Error loading Texture: " + texturePath); + return null; + } + try + { + return AddTexture(bmp); + } + finally + { + bmp.Dispose(); } - CLog.LogError("Can't find File: " + texturePath); - return new CTexture(-1); } public CTexture AddTexture(Bitmap bmp) { if (bmp.Height == 0 || bmp.Width == 0) - return new CTexture(-1); + return null; int maxSize; switch (CConfig.TextureQuality) @@ -766,7 +766,7 @@ namespace Vocaluxe.Lib.Draw { CTexture texture = new CTexture(-1, w, h); - _CreateTexture(data, ref texture); + _CreateTexture(texture, data); lock (_MutexTexture) { @@ -777,7 +777,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - private void _CreateTexture(byte[] data, ref CTexture texture) + private void _CreateTexture(CTexture texture, byte[] data) { int w = texture.OrigSize.Width; int h = texture.OrigSize.Height; @@ -831,7 +831,7 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { texture.Index = _IDs.Dequeue(); - queue.ID = texture.Index; + queue.Index = texture.Index; _Queue.Add(queue); _Textures[texture.Index] = texture; } @@ -841,51 +841,49 @@ namespace Vocaluxe.Lib.Draw #endregion adding #region updating - public bool UpdateTexture(ref CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, byte[] data) { - if (_TextureExists(ref texture)) + if (!_TextureExists(texture)) + return false; + if (_UsePBO) { - if (_UsePBO) - { - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); - IntPtr buffer = GL.MapBuffer(BufferTarget.PixelUnpackBuffer, BufferAccess.WriteOnly); - Marshal.Copy(data, 0, buffer, data.Length); + IntPtr buffer = GL.MapBuffer(BufferTarget.PixelUnpackBuffer, BufferAccess.WriteOnly); + Marshal.Copy(data, 0, buffer, data.Length); - GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); - - GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - - GL.BindTexture(TextureTarget.Texture2D, 0); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); - - return true; - } + GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); - - //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); - //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); - - //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); - //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); - //GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); return true; } - return false; + + GL.BindTexture(TextureTarget.Texture2D, texture.ID); + + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); + + //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); + //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + + //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); + //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); + //GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); + GL.BindTexture(TextureTarget.Texture2D, 0); + + return true; } #endregion updating public void RemoveTexture(ref CTexture texture) { - if ((texture.Index > 0) && (_Textures.Count > 0)) + if (texture != null && texture.Index > 0) { lock (_MutexTexture) { @@ -894,23 +892,19 @@ namespace Vocaluxe.Lib.Draw if (texture.PBO > 0) GL.DeleteBuffers(1, ref texture.PBO); _Textures.Remove(texture.Index); - texture.Index = -1; - texture.ID = -1; } } + texture = null; } - private bool _TextureExists(ref CTexture texture) + private bool _TextureExists(CTexture texture) { lock (_MutexTexture) { - if (_Textures.ContainsKey(texture.Index)) + if (texture != null && _Textures.ContainsKey(texture.Index)) { if (_Textures[texture.Index].ID > 0) - { - texture = _Textures[texture.Index]; return true; - } } } return false; @@ -919,11 +913,15 @@ namespace Vocaluxe.Lib.Draw #region drawing public void DrawTexture(CTexture texture) { + if (texture == null) + return; DrawTexture(texture, texture.Rect, texture.Color); } public void DrawTexture(CTexture texture, SRectF rect) { + if (texture == null) + return; DrawTexture(texture, rect, texture.Color); } @@ -934,6 +932,9 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { + if (!_TextureExists(texture)) + 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 || Math.Abs(color.A) < float.Epsilon) return; @@ -944,9 +945,6 @@ namespace Vocaluxe.Lib.Draw if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) return; - if (!_TextureExists(ref texture)) - return; - GL.BindTexture(TextureTarget.Texture2D, texture.ID); float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; @@ -1042,38 +1040,40 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) { - if (_TextureExists(ref texture)) - { - GL.BindTexture(TextureTarget.Texture2D, texture.ID); + if (!_TextureExists(texture)) + return; + GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.Begin(BeginMode.Quads); + 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, 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(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, 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.TexCoord2(texture.WidthRatio * end, 0f); + GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.End(); + GL.End(); - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); - } + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { + if (!_TextureExists(texture)) + 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 || Math.Abs(color.A) < float.Epsilon || height <= float.Epsilon) return; @@ -1087,84 +1087,81 @@ namespace Vocaluxe.Lib.Draw if (height > bounds.H) height = bounds.H; - if (_TextureExists(ref texture)) + GL.BindTexture(TextureTarget.Texture2D, texture.ID); + + 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 - height) / 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 + 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 (Math.Abs(rect.Rotation) > float.Epsilon) { - GL.BindTexture(TextureTarget.Texture2D, texture.ID); - - 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 - height) / 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 + 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 (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); + 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 @@ -1181,19 +1178,12 @@ namespace Vocaluxe.Lib.Draw { STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); - CTexture texture = new CTexture(-1); - if (_Textures.ContainsKey(q.ID)) - texture = _Textures[q.ID]; - - if (texture.Index < 1) + CTexture texture; + if (!_Textures.TryGetValue(q.Index, out texture)) continue; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) - { - _CreateTexture(q.Data, ref texture); - - _Textures[texture.Index] = texture; - } + _CreateTexture(texture, q.Data); else CLog.LogError("Wrong texture size in queue!"); } diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index b5066667..9c8f2dd3 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -43,7 +43,7 @@ namespace Vocaluxe.Lib.Draw CTexture AddTexture(Bitmap bitmap); CTexture AddTexture(int w, int h, byte[] data); CTexture EnqueueTexture(int w, int h, byte[] data); - bool UpdateTexture(ref CTexture texture, byte[] data); + bool UpdateTexture(CTexture texture, byte[] data); void RemoveTexture(ref CTexture texture); // Basic Draw Methods diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index 7203b015..cef73875 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -662,13 +662,13 @@ namespace Vocaluxe.Lib.Video if (num >= 0) { - if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) + if (frame == null || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _FrameBuffer[num].Data); } else - CDraw.UpdateTexture(ref frame, _FrameBuffer[num].Data); + CDraw.UpdateTexture(frame, _FrameBuffer[num].Data); lock (_MutexSyncSignals) { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 5d9def8b..7bf76966 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -122,13 +122,13 @@ namespace Vocaluxe.Lib.Video { if (data == null) return; - if (frame.Index == -1 || width != frame.OrigSize.Width || height != frame.OrigSize.Height || data.Length == 0) + if (frame == null || width != frame.OrigSize.Width || height != frame.OrigSize.Height || data.Length == 0) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(width, height, data); } else - CDraw.UpdateTexture(ref frame, data); + CDraw.UpdateTexture(frame, data); data = null; } } diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 20530dae..5655707a 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -57,13 +57,13 @@ namespace Vocaluxe.Lib.Webcam { lock (_MutexData) { - if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) + if (frame == null || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _Data); } else - CDraw.UpdateTexture(ref frame, _Data); + CDraw.UpdateTexture(frame, _Data); } } return false; diff --git a/Vocaluxe/Screens/CScreenOptionsVideo.cs b/Vocaluxe/Screens/CScreenOptionsVideo.cs index 6bbcee44..d0f25a5b 100644 --- a/Vocaluxe/Screens/CScreenOptionsVideo.cs +++ b/Vocaluxe/Screens/CScreenOptionsVideo.cs @@ -46,7 +46,7 @@ namespace Vocaluxe.Screens private const string _ButtonExit = "ButtonExit"; private SWebcamConfig _Config; - private CTexture _WebcamTexture = new CTexture(-1); + private CTexture _WebcamTexture; private int _DeviceNr; private int _CapabilityNr; diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index c666ee16..718583d0 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -61,7 +61,7 @@ namespace Vocaluxe.Screens private EEditMode _EditMode; - private CTexture _WebcamTexture = new CTexture(-1); + private CTexture _WebcamTexture; private Bitmap _Snapshot; public override void Init() @@ -210,7 +210,7 @@ namespace Vocaluxe.Screens { CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, _SelectSlides[_SelectSlideAvatars].Selection); - if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) + if (CWebcam.IsDeviceAvailable() && _WebcamTexture != null) _OnDiscardSnapshot(); } else if (_SelectSlides[_SelectSlideGuestProfile].Selected) @@ -311,7 +311,7 @@ namespace Vocaluxe.Screens int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); _SelectSlides[_SelectSlideAvatars].Selection = avatarNr; - if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) + if (CWebcam.IsDeviceAvailable() && _WebcamTexture != null) { if (_Snapshot == null) CWebcam.GetFrame(ref _WebcamTexture); diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 8c2ad2f9..b1869a6c 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -368,7 +368,7 @@ namespace Vocaluxe.Screens _Statics[_StaticPointsBarBG[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; _Statics[_StaticAvatar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - _Statics[_StaticAvatar[player, numplayer]].Texture = new CTexture(-1); + _Statics[_StaticAvatar[player, numplayer]].Texture = null; } } } diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 1f018cfc..3ce4ddff 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -97,9 +97,9 @@ namespace Vocaluxe.Screens private const float _Volume = 100f; private int _CurrentVideo = -1; private EAspect _VideoAspect = EAspect.Crop; - private CTexture _CurrentVideoTexture = new CTexture(-1); - private CTexture _CurrentWebcamFrameTexture = new CTexture(-1); - private CTexture _Background = new CTexture(-1); + private CTexture _CurrentVideoTexture; + private CTexture _CurrentWebcamFrameTexture; + private CTexture _Background; private float _CurrentTime; private float _FinishTime; @@ -412,8 +412,8 @@ namespace Vocaluxe.Screens _FadeOut = false; _CurrentVideo = -1; - _CurrentVideoTexture = new CTexture(-1); - _CurrentWebcamFrameTexture = new CTexture(-1); + _CurrentVideoTexture = null; + _CurrentWebcamFrameTexture = null; _CurrentBeat = -100; _CurrentTime = 0f; _FinishTime = 0f; @@ -468,12 +468,14 @@ namespace Vocaluxe.Screens } else background = _Background; - RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); - RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)background.OrigAspect, aspect); - - CDraw.DrawTexture(_Background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), - _Background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); + if (background != null) + { + RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); + RectangleF rect; + CHelper.SetRect(bounds, out rect, background.OrigAspect, aspect); + CDraw.DrawTexture(background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), + background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); + } } _DrawBG(); @@ -1354,7 +1356,7 @@ namespace Vocaluxe.Screens foreach (CLine line in voice.Lines.Where(line => line.VisibleInTimeLine)) { STimeRect trect = new STimeRect {StartBeat = line.FirstNoteBeat, EndBeat = line.EndBeat}; - trect.Rect = GetNewStatic(new CTexture(-1), + trect.Rect = GetNewStatic(null, new SColorF(1f, 1f, 1f, 1f), new SRectF( stat.Rect.X + stat.Rect.W * ((CGame.GetTimeFromBeats(trect.StartBeat, song.BPM) + song.Gap - song.Start) / totalTime), diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index f987ec8b..a6c48222 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -6,11 +6,11 @@ namespace VocaluxeLib.Draw { public class CTexture { - public int Index; + public int Index = -1; public int PBO; - public int ID; + public int ID = -1; - public string TexturePath; + public string TexturePath = ""; /// /// Original size (e.g. of bmp) @@ -26,10 +26,9 @@ namespace VocaluxeLib.Draw /// public SRectF Rect; - public SColorF Color; + public SColorF Color = new SColorF(1f, 1f, 1f, 1f); private int _W2, _H2; - private float _WidthRatio, _HeightRatio; private bool _UseFullTexture; /// /// Internal texture width (on device), a power of 2 if necessary @@ -61,19 +60,11 @@ namespace VocaluxeLib.Draw /// /// Internal use. Specifies which part of texture memory is actually used /// - public float WidthRatio - { - get { return _WidthRatio; } - private set { _WidthRatio = value; } - } + public float WidthRatio { get; private set; } /// /// Internal use. Specifies which part of texture memory is actually used /// - public float HeightRatio - { - get { return _HeightRatio; } - private set { _HeightRatio = value; } - } + public float HeightRatio { get; private set; } /// /// Internal use. Specifies if full texture memory should be used @@ -101,20 +92,12 @@ namespace VocaluxeLib.Draw public CTexture(int index, int origWidth = 1, int origHeight = 1) { Index = index; - PBO = 0; - ID = -1; - TexturePath = String.Empty; OrigSize = new Size(origWidth, origHeight); Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); - Color = new SColorF(1f, 1f, 1f, 1f); - _W2 = origWidth; _H2 = origHeight; - _WidthRatio = 1; - _HeightRatio = 1; - _UseFullTexture = false; } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index 0ac3edca..3507e0fa 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -80,8 +80,8 @@ namespace VocaluxeLib.Menu Text.Selected = value; } } - public bool Visible; - public bool Enabled; + public bool Visible = true; + public bool Enabled = true; public string GetThemeName() { @@ -91,28 +91,10 @@ namespace VocaluxeLib.Menu public CButton(int partyModeID) { _PartyModeID = partyModeID; - _Theme = new SThemeButton(); - Rect = new SRectF(); - Color = new SColorF(); - SelColor = new SColorF(); - Texture = new CTexture(-1); - SelTexture = new CTexture(-1); - - _IsSelText = false; Text = new CText(_PartyModeID); _SelText = new CText(_PartyModeID); Selected = false; - Visible = true; EditMode = false; - Enabled = true; - - _Reflection = false; - _ReflectionSpace = 0f; - _ReflectionHeight = 0f; - - _SelReflection = false; - _SelReflectionSpace = 0f; - _SelReflectionHeight = 0f; } public CButton(CButton button) @@ -132,13 +114,10 @@ namespace VocaluxeLib.Menu Texture = button.Texture; SelTexture = button.SelTexture; - _IsSelText = false; Text = new CText(button.Text); _SelText = new CText(button._SelText); Selected = false; - Visible = true; EditMode = false; - _ThemeLoaded = false; Enabled = button.Enabled; _Reflection = button._Reflection; diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index 928e624e..0f2fb800 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -50,7 +50,7 @@ namespace VocaluxeLib.Menu private SRectF _Rect; private float _Size; private SColorF _Color; - private float _Alpha; + private float _Alpha = 1; private float _Angle; //0..360° private readonly float _MaxAge; //[s] private float _Age; //[s] @@ -62,7 +62,7 @@ namespace VocaluxeLib.Menu private float _LastTime; private readonly EParticleType _Type; - private readonly Stopwatch _Timer; + private readonly Stopwatch _Timer = new Stopwatch(); #endregion private vars #region public vars @@ -116,21 +116,15 @@ namespace VocaluxeLib.Menu { _PartyModeID = partyModeID; _TextureName = textureName; - _Texture = new CTexture(-1); _Color = color; _Rect = new SRectF(x, y, size, size, z); _Size = size; - _Alpha = 1f; - _Angle = 0f; _Vx = vx; _Vy = vy; _Vr = vr; _Vsize = vsize; - _LastTime = 0f; _Type = type; - _Timer = new Stopwatch(); - _Age = 0f; _MaxAge = maxage; _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); } @@ -144,17 +138,12 @@ namespace VocaluxeLib.Menu _Color = color; _Rect = new SRectF(x, y, size, size, z); _Size = size; - _Alpha = 1f; - _Angle = 0f; _Vx = vx; _Vy = vy; _Vr = vr; _Vsize = vsize; - _LastTime = 0f; _Type = type; - _Timer = new Stopwatch(); - _Age = 0f; _MaxAge = maxage; _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); } @@ -357,7 +346,6 @@ namespace VocaluxeLib.Menu Rect = rect; Color = color; _Theme.TextureName = textureName; - Texture = new CTexture(-1); _MaxNumber = maxNumber; _Size = size; _Type = type; @@ -603,7 +591,7 @@ namespace VocaluxeLib.Menu public void UnloadTextures() { - Texture = new CTexture(); + Texture = null; } public void LoadTextures() diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 1269aaeb..28947a5c 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -531,7 +531,7 @@ namespace VocaluxeLib.Menu public void AddValue(string value, int partyModeID) { - AddValue(value, new CTexture(-1), _ValueIndexes.Count, partyModeID); + AddValue(value, null, _ValueIndexes.Count, partyModeID); } public void AddValue(string value, CTexture texture) @@ -560,7 +560,7 @@ namespace VocaluxeLib.Menu public void AddValues(IEnumerable values) { foreach (string value in values) - _AddValue(value, new CTexture(-1), _PartyModeID); + _AddValue(value, null, _PartyModeID); _ValueBounds.Clear(); } @@ -589,12 +589,7 @@ namespace VocaluxeLib.Menu RenameValue(Selection, newName); } - public void RenameValue(int selection, string newName) - { - RenameValue(selection, newName, new CTexture(-1)); - } - - public void RenameValue(int selection, string newName, CTexture newTexture) + public void RenameValue(int selection, string newName, CTexture newTexture = null) { if (selection < 0 && selection >= _ValueNames.Count) return; diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 5ad19529..d995021e 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -46,7 +46,7 @@ namespace VocaluxeLib.Menu private CTexture _Texture; public CTexture Texture { - get { return _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } + get { return _Texture?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } set { _Texture = value; } } @@ -59,35 +59,20 @@ namespace VocaluxeLib.Menu public float ReflectionHeight; public bool Selected; - public bool Visible; + public bool Visible=true; - public float Alpha; + public float Alpha=1; public EAspect Aspect = EAspect.Stretch; public CStatic(int partyModeID) { _PartyModeID = partyModeID; - _Theme = new SThemeStatic(); - _ThemeLoaded = false; - - _Texture = new CTexture(-1); - Color = new SColorF(); - Rect = new SRectF(); - Reflection = false; - ReflectionSpace = 0f; - ReflectionHeight = 0f; - - Selected = false; - Alpha = 1f; - Visible = true; } public CStatic(CStatic s) { _PartyModeID = s._PartyModeID; - _Theme = new SThemeStatic(); - _ThemeLoaded = false; _Texture = s.Texture; Color = new SColorF(s.Color); @@ -104,37 +89,18 @@ namespace VocaluxeLib.Menu public CStatic(int partyModeID, CTexture texture, SColorF color, SRectF rect) { _PartyModeID = partyModeID; - _Theme = new SThemeStatic(); - _ThemeLoaded = false; _Texture = texture; Color = color; Rect = rect; - Reflection = false; - ReflectionSpace = 0f; - ReflectionHeight = 0f; - - Selected = false; - Alpha = 1f; - Visible = true; } public CStatic(int partyModeID, string textureSkinName, SColorF color, SRectF rect) { _PartyModeID = partyModeID; - _Theme = new SThemeStatic {TextureName = textureSkinName}; - _ThemeLoaded = false; - - _Texture = new CTexture(-1); + _Theme.TextureName = textureSkinName; Color = color; Rect = rect; - Reflection = false; - ReflectionSpace = 0f; - ReflectionHeight = 0f; - - Selected = false; - Alpha = 1f; - Visible = true; } public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) @@ -239,7 +205,7 @@ namespace VocaluxeLib.Menu public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false) { - CTexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + CTexture texture = Texture; SRectF bounds = new SRectF( Rect.X - Rect.W * (scale - 1f), diff --git a/VocaluxeLib/Menu/SongMenu/CCategory.cs b/VocaluxeLib/Menu/SongMenu/CCategory.cs index 299f2adf..f107481f 100644 --- a/VocaluxeLib/Menu/SongMenu/CCategory.cs +++ b/VocaluxeLib/Menu/SongMenu/CCategory.cs @@ -25,9 +25,8 @@ namespace VocaluxeLib.Menu.SongMenu public class CCategory { public readonly string Name; - private CTexture _CoverTextureSmall = new CTexture(-1); - private CTexture _CoverTextureBig = new CTexture(-1); - private bool _CoverBigLoaded; + private CTexture _CoverTextureSmall; + private CTexture _CoverTextureBig; public readonly List Songs = new List(); public CCategory(string name) @@ -44,13 +43,12 @@ namespace VocaluxeLib.Menu.SongMenu public CTexture CoverTextureBig { - get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } + get { return _CoverTextureBig ?? _CoverTextureSmall; } set { if (value.Index == -1) return; _CoverTextureBig = value; - _CoverBigLoaded = true; } } diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index dc01c3f6..b6442725 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -70,10 +70,8 @@ namespace VocaluxeLib.Menu.SongMenu public class CSong { - private bool _CoverSmallLoaded; - private bool _CoverBigLoaded; - private CTexture _CoverTextureSmall = new CTexture(-1); - private CTexture _CoverTextureBig = new CTexture(-1); + private CTexture _CoverTextureSmall; + private CTexture _CoverTextureBig; public SMedley Medley; @@ -101,26 +99,18 @@ namespace VocaluxeLib.Menu.SongMenu { get { - if (!_CoverSmallLoaded) + if (_CoverTextureSmall == null) LoadSmallCover(); return _CoverTextureSmall; } - set - { - _CoverTextureSmall = value; - _CoverSmallLoaded = true; - } + set { _CoverTextureSmall = value; } } public CTexture CoverTextureBig { - get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } - set - { - _CoverTextureBig = value; - _CoverBigLoaded = true; - } + get { return _CoverTextureBig ?? _CoverTextureSmall; } + set { _CoverTextureBig = value; } } public string Title = String.Empty; @@ -215,8 +205,6 @@ namespace VocaluxeLib.Menu.SongMenu VideoFileName = song.VideoFileName; VideoAspect = song.VideoAspect; - _CoverSmallLoaded = song._CoverSmallLoaded; - _CoverBigLoaded = song._CoverBigLoaded; NotesLoaded = song.NotesLoaded; Artist = song.Artist; @@ -751,7 +739,7 @@ namespace VocaluxeLib.Menu.SongMenu public void LoadSmallCover() { - if (_CoverSmallLoaded) + if (_CoverTextureSmall != null) return; if (CoverFileName != "") { @@ -760,8 +748,6 @@ namespace VocaluxeLib.Menu.SongMenu } else _CoverTextureSmall = CBase.Cover.GetNoCover(); - - _CoverSmallLoaded = true; } private void _CheckFiles() diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 3621c14c..5b073b48 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -105,7 +105,7 @@ namespace VocaluxeLib.Menu.SongMenu private readonly List _Streams = new List(); private int _Actsong = -1; private int _Actsongstream = -1; - protected CTexture _Vidtex = new CTexture(-1); + protected CTexture _Vidtex; protected bool _Initialized; protected int _LastKnownNumSongs; @@ -464,7 +464,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void OnShow() { _Actsongstream = -1; - _Vidtex = new CTexture(-1); + _Vidtex = null; } public virtual void OnHide() diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 960f896a..4cfa78f9 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -453,8 +453,7 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - - if (_Vidtex.Index != -1 && _Video != -1) + if (_Vidtex != null && _Video != -1) { if (_Vidtex.Color.A < 1) _CoverBig.Draw(1f, EAspect.Crop); diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index fbce1f29..a4e03947 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -201,7 +201,7 @@ namespace VocaluxeLib.Menu // ReSharper restore UnusedParameter.Local { FileName = String.Empty; - Texture = new CTexture(-1); + Texture = null; } } #endregion Profiles