From d251329791811fa4ecdf6b370fdf71f456d9e0ce Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 24 Mar 2012 16:54:40 +0100 Subject: [PATCH 1/3] The aspect ratio is now correct on startup --- Vocaluxe/Lib/Draw/CDirect3D.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 9745fa92..8bd9e15c 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -504,6 +504,7 @@ namespace Vocaluxe.Lib.Draw CSettings.bFullScreen = true; EnterFullScreen(); } + RResize(); while (_Run) { From 380481054505bdcf357728c707e6416a11c136b0 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 26 Mar 2012 17:26:48 +0200 Subject: [PATCH 2/3] Better ID management --- Vocaluxe/Lib/Draw/CDirect3D.cs | 64 ++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 8bd9e15c..141fedbc 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -35,8 +35,9 @@ namespace Vocaluxe.Lib.Draw private Size _SizeBeforeMinimize; private Dictionary _Textures; - private List _D3DTextures; + private Dictionary _D3DTextures; private List _Queque; + private Queue _IDs; private Object MutexTexture = new Object(); @@ -48,7 +49,7 @@ namespace Vocaluxe.Lib.Draw private int y = 0; private int x = 0; - private STexture blankTexture; + private STexture _BlankTexture; private Queue _Vertices; private Queue _VerticesTextures; @@ -63,8 +64,13 @@ namespace Vocaluxe.Lib.Draw { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new Dictionary(); - _D3DTextures = new List(); + _D3DTextures = new Dictionary(); _Queque = 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(); @@ -270,6 +276,8 @@ namespace Vocaluxe.Lib.Draw y = 0; x = 0; + if ((float)w / (float)h == CSettings.GetRenderAspect()) + return; if ((float)w / (float)h > CSettings.GetRenderAspect()) { //The windows's width is too big @@ -482,7 +490,7 @@ namespace Vocaluxe.Lib.Draw Graphics g = Graphics.FromImage(blankMap); g.Clear(Color.White); g.Dispose(); - blankTexture = AddTexture(blankMap); + _BlankTexture = AddTexture(blankMap); blankMap.Dispose(); return true; @@ -583,11 +591,11 @@ namespace Vocaluxe.Lib.Draw public bool Unload() { //Dispose all textures - for (int i = 0; i < _D3DTextures.Count; i++) + foreach (KeyValuePair p in _D3DTextures) { - if (_D3DTextures[i] != null) - _D3DTextures[i].Dispose(); + p.Value.Dispose(); } + TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); _IndexBuffer.Dispose(); @@ -713,7 +721,7 @@ namespace Vocaluxe.Lib.Draw Surface textureSurface = tex.GetSurfaceLevel(0); Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0); backbufferSurface.Dispose(); - _D3DTextures.Add(tex); + _D3DTextures.Add(_IDs.Peek(), tex); texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); @@ -721,7 +729,7 @@ namespace Vocaluxe.Lib.Draw texture.height = h; texture.w2 = NextPowerOfTwo(texture.width); texture.h2 = NextPowerOfTwo(texture.height); - texture.index = _D3DTextures.Count - 1; + texture.index = _IDs.Dequeue(); lock (MutexTexture) { @@ -787,7 +795,7 @@ namespace Vocaluxe.Lib.Draw public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) { SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255); - DrawTexture(blankTexture, new SRectF(x1, y1, x2, y2, 1), color); + DrawTexture(_BlankTexture, new SRectF(x1, y1, x2, y2, 1), color); } /// @@ -822,7 +830,7 @@ namespace Vocaluxe.Lib.Draw /// The coordinates in a SRectF struct public void DrawColor(SColorF color, SRectF rect) { - DrawTexture(blankTexture, rect, color); + DrawTexture(_BlankTexture, rect, color); } #endregion Basic Draw Methods #region Textures @@ -951,8 +959,8 @@ namespace Vocaluxe.Lib.Draw texture.TexturePath = String.Empty; lock (MutexTexture) { - _D3DTextures.Add(t); - texture.index = _D3DTextures.Count - 1; + _D3DTextures.Add(_IDs.Peek(), t); + texture.index = _IDs.Dequeue(); _Textures[texture.index] = texture; } return texture; @@ -988,8 +996,8 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - _D3DTextures.Add(null); - texture.index = _D3DTextures.Count - 1; + _D3DTextures.Add(_IDs.Peek(), null); + texture.index = _IDs.Dequeue(); queque.ID = texture.index; _Queque.Add(queque); _Textures[texture.index] = texture; @@ -1024,8 +1032,8 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - _D3DTextures.Add(t); - texture.index = _D3DTextures.Count - 1; + _D3DTextures.Add(_IDs.Peek(), t); + texture.index = _IDs.Dequeue(); _Textures[texture.index] = texture; } return texture; @@ -1055,7 +1063,7 @@ namespace Vocaluxe.Lib.Draw /// True if succeeded public bool UpdateTexture(ref STexture Texture, ref byte[] Data) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) + if ((Texture.index >= 0) && (_Textures.Count > 0) && _TextureExists(ref Texture)) { DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); for (int i = 0; i < Data.Length; ) @@ -1108,8 +1116,9 @@ namespace Vocaluxe.Lib.Draw if ((Texture.index >= 0) && (_Textures.Count > 0)) { _D3DTextures[Texture.index].Dispose(); - _D3DTextures[Texture.index] = null; + _D3DTextures.Remove(Texture.index); _Textures.Remove(Texture.index); + _IDs.Enqueue(Texture.index); Texture.index = -1; Texture.ID = -1; } @@ -1123,8 +1132,7 @@ namespace Vocaluxe.Lib.Draw /// The texture to be drawn public void DrawTexture(STexture Texture) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, Texture.rect, Texture.color); + DrawTexture(Texture, Texture.rect, Texture.color); } /// @@ -1134,8 +1142,7 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing the destination coordinates public void DrawTexture(STexture Texture, SRectF rect) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, Texture.color, false); + DrawTexture(Texture, rect, Texture.color, false); } /// @@ -1146,8 +1153,7 @@ namespace Vocaluxe.Lib.Draw /// A SColorF struct containing a color which the texture will be colored in public void DrawTexture(STexture Texture, SRectF rect, SColorF color) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, false); + DrawTexture(Texture, rect, color, false); } /// @@ -1159,8 +1165,7 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing which part of the texture should be drawn public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, bounds, false); + DrawTexture(Texture, rect, color, bounds, false); } /// @@ -1172,8 +1177,7 @@ namespace Vocaluxe.Lib.Draw /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); + DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); } /// @@ -1186,7 +1190,7 @@ namespace Vocaluxe.Lib.Draw /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) + if (_TextureExists(ref Texture)) { if (_D3DTextures[Texture.index] == null) return; From fa975a99601304ae6ee13e3af61a77634e948466 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 28 Mar 2012 14:27:57 +0200 Subject: [PATCH 3/3] Fixed resizing --- Vocaluxe/Lib/Draw/CDirect3D.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 141fedbc..a37722fa 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -276,8 +276,6 @@ namespace Vocaluxe.Lib.Draw y = 0; x = 0; - if ((float)w / (float)h == CSettings.GetRenderAspect()) - return; if ((float)w / (float)h > CSettings.GetRenderAspect()) { //The windows's width is too big @@ -512,7 +510,10 @@ namespace Vocaluxe.Lib.Draw CSettings.bFullScreen = true; EnterFullScreen(); } - RResize(); + + //Resize window if aspect ratio is incorrect + if ((float)w / (float)h != CSettings.GetRenderAspect()) + RResize(); while (_Run) {