From d0f6fb03604512ceb5ebe9c915f9b3993fdee130 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 1 Jan 2015 15:29:32 +1100 Subject: [PATCH] Fix display lists with non-triangle draw modes, move mesh builder state updating to OnNewMapLoaded. --- GraphicsAPI/OpenGLApi.cs | 8 ++++---- MeshBuilders/ChunkMeshBuilder.cs | 16 ++++++++-------- Rendering/MapRenderer.cs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index eb65d12df..386fdb4cb 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -319,21 +319,21 @@ namespace ClassicalSharp.GraphicsAPI { if( format == VertexFormat.VertexPos3f ) { fixed( Vector3* p = (vertices as Vector3[]) ) { GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p ) ); - GL.DrawArrays( BeginMode.Triangles, 0, count ); + GL.DrawArrays( modeMappings[(int)mode], 0, count ); } } else if( format == VertexFormat.VertexPos3fCol4b ) { GL.EnableClientState( ArrayCap.ColorArray ); fixed( VertexPos3fCol4b* p = (vertices as VertexPos3fCol4b[]) ) { GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p ) ); GL.ColorPointer( 4, ColorPointerType.UnsignedByte, stride, (IntPtr)( 12 + (byte*)p ) ); - GL.DrawArrays( BeginMode.Triangles, 0, count ); + GL.DrawArrays( modeMappings[(int)mode], 0, count ); } } else if( format == VertexFormat.VertexPos3fTex2f ) { GL.EnableClientState( ArrayCap.TextureCoordArray ); fixed( VertexPos3fTex2f* p = (vertices as VertexPos3fTex2f[]) ) { GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p) ); GL.TexCoordPointer( 2, TexCoordPointerType.Float, stride, (IntPtr)( 12 + (byte*)p ) ); - GL.DrawArrays( BeginMode.Triangles, 0, count ); + GL.DrawArrays( modeMappings[(int)mode], 0, count ); } } else if( format == VertexFormat.VertexPos3fTex2fCol4b ) { GL.EnableClientState( ArrayCap.ColorArray ); @@ -342,7 +342,7 @@ namespace ClassicalSharp.GraphicsAPI { GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p ) ); GL.TexCoordPointer( 2, TexCoordPointerType.Float, stride, (IntPtr)( 12 + (byte*)p ) ); GL.ColorPointer( 4, ColorPointerType.UnsignedByte, stride, (IntPtr)( 20 + (byte*)p ) ); - GL.DrawArrays( BeginMode.Triangles, 0, count ); + GL.DrawArrays( modeMappings[(int)mode], 0, count ); } } diff --git a/MeshBuilders/ChunkMeshBuilder.cs b/MeshBuilders/ChunkMeshBuilder.cs index d3315ad50..4bab2add6 100644 --- a/MeshBuilders/ChunkMeshBuilder.cs +++ b/MeshBuilders/ChunkMeshBuilder.cs @@ -96,14 +96,7 @@ namespace ClassicalSharp { return allAir || allSolid; } - public ChunkDrawInfo[] GetDrawInfo( int x, int y, int z, Map map ) { - this.map = map; - width = map.Width; - height = map.Height; - length = map.Length; - maxX = width - 1; - maxY = height - 1; - maxZ = length - 1; + public ChunkDrawInfo[] GetDrawInfo( int x, int y, int z ) { BuildChunk( x, y, z ); return GetChunkInfo( x, y, z ); } @@ -373,6 +366,13 @@ namespace ClassicalSharp { } public virtual void OnNewMapLoaded() { + map = Window.Map; + width = map.Width; + height = map.Height; + length = map.Length; + maxX = width - 1; + maxY = height - 1; + maxZ = length - 1; } protected abstract ChunkDrawInfo[] GetChunkInfo( int x, int y, int z ); diff --git a/Rendering/MapRenderer.cs b/Rendering/MapRenderer.cs index fb630b9ee..c623e3cf1 100644 --- a/Rendering/MapRenderer.cs +++ b/Rendering/MapRenderer.cs @@ -296,7 +296,7 @@ namespace ClassicalSharp { if( info.DrawInfo == null ) { if( inRange && chunksUpdatedThisFrame < 4 ) { Window.ChunkUpdates++; - info.DrawInfo = builder.GetDrawInfo( loc.X, loc.Y, loc.Z, Window.Map ); + info.DrawInfo = builder.GetDrawInfo( loc.X, loc.Y, loc.Z ); chunksUpdatedThisFrame++; } }