From c89b9dc8befc632dcf7bccac10769ba0c9a6981a Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 00:19:16 +0200 Subject: [PATCH 01/22] Load all elements from queue (not doing this will result in not showing covers!) Will probably implement a loadOnDemand or sth like that later. --- Vocaluxe/Lib/Draw/CDirect3D.cs | 24 ++-- Vocaluxe/Lib/Draw/COpenGL.cs | 104 ++++++------------ .../Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- 3 files changed, 43 insertions(+), 87 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index f1b0b6bc..5d1bb3e0 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -1344,21 +1344,19 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - if (_Queue.Count == 0) - return; + while (_Queue.Count > 0) + { + STextureQueue q = _Queue[0]; + _Queue.RemoveAt(0); + if (!_Textures.ContainsKey(q.ID)) + continue; + STexture texture = _Textures[q.ID]; - STextureQueue q = _Queue[0]; - STexture texture; - if (_Textures.ContainsKey(q.ID)) - texture = _Textures[q.ID]; - else - return; + Texture t = _CreateTexture(q.Width, q.Height, q.Data, ref texture); + _D3DTextures[q.ID] = t; - Texture t = _CreateTexture(q.Width, q.Height, q.Data, ref texture); - _D3DTextures[q.ID] = t; - - _Textures[texture.Index] = texture; - _Queue.RemoveAt(0); + _Textures[texture.Index] = texture; + } } } diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index b866787c..83ce5c70 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -790,6 +790,19 @@ namespace Vocaluxe.Lib.Draw { STexture texture = new STexture(-1); + _CreateTexture(w, h, data, ref texture); + + lock (_MutexTexture) + { + texture.Index = _IDs.Dequeue(); + _Textures[texture.Index] = texture; + } + + return texture; + } + + private void _CreateTexture(int w, int h, byte[] data, ref STexture texture) + { if (_UsePBO) { try @@ -823,28 +836,20 @@ namespace Vocaluxe.Lib.Draw GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, 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.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.Linear); - //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); - //GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); + GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); // Add to Texture List texture.Color = new SColorF(1f, 1f, 1f, 1f); texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; - - lock (_MutexTexture) - { - texture.Index = _IDs.Dequeue(); - _Textures[texture.Index] = texture; - } - - return texture; } public STexture EnqueueTexture(int w, int h, byte[] data) @@ -1204,68 +1209,21 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - if (_Queue.Count == 0) - return; - - STextureQueue q = _Queue[0]; - STexture texture = new STexture(-1); - if (_Textures.ContainsKey(q.ID)) - texture = _Textures[q.ID]; - - if (texture.Index < 1) - return; - - if (_UsePBO) + while (_Queue.Count > 0) { - try - { - GL.GenBuffers(1, out texture.PBO); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); - GL.BufferData(BufferTarget.PixelUnpackBuffer, (IntPtr)q.Data.Length, IntPtr.Zero, BufferUsageHint.StreamDraw); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); - } - catch (Exception) - { - //throw; - _UsePBO = false; - } + STextureQueue q = _Queue[0]; + _Queue.RemoveAt(0); + STexture texture = new STexture(-1); + if (_Textures.ContainsKey(q.ID)) + texture = _Textures[q.ID]; + + if (texture.Index < 1) + continue; + + _CreateTexture(q.Width, q.Height, q.Data, ref texture); + + _Textures[texture.Index] = texture; } - - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; - - texture.Width = q.Width; - texture.Height = q.Height; - texture.W2 = MathHelper.NextPowerOfTwo(texture.Width); - texture.H2 = MathHelper.NextPowerOfTwo(texture.Height); - - texture.WidthRatio = texture.Width / texture.W2; - texture.HeightRatio = texture.Height / texture.H2; - - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.W2, (int)texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, q.Width, q.Height, PixelFormat.Bgra, PixelType.UnsignedByte, q.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.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); - - GL.BindTexture(TextureTarget.Texture2D, 0); - - // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); - texture.TexturePath = String.Empty; - - _Textures[texture.Index] = texture; - q.Data = null; - _Queue.RemoveAt(0); } } #endregion Textures diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 542e4d67..3c234a73 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -463,7 +463,7 @@ namespace VocaluxeLib.Menu.SongMenu SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); - CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, false); + CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds); CBase.Drawing.DrawTextureReflection(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); } else From 2018f3a16b7ba5b89354dada4731d9655ef82c60 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 19:04:35 +0200 Subject: [PATCH 02/22] Fixed EAspect.Letterbox Removed "Vd" prefixes on IVideo functions --- Vocaluxe/Base/CBackgroundMusic.cs | 34 +++++++------- Vocaluxe/Base/CDraw.cs | 4 +- Vocaluxe/Base/CMain.cs | 10 ++-- Vocaluxe/Base/CTheme.cs | 26 +++++------ Vocaluxe/Base/CVideo.cs | 41 ++++++++--------- Vocaluxe/Program.cs | 2 +- Vocaluxe/Screens/CScreenSing.cs | 46 ++++++++----------- VocaluxeLib/Menu/CBackground.cs | 12 ++--- VocaluxeLib/Menu/CHelper.cs | 39 ++++++++-------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 4 +- 10 files changed, 101 insertions(+), 117 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 53a169db..40b3c014 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -155,7 +155,7 @@ namespace Vocaluxe.Base CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); CSound.Play(_CurrentMusicStream); if (_VideoEnabled && _Video != -1) - CVideo.VdResume(_Video); + CVideo.Resume(_Video); IsPlaying = true; } else @@ -173,7 +173,7 @@ namespace Vocaluxe.Base if (_VideoEnabled && _Video != -1) { - CVideo.VdClose(_Video); + CVideo.Close(_Video); CDraw.RemoveTexture(ref _CurrentVideoTexture); _Video = -1; } @@ -191,8 +191,8 @@ namespace Vocaluxe.Base if (_VideoEnabled && _Video != -1) { - CVideo.VdPause(_Video); - CVideo.VdSkip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); + CVideo.Pause(_Video); + CVideo.Skip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); } CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); IsPlaying = false; @@ -221,9 +221,9 @@ namespace Vocaluxe.Base if (_VideoEnabled && _Video != -1) { if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else - CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); } } else @@ -287,9 +287,9 @@ namespace Vocaluxe.Base if (_VideoEnabled && _Video != -1) { if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else - CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); } } else @@ -319,9 +319,9 @@ namespace Vocaluxe.Base if (_VideoEnabled && _Video != -1) { if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else - CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); } } } @@ -441,14 +441,14 @@ namespace Vocaluxe.Base if (_VideoEnabled) { _VideoEnabled = false; - CVideo.VdClose(_Video); + CVideo.Close(_Video); _Video = -1; CDraw.RemoveTexture(ref _CurrentVideoTexture); return; } - if (CVideo.VdFinished(_Video)) + if (CVideo.Finished(_Video)) { - CVideo.VdClose(_Video); + CVideo.Close(_Video); CDraw.RemoveTexture(ref _CurrentVideoTexture); _Video = -1; } @@ -462,7 +462,7 @@ namespace Vocaluxe.Base if (_Video != -1) { float vtime; - CVideo.VdGetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime); + CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime); if (_FadeTimer.ElapsedMilliseconds <= 3000L) _CurrentVideoTexture.Color.A = _FadeTimer.ElapsedMilliseconds / 3000f; else @@ -484,11 +484,11 @@ namespace Vocaluxe.Base { if (_Video == -1) { - _Video = CVideo.VdLoad(_CurrentPlaylistElement.VideoFilePath); + _Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath); if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else - CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); + CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); _VideoEnabled = true; _FadeTimer.Reset(); _FadeTimer.Start(); diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 82c0bdd2..e7f48201 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -200,9 +200,9 @@ namespace Vocaluxe.Base return; RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H); - RectangleF rect = new RectangleF(0f, 0f, texture.Width, texture.Height); + RectangleF rect; - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, aspect); + CHelper.SetRect(bounds, out rect, texture.Width / texture.Height, aspect); DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, staticBounds.Rect.Z), texture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); } diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index aaaf62dc..1a4cc94a 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -672,27 +672,27 @@ namespace Vocaluxe.Base { public int Load(string videoFileName) { - return CVideo.VdLoad(videoFileName); + return CVideo.Load(videoFileName); } public bool Skip(int videoStream, float startPosition, float videoGap) { - return CVideo.VdSkip(videoStream, startPosition, videoGap); + return CVideo.Skip(videoStream, startPosition, videoGap); } public bool GetFrame(int videoStream, ref STexture videoTexture, float time, out float videoTime) { - return CVideo.VdGetFrame(videoStream, ref videoTexture, time, out videoTime); + return CVideo.GetFrame(videoStream, ref videoTexture, time, out videoTime); } public bool IsFinished(int videoStream) { - return CVideo.VdFinished(videoStream); + return CVideo.Finished(videoStream); } public bool Close(int videoStream) { - return CVideo.VdClose(videoStream); + return CVideo.Close(videoStream); } } diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index fa7a3c2b..d26b8813 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -199,9 +199,9 @@ namespace Vocaluxe.Base { xmlReader.GetValue("//root/Videos/" + _Skins[skinIndex].VideoList[i].Name, out value, String.Empty); SSkinElement sk = new SSkinElement {Name = _Skins[skinIndex].VideoList[i].Name, Value = value}; - sk.VideoIndex = CVideo.VdLoad(Path.Combine(_Skins[skinIndex].Path, sk.Value)); - CVideo.VdSetLoop(sk.VideoIndex, true); - CVideo.VdPause(sk.VideoIndex); + sk.VideoIndex = CVideo.Load(Path.Combine(_Skins[skinIndex].Path, sk.Value)); + CVideo.SetLoop(sk.VideoIndex, true); + CVideo.Pause(sk.VideoIndex); sk.Texture = new STexture(-1); _Skins[skinIndex].VideoList[i] = sk; } @@ -230,7 +230,7 @@ namespace Vocaluxe.Base for (int j = 0; j < _Skins[i].VideoList.Count; j++) { - CVideo.VdClose(_Skins[i].VideoList[j].VideoIndex); + CVideo.Close(_Skins[i].VideoList[j].VideoIndex); STexture videoTexture = _Skins[i].VideoList[j].Texture; CDraw.RemoveTexture(ref videoTexture); } @@ -617,10 +617,10 @@ namespace Vocaluxe.Base float time = 0f; if (sk.VideoIndex == -1) { - sk.VideoIndex = CVideo.VdLoad(GetVideoFilePath(sk.Name, partyModeID)); - CVideo.VdSetLoop(sk.VideoIndex, true); + sk.VideoIndex = CVideo.Load(GetVideoFilePath(sk.Name, partyModeID)); + CVideo.SetLoop(sk.VideoIndex, true); } - CVideo.VdGetFrame(sk.VideoIndex, ref sk.Texture, time, out time); + CVideo.GetFrame(sk.VideoIndex, ref sk.Texture, time, out time); _Skins[skinIndex].VideoList[i] = sk; return sk.Texture; } @@ -641,10 +641,10 @@ namespace Vocaluxe.Base { if (sk.VideoIndex == -1) { - sk.VideoIndex = CVideo.VdLoad(GetVideoFilePath(sk.Name, partyModeID)); - CVideo.VdSetLoop(sk.VideoIndex, true); + sk.VideoIndex = CVideo.Load(GetVideoFilePath(sk.Name, partyModeID)); + CVideo.SetLoop(sk.VideoIndex, true); } - CVideo.VdPause(sk.VideoIndex); + CVideo.Pause(sk.VideoIndex); _Skins[skinIndex].VideoList[i] = sk; return; } @@ -664,10 +664,10 @@ namespace Vocaluxe.Base { if (sk.VideoIndex == -1) { - sk.VideoIndex = CVideo.VdLoad(GetVideoFilePath(sk.Name, partyModeID)); - CVideo.VdSetLoop(sk.VideoIndex, true); + sk.VideoIndex = CVideo.Load(GetVideoFilePath(sk.Name, partyModeID)); + CVideo.SetLoop(sk.VideoIndex, true); } - CVideo.VdResume(sk.VideoIndex); + CVideo.Resume(sk.VideoIndex); _Skins[skinIndex].VideoList[i] = sk; return; } diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index db7390fb..b78ef2c9 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -50,12 +50,7 @@ namespace Vocaluxe.Base #endregion Init #region Interface - public static bool VdInit() - { - return _VideoDecoder.Init(); - } - - public static void VdCloseAll() + public static void CloseAll() { _VideoDecoder.CloseAll(); } @@ -65,47 +60,47 @@ namespace Vocaluxe.Base return _VideoDecoder.GetNumStreams(); } - public static int VdLoad(string videoFileName) + public static int Load(string videoFileName) { return _VideoDecoder.Load(videoFileName); } - public static bool VdClose(int streamID) + public static bool Close(int streamID) { return _VideoDecoder.Close(streamID); } - public static float VdGetLength(int streamID) + public static float GetLength(int streamID) { return _VideoDecoder.GetLength(streamID); } - public static bool VdGetFrame(int streamID, ref STexture frame, float time, out float videoTime) + public static bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) { return _VideoDecoder.GetFrame(streamID, ref frame, time, out videoTime); } - public static bool VdSkip(int streamID, float start, float gap) + public static bool Skip(int streamID, float start, float gap) { return _VideoDecoder.Skip(streamID, start, gap); } - public static void VdSetLoop(int streamID, bool loop) + public static void SetLoop(int streamID, bool loop) { _VideoDecoder.SetLoop(streamID, loop); } - public static void VdPause(int streamID) + public static void Pause(int streamID) { _VideoDecoder.Pause(streamID); } - public static void VdResume(int streamID) + public static void Resume(int streamID) { _VideoDecoder.Resume(streamID); } - public static bool VdFinished(int streamID) + public static bool Finished(int streamID) { return _VideoDecoder.Finished(streamID); } @@ -134,7 +129,7 @@ namespace Vocaluxe.Base public bool Loop { - set { CVideo.VdSetLoop(_VideoStream, value); } + set { CVideo.SetLoop(_VideoStream, value); } } public CVideoPlayer() @@ -147,7 +142,7 @@ namespace Vocaluxe.Base public void Load(string videoName) { - _VideoStream = CVideo.VdLoad(CTheme.GetVideoFilePath(videoName, -1)); + _VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1)); _Loaded = true; } @@ -174,10 +169,10 @@ namespace Vocaluxe.Base if (!_Finished) { float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; - _Finished = CVideo.VdFinished(_VideoStream); + _Finished = CVideo.Finished(_VideoStream); STexture tex = new STexture(-1) {Height = 0f}; - CVideo.VdGetFrame(_VideoStream, ref tex, videoTime, out videoTime); + CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime); if (tex.Height > 0) { @@ -186,8 +181,8 @@ namespace Vocaluxe.Base } } RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); - RectangleF rect = new RectangleF(0f, 0f, _VideoTexture.Width, _VideoTexture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + RectangleF rect; + CHelper.SetRect(bounds, out rect, _VideoTexture.Width / _VideoTexture.Height, EAspect.Crop); CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); } @@ -198,14 +193,14 @@ namespace Vocaluxe.Base while (_VideoTexture.Index == -1 && videoTime < 1f) { float dummy; - CVideo.VdGetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); + CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); videoTime += 0.05f; } } public void Close() { - CVideo.VdClose(_VideoStream); + CVideo.Close(_VideoStream); CDraw.RemoveTexture(ref _VideoTexture); _Loaded = false; _Finished = false; diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index f45e8866..955dc023 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -223,7 +223,7 @@ namespace Vocaluxe CController.Close(); CSound.RecordCloseAll(); CSound.CloseAllStreams(); - CVideo.VdCloseAll(); + CVideo.CloseAll(); CDraw.Unload(); CDataBase.CloseConnections(); CWebcam.Close(); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index f85934f9..04f7e174 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -395,7 +395,7 @@ namespace Vocaluxe.Screens if (_CurrentVideo != -1 && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON) { float vtime; - CVideo.VdGetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, out vtime); + CVideo.GetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, out vtime); } if (_Webcam) @@ -453,34 +453,26 @@ namespace Vocaluxe.Screens { if (_Active) { + STexture background; + EAspect aspect = EAspect.Crop; if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) { - RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); - RectangleF rect = new RectangleF(0f, 0f, _CurrentVideoTexture.Width, _CurrentVideoTexture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, _VideoAspect); - - CDraw.DrawTexture(_CurrentVideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), - _CurrentVideoTexture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); + background = _CurrentVideoTexture; + aspect = _VideoAspect; } else if (_Webcam) { - RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); - RectangleF rect = new RectangleF(0f, 0f, _CurrentWebcamFrameTexture.Width, _CurrentWebcamFrameTexture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, _VideoAspect); - - CDraw.DrawTexture(_CurrentWebcamFrameTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), - _CurrentVideoTexture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); + background = _CurrentWebcamFrameTexture; + aspect = _VideoAspect; } else - { - // Draw Background - RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); - RectangleF rect = new RectangleF(0f, 0f, _Background.Width, _Background.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + background = _Background; + RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); + RectangleF rect; + CHelper.SetRect(bounds, out rect, background.Width / background.Height, 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), false); - } + 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(); @@ -556,7 +548,7 @@ namespace Vocaluxe.Screens CSound.RecordStop(); if (_CurrentVideo != -1) { - CVideo.VdClose(_CurrentVideo); + CVideo.Close(_CurrentVideo); _CurrentVideo = -1; CDraw.RemoveTexture(ref _CurrentVideoTexture); } @@ -621,8 +613,8 @@ namespace Vocaluxe.Screens if (song.VideoFileName != "") { - _CurrentVideo = CVideo.VdLoad(Path.Combine(song.Folder, song.VideoFileName)); - CVideo.VdSkip(_CurrentVideo, song.Start, song.VideoGap); + _CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName)); + CVideo.Skip(_CurrentVideo, song.Start, song.VideoGap); _VideoAspect = song.VideoAspect; } @@ -691,9 +683,9 @@ namespace Vocaluxe.Screens } else { - bool lyricsOnTop = CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP - || CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH - || (CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && (CGame.NumPlayer > 2 && CGame.NumPlayer != 4)); + bool lyricsOnTop = CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP + || CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH + || (CConfig.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && (CGame.NumPlayer > 2 && CGame.NumPlayer != 4)); _Lyrics[_LyricMainTop].Visible = lyricsOnTop; _Lyrics[_LyricSubTop].Visible = lyricsOnTop; _Statics[_StaticLyricsTop].Visible = lyricsOnTop; diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 11cf7124..3dafcbb5 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -206,8 +206,8 @@ namespace VocaluxeLib.Menu if (texture.Height > 0) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); - RectangleF rect = new RectangleF(0f, 0f, texture.Width, texture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + RectangleF rect; + CHelper.SetRect(bounds, out rect, texture.Width / texture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -221,8 +221,8 @@ namespace VocaluxeLib.Menu if (videoTexture.Height > 0) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); - RectangleF rect = new RectangleF(0f, 0f, videoTexture.Width, videoTexture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + RectangleF rect; + CHelper.SetRect(bounds, out rect, videoTexture.Width / videoTexture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -236,8 +236,8 @@ namespace VocaluxeLib.Menu if (videoTexture.Height > 0) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); - RectangleF rect = new RectangleF(0f, 0f, videoTexture.Width, videoTexture.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + RectangleF rect; + CHelper.SetRect(bounds, out rect, videoTexture.Width / videoTexture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; diff --git a/VocaluxeLib/Menu/CHelper.cs b/VocaluxeLib/Menu/CHelper.cs index bdf1a007..fba78729 100644 --- a/VocaluxeLib/Menu/CHelper.cs +++ b/VocaluxeLib/Menu/CHelper.cs @@ -91,9 +91,9 @@ namespace VocaluxeLib.Menu public static void SetRect(RectangleF bounds, out RectangleF rect, float rectAspect, EAspect aspect) { - float rW = bounds.Right - bounds.Left; - float rH = bounds.Bottom - bounds.Top; - float rA = rW / rH; + float boundsW = bounds.Width; + float boundsH = bounds.Height; + float boundsAspect = boundsW / boundsH; float scaledWidth; float scaledHeight; @@ -101,42 +101,39 @@ namespace VocaluxeLib.Menu switch (aspect) { case EAspect.Crop: - if (rA >= rectAspect) + if (boundsAspect >= rectAspect) { - scaledWidth = rW; - scaledHeight = rH * rA / rectAspect; + scaledWidth = boundsW; + scaledHeight = boundsW / rectAspect; } else { - scaledHeight = rH; - scaledWidth = rW * rectAspect / rA; + scaledHeight = boundsH; + scaledWidth = boundsH * rectAspect; } break; case EAspect.LetterBox: - if (rectAspect >= 1) + if (boundsAspect <= rectAspect) { - scaledWidth = rW; - scaledHeight = rH * rA / rectAspect; + scaledWidth = boundsW; + scaledHeight = boundsW / rectAspect; } else { - scaledHeight = rH; - scaledWidth = rW * rectAspect / rA; + scaledHeight = boundsH; + scaledWidth = boundsH * rectAspect; } break; default: - scaledWidth = rW; - scaledHeight = rH; + scaledWidth = boundsW; + scaledHeight = boundsH; break; } - float left = (rW - scaledWidth) / 2 + bounds.Left; - float rigth = left + scaledWidth; + float left = (boundsW - scaledWidth) / 2 + bounds.Left; + float upper = (boundsH - scaledHeight) / 2 + bounds.Top; - float upper = (rH - scaledHeight) / 2 + bounds.Top; - float lower = upper + scaledHeight; - - rect = new RectangleF(left, upper, rigth - left, lower - upper); + rect = new RectangleF(left, upper, scaledWidth, scaledHeight); } public static List ListFiles(string path, string cast, bool recursive = false, bool fullpath = false) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 3c234a73..5d437d1d 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -458,8 +458,8 @@ namespace VocaluxeLib.Menu.SongMenu if (_Vidtex.Color.A < 1) _CoverBig.Draw(1f, EAspect.Crop); RectangleF bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); - RectangleF rect = new RectangleF(0f, 0f, _Vidtex.Width, _Vidtex.Height); - CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); + RectangleF rect; + CHelper.SetRect(bounds, out rect, _Vidtex.Width / _Vidtex.Height, EAspect.Crop); SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); From 1bfc76e4d39666fef9f7f1fbb7c13827162359f7 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 19:56:04 +0200 Subject: [PATCH 03/22] Better readability for CSingNotes --- VocaluxeLib/Menu/SingNotes/CSingNotes.cs | 40 +++++++++--------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index 457fb7fc..4fab9280 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -384,9 +384,7 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes[n].Rect.Z ); - float f = 0.7f; - if (!note.Hit) - f = 0.4f; + float f = (note.Hit) ? 0.7f : 0.4f; _DrawNote(rect, color, f); @@ -469,39 +467,31 @@ namespace VocaluxeLib.Menu.SingNotes private void _DrawNote(SRectF rect, SColorF color, float factor = 1f) { - const int spacing = 0; + if (factor <= 0) + return; - float d = (1f - factor) / 2 * rect.H; - float dw = d; + float dh = (1f - factor) * rect.H / 2; + float dw = Math.Min(dh, rect.W / 2); - if (2 * dw > rect.W) - dw = rect.W / 2; - - SRectF r = new SRectF( - rect.X + dw + spacing, - rect.Y + d + spacing, - rect.W - 2 * dw - 2 * spacing, - rect.H - 2 * d - 2 * spacing, - rect.Z - ); + SRectF noteRect = new SRectF(rect.X + dw, rect.Y + dh, rect.W - 2 * dw, rect.H - 2 * dh, rect.Z); STexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); STexture noteMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinMiddleName, _PartyModeID); STexture noteEnd = CBase.Theme.GetSkinTexture(_Theme.SkinRightName, _PartyModeID); - float dx = noteBegin.Width * r.H / noteBegin.Height; - if (2 * dx > r.W) - dx = r.W / 2; + //Width of each of the ends (round parts) + //Need 2 of them so use minimum + float endsW = Math.Min(noteRect.H * noteBegin.Width / noteBegin.Height, noteRect.W / 2); + CBase.Drawing.DrawTexture(noteBegin, new SRectF(noteRect.X, noteRect.Y, endsW, noteRect.H, noteRect.Z), color); - CBase.Drawing.DrawTexture(noteBegin, new SRectF(r.X, r.Y, dx, r.H, r.Z), color); - - if (r.W - 2 * dx >= 2 * dx) - CBase.Drawing.DrawTexture(noteMiddle, new SRectF(r.X + dx, r.Y, r.W - 2 * dx, r.H, r.Z), color); + SRectF middleRect = new SRectF(noteRect.X + endsW, noteRect.Y, noteRect.W - 2 * endsW, noteRect.H, noteRect.Z); + if (noteRect.W >= 4 * endsW) + CBase.Drawing.DrawTexture(noteMiddle, middleRect, color); else - CBase.Drawing.DrawTexture(noteMiddle, new SRectF(r.X + dx, r.Y, 2 * dx, r.H, r.Z), color, new SRectF(r.X + dx, r.Y, r.W - 2 * dx, r.H, r.Z)); + CBase.Drawing.DrawTexture(noteMiddle, new SRectF(middleRect.X, middleRect.Y, 2 * endsW, middleRect.H, middleRect.Z), color, middleRect); - CBase.Drawing.DrawTexture(noteEnd, new SRectF(r.X + r.W - dx, r.Y, dx, r.H, r.Z), color); + CBase.Drawing.DrawTexture(noteEnd, new SRectF(noteRect.X + noteRect.W - endsW, noteRect.Y, endsW, noteRect.H, noteRect.Z), color); } private void _DrawNoteBG(SRectF rect, SColorF color, float factor, Stopwatch timer) From 151fab8857b5e290f96b0f63b63296bd6a80c064 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 20:07:53 +0200 Subject: [PATCH 04/22] Changed texture sizes to more reasonable int --- .../CChallengeRounds.cs | 2 +- Vocaluxe/Base/CDraw.cs | 2 +- Vocaluxe/Base/CVideo.cs | 4 +-- Vocaluxe/Base/Fonts/CFonts.cs | 6 ++--- Vocaluxe/Base/Fonts/CGlyph.cs | 2 ++ Vocaluxe/Lib/Draw/CDirect3D.cs | 24 ++++++++--------- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 2 +- Vocaluxe/Lib/Draw/COpenGL.cs | 26 +++++++++---------- Vocaluxe/Lib/Draw/IDraw.cs | 1 - Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 2 +- Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 2 +- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 2 +- Vocaluxe/Screens/CScreenCredits.cs | 2 +- Vocaluxe/Screens/CScreenNames.cs | 8 +++--- Vocaluxe/Screens/CScreenSing.cs | 2 +- Vocaluxe/Screens/CScreenTest.cs | 12 ++++----- VocaluxeLib/Menu/CBackground.cs | 6 ++--- VocaluxeLib/Menu/CNameSelection.cs | 2 +- VocaluxeLib/Menu/CStatic.cs | 2 +- VocaluxeLib/Menu/CText.cs | 6 ++--- .../Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- VocaluxeLib/Menu/Structs.cs | 16 ++++++------ 22 files changed, 67 insertions(+), 66 deletions(-) diff --git a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs index 4114320b..d2345005 100644 --- a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs +++ b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs @@ -146,7 +146,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _Rand = rand; } - public CCombination GetNextCombination(List playerNrDemand) + public CCombination GetNextCombination(IEnumerable playerNrDemand) { if (_Combs.Count == 0) _Create(); diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index e7f48201..d2b9b74d 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -202,7 +202,7 @@ namespace Vocaluxe.Base RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H); RectangleF rect; - CHelper.SetRect(bounds, out rect, texture.Width / texture.Height, aspect); + CHelper.SetRect(bounds, out rect, (float)texture.Width / texture.Height, aspect); DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, staticBounds.Rect.Z), texture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); } diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index b78ef2c9..a8926164 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -171,7 +171,7 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.Finished(_VideoStream); - STexture tex = new STexture(-1) {Height = 0f}; + STexture tex = new STexture(-1) {Height = 0}; CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime); if (tex.Height > 0) @@ -182,7 +182,7 @@ namespace Vocaluxe.Base } RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect; - CHelper.SetRect(bounds, out rect, _VideoTexture.Width / _VideoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, (float)_VideoTexture.Width / _VideoTexture.Height, EAspect.Crop); CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); } diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index 0db4b25d..e0e50e84 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -70,7 +70,7 @@ namespace Vocaluxe.Base.Fonts private static void _BuildFonts() { - foreach (var font in _Fonts) + foreach (SFont font in _Fonts) { font.Normal.Dispose(); font.Bold.Dispose(); @@ -257,8 +257,8 @@ namespace Vocaluxe.Base.Fonts Height = height; SetFont(text.Font); Style = text.Style; - var result = new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text, text.TranslationID)), - GetTextHeight(CLanguage.Translate(text.Text, text.TranslationID))); + RectangleF result = new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text, text.TranslationID)), + GetTextHeight(CLanguage.Translate(text.Text, text.TranslationID))); //restore old values Height = oldHeight; _CurrentFont = oldFont; diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index 453301ad..af06252b 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -121,6 +121,7 @@ namespace Vocaluxe.Base.Fonts _DrawBounding.Width = _Texture.Width; _DrawBounding.Height = _Texture.Height;*/ #pragma warning disable 162 + // ReSharper disable HeuristicUnreachableCode if (false) { if (outline > 0) @@ -128,6 +129,7 @@ namespace Vocaluxe.Base.Fonts else bmpCropped.Save("font/" + chr + CFonts.Style + "2.png", ImageFormat.Png); } + // ReSharper restore HeuristicUnreachableCode #pragma warning restore 162 } } diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 5d1bb3e0..7aff044b 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -708,7 +708,7 @@ namespace Vocaluxe.Lib.Draw /// The texture in which the frame is copied to public void CopyScreen(ref STexture texture) { - if (!_TextureExists(ref texture) || (int)texture.Width != GetScreenWidth() || (int)texture.Height != GetScreenHeight()) + if (!_TextureExists(ref texture) || texture.Width != GetScreenWidth() || texture.Height != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -758,8 +758,8 @@ namespace Vocaluxe.Lib.Draw /// The end y-value public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) { - var lineVector = new Vector2[] {new Vector2(x1, y1), new Vector2(x2, y2)}; - using (var line = new Line(_Device)) + Vector2[] lineVector = new Vector2[] {new Vector2(x1, y1), new Vector2(x2, y2)}; + using (Line line = new Line(_Device)) { line.Antialias = true; line.Begin(); @@ -872,9 +872,9 @@ namespace Vocaluxe.Lib.Draw else if (h > maxSize) newH = maxSize; else if (w > h) - newW = (int)_CheckForNextPowerOf2(w); + newW = _CheckForNextPowerOf2(w); else - newH = (int)_CheckForNextPowerOf2(h); + newH = _CheckForNextPowerOf2(h); Bitmap bmp2 = null; byte[] data; @@ -943,18 +943,18 @@ namespace Vocaluxe.Lib.Draw texture.Height = h; texture.W2 = _CheckForNextPowerOf2(w); texture.H2 = _CheckForNextPowerOf2(h); - texture.WidthRatio = w / texture.W2; - texture.HeightRatio = h / texture.H2; + texture.WidthRatio = (float)w / texture.W2; + texture.HeightRatio = (float)h / texture.H2; //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 Texture t = null; try { - t = new Texture(_Device, (int)texture.W2, (int)texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + t = new Texture(_Device, texture.W2, texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); //Lock the texture and fill it with the data DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); - int rowWidth = 4 * (int)texture.W2; + int rowWidth = 4 * texture.W2; for (int i = 0; i + rowWidth <= data.Length; i += 4 * w) { rect.Data.Write(data, i, rowWidth); @@ -1010,7 +1010,7 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); - int w = (int)texture.Width; + int w = texture.Width; for (int i = 0; i < data.Length; i += 4 * w) { rect.Data.Write(data, i, 4 * w); @@ -1378,13 +1378,13 @@ namespace Vocaluxe.Lib.Draw /// /// The value of which the next power of two will be calculated /// The next power of two - private float _CheckForNextPowerOf2(float n) + private int _CheckForNextPowerOf2(int n) { if (_NonPowerOf2TextureSupported) return n; if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); - return (float)Math.Pow(2, Math.Ceiling(Math.Log(n, 2))); + return (int)Math.Pow(2, Math.Ceiling(Math.Log(n, 2))); } private SlimDX.Matrix _CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 58617230..1a8a5f80 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -310,7 +310,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref STexture texture) { - if (texture.Index == 0 || (int)texture.Width != GetScreenWidth() || (int)texture.Height != GetScreenHeight()) + if (texture.Index == 0 || texture.Width != GetScreenWidth() || texture.Height != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 83ce5c70..653dc770 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -501,12 +501,12 @@ namespace Vocaluxe.Lib.Draw texture.W2 = MathHelper.NextPowerOfTwo(texture.Width); texture.H2 = MathHelper.NextPowerOfTwo(texture.Height); - texture.WidthRatio = texture.Width / texture.W2; - texture.HeightRatio = texture.Height / texture.H2; + texture.WidthRatio = (float)texture.Width / texture.W2; + texture.HeightRatio = (float)texture.Height / texture.H2; - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.W2, (int)texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + 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, (int)texture.Width, (int)texture.Height); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, _X, _Y, texture.Width, texture.Height); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); @@ -537,7 +537,7 @@ namespace Vocaluxe.Lib.Draw { GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, (int)texture.Width, (int)texture.Height); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.Width, texture.Height); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -737,7 +737,7 @@ namespace Vocaluxe.Lib.Draw texture.H2 = MathHelper.NextPowerOfTwo(h); try { - using (Bitmap bmp2 = new Bitmap((int)texture.W2, (int)texture.H2)) + using (Bitmap bmp2 = new Bitmap(texture.W2, texture.H2)) { Graphics g = Graphics.FromImage(bmp2); g.InterpolationMode = InterpolationMode.HighQualityBicubic; @@ -750,7 +750,7 @@ namespace Vocaluxe.Lib.Draw BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.W2, (int)texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + 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, bmpData.Width, bmpData.Height, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); @@ -759,7 +759,7 @@ namespace Vocaluxe.Lib.Draw } catch { - CLog.LogError(w + " " + h + " " + (int)texture.W2 + " " + (int)texture.H2); + CLog.LogError(w + " " + h + " " + texture.W2 + " " + texture.H2); throw; } @@ -828,10 +828,10 @@ namespace Vocaluxe.Lib.Draw texture.W2 = MathHelper.NextPowerOfTwo(texture.Width); texture.H2 = MathHelper.NextPowerOfTwo(texture.Height); - texture.WidthRatio = texture.Width / texture.W2; - texture.HeightRatio = texture.Height / texture.H2; + texture.WidthRatio = (float)texture.Width / texture.W2; + texture.HeightRatio = (float)texture.Height / texture.H2; - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.W2, (int)texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + 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); @@ -887,7 +887,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)texture.Width, (int)texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.Width, texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); @@ -897,7 +897,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)texture.Width, (int)texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.Width, texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 3a48be4c..77a605aa 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -17,7 +17,6 @@ // */ #endregion -using System; using System.Drawing; using VocaluxeLib.Menu; diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index e9dcd175..7beeb29c 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -661,7 +661,7 @@ namespace Vocaluxe.Lib.Video if (num >= 0) { - if (frame.Index == -1 || _Width != (int)frame.Width || _Height != (int)frame.Height) + if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _FrameBuffer[num].Data); diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index c5449dbc..5bfcf8a5 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -121,7 +121,7 @@ namespace Vocaluxe.Lib.Video { if (data == null) return; - if (frame.Index == -1 || width != (int)frame.Width || height != (int)frame.Height || data.Length == 0) + if (frame.Index == -1 || width != frame.Width || height != frame.Height || data.Length == 0) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(width, height, data); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 99c1f820..14ef1782 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -56,7 +56,7 @@ namespace Vocaluxe.Lib.Webcam { lock (_MutexData) { - if (frame.Index == -1 || _Width != (int)frame.Width || _Height != (int)frame.Height) + if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _Data); diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 495bc9c6..3f2367bd 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -317,7 +317,7 @@ namespace Vocaluxe.Screens base.OnShow(); //Vocaluxe-Logo - _Logo = GetNewStatic(_TexLogo, new SColorF(1, 1, 1, 1), new SRectF((CSettings.RenderW - _TexLogo.Width) / 2, -270, _TexLogo.Width, _TexLogo.Height, -2)); + _Logo = GetNewStatic(_TexLogo, new SColorF(1, 1, 1, 1), new SRectF((float)(CSettings.RenderW - _TexLogo.Width) / 2, -270, _TexLogo.Width, _TexLogo.Height, -2)); //Little stars for logo int numstars = (int)(_Logo.Rect.W * 0.25f / 2f); diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 99006246..c1e332c4 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -58,7 +58,7 @@ namespace Vocaluxe.Screens private bool _SelectingKeyboardActive; private bool _SelectingFast; private int _SelectingSwitchNr = -1; - private int _SelectingFastPlayerNr = 0; + private int _SelectingFastPlayerNr; private int _SelectedPlayerNr = -1; public override void Init() @@ -430,7 +430,7 @@ namespace Vocaluxe.Screens CConfig.Players[_SelectingSwitchNr] = string.Empty; //Update texture and name _Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = _OriginalPlayerAvatarTextures[_SelectingSwitchNr]; - _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr+1)); + _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr + 1)); } //Update Game-infos with new player CGame.Players[i].ProfileID = _SelectedPlayerNr; @@ -447,7 +447,7 @@ namespace Vocaluxe.Screens break; } //Selected player is dropped out of area - else if (_SelectingSwitchNr > -1) + if (_SelectingSwitchNr > -1) { //Update Game-infos with new player CGame.Players[_SelectingSwitchNr].ProfileID = -1; @@ -569,7 +569,7 @@ namespace Vocaluxe.Screens else stopSelectingFast = true; } - else if(mouseEvent.MB) + else if (mouseEvent.MB) { _ResetPlayerSelections(); _SelectingFast = true; diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 04f7e174..c6dbd9d4 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -469,7 +469,7 @@ namespace Vocaluxe.Screens background = _Background; RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); RectangleF rect; - CHelper.SetRect(bounds, out rect, background.Width / background.Height, aspect); + CHelper.SetRect(bounds, out rect, (float)background.Width / background.Height, 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)); diff --git a/Vocaluxe/Screens/CScreenTest.cs b/Vocaluxe/Screens/CScreenTest.cs index 7783f39b..b4362f55 100644 --- a/Vocaluxe/Screens/CScreenTest.cs +++ b/Vocaluxe/Screens/CScreenTest.cs @@ -41,17 +41,17 @@ namespace Vocaluxe.Screens base.Init(); const string test = "Ö ÄÜabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWGXZ1234567890"; SColorF color = new SColorF(1, 0, 0, 1); - CText text = new CText(10, 50, 1, 32, 0, EAlignment.Left, EStyle.Normal, "Normal", color, "jÄNormal Text" + test, -1, 26, 0); + CText text = new CText(10, 50, 1, 32, 0, EAlignment.Left, EStyle.Normal, "Normal", color, "jÄNormal Text" + test, -1, 26, 1); _AddText(text); - text = new CText(10, 90, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Normal", color, "jÄBold Text" + test, -1, 26, 0); + text = new CText(10, 90, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Normal", color, "jÄBold Text" + test, -1, 26, 1); _AddText(text); - text = new CText(10, 130, 1, 32, 0, EAlignment.Left, EStyle.Italic, "Normal", color, "jÄItalic Text" + test, -1, 26, 0); + text = new CText(10, 130, 1, 32, 0, EAlignment.Left, EStyle.Italic, "Normal", color, "jÄItalic Text" + test, -1, 26, 1); _AddText(text); - text = new CText(10, 170, 1, 32, 0, EAlignment.Left, EStyle.Normal, "Outline", color, "jÄNormal Text" + test, -1, 50, 0); + text = new CText(10, 170, 1, 32, 0, EAlignment.Left, EStyle.Normal, "Outline", color, "jÄNormal Text" + test, -1, 50, 1); _AddText(text); - text = new CText(10, 210, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Outline", color, "jÄBold Text" + test, -1, 100, 0); + text = new CText(10, 210, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Outline", color, "jÄBold Text" + test, -1, 100, 1); _AddText(text); - text = new CText(10, 250, 1, 32, 0, EAlignment.Left, EStyle.Italic, "Outline", color, "jÄItalic Text" + test, -1, 150, 0); + text = new CText(10, 250, 1, 32, 0, EAlignment.Left, EStyle.Italic, "Outline", color, "jÄItalic Text" + test, -1, 150, 1); _AddText(text); } diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 3dafcbb5..c63aeb24 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -207,7 +207,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, texture.Width / texture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, (float)texture.Width / texture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -222,7 +222,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, videoTexture.Width / videoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, (float)videoTexture.Width / videoTexture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -237,7 +237,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, videoTexture.Width / videoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, (float)videoTexture.Width / videoTexture.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 2888d8ea..39fba2b4 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -348,7 +348,7 @@ namespace VocaluxeLib.Menu public void HandleMouse(SMouseEvent mevent) { - for (int i = 0; i < _Tiles.Count; i++ ) + for (int i = 0; i < _Tiles.Count; i++) { if (CHelper.IsInBounds(_Tiles[i].Avatar.Rect, mevent)) { diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 8dfa8d07..d5a1f6f3 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -253,7 +253,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); RectangleF rect2; - CHelper.SetRect(bounds2, out rect2, texture.Width / texture.Height, aspect); + CHelper.SetRect(bounds2, out rect2, (float)texture.Width / texture.Height, aspect); rect.X = rect2.X; rect.Y = rect2.Y; diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index 978eaf6f..6fc4e09f 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -169,7 +169,7 @@ namespace VocaluxeLib.Menu } /// - /// Do NOT read/write this anywhere but in _UpdateTextPosition! + /// Do NOT read/write this anywhere but in _UpdateTextPosition! /// private SRectF _Rect; public SRectF Rect @@ -499,8 +499,8 @@ namespace VocaluxeLib.Menu public void DrawRelative(float rx, float ry, float reflectionHeight = 0f, float reflectionSpace = 0f, float rectHeight = 0f) { - var oldReflectionSpace = ReflectionSpace; - var oldReflectionHeight = ReflectionHeight; + float oldReflectionSpace = ReflectionSpace; + float oldReflectionHeight = ReflectionHeight; if (reflectionHeight > 0) { ReflectionSpace = (rectHeight - Rect.Y - Rect.H) * 2 + reflectionSpace; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 5d437d1d..b5a65b20 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -459,7 +459,7 @@ namespace VocaluxeLib.Menu.SongMenu _CoverBig.Draw(1f, EAspect.Crop); RectangleF bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); RectangleF rect; - CHelper.SetRect(bounds, out rect, _Vidtex.Width / _Vidtex.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, (float)_Vidtex.Width / _Vidtex.Height, EAspect.Crop); SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index 062379fe..59ce099c 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -108,12 +108,12 @@ namespace VocaluxeLib.Menu public string TexturePath; - public float Width; - public float Height; + public int Width; + public int Height; public SRectF Rect; - public float W2; //power of 2 width - public float H2; //power of 2 height + public int W2; //power of 2 width + public int H2; //power of 2 height public float WidthRatio; public float HeightRatio; @@ -126,12 +126,12 @@ namespace VocaluxeLib.Menu ID = -1; TexturePath = String.Empty; - Width = 1f; - Height = 1f; + Width = 1; + Height = 1; Rect = new SRectF(0f, 0f, 1f, 1f, 0f); - W2 = 2f; - H2 = 2f; + W2 = 1; + H2 = 1; WidthRatio = 0.5f; HeightRatio = 0.5f; From 5bbfd07e013c7179fedf514f590a730e701e55c5 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 22:29:47 +0200 Subject: [PATCH 05/22] Introduced OrigSize for original size of textures --- Vocaluxe/Base/CDraw.cs | 4 +- Vocaluxe/Base/CVideo.cs | 6 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 80 ++---- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 14 +- Vocaluxe/Lib/Draw/COpenGL.cs | 255 +++++++++--------- Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 2 +- Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 2 +- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 2 +- Vocaluxe/Screens/CScreenCredits.cs | 7 +- Vocaluxe/Screens/CScreenSing.cs | 2 +- VocaluxeLib/Menu/CBackground.cs | 12 +- VocaluxeLib/Menu/CStatic.cs | 2 +- VocaluxeLib/Menu/SingNotes/CSingNotes.cs | 6 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- VocaluxeLib/Menu/Structs.cs | 39 ++- 15 files changed, 206 insertions(+), 229 deletions(-) diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index d2b9b74d..41a323e3 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -196,13 +196,13 @@ namespace Vocaluxe.Base public static void DrawTexture(CStatic staticBounds, STexture texture, EAspect aspect) { - if (texture.Height <= 0f) + if (texture.OrigSize.Height <= 0) return; RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)texture.Width / texture.Height, aspect); + CHelper.SetRect(bounds, out rect, texture.OrigAspect, aspect); DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, staticBounds.Rect.Z), texture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); } diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index a8926164..10c59af0 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -171,10 +171,10 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.Finished(_VideoStream); - STexture tex = new STexture(-1) {Height = 0}; + STexture tex = new STexture(-1); CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime); - if (tex.Height > 0) + if (tex.Index > 0) { CDraw.RemoveTexture(ref _VideoTexture); _VideoTexture = tex; @@ -182,7 +182,7 @@ namespace Vocaluxe.Base } RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)_VideoTexture.Width / _VideoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop); CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); } diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 7aff044b..48f451bc 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -678,23 +678,21 @@ namespace Vocaluxe.Lib.Draw /// public STexture CopyScreen() { - STexture texture = new STexture(-1); + STexture texture = new STexture(-1, _W, _H); + texture.W2 = _CheckForNextPowerOf2(_W); + texture.H2 = _CheckForNextPowerOf2(_H); + + texture.WidthRatio = (float)texture.OrigSize.Width / texture.W2; + texture.HeightRatio = (float)texture.OrigSize.Height / texture.H2; Surface backbufferSurface = _Device.GetBackBuffer(0, 0); - Texture tex = new Texture(_Device, _PresentParameters.BackBufferWidth, _PresentParameters.BackBufferHeight, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Surface textureSurface = tex.GetSurfaceLevel(0); - Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0); + Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0, new Rectangle(0, 0, _W, _H), new Rectangle(0, 0, _W, _H)); backbufferSurface.Dispose(); lock (_MutexTexture) { _D3DTextures.Add(_IDs.Peek(), tex); - - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); - texture.Width = _W; - texture.Height = _H; - texture.W2 = _CheckForNextPowerOf2(texture.Width); - texture.H2 = _CheckForNextPowerOf2(texture.Height); texture.Index = _IDs.Dequeue(); _Textures[texture.Index] = texture; @@ -708,7 +706,8 @@ namespace Vocaluxe.Lib.Draw /// The texture in which the frame is copied to public void CopyScreen(ref STexture texture) { - if (!_TextureExists(ref texture) || texture.Width != GetScreenWidth() || texture.Height != GetScreenHeight()) + //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()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -924,9 +923,9 @@ namespace Vocaluxe.Lib.Draw public STexture AddTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1); + STexture texture = new STexture(-1, w, h); - Texture t = _CreateTexture(w, h, data, ref texture); + Texture t = _CreateTexture(data, ref texture); lock (_MutexTexture) { @@ -937,10 +936,10 @@ namespace Vocaluxe.Lib.Draw return texture; } - private Texture _CreateTexture(int w, int h, byte[] data, ref STexture texture) + private Texture _CreateTexture(byte[] data, ref STexture texture) { - texture.Width = w; - texture.Height = h; + int w = texture.OrigSize.Width; + int h = texture.OrigSize.Height; texture.W2 = _CheckForNextPowerOf2(w); texture.H2 = _CheckForNextPowerOf2(h); texture.WidthRatio = (float)w / texture.W2; @@ -957,14 +956,12 @@ namespace Vocaluxe.Lib.Draw int rowWidth = 4 * texture.W2; for (int i = 0; i + rowWidth <= data.Length; i += 4 * w) { - rect.Data.Write(data, i, rowWidth); + rect.Data.Write(data, i, 4 * w); rect.Data.Position = rect.Data.Position - rowWidth; rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; } catch (Exception) @@ -978,12 +975,9 @@ namespace Vocaluxe.Lib.Draw public STexture EnqueueTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1); + STexture texture = new STexture(-1, w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; - texture.Height = h; - texture.Width = w; - lock (_MutexTexture) { _D3DTextures.Add(_IDs.Peek(), null); @@ -1010,37 +1004,17 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); - int w = texture.Width; - for (int i = 0; i < data.Length; i += 4 * w) + 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 -= 4 * w; + rect.Data.Position = rect.Data.Position - rowWidth; rect.Data.Position += rect.Pitch; } _D3DTextures[texture.Index].UnlockRectangle(0); } - - //Flamefire: Unneccesary as height can not be changed by this! (Texture gets copied) - //Texture.height_ratio = Texture.height / CheckForNextPowerOf2(Texture.height); - //Texture.width_ratio = Texture.width / CheckForNextPowerOf2(Texture.width); return true; - - /*Surface s = _D3DTextures[Texture.index].GetSurfaceLevel(0); - DataRectangle d = s.LockRectangle(LockFlags.Discard); - - for (int i = 0; i < Data.Length; ) - { - d.Data.Write(Data, i, 4 * (int)Texture.width); - i += 4 * (int)Texture.width; - d.Data.Position = d.Data.Position - 4 * (int)Texture.width; - d.Data.Position += d.Pitch; - } - - Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); - Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); - - s.UnlockRectangle(); - return true; */ } return false; } @@ -1351,11 +1325,15 @@ namespace Vocaluxe.Lib.Draw if (!_Textures.ContainsKey(q.ID)) continue; STexture texture = _Textures[q.ID]; + if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) + { + Texture t = _CreateTexture(q.Data, ref texture); + _D3DTextures[q.ID] = t; - Texture t = _CreateTexture(q.Width, q.Height, q.Data, ref texture); - _D3DTextures[q.ID] = t; - - _Textures[texture.Index] = texture; + _Textures[texture.Index] = texture; + } + else + CLog.LogError("Wrong texture size in queue!"); } } } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 1a8a5f80..ade2012b 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -291,18 +291,11 @@ namespace Vocaluxe.Lib.Draw public STexture CopyScreen() { - STexture texture = new STexture(0); Bitmap bmp = new Bitmap(_Backbuffer); _Bitmaps.Add(bmp); - - texture.Index = _Bitmaps.Count - 1; - - texture.Width = bmp.Width; - texture.Height = bmp.Height; + STexture texture = new STexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); _Textures.Add(texture); return texture; @@ -310,7 +303,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref STexture texture) { - if (texture.Index == 0 || texture.Width != GetScreenWidth() || texture.Height != GetScreenHeight()) + if (texture.Index == 0 || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -344,10 +337,9 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - STexture texture = new STexture {Index = _Bitmaps.Count - 1, Width = bmp.Width, Height = bmp.Height, Color = new SColorF(1f, 1f, 1f, 1f)}; + STexture texture = new STexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; _Textures.Add(texture); diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 653dc770..0047ecf1 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -490,23 +490,20 @@ namespace Vocaluxe.Lib.Draw public STexture CopyScreen() { - STexture texture = new STexture(-1); - + STexture texture = new STexture(-1, _W, _H); int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - texture.Width = _W; - texture.Height = _H; - texture.W2 = MathHelper.NextPowerOfTwo(texture.Width); - texture.H2 = MathHelper.NextPowerOfTwo(texture.Height); + texture.W2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Width); + texture.H2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Height); - texture.WidthRatio = (float)texture.Width / texture.W2; - texture.HeightRatio = (float)texture.Height / texture.H2; + texture.WidthRatio = (float)texture.OrigSize.Width / texture.W2; + texture.HeightRatio = (float)texture.OrigSize.Height / texture.H2; 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, texture.Width, texture.Height); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, _X, _Y, _W, _H); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); @@ -514,8 +511,6 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, 0); // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); lock (_MutexTexture) { @@ -528,7 +523,8 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref STexture texture) { - if (!_TextureExists(ref texture) || Math.Abs(texture.Width - GetScreenWidth()) > 1 || Math.Abs(texture.Height - GetScreenHeight()) > 1) + //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()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -537,7 +533,7 @@ namespace Vocaluxe.Lib.Draw { GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.Width, texture.Height); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -679,10 +675,8 @@ namespace Vocaluxe.Lib.Draw public STexture AddTexture(Bitmap bmp) { - STexture texture = new STexture(-1); - if (bmp.Height == 0 || bmp.Width == 0) - return texture; + return new STexture(-1); int maxSize; switch (CConfig.TextureQuality) @@ -726,13 +720,12 @@ namespace Vocaluxe.Lib.Draw h = maxSize; } + STexture texture = new STexture(-1, w, h); + int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - texture.Width = w; - texture.Height = h; - texture.W2 = MathHelper.NextPowerOfTwo(w); texture.H2 = MathHelper.NextPowerOfTwo(h); try @@ -773,8 +766,6 @@ namespace Vocaluxe.Lib.Draw // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; lock (_MutexTexture) @@ -788,9 +779,9 @@ namespace Vocaluxe.Lib.Draw public STexture AddTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1); + STexture texture = new STexture(-1, w, h); - _CreateTexture(w, h, data, ref texture); + _CreateTexture(data, ref texture); lock (_MutexTexture) { @@ -801,8 +792,10 @@ namespace Vocaluxe.Lib.Draw return texture; } - private void _CreateTexture(int w, int h, byte[] data, ref STexture texture) + private void _CreateTexture(byte[] data, ref STexture texture) { + int w = texture.OrigSize.Width; + int h = texture.OrigSize.Height; if (_UsePBO) { try @@ -823,13 +816,11 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - texture.Width = w; - texture.Height = h; - texture.W2 = MathHelper.NextPowerOfTwo(texture.Width); - texture.H2 = MathHelper.NextPowerOfTwo(texture.Height); + texture.W2 = MathHelper.NextPowerOfTwo(w); + texture.H2 = MathHelper.NextPowerOfTwo(h); - texture.WidthRatio = (float)texture.Width / texture.W2; - texture.HeightRatio = (float)texture.Height / texture.H2; + texture.WidthRatio = (float)w / texture.W2; + texture.HeightRatio = (float)h / texture.H2; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); @@ -847,19 +838,14 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, 0); // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); - texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; } public STexture EnqueueTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1); + STexture texture = new STexture(-1, w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; - texture.Height = h; - texture.Width = w; - lock (_MutexTexture) { texture.Index = _IDs.Dequeue(); @@ -887,7 +873,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.Width, texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + 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); @@ -897,7 +883,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.Width, texture.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); + 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); @@ -976,100 +962,100 @@ namespace Vocaluxe.Lib.Draw if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) return; - if (_TextureExists(ref texture)) + if (!_TextureExists(ref texture)) + return; + + 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 * texture.HeightRatio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > texture.WidthRatio) + x2 = texture.WidthRatio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > texture.HeightRatio) + y2 = texture.HeightRatio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y) + ry1 = bounds.Y; + + if (ry2 > bounds.Y + bounds.H) + ry2 = bounds.Y + bounds.H; + + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + + GL.MatrixMode(MatrixMode.Texture); + GL.PushMatrix(); + + if (Math.Abs(rect.Rotation) > float.Epsilon) { - GL.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 * texture.HeightRatio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > texture.WidthRatio) - x2 = texture.WidthRatio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > texture.HeightRatio) - y2 = texture.HeightRatio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y) - ry1 = bounds.Y; - - if (ry2 > bounds.Y + bounds.H) - ry2 = bounds.Y + bounds.H; - - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - - GL.MatrixMode(MatrixMode.Texture); - GL.PushMatrix(); - - if (Math.Abs(rect.Rotation) > float.Epsilon) - { - GL.Translate(0.5f, 0.5f, 0); - GL.Rotate(-rect.Rotation, 0f, 0f, 1f); - GL.Translate(-0.5f, -0.5f, 0); - } - - if (!mirrored) - { - 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.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); } public void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) @@ -1220,9 +1206,14 @@ namespace Vocaluxe.Lib.Draw if (texture.Index < 1) continue; - _CreateTexture(q.Width, q.Height, q.Data, ref texture); + if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) + { + _CreateTexture(q.Data, ref texture); - _Textures[texture.Index] = texture; + _Textures[texture.Index] = texture; + } + else + CLog.LogError("Wrong texture size in queue!"); } } } diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index 7beeb29c..77f6592a 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -661,7 +661,7 @@ namespace Vocaluxe.Lib.Video if (num >= 0) { - if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) + if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _FrameBuffer[num].Data); diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 5bfcf8a5..4c411cc2 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -121,7 +121,7 @@ namespace Vocaluxe.Lib.Video { if (data == null) return; - if (frame.Index == -1 || width != frame.Width || height != frame.Height || data.Length == 0) + if (frame.Index == -1 || width != frame.OrigSize.Width || height != frame.OrigSize.Height || data.Length == 0) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(width, height, data); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 14ef1782..e2589dfe 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -56,7 +56,7 @@ namespace Vocaluxe.Lib.Webcam { lock (_MutexData) { - if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) + if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, _Data); diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 3f2367bd..e5d3e81c 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -50,8 +50,8 @@ namespace Vocaluxe.Screens _Image = image; _ImgDot = imgDot; _Particle = particle; - _ParticleOffsetX = (int)Math.Round(particleOffsetX * image.Rect.W / image.Texture.Width - particle.Rect.W / 2); - _ParticleOffsetY = (int)Math.Round(particleOffsetY * image.Rect.H / image.Texture.Height - particle.Rect.H / 2); + _ParticleOffsetX = (int)Math.Round(particleOffsetX * image.Rect.W / image.Texture.OrigSize.Width - particle.Rect.W / 2); + _ParticleOffsetY = (int)Math.Round(particleOffsetY * image.Rect.H / image.Texture.OrigSize.Height - particle.Rect.H / 2); Active = true; } @@ -317,7 +317,8 @@ namespace Vocaluxe.Screens base.OnShow(); //Vocaluxe-Logo - _Logo = GetNewStatic(_TexLogo, new SColorF(1, 1, 1, 1), new SRectF((float)(CSettings.RenderW - _TexLogo.Width) / 2, -270, _TexLogo.Width, _TexLogo.Height, -2)); + _Logo = GetNewStatic(_TexLogo, new SColorF(1, 1, 1, 1), + new SRectF((float)(CSettings.RenderW - _TexLogo.OrigSize.Width) / 2, -270, _TexLogo.OrigSize.Width, _TexLogo.OrigSize.Height, -2)); //Little stars for logo int numstars = (int)(_Logo.Rect.W * 0.25f / 2f); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index c6dbd9d4..166dd841 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -469,7 +469,7 @@ namespace Vocaluxe.Screens background = _Background; RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)background.Width / background.Height, aspect); + 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)); diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index c63aeb24..073325ea 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -203,11 +203,11 @@ namespace VocaluxeLib.Menu private bool _DrawTexture() { STexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); - if (texture.Height > 0) + if (texture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)texture.Width / texture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -218,11 +218,11 @@ namespace VocaluxeLib.Menu private bool _DrawVideo() { STexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); - if (videoTexture.Height > 0) + if (videoTexture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)videoTexture.Width / videoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, videoTexture.OrigAspect, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -233,11 +233,11 @@ namespace VocaluxeLib.Menu private bool _DrawBackgroundMusicVideo() { STexture videoTexture = CBase.BackgroundMusic.GetVideoTexture(); - if (videoTexture.Height > 0) + if (videoTexture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)videoTexture.Width / videoTexture.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, videoTexture.OrigAspect, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index d5a1f6f3..3a56a25f 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -253,7 +253,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); RectangleF rect2; - CHelper.SetRect(bounds2, out rect2, (float)texture.Width / texture.Height, aspect); + CHelper.SetRect(bounds2, out rect2, texture.OrigAspect, aspect); rect.X = rect2.X; rect.Y = rect2.Y; diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index 4fab9280..f5e68c61 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -481,7 +481,7 @@ namespace VocaluxeLib.Menu.SingNotes //Width of each of the ends (round parts) //Need 2 of them so use minimum - float endsW = Math.Min(noteRect.H * noteBegin.Width / noteBegin.Height, noteRect.W / 2); + float endsW = Math.Min(noteRect.H * noteBegin.OrigAspect, noteRect.W / 2); CBase.Drawing.DrawTexture(noteBegin, new SRectF(noteRect.X, noteRect.Y, endsW, noteRect.H, noteRect.Z), color); @@ -526,7 +526,7 @@ namespace VocaluxeLib.Menu.SingNotes STexture noteBackgroundMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundMiddleName, _PartyModeID); STexture noteBackgroundEnd = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundRightName, _PartyModeID); - float dx = noteBackgroundBegin.Width * r.H / noteBackgroundBegin.Height; + float dx = r.H * noteBackgroundBegin.OrigAspect; if (2 * dx > r.W) dx = r.W / 2; @@ -618,7 +618,7 @@ namespace VocaluxeLib.Menu.SingNotes ); STexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); - float dx = noteBegin.Width * r.H / noteBegin.Height; + float dx = r.H * noteBegin.OrigAspect; if (2 * dx > r.W) dx = r.W / 2; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index b5a65b20..cad9f32f 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -459,7 +459,7 @@ namespace VocaluxeLib.Menu.SongMenu _CoverBig.Draw(1f, EAspect.Crop); RectangleF bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); RectangleF rect; - CHelper.SetRect(bounds, out rect, (float)_Vidtex.Width / _Vidtex.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, _Vidtex.OrigAspect, EAspect.Crop); SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index 59ce099c..9af269b8 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -108,32 +108,47 @@ namespace VocaluxeLib.Menu public string TexturePath; - public int Width; - public int Height; + /// + /// Original size (e.g. of bmp) + /// + public readonly Size OrigSize; + public float OrigAspect + { + get { return (float)OrigSize.Width / OrigSize.Height; } + } + + /// + /// Current size when drawn + /// public SRectF Rect; - public int W2; //power of 2 width - public int H2; //power of 2 height + /// + /// Internal texture width (on device), a power of 2 if necessary + /// + public int W2; + /// + /// Internal texture height (on device), a power of 2 if necessary + /// + public int H2; public float WidthRatio; public float HeightRatio; public SColorF Color; - public STexture(int index) + public STexture(int index, int origWidth = 1, int origHeight = 1) { Index = index; PBO = 0; ID = -1; TexturePath = String.Empty; - Width = 1; - Height = 1; - Rect = new SRectF(0f, 0f, 1f, 1f, 0f); + OrigSize = new Size(origWidth, origHeight); + Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); - W2 = 1; - H2 = 1; - WidthRatio = 0.5f; - HeightRatio = 0.5f; + W2 = origWidth; + H2 = origHeight; + WidthRatio = 1; + HeightRatio = 1; Color = new SColorF(1f, 1f, 1f, 1f); } From f8fb7bda25fd1059933f8fa53e2dfba8cd15f1f6 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 22:38:19 +0200 Subject: [PATCH 06/22] Added auto property for W/H-Ratio --- Vocaluxe/Lib/Draw/CDirect3D.cs | 5 ---- Vocaluxe/Lib/Draw/COpenGL.cs | 13 +++------- VocaluxeLib/Menu/Structs.cs | 47 ++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 48f451bc..1f373d3b 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -682,9 +682,6 @@ namespace Vocaluxe.Lib.Draw texture.W2 = _CheckForNextPowerOf2(_W); texture.H2 = _CheckForNextPowerOf2(_H); - texture.WidthRatio = (float)texture.OrigSize.Width / texture.W2; - texture.HeightRatio = (float)texture.OrigSize.Height / texture.H2; - Surface backbufferSurface = _Device.GetBackBuffer(0, 0); Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Surface textureSurface = tex.GetSurfaceLevel(0); @@ -942,8 +939,6 @@ namespace Vocaluxe.Lib.Draw int h = texture.OrigSize.Height; texture.W2 = _CheckForNextPowerOf2(w); texture.H2 = _CheckForNextPowerOf2(h); - texture.WidthRatio = (float)w / texture.W2; - texture.HeightRatio = (float)h / texture.H2; //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 diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 0047ecf1..a30aa642 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -498,9 +498,6 @@ namespace Vocaluxe.Lib.Draw texture.W2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Width); texture.H2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Height); - texture.WidthRatio = (float)texture.OrigSize.Width / texture.W2; - texture.HeightRatio = (float)texture.OrigSize.Height / texture.H2; - 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); @@ -720,7 +717,7 @@ namespace Vocaluxe.Lib.Draw h = maxSize; } - STexture texture = new STexture(-1, w, h); + STexture texture = new STexture(-1, bmp.Width, bmp.Height); int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); @@ -738,8 +735,9 @@ namespace Vocaluxe.Lib.Draw g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); g.Dispose(); - texture.WidthRatio = 1f; - texture.HeightRatio = 1f; + //TODO: Check this! + //texture.WidthRatio = 1f; + //texture.HeightRatio = 1f; BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); @@ -819,9 +817,6 @@ namespace Vocaluxe.Lib.Draw texture.W2 = MathHelper.NextPowerOfTwo(w); texture.H2 = MathHelper.NextPowerOfTwo(h); - texture.WidthRatio = (float)w / texture.W2; - texture.HeightRatio = (float)h / texture.H2; - 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); diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index 9af269b8..9a7827cf 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -122,18 +122,45 @@ namespace VocaluxeLib.Menu /// public SRectF Rect; + public SColorF Color; + + private int _W2, _H2; + private float _WidthRatio, _HeightRatio; /// /// Internal texture width (on device), a power of 2 if necessary /// - public int W2; + public int W2 + { + get { return _W2; } + set + { + _W2 = value; + WidthRatio = (float)OrigSize.Width / _W2; + } + } /// /// Internal texture height (on device), a power of 2 if necessary /// - public int H2; - public float WidthRatio; - public float HeightRatio; + public int H2 + { + get { return _H2; } + set + { + _H2 = value; + HeightRatio = (float)OrigSize.Height / _H2; + } + } - public SColorF Color; + public float WidthRatio + { + get { return _WidthRatio; } + private set { _WidthRatio = value; } + } + public float HeightRatio + { + get { return _HeightRatio; } + private set { _HeightRatio = value; } + } public STexture(int index, int origWidth = 1, int origHeight = 1) { @@ -145,12 +172,12 @@ namespace VocaluxeLib.Menu OrigSize = new Size(origWidth, origHeight); Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); - W2 = origWidth; - H2 = origHeight; - WidthRatio = 1; - HeightRatio = 1; - Color = new SColorF(1f, 1f, 1f, 1f); + + _W2 = origWidth; + _H2 = origHeight; + _WidthRatio = 1; + _HeightRatio = 1; } } #endregion Drawing From 5aeea59e76648e5644ee0e9b2650c3eb530691d3 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 23:02:23 +0200 Subject: [PATCH 07/22] Fixed wrong sizes for resized textures --- Vocaluxe/Lib/Draw/COpenGL.cs | 6 +----- VocaluxeLib/Menu/Structs.cs | 37 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index a30aa642..ae62cecb 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -717,7 +717,7 @@ namespace Vocaluxe.Lib.Draw h = maxSize; } - STexture texture = new STexture(-1, bmp.Width, bmp.Height); + STexture texture = new STexture(-1, bmp.Width, bmp.Height){UseFullTexture = true}; int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); @@ -735,10 +735,6 @@ namespace Vocaluxe.Lib.Draw g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); g.Dispose(); - //TODO: Check this! - //texture.WidthRatio = 1f; - //texture.HeightRatio = 1f; - BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index 9a7827cf..fef94d82 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -126,6 +126,7 @@ namespace VocaluxeLib.Menu private int _W2, _H2; private float _WidthRatio, _HeightRatio; + private bool _UseFullTexture; /// /// Internal texture width (on device), a power of 2 if necessary /// @@ -135,7 +136,8 @@ namespace VocaluxeLib.Menu set { _W2 = value; - WidthRatio = (float)OrigSize.Width / _W2; + if (!_UseFullTexture) + WidthRatio = (float)OrigSize.Width / _W2; } } /// @@ -147,21 +149,51 @@ namespace VocaluxeLib.Menu set { _H2 = value; - HeightRatio = (float)OrigSize.Height / _H2; + if (!_UseFullTexture) + HeightRatio = (float)OrigSize.Height / _H2; } } + /// + /// Internal use. Specifies which part of texture memory is actually used + /// public float WidthRatio { get { return _WidthRatio; } private set { _WidthRatio = value; } } + /// + /// Internal use. Specifies which part of texture memory is actually used + /// public float HeightRatio { get { return _HeightRatio; } private set { _HeightRatio = value; } } + /// + /// Internal use. Specifies if full texture memory should be used + /// Set to true if you resized the original image to the maximum + /// + public bool UseFullTexture + { + get { return _UseFullTexture; } + set + { + _UseFullTexture = value; + if (value) + { + WidthRatio = 1; + HeightRatio = 1; + } + else + { + WidthRatio = (float)OrigSize.Width / _W2; + HeightRatio = (float)OrigSize.Height / _H2; + } + } + } + public STexture(int index, int origWidth = 1, int origHeight = 1) { Index = index; @@ -178,6 +210,7 @@ namespace VocaluxeLib.Menu _H2 = origHeight; _WidthRatio = 1; _HeightRatio = 1; + _UseFullTexture = false; } } #endregion Drawing From 55ef3a0050ae39dccc7424fac195e23d280f63e1 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 23:56:08 +0200 Subject: [PATCH 08/22] Use maximum possible resolution for bmp->texture --- Vocaluxe/Lib/Draw/CDirect3D.cs | 69 +++++++++++++--------------------- Vocaluxe/Lib/Draw/COpenGL.cs | 34 +++++------------ 2 files changed, 35 insertions(+), 68 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 1f373d3b..241a05b3 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -857,49 +857,31 @@ namespace Vocaluxe.Lib.Draw break; } - int w = bmp.Width; - int h = bmp.Height; - float ratio = (float)w / h; - int newW = w; - int newH = h; + STexture texture = new STexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; - if (w > maxSize && w > h) - newW = maxSize; - else if (h > maxSize) - newH = maxSize; - else if (w > h) - newW = _CheckForNextPowerOf2(w); - else - newH = _CheckForNextPowerOf2(h); + int w = Math.Min(bmp.Width, maxSize); + int h = Math.Min(bmp.Height, maxSize); + w = _CheckForNextPowerOf2(w); + h = _CheckForNextPowerOf2(h); + + texture.W2 = w; + texture.H2 = h; Bitmap bmp2 = null; byte[] data; try { - if (w != newW || h != newH) + if (bmp.Width != w || bmp.Height != h) { - if (w != newW) - { - w = newW; - h = (int)Math.Round(w / ratio); - if (h == 0) - h = 1; - } - else - { - h = newH; - w = (int)Math.Round(h * ratio); - if (w == 0) - w = 1; - } //Create a new Bitmap with the new sizes bmp2 = new Bitmap(w, h); //Scale the texture - Graphics g = Graphics.FromImage(bmp2); - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.SmoothingMode = SmoothingMode.HighQuality; - g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); - g.Dispose(); + using (Graphics g = Graphics.FromImage(bmp2)) + { + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.SmoothingMode = SmoothingMode.HighQuality; + g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); + } bmp = bmp2; } @@ -915,14 +897,18 @@ namespace Vocaluxe.Lib.Draw bmp2.Dispose(); } - return AddTexture(w, h, data); + return _AddTexture(texture, w, data); } public STexture AddTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1, w, h); + STexture texture = new STexture(-1, w, h) {W2 = _CheckForNextPowerOf2(w), H2 = _CheckForNextPowerOf2(h)}; + return _AddTexture(texture, w, data); + } - Texture t = _CreateTexture(data, ref texture); + private STexture _AddTexture(STexture texture, int w, byte[] data) + { + Texture t = _CreateTexture(ref texture, w, data); lock (_MutexTexture) { @@ -933,13 +919,8 @@ namespace Vocaluxe.Lib.Draw return texture; } - private Texture _CreateTexture(byte[] data, ref STexture texture) + private Texture _CreateTexture(ref STexture texture, int w, byte[] data) { - int w = texture.OrigSize.Width; - int h = texture.OrigSize.Height; - texture.W2 = _CheckForNextPowerOf2(w); - texture.H2 = _CheckForNextPowerOf2(h); - //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 Texture t = null; @@ -1322,7 +1303,9 @@ namespace Vocaluxe.Lib.Draw STexture texture = _Textures[q.ID]; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) { - Texture t = _CreateTexture(q.Data, ref texture); + 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; diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index ae62cecb..625558ae 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -698,42 +698,26 @@ namespace Vocaluxe.Lib.Draw break; } - int w = bmp.Width; - int h = bmp.Height; - - if (w > maxSize) - { - h = (int)Math.Round((float)maxSize / bmp.Width * bmp.Height); - if (h == 0) - h = 1; - w = maxSize; - } - - if (h > maxSize) - { - w = (int)Math.Round((float)maxSize / bmp.Height * bmp.Width); - if (w == 0) - w = 1; - h = maxSize; - } - - STexture texture = new STexture(-1, bmp.Width, bmp.Height){UseFullTexture = true}; + STexture texture = new STexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; + int w = Math.Min(bmp.Width, maxSize); + int h = Math.Min(bmp.Height, maxSize); texture.W2 = MathHelper.NextPowerOfTwo(w); texture.H2 = MathHelper.NextPowerOfTwo(h); try { using (Bitmap bmp2 = new Bitmap(texture.W2, texture.H2)) { - Graphics g = Graphics.FromImage(bmp2); - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.SmoothingMode = SmoothingMode.HighQuality; - g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); - g.Dispose(); + using (Graphics g = Graphics.FromImage(bmp2)) + { + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.SmoothingMode = SmoothingMode.HighQuality; + g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); + } BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); From 6083d58499631c094e61138d28b9ff4a52d2e2b7 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 23:59:08 +0200 Subject: [PATCH 09/22] Only resize bmp if necessary --- Vocaluxe/Lib/Draw/COpenGL.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 625558ae..4cfb9866 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -708,30 +708,33 @@ namespace Vocaluxe.Lib.Draw int h = Math.Min(bmp.Height, maxSize); texture.W2 = MathHelper.NextPowerOfTwo(w); texture.H2 = MathHelper.NextPowerOfTwo(h); + + Bitmap bmp2 = null; try { - using (Bitmap bmp2 = new Bitmap(texture.W2, texture.H2)) + if (bmp.Width != w || bmp.Height != h) { + //Create a new Bitmap with the new sizes + bmp2 = new Bitmap(w, h); + //Scale the texture using (Graphics g = Graphics.FromImage(bmp2)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); } - - BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - 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, bmpData.Width, bmpData.Height, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); - - bmp2.UnlockBits(bmpData); + bmp = bmp2; } + + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + 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, bmpData.Width, bmpData.Height, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); + bmp.UnlockBits(bmpData); } - catch + finally { - CLog.LogError(w + " " + h + " " + texture.W2 + " " + texture.H2); - throw; + if (bmp2 != null) + bmp2.Dispose(); } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); From 017b96be5fb00493f96e89505d6c38fd8c66db45 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 4 May 2013 14:20:44 +0200 Subject: [PATCH 10/22] Bugfix for OpenGL (missing real bmp size) --- Vocaluxe/Lib/Draw/COpenGL.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 4cfb9866..3cdd6c02 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -706,8 +706,11 @@ namespace Vocaluxe.Lib.Draw int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); - texture.W2 = MathHelper.NextPowerOfTwo(w); - texture.H2 = MathHelper.NextPowerOfTwo(h); + w = MathHelper.NextPowerOfTwo(w); + h = MathHelper.NextPowerOfTwo(h); + + texture.W2 = w; + texture.H2 = h; Bitmap bmp2 = null; try From f370693dde80f3f6b1e306d52d1d9688a6a865c6 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 4 May 2013 15:14:02 +0200 Subject: [PATCH 11/22] Convert STexture to class CTexture --- Vocaluxe/Base/CBackgroundMusic.cs | 11 +- Vocaluxe/Base/CCover.cs | 13 +- Vocaluxe/Base/CDataBase.cs | 5 +- Vocaluxe/Base/CDraw.cs | 31 ++--- Vocaluxe/Base/CGraphics.cs | 3 +- Vocaluxe/Base/CMain.cs | 23 ++-- Vocaluxe/Base/CProfiles.cs | 5 +- Vocaluxe/Base/CTheme.cs | 17 +-- Vocaluxe/Base/CVideo.cs | 9 +- Vocaluxe/Base/CWebcam.cs | 3 +- Vocaluxe/Base/Fonts/CFont.cs | 7 +- Vocaluxe/Base/Fonts/CGlyph.cs | 5 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 59 ++++----- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 41 +++--- Vocaluxe/Lib/Draw/COpenGL.cs | 55 ++++---- Vocaluxe/Lib/Draw/IDraw.cs | 29 +++-- Vocaluxe/Lib/Video/CVideoDecoder.cs | 3 +- Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 7 +- Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 5 +- Vocaluxe/Lib/Video/IVideoDecoder.cs | 3 +- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 3 +- Vocaluxe/Lib/Webcam/IWebcam.cs | 3 +- Vocaluxe/Screens/CScreenCredits.cs | 31 ++--- Vocaluxe/Screens/CScreenNames.cs | 3 +- Vocaluxe/Screens/CScreenOptionsVideo.cs | 3 +- Vocaluxe/Screens/CScreenProfiles.cs | 3 +- Vocaluxe/Screens/CScreenScore.cs | 3 +- Vocaluxe/Screens/CScreenSing.cs | 15 ++- VocaluxeLib/Draw/CTexture.cs | 120 ++++++++++++++++++ VocaluxeLib/Menu/CBackground.cs | 7 +- VocaluxeLib/Menu/CButton.cs | 11 +- VocaluxeLib/Menu/CMenu.cs | 5 +- VocaluxeLib/Menu/CNameSelection.cs | 5 +- VocaluxeLib/Menu/CParticle.cs | 15 ++- VocaluxeLib/Menu/CScreenSetting.cs | 3 +- VocaluxeLib/Menu/CSelectSlide.cs | 37 +++--- VocaluxeLib/Menu/CStatic.cs | 13 +- VocaluxeLib/Menu/IMenu.cs | 23 ++-- VocaluxeLib/Menu/SingNotes/CSingNotes.cs | 17 +-- VocaluxeLib/Menu/SongMenu/CCategory.cs | 11 +- VocaluxeLib/Menu/SongMenu/CSong.cs | 9 +- .../Menu/SongMenu/CSongMenuFramework.cs | 5 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 5 +- VocaluxeLib/Menu/Structs.cs | 119 +---------------- VocaluxeLib/VocaluxeLib.csproj | 1 + 45 files changed, 427 insertions(+), 377 deletions(-) create mode 100644 VocaluxeLib/Draw/CTexture.cs diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 40b3c014..b898514d 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -39,7 +40,7 @@ namespace Vocaluxe.Base private static readonly List _PreviousFileNames = new List(); private static int _Video = -1; - private static STexture _CurrentVideoTexture = new STexture(-1); + private static CTexture _CurrentVideoTexture = new CTexture(-1); private static readonly Stopwatch _FadeTimer = new Stopwatch(); private static bool _VideoEnabled; @@ -118,7 +119,7 @@ namespace Vocaluxe.Base } } - public static STexture Cover + public static CTexture Cover { get { return _CurrentPlaylistElement.Cover; } } @@ -457,7 +458,7 @@ namespace Vocaluxe.Base _LoadVideo(); } - public static STexture GetVideoTexture() + public static CTexture GetVideoTexture() { if (_Video != -1) { @@ -472,7 +473,7 @@ namespace Vocaluxe.Base } return _CurrentVideoTexture; } - return new STexture(-1); + return new CTexture(-1); } private static bool _IsBackgroundFile(CPlaylistElement element) @@ -576,7 +577,7 @@ namespace Vocaluxe.Base } } - public STexture Cover + public CTexture Cover { get { diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 24f80d64..c39928f5 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -23,6 +23,7 @@ using System.IO; using System.Linq; using System.Text; using System.Xml; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -31,7 +32,7 @@ namespace Vocaluxe.Base { public string Name; public string Value; - public STexture Texture; + public CTexture Texture; } struct SCoverTheme @@ -46,11 +47,11 @@ 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 STexture _NoCover = new STexture(-1); + private static CTexture _NoCover = new CTexture(-1); private static readonly Object _MutexCover = new Object(); - public static STexture NoCover + public static CTexture NoCover { get { return _NoCover; } } @@ -97,9 +98,9 @@ namespace Vocaluxe.Base /// /// Returns a STexture for a given cover name. Returns "NoCover" if the cover does not exist. /// - public static STexture Cover(string name) + public static CTexture Cover(string name) { - STexture cov = _NoCover; + CTexture cov = _NoCover; lock (_MutexCover) { foreach (SCover cover in _Cover) @@ -132,7 +133,7 @@ namespace Vocaluxe.Base { foreach (SCover cover in _Cover) { - STexture texture = cover.Texture; + CTexture texture = cover.Texture; CDraw.RemoveTexture(ref texture); } _Cover.Clear(); diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 008542ef..c59e04a3 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -35,6 +35,7 @@ using SQLiteCommand = Mono.Data.Sqlite.SqliteCommand; using SQLiteDataReader = Mono.Data.Sqlite.SqliteDataReader; #endif using Community.CsharpSqlite; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -912,7 +913,7 @@ namespace Vocaluxe.Base #endregion Highscores #region Cover - public static bool GetCover(string coverPath, ref STexture tex, int maxSize) + public static bool GetCover(string coverPath, ref CTexture tex, int maxSize) { if (!File.Exists(coverPath)) { @@ -1141,7 +1142,7 @@ namespace Vocaluxe.Base #endregion Cover #region CreditsRessources - public static bool GetCreditsRessource(string fileName, ref STexture tex) + public static bool GetCreditsRessource(string fileName, ref CTexture tex) { bool result = false; diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 41a323e3..921c772a 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -20,6 +20,7 @@ using System; using System.Drawing; using Vocaluxe.Lib.Draw; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -124,12 +125,12 @@ namespace Vocaluxe.Base _Draw.ClearScreen(); } - public static STexture CopyScreen() + public static CTexture CopyScreen() { return _Draw.CopyScreen(); } - public static void CopyScreen(ref STexture texture) + public static void CopyScreen(ref CTexture texture) { _Draw.CopyScreen(ref texture); } @@ -139,62 +140,62 @@ namespace Vocaluxe.Base _Draw.MakeScreenShot(); } - public static STexture AddTexture(Bitmap bitmap) + public static CTexture AddTexture(Bitmap bitmap) { return _Draw.AddTexture(bitmap); } - public static STexture AddTexture(string texturePath) + public static CTexture AddTexture(string texturePath) { return _Draw.AddTexture(texturePath); } - public static STexture AddTexture(int w, int h, byte[] data) + public static CTexture AddTexture(int w, int h, byte[] data) { return _Draw.AddTexture(w, h, data); } - public static STexture EnqueueTexture(int w, int h, byte[] data) + public static CTexture EnqueueTexture(int w, int h, byte[] data) { return _Draw.EnqueueTexture(w, h, data); } - public static bool UpdateTexture(ref STexture texture, byte[] data) + public static bool UpdateTexture(ref CTexture texture, byte[] data) { return _Draw.UpdateTexture(ref texture, data); } - public static void RemoveTexture(ref STexture texture) + public static void RemoveTexture(ref CTexture texture) { _Draw.RemoveTexture(ref texture); } - public static void DrawTexture(STexture texture) + public static void DrawTexture(CTexture texture) { _Draw.DrawTexture(texture); } - public static void DrawTexture(STexture texture, SRectF rect) + public static void DrawTexture(CTexture texture, SRectF rect) { _Draw.DrawTexture(texture, rect); } - public static void DrawTexture(STexture texture, SRectF rect, SColorF color, bool mirrored = false) + public static void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false) { _Draw.DrawTexture(texture, rect, color, mirrored); } - public static void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + public static void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { _Draw.DrawTexture(texture, rect, color, bounds, mirrored); } - public static void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) + public static void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) { _Draw.DrawTexture(texture, rect, color, begin, end); } - public static void DrawTexture(CStatic staticBounds, STexture texture, EAspect aspect) + public static void DrawTexture(CStatic staticBounds, CTexture texture, EAspect aspect) { if (texture.OrigSize.Height <= 0) return; @@ -207,7 +208,7 @@ namespace Vocaluxe.Base texture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); } - public static void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) + public static void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { _Draw.DrawTextureReflection(texture, rect, color, bounds, space, height); } diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index cbb268c6..efb5404a 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -24,6 +24,7 @@ using System.Drawing; using System.Windows.Forms; using Vocaluxe.Base.Fonts; using Vocaluxe.Screens; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; @@ -35,7 +36,7 @@ namespace Vocaluxe.Base private float _CursorTargetAlpha; private float _CursorStartAlpha; private float _CursorFadingTime; - private STexture _Cursor; + private CTexture _Cursor; private readonly string _CursorName = String.Empty; private readonly Stopwatch _Movetimer; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 1a4cc94a..3f844ef5 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using Vocaluxe.Base.Fonts; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -224,12 +225,12 @@ namespace Vocaluxe.Base return CTheme.GetSkinIndex(partyModeID); } - public STexture GetSkinTexture(string textureName, int partyModeID) + public CTexture GetSkinTexture(string textureName, int partyModeID) { return CTheme.GetSkinTexture(textureName, partyModeID); } - public STexture GetSkinVideoTexture(string videoName, int partyModeID) + public CTexture GetSkinVideoTexture(string videoName, int partyModeID) { return CTheme.GetSkinVideoTexture(videoName, partyModeID); } @@ -332,7 +333,7 @@ namespace Vocaluxe.Base CBackgroundMusic.ApplyVolume(); } - public STexture GetVideoTexture() + public CTexture GetVideoTexture() { return CBackgroundMusic.GetVideoTexture(); } @@ -340,27 +341,27 @@ namespace Vocaluxe.Base class CBdraw : IDrawing { - public void DrawTexture(STexture texture, SRectF rect) + public void DrawTexture(CTexture texture, SRectF rect) { CDraw.DrawTexture(texture, rect); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color) { CDraw.DrawTexture(texture, rect, color); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { CDraw.DrawTexture(texture, rect, color, bounds, mirrored); } - public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight) + public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight) { CDraw.DrawTextureReflection(texture, rect, color, bounds, reflectionSpace, reflectionHeight); } - public void RemoveTexture(ref STexture texture) + public void RemoveTexture(ref CTexture texture) { CDraw.RemoveTexture(ref texture); } @@ -680,7 +681,7 @@ namespace Vocaluxe.Base return CVideo.Skip(videoStream, startPosition, videoGap); } - public bool GetFrame(int videoStream, ref STexture videoTexture, float time, out float videoTime) + public bool GetFrame(int videoStream, ref CTexture videoTexture, float time, out float videoTime) { return CVideo.GetFrame(videoStream, ref videoTexture, time, out videoTime); } @@ -751,7 +752,7 @@ namespace Vocaluxe.Base class CBcover : ICover { - public STexture GetNoCover() + public CTexture GetNoCover() { return CCover.NoCover; } @@ -759,7 +760,7 @@ namespace Vocaluxe.Base class CBdataBase : IDataBase { - public bool GetCover(string fileName, ref STexture texture, int coverSize) + public bool GetCover(string fileName, ref CTexture texture, int coverSize) { return CDataBase.GetCover(fileName, ref texture, coverSize); } diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 2944b0e7..12320bd2 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using System.Xml; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -114,7 +115,7 @@ namespace Vocaluxe.Base { for (int i = 0; i < _Avatars.Count; i++) { - STexture texture = _Avatars[i].Texture; + CTexture texture = _Avatars[i].Texture; CDraw.RemoveTexture(ref texture); } _Avatars.Clear(); @@ -127,7 +128,7 @@ namespace Vocaluxe.Base foreach (string file in files) { - STexture tex = CDraw.AddTexture(file); + CTexture tex = CDraw.AddTexture(file); if (tex.Index != -1) { diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index d26b8813..ac5a5862 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -24,6 +24,7 @@ using System.Text; using System.Windows.Forms; using System.Xml; using Vocaluxe.Base.Fonts; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -48,7 +49,7 @@ namespace Vocaluxe.Base public string Name; public string Value; - public STexture Texture; + public CTexture Texture; public int VideoIndex; } @@ -202,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 STexture(-1); + sk.Texture = new CTexture(-1); _Skins[skinIndex].VideoList[i] = sk; } catch (Exception e) @@ -224,14 +225,14 @@ namespace Vocaluxe.Base { foreach (SSkinElement sk in _Skins[i].SkinList.Values) { - STexture texture = sk.Texture; + CTexture texture = sk.Texture; CDraw.RemoveTexture(ref texture); } for (int j = 0; j < _Skins[i].VideoList.Count; j++) { CVideo.Close(_Skins[i].VideoList[j].VideoIndex); - STexture videoTexture = _Skins[i].VideoList[j].Texture; + CTexture videoTexture = _Skins[i].VideoList[j].Texture; CDraw.RemoveTexture(ref videoTexture); } @@ -579,12 +580,12 @@ namespace Vocaluxe.Base return path; } - public static STexture GetSkinTexture(string textureName, int partyModeID) + public static CTexture GetSkinTexture(string textureName, int partyModeID) { int skinIndex = GetSkinIndex(partyModeID); if (skinIndex != -1 && textureName != null && _Skins[skinIndex].SkinList.ContainsKey(textureName)) return _Skins[skinIndex].SkinList[textureName].Texture; - return new STexture(-1); + return new CTexture(-1); } public static string GetSkinFilePath(string skinName, int partyModeID) @@ -604,7 +605,7 @@ namespace Vocaluxe.Base return skinName; } - public static STexture GetSkinVideoTexture(string videoName, int partyModeID) + public static CTexture GetSkinVideoTexture(string videoName, int partyModeID) { int skinIndex = GetSkinIndex(partyModeID); if (skinIndex != -1) @@ -626,7 +627,7 @@ namespace Vocaluxe.Base } } } - return new STexture(-1); + return new CTexture(-1); } public static void SkinVideoPause(string videoName, int partyModeID) diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 10c59af0..743d54d2 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -20,6 +20,7 @@ using System.Diagnostics; using System.Drawing; using Vocaluxe.Lib.Video; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -75,7 +76,7 @@ namespace Vocaluxe.Base return _VideoDecoder.GetLength(streamID); } - public static bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) + public static bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime) { return _VideoDecoder.GetFrame(streamID, ref frame, time, out videoTime); } @@ -116,7 +117,7 @@ namespace Vocaluxe.Base class CVideoPlayer { - private STexture _VideoTexture; + private CTexture _VideoTexture; private int _VideoStream; private readonly Stopwatch _VideoTimer; private bool _Finished; @@ -135,7 +136,7 @@ namespace Vocaluxe.Base public CVideoPlayer() { _VideoTimer = new Stopwatch(); - _VideoTexture = new STexture(-1); + _VideoTexture = new CTexture(-1); _Finished = false; _Loaded = false; } @@ -171,7 +172,7 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.Finished(_VideoStream); - STexture tex = new STexture(-1); + CTexture tex = new CTexture(-1); CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime); if (tex.Index > 0) diff --git a/Vocaluxe/Base/CWebcam.cs b/Vocaluxe/Base/CWebcam.cs index 0a361c68..677a2e36 100644 --- a/Vocaluxe/Base/CWebcam.cs +++ b/Vocaluxe/Base/CWebcam.cs @@ -19,6 +19,7 @@ using System.Drawing; using Vocaluxe.Lib.Webcam; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base @@ -46,7 +47,7 @@ namespace Vocaluxe.Base CConfig.SaveConfig(); } - public static bool GetFrame(ref STexture tex) + public static bool GetFrame(ref CTexture tex) { _Webcam.GetFrame(ref tex); return true; diff --git a/Vocaluxe/Base/Fonts/CFont.cs b/Vocaluxe/Base/Fonts/CFont.cs index 5ac016df..e4ccefa8 100644 --- a/Vocaluxe/Base/Fonts/CFont.cs +++ b/Vocaluxe/Base/Fonts/CFont.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Text; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base.Fonts @@ -86,7 +87,7 @@ namespace Vocaluxe.Base.Fonts public void DrawGlyph(char chr, float x, float y, float z, SColorF color) { - STexture texture; + CTexture texture; SRectF rect; GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); CDraw.DrawTexture(texture, rect, color); @@ -94,7 +95,7 @@ namespace Vocaluxe.Base.Fonts public void DrawGlyph(char chr, float x, float y, float z, SColorF color, float begin, float end) { - STexture texture; + CTexture texture; SRectF rect; GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); CDraw.DrawTexture(texture, rect, color, begin, end); @@ -102,7 +103,7 @@ namespace Vocaluxe.Base.Fonts public void DrawGlyphReflection(char chr, float x, float y, float z, SColorF color, float rspace, float rheight) { - STexture texture; + CTexture texture; SRectF rect; GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight); diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index af06252b..7842badc 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -23,13 +23,14 @@ using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.Runtime.InteropServices; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Base.Fonts { class CGlyph { - private STexture _Texture; + private CTexture _Texture; private readonly SizeF _BoundingBox; private readonly RectangleF _DrawBounding; public readonly float MaxHeight; @@ -147,7 +148,7 @@ namespace Vocaluxe.Base.Fonts return CFonts.Height / _BoundingBox.Height; } - public void GetTextureAndRect(float x, float y, float z, out STexture texture, out SRectF rect) + public void GetTextureAndRect(float x, float y, float z, out CTexture texture, out SRectF rect) { texture = _Texture; float factor = _GetFactor(); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 241a05b3..ce51146d 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -31,6 +31,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using SlimDX.Windows; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw @@ -50,7 +51,7 @@ namespace Vocaluxe.Lib.Draw private Size _OldSize; private Size _SizeBeforeMinimize; - private readonly Dictionary _Textures; + private readonly Dictionary _Textures; private readonly Dictionary _D3DTextures; private readonly List _Queue; private readonly Queue _IDs; @@ -65,7 +66,7 @@ namespace Vocaluxe.Lib.Draw private int _Y; private int _X; - private STexture _BlankTexture; + private CTexture _BlankTexture; private readonly Queue _Vertices; private readonly Queue _VerticesTextures; @@ -80,7 +81,7 @@ namespace Vocaluxe.Lib.Draw public CDirect3D() { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new Dictionary(); + _Textures = new Dictionary(); _D3DTextures = new Dictionary(); _Queue = new List(); _IDs = new Queue(); @@ -676,9 +677,9 @@ namespace Vocaluxe.Lib.Draw /// Copies the current frame into a texture /// A texture holding the current frame /// - public STexture CopyScreen() + public CTexture CopyScreen() { - STexture texture = new STexture(-1, _W, _H); + CTexture texture = new CTexture(-1, _W, _H); texture.W2 = _CheckForNextPowerOf2(_W); texture.H2 = _CheckForNextPowerOf2(_H); @@ -701,7 +702,7 @@ namespace Vocaluxe.Lib.Draw /// Copies the current frame into a texture /// /// The texture in which the frame is copied to - public void CopyScreen(ref STexture texture) + 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()) @@ -795,7 +796,7 @@ namespace Vocaluxe.Lib.Draw /// /// The texture's filepath /// A STexture object containing the added texture - public STexture AddTexture(string texturePath) + public CTexture AddTexture(string texturePath) { if (File.Exists(texturePath)) { @@ -807,9 +808,9 @@ namespace Vocaluxe.Lib.Draw catch (Exception) { CLog.LogError("Error loading Texture: " + texturePath); - return new STexture(-1); + return new CTexture(-1); } - STexture s; + CTexture s; try { s = AddTexture(bmp); @@ -821,7 +822,7 @@ namespace Vocaluxe.Lib.Draw return s; } CLog.LogError("Can't find File: " + texturePath); - return new STexture(-1); + return new CTexture(-1); } /// @@ -829,10 +830,10 @@ namespace Vocaluxe.Lib.Draw /// /// The Bitmap of which the texure will be created from /// A STexture object containing the added texture - public STexture AddTexture(Bitmap bmp) + public CTexture AddTexture(Bitmap bmp) { if (bmp.Height == 0 || bmp.Width == 0) - return new STexture(-1); + return new CTexture(-1); int maxSize; //Apply the right max size switch (CConfig.TextureQuality) @@ -857,7 +858,7 @@ namespace Vocaluxe.Lib.Draw break; } - STexture texture = new STexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; + CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); @@ -900,13 +901,13 @@ namespace Vocaluxe.Lib.Draw return _AddTexture(texture, w, data); } - public STexture AddTexture(int w, int h, byte[] data) + public CTexture AddTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1, w, h) {W2 = _CheckForNextPowerOf2(w), H2 = _CheckForNextPowerOf2(h)}; + CTexture texture = new CTexture(-1, w, h) {W2 = _CheckForNextPowerOf2(w), H2 = _CheckForNextPowerOf2(h)}; return _AddTexture(texture, w, data); } - private STexture _AddTexture(STexture texture, int w, byte[] data) + private CTexture _AddTexture(CTexture texture, int w, byte[] data) { Texture t = _CreateTexture(ref texture, w, data); @@ -919,7 +920,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - private Texture _CreateTexture(ref STexture texture, int w, byte[] data) + private Texture _CreateTexture(ref 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 @@ -949,9 +950,9 @@ namespace Vocaluxe.Lib.Draw return t; } - public STexture EnqueueTexture(int w, int h, byte[] data) + public CTexture EnqueueTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1, w, h); + CTexture texture = new CTexture(-1, w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -973,7 +974,7 @@ namespace Vocaluxe.Lib.Draw /// The texture to update /// A byte array containing the new texture's data /// True if succeeded - public bool UpdateTexture(ref STexture texture, byte[] data) + public bool UpdateTexture(ref CTexture texture, byte[] data) { if ((texture.Index >= 0) && (_Textures.Count > 0) && _TextureExists(ref texture)) { @@ -1001,7 +1002,7 @@ namespace Vocaluxe.Lib.Draw /// /// The texture to check /// True if the texture exists - private bool _TextureExists(ref STexture texture) + private bool _TextureExists(ref CTexture texture) { lock (_MutexTexture) { @@ -1021,7 +1022,7 @@ namespace Vocaluxe.Lib.Draw /// Removes a texture from the Vram /// /// The texture to be removed - public void RemoveTexture(ref STexture texture) + public void RemoveTexture(ref CTexture texture) { lock (_MutexTexture) { @@ -1042,7 +1043,7 @@ namespace Vocaluxe.Lib.Draw /// Draws a texture /// /// The texture to be drawn - public void DrawTexture(STexture texture) + public void DrawTexture(CTexture texture) { DrawTexture(texture, texture.Rect, texture.Color); } @@ -1052,7 +1053,7 @@ namespace Vocaluxe.Lib.Draw /// /// The texture to be drawn /// A SRectF struct containing the destination coordinates - public void DrawTexture(STexture texture, SRectF rect) + public void DrawTexture(CTexture texture, SRectF rect) { DrawTexture(texture, rect, texture.Color); } @@ -1064,7 +1065,7 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing the destination coordinates /// A SColorF struct containing a color which the texture will be colored in /// True if the texture should be mirrored - public void DrawTexture(STexture texture, SRectF rect, SColorF color, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false) { DrawTexture(texture, rect, color, new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, rect.Z), mirrored); } @@ -1077,7 +1078,7 @@ namespace Vocaluxe.Lib.Draw /// A SColorF struct containing a color which the texture will be colored in /// A SRectF struct containing which part of the texture should be drawn /// True if the texture should be mirrored - public void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { if (_TextureExists(ref texture)) { @@ -1168,7 +1169,7 @@ namespace Vocaluxe.Lib.Draw /// A SColorF struct containing a color which the texture will be colored in /// A Value ranging from 0 to 1 containing the beginning of the texture /// A Value ranging from 0 to 1 containing the ending of the texture - public void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) { if (!_TextureExists(ref texture)) return; @@ -1212,7 +1213,7 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing which part of the texture should be drawn /// The space between the texture and the reflection /// The height of the reflection - public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) + public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { if (!_TextureExists(ref texture)) return; @@ -1300,7 +1301,7 @@ namespace Vocaluxe.Lib.Draw _Queue.RemoveAt(0); if (!_Textures.ContainsKey(q.ID)) continue; - STexture texture = _Textures[q.ID]; + CTexture texture = _Textures[q.ID]; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) { texture.W2 = _CheckForNextPowerOf2(texture.OrigSize.Width); diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index ade2012b..ab765c21 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -27,6 +27,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw @@ -45,7 +46,7 @@ namespace Vocaluxe.Lib.Draw private bool _TopMost; private Rectangle _Bounds; - private readonly List _Textures; + private readonly List _Textures; private readonly List _Bitmaps; private readonly Color _ClearColor = Color.DarkBlue; @@ -54,7 +55,7 @@ namespace Vocaluxe.Lib.Draw { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new List(); + _Textures = new List(); _Bitmaps = new List(); _Keys = new CKeys(); @@ -289,11 +290,11 @@ namespace Vocaluxe.Lib.Draw _G.Clear(_ClearColor); } - public STexture CopyScreen() + public CTexture CopyScreen() { Bitmap bmp = new Bitmap(_Backbuffer); _Bitmaps.Add(bmp); - STexture texture = new STexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List _Textures.Add(texture); @@ -301,7 +302,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - public void CopyScreen(ref STexture texture) + public void CopyScreen(ref CTexture texture) { if (texture.Index == 0 || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) { @@ -333,11 +334,11 @@ namespace Vocaluxe.Lib.Draw public void DrawColorReflection(SColorF color, SRectF rect, float space, float height) {} - public STexture AddTexture(Bitmap bmp) + public CTexture AddTexture(Bitmap bmp) { Bitmap bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - STexture texture = new STexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List texture.TexturePath = String.Empty; @@ -347,13 +348,13 @@ namespace Vocaluxe.Lib.Draw return texture; } - public STexture AddTexture(string texturePath) + public CTexture AddTexture(string texturePath) { - STexture texture = new STexture(); + CTexture texture = new CTexture(); if (File.Exists(texturePath)) { bool found = false; - foreach (STexture tex in _Textures) + foreach (CTexture tex in _Textures) { if (tex.TexturePath == texturePath) { @@ -373,7 +374,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - public void RemoveTexture(ref STexture texture) + public void RemoveTexture(ref CTexture texture) { if ((texture.Index >= 0) && (_Textures.Count > 0)) { @@ -390,12 +391,12 @@ namespace Vocaluxe.Lib.Draw } } - public STexture EnqueueTexture(int w, int h, byte[] data) + public CTexture EnqueueTexture(int w, int h, byte[] data) { return AddTexture(w, h, data); } - public STexture AddTexture(int w, int h, byte[] data) + public CTexture AddTexture(int w, int h, byte[] data) { using (Bitmap bmp = new Bitmap(w, h)) { @@ -406,7 +407,7 @@ namespace Vocaluxe.Lib.Draw } } - public bool UpdateTexture(ref STexture texture, byte[] data) + public bool UpdateTexture(ref CTexture texture, byte[] data) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) { @@ -418,25 +419,25 @@ namespace Vocaluxe.Lib.Draw return true; } - public void DrawTexture(STexture texture) + public void DrawTexture(CTexture texture) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) DrawTexture(texture, texture.Rect, texture.Color); } - public void DrawTexture(STexture texture, SRectF rect) + public void DrawTexture(CTexture texture, SRectF rect) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) DrawTexture(texture, rect, texture.Color); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) DrawTexture(texture, rect, color, rect, mirrored); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) { @@ -446,9 +447,9 @@ namespace Vocaluxe.Lib.Draw } } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) {} + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) {} - public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) {} + public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) {} public int GetTextureCount() { diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 3cdd6c02..f460d4fa 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -30,6 +30,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using BeginMode = OpenTK.Graphics.OpenGL.BeginMode; using BlendingFactorDest = OpenTK.Graphics.OpenGL.BlendingFactorDest; @@ -82,7 +83,7 @@ namespace Vocaluxe.Lib.Draw private SClientRect _Restore; private bool _Fullscreen; - private readonly Dictionary _Textures; + private readonly Dictionary _Textures; private readonly Queue _IDs; private readonly List _Queue; @@ -100,7 +101,7 @@ namespace Vocaluxe.Lib.Draw { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new Dictionary(); + _Textures = new Dictionary(); _Queue = new List(); _IDs = new Queue(1000000); @@ -465,7 +466,7 @@ namespace Vocaluxe.Lib.Draw Close(); } catch {} - STexture[] textures = new STexture[_Textures.Count]; + CTexture[] textures = new CTexture[_Textures.Count]; _Textures.Values.CopyTo(textures, 0); for (int i = 0; i < _Textures.Count; i++) RemoveTexture(ref textures[i]); @@ -488,9 +489,9 @@ namespace Vocaluxe.Lib.Draw GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); } - public STexture CopyScreen() + public CTexture CopyScreen() { - STexture texture = new STexture(-1, _W, _H); + CTexture texture = new CTexture(-1, _W, _H); int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; @@ -518,7 +519,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - public void CopyScreen(ref STexture texture) + 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()) @@ -643,7 +644,7 @@ namespace Vocaluxe.Lib.Draw #region Textures #region adding - public STexture AddTexture(string texturePath) + public CTexture AddTexture(string texturePath) { if (File.Exists(texturePath)) { @@ -655,7 +656,7 @@ namespace Vocaluxe.Lib.Draw catch (Exception) { CLog.LogError("Error loading Texture: " + texturePath); - return new STexture(-1); + return new CTexture(-1); } try { @@ -667,13 +668,13 @@ namespace Vocaluxe.Lib.Draw } } CLog.LogError("Can't find File: " + texturePath); - return new STexture(-1); + return new CTexture(-1); } - public STexture AddTexture(Bitmap bmp) + public CTexture AddTexture(Bitmap bmp) { if (bmp.Height == 0 || bmp.Width == 0) - return new STexture(-1); + return new CTexture(-1); int maxSize; switch (CConfig.TextureQuality) @@ -698,7 +699,7 @@ namespace Vocaluxe.Lib.Draw break; } - STexture texture = new STexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; + CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); @@ -761,9 +762,9 @@ namespace Vocaluxe.Lib.Draw return texture; } - public STexture AddTexture(int w, int h, byte[] data) + public CTexture AddTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1, w, h); + CTexture texture = new CTexture(-1, w, h); _CreateTexture(data, ref texture); @@ -776,7 +777,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - private void _CreateTexture(byte[] data, ref STexture texture) + private void _CreateTexture(byte[] data, ref CTexture texture) { int w = texture.OrigSize.Width; int h = texture.OrigSize.Height; @@ -822,9 +823,9 @@ namespace Vocaluxe.Lib.Draw texture.TexturePath = String.Empty; } - public STexture EnqueueTexture(int w, int h, byte[] data) + public CTexture EnqueueTexture(int w, int h, byte[] data) { - STexture texture = new STexture(-1, w, h); + CTexture texture = new CTexture(-1, w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -840,7 +841,7 @@ namespace Vocaluxe.Lib.Draw #endregion adding #region updating - public bool UpdateTexture(ref STexture texture, byte[] data) + public bool UpdateTexture(ref CTexture texture, byte[] data) { if (_TextureExists(ref texture)) { @@ -882,7 +883,7 @@ namespace Vocaluxe.Lib.Draw } #endregion updating - public void RemoveTexture(ref STexture texture) + public void RemoveTexture(ref CTexture texture) { if ((texture.Index > 0) && (_Textures.Count > 0)) { @@ -899,7 +900,7 @@ namespace Vocaluxe.Lib.Draw } } - private bool _TextureExists(ref STexture texture) + private bool _TextureExists(ref CTexture texture) { lock (_MutexTexture) { @@ -916,22 +917,22 @@ namespace Vocaluxe.Lib.Draw } #region drawing - public void DrawTexture(STexture texture) + public void DrawTexture(CTexture texture) { DrawTexture(texture, texture.Rect, texture.Color); } - public void DrawTexture(STexture texture, SRectF rect) + public void DrawTexture(CTexture texture, SRectF rect) { DrawTexture(texture, rect, texture.Color); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false) { DrawTexture(texture, rect, color, new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, rect.Z), mirrored); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { 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) @@ -1039,7 +1040,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, 0); } - public void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) + public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) { if (_TextureExists(ref texture)) { @@ -1071,7 +1072,7 @@ namespace Vocaluxe.Lib.Draw } } - public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) + public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { 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) @@ -1180,7 +1181,7 @@ namespace Vocaluxe.Lib.Draw { STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); - STexture texture = new STexture(-1); + CTexture texture = new CTexture(-1); if (_Textures.ContainsKey(q.ID)) texture = _Textures[q.ID]; diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 77a605aa..b5066667 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -18,6 +18,7 @@ #endregion using System.Drawing; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw @@ -34,28 +35,28 @@ namespace Vocaluxe.Lib.Draw int GetTextureCount(); void ClearScreen(); - STexture CopyScreen(); - void CopyScreen(ref STexture texture); + CTexture CopyScreen(); + void CopyScreen(ref CTexture texture); void MakeScreenShot(); - STexture AddTexture(string texturePath); - STexture AddTexture(Bitmap bitmap); - STexture AddTexture(int w, int h, byte[] data); - STexture EnqueueTexture(int w, int h, byte[] data); - bool UpdateTexture(ref STexture texture, byte[] data); - void RemoveTexture(ref STexture texture); + CTexture AddTexture(string texturePath); + 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); + void RemoveTexture(ref CTexture texture); // Basic Draw Methods void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2); void DrawColor(SColorF color, SRectF rect); void DrawColorReflection(SColorF color, SRectF rect, float space, float height); - void DrawTexture(STexture texture); - void DrawTexture(STexture texture, SRectF rect); - void DrawTexture(STexture texture, SRectF rect, SColorF color, bool mirrored = false); - void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false); - void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end); + void DrawTexture(CTexture texture); + void DrawTexture(CTexture texture, SRectF rect); + void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false); + void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false); + void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end); - void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height); + void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height); } } \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/CVideoDecoder.cs b/Vocaluxe/Lib/Video/CVideoDecoder.cs index 53d96bef..691f5e96 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoder.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Linq; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -58,7 +59,7 @@ namespace Vocaluxe.Lib.Video return 0f; } - public abstract bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime); + public abstract bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime); public virtual bool Skip(int streamID, float start, float gap) { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index 77f6592a..7203b015 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -25,6 +25,7 @@ using System.Runtime.InteropServices; using System.Threading; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Acinerella; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -90,7 +91,7 @@ namespace Vocaluxe.Lib.Video return false; } - public override bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) + public override bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime) { videoTime = 0; if (_Initialized) @@ -299,7 +300,7 @@ namespace Vocaluxe.Lib.Video return true; } - public bool GetFrame(ref STexture frame, float time, out float videoTime) + public bool GetFrame(ref CTexture frame, float time, out float videoTime) { videoTime = 0; if (!_FileOpened) @@ -650,7 +651,7 @@ namespace Vocaluxe.Lib.Video } } - private void _UploadNewFrame(ref STexture frame) + private void _UploadNewFrame(ref CTexture frame) { if (!_FileOpened) return; diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 4c411cc2..5d9def8b 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -20,6 +20,7 @@ using System; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Gstreamer; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -78,7 +79,7 @@ namespace Vocaluxe.Lib.Video return CGstreamerVideoWrapper.GetVideoLength(streamID); } - public bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) + public bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime) { SManagedFrame managedFrame = CGstreamerVideoWrapper.GetFrame(streamID, time); videoTime = managedFrame.Videotime; @@ -117,7 +118,7 @@ namespace Vocaluxe.Lib.Video CGstreamerVideoWrapper.UpdateVideo(); } - private void _UploadNewFrame(ref STexture frame, ref byte[] data, int width, int height) + private void _UploadNewFrame(ref CTexture frame, ref byte[] data, int width, int height) { if (data == null) return; diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index 4dc3905a..ef8d57c7 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -17,6 +17,7 @@ // */ #endregion +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -41,7 +42,7 @@ namespace Vocaluxe.Lib.Video int GetNumStreams(); float GetLength(int streamID); - bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime); + bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime); bool Skip(int streamID, float start, float gap); void SetLoop(int streamID, bool loop); void Pause(int streamID); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index e2589dfe..20530dae 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -24,6 +24,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam @@ -50,7 +51,7 @@ namespace Vocaluxe.Lib.Webcam } } - public bool GetFrame(ref STexture frame) + public bool GetFrame(ref CTexture frame) { if (_Webcam != null && _Width > 0 && _Height > 0 && _Data.Length == _Width * _Height * 4) { diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 32804bfc..0d8042ef 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Drawing; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam @@ -54,7 +55,7 @@ namespace Vocaluxe.Lib.Webcam void Stop(); void Close(); - bool GetFrame(ref STexture frame); + bool GetFrame(ref CTexture frame); Bitmap GetBitmap(); SWebcamConfig GetConfig(); SWebcamDevice[] GetDevices(); diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index e5d3e81c..861adea3 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -23,6 +23,7 @@ using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Fonts; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Screens @@ -126,21 +127,21 @@ namespace Vocaluxe.Screens private List _Paragraphs; private List _ParagraphTexts; - private STexture _TexLogo; - private STexture _TexPerfectNoteStar; + private CTexture _TexLogo; + private CTexture _TexPerfectNoteStar; - private STexture _TexRedDot; - private STexture _TexBlueDot; + private CTexture _TexRedDot; + private CTexture _TexBlueDot; - private STexture _TexNameBrunzel; - private STexture _TexNameDarkice; - private STexture _TexNameFlokuep; - private STexture _TexNameFlamefire; - private STexture _TexNameMesand; - private STexture _TexNameBohning; - private STexture _TexNameBabene03; - private STexture _TexNamePantero; - private STexture _TexNamePinky007; + private CTexture _TexNameBrunzel; + private CTexture _TexNameDarkice; + private CTexture _TexNameFlokuep; + private CTexture _TexNameFlamefire; + private CTexture _TexNameMesand; + private CTexture _TexNameBohning; + private CTexture _TexNameBabene03; + private CTexture _TexNamePantero; + private CTexture _TexNamePinky007; public override void Init() { @@ -282,12 +283,12 @@ namespace Vocaluxe.Screens return GetNewParticleEffect(numStars, partColor, rect, _TexPerfectNoteStar, partSize, EParticleType.Star); } - private void _AddNewCreditName(STexture texture, int particleOffsetX, int particleOffsetY, bool bigParticles) + private void _AddNewCreditName(CTexture texture, int particleOffsetX, int particleOffsetY, bool bigParticles) { bool isRight = _CreditNames.Count % 2 == 0; int partRectSize = bigParticles ? 25 : 20; int partCount = bigParticles ? 8 : 6; - STexture texDot = isRight ? _TexRedDot : _TexBlueDot; + CTexture texDot = isRight ? _TexRedDot : _TexBlueDot; CStatic image = GetNewStatic(texture, new SColorF(1, 1, 1, 1), new SRectF(-1, -1, 400, 120, -4)); diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index c1e332c4..30ad6d92 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Screens @@ -53,7 +54,7 @@ namespace Vocaluxe.Screens {"EqualizerPlayer1", "EqualizerPlayer2", "EqualizerPlayer3", "EqualizerPlayer4", "EqualizerPlayer5", "EqualizerPlayer6"}; private readonly string[] _SelectSlideDuetPlayer = new string[] {"SelectSlideDuetPlayer1", "SelectSlideDuetPlayer2", "SelectSlideDuetPlayer3", "SelectSlideDuetPlayer4", "SelectSlideDuetPlayer5", "SelectSlideDuetPlayer6"}; - private readonly STexture[] _OriginalPlayerAvatarTextures = new STexture[CSettings.MaxNumPlayer]; + private readonly CTexture[] _OriginalPlayerAvatarTextures = new CTexture[CSettings.MaxNumPlayer]; private bool _SelectingKeyboardActive; private bool _SelectingFast; diff --git a/Vocaluxe/Screens/CScreenOptionsVideo.cs b/Vocaluxe/Screens/CScreenOptionsVideo.cs index 3367edc2..6bbcee44 100644 --- a/Vocaluxe/Screens/CScreenOptionsVideo.cs +++ b/Vocaluxe/Screens/CScreenOptionsVideo.cs @@ -21,6 +21,7 @@ using System; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Lib.Webcam; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Screens @@ -45,7 +46,7 @@ namespace Vocaluxe.Screens private const string _ButtonExit = "ButtonExit"; private SWebcamConfig _Config; - private STexture _WebcamTexture = new STexture(-1); + private CTexture _WebcamTexture = new CTexture(-1); private int _DeviceNr; private int _CapabilityNr; diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index b3c3740e..c666ee16 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -23,6 +23,7 @@ using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; namespace Vocaluxe.Screens @@ -60,7 +61,7 @@ namespace Vocaluxe.Screens private EEditMode _EditMode; - private STexture _WebcamTexture = new STexture(-1); + private CTexture _WebcamTexture = new CTexture(-1); private Bitmap _Snapshot; public override void Init() diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 57764cac..8c2ad2f9 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -367,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 STexture(-1); + _Statics[_StaticAvatar[player, numplayer]].Texture = new CTexture(-1); } } } diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 166dd841..1f018cfc 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -26,6 +26,7 @@ using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Fonts; +using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; @@ -96,9 +97,9 @@ namespace Vocaluxe.Screens private const float _Volume = 100f; private int _CurrentVideo = -1; private EAspect _VideoAspect = EAspect.Crop; - private STexture _CurrentVideoTexture = new STexture(-1); - private STexture _CurrentWebcamFrameTexture = new STexture(-1); - private STexture _Background = new STexture(-1); + private CTexture _CurrentVideoTexture = new CTexture(-1); + private CTexture _CurrentWebcamFrameTexture = new CTexture(-1); + private CTexture _Background = new CTexture(-1); private float _CurrentTime; private float _FinishTime; @@ -411,8 +412,8 @@ namespace Vocaluxe.Screens _FadeOut = false; _CurrentVideo = -1; - _CurrentVideoTexture = new STexture(-1); - _CurrentWebcamFrameTexture = new STexture(-1); + _CurrentVideoTexture = new CTexture(-1); + _CurrentWebcamFrameTexture = new CTexture(-1); _CurrentBeat = -100; _CurrentTime = 0f; _FinishTime = 0f; @@ -453,7 +454,7 @@ namespace Vocaluxe.Screens { if (_Active) { - STexture background; + CTexture background; EAspect aspect = EAspect.Crop; if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) { @@ -1353,7 +1354,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 STexture(-1), + trect.Rect = GetNewStatic(new CTexture(-1), 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 new file mode 100644 index 00000000..f987ec8b --- /dev/null +++ b/VocaluxeLib/Draw/CTexture.cs @@ -0,0 +1,120 @@ +using System; +using System.Drawing; +using VocaluxeLib.Menu; + +namespace VocaluxeLib.Draw +{ + public class CTexture + { + public int Index; + public int PBO; + public int ID; + + public string TexturePath; + + /// + /// Original size (e.g. of bmp) + /// + public readonly Size OrigSize; + public float OrigAspect + { + get { return (float)OrigSize.Width / OrigSize.Height; } + } + + /// + /// Current size when drawn + /// + public SRectF Rect; + + public SColorF Color; + + private int _W2, _H2; + private float _WidthRatio, _HeightRatio; + private bool _UseFullTexture; + /// + /// Internal texture width (on device), a power of 2 if necessary + /// + public int W2 + { + get { return _W2; } + set + { + _W2 = value; + if (!_UseFullTexture) + WidthRatio = (float)OrigSize.Width / _W2; + } + } + /// + /// Internal texture height (on device), a power of 2 if necessary + /// + public int H2 + { + get { return _H2; } + set + { + _H2 = value; + if (!_UseFullTexture) + HeightRatio = (float)OrigSize.Height / _H2; + } + } + + /// + /// Internal use. Specifies which part of texture memory is actually used + /// + public float WidthRatio + { + get { return _WidthRatio; } + private set { _WidthRatio = value; } + } + /// + /// Internal use. Specifies which part of texture memory is actually used + /// + public float HeightRatio + { + get { return _HeightRatio; } + private set { _HeightRatio = value; } + } + + /// + /// Internal use. Specifies if full texture memory should be used + /// Set to true if you resized the original image to the maximum + /// + public bool UseFullTexture + { + get { return _UseFullTexture; } + set + { + _UseFullTexture = value; + if (value) + { + WidthRatio = 1; + HeightRatio = 1; + } + else + { + WidthRatio = (float)OrigSize.Width / _W2; + HeightRatio = (float)OrigSize.Height / _H2; + } + } + } + + 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/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 073325ea..21e6814d 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -20,6 +20,7 @@ using System; using System.Drawing; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -202,7 +203,7 @@ namespace VocaluxeLib.Menu private bool _DrawTexture() { - STexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + CTexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); if (texture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); @@ -217,7 +218,7 @@ namespace VocaluxeLib.Menu private bool _DrawVideo() { - STexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); + CTexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); if (videoTexture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); @@ -232,7 +233,7 @@ namespace VocaluxeLib.Menu private bool _DrawBackgroundMusicVideo() { - STexture videoTexture = CBase.BackgroundMusic.GetVideoTexture(); + CTexture videoTexture = CBase.BackgroundMusic.GetVideoTexture(); if (videoTexture.OrigSize.Height > 1) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index 976da6b4..0ac3edca 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -19,6 +19,7 @@ using System; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -39,8 +40,8 @@ namespace VocaluxeLib.Menu private bool _ThemeLoaded; private readonly int _PartyModeID; - public STexture Texture; - public STexture SelTexture; + public CTexture Texture; + public CTexture SelTexture; public SRectF Rect; public SColorF Color; public SColorF SelColor; @@ -94,8 +95,8 @@ namespace VocaluxeLib.Menu Rect = new SRectF(); Color = new SColorF(); SelColor = new SColorF(); - Texture = new STexture(-1); - SelTexture = new STexture(-1); + Texture = new CTexture(-1); + SelTexture = new CTexture(-1); _IsSelText = false; Text = new CText(_PartyModeID); @@ -301,7 +302,7 @@ namespace VocaluxeLib.Menu if (!Visible && CBase.Settings.GetGameState() != EGameState.EditTheme && !forceDraw) return; - STexture texture; + CTexture texture; if (!Selected && !Pressed || !Enabled) { diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 9a5d6da8..3de37a98 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -24,6 +24,7 @@ using System.IO; using System.Text; using System.Windows.Forms; using System.Xml; +using VocaluxeLib.Draw; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; @@ -478,7 +479,7 @@ namespace VocaluxeLib.Menu return new CStatic(oldStatic); } - public CStatic GetNewStatic(STexture texture, SColorF color, SRectF rect) + public CStatic GetNewStatic(CTexture texture, SColorF color, SRectF rect) { return new CStatic(_PartyModeID, texture, color, rect); } @@ -523,7 +524,7 @@ namespace VocaluxeLib.Menu return new CPlaylist(_PartyModeID); } - public CParticleEffect GetNewParticleEffect(int maxNumber, SColorF color, SRectF area, STexture texture, float size, EParticleType type) + public CParticleEffect GetNewParticleEffect(int maxNumber, SColorF color, SRectF area, CTexture texture, float size, EParticleType type) { return new CParticleEffect(_PartyModeID, maxNumber, color, area, texture, size, type); } diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 39fba2b4..2347ca88 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -69,8 +70,8 @@ namespace VocaluxeLib.Menu public SRectF Rect; private readonly List _Tiles; - private STexture _TextureEmptyTile; - private STexture _TextureTileSelected; + private CTexture _TextureEmptyTile; + private CTexture _TextureTileSelected; public SColorF ColorEmptyTile; diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index e9a832cc..928e624e 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -45,7 +46,7 @@ namespace VocaluxeLib.Menu #region private vars private readonly int _PartyModeID; private readonly string _TextureName; - private readonly STexture _Texture; + private readonly CTexture _Texture; private SRectF _Rect; private float _Size; private SColorF _Color; @@ -115,7 +116,7 @@ namespace VocaluxeLib.Menu { _PartyModeID = partyModeID; _TextureName = textureName; - _Texture = new STexture(-1); + _Texture = new CTexture(-1); _Color = color; _Rect = new SRectF(x, y, size, size, z); _Size = size; @@ -134,7 +135,7 @@ namespace VocaluxeLib.Menu _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); } - public CParticle(int partyModeID, STexture texture, SColorF color, float x, float y, float size, float maxage, float z, float vx, float vy, float vr, float vsize, + public CParticle(int partyModeID, CTexture texture, SColorF color, float x, float y, float size, float maxage, float z, float vx, float vy, float vr, float vsize, EParticleType type) { _PartyModeID = partyModeID; @@ -312,7 +313,7 @@ namespace VocaluxeLib.Menu private SThemeParticleEffect _Theme; private bool _ThemeLoaded; - public STexture Texture; + public CTexture Texture; public SColorF Color; public SRectF Rect; @@ -356,7 +357,7 @@ namespace VocaluxeLib.Menu Rect = rect; Color = color; _Theme.TextureName = textureName; - Texture = new STexture(-1); + Texture = new CTexture(-1); _MaxNumber = maxNumber; _Size = size; _Type = type; @@ -365,7 +366,7 @@ namespace VocaluxeLib.Menu Visible = true; } - public CParticleEffect(int partyModeID, int maxNumber, SColorF color, SRectF rect, STexture texture, float size, EParticleType type) + public CParticleEffect(int partyModeID, int maxNumber, SColorF color, SRectF rect, CTexture texture, float size, EParticleType type) { _PartyModeID = partyModeID; _Theme = new SThemeParticleEffect(); @@ -602,7 +603,7 @@ namespace VocaluxeLib.Menu public void UnloadTextures() { - Texture = new STexture(); + Texture = new CTexture(); } public void LoadTextures() diff --git a/VocaluxeLib/Menu/CScreenSetting.cs b/VocaluxeLib/Menu/CScreenSetting.cs index 691074f9..ffe6e98f 100644 --- a/VocaluxeLib/Menu/CScreenSetting.cs +++ b/VocaluxeLib/Menu/CScreenSetting.cs @@ -19,6 +19,7 @@ using System; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -127,7 +128,7 @@ namespace VocaluxeLib.Menu } } - private STexture _GetTextureValue(string value) + private CTexture _GetTextureValue(string value) { return CBase.Theme.GetSkinTexture(value, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 488d2af6..1269aaeb 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -110,7 +111,7 @@ namespace VocaluxeLib.Menu private readonly List _ValueNames; private readonly List _ValuePartyModeIDs; - private readonly List _Textures; + private readonly List _Textures; private readonly List _ValueIndexes; private readonly List _ValueBounds = new List(); @@ -178,7 +179,7 @@ namespace VocaluxeLib.Menu MaxW = 0f; _Selected = false; - _Textures = new List(); + _Textures = new List(); _ValueIndexes = new List(); _ValueNames = new List(); _ValuePartyModeIDs = new List(); @@ -226,7 +227,7 @@ namespace VocaluxeLib.Menu MaxW = slide.MaxW; _Selected = slide._Selected; - _Textures = new List(slide._Textures); + _Textures = new List(slide._Textures); _ValueIndexes = new List(slide._ValueIndexes); _ValueNames = new List(slide._ValueNames); _ValueBounds = new List(slide._ValueBounds); @@ -530,20 +531,20 @@ namespace VocaluxeLib.Menu public void AddValue(string value, int partyModeID) { - AddValue(value, new STexture(-1), _ValueIndexes.Count, partyModeID); + AddValue(value, new CTexture(-1), _ValueIndexes.Count, partyModeID); } - public void AddValue(string value, STexture texture) + public void AddValue(string value, CTexture texture) { AddValue(value, texture, _ValueIndexes.Count, _PartyModeID); } - private void _AddValue(string value, STexture texture, int valueIndex) + private void _AddValue(string value, CTexture texture, int valueIndex) { AddValue(value, texture, valueIndex, _PartyModeID); } - public void AddValue(string value, STexture texture, int valueIndex, int partyModeID) + public void AddValue(string value, CTexture texture, int valueIndex, int partyModeID) { _ValueNames.Add(value); _Textures.Add(texture); @@ -559,12 +560,12 @@ namespace VocaluxeLib.Menu public void AddValues(IEnumerable values) { foreach (string value in values) - _AddValue(value, new STexture(-1), _PartyModeID); + _AddValue(value, new CTexture(-1), _PartyModeID); _ValueBounds.Clear(); } - public void AddValues(string[] values, STexture[] textures) + public void AddValues(string[] values, CTexture[] textures) { if (values.Length != textures.Length) return; @@ -590,10 +591,10 @@ namespace VocaluxeLib.Menu public void RenameValue(int selection, string newName) { - RenameValue(selection, newName, new STexture(-1)); + RenameValue(selection, newName, new CTexture(-1)); } - public void RenameValue(int selection, string newName, STexture newTexture) + public void RenameValue(int selection, string newName, CTexture newTexture) { if (selection < 0 && selection >= _ValueNames.Count) return; @@ -696,15 +697,15 @@ namespace VocaluxeLib.Menu if (!Visible && CBase.Settings.GetGameState() != EGameState.EditTheme) return; - STexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); - STexture textureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.TextureArrowLeftName, _PartyModeID); - STexture textureArrowRight = CBase.Theme.GetSkinTexture(_Theme.TextureArrowRightName, _PartyModeID); + CTexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + CTexture textureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.TextureArrowLeftName, _PartyModeID); + CTexture textureArrowRight = CBase.Theme.GetSkinTexture(_Theme.TextureArrowRightName, _PartyModeID); - STexture selTexture = CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); - STexture selTextureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowLeftName, _PartyModeID); - STexture selTextureArrowRight = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowRightName, _PartyModeID); + CTexture selTexture = CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); + CTexture selTextureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowLeftName, _PartyModeID); + CTexture selTextureArrowRight = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowRightName, _PartyModeID); - STexture highlightTexture = CBase.Theme.GetSkinTexture(_Theme.HighlightTextureName, _PartyModeID); + CTexture highlightTexture = CBase.Theme.GetSkinTexture(_Theme.HighlightTextureName, _PartyModeID); if (Selected) { diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 3a56a25f..5ad19529 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -20,6 +20,7 @@ using System; using System.Drawing; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { @@ -42,8 +43,8 @@ namespace VocaluxeLib.Menu return _Theme.Name; } - private STexture _Texture; - public STexture Texture + private CTexture _Texture; + public CTexture Texture { get { return _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } @@ -70,7 +71,7 @@ namespace VocaluxeLib.Menu _Theme = new SThemeStatic(); _ThemeLoaded = false; - _Texture = new STexture(-1); + _Texture = new CTexture(-1); Color = new SColorF(); Rect = new SRectF(); Reflection = false; @@ -100,7 +101,7 @@ namespace VocaluxeLib.Menu Visible = s.Visible; } - public CStatic(int partyModeID, STexture texture, SColorF color, SRectF rect) + public CStatic(int partyModeID, CTexture texture, SColorF color, SRectF rect) { _PartyModeID = partyModeID; _Theme = new SThemeStatic(); @@ -124,7 +125,7 @@ namespace VocaluxeLib.Menu _Theme = new SThemeStatic {TextureName = textureSkinName}; _ThemeLoaded = false; - _Texture = new STexture(-1); + _Texture = new CTexture(-1); Color = color; Rect = rect; Reflection = false; @@ -238,7 +239,7 @@ namespace VocaluxeLib.Menu public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false) { - STexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + CTexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); SRectF bounds = new SRectF( Rect.X - Rect.W * (scale - 1f), diff --git a/VocaluxeLib/Menu/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index b2b91758..aac8f334 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; +using VocaluxeLib.Draw; using VocaluxeLib.Menu.SongMenu; namespace VocaluxeLib.Menu @@ -113,8 +114,8 @@ namespace VocaluxeLib.Menu { string GetThemeScreensPath(int partyModeID); int GetSkinIndex(int partyModeID); - STexture GetSkinTexture(string textureName, int partyModeID); - STexture GetSkinVideoTexture(string videoName, int partyModeID); + CTexture GetSkinTexture(string textureName, int partyModeID); + CTexture GetSkinVideoTexture(string videoName, int partyModeID); void SkinVideoResume(string videoName, int partyModeID); void SkinVideoPause(string videoName, int partyModeID); @@ -144,17 +145,17 @@ namespace VocaluxeLib.Menu void ApplyVolume(); - STexture GetVideoTexture(); + CTexture GetVideoTexture(); } public interface IDrawing { - void DrawTexture(STexture texture, SRectF rect); - void DrawTexture(STexture texture, SRectF rect, SColorF color); - void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false); - void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight); + void DrawTexture(CTexture texture, SRectF rect); + void DrawTexture(CTexture texture, SRectF rect, SColorF color); + void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false); + void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float reflectionSpace, float reflectionHeight); - void RemoveTexture(ref STexture texture); + void RemoveTexture(ref CTexture texture); void DrawColor(SColorF color, SRectF rect); void DrawColorReflection(SColorF color, SRectF rect, float space, float height); @@ -259,7 +260,7 @@ namespace VocaluxeLib.Menu { int Load(string videoFileName); bool Skip(int videoStream, float startPosition, float videoGap); - bool GetFrame(int videoStream, ref STexture videoTexture, float time, out float videoTime); + bool GetFrame(int videoStream, ref CTexture videoTexture, float time, out float videoTime); bool IsFinished(int videoStream); bool Close(int videoStream); } @@ -282,12 +283,12 @@ namespace VocaluxeLib.Menu public interface ICover { - STexture GetNoCover(); + CTexture GetNoCover(); } public interface IDataBase { - bool GetCover(string fileName, ref STexture texture, int coverSize); + bool GetCover(string fileName, ref CTexture texture, int coverSize); } public interface IControllers diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index f5e68c61..72ca886f 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Xml; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu.SingNotes { @@ -475,9 +476,9 @@ namespace VocaluxeLib.Menu.SingNotes SRectF noteRect = new SRectF(rect.X + dw, rect.Y + dh, rect.W - 2 * dw, rect.H - 2 * dh, rect.Z); - STexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); - STexture noteMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinMiddleName, _PartyModeID); - STexture noteEnd = CBase.Theme.GetSkinTexture(_Theme.SkinRightName, _PartyModeID); + CTexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); + CTexture noteMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinMiddleName, _PartyModeID); + CTexture noteEnd = CBase.Theme.GetSkinTexture(_Theme.SkinRightName, _PartyModeID); //Width of each of the ends (round parts) //Need 2 of them so use minimum @@ -522,9 +523,9 @@ namespace VocaluxeLib.Menu.SingNotes rect.Z ); - STexture noteBackgroundBegin = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundLeftName, _PartyModeID); - STexture noteBackgroundMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundMiddleName, _PartyModeID); - STexture noteBackgroundEnd = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundRightName, _PartyModeID); + CTexture noteBackgroundBegin = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundLeftName, _PartyModeID); + CTexture noteBackgroundMiddle = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundMiddleName, _PartyModeID); + CTexture noteBackgroundEnd = CBase.Theme.GetSkinTexture(_Theme.SkinBackgroundRightName, _PartyModeID); float dx = r.H * noteBackgroundBegin.OrigAspect; if (2 * dx > r.W) @@ -617,7 +618,7 @@ namespace VocaluxeLib.Menu.SingNotes rect.Z ); - STexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); + CTexture noteBegin = CBase.Theme.GetSkinTexture(_Theme.SkinLeftName, _PartyModeID); float dx = r.H * noteBegin.OrigAspect; if (2 * dx > r.W) dx = r.W / 2; @@ -674,7 +675,7 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes[n].Color.B, _PlayerNotes[n].Color.A * _PlayerNotes[n].Alpha); - STexture toneHelper = CBase.Theme.GetSkinTexture(_Theme.SkinToneHelperName, _PartyModeID); + CTexture toneHelper = CBase.Theme.GetSkinTexture(_Theme.SkinToneHelperName, _PartyModeID); CBase.Drawing.DrawTexture(toneHelper, drawRect, color); diff --git a/VocaluxeLib/Menu/SongMenu/CCategory.cs b/VocaluxeLib/Menu/SongMenu/CCategory.cs index faa5a22a..299f2adf 100644 --- a/VocaluxeLib/Menu/SongMenu/CCategory.cs +++ b/VocaluxeLib/Menu/SongMenu/CCategory.cs @@ -18,14 +18,15 @@ #endregion using System.Collections.Generic; +using VocaluxeLib.Draw; namespace VocaluxeLib.Menu.SongMenu { public class CCategory { public readonly string Name; - private STexture _CoverTextureSmall = new STexture(-1); - private STexture _CoverTextureBig = new STexture(-1); + private CTexture _CoverTextureSmall = new CTexture(-1); + private CTexture _CoverTextureBig = new CTexture(-1); private bool _CoverBigLoaded; public readonly List Songs = new List(); @@ -34,14 +35,14 @@ namespace VocaluxeLib.Menu.SongMenu Name = name; } - public STexture CoverTextureSmall + public CTexture CoverTextureSmall { get { return _CoverTextureSmall; } set { _CoverTextureSmall = value; } } - public STexture CoverTextureBig + public CTexture CoverTextureBig { get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set @@ -53,7 +54,7 @@ namespace VocaluxeLib.Menu.SongMenu } } - public CCategory(string name, STexture coverSmall, STexture coverBig) + public CCategory(string name, CTexture coverSmall, CTexture coverBig) { Name = name; CoverTextureSmall = coverSmall; diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index c3598585..dc01c3f6 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; +using VocaluxeLib.Draw; using VocaluxeLib.Menu.SingNotes; namespace VocaluxeLib.Menu.SongMenu @@ -71,8 +72,8 @@ namespace VocaluxeLib.Menu.SongMenu { private bool _CoverSmallLoaded; private bool _CoverBigLoaded; - private STexture _CoverTextureSmall = new STexture(-1); - private STexture _CoverTextureBig = new STexture(-1); + private CTexture _CoverTextureSmall = new CTexture(-1); + private CTexture _CoverTextureBig = new CTexture(-1); public SMedley Medley; @@ -96,7 +97,7 @@ namespace VocaluxeLib.Menu.SongMenu public bool NotesLoaded { get; private set; } - public STexture CoverTextureSmall + public CTexture CoverTextureSmall { get { @@ -112,7 +113,7 @@ namespace VocaluxeLib.Menu.SongMenu } } - public STexture CoverTextureBig + public CTexture CoverTextureBig { get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 8ff84dc1..3621c14c 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Xml; +using VocaluxeLib.Draw; using VocaluxeLib.PartyModes; namespace VocaluxeLib.Menu.SongMenu @@ -104,7 +105,7 @@ namespace VocaluxeLib.Menu.SongMenu private readonly List _Streams = new List(); private int _Actsong = -1; private int _Actsongstream = -1; - protected STexture _Vidtex = new STexture(-1); + protected CTexture _Vidtex = new CTexture(-1); protected bool _Initialized; protected int _LastKnownNumSongs; @@ -463,7 +464,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void OnShow() { _Actsongstream = -1; - _Vidtex = new STexture(-1); + _Vidtex = new CTexture(-1); } public virtual void OnHide() diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index cad9f32f..960f896a 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; +using VocaluxeLib.Draw; using VocaluxeLib.PartyModes; namespace VocaluxeLib.Menu.SongMenu @@ -37,8 +38,8 @@ namespace VocaluxeLib.Menu.SongMenu private CStatic _MedleyCalcIcon; private CStatic _MedleyTagIcon; - private STexture _CoverBigTexture; - private STexture _CoverTexture; + private CTexture _CoverBigTexture; + private CTexture _CoverTexture; private CText _Artist; private CText _Title; diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index fef94d82..fbce1f29 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; +using VocaluxeLib.Draw; using VocaluxeLib.Menu.SingNotes; namespace VocaluxeLib.Menu @@ -99,120 +100,6 @@ namespace VocaluxeLib.Menu public int Y; public int Z; } - - public struct STexture - { - public int Index; - public int PBO; - public int ID; - - public string TexturePath; - - /// - /// Original size (e.g. of bmp) - /// - public readonly Size OrigSize; - public float OrigAspect - { - get { return (float)OrigSize.Width / OrigSize.Height; } - } - - /// - /// Current size when drawn - /// - public SRectF Rect; - - public SColorF Color; - - private int _W2, _H2; - private float _WidthRatio, _HeightRatio; - private bool _UseFullTexture; - /// - /// Internal texture width (on device), a power of 2 if necessary - /// - public int W2 - { - get { return _W2; } - set - { - _W2 = value; - if (!_UseFullTexture) - WidthRatio = (float)OrigSize.Width / _W2; - } - } - /// - /// Internal texture height (on device), a power of 2 if necessary - /// - public int H2 - { - get { return _H2; } - set - { - _H2 = value; - if (!_UseFullTexture) - HeightRatio = (float)OrigSize.Height / _H2; - } - } - - /// - /// Internal use. Specifies which part of texture memory is actually used - /// - public float WidthRatio - { - get { return _WidthRatio; } - private set { _WidthRatio = value; } - } - /// - /// Internal use. Specifies which part of texture memory is actually used - /// - public float HeightRatio - { - get { return _HeightRatio; } - private set { _HeightRatio = value; } - } - - /// - /// Internal use. Specifies if full texture memory should be used - /// Set to true if you resized the original image to the maximum - /// - public bool UseFullTexture - { - get { return _UseFullTexture; } - set - { - _UseFullTexture = value; - if (value) - { - WidthRatio = 1; - HeightRatio = 1; - } - else - { - WidthRatio = (float)OrigSize.Width / _W2; - HeightRatio = (float)OrigSize.Height / _H2; - } - } - } - - public STexture(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; - } - } #endregion Drawing #region Inputs @@ -307,14 +194,14 @@ namespace VocaluxeLib.Menu public struct SAvatar { public string FileName; - public STexture Texture; + public CTexture Texture; // ReSharper disable UnusedParameter.Local public SAvatar(int dummy) // ReSharper restore UnusedParameter.Local { FileName = String.Empty; - Texture = new STexture(-1); + Texture = new CTexture(-1); } } #endregion Profiles diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 93b1517f..37c027d5 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -130,6 +130,7 @@ + From 142a690cc6d94b900642bf7813c7fb1deff8b27b Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 5 May 2013 20:02:28 +0200 Subject: [PATCH 12/22] 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 From e43f5e7b0a77281f5b5b02f86fb6469cec46bd6e Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 6 May 2013 20:18:17 +0200 Subject: [PATCH 13/22] Changed usage of CTexture.Index: You only need to check for null as of last commit --- Vocaluxe/Base/CProfiles.cs | 2 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 9 +--- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 54 ++++++++----------- Vocaluxe/Lib/Draw/COpenGL.cs | 6 +-- VocaluxeLib/Draw/CTexture.cs | 3 +- VocaluxeLib/Menu/CButton.cs | 6 +-- VocaluxeLib/Menu/SongMenu/CCategory.cs | 2 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 6 +-- 8 files changed, 37 insertions(+), 51 deletions(-) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 12320bd2..aa45b4d2 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -130,7 +130,7 @@ namespace Vocaluxe.Base { CTexture tex = CDraw.AddTexture(file); - if (tex.Index != -1) + if (tex != null) { SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)}; _Avatars.Add(avatar); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 6d8e5df2..d6c455b8 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -1002,13 +1002,8 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - if (texture != null && _Textures.ContainsKey(texture.Index)) - { - if (_Textures[texture.Index].ID > 0) - return true; - } + return texture != null && _Textures.ContainsKey(texture.Index); } - return false; } /// @@ -1017,7 +1012,7 @@ namespace Vocaluxe.Lib.Draw /// The texture to be removed public void RemoveTexture(ref CTexture texture) { - if (texture != null && texture.Index >= 0) + if (_TextureExists(texture)) { lock (_MutexTexture) { diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 065170d3..b13a52c6 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -46,8 +46,8 @@ namespace Vocaluxe.Lib.Draw private bool _TopMost; private Rectangle _Bounds; - private readonly List _Textures; - private readonly List _Bitmaps; + private readonly Dictionary _Textures = new Dictionary(); + private readonly List _Bitmaps = new List(); private readonly Color _ClearColor = Color.DarkBlue; @@ -55,9 +55,6 @@ namespace Vocaluxe.Lib.Draw { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new List(); - _Bitmaps = new List(); - _Keys = new CKeys(); _Mouse = new CMouse(); ClientSize = new Size(1280, 720); @@ -297,14 +294,14 @@ namespace Vocaluxe.Lib.Draw CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List - _Textures.Add(texture); + _Textures[texture.Index] = texture; return texture; } public void CopyScreen(ref CTexture texture) { - if (texture.Index == 0 || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) + if (!_TextureExists(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -341,9 +338,7 @@ namespace Vocaluxe.Lib.Draw CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); // Add to Texture List - texture.TexturePath = String.Empty; - - _Textures.Add(texture); + _Textures[texture.Index] = texture; return texture; } @@ -352,7 +347,7 @@ namespace Vocaluxe.Lib.Draw { if (File.Exists(texturePath)) { - foreach (CTexture tex in _Textures) + foreach (CTexture tex in _Textures.Values) { if (tex.TexturePath == texturePath) return tex; @@ -367,19 +362,17 @@ namespace Vocaluxe.Lib.Draw return null; } + private bool _TextureExists(CTexture texture) + { + return texture != null && _Textures.ContainsKey(texture.Index); + } + public void RemoveTexture(ref CTexture texture) { - if (texture != null && texture.Index >= 0) + if (_TextureExists(texture)) { - for (int i = 0; i < _Textures.Count; i++) - { - if (_Textures[i].Index == texture.Index) - { - _Bitmaps[texture.Index].Dispose(); - _Textures.RemoveAt(i); - break; - } - } + _Bitmaps[texture.Index].Dispose(); + _Textures.Remove(texture.Index); } texture = null; } @@ -402,7 +395,7 @@ namespace Vocaluxe.Lib.Draw public bool UpdateTexture(CTexture texture, byte[] data) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) + 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); @@ -415,30 +408,29 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(CTexture texture) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) + if (texture != null) DrawTexture(texture, texture.Rect, texture.Color); } public void DrawTexture(CTexture texture, SRectF rect) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) + if (texture != null) DrawTexture(texture, rect, texture.Color); } public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) + if (texture != null) DrawTexture(texture, rect, color, rect, mirrored); } public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) { - if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) - { - Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color); - _G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H)); - coloredBitmap.Dispose(); - } + if (!_TextureExists(texture)) + return; + Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color); + _G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H)); + coloredBitmap.Dispose(); } public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) {} diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index f3aa39b4..c404b037 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -883,7 +883,7 @@ namespace Vocaluxe.Lib.Draw public void RemoveTexture(ref CTexture texture) { - if (texture != null && texture.Index > 0) + if (_TextureExists(texture, false)) { lock (_MutexTexture) { @@ -897,13 +897,13 @@ namespace Vocaluxe.Lib.Draw texture = null; } - private bool _TextureExists(CTexture texture) + private bool _TextureExists(CTexture texture, bool checkIfLoaded = true) { lock (_MutexTexture) { if (texture != null && _Textures.ContainsKey(texture.Index)) { - if (_Textures[texture.Index].ID > 0) + if (!checkIfLoaded || _Textures[texture.Index].ID > 0) return true; } } diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index a6c48222..c0604f3e 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -1,5 +1,4 @@ -using System; -using System.Drawing; +using System.Drawing; using VocaluxeLib.Menu; namespace VocaluxeLib.Draw diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index 3507e0fa..34fa5fa7 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -285,7 +285,7 @@ namespace VocaluxeLib.Menu if (!Selected && !Pressed || !Enabled) { - texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + texture = Texture ?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); CBase.Drawing.DrawTexture(texture, Rect, Color); @@ -299,7 +299,7 @@ namespace VocaluxeLib.Menu } else if (!_IsSelText) { - texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); + texture = Texture ?? CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); CBase.Drawing.DrawTexture(texture, Rect, SelColor); @@ -313,7 +313,7 @@ namespace VocaluxeLib.Menu } else if (_IsSelText) { - texture = SelTexture.Index != -1 ? SelTexture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); + texture = SelTexture ?? CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); CBase.Drawing.DrawTexture(texture, Rect, SelColor); diff --git a/VocaluxeLib/Menu/SongMenu/CCategory.cs b/VocaluxeLib/Menu/SongMenu/CCategory.cs index f107481f..d94848f0 100644 --- a/VocaluxeLib/Menu/SongMenu/CCategory.cs +++ b/VocaluxeLib/Menu/SongMenu/CCategory.cs @@ -46,7 +46,7 @@ namespace VocaluxeLib.Menu.SongMenu get { return _CoverTextureBig ?? _CoverTextureSmall; } set { - if (value.Index == -1) + if (value == null) return; _CoverTextureBig = value; } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 4cfa78f9..291a8c5b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -323,7 +323,7 @@ namespace VocaluxeLib.Menu.SongMenu { foreach (CStatic tile in _Tiles) { - if ((tile.Texture.Index != _CoverTexture.Index) && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel) + if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel) { if (mouseEvent.LB || !CBase.Songs.IsInCategory()) { @@ -371,7 +371,7 @@ namespace VocaluxeLib.Menu.SongMenu { foreach (CStatic tile in _Tiles) { - if ((tile.Texture.Index != _CoverTexture.Index) && CHelper.IsInBounds(tile.Rect, mouseEvent)) + if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent)) { _EnterCategory(_PreviewSelected); mouseEvent.Handled = true; @@ -394,7 +394,7 @@ namespace VocaluxeLib.Menu.SongMenu else { // ReSharper disable ConvertIfStatementToConditionalTernaryExpression - if (tile.Texture.Index != _CoverTexture.Index) + if (tile.Texture != _CoverTexture) // ReSharper restore ConvertIfStatementToConditionalTernaryExpression tile.Draw(1f, tile.Rect.Z, EAspect.Crop); else From dd96b61caed15e4297237f1a010ec4bd7a818b12 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 6 May 2013 23:35:18 +0200 Subject: [PATCH 14/22] Improved CTexture creation --- Vocaluxe/Base/CVideo.cs | 2 + Vocaluxe/Lib/Draw/CDirect3D.cs | 25 ++++++------ Vocaluxe/Lib/Draw/CDrawWinForm.cs | 9 ++++- Vocaluxe/Lib/Draw/COpenGL.cs | 42 ++++++++------------ Vocaluxe/Lib/Video/CVideoDecoder.cs | 1 - Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 1 - Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 1 - Vocaluxe/Lib/Video/IVideoDecoder.cs | 1 - Vocaluxe/Lib/Webcam/CAForgeNet.cs | 1 - Vocaluxe/Lib/Webcam/IWebcam.cs | 1 - Vocaluxe/Screens/CScreenScore.cs | 1 - VocaluxeLib/Draw/CTexture.cs | 20 +++++++--- 12 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 597a0f22..0c24177c 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -166,6 +166,8 @@ namespace Vocaluxe.Base CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); } + if (_VideoTexture == null) + return; RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect; CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index d6c455b8..079fa61c 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -679,21 +679,21 @@ namespace Vocaluxe.Lib.Draw /// public CTexture CopyScreen() { - CTexture texture = new CTexture(-1, _W, _H) {W2 = _CheckForNextPowerOf2(_W), H2 = _CheckForNextPowerOf2(_H)}; + CTexture texture = _GetNewTexture(_W, _H); Surface backbufferSurface = _Device.GetBackBuffer(0, 0); - Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + Texture tex = new Texture(_Device, texture.W2, texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Surface textureSurface = tex.GetSurfaceLevel(0); Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0, new Rectangle(0, 0, _W, _H), new Rectangle(0, 0, _W, _H)); backbufferSurface.Dispose(); lock (_MutexTexture) { - _D3DTextures.Add(_IDs.Peek(), tex); texture.Index = _IDs.Dequeue(); + _D3DTextures.Add(texture.Index, tex); _Textures[texture.Index] = texture; + return texture; } - return texture; } /// @@ -856,16 +856,11 @@ namespace Vocaluxe.Lib.Draw break; } - CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; - int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); w = _CheckForNextPowerOf2(w); h = _CheckForNextPowerOf2(h); - texture.W2 = w; - texture.H2 = h; - Bitmap bmp2 = null; byte[] data; try @@ -896,12 +891,13 @@ namespace Vocaluxe.Lib.Draw bmp2.Dispose(); } + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h,true); return _AddTexture(texture, w, data); } public CTexture AddTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h) {W2 = _CheckForNextPowerOf2(w), H2 = _CheckForNextPowerOf2(h)}; + CTexture texture = _GetNewTexture(w, h); return _AddTexture(texture, w, data); } @@ -936,8 +932,6 @@ namespace Vocaluxe.Lib.Draw rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - - texture.TexturePath = String.Empty; } catch (Exception) { @@ -950,7 +944,7 @@ namespace Vocaluxe.Lib.Draw public CTexture EnqueueTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -963,6 +957,11 @@ namespace Vocaluxe.Lib.Draw } return texture; } + + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h, _CheckForNextPowerOf2(w), _CheckForNextPowerOf2(h)); + } #endregion adding #region updating diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index b13a52c6..ca19a4fa 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -291,7 +291,7 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp = new Bitmap(_Backbuffer); _Bitmaps.Add(bmp); - CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List _Textures[texture.Index] = texture; @@ -335,7 +335,7 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List _Textures[texture.Index] = texture; @@ -343,6 +343,11 @@ namespace Vocaluxe.Lib.Draw return texture; } + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h) {Index = _Bitmaps.Count - 1}; + } + public CTexture AddTexture(string texturePath) { if (File.Exists(texturePath)) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index c404b037..8dd43f54 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -491,14 +491,11 @@ namespace Vocaluxe.Lib.Draw public CTexture CopyScreen() { - CTexture texture = new CTexture(-1, _W, _H); + CTexture texture = _GetNewTexture(_W, _H); + int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - - texture.W2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Width); - texture.H2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Height); - 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); @@ -699,20 +696,16 @@ namespace Vocaluxe.Lib.Draw break; } - CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; - - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; - int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); w = MathHelper.NextPowerOfTwo(w); h = MathHelper.NextPowerOfTwo(h); - texture.W2 = w; - texture.H2 = h; + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true); + int id = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, id); + texture.ID = id; Bitmap bmp2 = null; try { @@ -764,9 +757,9 @@ namespace Vocaluxe.Lib.Draw public CTexture AddTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); - _CreateTexture(texture, data); + _CreateTexture(texture, w, h, data); lock (_MutexTexture) { @@ -777,10 +770,8 @@ namespace Vocaluxe.Lib.Draw return texture; } - private void _CreateTexture(CTexture texture, byte[] data) + private void _CreateTexture(CTexture texture, int w, int h, byte[] data) { - int w = texture.OrigSize.Width; - int h = texture.OrigSize.Height; if (_UsePBO) { try @@ -801,9 +792,6 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - texture.W2 = MathHelper.NextPowerOfTwo(w); - texture.H2 = MathHelper.NextPowerOfTwo(h); - 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); @@ -818,14 +806,11 @@ namespace Vocaluxe.Lib.Draw //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); - - // Add to Texture List - texture.TexturePath = String.Empty; } public CTexture EnqueueTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -838,6 +823,11 @@ namespace Vocaluxe.Lib.Draw return texture; } + + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h, MathHelper.NextPowerOfTwo(w), MathHelper.NextPowerOfTwo(h)); + } #endregion adding #region updating @@ -1183,7 +1173,7 @@ namespace Vocaluxe.Lib.Draw continue; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) - _CreateTexture(texture, q.Data); + _CreateTexture(texture, q.Width, q.Height, q.Data); else CLog.LogError("Wrong texture size in queue!"); } diff --git a/Vocaluxe/Lib/Video/CVideoDecoder.cs b/Vocaluxe/Lib/Video/CVideoDecoder.cs index 691f5e96..79ea8b52 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoder.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Linq; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index cef73875..fb5c2951 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -26,7 +26,6 @@ using System.Threading; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Acinerella; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 7bf76966..199b82d5 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -21,7 +21,6 @@ using System; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Gstreamer; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index ef8d57c7..ded5d7a5 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -18,7 +18,6 @@ #endregion using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 5655707a..1413cd73 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -25,7 +25,6 @@ using System.Drawing.Imaging; using System.Runtime.InteropServices; using Vocaluxe.Base; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam { diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 0d8042ef..3244c218 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Drawing; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam { diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index b1869a6c..b50723ee 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -22,7 +22,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; -using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index c0604f3e..f3823112 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -65,6 +65,7 @@ namespace VocaluxeLib.Draw /// public float HeightRatio { get; private set; } + /* /// /// Internal use. Specifies if full texture memory should be used /// Set to true if you resized the original image to the maximum @@ -87,16 +88,25 @@ namespace VocaluxeLib.Draw } } } +*/ - public CTexture(int index, int origWidth = 1, int origHeight = 1) + /// + /// Creates a new texture reference + /// + /// Original width (Bitmap size) + /// Original height (Bitmap size) + /// Width in video memory + /// Height in video memory + /// True if it is using the full size of the video memory (no blank parts due to Pow-2-Issue) + public CTexture(int origWidth, int origHeight, int texWidth = 0, int texHeight = 0, bool useFullTexture = false) { - Index = index; - OrigSize = new Size(origWidth, origHeight); Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); + _UseFullTexture = useFullTexture; - _W2 = origWidth; - _H2 = origHeight; + //IMPORTANT: Use setter here to calculate ratios! + W2 = (texWidth > 0) ? texWidth : origWidth; + H2 = (texHeight > 0) ? texHeight : origHeight; } } } \ No newline at end of file From a2c1ee67ad0a7745ee00386b1ea41777c59513df Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 13:37:55 +0200 Subject: [PATCH 15/22] Improved Texture update handling --- Vocaluxe/Base/CBackgroundMusic.cs | 16 ++--- Vocaluxe/Base/CDraw.cs | 9 ++- Vocaluxe/Lib/Draw/CDirect3D.cs | 52 ++++++++------- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 12 +++- Vocaluxe/Lib/Draw/COpenGL.cs | 30 +++++---- Vocaluxe/Lib/Draw/IDraw.cs | 3 +- Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs | 12 +--- Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs | 10 +-- Vocaluxe/Lib/Video/IVideoDecoder.cs | 10 +++ Vocaluxe/Lib/Webcam/CAForgeNet.cs | 63 ++++++++----------- Vocaluxe/Screens/CScreenCredits.cs | 2 +- VocaluxeLib/Draw/CTexture.cs | 26 +++++++- VocaluxeLib/Menu/CBackground.cs | 6 +- .../Menu/SongMenu/CSongMenuFramework.cs | 22 ++++--- 14 files changed, 157 insertions(+), 116 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index d227c7c0..5c8bfa50 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -463,15 +463,17 @@ namespace Vocaluxe.Base if (_Video != -1) { float vtime; - CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime); - if (_FadeTimer.ElapsedMilliseconds <= 3000L) - _CurrentVideoTexture.Color.A = _FadeTimer.ElapsedMilliseconds / 3000f; - else + if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime)) { - _CurrentVideoTexture.Color.A = 1f; - _FadeTimer.Stop(); + if (_FadeTimer.ElapsedMilliseconds <= 3000L) + _CurrentVideoTexture.Color.A = _FadeTimer.ElapsedMilliseconds / 3000f; + else + { + _CurrentVideoTexture.Color.A = 1f; + _FadeTimer.Stop(); + } + return _CurrentVideoTexture; } - return _CurrentVideoTexture; } return null; } diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 6f377402..2acc4d35 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -160,9 +160,14 @@ namespace Vocaluxe.Base return _Draw.EnqueueTexture(w, h, data); } - public static bool UpdateTexture(CTexture texture, byte[] data) + public static bool UpdateTexture(CTexture texture, int w, int h, byte[] data) { - return _Draw.UpdateTexture(texture, data); + return _Draw.UpdateTexture(texture, w, h, data); + } + + public static bool UpdateOrAddTexture(ref CTexture texture, int w, int h, byte[] data) + { + return _Draw.UpdateOrAddTexture(ref texture, w, h, data); } public static void RemoveTexture(ref CTexture texture) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 079fa61c..9d92cb2b 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -891,7 +891,7 @@ namespace Vocaluxe.Lib.Draw bmp2.Dispose(); } - CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h,true); + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true); return _AddTexture(texture, w, data); } @@ -924,12 +924,12 @@ namespace Vocaluxe.Lib.Draw t = new Texture(_Device, texture.W2, texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); //Lock the texture and fill it with the data DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); - int rowWidth = 4 * texture.W2; - for (int i = 0; i + rowWidth <= data.Length; i += 4 * w) + int rowWidth = 4 * w; + for (int i = 0; i + rowWidth <= data.Length; i += rowWidth) { - rect.Data.Write(data, i, 4 * w); - rect.Data.Position = rect.Data.Position - rowWidth; - rect.Data.Position += rect.Pitch; + rect.Data.Write(data, i, rowWidth); + //Go to next row + rect.Data.Position = rect.Data.Position - rowWidth + rect.Pitch; } t.UnlockRectangle(0); } @@ -969,27 +969,39 @@ namespace Vocaluxe.Lib.Draw /// Updates the data of a texture /// /// The texture to update + /// + /// /// A byte array containing the new texture's data /// True if succeeded - public bool UpdateTexture(CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, int w, int h, byte[] data) { - if (!_TextureExists(texture)) + //Check if texture exists and extend matches + if (!_TextureExists(texture) || texture.UsedWidth != w || texture.UsedHeight != h) return false; 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) + int rowWidth = 4 * w; + for (int i = 0; i + rowWidth <= data.Length; i += rowWidth) { - rect.Data.Write(data, i, 4 * w); - rect.Data.Position = rect.Data.Position - rowWidth; - rect.Data.Position += rect.Pitch; + rect.Data.Write(data, i, rowWidth); + //Go to next row + rect.Data.Position = rect.Data.Position - rowWidth + rect.Pitch; } _D3DTextures[texture.Index].UnlockRectangle(0); } return true; } + + public bool UpdateOrAddTexture(ref CTexture texture, int w, int h, byte[] data) + { + if (!UpdateTexture(texture, w, h, data)) + { + RemoveTexture(ref texture); + texture = AddTexture(w, h, data); + } + return true; + } #endregion updating /// @@ -1288,15 +1300,9 @@ namespace Vocaluxe.Lib.Draw CTexture texture; if (!_Textures.TryGetValue(q.Index, out texture)) continue; - 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(texture, q.Width, q.Data); - _D3DTextures[q.Index] = t; - } - else - CLog.LogError("Wrong texture size in queue!"); + + Texture t = _CreateTexture(texture, q.Width, q.Data); + _D3DTextures[q.Index] = t; } } } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index ca19a4fa..ff52c50d 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -398,7 +398,7 @@ namespace Vocaluxe.Lib.Draw } } - public bool UpdateTexture(CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, int w, int h, byte[] data) { if (_TextureExists(texture)) { @@ -411,6 +411,16 @@ namespace Vocaluxe.Lib.Draw return false; } + public bool UpdateOrAddTexture(ref CTexture texture, int w, int h, byte[] data) + { + if (!UpdateTexture(texture, w, h, data)) + { + RemoveTexture(ref texture); + texture = AddTexture(w, h, data); + } + return true; + } + public void DrawTexture(CTexture texture) { if (texture != null) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 8dd43f54..57e93f9a 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -518,8 +518,8 @@ 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(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) + //Check for actual texture sizes as it may be downsized compared to OrigSize + if (!_TextureExists(texture) || texture.UsedWidth != GetScreenWidth() || texture.UsedHeight != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -528,7 +528,7 @@ namespace Vocaluxe.Lib.Draw { GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.OrigSize.Width, texture.OrigSize.Height); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.UsedWidth, texture.UsedHeight); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -831,9 +831,10 @@ namespace Vocaluxe.Lib.Draw #endregion adding #region updating - public bool UpdateTexture(CTexture texture, byte[] data) + public bool UpdateTexture(CTexture texture, int w, int h, byte[] data) { - if (!_TextureExists(texture)) + //Check if texture exists and extend matches + if (!_TextureExists(texture) || texture.UsedWidth != w || texture.UsedHeight != h) return false; if (_UsePBO) { @@ -845,7 +846,7 @@ namespace Vocaluxe.Lib.Draw 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, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); @@ -855,7 +856,7 @@ namespace Vocaluxe.Lib.Draw 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.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, data); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); @@ -869,6 +870,16 @@ namespace Vocaluxe.Lib.Draw return true; } + + public bool UpdateOrAddTexture(ref CTexture texture, int w, int h, byte[] data) + { + if (!UpdateTexture(texture, w, h, data)) + { + RemoveTexture(ref texture); + texture = AddTexture(w, h, data); + } + return true; + } #endregion updating public void RemoveTexture(ref CTexture texture) @@ -1172,10 +1183,7 @@ namespace Vocaluxe.Lib.Draw if (!_Textures.TryGetValue(q.Index, out texture)) continue; - if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) - _CreateTexture(texture, q.Width, q.Height, q.Data); - else - CLog.LogError("Wrong texture size in queue!"); + _CreateTexture(texture, q.Width, q.Height, q.Data); } } } diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 9c8f2dd3..96a9df0b 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -43,7 +43,8 @@ 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(CTexture texture, byte[] data); + bool UpdateTexture(CTexture texture, int w, int h, byte[] data); + bool UpdateOrAddTexture(ref CTexture texture, int w, int h, 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 fb5c2951..003f1a09 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -323,7 +323,7 @@ namespace Vocaluxe.Lib.Video _UploadNewFrame(ref frame); //EventDecode.Set(); - return true; + return frame != null; } if (Math.Abs(_SetTime - time) > float.Epsilon) @@ -335,7 +335,7 @@ namespace Vocaluxe.Lib.Video _UploadNewFrame(ref frame); videoTime = _CurrentVideoTime; //EventDecode.Set(); - return true; + return frame != null; } return false; } @@ -661,13 +661,7 @@ namespace Vocaluxe.Lib.Video if (num >= 0) { - 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(frame, _FrameBuffer[num].Data); + CDraw.UpdateOrAddTexture(ref frame, _Width, _Height, _FrameBuffer[num].Data); lock (_MutexSyncSignals) { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 199b82d5..f37b0dc8 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -84,7 +84,7 @@ namespace Vocaluxe.Lib.Video videoTime = managedFrame.Videotime; _UploadNewFrame(ref frame, ref managedFrame.Buffer, managedFrame.Width, managedFrame.Height); - return true; + return frame != null; } public bool Skip(int streamID, float start, float gap) @@ -121,13 +121,7 @@ namespace Vocaluxe.Lib.Video { if (data == null) return; - 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(frame, data); + CDraw.UpdateOrAddTexture(ref frame, width, height, data); data = null; } } diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index ded5d7a5..dcf1120e 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -41,7 +41,17 @@ namespace Vocaluxe.Lib.Video int GetNumStreams(); float GetLength(int streamID); + + /// + /// + /// + /// + /// + /// + /// + /// True if frame is valid bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime); + bool Skip(int streamID, float start, float gap); void SetLoop(int streamID, bool loop); void Pause(int streamID); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 1413cd73..2d056ac3 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -41,29 +41,20 @@ namespace Vocaluxe.Lib.Webcam public void Close() { - if (_Webcam != null) - { - _Webcam.SignalToStop(); - _Webcam.WaitForStop(); - _Webcam.NewFrame -= _OnFrame; - _Data = new byte[1]; - } + if (_Webcam == null) + return; + _Webcam.SignalToStop(); + _Webcam.WaitForStop(); + _Webcam.NewFrame -= _OnFrame; + _Data = new byte[1]; } public bool GetFrame(ref CTexture frame) { - if (_Webcam != null && _Width > 0 && _Height > 0 && _Data.Length == _Width * _Height * 4) + lock (_MutexData) { - lock (_MutexData) - { - if (frame == null || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) - { - CDraw.RemoveTexture(ref frame); - frame = CDraw.AddTexture(_Width, _Height, _Data); - } - else - CDraw.UpdateTexture(frame, _Data); - } + if (_Webcam != null && _Width > 0 && _Height > 0 && _Data.Length == _Width * _Height * 4) + CDraw.UpdateOrAddTexture(ref frame, _Width, _Height, _Data); } return false; } @@ -114,19 +105,18 @@ namespace Vocaluxe.Lib.Webcam private void _OnFrame(object sender, NewFrameEventArgs e) { - if (!_Paused) + if (_Paused) + return; + lock (_MutexData) { - lock (_MutexData) - { - if (_Width != e.Frame.Width || _Height != e.Frame.Height || _Data.Length != e.Frame.Width * e.Frame.Height * 4) - _Data = new byte[4 * e.Frame.Width * e.Frame.Height]; + if (_Width != e.Frame.Width || _Height != e.Frame.Height || _Data.Length != e.Frame.Width * e.Frame.Height * 4) + _Data = new byte[4 * e.Frame.Width * e.Frame.Height]; - _Width = e.Frame.Width; - _Height = e.Frame.Height; - BitmapData bitmapdata = e.Frame.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - Marshal.Copy(bitmapdata.Scan0, _Data, 0, _Data.Length); - e.Frame.UnlockBits(bitmapdata); - } + _Width = e.Frame.Width; + _Height = e.Frame.Height; + BitmapData bitmapdata = e.Frame.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + Marshal.Copy(bitmapdata.Scan0, _Data, 0, _Data.Length); + e.Frame.UnlockBits(bitmapdata); } } @@ -138,14 +128,13 @@ namespace Vocaluxe.Lib.Webcam public void Start() { - if (_Webcam != null) - { - _Webcam.NewFrame -= _OnFrame; - //Subscribe to NewFrame event - _Webcam.NewFrame += _OnFrame; - _Webcam.Start(); - _Paused = false; - } + if (_Webcam == null) + return; + _Webcam.NewFrame -= _OnFrame; + //Subscribe to NewFrame event + _Webcam.NewFrame += _OnFrame; + _Webcam.Start(); + _Paused = false; } public void Stop() diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 861adea3..226e21ee 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -213,7 +213,7 @@ namespace Vocaluxe.Screens if (paragraph[e] == null) continue; string newLine = " " + paragraph[e]; - CText text = GetNewText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); + CText text = GetNewText(75, lastY, -2, 25, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); if (CFonts.GetTextBounds(text).Width < (CSettings.RenderW - 220)) { line += newLine; diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index f3823112..841a4c55 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -28,7 +28,7 @@ namespace VocaluxeLib.Draw public SColorF Color = new SColorF(1f, 1f, 1f, 1f); private int _W2, _H2; - private bool _UseFullTexture; + private readonly bool _UseFullTexture; /// /// Internal texture width (on device), a power of 2 if necessary /// @@ -38,7 +38,9 @@ namespace VocaluxeLib.Draw set { _W2 = value; - if (!_UseFullTexture) + if (_UseFullTexture) + WidthRatio = 1; + else WidthRatio = (float)OrigSize.Width / _W2; } } @@ -51,7 +53,9 @@ namespace VocaluxeLib.Draw set { _H2 = value; - if (!_UseFullTexture) + if (_UseFullTexture) + HeightRatio = 1; + else HeightRatio = (float)OrigSize.Height / _H2; } } @@ -65,6 +69,22 @@ namespace VocaluxeLib.Draw /// public float HeightRatio { get; private set; } + /// + /// Actual texture space used in x direction + /// + public int UsedWidth + { + get { return (int)(_W2 * WidthRatio); } + } + + /// + /// Actual texture space used in y direction + /// + public int UsedHeight + { + get { return (int)(_H2 * HeightRatio); } + } + /* /// /// Internal use. Specifies if full texture memory should be used diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 21e6814d..f86041f0 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -204,7 +204,7 @@ namespace VocaluxeLib.Menu private bool _DrawTexture() { CTexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); - if (texture.OrigSize.Height > 1) + if (texture != null) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; @@ -219,7 +219,7 @@ namespace VocaluxeLib.Menu private bool _DrawVideo() { CTexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); - if (videoTexture.OrigSize.Height > 1) + if (videoTexture != null) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; @@ -234,7 +234,7 @@ namespace VocaluxeLib.Menu private bool _DrawBackgroundMusicVideo() { CTexture videoTexture = CBase.BackgroundMusic.GetVideoTexture(); - if (videoTexture.OrigSize.Height > 1) + if (videoTexture != null) { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 5b073b48..dc6fea65 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -438,19 +438,21 @@ namespace VocaluxeLib.Menu.SongMenu if (_Actsong != _PreviewSelected) _SelectSong(_PreviewSelected); - if (_Streams.Count > 0 && _Video != -1) + if (_Streams.Count <= 0 || _Video == -1) + return; + + if (CBase.Video.IsFinished(_Video) || CBase.Sound.IsFinished(_Actsongstream)) { - if (CBase.Video.IsFinished(_Video) || CBase.Sound.IsFinished(_Actsongstream)) - { - CBase.Video.Close(_Video); - _Video = -1; - return; - } + CBase.Video.Close(_Video); + _Video = -1; + return; + } - float time = CBase.Sound.GetPosition(_Actsongstream); + float time = CBase.Sound.GetPosition(_Actsongstream); - float vtime; - CBase.Video.GetFrame(_Video, ref _Vidtex, time, out vtime); + float vtime; + if (CBase.Video.GetFrame(_Video, ref _Vidtex, time, out vtime)) + { if (_VideoFadeTimer.ElapsedMilliseconds <= 3000L) _Vidtex.Color.A = _VideoFadeTimer.ElapsedMilliseconds / 3000f; else From 7f5cbbf686f083fc4166554223873524a2fa00bb Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 14:31:20 +0200 Subject: [PATCH 16/22] Fixed string comparisons Added CCursor.ReloadTextures without position flickering --- Vocaluxe/Base/CCover.cs | 2 +- Vocaluxe/Base/CGraphics.cs | 83 ++++++------------- Vocaluxe/Base/CProfiles.cs | 8 +- Vocaluxe/Base/CTheme.cs | 7 +- Vocaluxe/Screens/CScreenSing.cs | 4 +- VocaluxeLib/Menu/CBackground.cs | 10 +-- VocaluxeLib/Menu/CButton.cs | 8 +- VocaluxeLib/Menu/CEqualizer.cs | 8 +- VocaluxeLib/Menu/CLyric.cs | 8 +- VocaluxeLib/Menu/CNameSelection.cs | 8 +- VocaluxeLib/Menu/CParticle.cs | 10 +-- VocaluxeLib/Menu/CPlaylist.cs | 10 +-- VocaluxeLib/Menu/CSelectSlide.cs | 28 +++---- VocaluxeLib/Menu/CStatic.cs | 10 +-- VocaluxeLib/Menu/CText.cs | 8 +- .../Menu/SongMenu/CSongMenuFramework.cs | 4 +- 16 files changed, 90 insertions(+), 126 deletions(-) diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 3f69813a..2f99b82d 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -186,7 +186,7 @@ namespace Vocaluxe.Base { SCoverTheme coverTheme = _CoverTheme(coverThemeName); - if (coverTheme.Name == "") + if (String.IsNullOrEmpty(coverTheme.Name)) return; CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index efb5404a..7b2f3247 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -32,29 +32,26 @@ namespace Vocaluxe.Base { class CCursor { - private readonly Stopwatch _CursorFadingTimer; - private float _CursorTargetAlpha; + private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); + private float _CursorTargetAlpha = 1f; private float _CursorStartAlpha; - private float _CursorFadingTime; + private float _CursorFadingTime = 0.5f; private CTexture _Cursor; - private readonly string _CursorName = String.Empty; - private readonly Stopwatch _Movetimer; + private readonly Stopwatch _Movetimer = new Stopwatch(); - public bool ShowCursor; + public bool ShowCursor = true; public bool Visible = true; public bool CursorVisible = true; public int X { get { return (int)_Cursor.Rect.X; } - set { UpdatePosition(value, (int)_Cursor.Rect.Y); } } public int Y { get { return (int)_Cursor.Rect.Y; } - set { UpdatePosition((int)_Cursor.Rect.X, value); } } public bool IsActive @@ -62,25 +59,6 @@ namespace Vocaluxe.Base get { return _Movetimer.IsRunning; } } - public CCursor(string textureName, SColorF color, float w, float h, float z) - { - _CursorFadingTimer = new Stopwatch(); - ShowCursor = true; - _CursorTargetAlpha = 1f; - _CursorStartAlpha = 0f; - _CursorFadingTime = 0.5f; - - _CursorName = textureName; - _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(_CursorName, -1)); - - _Cursor.Color = color; - _Cursor.Rect.W = w; - _Cursor.Rect.H = h; - _Cursor.Rect.Z = z; - - _Movetimer = new Stopwatch(); - } - public void Draw() { if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) @@ -128,6 +106,17 @@ namespace Vocaluxe.Base _Cursor.Rect.Y = y; } + public void LoadTextures() + { + _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(CTheme.Cursor.SkinName, -1)); + + _Cursor.Color = !String.IsNullOrEmpty(CTheme.Cursor.Color) + ? CTheme.GetColor(CTheme.Cursor.Color, -1) : new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A); + _Cursor.Rect.W = CTheme.Cursor.W; + _Cursor.Rect.H = CTheme.Cursor.H; + _Cursor.Rect.Z = CSettings.ZNear; + } + public void UnloadTextures() { CDraw.RemoveTexture(ref _Cursor); @@ -135,9 +124,11 @@ namespace Vocaluxe.Base public void ReloadTextures() { + int x = X; + int y = Y; UnloadTextures(); - - _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(_CursorName, -1)); + LoadTextures(); + UpdatePosition(x, y); } public void FadeOut() @@ -175,7 +166,7 @@ namespace Vocaluxe.Base { private static bool _Fading; private static Stopwatch _FadingTimer; - private static CCursor _Cursor; + private static readonly CCursor _Cursor = new CCursor(); private static float _GlobalAlpha; private static float _ZOffset; @@ -252,12 +243,7 @@ namespace Vocaluxe.Base public static void LoadTheme() { - _Cursor = new CCursor( - CTheme.Cursor.SkinName, - new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A), - CTheme.Cursor.W, - CTheme.Cursor.H, - CSettings.ZNear); + _Cursor.LoadTextures(); for (int i = 0; i < _Screens.Count; i++) { @@ -276,7 +262,7 @@ namespace Vocaluxe.Base public static void ReloadTheme() { - _ReloadCursor(); + _Cursor.ReloadTextures(); foreach (IMenu screen in _Screens) screen.ReloadTheme(CTheme.GetThemeScreensPath(-1)); @@ -286,7 +272,7 @@ namespace Vocaluxe.Base public static void ReloadSkin() { - _ReloadCursor(); + _Cursor.ReloadTextures(); foreach (IMenu menu in _Screens) menu.ReloadTextures(); @@ -782,27 +768,6 @@ namespace Vocaluxe.Base y += rect.Height; } } - - private static void _ReloadCursor() - { - _Cursor.UnloadTextures(); - - if (CTheme.Cursor.Color != "") - { - SColorF color = CTheme.GetColor(CTheme.Cursor.Color, -1); - CTheme.Cursor.R = color.R; - CTheme.Cursor.G = color.G; - CTheme.Cursor.B = color.B; - CTheme.Cursor.A = color.A; - } - - _Cursor = new CCursor( - CTheme.Cursor.SkinName, - new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A), - CTheme.Cursor.W, - CTheme.Cursor.H, - CSettings.ZNear); - } #endregion private stuff } } \ No newline at end of file diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index aa45b4d2..e19b69ef 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -156,7 +156,7 @@ namespace Vocaluxe.Base return String.Empty; SProfile profile = _Profiles[profileID]; - if (profile.PlayerName != "") + if (!String.IsNullOrEmpty(profile.PlayerName)) profile.PlayerName = profile.PlayerName.Remove(profile.PlayerName.Length - 1); _Profiles[profileID] = profile; @@ -255,7 +255,7 @@ namespace Vocaluxe.Base { if (!IsProfileIDValid(profileID)) return; - if (_Profiles[profileID].ProfileFile == "") + if (String.IsNullOrEmpty(_Profiles[profileID].ProfileFile)) return; try { @@ -311,9 +311,9 @@ namespace Vocaluxe.Base if (!IsProfileIDValid(profileID)) return; - if (_Profiles[profileID].ProfileFile == "") + if (String.IsNullOrEmpty(_Profiles[profileID].ProfileFile)) { - string filename = string.Empty; + string filename = ""; foreach (char chr in _Profiles[profileID].PlayerName) { if (char.IsLetter(chr)) diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 5995e024..51d8c44b 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -809,7 +809,7 @@ namespace Vocaluxe.Base writer.WriteElementString("W", Cursor.W.ToString("#0.000")); writer.WriteElementString("H", Cursor.H.ToString("#0.000")); - if (Cursor.Color != "") + if (!String.IsNullOrEmpty(Cursor.Color)) writer.WriteElementString("Color", Cursor.Color); else { @@ -871,7 +871,7 @@ namespace Vocaluxe.Base public static SColorF GetPlayerColor(string playerNrString, int skinIndex, out bool success) { int selection = 0; - if (playerNrString.StartsWith("Player")) + if (playerNrString != null && playerNrString.StartsWith("Player")) int.TryParse(playerNrString.Substring(6), out selection); return GetPlayerColor(selection, skinIndex, out success); @@ -885,13 +885,12 @@ namespace Vocaluxe.Base public static SColorF GetPlayerColor(int playerNr, int skinIndex, out bool success) { success = false; - SColorF color = new SColorF(1f, 1f, 1f, 1f); if (_Skins[skinIndex].PartyModeID != -1) skinIndex = GetSkinIndex(-1); if (_Skins[skinIndex].ThemeColors.Player.Length < playerNr || playerNr < 1) - return color; + return new SColorF(1f, 1f, 1f, 1f); success = true; return _Skins[skinIndex].ThemeColors.Player[playerNr - 1]; diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 3ce4ddff..a359885a 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -614,7 +614,7 @@ namespace Vocaluxe.Screens CDraw.RemoveTexture(ref _CurrentVideoTexture); - if (song.VideoFileName != "") + if (!String.IsNullOrEmpty(song.VideoFileName)) { _CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName)); CVideo.Skip(_CurrentVideo, song.Start, song.VideoGap); @@ -622,7 +622,7 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); - if (song.BackgroundFileName != "") + if (!String.IsNullOrEmpty(song.BackgroundFileName)) _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileName)); _SingNotes[_SingBars].Reset(); diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index f86041f0..068ea9fc 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -119,7 +119,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Background color for type \"Color\" from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -140,13 +140,13 @@ namespace VocaluxeLib.Menu public void Resume() { - if (_Theme.Type == EBackgroundTypes.Video && _Theme.VideoName != "" && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) + if (_Theme.Type == EBackgroundTypes.Video && !String.IsNullOrEmpty(_Theme.VideoName) && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) CBase.Theme.SkinVideoResume(_Theme.VideoName, _PartyModeID); } public void Pause() { - if (_Theme.VideoName != "") + if (!String.IsNullOrEmpty(_Theme.VideoName)) CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID); } @@ -166,7 +166,7 @@ namespace VocaluxeLib.Menu ok = _DrawVideo(); } - if (_Theme.TextureName != "" && + if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) ok = _DrawTexture(); @@ -182,7 +182,7 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index 34fa5fa7..e5551a93 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -221,7 +221,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -233,7 +233,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -341,10 +341,10 @@ namespace VocaluxeLib.Menu { Text.LoadTextures(); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CEqualizer.cs b/VocaluxeLib/Menu/CEqualizer.cs index 5c258229..c65b42c0 100644 --- a/VocaluxeLib/Menu/CEqualizer.cs +++ b/VocaluxeLib/Menu/CEqualizer.cs @@ -175,7 +175,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Equalizer color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -186,7 +186,7 @@ namespace VocaluxeLib.Menu } writer.WriteComment(": Equalizer color for maximal volume from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("MaxColor", _Theme.ColorName); else { @@ -274,10 +274,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.MaxColorName != "") + if (!String.IsNullOrEmpty(_Theme.MaxColorName)) MaxColor = CBase.Theme.GetColor(_Theme.MaxColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CLyric.cs b/VocaluxeLib/Menu/CLyric.cs index aeffa9f8..3bcce6ff 100644 --- a/VocaluxeLib/Menu/CLyric.cs +++ b/VocaluxeLib/Menu/CLyric.cs @@ -172,7 +172,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Lyric text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -184,7 +184,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Highlighted lyric color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -521,10 +521,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) _ColorProcessed = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 2347ca88..563a8ea6 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -193,7 +193,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorEmptyTileName != "") + if (!String.IsNullOrEmpty(_Theme.ColorEmptyTileName)) writer.WriteElementString("ColorEmptyTile", _Theme.ColorEmptyTileName); else { @@ -224,7 +224,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text font name"); writer.WriteElementString("Font", _Theme.NameFont); writer.WriteComment(": Text color from ColorScheme (high priority)"); - if (_Theme.NameColorName != "") + if (!String.IsNullOrEmpty(_Theme.NameColorName)) writer.WriteElementString("Color", _Theme.NameColorName); else { @@ -464,10 +464,10 @@ namespace VocaluxeLib.Menu _TextureEmptyTile = CBase.Theme.GetSkinTexture(_Theme.TextureEmptyTileName, _PartyModeID); _TextureTileSelected = CBase.Theme.GetSkinTexture(_Theme.TextureTileSelectedName, _PartyModeID); - if (_Theme.ColorEmptyTileName != "") + if (!String.IsNullOrEmpty(_Theme.ColorEmptyTileName)) ColorEmptyTile = CBase.Theme.GetColor(_Theme.ColorEmptyTileName, _PartyModeID); - if (_Theme.NameColorName != "") + if (!String.IsNullOrEmpty(_Theme.NameColorName)) _Theme.NameColor = CBase.Theme.GetColor(_Theme.NameColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index 0f2fb800..3e49902b 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -288,7 +288,7 @@ namespace VocaluxeLib.Menu public void Draw() { // ReSharper disable ConvertIfStatementToConditionalTernaryExpression - if (_TextureName != "") + if (!String.IsNullOrEmpty(_TextureName)) // ReSharper restore ConvertIfStatementToConditionalTernaryExpression CBase.Drawing.DrawTexture(CBase.Theme.GetSkinTexture(_TextureName, _PartyModeID), _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); else @@ -424,7 +424,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": ParticleEffect color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -535,7 +535,7 @@ namespace VocaluxeLib.Menu h = 0; CParticle star; - if (_Theme.TextureName != "") + if (!String.IsNullOrEmpty(_Theme.TextureName)) { star = new CParticle(_PartyModeID, _Theme.TextureName, Color, CBase.Game.GetRandom(w) + Rect.X - size / 4f, @@ -596,9 +596,9 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.TextureName != "") + if (!String.IsNullOrEmpty(_Theme.TextureName)) Texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index 29bb1943..ade23834 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -372,7 +372,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorBackgroundName != "") + if (!String.IsNullOrEmpty(_Theme.ColorBackgroundName)) writer.WriteElementString("ColorBackground", _Theme.ColorBackgroundName); else { @@ -384,7 +384,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected paylist-entry color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorBackgroundName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorBackgroundName)) writer.WriteElementString("SColorBackground", _Theme.SelColorBackgroundName); else { @@ -463,10 +463,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorBackgroundName != "") + if (!String.IsNullOrEmpty(_Theme.ColorBackgroundName)) BackgroundColor = CBase.Theme.GetColor(_Theme.ColorBackgroundName, _PartyModeID); - if (_Theme.SelColorBackgroundName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorBackgroundName)) BackgroundSelColor = CBase.Theme.GetColor(_Theme.SelColorBackgroundName, _PartyModeID); _Theme.Text1.LoadTextures(); @@ -517,7 +517,7 @@ namespace VocaluxeLib.Menu break; case Keys.Delete: case Keys.Back: - if (_Theme.ButtonPlaylistName.Text.Text != "") + if (!String.IsNullOrEmpty(_Theme.ButtonPlaylistName.Text.Text)) _Theme.ButtonPlaylistName.Text.Text = _Theme.ButtonPlaylistName.Text.Text.Remove(_Theme.ButtonPlaylistName.Text.Text.Length - 1); break; } diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 28947a5c..b7f62571 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -412,7 +412,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -424,7 +424,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -436,7 +436,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Highlighted SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or
, , , (lower priority)"); - if (_Theme.HighlightColorName != "") + if (!String.IsNullOrEmpty(_Theme.HighlightColorName)) writer.WriteElementString("HColor", _Theme.HighlightColorName); else { @@ -448,7 +448,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ArrowColorName != "") + if (!String.IsNullOrEmpty(_Theme.ArrowColorName)) writer.WriteElementString("ArrowColor", _Theme.ArrowColorName); else { @@ -460,7 +460,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelArrowColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelArrowColorName)) writer.WriteElementString("ArrowSColor", _Theme.SelArrowColorName); else { @@ -472,7 +472,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.TextColorName != "") + if (!String.IsNullOrEmpty(_Theme.TextColorName)) writer.WriteElementString("TextColor", _Theme.TextColorName); else { @@ -484,7 +484,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelTextColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelTextColorName)) writer.WriteElementString("TextSColor", _Theme.SelTextColorName); else { @@ -787,25 +787,25 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); - if (_Theme.HighlightColorName != "") + if (!String.IsNullOrEmpty(_Theme.HighlightColorName)) HighlightColor = CBase.Theme.GetColor(_Theme.HighlightColorName, _PartyModeID); - if (_Theme.ArrowColorName != "") + if (!String.IsNullOrEmpty(_Theme.ArrowColorName)) ColorArrow = CBase.Theme.GetColor(_Theme.ArrowColorName, _PartyModeID); - if (_Theme.SelArrowColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelArrowColorName)) SelColorArrow = CBase.Theme.GetColor(_Theme.SelArrowColorName, _PartyModeID); - if (_Theme.TextColorName != "") + if (!String.IsNullOrEmpty(_Theme.TextColorName)) TextColor = CBase.Theme.GetColor(_Theme.TextColorName, _PartyModeID); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) SelTextColor = CBase.Theme.GetColor(_Theme.SelTextColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index d995021e..159b6319 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?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } + get { return _Texture ?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } set { _Texture = value; } } @@ -59,9 +59,9 @@ namespace VocaluxeLib.Menu public float ReflectionHeight; public bool Selected; - public bool Visible=true; + public bool Visible = true; - public float Alpha=1; + public float Alpha = 1; public EAspect Aspect = EAspect.Stretch; @@ -161,7 +161,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , ,
(lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -244,7 +244,7 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index 6fc4e09f..04b84814 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -396,7 +396,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -408,7 +408,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -521,10 +521,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName != "") + if (!String.IsNullOrEmpty(_Theme.SelColorName)) SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index dc6fea65..65917ace 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -351,7 +351,7 @@ namespace VocaluxeLib.Menu.SongMenu writer.WriteComment(": Tile color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) writer.WriteElementString("Color", _Theme.ColorName); else { @@ -548,7 +548,7 @@ namespace VocaluxeLib.Menu.SongMenu { Init(); - if (_Theme.ColorName != "") + if (!String.IsNullOrEmpty(_Theme.ColorName)) _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } From 2ca2af6ea64d91e7c82698bbf14b2788d474fae9 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 14:36:23 +0200 Subject: [PATCH 17/22] Moved CCursor --- Vocaluxe/Base/CCover.cs | 10 +-- Vocaluxe/Base/CCursor.cs | 138 +++++++++++++++++++++++++++++++++ Vocaluxe/Base/CGraphics.cs | 135 +------------------------------- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 - Vocaluxe/Vocaluxe.csproj | 1 + 5 files changed, 143 insertions(+), 143 deletions(-) create mode 100644 Vocaluxe/Base/CCursor.cs diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 2f99b82d..43abe8e8 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -136,16 +136,12 @@ namespace Vocaluxe.Base ///
private static SCoverTheme _CoverTheme(string coverThemeName) { - SCoverTheme coverTheme = new SCoverTheme(); for (int i = 0; i < _CoverThemes.Count; i++) { if (_CoverThemes[i].Name == coverThemeName) - { - coverTheme = _CoverThemes[i]; - break; - } + return _CoverThemes[i]; } - return coverTheme; + return new SCoverTheme(); } /// @@ -231,7 +227,7 @@ namespace Vocaluxe.Base if (_CoverExists(name)) continue; // ReSharper disable AssignNullToNotNullAttribute - SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.GetFileName(file)))}; + SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(file)}; // ReSharper restore AssignNullToNotNullAttribute _Cover.Add(sk); diff --git a/Vocaluxe/Base/CCursor.cs b/Vocaluxe/Base/CCursor.cs new file mode 100644 index 00000000..4a3b45d0 --- /dev/null +++ b/Vocaluxe/Base/CCursor.cs @@ -0,0 +1,138 @@ +using System; +using System.Diagnostics; +using VocaluxeLib.Draw; +using VocaluxeLib.Menu; + +namespace Vocaluxe.Base +{ + class CCursor + { + private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); + private float _CursorTargetAlpha = 1f; + private float _CursorStartAlpha; + private float _CursorFadingTime = 0.5f; + private CTexture _Cursor; + + private readonly Stopwatch _Movetimer = new Stopwatch(); + + public bool ShowCursor = true; + public bool Visible = true; + + public int X + { + get { return (int)_Cursor.Rect.X; } + } + + public int Y + { + get { return (int)_Cursor.Rect.Y; } + } + + public bool IsActive + { + get { return _Movetimer.IsRunning; } + } + + public void Draw() + { + if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) + { + _Movetimer.Stop(); + _Fade(0f, 0.5f); + } + + + if (_CursorFadingTimer.IsRunning) + { + float t = _CursorFadingTimer.ElapsedMilliseconds / 1000f; + if (t < _CursorFadingTime) + { + if (_CursorTargetAlpha >= _CursorStartAlpha) + _Cursor.Color.A = _CursorStartAlpha + (_CursorTargetAlpha - _CursorStartAlpha) * t / _CursorFadingTime; + else + _Cursor.Color.A = (_CursorStartAlpha - _CursorTargetAlpha) * (1f - t / _CursorFadingTime); + } + else + { + _CursorFadingTimer.Stop(); + _Cursor.Color.A = _CursorTargetAlpha; + } + } + + if (Visible && (CSettings.GameState == EGameState.EditTheme || ShowCursor)) + CDraw.DrawTexture(_Cursor); + } + + public void UpdatePosition(int x, int y) + { + if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || + Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) + { + if (_CursorTargetAlpha < 0.01) + _Fade(1f, 0.2f); + + _Movetimer.Reset(); + _Movetimer.Start(); + CSettings.MouseActive(); + } + + _Cursor.Rect.X = x; + _Cursor.Rect.Y = y; + } + + public void LoadTextures() + { + _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(CTheme.Cursor.SkinName, -1)); + + _Cursor.Color = !String.IsNullOrEmpty(CTheme.Cursor.Color) + ? CTheme.GetColor(CTheme.Cursor.Color, -1) : new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A); + _Cursor.Rect.W = CTheme.Cursor.W; + _Cursor.Rect.H = CTheme.Cursor.H; + _Cursor.Rect.Z = CSettings.ZNear; + } + + public void UnloadTextures() + { + CDraw.RemoveTexture(ref _Cursor); + } + + public void ReloadTextures() + { + int x = X; + int y = Y; + UnloadTextures(); + LoadTextures(); + UpdatePosition(x, y); + } + + public void FadeOut() + { + _Movetimer.Stop(); + _Fade(0f, 0.5f); + } + + public void FadeIn() + { + _Movetimer.Reset(); + _Movetimer.Start(); + _Fade(1f, 0.2f); + } + + private void _Fade(float targetAlpha, float time) + { + _CursorFadingTimer.Stop(); + _CursorFadingTimer.Reset(); + + if (targetAlpha >= 0f && targetAlpha <= 1f) + _CursorTargetAlpha = targetAlpha; + else + _CursorTargetAlpha = 1f; + + if (time >= 0f) + _CursorFadingTime = time; + + _CursorStartAlpha = _Cursor.Color.A; + _CursorFadingTimer.Start(); + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 7b2f3247..945d30e0 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -24,144 +24,11 @@ using System.Drawing; using System.Windows.Forms; using Vocaluxe.Base.Fonts; using Vocaluxe.Screens; -using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; namespace Vocaluxe.Base { - class CCursor - { - private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); - private float _CursorTargetAlpha = 1f; - private float _CursorStartAlpha; - private float _CursorFadingTime = 0.5f; - private CTexture _Cursor; - - private readonly Stopwatch _Movetimer = new Stopwatch(); - - public bool ShowCursor = true; - public bool Visible = true; - public bool CursorVisible = true; - - public int X - { - get { return (int)_Cursor.Rect.X; } - } - - public int Y - { - get { return (int)_Cursor.Rect.Y; } - } - - public bool IsActive - { - get { return _Movetimer.IsRunning; } - } - - public void Draw() - { - if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) - { - _Movetimer.Stop(); - _Fade(0f, 0.5f); - } - - - if (_CursorFadingTimer.IsRunning) - { - float t = _CursorFadingTimer.ElapsedMilliseconds / 1000f; - if (t < _CursorFadingTime) - { - if (_CursorTargetAlpha >= _CursorStartAlpha) - _Cursor.Color.A = _CursorStartAlpha + (_CursorTargetAlpha - _CursorStartAlpha) * t / _CursorFadingTime; - else - _Cursor.Color.A = (_CursorStartAlpha - _CursorTargetAlpha) * (1f - t / _CursorFadingTime); - } - else - { - _CursorFadingTimer.Stop(); - _Cursor.Color.A = _CursorTargetAlpha; - } - } - - if (CursorVisible && (CSettings.GameState == EGameState.EditTheme || ShowCursor)) - CDraw.DrawTexture(_Cursor); - } - - public void UpdatePosition(int x, int y) - { - if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || - Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) - { - if (_CursorTargetAlpha < 0.01) - _Fade(1f, 0.2f); - - _Movetimer.Reset(); - _Movetimer.Start(); - CSettings.MouseActive(); - } - - _Cursor.Rect.X = x; - _Cursor.Rect.Y = y; - } - - public void LoadTextures() - { - _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(CTheme.Cursor.SkinName, -1)); - - _Cursor.Color = !String.IsNullOrEmpty(CTheme.Cursor.Color) - ? CTheme.GetColor(CTheme.Cursor.Color, -1) : new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A); - _Cursor.Rect.W = CTheme.Cursor.W; - _Cursor.Rect.H = CTheme.Cursor.H; - _Cursor.Rect.Z = CSettings.ZNear; - } - - public void UnloadTextures() - { - CDraw.RemoveTexture(ref _Cursor); - } - - public void ReloadTextures() - { - int x = X; - int y = Y; - UnloadTextures(); - LoadTextures(); - UpdatePosition(x, y); - } - - public void FadeOut() - { - _Movetimer.Stop(); - _Fade(0f, 0.5f); - } - - public void FadeIn() - { - _Movetimer.Reset(); - _Movetimer.Start(); - _Fade(1f, 0.2f); - } - - private void _Fade(float targetAlpha, float time) - { - _CursorFadingTimer.Stop(); - _CursorFadingTimer.Reset(); - - if (targetAlpha >= 0f && targetAlpha <= 1f) - _CursorTargetAlpha = targetAlpha; - else - _CursorTargetAlpha = 1f; - - if (time >= 0f) - _CursorFadingTime = time; - - _CursorStartAlpha = _Cursor.Color.A; - _CursorFadingTimer.Start(); - } - } - static class CGraphics { private static bool _Fading; @@ -299,7 +166,7 @@ namespace Vocaluxe.Base public static bool UpdateGameLogic(CKeys keys, CMouse mouse) { bool run = true; - _Cursor.CursorVisible = mouse.Visible; + _Cursor.Visible = mouse.Visible; mouse.CopyEvents(); keys.CopyEvents(); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 9d92cb2b..c3e0798f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -735,8 +735,6 @@ namespace Vocaluxe.Lib.Draw screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); screen.Dispose(); } - Cursor.Hide(); - _Mouse.Visible = true; } /// diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 53c2b29b..bd9bb9b2 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -174,6 +174,7 @@ + From 5587a322beefd1da62d0e367abe38dc585adc568 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 15:23:12 +0200 Subject: [PATCH 18/22] Removed second texture list in D3D (needed to check for GC disposal of CTexture) --- Vocaluxe/Lib/Draw/CDirect3D.cs | 85 +++++++++++++--------------------- Vocaluxe/Lib/Draw/COpenGL.cs | 21 +++++++-- 2 files changed, 48 insertions(+), 58 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index c3e0798f..57cad324 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -51,10 +51,9 @@ namespace Vocaluxe.Lib.Draw private Size _OldSize; private Size _SizeBeforeMinimize; - private readonly Dictionary _Textures; - private readonly Dictionary _D3DTextures; - private readonly List _Queue; - private readonly Queue _IDs; + private readonly Dictionary _D3DTextures = new Dictionary(); + private readonly List _Queue = new List(); + private readonly Queue _IDs = new Queue(); private readonly Object _MutexTexture = new Object(); @@ -68,9 +67,9 @@ namespace Vocaluxe.Lib.Draw private CTexture _BlankTexture; - private readonly Queue _Vertices; - private readonly Queue _VerticesTextures; - private readonly Queue _VerticesRotationMatrices; + private readonly Queue _Vertices = new Queue(); + private readonly Queue _VerticesTextures = new Queue(); + private readonly Queue _VerticesRotationMatrices = new Queue(); private readonly bool _NonPowerOf2TextureSupported; #endregion private vars @@ -81,19 +80,11 @@ namespace Vocaluxe.Lib.Draw public CDirect3D() { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new Dictionary(); - _D3DTextures = new Dictionary(); - _Queue = new List(); - _IDs = new Queue(); //Fill Queue with 100000 IDs for (int i = 0; i < 100000; i++) _IDs.Enqueue(i); - _Vertices = new Queue(); - _VerticesTextures = new Queue(); - _VerticesRotationMatrices = new Queue(); - _Keys = new CKeys(); try { @@ -691,7 +682,6 @@ namespace Vocaluxe.Lib.Draw texture.Index = _IDs.Dequeue(); _D3DTextures.Add(texture.Index, tex); - _Textures[texture.Index] = texture; return texture; } } @@ -901,57 +891,55 @@ namespace Vocaluxe.Lib.Draw private CTexture _AddTexture(CTexture texture, int w, byte[] data) { - Texture t = _CreateTexture(texture, w, data); + Texture t = _CreateTexture(texture.W2, texture.H2, w, data); lock (_MutexTexture) { - _D3DTextures.Add(_IDs.Peek(), t); texture.Index = _IDs.Dequeue(); - _Textures[texture.Index] = texture; + _D3DTextures.Add(texture.Index, t); } return texture; } - private Texture _CreateTexture(CTexture texture, int w, byte[] data) + private Texture _CreateTexture(int textureW, int textureH, 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 - Texture t = null; - try + Texture t; + using (t = new Texture(_Device, textureW, textureH, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed)) + _WriteDataToTexture(t, w, data); + return t; + } + + private static void _WriteDataToTexture(Texture t, int w, byte[] data) + { + //Lock the texture and fill it with the data + DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); + int rowWidth = 4 * w; + if (rowWidth == rect.Pitch) + rect.Data.Write(data, 0, data.Length); + else { - t = new Texture(_Device, texture.W2, texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); - //Lock the texture and fill it with the data - DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); - int rowWidth = 4 * w; for (int i = 0; i + rowWidth <= data.Length; i += rowWidth) { rect.Data.Write(data, i, rowWidth); //Go to next row rect.Data.Position = rect.Data.Position - rowWidth + rect.Pitch; } - t.UnlockRectangle(0); } - catch (Exception) - { - if (t != null) - t.Dispose(); - throw; - } - return t; + t.UnlockRectangle(0); } public CTexture EnqueueTexture(int w, int h, byte[] data) { CTexture texture = _GetNewTexture(w, h); - STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) { - _D3DTextures.Add(_IDs.Peek(), null); texture.Index = _IDs.Dequeue(); - queue.Index = texture.Index; + _D3DTextures.Add(texture.Index, null); + STextureQueue queue = new STextureQueue(texture.Index, texture.W2, texture.H2, w, h, data); _Queue.Add(queue); - _Textures[texture.Index] = texture; } return texture; } @@ -978,15 +966,7 @@ namespace Vocaluxe.Lib.Draw return false; lock (_MutexTexture) { - DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); - int rowWidth = 4 * w; - for (int i = 0; i + rowWidth <= data.Length; i += rowWidth) - { - rect.Data.Write(data, i, rowWidth); - //Go to next row - rect.Data.Position = rect.Data.Position - rowWidth + rect.Pitch; - } - _D3DTextures[texture.Index].UnlockRectangle(0); + _WriteDataToTexture(_D3DTextures[texture.Index], w, data); } return true; } @@ -1011,7 +991,7 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - return texture != null && _Textures.ContainsKey(texture.Index); + return texture != null && _D3DTextures.ContainsKey(texture.Index); } } @@ -1027,7 +1007,6 @@ namespace Vocaluxe.Lib.Draw { _D3DTextures[texture.Index].Dispose(); _D3DTextures.Remove(texture.Index); - _Textures.Remove(texture.Index); _IDs.Enqueue(texture.Index); } } @@ -1295,11 +1274,11 @@ namespace Vocaluxe.Lib.Draw { STextureQueue q = _Queue[0]; _Queue.RemoveAt(0); - CTexture texture; - if (!_Textures.TryGetValue(q.Index, out texture)) + Texture t; + if (_D3DTextures.TryGetValue(q.Index, out t) && t != null) continue; - Texture t = _CreateTexture(texture, q.Width, q.Data); + t = _CreateTexture(q.TextureWidth, q.TextureHeight, q.DataWidth, q.Data); _D3DTextures[q.Index] = t; } } @@ -1311,7 +1290,7 @@ namespace Vocaluxe.Lib.Draw /// The amount of textures public int GetTextureCount() { - return _Textures.Count; + return _D3DTextures.Count; } #endregion Textures diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 57e93f9a..d2eda560 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -66,9 +66,21 @@ namespace Vocaluxe.Lib.Draw struct STextureQueue { public int Index; - public int Width; - public int Height; + public int TextureWidth; + public int TextureHeight; + public int DataWidth; + public int DataHeight; public byte[] Data; + + public STextureQueue(int index, int textureWidth, int textureHeight, int dataWidth, int dataHeight, byte[] data) + { + Index = index; + TextureWidth = textureWidth; + TextureHeight = textureHeight; + DataWidth = dataWidth; + DataHeight = dataHeight; + Data = data; + } } class COpenGL : Form, IDraw @@ -811,12 +823,11 @@ namespace Vocaluxe.Lib.Draw public CTexture EnqueueTexture(int w, int h, byte[] data) { CTexture texture = _GetNewTexture(w, h); - STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) { texture.Index = _IDs.Dequeue(); - queue.Index = texture.Index; + STextureQueue queue = new STextureQueue(texture.Index, texture.W2, texture.H2, w, h, data); _Queue.Add(queue); _Textures[texture.Index] = texture; } @@ -1183,7 +1194,7 @@ namespace Vocaluxe.Lib.Draw if (!_Textures.TryGetValue(q.Index, out texture)) continue; - _CreateTexture(texture, q.Width, q.Height, q.Data); + _CreateTexture(texture, q.DataWidth, q.DataHeight, q.Data); } } } From 914f15f0ad66922906a4510cf1cd05c04bc3accc Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 17:53:44 +0200 Subject: [PATCH 19/22] Some styling for Draw classes --- Vocaluxe/Lib/Draw/CDirect3D.cs | 63 +++++++++++++------------ Vocaluxe/Lib/Draw/COpenGL.cs | 85 +++++++++++++++------------------- 2 files changed, 68 insertions(+), 80 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 57cad324..9b8bb989 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -246,40 +246,39 @@ namespace Vocaluxe.Lib.Draw // The window was minimized, so restore it to the last known size if (ClientSize.Width == 0 || ClientSize.Height == 0) ClientSize = _SizeBeforeMinimize; - if (_Run) + if (!_Run) + return; + _H = ClientSize.Height; + _W = ClientSize.Width; + _Y = 0; + _X = 0; + + if (_W / (float)_H > CSettings.GetRenderAspect()) { - _H = ClientSize.Height; - _W = ClientSize.Width; - _Y = 0; - _X = 0; - - if (_W / (float)_H > CSettings.GetRenderAspect()) - { - //The windows's width is too big - _W = (int)Math.Round(_H * CSettings.GetRenderAspect()); - _X = (ClientSize.Width - _W) / 2; - } - else - { - //The windows's height is too big - _H = (int)Math.Round(_W / CSettings.GetRenderAspect()); - _Y = (ClientSize.Height - _H) / 2; - } - - //Apply the new sizes to the PresentParameters - _PresentParameters.BackBufferWidth = ClientSize.Width; - _PresentParameters.BackBufferHeight = ClientSize.Height; - ClearScreen(); - //To set new PresentParameters the device has to be resetted - _Reset(); - //All configurations got flushed due to Reset(), so apply them again - Init(); - - //Set the new Viewport - _Device.Viewport = new Viewport(_X, _Y, _W, _H); - //Store size so it can get restored after the window gets minimized - _SizeBeforeMinimize = ClientSize; + //The windows's width is too big + _W = (int)Math.Round(_H * CSettings.GetRenderAspect()); + _X = (ClientSize.Width - _W) / 2; } + else + { + //The windows's height is too big + _H = (int)Math.Round(_W / CSettings.GetRenderAspect()); + _Y = (ClientSize.Height - _H) / 2; + } + + //Apply the new sizes to the PresentParameters + _PresentParameters.BackBufferWidth = ClientSize.Width; + _PresentParameters.BackBufferHeight = ClientSize.Height; + ClearScreen(); + //To set new PresentParameters the device has to be resetted + _Reset(); + //All configurations got flushed due to Reset(), so apply them again + Init(); + + //Set the new Viewport + _Device.Viewport = new Viewport(_X, _Y, _W, _H); + //Store size so it can get restored after the window gets minimized + _SizeBeforeMinimize = ClientSize; } /// diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index d2eda560..fccae61f 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -441,32 +441,29 @@ namespace Vocaluxe.Lib.Draw while (_Run) { + ClearScreen(); + if (!CGraphics.Draw()) + _Run = false; + if (!CGraphics.UpdateGameLogic(_Keys, _Mouse)) + _Run = false; + + _Control.SwapBuffers(); + + if (CSettings.IsFullScreen != _Fullscreen) + _ToggleFullScreen(); + + _CheckQueue(); + + if (CTime.IsRunning()) + delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); + + if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) + Thread.Sleep(delay); + + CTime.CalculateFPS(); + CTime.Restart(); + Application.DoEvents(); - - if (_Run) - { - ClearScreen(); - if (!CGraphics.Draw()) - _Run = false; - if (!CGraphics.UpdateGameLogic(_Keys, _Mouse)) - _Run = false; - - _Control.SwapBuffers(); - - if ((CSettings.IsFullScreen && !_Fullscreen) || (!CSettings.IsFullScreen && _Fullscreen)) - _ToggleFullScreen(); - - _CheckQueue(); - - if (CTime.IsRunning()) - delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); - - if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) - Thread.Sleep(delay); - - CTime.CalculateFPS(); - CTime.Restart(); - } } Close(); } @@ -505,11 +502,10 @@ namespace Vocaluxe.Lib.Draw { CTexture texture = _GetNewTexture(_W, _H); - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + texture.ID = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture.ID); + 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); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); @@ -540,7 +536,7 @@ namespace Vocaluxe.Lib.Draw { GL.BindTexture(TextureTarget.Texture2D, texture.ID); - GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, texture.UsedWidth, texture.UsedHeight); + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, GetScreenWidth(), GetScreenHeight()); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -715,9 +711,8 @@ namespace Vocaluxe.Lib.Draw CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true); - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; + texture.ID = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture.ID); Bitmap bmp2 = null; try { @@ -751,10 +746,9 @@ namespace Vocaluxe.Lib.Draw GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); - //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); - + GL.BindTexture(TextureTarget.Texture2D, 0); // Add to Texture List texture.TexturePath = String.Empty; @@ -800,23 +794,18 @@ namespace Vocaluxe.Lib.Draw } } - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; + texture.ID = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture.ID); 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); - 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); } @@ -857,6 +846,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.BindTexture(TextureTarget.Texture2D, texture.ID); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.BindTexture(TextureTarget.Texture2D, 0); @@ -869,14 +859,13 @@ namespace Vocaluxe.Lib.Draw GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, 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.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.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); - //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; From 292f6119fd8fdb4516aa8b472833c78f4d90a692 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 13 May 2013 18:51:48 +0200 Subject: [PATCH 20/22] Removed unnecessary texture parameter setting on update --- Vocaluxe/Lib/Draw/COpenGL.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index fccae61f..db0308fd 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -824,7 +824,7 @@ namespace Vocaluxe.Lib.Draw return texture; } - private CTexture _GetNewTexture(int w, int h) + private static CTexture _GetNewTexture(int w, int h) { return new CTexture(w, h, MathHelper.NextPowerOfTwo(w), MathHelper.NextPowerOfTwo(h)); } @@ -849,6 +849,8 @@ namespace Vocaluxe.Lib.Draw GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); + GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); @@ -859,11 +861,6 @@ namespace Vocaluxe.Lib.Draw GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, 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.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); From cdad90a93df1cf6b4d3b52e12a1a0b364e8cae8c Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 13 May 2013 18:56:13 +0200 Subject: [PATCH 21/22] 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 = ""; From f1ca307bc2a7c801e237e298a073c94ecf04daab Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 13 May 2013 19:02:58 +0200 Subject: [PATCH 22/22] Used Queue instead of list for the queue --- Vocaluxe/Lib/Draw/CDirect3D.cs | 15 ++++++++------- Vocaluxe/Lib/Draw/COpenGL.cs | 21 +++++++++------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 83df21fc..b595511f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -39,6 +39,8 @@ namespace Vocaluxe.Lib.Draw class CDirect3D : RenderForm, IDraw { #region private vars + private const int _MaxID = 100000; + private readonly CKeys _Keys; private readonly CMouse _Mouse; private bool _Run; @@ -52,8 +54,8 @@ namespace Vocaluxe.Lib.Draw private Size _SizeBeforeMinimize; private readonly Dictionary _D3DTextures = new Dictionary(); - private readonly List _Queue = new List(); - private readonly Queue _IDs = new Queue(); + private readonly Queue _TexturesToLoad = new Queue(); + private readonly Queue _IDs = new Queue(_MaxID); private readonly Object _MutexTexture = new Object(); @@ -82,7 +84,7 @@ namespace Vocaluxe.Lib.Draw Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); //Fill Queue with 100000 IDs - for (int i = 0; i < 100000; i++) + for (int i = 0; i < _MaxID; i++) _IDs.Enqueue(i); _Keys = new CKeys(); @@ -938,7 +940,7 @@ namespace Vocaluxe.Lib.Draw 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); + _TexturesToLoad.Enqueue(queue); } return texture; } @@ -1269,10 +1271,9 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - while (_Queue.Count > 0) + while (_TexturesToLoad.Count > 0) { - STextureQueue q = _Queue[0]; - _Queue.RemoveAt(0); + STextureQueue q = _TexturesToLoad.Dequeue(); Texture t; if (_D3DTextures.TryGetValue(q.ID, out t) && t != null) continue; diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index c46c5f27..92ce0a0a 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -86,6 +86,8 @@ namespace Vocaluxe.Lib.Draw class COpenGL : Form, IDraw { #region private vars + private const int _MaxID = 100000; + private readonly CKeys _Keys; private readonly CMouse _Mouse; private bool _Run; @@ -95,9 +97,9 @@ namespace Vocaluxe.Lib.Draw private SClientRect _Restore; private bool _Fullscreen; - private readonly Dictionary _Textures; - private readonly Queue _IDs; - private readonly List _Queue; + private readonly Dictionary _Textures = new Dictionary(); + private readonly Queue _IDs = new Queue(_MaxID); + private readonly Queue _TexturesToLoad = new Queue(); private readonly Object _MutexTexture = new Object(); @@ -113,11 +115,7 @@ namespace Vocaluxe.Lib.Draw { Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); - _Textures = new Dictionary(); - _Queue = new List(); - _IDs = new Queue(1000000); - - for (int i = 1; i < 1000000; i++) + for (int i = 1; i < _MaxID; i++) _IDs.Enqueue(i); //Check AA Mode @@ -816,7 +814,7 @@ namespace Vocaluxe.Lib.Draw { texture.ID = _IDs.Dequeue(); STextureQueue queue = new STextureQueue(texture.ID, texture.W2, texture.H2, w, h, data); - _Queue.Add(queue); + _TexturesToLoad.Enqueue(queue); _Textures[texture.ID] = texture; } @@ -1171,10 +1169,9 @@ namespace Vocaluxe.Lib.Draw { lock (_MutexTexture) { - while (_Queue.Count > 0) + while (_TexturesToLoad.Count > 0) { - STextureQueue q = _Queue[0]; - _Queue.RemoveAt(0); + STextureQueue q = _TexturesToLoad.Dequeue(); CTexture texture; if (!_Textures.TryGetValue(q.ID, out texture)) continue;