From 18940c7ed9dc231d3eae015b809d3a2547958cc4 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 13:25:51 +0100 Subject: [PATCH 01/31] some improvements in credits screen --- Vocaluxe/Menu/CGraphics.cs | 24 +--- Vocaluxe/Screens/CScreenCredits.cs | 181 ++++++++++++++++++----------- 2 files changed, 117 insertions(+), 88 deletions(-) diff --git a/Vocaluxe/Menu/CGraphics.cs b/Vocaluxe/Menu/CGraphics.cs index d924c584..cd3148de 100644 --- a/Vocaluxe/Menu/CGraphics.cs +++ b/Vocaluxe/Menu/CGraphics.cs @@ -249,12 +249,9 @@ namespace Vocaluxe.Menu for (int i = 0; i < Screens.Length; i++) { - if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits)) - { - CLog.StartBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); - Screens[i].LoadTheme(); - CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); - } + CLog.StartBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); + Screens[i].LoadTheme(); + CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); } } @@ -263,10 +260,7 @@ namespace Vocaluxe.Menu ReloadCursor(); for (int i = 0; i < Screens.Length; i++) { - if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits)) - { - Screens[i].ReloadTheme(); - } + Screens[i].ReloadTheme(); } } @@ -275,10 +269,7 @@ namespace Vocaluxe.Menu ReloadCursor(); for (int i = 0; i < Screens.Length; i++) { - if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits)) - { - Screens[i].ReloadTextures(); - } + Screens[i].ReloadTextures(); } } @@ -287,10 +278,7 @@ namespace Vocaluxe.Menu CTheme.SaveTheme(); for (int i = 0; i < Screens.Length; i++) { - if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits)) - { - Screens[i].SaveTheme(); - } + Screens[i].SaveTheme(); } } diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index e1b988b4..fab7271c 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -33,7 +33,6 @@ namespace Vocaluxe.Screens // Version number for theme files. Increment it, if you've changed something on the theme files! const int ScreenVersion = 1; - private CStatic logo; private CParticleEffect starsRed; private CParticleEffect starsBlue; @@ -45,6 +44,18 @@ namespace Vocaluxe.Screens private List paragraphs; private List paragraphTexts; + + private STexture _TexLogo; + private STexture _TexPerfectNoteStar; + + private STexture _TexNameBrunzel; + private STexture _TexNameDarkice; + private STexture _TexNameFlokuep; + private STexture _TexNameMesand; + private STexture _TexNameBohning; + private STexture _TexNameBabene03; + private STexture _TexNamePantero; + private STexture _TexNamePinky007; public CScreenCredits() { @@ -96,6 +107,81 @@ namespace Vocaluxe.Screens paragraphs.Add(words); } + public override void LoadTheme() + { + //Vocaluxe-Logo + CDataBase.GetCreditsRessource("Logo_voc.png", ref _TexLogo); + + //Little stars for logo + CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref _TexPerfectNoteStar); + + //brunzel + CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel); + + //Darkice + CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice); + + //flokuep + CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep); + + //bohning + CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning); + + //mesand + CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand); + + //babene03 + CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03); + + //pantero + CDataBase.GetCreditsRessource("pantero.png", ref _TexNamePantero); + + //Pinky007 + CDataBase.GetCreditsRessource("Pinky007.png", ref _TexNamePinky007); + + //Prepare Text + int lastY = 280; + for (int i = 0; i < paragraphs.Count; i++) + { + string line = ""; + for (int e = 0; e < paragraphs[i].Length; e++) + { + if (paragraphs[i][e] != null) + { + string newline = line + " " + paragraphs[i][e]; + CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); + if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 220)) + { + line = line + " " + paragraphs[i][e]; + + //Check if all words are used + if ((e + 1) == paragraphs[i].Length) + { + text.Text = line; + paragraphTexts.Add(text); + line = ""; + lastY += 40; + } + } + else + { + paragraphTexts.Add(text); + line = " " + paragraphs[i][e]; + lastY += 27; + } + } + } + } + } + + public override void ReloadTheme() {} + + public override void SaveTheme() {} + + public override void UnloadTextures() {} + + public override void ReloadTextures() {} + public override bool HandleInput(KeyEvent KeyEvent) { if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode)) @@ -150,137 +236,92 @@ namespace Vocaluxe.Screens public override void OnShow() { - STexture tex = new STexture(); - STexture particleTex = new STexture(); + base.OnShow(); //Vocaluxe-Logo - CDataBase.GetCreditsRessource("Logo_voc.png", ref tex); - logo = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF((CSettings.iRenderW - tex.width)/2, -270 , tex.width, tex.height, -2)); - + logo = new CStatic(_TexLogo, new SColorF(1, 1, 1, 1), new SRectF((CSettings.iRenderW - _TexLogo.width) / 2, -270, _TexLogo.width, _TexLogo.height, -2)); + //Little stars for logo - CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref particleTex); - int numstars = (int)(logo.Rect.W * 0.25f /2f); - starsRed = new CParticleEffect(numstars, new SColorF(1, 0, 0, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), particleTex, 35, EParticeType.Star); - starsBlue = new CParticleEffect(numstars, new SColorF(0.149f, 0.415f, 0.819f, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), particleTex, 35, EParticeType.Star); + int numstars = (int)(logo.Rect.W * 0.25f / 2f); + starsRed = new CParticleEffect(numstars, new SColorF(1, 0, 0, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), _TexPerfectNoteStar, 35, EParticeType.Star); + starsBlue = new CParticleEffect(numstars, new SColorF(0.149f, 0.415f, 0.819f, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), _TexPerfectNoteStar, 35, EParticeType.Star); //Credit names _CreditNames = new List(); - CCreditName CreditEntry = new CCreditName(); //brunzel - CDataBase.GetCreditsRessource("brunzel.png", ref tex); CCreditName CreditEntryBrunzel = new CCreditName(); - CreditEntryBrunzel.image = new CStatic(tex, new SColorF(1,1,1,1), new SRectF(-450, 580, 400, 120, -4)); + CreditEntryBrunzel.image = new CStatic(_TexNameBrunzel, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4)); CreditEntryBrunzel.particleRect = new SRectF(CreditEntryBrunzel.image.Rect.X + 342, CreditEntryBrunzel.image.Rect.Y + 4, 30, 30, -5); - CreditEntryBrunzel.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryBrunzel.particleRect, particleTex, 35, EParticeType.Star); + CreditEntryBrunzel.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryBrunzel.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star); CreditEntryBrunzel.active = true; CreditEntryBrunzel.direction = EDirection.Left; _CreditNames.Add(CreditEntryBrunzel); //Darkice - CDataBase.GetCreditsRessource("Darkice.png", ref tex); CCreditName CreditEntryDarkice = new CCreditName(); - CreditEntryDarkice.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 400, 120, -4)); + CreditEntryDarkice.image = new CStatic(_TexNameDarkice, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 400, 120, -4)); CreditEntryDarkice.particleRect = new SRectF(CreditEntryDarkice.image.Rect.X + 242, CreditEntryDarkice.image.Rect.Y + 23, 30, 30, -5); - CreditEntryDarkice.particle = new CParticleEffect(8, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryDarkice.particleRect, particleTex, 35, EParticeType.Star); + CreditEntryDarkice.particle = new CParticleEffect(8, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryDarkice.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star); CreditEntryDarkice.active = true; CreditEntryDarkice.direction = EDirection.Right; _CreditNames.Add(CreditEntryDarkice); //flokuep - CDataBase.GetCreditsRessource("flokuep.png", ref tex); CCreditName CreditEntryFlokuep = new CCreditName(); - CreditEntryFlokuep.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4)); - CreditEntryFlokuep.particleRect = new SRectF(CreditEntryFlokuep.image.Rect.X + 141, CreditEntryFlokuep.image.Rect.Y-2, 30, 30, -5); - CreditEntryFlokuep.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryFlokuep.particleRect, particleTex, 35, EParticeType.Star); + CreditEntryFlokuep.image = new CStatic(_TexNameFlokuep, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4)); + CreditEntryFlokuep.particleRect = new SRectF(CreditEntryFlokuep.image.Rect.X + 141, CreditEntryFlokuep.image.Rect.Y - 2, 30, 30, -5); + CreditEntryFlokuep.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryFlokuep.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star); CreditEntryFlokuep.active = true; CreditEntryFlokuep.direction = EDirection.Left; _CreditNames.Add(CreditEntryFlokuep); //bohning - CDataBase.GetCreditsRessource("bohning.png", ref tex); CCreditName CreditEntryBohning = new CCreditName(); - CreditEntryBohning.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); + CreditEntryBohning.image = new CStatic(_TexNameBohning, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryBohning.particleRect = new SRectF(CreditEntryBohning.image.Rect.X + 172, CreditEntryBohning.image.Rect.Y + 16, 10, 10, -5); - CreditEntryBohning.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryBohning.particleRect, particleTex, 25, EParticeType.Star); + CreditEntryBohning.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryBohning.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star); CreditEntryBohning.active = true; CreditEntryBohning.direction = EDirection.Right; _CreditNames.Add(CreditEntryBohning); //mesand - CDataBase.GetCreditsRessource("mesand.png", ref tex); CCreditName CreditEntryMesand = new CCreditName(); - CreditEntryMesand.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); + CreditEntryMesand.image = new CStatic(_TexNameMesand, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); CreditEntryMesand.particleRect = new SRectF(CreditEntryMesand.image.Rect.X + 240, CreditEntryMesand.image.Rect.Y - 2, 10, 10, -5); - CreditEntryMesand.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntryMesand.particleRect, particleTex, 25, EParticeType.Star); + CreditEntryMesand.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntryMesand.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star); CreditEntryMesand.active = true; CreditEntryMesand.direction = EDirection.Left; _CreditNames.Add(CreditEntryMesand); //babene03 - CDataBase.GetCreditsRessource("babene03.png", ref tex); CCreditName CreditEntryBabene03 = new CCreditName(); - CreditEntryBabene03.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); + CreditEntryBabene03.image = new CStatic(_TexNameBabene03, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryBabene03.particleRect = new SRectF(CreditEntryBabene03.image.Rect.X + 7, CreditEntryBabene03.image.Rect.Y + 4, 10, 10, -5); - CreditEntryBabene03.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryBabene03.particleRect, particleTex, 25, EParticeType.Star); + CreditEntryBabene03.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryBabene03.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star); CreditEntryBabene03.active = true; CreditEntryBabene03.direction = EDirection.Right; _CreditNames.Add(CreditEntryBabene03); //pantero - CDataBase.GetCreditsRessource("pantero.png", ref tex); CCreditName CreditEntrypantero = new CCreditName(); - CreditEntrypantero.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); + CreditEntrypantero.image = new CStatic(_TexNamePantero, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); CreditEntrypantero.particleRect = new SRectF(CreditEntrypantero.image.Rect.X + 140, CreditEntrypantero.image.Rect.Y + 15, 10, 10, -5); - CreditEntrypantero.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntrypantero.particleRect, particleTex, 25, EParticeType.Star); + CreditEntrypantero.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntrypantero.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star); CreditEntrypantero.active = true; CreditEntrypantero.direction = EDirection.Left; _CreditNames.Add(CreditEntrypantero); - + //Pinky007 - CDataBase.GetCreditsRessource("Pinky007.png", ref tex); CCreditName CreditEntryPinky007 = new CCreditName(); - CreditEntryPinky007.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); + CreditEntryPinky007.image = new CStatic(_TexNamePinky007, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryPinky007.particleRect = new SRectF(CreditEntryPinky007.image.Rect.X + 42, CreditEntryPinky007.image.Rect.Y + 15, 10, 10, -5); - CreditEntryPinky007.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryPinky007.particleRect, particleTex, 25, EParticeType.Star); + CreditEntryPinky007.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryPinky007.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star); CreditEntryPinky007.active = true; CreditEntryPinky007.direction = EDirection.Right; _CreditNames.Add(CreditEntryPinky007); - //Prepare Text - int lastY = 280; - for (int i = 0; i < paragraphs.Count; i++) - { - string line = ""; - for (int e = 0; e < paragraphs[i].Length; e++ ) - { - if (paragraphs[i][e] != null) - { - string newline = line + " " + paragraphs[i][e]; - CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); - if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 220)) - { - line = line + " " + paragraphs[i][e]; - - //Check if all words are used - if ((e + 1) == paragraphs[i].Length) - { - text.Text = line; - paragraphTexts.Add(text); - line = ""; - lastY += 40; - } - } - else - { - paragraphTexts.Add(text); - line = " "+paragraphs[i][e]; - lastY += 27; - } - } - } - } TextTimer.Reset(); LogoTimer.Reset(); CreditsTimer.Reset(); From 21fea926481e65be9a8f301df531ad391ad5693d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 17 Mar 2012 01:17:51 +0100 Subject: [PATCH 02/31] Massive performance increase in Direct3D, especially when drawing many textures, please test! --- Vocaluxe/Base/CSettings.cs | 1 + Vocaluxe/Lib/Draw/CDirect3D.cs | 266 +++++++++++++++------------------ 2 files changed, 118 insertions(+), 149 deletions(-) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index d17bc699..d0367a7d 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -61,6 +61,7 @@ namespace Vocaluxe.Base public static int zFar = 100; public static bool bFullScreen = false; + public static int iVertexBufferElements = 1000; public const string sIcon = "Vocaluxe.ico"; public const string sLogo = "Logo.png"; diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 68e62185..b7dd0d2b 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -41,15 +41,18 @@ namespace Vocaluxe.Lib.Draw private Object MutexTexture = new Object(); private VertexBuffer _VertexBuffer; + private IndexBuffer _IndexBuffer; private int h = 1; private int w = 1; private int y = 0; private int x = 0; - private Bitmap blankMap; private STexture blankTexture; - private Texture transparentTexture; + + private List _Vertices; + private List _VerticesTextures; + private List _VerticesRotationMatrices; #endregion private vars @@ -63,6 +66,10 @@ namespace Vocaluxe.Lib.Draw _D3DTextures = new List(); _Queque = new List(); + _Vertices = new List(); + _VerticesTextures = new List(); + _VerticesRotationMatrices = new List(); + _Keys = new CKeys(); _D3D = new Direct3D(); @@ -164,13 +171,12 @@ namespace Vocaluxe.Lib.Draw //This creates a new white texture and adds it to the texture pool //This texture is used for the DrawRect method - blankMap = new Bitmap(1, 1); + Bitmap blankMap = new Bitmap(1, 1); Graphics g = Graphics.FromImage(blankMap); g.Clear(Color.White); g.Dispose(); blankTexture = AddTexture(blankMap); - transparentTexture = new Texture(_Device, 1, 1, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); blankMap.Dispose(); } @@ -357,7 +363,7 @@ namespace Vocaluxe.Lib.Draw this.Text = CSettings.GetFullVersionText(); Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); Matrix projection = Matrix.OrthoOffCenterLH(-CSettings.iRenderW / 2, CSettings.iRenderW / 2, -CSettings.iRenderH / 2, CSettings.iRenderH / 2, CSettings.zNear, CSettings.zFar); - _VertexBuffer = new VertexBuffer(_Device, 4 * Marshal.SizeOf(typeof(TexturedColoredVertex)), Usage.WriteOnly | Usage.Dynamic, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); + _VertexBuffer = new VertexBuffer(_Device, CSettings.iVertexBufferElements * (4 * Marshal.SizeOf(typeof(TexturedColoredVertex))), Usage.WriteOnly | Usage.Dynamic, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); _Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(TexturedColoredVertex))); _Device.VertexDeclaration = TexturedColoredVertex.GetDeclaration(_Device); _Device.SetTransform(TransformState.Projection, projection); @@ -377,6 +383,21 @@ namespace Vocaluxe.Lib.Draw _Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture); _Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse); _Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate); + + int[] indices = new int[6]; + indices[0] = 0; + indices[1] = 1; + indices[2] = 2; + indices[3] = 0; + indices[4] = 2; + indices[5] = 3; + + _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(int), Usage.WriteOnly, Pool.Managed, false); + + DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.None); + stream.WriteRange(indices); + _IndexBuffer.Unlock(); + _Device.Indices = _IndexBuffer; return true; } else @@ -409,6 +430,7 @@ namespace Vocaluxe.Lib.Draw _Device.BeginScene(); CheckQueque(); _Run = _Run && CGraphics.Draw(); + RenderVertexBuffer(); //We finished drawing the frame _Device.EndScene(); _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); @@ -459,6 +481,7 @@ namespace Vocaluxe.Lib.Draw //Dispose all objects in the default pool, those need to be recreated TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); + _IndexBuffer.Dispose(); _Device.Reset(_PresentParameters); } @@ -471,11 +494,12 @@ namespace Vocaluxe.Lib.Draw //Dispose all textures for (int i = 0; i < _D3DTextures.Count; i++) { - if(_D3DTextures[i] != null) + if (_D3DTextures[i] != null) _D3DTextures[i].Dispose(); } TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); + _IndexBuffer.Dispose(); _Device.Dispose(); _D3D.Dispose(); return true; @@ -523,6 +547,37 @@ namespace Vocaluxe.Lib.Draw return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } + private void AddToVertexBuffer(TexturedColoredVertex[] vertices, Texture tex, Matrix rotation) + { + if (_Vertices.Count >= CSettings.iVertexBufferElements) + RenderVertexBuffer(); + _Vertices.AddRange(vertices); + _VerticesTextures.Add(tex); + _VerticesRotationMatrices.Add(rotation); + } + + private void RenderVertexBuffer() + { + if (_Vertices.Count > 0) + { + DataStream stream = _VertexBuffer.Lock(0, _Vertices.Count * Marshal.SizeOf(typeof(TexturedColoredVertex)), LockFlags.Discard); + stream.WriteRange(_Vertices.ToArray()); + _VertexBuffer.Unlock(); + stream.Dispose(); + + for (int i = 0; i < _Vertices.Count; i += 4) + { + _Device.SetTransform(TransformState.World, _VerticesRotationMatrices[i / 4]); + _Device.SetTexture(0, _VerticesTextures[i / 4]); + _Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, i, 0, 4, 0, 2); + _Device.SetTransform(TransformState.World, _VerticesRotationMatrices[i / 4]); + } + _Vertices.Clear(); + _VerticesTextures.Clear(); + _VerticesRotationMatrices.Clear(); + } + } + #region Basic Draw Methods /// @@ -764,7 +819,7 @@ namespace Vocaluxe.Lib.Draw rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - + bmp2.Dispose(); bmp_data = null; @@ -778,7 +833,6 @@ namespace Vocaluxe.Lib.Draw texture.index = _D3DTextures.Count - 1; _Textures.Add(texture); } - return texture; } @@ -1058,69 +1112,34 @@ namespace Vocaluxe.Lib.Draw rx2 -= 0.5f; ry2 -= 0.5f; - if (color.R >= 1f) - color.R = 1f; - if (color.B >= 1f) - color.B = 1f; - if (color.G >= 1f) - color.G = 1f; - - //Apply rotation - //FIXME: Rotated textures get distorted when they hit the border of the window - if (rect.Rotation != 0) - { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; - - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); - - //Multiplicate the matrices to get the real world matrix, - //First shift the texture into the center - //Rotate it and shift it back to the origin position - //Apply the originTranslation after - Matrix result = translationA * rotation * translationB * originTranslation; - - _Device.SetTransform(TransformState.World, result); - } + 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.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - //Create new vertices and write them into a vertexbuffer - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); if (!mirrored) { - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), - }); + TexturedColoredVertex[] vert = new TexturedColoredVertex[4]; + vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()); + vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); + vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); + vert[3] = new TexturedColoredVertex(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 { - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb()), - }); - } - _VertexBuffer.Unlock(); - stream.Dispose(); - //Set the texture - _Device.SetTexture(0, _D3DTextures[Texture.index]); - //Draw 2 triangles to build a quad - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - - //Reapply old matrices if the texture was rotated - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); + TexturedColoredVertex[] vert = new TexturedColoredVertex[4]; + vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()); + vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()); + vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()); + vert[3] = new TexturedColoredVertex(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)); } } } @@ -1156,49 +1175,12 @@ namespace Vocaluxe.Lib.Draw Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - //Apply rotation - //FIXME: Rotated textures get distorted when they hit the border of the window - if (rect.Rotation != 0) - { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; - - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); - - //Multiplicate the matrices to get the real world matrix, - //First shift the texture into the center - //Rotate it and shift it back to the origin position - //Apply the originTranslation after - Matrix result = translationA * rotation * translationB * originTranslation; - - _Device.SetTransform(TransformState.World, result); - } - - //Create new vertices and write them into a vertexbuffer - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), - }); - _VertexBuffer.Unlock(); - stream.Dispose(); - //Set the texture - _Device.SetTexture(0, _D3DTextures[Texture.index]); - //Draw 2 triangles to build a quad - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - - //Reapply old matrices if the texture was rotated - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); - } + TexturedColoredVertex[] vert = new TexturedColoredVertex[4]; + vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()); + vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); + vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); + vert[3] = new TexturedColoredVertex(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)); } } @@ -1270,52 +1252,15 @@ namespace Vocaluxe.Lib.Draw rx2 -= 0.5f; ry2 -= 0.5f; - //Apply rotation - //FIXME: Rotated textures get distorted when they hit the border of the window - if (rect.Rotation != 0) - { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; - - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); - - //Multiplicate the matrices to get the real world matrix, - //First shift the texture into the center - //Rotate it and shift it back to the origin position - //Apply the originTranslation after - Matrix result = translationA * rotation * translationB * originTranslation; - - _Device.SetTransform(TransformState.World, result); - } - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - //Create new vertices and write them into a vertexbuffer - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - }); - _VertexBuffer.Unlock(); - stream.Dispose(); - //Set the texture - _Device.SetTexture(0, _D3DTextures[Texture.index]); - //Draw 2 triangles to build a quad - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - - //Reapply old matrices if the texture was rotated - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); - } + TexturedColoredVertex[] vert = new TexturedColoredVertex[4]; + vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); + vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()); + vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()); + vert[3] = new TexturedColoredVertex(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)); } } } @@ -1381,6 +1326,29 @@ namespace Vocaluxe.Lib.Draw { return _Textures.Count; } + + private Matrix CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + if (rot != 0) + { + float rotation = rot * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; + + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotationMat = Matrix.RotationZ(-rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); + + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotationMat * translationB * originTranslation; + return result; + } + return originTranslation; + } #endregion Textures #endregion implementation From c058ce59113a13e8ba0dd4eddeda8d041057eace Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 17 Mar 2012 11:06:30 +0100 Subject: [PATCH 03/31] Small performance increase --- Vocaluxe/Lib/Draw/CDirect3D.cs | 41 ++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index b7dd0d2b..3b4d828d 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -50,9 +50,9 @@ namespace Vocaluxe.Lib.Draw private STexture blankTexture; - private List _Vertices; - private List _VerticesTextures; - private List _VerticesRotationMatrices; + private Queue _Vertices; + private Queue _VerticesTextures; + private Queue _VerticesRotationMatrices; #endregion private vars @@ -66,9 +66,9 @@ namespace Vocaluxe.Lib.Draw _D3DTextures = new List(); _Queque = new List(); - _Vertices = new List(); - _VerticesTextures = new List(); - _VerticesRotationMatrices = new List(); + _Vertices = new Queue(); + _VerticesTextures = new Queue(); + _VerticesRotationMatrices = new Queue(); _Keys = new CKeys(); _D3D = new Direct3D(); @@ -547,19 +547,33 @@ namespace Vocaluxe.Lib.Draw return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } + /// + /// Adds a quad a list which will be added and rendered to the vertexbuffer when calling RenderToVertexBuffer to reduce vertexbuffer calls each frame to a minimum + /// + /// A TexturedColoredVertex array containg 4 vertices + /// The texture the vertex should be textured with + /// The vertices' rotation private void AddToVertexBuffer(TexturedColoredVertex[] vertices, Texture tex, Matrix rotation) { + //The vertexbuffer is full, so we need to flush it before we can continue if (_Vertices.Count >= CSettings.iVertexBufferElements) RenderVertexBuffer(); - _Vertices.AddRange(vertices); - _VerticesTextures.Add(tex); - _VerticesRotationMatrices.Add(rotation); + _Vertices.Enqueue(vertices[0]); + _Vertices.Enqueue(vertices[1]); + _Vertices.Enqueue(vertices[2]); + _Vertices.Enqueue(vertices[3]); + _VerticesTextures.Enqueue(tex); + _VerticesRotationMatrices.Enqueue(rotation); } + /// + /// Renders the vertex buffer + /// private void RenderVertexBuffer() { if (_Vertices.Count > 0) { + //The vertex buffer locks are slow actions, its better to lock once per frame and write all vertices to the buffer at once DataStream stream = _VertexBuffer.Lock(0, _Vertices.Count * Marshal.SizeOf(typeof(TexturedColoredVertex)), LockFlags.Discard); stream.WriteRange(_Vertices.ToArray()); _VertexBuffer.Unlock(); @@ -567,11 +581,14 @@ namespace Vocaluxe.Lib.Draw for (int i = 0; i < _Vertices.Count; i += 4) { - _Device.SetTransform(TransformState.World, _VerticesRotationMatrices[i / 4]); - _Device.SetTexture(0, _VerticesTextures[i / 4]); + //Apply rotation + _Device.SetTransform(TransformState.World, _VerticesRotationMatrices.Dequeue()); + //Apply texture + _Device.SetTexture(0, _VerticesTextures.Dequeue()); + //Draw 2 triangles from vertexbuffer _Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, i, 0, 4, 0, 2); - _Device.SetTransform(TransformState.World, _VerticesRotationMatrices[i / 4]); } + //Clear the queues for the next frame _Vertices.Clear(); _VerticesTextures.Clear(); _VerticesRotationMatrices.Clear(); From e65675f32311dbdba4f4b3e22f271b8fd34351da Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 17 Mar 2012 12:26:15 +0100 Subject: [PATCH 04/31] Text in credits screen was not removed on close --- Vocaluxe/Screens/CScreenCredits.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index e1b988b4..fef2daca 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -293,6 +293,15 @@ namespace Vocaluxe.Screens LogoTimer.Start(); } + public override void OnClose() + { + base.OnClose(); + + foreach (CText text in paragraphTexts) + text.UnloadTextures(); + paragraphTexts.Clear(); + } + public override bool Draw() { base.Draw(); From c098a199a961fdb4621b6f56984011c31e03fb53 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 17 Mar 2012 13:01:17 +0100 Subject: [PATCH 05/31] reverted last commit --- Vocaluxe/Screens/CScreenCredits.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index fef2daca..e1b988b4 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -293,15 +293,6 @@ namespace Vocaluxe.Screens LogoTimer.Start(); } - public override void OnClose() - { - base.OnClose(); - - foreach (CText text in paragraphTexts) - text.UnloadTextures(); - paragraphTexts.Clear(); - } - public override bool Draw() { base.Draw(); From 714d8f1d85c7b10d53e1e9d8a6bae648f16b81e1 Mon Sep 17 00:00:00 2001 From: Benjamin Hess Date: Sat, 17 Mar 2012 15:08:38 +0100 Subject: [PATCH 06/31] OpenGl texture list changed to dictionary for O(1) checks if texture exists --- Vocaluxe/Lib/Draw/COpenGL.cs | 81 ++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index f12be76d..558bf654 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -46,7 +46,7 @@ namespace Vocaluxe.Lib.Draw private SClientRect _restore; private bool _fullscreen = false; - private List _Textures; + private Dictionary _Textures; private Queue _IDs; private List _Queque; @@ -65,7 +65,7 @@ namespace Vocaluxe.Lib.Draw { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); - _Textures = new List(); + _Textures = new Dictionary(); _Queque = new List(); _IDs = new Queue(1000000); @@ -448,7 +448,9 @@ namespace Vocaluxe.Lib.Draw CSettings.bFullScreen = true; EnterFullScreen(); } - + + double draw_time = 0; + UInt64 draws = 0; while (_Run) { Application.DoEvents(); @@ -456,12 +458,14 @@ namespace Vocaluxe.Lib.Draw if (_Run) { ClearScreen(); - + double start = CTime.GetMilliseconds(); _Run = _Run && CGraphics.Draw(); + draw_time += CTime.GetMilliseconds() - start; + draws += 1; _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); control.SwapBuffers(); - + if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) ToggleFullScreen(); @@ -469,11 +473,12 @@ namespace Vocaluxe.Lib.Draw if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); - + if (delay >= 1) System.Threading.Thread.Sleep(delay); CTime.CalculateFPS(); + CLog.LogError("drawTime:" + (draw_time / draws).ToString() + " " + draws.ToString()); CTime.Restart(); } else @@ -483,11 +488,13 @@ namespace Vocaluxe.Lib.Draw public bool Unload() { - while (_Textures.Count > 0) + STexture[] textures = new STexture[_Textures.Count]; + _Textures.Values.CopyTo(textures, 0); + for (int i = 0; i < _Textures.Count; i++ ) { - STexture tex = _Textures[0]; - RemoveTexture(ref tex); + RemoveTexture(ref textures[i]); } + return true; } @@ -554,7 +561,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { texture.index = _IDs.Dequeue(); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; @@ -758,7 +765,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { texture.index = _IDs.Dequeue(); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; @@ -822,7 +829,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { texture.index = _IDs.Dequeue(); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; @@ -887,7 +894,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { texture.index = _IDs.Dequeue(); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; @@ -907,7 +914,7 @@ namespace Vocaluxe.Lib.Draw texture.index = _IDs.Dequeue(); queque.ID = texture.index; _Queque.Add(queque); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; @@ -1027,21 +1034,13 @@ namespace Vocaluxe.Lib.Draw { lock (MutexTexture) { - for (int i = 0; i < _Textures.Count; i++) - { - if (_Textures[i].index == Texture.index) - { - _IDs.Enqueue(Texture.index); - - GL.DeleteTexture(Texture.ID); - if (Texture.PBO > 0) - GL.DeleteBuffers(1, ref Texture.PBO); - _Textures.RemoveAt(i); - Texture.index = -1; - Texture.ID = -1; - break; - } - } + _IDs.Enqueue(Texture.index); + GL.DeleteTexture(Texture.ID); + if (Texture.PBO > 0) + GL.DeleteBuffers(1, ref Texture.PBO); + _Textures.Remove(Texture.index); + Texture.index = -1; + Texture.ID = -1; } } } @@ -1050,16 +1049,12 @@ namespace Vocaluxe.Lib.Draw { lock (MutexTexture) { - for (int i = 0; i < _Textures.Count; i++) + if(_Textures.ContainsKey((Texture.index))) { - if (Texture.index == _Textures[i].index) + if(_Textures[Texture.index].ID > 0) { - if (_Textures[i].ID > 0) - { - Texture = _Textures[i]; - return true; - } - break; + Texture = _Textures[Texture.index]; + return true; } } } @@ -1338,15 +1333,9 @@ namespace Vocaluxe.Lib.Draw STextureQueque q = _Queque[0]; STexture texture = new STexture(-1); - int index = -1; - for (int i = 0; i < _Textures.Count; i++) + if (_Textures.ContainsKey(q.ID)) { - if (_Textures[i].index == q.ID) - { - texture = _Textures[i]; - index = i; - break; - } + texture = _Textures[q.ID]; } if (texture.index < 1) @@ -1396,7 +1385,7 @@ namespace Vocaluxe.Lib.Draw texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; - _Textures[index] = texture; + _Textures[texture.index] = texture; q.data = null; _Queque.RemoveAt(0); } From ac5b57770ec7076b03b1401a8e726a0abfff70eb Mon Sep 17 00:00:00 2001 From: Benjamin Hess Date: Sat, 17 Mar 2012 15:20:45 +0100 Subject: [PATCH 07/31] removed debug output from last commit --- Vocaluxe/Lib/Draw/COpenGL.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 558bf654..49d99366 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -449,8 +449,6 @@ namespace Vocaluxe.Lib.Draw EnterFullScreen(); } - double draw_time = 0; - UInt64 draws = 0; while (_Run) { Application.DoEvents(); @@ -458,10 +456,7 @@ namespace Vocaluxe.Lib.Draw if (_Run) { ClearScreen(); - double start = CTime.GetMilliseconds(); _Run = _Run && CGraphics.Draw(); - draw_time += CTime.GetMilliseconds() - start; - draws += 1; _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); control.SwapBuffers(); @@ -478,7 +473,6 @@ namespace Vocaluxe.Lib.Draw System.Threading.Thread.Sleep(delay); CTime.CalculateFPS(); - CLog.LogError("drawTime:" + (draw_time / draws).ToString() + " " + draws.ToString()); CTime.Restart(); } else From 44458f4d8632bb2c2e1247ea25ece7bf4d4851d3 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 13:27:33 +0100 Subject: [PATCH 08/31] added _NewEntryIDs.Clear() in CSreenHighscore.OnShow() --- Vocaluxe/Screens/CScreenHighscore.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index ed031a09..b66a5f79 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -186,6 +186,7 @@ namespace Vocaluxe.Screens _Round = 0; _Pos = 0; _Scores = new List(); + _NewEntryIDs.Clear(); AddScoresToDB(); LoadScores(); From df1b531cb4e9c2096cc39eabf1e7e35189a8ea63 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sun, 18 Mar 2012 14:33:07 +0100 Subject: [PATCH 09/31] Use dictionary to increase performance in _TextureExists method --- Vocaluxe/Lib/Draw/CDirect3D.cs | 53 +++++++++++----------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3b4d828d..b7360c6f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -34,7 +34,7 @@ namespace Vocaluxe.Lib.Draw private Size _OldSize; private Size _SizeBeforeMinimize; - private List _Textures; + private Dictionary _Textures; private List _D3DTextures; private List _Queque; @@ -62,7 +62,7 @@ namespace Vocaluxe.Lib.Draw public CDirect3D() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); - _Textures = new List(); + _Textures = new Dictionary(); _D3DTextures = new List(); _Queque = new List(); @@ -848,7 +848,7 @@ namespace Vocaluxe.Lib.Draw { _D3DTextures.Add(t); texture.index = _D3DTextures.Count - 1; - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; } @@ -885,7 +885,7 @@ namespace Vocaluxe.Lib.Draw texture.index = _D3DTextures.Count - 1; queque.ID = texture.index; _Queque.Add(queque); - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; } @@ -919,7 +919,7 @@ namespace Vocaluxe.Lib.Draw { _D3DTextures.Add(t); texture.index = _D3DTextures.Count - 1; - _Textures.Add(texture); + _Textures[texture.index] = texture; } return texture; } @@ -975,16 +975,12 @@ namespace Vocaluxe.Lib.Draw { lock (MutexTexture) { - for (int i = 0; i < _Textures.Count; i++) + if (_Textures.ContainsKey(Texture.index)) { - if (Texture.index == _Textures[i].index) + if (_Textures[Texture.index].index >= 0) { - if (_Textures[i].index >= 0) - { - Texture = _Textures[i]; - return true; - } - break; + Texture = _Textures[Texture.index]; + return true; } } } @@ -1001,17 +997,11 @@ namespace Vocaluxe.Lib.Draw { if ((Texture.index >= 0) && (_Textures.Count > 0)) { - for (int i = 0; i < _Textures.Count; i++) - { - if (_Textures[i].index == Texture.index) - { - _D3DTextures[Texture.index].Dispose(); - _D3DTextures[Texture.index] = null; - _Textures.RemoveAt(i); - Texture.index = -1; - Texture.ID = -1; - } - } + _D3DTextures[Texture.index].Dispose(); + _D3DTextures[Texture.index] = null; + _Textures.Remove(Texture.index); + Texture.index = -1; + Texture.ID = -1; } } } @@ -1291,17 +1281,8 @@ namespace Vocaluxe.Lib.Draw STextureQueque q = _Queque[0]; STexture texture = new STexture(-1); - int index = -1; - for (int i = 0; i < _Textures.Count; i++) - { - if (_Textures[i].index == q.ID) - { - texture = _Textures[i]; - index = i; - break; - } - } - + if (_Textures.ContainsKey(q.ID)) + texture = _Textures[q.ID]; if (texture.index < 0) return; @@ -1330,7 +1311,7 @@ namespace Vocaluxe.Lib.Draw texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; - _Textures[index] = texture; + _Textures[texture.index] = texture; _Queque.RemoveAt(0); } } From a663718f81ed76f4720899323cc4c4c411225283 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 15:04:59 +0100 Subject: [PATCH 10/31] set texture width and height in AddQueque --- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 ++ Vocaluxe/Lib/Draw/COpenGL.cs | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 68e62185..8d80eb24 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -807,6 +807,8 @@ namespace Vocaluxe.Lib.Draw queque.data = Data; queque.height = H; queque.width = W; + texture.height = H; + texture.width = W; lock (MutexTexture) { diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 49d99366..517b3b4a 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -419,7 +419,7 @@ namespace Vocaluxe.Lib.Draw #region implementation - + #region main stuff public bool Init() { this.Text = CSettings.GetFullVersionText(); @@ -514,7 +514,8 @@ namespace Vocaluxe.Lib.Draw CFonts.Style = text.Style; return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } - + #endregion main stuff + #region Basic Draw Methods public void ClearScreen() { @@ -638,6 +639,8 @@ namespace Vocaluxe.Lib.Draw #endregion Basic Draw Methods #region Textures + + #region adding public STexture AddTexture(string TexturePath) { if (System.IO.File.Exists(TexturePath)) @@ -902,6 +905,8 @@ namespace Vocaluxe.Lib.Draw queque.data = Data; queque.height = H; queque.width = W; + texture.height = H; + texture.width = W; lock (MutexTexture) { @@ -913,7 +918,9 @@ namespace Vocaluxe.Lib.Draw return texture; } + #endregion adding + #region updating public bool UpdateTexture(ref STexture Texture, IntPtr Data) { if (_TextureExists(ref Texture)) @@ -1021,6 +1028,7 @@ namespace Vocaluxe.Lib.Draw } return false; } + #endregion updating public void RemoveTexture(ref STexture Texture) { @@ -1055,6 +1063,7 @@ namespace Vocaluxe.Lib.Draw return false; } + #region drawing public void DrawTexture(STexture Texture) { DrawTexture(Texture, Texture.rect, Texture.color); @@ -1312,6 +1321,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, 0); } } + #endregion drawing public int TextureCount() { @@ -1369,9 +1379,15 @@ namespace Vocaluxe.Lib.Draw GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, q.width, q.height, OpenTK.Graphics.OpenGL.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 @@ -1384,7 +1400,6 @@ namespace Vocaluxe.Lib.Draw _Queque.RemoveAt(0); } } - #endregion Textures #endregion implementation From 9361c8b3754a072554d56d716d1837eabd252477 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 19:39:04 +0100 Subject: [PATCH 11/31] do not draw D3DTextures which are == null --- Vocaluxe/Lib/Draw/CDirect3D.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 8a5acee8..45190cc1 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -1079,6 +1079,9 @@ namespace Vocaluxe.Lib.Draw { if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) { + if (_D3DTextures[Texture.index] == null) + return; + //Calculate the position float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; @@ -1166,6 +1169,9 @@ namespace Vocaluxe.Lib.Draw { if (_TextureExists(ref Texture)) { + if (_D3DTextures[Texture.index] == null) + return; + float x1 = 0f + begin * Texture.width_ratio; float x2 = Texture.width_ratio * end; float y1 = 0f; @@ -1206,6 +1212,9 @@ namespace Vocaluxe.Lib.Draw { if (_TextureExists(ref Texture)) { + if (_D3DTextures[Texture.index] == null) + return; + if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) return; From 807d9f0e8b136acf091b465ea6eda50e8cdc0fb1 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 20:10:49 +0100 Subject: [PATCH 12/31] fixed client size on secondary screens in d3d --- Vocaluxe/Lib/Draw/CDirect3D.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 45190cc1..a6dffe0e 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -263,7 +263,16 @@ namespace Vocaluxe.Lib.Draw //Real fullscreen could be gained setting _PresentParameters.Windowed = true //And calling Reset() and Init() after _OldSize = this.ClientSize; - this.ClientSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); + + int ScreenNr = 0; + for (int i = 0; i < Screen.AllScreens.Length; i++) + { + Screen scr = Screen.AllScreens[i]; + if (scr.Bounds.Top <= this.Top && scr.Bounds.Left <= this.Left) + ScreenNr = i; + } + + this.ClientSize = new Size(Screen.AllScreens[ScreenNr].Bounds.Width, Screen.AllScreens[ScreenNr].Bounds.Height); this.FormBorderStyle = FormBorderStyle.None; CenterToScreen(); _fullscreen = true; @@ -462,7 +471,7 @@ namespace Vocaluxe.Lib.Draw if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); - if (delay >= 1) + if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) System.Threading.Thread.Sleep(delay); //Calculate the FPS Rate and restart the timer after a frame CTime.CalculateFPS(); From 3cc02a189a39799b6e431dec872d6f9dbe17ee1d Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 20:12:18 +0100 Subject: [PATCH 13/31] fixed vsync handling in COpenGL.cs --- Vocaluxe/Lib/Draw/COpenGL.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 517b3b4a..63d2ba07 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -469,7 +469,7 @@ namespace Vocaluxe.Lib.Draw if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); - if (delay >= 1) + if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) System.Threading.Thread.Sleep(delay); CTime.CalculateFPS(); From 6734ddb7e0e771971cb23f05f3db049f08b86b73 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 18 Mar 2012 20:21:47 +0100 Subject: [PATCH 14/31] fixed mouse cursor after fullscreen change in D3D, fixed fullscreen from maximized screen in D3D (by xDarkice) --- Vocaluxe/Lib/Draw/CDirect3D.cs | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index a6dffe0e..5bb3ece1 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -207,6 +207,27 @@ namespace Vocaluxe.Lib.Draw this.ClientSize = this.ClientSize; RResize(); } + + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case 0x112: // WM_SYSCOMMAND + switch ((int)m.WParam & 0xFFF0) + { + case 0xF100: // SC_KEYMENU + m.Result = IntPtr.Zero; + break; + default: + base.WndProc(ref m); + break; + } + break; + default: + base.WndProc(ref m); + break; + } + } #endregion form events /// /// Resizes the viewport @@ -277,10 +298,15 @@ namespace Vocaluxe.Lib.Draw CenterToScreen(); _fullscreen = true; CConfig.FullScreen = EOffOn.TR_CONFIG_ON; - RResize(); - Cursor.Hide(); - _Mouse.Visible = true; + if (this.WindowState == FormWindowState.Maximized) + { + this.WindowState = FormWindowState.Normal; + RResize(); + this.WindowState = FormWindowState.Maximized; + } + else + RResize(); CConfig.SaveConfig(); } @@ -295,9 +321,6 @@ namespace Vocaluxe.Lib.Draw _fullscreen = false; CConfig.FullScreen = EOffOn.TR_CONFIG_OFF; - Cursor.Hide(); - _Mouse.Visible = true; - CConfig.SaveConfig(); } From 7b06ac12bdc08c970d298a67d8c90778b84bcf80 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sun, 18 Mar 2012 22:53:29 +0100 Subject: [PATCH 15/31] Some cleanup and restructuring Increased max vertex count to 10000, which will result in a dynamic vertex buffer up to 1MB --- Vocaluxe/Base/CSettings.cs | 2 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index d0367a7d..9aa5d8b1 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -61,7 +61,7 @@ namespace Vocaluxe.Base public static int zFar = 100; public static bool bFullScreen = false; - public static int iVertexBufferElements = 1000; + public static int iVertexBufferElements = 10000; public const string sIcon = "Vocaluxe.ico"; public const string sLogo = "Logo.png"; diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 5bb3ece1..f2a01f94 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -178,6 +178,8 @@ namespace Vocaluxe.Lib.Draw blankTexture = AddTexture(blankMap); blankMap.Dispose(); + + int size = Marshal.SizeOf(typeof(TexturedColoredVertex)); } #region form events From 046fe6782f573ac0ae7bd495a81682837dcbddd8 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sun, 18 Mar 2012 23:18:16 +0100 Subject: [PATCH 16/31] Implemented CopyScreen method --- Vocaluxe/Lib/Draw/CDirect3D.cs | 91 +++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index f2a01f94..a10993e8 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -231,6 +231,8 @@ namespace Vocaluxe.Lib.Draw } } #endregion form events + + #region resize /// /// Resizes the viewport /// @@ -325,6 +327,7 @@ namespace Vocaluxe.Lib.Draw CConfig.SaveConfig(); } + #endregion resize #region mouse event handlers private void OnMouseMove(object sender, MouseEventArgs e) @@ -385,7 +388,7 @@ namespace Vocaluxe.Lib.Draw #endregion keyboard event handlers #region implementation - + #region main stuff /// /// Inits the Device /// @@ -628,6 +631,7 @@ namespace Vocaluxe.Lib.Draw _VerticesRotationMatrices.Clear(); } } +#endregion main stuff #region Basic Draw Methods @@ -640,24 +644,51 @@ namespace Vocaluxe.Lib.Draw } /// - /// Not implemented yet - /// - /// + /// Copies the current frame into a texture + /// A texture holding the current frame public STexture CopyScreen() { - //FIXME STexture texture = new STexture(-1); + + Surface backbufferSurface = _Device.GetBackBuffer(0, 0); + Texture tex = new Texture(_Device, _PresentParameters.BackBufferWidth, _PresentParameters.BackBufferHeight, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + Surface textureSurface = tex.GetSurfaceLevel(0); + Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0); + backbufferSurface.Dispose(); + _D3DTextures.Add(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 = NextPowerOfTwo(texture.width); + texture.h2 = NextPowerOfTwo(texture.height); + texture.index = _D3DTextures.Count - 1; + + lock (MutexTexture) + { + _Textures[texture.index] = texture; + } return texture; } /// - /// Not implemented yet + /// Copies the current frame into a texture /// - /// + /// The texture in which the frame is copied to public void CopyScreen(ref STexture Texture) { - //FIXME - return; + if (!_TextureExists(ref Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight())) + { + RemoveTexture(ref Texture); + Texture = CopyScreen(); + } + else + { + Surface backbufferSurface = _Device.GetBackBuffer(0, 0); + Surface textureSurface = _D3DTextures[Texture.index].GetSurfaceLevel(0); + Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0); + } } /// @@ -733,18 +764,11 @@ namespace Vocaluxe.Lib.Draw /// The coordinates in a SRectF struct public void DrawColor(SColorF color, SRectF rect) { - //blankMap = new Bitmap(1, 1); - //Graphics g = Graphics.FromImage(blankMap); - //g.Clear(Color.White); - //g.Dispose(); - //blankTexture = AddTexture(blankMap); - //blankMap.Dispose(); - DrawTexture(blankTexture, rect, color); - //RemoveTexture(ref blankTexture); } #endregion Basic Draw Methods #region Textures + #region adding /// /// Adds a texture and stores it in the VRam @@ -771,17 +795,6 @@ namespace Vocaluxe.Lib.Draw return new STexture(-1); } - /// - /// Calculates the next power of two - /// - /// The value of which the next power of two will be calculated - /// The next power of two - private static float NextPowerOfTwo(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))); - } - /// /// Adds a texture and stores it in the Vram /// @@ -959,7 +972,9 @@ namespace Vocaluxe.Lib.Draw } return texture; } + #endregion adding + #region updating /// /// Updates the data of a texture /// @@ -1001,6 +1016,7 @@ namespace Vocaluxe.Lib.Draw else return false; } + #endregion updating /// /// Checks if a texture exists @@ -1042,6 +1058,7 @@ namespace Vocaluxe.Lib.Draw } } + #region drawing /// /// Draws a texture /// @@ -1316,6 +1333,7 @@ namespace Vocaluxe.Lib.Draw } } } + #endregion drawing private void CheckQueque() { @@ -1369,6 +1387,20 @@ namespace Vocaluxe.Lib.Draw { return _Textures.Count; } + #endregion Textures + #endregion implementation + + #region utility + /// + /// Calculates the next power of two + /// + /// The value of which the next power of two will be calculated + /// The next power of two + private static float NextPowerOfTwo(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))); + } private Matrix CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) { @@ -1392,8 +1424,7 @@ namespace Vocaluxe.Lib.Draw } return originTranslation; } - #endregion Textures - #endregion implementation + #endregion utility #region TexturedColoredVertex public struct TexturedColoredVertex From b340d4acbf64e5a27176899960eed682d7695643 Mon Sep 17 00:00:00 2001 From: xDarkice Date: Mon, 19 Mar 2012 13:47:28 +0100 Subject: [PATCH 17/31] Removed unused debug line --- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index a10993e8..07fb2e5c 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -178,8 +178,6 @@ namespace Vocaluxe.Lib.Draw blankTexture = AddTexture(blankMap); blankMap.Dispose(); - - int size = Marshal.SizeOf(typeof(TexturedColoredVertex)); } #region form events From d693e35660871011b0c4107d5c142a52f618583f Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 17:38:52 +0100 Subject: [PATCH 18/31] fixed switching to full screen in opengl, removed topmost flag --- Vocaluxe/Lib/Draw/COpenGL.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 63d2ba07..cee399ef 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -121,7 +121,6 @@ namespace Vocaluxe.Lib.Draw control.MouseEnter += new EventHandler(this.OnMouseEnter); this.ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH); - //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true); this.CenterToScreen(); } @@ -285,8 +284,15 @@ namespace Vocaluxe.Lib.Draw this.DesktopBounds = new Rectangle(Screen.AllScreens[ScreenNr].Bounds.Location, new Size(Screen.AllScreens[ScreenNr].Bounds.Width, Screen.AllScreens[ScreenNr].Bounds.Height)); - this.TopMost = true; - this.Show(); + + if (this.WindowState == FormWindowState.Maximized) + { + this.WindowState = FormWindowState.Normal; + RResize(); + this.WindowState = FormWindowState.Maximized; + } + else + RResize(); CConfig.SaveConfig(); } @@ -299,8 +305,6 @@ namespace Vocaluxe.Lib.Draw this.FormBorderStyle = FormBorderStyle.Sizable; this.DesktopBounds = new Rectangle(_restore.location, new Size(_restore.width, _restore.height)); - this.TopMost = false; - CConfig.SaveConfig(); } #endregion Helpers From a49d458f17ad1096821fa6e0614028c40fe835e3 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 17:42:25 +0100 Subject: [PATCH 19/31] set default renderer to D3D --- Vocaluxe/Base/CConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index b4512ecc..6beb8278 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -162,7 +162,7 @@ namespace Vocaluxe.Base public static EDebugLevel DebugLevel = EDebugLevel.TR_CONFIG_OFF; // Graphics - public static ERenderer Renderer = ERenderer.TR_CONFIG_OPENGL; + public static ERenderer Renderer = ERenderer.TR_CONFIG_DIRECT3D; public static ETextureQuality TextureQuality = ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM; public static float MaxFPS = 60f; From bbfb19aec5ea173be2139be7c8de7649030e35bb Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 17:53:47 +0100 Subject: [PATCH 20/31] catch ALT-Key also in WinForm and OpenGL (don't really know whether it makes sense) --- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 21 +++++++++++++++++++++ Vocaluxe/Lib/Draw/COpenGL.cs | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index c0779426..c94f0073 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -153,6 +153,27 @@ namespace Vocaluxe.Lib.Draw _Run = false; } + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case 0x112: // WM_SYSCOMMAND + switch ((int)m.WParam & 0xFFF0) + { + case 0xF100: // SC_KEYMENU + m.Result = IntPtr.Zero; + break; + default: + base.WndProc(ref m); + break; + } + break; + default: + base.WndProc(ref m); + break; + } + } + private void OnKeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e) { _Keys.KeyDown(e); diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index cee399ef..7809edce 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -337,6 +337,27 @@ namespace Vocaluxe.Lib.Draw control.ClientSize = this.ClientSize; RResize(); } + + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case 0x112: // WM_SYSCOMMAND + switch ((int)m.WParam & 0xFFF0) + { + case 0xF100: // SC_KEYMENU + m.Result = IntPtr.Zero; + break; + default: + base.WndProc(ref m); + break; + } + break; + default: + base.WndProc(ref m); + break; + } + } #endregion form events #region mouse event handlers From 7f1c871c753a88f7760897d910b0e91198be1203 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 19:47:40 +0100 Subject: [PATCH 21/31] update to build 0056 --- Vocaluxe/Base/CSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 9aa5d8b1..ba5e667f 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -47,7 +47,7 @@ namespace Vocaluxe.Base public const int iVersionSub = 0; // steps public const ERevision VersionRevision = ERevision.Beta; - public const int iBuild = 55; // Increase on every published version! Never Reset! + public const int iBuild = 56; // Increase on every published version! Never Reset! public const int iDatabaseHighscoreVersion = 1; public const int iDatabaseCoverVersion = 1; From 46dac3f73435d27d5ac505881ae0c0100898a0c3 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 20:06:33 +0100 Subject: [PATCH 22/31] fixed player 3 color (thx to pinky007) --- Output/Themes/Ambient/Screens/ScreenNames.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Output/Themes/Ambient/Screens/ScreenNames.xml b/Output/Themes/Ambient/Screens/ScreenNames.xml index 0daa48e9..3fff5c64 100644 --- a/Output/Themes/Ambient/Screens/ScreenNames.xml +++ b/Output/Themes/Ambient/Screens/ScreenNames.xml @@ -534,7 +534,7 @@ TextColor - TextColor + TextSColor 32,00 From 0dc51aefc0056eaf52af2ea71ac274be404f3509 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 19 Mar 2012 20:36:25 +0100 Subject: [PATCH 23/31] slightly better contrast for time bar in sing screen --- Output/Themes/Ambient/Screens/ScreenSing.xml | 7 ++----- Output/Themes/Ambient/Skin Blue.xml | 12 ++++++++++++ Output/Themes/Ambient/Skin Green.xml | 12 ++++++++++++ Output/Themes/Ambient/Skin Red.xml | 12 ++++++++++++ Output/Themes/Ambient/Skin Yellow.xml | 12 ++++++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Output/Themes/Ambient/Screens/ScreenSing.xml b/Output/Themes/Ambient/Screens/ScreenSing.xml index 0e206c1d..5c85960a 100644 --- a/Output/Themes/Ambient/Screens/ScreenSing.xml +++ b/Output/Themes/Ambient/Screens/ScreenSing.xml @@ -119,10 +119,7 @@ 9 - 0,68 - 0,89 - 0,97 - 0,40 + TimeBar @@ -138,7 +135,7 @@ 9 - StaticColor + TimeBarSentence diff --git a/Output/Themes/Ambient/Skin Blue.xml b/Output/Themes/Ambient/Skin Blue.xml index 585aff80..33203fdf 100644 --- a/Output/Themes/Ambient/Skin Blue.xml +++ b/Output/Themes/Ambient/Skin Blue.xml @@ -178,6 +178,18 @@ 0,300 1,000 + + 0,800 + 0,950 + 1,000 + 0,500 + + + 0,800 + 0,950 + 1,000 + 0,850 + [Blue]BG_Default.png diff --git a/Output/Themes/Ambient/Skin Green.xml b/Output/Themes/Ambient/Skin Green.xml index c1fb83b1..3a59c0b6 100644 --- a/Output/Themes/Ambient/Skin Green.xml +++ b/Output/Themes/Ambient/Skin Green.xml @@ -178,6 +178,18 @@ 0,300 1,000 + + 0,800 + 0,950 + 1,000 + 0,500 + + + 0,800 + 0,950 + 1,000 + 0,850 + [Green]BG_Default.png diff --git a/Output/Themes/Ambient/Skin Red.xml b/Output/Themes/Ambient/Skin Red.xml index bf15aab2..25b2f9fd 100644 --- a/Output/Themes/Ambient/Skin Red.xml +++ b/Output/Themes/Ambient/Skin Red.xml @@ -178,6 +178,18 @@ 0,300 1,000 + + 0,800 + 0,950 + 1,000 + 0,500 + + + 0,800 + 0,950 + 1,000 + 0,850 + [Red]BG_Default.png diff --git a/Output/Themes/Ambient/Skin Yellow.xml b/Output/Themes/Ambient/Skin Yellow.xml index a72e0825..25c7bb21 100644 --- a/Output/Themes/Ambient/Skin Yellow.xml +++ b/Output/Themes/Ambient/Skin Yellow.xml @@ -178,6 +178,18 @@ 0,300 1,000 + + 0,800 + 0,950 + 1,000 + 0,500 + + + 0,800 + 0,950 + 1,000 + 0,850 + [Yellow]BG_Default.png From 081a2fc2bab396c889e4a1de3c5d9a12108431e9 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 20 Mar 2012 16:03:59 +0100 Subject: [PATCH 24/31] fixed calculating FPS --- Vocaluxe/Base/CUtility.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Base/CUtility.cs b/Vocaluxe/Base/CUtility.cs index ef4e94dd..909dc798 100644 --- a/Vocaluxe/Base/CUtility.cs +++ b/Vocaluxe/Base/CUtility.cs @@ -119,7 +119,7 @@ namespace Vocaluxe.Base { private static Stopwatch _Stopwatch = new Stopwatch(); private static float _fps = 0.0f; - private static long nanosecPerTick = (1000L * 1000L * 1000L) / Stopwatch.Frequency; + private static double nanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency; public static void Reset() { @@ -149,7 +149,7 @@ namespace Vocaluxe.Base { long ticks = _Stopwatch.ElapsedTicks; if (Stopwatch.IsHighResolution && ticks != 0) - return (float)(((double)nanosecPerTick * (double)ticks) / (1000.0 * 1000.0)); + return (float)((nanosecPerTick * ticks) / (1000.0 * 1000.0)); else return (float)_Stopwatch.ElapsedMilliseconds; } From 5b3ca8d1cd5f307097f45aa7a4eb182ef8fd6ce9 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 20 Mar 2012 16:49:25 +0100 Subject: [PATCH 25/31] fixed playback timer --- Vocaluxe/Base/CSound.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index ff4a30ff..e7956ecb 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -497,7 +497,7 @@ namespace Vocaluxe.Base { get { - long nanosecPerTick = (1000L * 1000L * 1000L) / Stopwatch.Frequency; + double nanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency; long ticks = _Timer.ElapsedTicks; float dt = _Timer.ElapsedMilliseconds / 1000f; @@ -577,7 +577,7 @@ namespace Vocaluxe.Base { get { - long nanosecPerTick = (1000L * 1000L * 1000L) / Stopwatch.Frequency; + double nanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency; long ticks = _STimer.ElapsedTicks; float dt = _STimer.ElapsedMilliseconds / 1000f; @@ -613,7 +613,7 @@ namespace Vocaluxe.Base { _STimer.Stop(); - long nanosecPerTick = (1000L * 1000L * 1000L) / Stopwatch.Frequency; + double nanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency; long ticks = _STimer.ElapsedTicks; float dt = _STimer.ElapsedMilliseconds / 1000f; From 6e99108287029307dfee4aad2f34fd3e59e15810 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 20 Mar 2012 18:55:59 +0100 Subject: [PATCH 26/31] update to build 0057 --- Vocaluxe/Base/CSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index ba5e667f..19906005 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -47,7 +47,7 @@ namespace Vocaluxe.Base public const int iVersionSub = 0; // steps public const ERevision VersionRevision = ERevision.Beta; - public const int iBuild = 56; // Increase on every published version! Never Reset! + public const int iBuild = 57; // Increase on every published version! Never Reset! public const int iDatabaseHighscoreVersion = 1; public const int iDatabaseCoverVersion = 1; From fc0dd193ba64ca2029f4f3c5f4bb40bb7b8ee324 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 19 Mar 2012 17:43:11 +0100 Subject: [PATCH 27/31] Fixed JumpTo method, JumpTo is still disabled in 0.1 --- Vocaluxe/Screens/CScreenSong.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 42fb3b06..c336e187 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -63,7 +63,7 @@ namespace Vocaluxe.Screens { JumpTo(KeyEvent.Unicode); return true; - }*/ + } */ } else { @@ -304,11 +304,10 @@ namespace Vocaluxe.Screens id = CSongs.VisibleSongs[song].ID; } - // here is a fault: SetSelectedSong should point to the visible index - Vocaluxe.Lib.Song.CSong s = Array.Find(CSongs.VisibleSongs, element => element.Artist.StartsWith(Letter.ToString(), StringComparison.OrdinalIgnoreCase)); - if (s != null && s.ID > -1) + int visibleID = Array.FindIndex(CSongs.VisibleSongs, element => element.Artist.StartsWith(Letter.ToString(), StringComparison.OrdinalIgnoreCase)); + if (visibleID > -1) { - id = s.ID; + id = visibleID; SongMenus[htSongMenus(SongMenu)].SetSelectedSong(id); } } @@ -345,4 +344,4 @@ namespace Vocaluxe.Screens SongMenus[htSongMenus(SongMenu)].OnShow(); } } -} +} \ No newline at end of file From 75af56d8b5e31212e19a402e9085f981aca6d1c9 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 19 Mar 2012 18:23:16 +0100 Subject: [PATCH 28/31] Log error if device creation failed --- Vocaluxe/Lib/Draw/CDirect3D.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 07fb2e5c..15842ce8 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -166,6 +166,9 @@ namespace Vocaluxe.Lib.Draw else flags = CreateFlags.SoftwareVertexProcessing; _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); + + if(_Device.Disposed || _D3D.Disposed || _Device == null || _D3D == null) + CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and graficcard drivers are up to date"); this.CenterToScreen(); From 2f5cbfe066a55dc42d7474b1fb0601e621f190e3 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 20 Mar 2012 14:57:09 +0100 Subject: [PATCH 29/31] Intel GMA cannot handle 32 bit indexbuffers, please test on a GMA device please --- Vocaluxe/Lib/Draw/CDirect3D.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 15842ce8..5b9be8f3 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -171,16 +171,6 @@ namespace Vocaluxe.Lib.Draw CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and graficcard drivers are up to date"); this.CenterToScreen(); - - //This creates a new white texture and adds it to the texture pool - //This texture is used for the DrawRect method - Bitmap blankMap = new Bitmap(1, 1); - Graphics g = Graphics.FromImage(blankMap); - g.Clear(Color.White); - g.Dispose(); - blankTexture = AddTexture(blankMap); - - blankMap.Dispose(); } #region form events @@ -422,7 +412,7 @@ namespace Vocaluxe.Lib.Draw _Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse); _Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate); - int[] indices = new int[6]; + Int16[] indices = new Int16[6]; indices[0] = 0; indices[1] = 1; indices[2] = 2; @@ -430,12 +420,22 @@ namespace Vocaluxe.Lib.Draw indices[4] = 2; indices[5] = 3; - _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(int), Usage.WriteOnly, Pool.Managed, false); + _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(int), Usage.WriteOnly, Pool.Managed, true); DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.None); stream.WriteRange(indices); _IndexBuffer.Unlock(); _Device.Indices = _IndexBuffer; + + //This creates a new white texture and adds it to the texture pool + //This texture is used for the DrawRect method + Bitmap blankMap = new Bitmap(1, 1); + Graphics g = Graphics.FromImage(blankMap); + g.Clear(Color.White); + g.Dispose(); + blankTexture = AddTexture(blankMap); + + blankMap.Dispose(); return true; } else From fd946dfcdb342d7ea2b8396dd071e637d5740666 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 21 Mar 2012 15:25:42 +0100 Subject: [PATCH 30/31] Added link to directx runtimes --- Vocaluxe/Lib/Draw/CDirect3D.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 5b9be8f3..3ec360fd 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -168,7 +168,7 @@ namespace Vocaluxe.Lib.Draw _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); if(_Device.Disposed || _D3D.Disposed || _Device == null || _D3D == null) - CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and graficcard drivers are up to date"); + CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and graficcard drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); this.CenterToScreen(); } @@ -197,7 +197,6 @@ namespace Vocaluxe.Lib.Draw protected override void OnResize(EventArgs e) { base.OnResize(e); - this.ClientSize = this.ClientSize; RResize(); } From b58087776cc0e596b34d244e7662cddaa7a93e5c Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 21 Mar 2012 15:56:10 +0100 Subject: [PATCH 31/31] Terminate Vocaluxe and show a message box if no DirectX runtime was found --- Vocaluxe/Lib/Draw/CDirect3D.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3ec360fd..2a6de382 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -73,6 +73,13 @@ namespace Vocaluxe.Lib.Draw _Keys = new CKeys(); _D3D = new Direct3D(); + if (_D3D == null) + { + MessageBox.Show("No DirectX runtimes were found, please download and install them from http://www.microsoft.com/download/en/details.aspx?id=8109"); + CLog.LogError("No DirectX runtimes were found, please download and install them from http://www.microsoft.com/download/en/details.aspx?id=8109"); + Environment.Exit(Environment.ExitCode); + } + this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.Resize += new EventHandler(this.OnResizeEvent); @@ -166,9 +173,13 @@ namespace Vocaluxe.Lib.Draw else flags = CreateFlags.SoftwareVertexProcessing; _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); - - if(_Device.Disposed || _D3D.Disposed || _Device == null || _D3D == null) - CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and graficcard drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); + + if (_Device.Disposed || _D3D.Disposed || _Device == null || _D3D == null) + { + MessageBox.Show("Something went wrong with device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); + CLog.LogError("Something went wrong with device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); + Environment.Exit(Environment.ExitCode); + } this.CenterToScreen(); }