From e8103dd80ecb31660086b1228be1178abe742a78 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sun, 13 May 2012 17:37:32 +0200 Subject: [PATCH 1/5] Added alternative method to update a texture, for now we just stick with the old one Changed lockflags to discard old data to improve performance --- Vocaluxe/Lib/Draw/CDirect3D.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3141d237..7207a945 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -477,7 +477,7 @@ namespace Vocaluxe.Lib.Draw _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(Int16), Usage.WriteOnly, Pool.Managed, true); - DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.None); + DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.Discard); stream.WriteRange(indices); _IndexBuffer.Unlock(); _Device.Indices = _IndexBuffer; @@ -944,7 +944,7 @@ namespace Vocaluxe.Lib.Draw //because a copy of the texture is hold in the Ram Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); //Lock the texture and fill it with the data - DataRectangle rect = t.LockRectangle(0, LockFlags.None); + DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); for (int i = 0; i < Data.Length; ) { rect.Data.Write(Data, i, 4 * bmp2.Width); @@ -1020,7 +1020,7 @@ namespace Vocaluxe.Lib.Draw texture.height_ratio = texture.height / texture.h2; Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); - DataRectangle rect = t.LockRectangle(0, LockFlags.None); + DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); for (int i = 0; i < Data.Length; ) { rect.Data.Write(Data, i, 4 * W); @@ -1069,7 +1069,7 @@ namespace Vocaluxe.Lib.Draw { if ((Texture.index >= 0) && (_Textures.Count > 0) && _TextureExists(ref Texture)) { - DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); + DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.Discard); for (int i = 0; i < Data.Length; ) { rect.Data.Write(Data, i, 4 * (int)Texture.width); @@ -1082,6 +1082,23 @@ namespace Vocaluxe.Lib.Draw Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); Texture.width_ratio = Texture.width / NextPowerOfTwo(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; */ } else return false; @@ -1424,7 +1441,7 @@ namespace Vocaluxe.Lib.Draw texture.height_ratio = texture.height / texture.h2; Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); - DataRectangle rect = t.LockRectangle(0, LockFlags.None); + DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); for (int i = 0; i < q.data.Length; ) { rect.Data.Write(q.data, i, 4 * q.width); From e62479249030d0e146224f57684200a7f869de98 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 10 Jul 2012 17:52:18 +0200 Subject: [PATCH 2/5] Background music is now using #Start and #End tags, if found --- Vocaluxe/Base/CBackgroundMusic.cs | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index e475081c..17657e6a 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -217,7 +217,12 @@ namespace Vocaluxe.Base { if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1) { - float timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream); + float timeToPlay; + if(_CurrentPlaylistElement.Finish == 0f) //No End-Tag defined + timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream); + else //End-Tag found + timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream); + bool finished = CSound.IsFinished(_CurrentMusicStream); if (_Playing && (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished)) Next(); @@ -248,6 +253,11 @@ namespace Vocaluxe.Base _CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex]; } _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath); + + //Seek to #Start-Tag, if found + if (_CurrentPlaylistElement.Start != 0f) + CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); + if (_VideoEnabled) LoadVideo(); CSound.SetStreamVolume(_CurrentMusicStream, 0f); @@ -524,6 +534,28 @@ class PlaylistElement } } + public float Start + { + get + { + if (_Song != null) + return _Song.Start; + + return 0f; + } + } + + public float Finish + { + get + { + if (_Song != null) + return _Song.Finish; + + return 0f; + } + } + public STexture Cover { get From 1844316ac77ed7c23c27f5c900f1051d75eb3c07 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sun, 16 Sep 2012 15:40:10 +0200 Subject: [PATCH 3/5] Only use power of 2 textures when needed, Vocaluxe now uses about 100MB less RAM on startup. Please test on a Intel Graphics device! --- Vocaluxe/Lib/Draw/CDirect3D.cs | 41 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 492834c9..10820a50 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -55,6 +55,8 @@ namespace Vocaluxe.Lib.Draw private Queue _VerticesTextures; private Queue _VerticesRotationMatrices; + private bool _NonPowerOf2TextureSupported; + #endregion private vars /// @@ -182,6 +184,13 @@ namespace Vocaluxe.Lib.Draw flags = CreateFlags.HardwareVertexProcessing; else flags = CreateFlags.SoftwareVertexProcessing; + + //Check if Pow2 textures are needed + if ((caps.TextureCaps & TextureCaps.Pow2) != 0) + _NonPowerOf2TextureSupported = false; + else + _NonPowerOf2TextureSupported = true; + try { _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); @@ -731,8 +740,8 @@ namespace Vocaluxe.Lib.Draw texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.width = w; texture.height = h; - texture.w2 = NextPowerOfTwo(texture.width); - texture.h2 = NextPowerOfTwo(texture.height); + texture.w2 = CheckForNextPowerOf2(texture.width); + texture.h2 = CheckForNextPowerOf2(texture.height); texture.index = _IDs.Dequeue(); lock (MutexTexture) @@ -932,8 +941,8 @@ namespace Vocaluxe.Lib.Draw texture.height = h; //Older graphics card can only handle textures with sizes being powers of two - texture.w2 = (float)NextPowerOfTwo(w); - texture.h2 = (float)NextPowerOfTwo(h); + texture.w2 = (float)CheckForNextPowerOf2(w); + texture.h2 = (float)CheckForNextPowerOf2(h); //Create a new Bitmap with the new sizes Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); @@ -1027,8 +1036,8 @@ namespace Vocaluxe.Lib.Draw STexture texture = new STexture(-1); texture.width = W; texture.height = H; - texture.w2 = NextPowerOfTwo(texture.width); - texture.h2 = NextPowerOfTwo(texture.height); + texture.w2 = CheckForNextPowerOf2(texture.width); + texture.h2 = CheckForNextPowerOf2(texture.height); texture.width_ratio = texture.width / texture.w2; texture.height_ratio = texture.height / texture.h2; @@ -1092,8 +1101,8 @@ namespace Vocaluxe.Lib.Draw } _D3DTextures[Texture.index].UnlockRectangle(0); - Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); - Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); + Texture.height_ratio = Texture.height / CheckForNextPowerOf2(Texture.height); + Texture.width_ratio = Texture.width / CheckForNextPowerOf2(Texture.width); return true; } else @@ -1430,8 +1439,8 @@ namespace Vocaluxe.Lib.Draw texture.width = q.width; texture.height = q.height; - texture.w2 = NextPowerOfTwo(texture.width); - texture.h2 = NextPowerOfTwo(texture.height); + texture.w2 = CheckForNextPowerOf2(texture.width); + texture.h2 = CheckForNextPowerOf2(texture.height); texture.width_ratio = texture.width / texture.w2; texture.height_ratio = texture.height / texture.h2; @@ -1471,14 +1480,18 @@ namespace Vocaluxe.Lib.Draw #region utility /// - /// Calculates the next power of two + /// Calculates the next power of two if the device has the POW2 flag set /// /// The value of which the next power of two will be calculated /// The next power of two - private static float NextPowerOfTwo(float n) + private float CheckForNextPowerOf2(float n) { - if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); - return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); + if (!_NonPowerOf2TextureSupported) + { + if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); + return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); + } + else return n; } private Matrix CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) From b4d0449b4a39ed0426bced45f4f897223b328a6d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 17 Sep 2012 14:24:14 +0200 Subject: [PATCH 4/5] Improved NPOT texture detection --- Vocaluxe/Lib/Draw/CDirect3D.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 867a7187..3b15b4e0 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -186,10 +186,10 @@ namespace Vocaluxe.Lib.Draw flags = CreateFlags.SoftwareVertexProcessing; //Check if Pow2 textures are needed - if ((caps.TextureCaps & TextureCaps.Pow2) != 0) - _NonPowerOf2TextureSupported = false; - else - _NonPowerOf2TextureSupported = true; + _NonPowerOf2TextureSupported = true; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.Pow2) != 0; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.NonPow2Conditional) != 0; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.SquareOnly) != 0; try { From 91dd3a550c4f465eb93218b551a9c8bd8e8ff3cb Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 19 Sep 2012 20:41:17 +0200 Subject: [PATCH 5/5] Fixed detection --- Vocaluxe/Lib/Draw/CDirect3D.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3b15b4e0..a5a5e167 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -187,9 +187,9 @@ namespace Vocaluxe.Lib.Draw //Check if Pow2 textures are needed _NonPowerOf2TextureSupported = true; - _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.Pow2) != 0; - _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.NonPow2Conditional) != 0; - _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.SquareOnly) != 0; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.Pow2) == 0; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.NonPow2Conditional) == 0; + _NonPowerOf2TextureSupported &= (caps.TextureCaps & TextureCaps.SquareOnly) == 0; try {