diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 9480d55b8..dd3e3a1e3 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -193,7 +193,4 @@ OpenTK - - - \ No newline at end of file diff --git a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs index 9e7eb10f5..67adea02e 100644 --- a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs +++ b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs @@ -282,9 +282,14 @@ namespace ClassicalSharp.GraphicsAPI { indicesCount / 6 * 4, startIndex, NumPrimitives( indicesCount, mode ) ); } - public override void DrawIndexedVb_T2fC4b( DrawMode mode, int indicesCount, int startVertex, int startIndex ) { - device.DrawIndexedPrimitives( modeMappings[(int)mode], startVertex, 0, - indicesCount / 6 * 4, startIndex, NumPrimitives( indicesCount, mode ) ); + internal override void DrawIndexedVb_TrisT2fC4b( DrawMode mode, int indicesCount, int startIndex ) { + device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, + indicesCount / 6 * 4, startIndex, indicesCount / 3 ); + } + + internal override void DrawIndexedVb_TrisT2fC4b( DrawMode mode, int indicesCount, int startVertex, int startIndex ) { + device.DrawIndexedPrimitives( PrimitiveType.TriangleList, startVertex, 0, + indicesCount / 6 * 4, startIndex, indicesCount / 3 ); } #endregion diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs index 504662660..b5a1b86cc 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs @@ -129,7 +129,9 @@ namespace ClassicalSharp.GraphicsAPI { public abstract void DrawIndexedVb( DrawMode mode, int indicesCount, int startIndex ); /// Optimised version of DrawIndexedVb for VertexFormat.Pos3fTex2fCol4b - public abstract void DrawIndexedVb_T2fC4b( DrawMode mode, int indicesCount, int offsetVertex, int startIndex ); + internal abstract void DrawIndexedVb_TrisT2fC4b( int indicesCount, int offsetVertex, int startIndex ); + + internal abstract void DrawIndexedVb_TrisT2fC4b( int indicesCount, int startIndex ); protected static int[] strideSizes = { 20, 16, 24 }; diff --git a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs index 1117b1563..a7bd8b139 100644 --- a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs +++ b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs @@ -285,12 +285,19 @@ namespace ClassicalSharp.GraphicsAPI { GL.DrawElements( modeMappings[(int)mode], indicesCount, indexType, new IntPtr( startIndex * 2 ) ); } - public override void DrawIndexedVb_T2fC4b( DrawMode mode, int indicesCount, int startVertex, int startIndex ) { + internal override void DrawIndexedVb_TrisT2fC4b( int indicesCount, int startIndex ) { + GL.VertexPointer( 3, PointerType.Float, 24, zero ); + GL.ColorPointer( 4, PointerType.UnsignedByte, 24, twelve ); + GL.TexCoordPointer( 2, PointerType.Float, 24, sixteen ); + GL.DrawElements( BeginMode.Triangles, indicesCount, indexType, new IntPtr( startIndex * 2 ) ); + } + + internal override void DrawIndexedVb_TrisT2fC4b( int indicesCount, int startVertex, int startIndex ) { int offset = startVertex * VertexPos3fTex2fCol4b.Size; GL.VertexPointer( 3, PointerType.Float, 24, new IntPtr( offset ) ); GL.ColorPointer( 4, PointerType.UnsignedByte, 24, new IntPtr( offset + 12 ) ); GL.TexCoordPointer( 2, PointerType.Float, 24, new IntPtr( offset + 16 ) ); - GL.DrawElements( modeMappings[(int)mode], indicesCount, indexType, new IntPtr( startIndex * 2 ) ); + GL.DrawElements( BeginMode.Triangles, indicesCount, indexType, new IntPtr( startIndex * 2 ) ); } IntPtr zero = new IntPtr( 0 ), twelve = new IntPtr( 12 ), sixteen = new IntPtr( 16 ); diff --git a/ClassicalSharp/Model/ModelPart.cs b/ClassicalSharp/Model/ModelPart.cs index e6769fd3a..afc517dd5 100644 --- a/ClassicalSharp/Model/ModelPart.cs +++ b/ClassicalSharp/Model/ModelPart.cs @@ -13,7 +13,7 @@ namespace ClassicalSharp { } public void Render( IGraphicsApi api ) { - api.DrawIndexedVb_T2fC4b( DrawMode.Triangles, Count, 0, Offset ); + api.DrawIndexedVb_TrisT2fC4b( Count, Offset ); } } diff --git a/ClassicalSharp/Rendering/MapEnvRenderer.cs b/ClassicalSharp/Rendering/MapEnvRenderer.cs index 1337189b3..9acc3e592 100644 --- a/ClassicalSharp/Rendering/MapEnvRenderer.cs +++ b/ClassicalSharp/Rendering/MapEnvRenderer.cs @@ -46,7 +46,7 @@ namespace ClassicalSharp { Graphics.BindTexture( sideTexId ); Graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); Graphics.BindVb( sidesVb ); - Graphics.DrawIndexedVb_T2fC4b( DrawMode.Triangles, sidesIndices, 0, 0 ); + Graphics.DrawIndexedVb_TrisT2fC4b( sidesIndices, 0 ); // Do not draw water when we cannot see it. // Fixes 'depth bleeding through' issues with 16 bit depth buffers on large maps. @@ -54,7 +54,7 @@ namespace ClassicalSharp { Graphics.AlphaBlending = true; Graphics.BindTexture( edgeTexId ); Graphics.BindVb( edgesVb ); - Graphics.DrawIndexedVb_T2fC4b( DrawMode.Triangles, edgesIndices, 0, 0 ); + Graphics.DrawIndexedVb_TrisT2fC4b( edgesIndices, 0 ); Graphics.AlphaBlending = false; } Graphics.Texturing = false; diff --git a/ClassicalSharp/Rendering/MapRenderer.Rendering.cs b/ClassicalSharp/Rendering/MapRenderer.Rendering.cs index 81ab727b9..8366aac81 100644 --- a/ClassicalSharp/Rendering/MapRenderer.Rendering.cs +++ b/ClassicalSharp/Rendering/MapRenderer.Rendering.cs @@ -18,10 +18,14 @@ namespace ClassicalSharp { ChunkPartInfo part = info.NormalParts[batch]; if( part.IndicesCount == 0 ) continue; - DrawPart( info, ref part ); + if( part.IndicesCount > maxIndices ) { + DrawBigPart( info, ref part ); + } else { + DrawPart( info, ref part ); + } if( part.spriteCount > 0 ) - api.DrawIndexedVb_T2fC4b( mode, part.spriteCount, 0, 0 ); + api.DrawIndexedVb_TrisT2fC4b( part.spriteCount, 0, 0 ); game.Vertices += part.IndicesCount; } } @@ -60,66 +64,94 @@ namespace ClassicalSharp { if( drawLeft && drawRight ) { api.FaceCulling = true; - api.DrawIndexedVb_T2fC4b( mode, part.leftCount + part.rightCount, 0, part.leftIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.leftCount + part.rightCount, part.leftIndex ); api.FaceCulling = false; } else if( drawLeft ) { - api.DrawIndexedVb_T2fC4b( mode, part.leftCount, 0, part.leftIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.leftCount, part.leftIndex ); } else if( drawRight ) { - api.DrawIndexedVb_T2fC4b( mode, part.rightCount, 0, part.rightIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.rightCount, part.rightIndex ); } if( drawFront && drawBack ) { api.FaceCulling = true; - api.DrawIndexedVb_T2fC4b( mode, part.frontCount + part.backCount, 0, part.frontIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.frontCount + part.backCount, part.frontIndex ); api.FaceCulling = false; } else if( drawFront ) { - api.DrawIndexedVb_T2fC4b( mode, part.frontCount, 0, part.frontIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.frontCount, part.frontIndex ); } else if( drawBack ) { - api.DrawIndexedVb_T2fC4b( mode, part.backCount, 0, part.backIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.backCount, part.backIndex ); } + if( drawBottom && drawTop ) { + api.FaceCulling = true; + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount, part.bottomIndex ); + api.FaceCulling = false; + } else if( drawBottom ) { + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount, part.bottomIndex ); + } else if( drawTop ) { + api.DrawIndexedVb_TrisT2fC4b( part.topCount, part.topIndex ); + } + } + + void DrawBigPart( ChunkInfo info, ref ChunkPartInfo part ) { + api.BindVb( part.VbId ); + bool drawLeft = info.DrawLeft && part.leftCount > 0; + bool drawRight = info.DrawRight && part.rightCount > 0; + bool drawBottom = info.DrawBottom && part.bottomCount > 0; + bool drawTop = info.DrawTop && part.topCount > 0; + bool drawFront = info.DrawFront && part.frontCount > 0; + bool drawBack = info.DrawBack && part.backCount > 0; + + if( drawLeft && drawRight ) { + api.FaceCulling = true; + api.DrawIndexedVb_TrisT2fC4b( part.leftCount + part.rightCount, part.leftIndex ); + api.FaceCulling = false; + } else if( drawLeft ) { + api.DrawIndexedVb_TrisT2fC4b( part.leftCount, part.leftIndex ); + } else if( drawRight ) { + api.DrawIndexedVb_TrisT2fC4b( part.rightCount, part.rightIndex ); + } + + if( drawFront && drawBack ) { + api.FaceCulling = true; + api.DrawIndexedVb_TrisT2fC4b( part.frontCount + part.backCount, part.frontIndex ); + api.FaceCulling = false; + } else if( drawFront ) { + api.DrawIndexedVb_TrisT2fC4b( part.frontCount, part.frontIndex ); + } else if( drawBack ) { + api.DrawIndexedVb_TrisT2fC4b( part.backCount, part.backIndex ); + } + + // Special handling for top and bottom as these can go over 65536 vertices and we need to adjust the indices in this case. if( drawBottom && drawTop ) { api.FaceCulling = true; if( part.IndicesCount > maxIndices ) { int part1Count = maxIndices - part.bottomIndex; - api.DrawIndexedVb_T2fC4b( mode, part1Count, 0, part.bottomIndex ); - api.DrawIndexedVb_T2fC4b( mode, part.bottomCount + part.topCount - part1Count, maxVertex, 0 ); + api.DrawIndexedVb_TrisT2fC4b( part1Count, part.bottomIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount - part1Count, maxVertex, 0 ); } else { - api.DrawIndexedVb_T2fC4b( mode, part.bottomCount + part.topCount, 0, part.bottomIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount, part.bottomIndex ); } api.FaceCulling = false; } else if( drawBottom ) { int part1Count; if( part.IndicesCount > maxIndices && ( part1Count = maxIndices - part.bottomIndex ) < part.bottomCount ) { - api.DrawIndexedVb_T2fC4b( mode, part1Count, 0, part.bottomIndex ); - api.DrawIndexedVb_T2fC4b( mode, part.bottomCount - part1Count, maxVertex, 0 ); + api.DrawIndexedVb_TrisT2fC4b( part1Count, part.bottomIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount - part1Count, maxVertex, 0 ); } else { - api.DrawIndexedVb_T2fC4b( mode, part.bottomCount, 0, part.bottomIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.bottomCount, part.bottomIndex ); } } else if( drawTop ) { int part1Count; if( part.IndicesCount > maxIndices && ( part1Count = maxIndices - part.topIndex ) < part.topCount ) { - api.DrawIndexedVb_T2fC4b( mode, part1Count, 0, part.topIndex ); - api.DrawIndexedVb_T2fC4b( mode, part.topCount - part1Count, maxVertex, 0 ); + api.DrawIndexedVb_TrisT2fC4b( part1Count, part.topIndex ); + api.DrawIndexedVb_TrisT2fC4b( part.topCount - part1Count, maxVertex, 0 ); } else { - api.DrawIndexedVb_T2fC4b( mode, part.topCount, 0, part.topIndex ); - } - + api.DrawIndexedVb_TrisT2fC4b( part.topCount, part.topIndex ); + } } - /*if( info.DrawLeft && part.leftCount > 0 ) - api.DrawIndexedVb( mode, part.leftCount, 0, part.leftIndex ); - if( info.DrawRight && part.rightCount > 0 ) - api.DrawIndexedVb( mode, part.rightCount, 0, part.rightIndex ); - if( info.DrawBottom && part.bottomCount > 0 ) - api.DrawIndexedVb( mode, part.bottomCount, 0, part.bottomIndex ); - if( info.DrawTop && part.topCount > 0 ) - api.DrawIndexedVb( mode, part.topCount, 0, part.topIndex ); - if( info.DrawFront && part.frontCount > 0 ) - api.DrawIndexedVb( mode, part.frontCount, 0, part.frontIndex ); - if( info.DrawBack && part.backCount > 0 ) - api.DrawIndexedVb( mode, part.backCount, 0, part.backIndex );*/ } } } \ No newline at end of file diff --git a/ClassicalSharp/Rendering/StandardEnvRenderer.cs b/ClassicalSharp/Rendering/StandardEnvRenderer.cs index a02236876..f614206f2 100644 --- a/ClassicalSharp/Rendering/StandardEnvRenderer.cs +++ b/ClassicalSharp/Rendering/StandardEnvRenderer.cs @@ -100,7 +100,7 @@ namespace ClassicalSharp.Renderers { Graphics.BindTexture( cloudTexture ); Graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); Graphics.BindVb( cloudsVb ); - Graphics.DrawIndexedVb_T2fC4b( DrawMode.Triangles, cloudsIndices, 0, 0 ); + Graphics.DrawIndexedVb_TrisT2fC4b( cloudsIndices, 0 ); Graphics.AlphaTest = false; Graphics.Texturing = false; diff --git a/license.txt b/license.txt index 9eee868cc..71a573cbe 100644 --- a/license.txt +++ b/license.txt @@ -1,15 +1,29 @@ Copyright (c) 2014 - 2015, UnknownShadow200 All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or other +materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +3. Neither the name of the copyright holder nor the names of its contributors may be +used to endorse or promote products derived from this software without specific prior +written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Other function licenses