diff --git a/ClassicalSharp/2D/Screens/StatusScreen.cs b/ClassicalSharp/2D/Screens/StatusScreen.cs index 811b90e3e..daa04cddd 100644 --- a/ClassicalSharp/2D/Screens/StatusScreen.cs +++ b/ClassicalSharp/2D/Screens/StatusScreen.cs @@ -61,7 +61,7 @@ namespace ClassicalSharp.Gui.Screens { if (game.ChunkUpdates > 0) { statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, "); } - int indices = (game.Vertices / 4) * 6; + int indices = (game.Vertices >> 2) * 6; statusBuffer.AppendNum(ref index, indices).Append(ref index, " vertices"); int ping = PingList.AveragePingMilliseconds(); diff --git a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs index 863c486f3..6f72bede8 100644 --- a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs +++ b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs @@ -337,17 +337,17 @@ namespace ClassicalSharp.GraphicsAPI { } public override void DrawVb_Lines(int verticesCount) { - device.DrawPrimitives(PrimitiveType.LineList, 0, verticesCount / 2); + device.DrawPrimitives(PrimitiveType.LineList, 0, verticesCount >> 1); } - public override void DrawVb_IndexedTris(int indicesCount, int startIndex) { - device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, startIndex / 6 * 4, - indicesCount / 6 * 4, startIndex, indicesCount / 3); + public override void DrawVb_IndexedTris(int verticesCount, int startVertex) { + device.DrawIndexedPrimitives(PrimitiveType.TriangleList, startVertex, 0, + verticesCount, 0, verticesCount >> 1); } - public override void DrawVb_IndexedTris(int indicesCount) { + public override void DrawVb_IndexedTris(int verticesCount) { device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, - indicesCount / 6 * 4, 0, indicesCount / 3); + verticesCount, 0, verticesCount >> 1); } internal override void DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) { diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs index 5c79fb04b..9c3423e87 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs @@ -45,7 +45,7 @@ namespace ClassicalSharp.GraphicsAPI { /// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. public void UpdateDynamicVb_IndexedTris(int vb, T[] vertices, int vCount) where T : struct { SetDynamicVbData(vb, vertices, vCount); - DrawVb_IndexedTris(vCount * 6 / 4); + DrawVb_IndexedTris(vCount); } diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs index 32d8220e7..0f53386d6 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs @@ -186,10 +186,10 @@ namespace ClassicalSharp.GraphicsAPI { public abstract void DrawVb_Lines(int verticesCount); /// Draws the specified subset of the vertices in the current vertex buffer as triangles. - public abstract void DrawVb_IndexedTris(int indicesCount, int startIndex); + public abstract void DrawVb_IndexedTris(int verticesCount, int startVertex); /// Draws the specified subset of the vertices in the current vertex buffer as triangles. - public abstract void DrawVb_IndexedTris(int indicesCount); + public abstract void DrawVb_IndexedTris(int verticesCount); /// Optimised version of DrawIndexedVb for VertexFormat.Pos3fTex2fCol4b internal abstract void DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex); diff --git a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs index bd4a0e16b..6d7900e8d 100644 --- a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs +++ b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs @@ -263,7 +263,7 @@ namespace ClassicalSharp.GraphicsAPI { GL.TexCoordPointer(2, PointerType.Float, stride, (IntPtr)((byte*)vertices + 16)); } - GL.DrawElements(BeginMode.Triangles, count * 6 / 4, DrawElementsType.UnsignedShort, (IntPtr)indicesPtr); + GL.DrawElements(BeginMode.Triangles, (count >> 2) * 6, DrawElementsType.UnsignedShort, (IntPtr)indicesPtr); GL.EndList(); return list; } @@ -368,26 +368,26 @@ namespace ClassicalSharp.GraphicsAPI { GL.DrawArrays(BeginMode.Lines, 0, verticesCount); } - public override void DrawVb_IndexedTris(int indicesCount, int startIndex) { + public override void DrawVb_IndexedTris(int verticesCount, int startVertex) { if (glLists) { if (activeList != dynamicListId) { GL.CallList(activeList); } - else { DrawDynamicTriangles(indicesCount, startIndex); } + else { DrawDynamicTriangles(verticesCount, startVertex); } return; } - setupBatchFunc_Range(startIndex); - GL.DrawElements(BeginMode.Triangles, indicesCount, indexType, IntPtr.Zero); + setupBatchFunc_Range(startVertex); + GL.DrawElements(BeginMode.Triangles, (verticesCount >> 2) * 6, indexType, IntPtr.Zero); } - public override void DrawVb_IndexedTris(int indicesCount) { + public override void DrawVb_IndexedTris(int verticesCount) { if (glLists) { if (activeList != dynamicListId) { GL.CallList(activeList); } - else { DrawDynamicTriangles(indicesCount, 0); } + else { DrawDynamicTriangles(verticesCount, 0); } return; } setupBatchFunc(); - GL.DrawElements(BeginMode.Triangles, indicesCount, indexType, IntPtr.Zero); + GL.DrawElements(BeginMode.Triangles, (verticesCount >> 2) * 6, indexType, IntPtr.Zero); } void DrawDynamicLines(int verticesCount) { @@ -408,10 +408,6 @@ namespace ClassicalSharp.GraphicsAPI { void DrawDynamicTriangles(int verticesCount, int startVertex) { GL.Begin(BeginMode.Triangles); - // indices -> vertices count - verticesCount = verticesCount * 4 / 6; - startVertex = startVertex * 4 / 6; - if (batchFormat == VertexFormat.P3fT2fC4b) { VertexP3fT2fC4b[] ptr = (VertexP3fT2fC4b[])dynamicListData; for (int i = startVertex; i < startVertex + verticesCount; i += 4) { @@ -442,7 +438,7 @@ namespace ClassicalSharp.GraphicsAPI { GL.VertexPointer(3, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset)); GL.ColorPointer(4, PointerType.UnsignedByte, VertexP3fT2fC4b.Size, new IntPtr(offset + 12)); GL.TexCoordPointer(2, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset + 16)); - GL.DrawElements(BeginMode.Triangles, (verticesCount * 6) >> 2, indexType, IntPtr.Zero); + GL.DrawElements(BeginMode.Triangles, (verticesCount >> 2) * 6, indexType, IntPtr.Zero); } IntPtr zero = new IntPtr(0), twelve = new IntPtr(12), sixteen = new IntPtr(16); @@ -458,14 +454,14 @@ namespace ClassicalSharp.GraphicsAPI { GL.TexCoordPointer(2, PointerType.Float, VertexP3fT2fC4b.Size, sixteen); } - void SetupVbPos3fCol4b_Range(int startIndex) { - int offset = (startIndex / 6 * 4) * VertexP3fC4b.Size; + void SetupVbPos3fCol4b_Range(int startVertex) { + int offset = startVertex * VertexP3fC4b.Size; GL.VertexPointer(3, PointerType.Float, VertexP3fC4b.Size, new IntPtr(offset)); GL.ColorPointer(4, PointerType.UnsignedByte, VertexP3fC4b.Size, new IntPtr(offset + 12)); } - void SetupVbPos3fTex2fCol4b_Range(int startIndex) { - int offset = (startIndex / 6 * 4) * VertexP3fT2fC4b.Size; + void SetupVbPos3fTex2fCol4b_Range(int startVertex) { + int offset = startVertex * VertexP3fT2fC4b.Size; GL.VertexPointer(3, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset)); GL.ColorPointer(4, PointerType.UnsignedByte, VertexP3fT2fC4b.Size, new IntPtr(offset + 12)); GL.TexCoordPointer(2, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset + 16)); diff --git a/ClassicalSharp/Particles/ParticleManager.cs b/ClassicalSharp/Particles/ParticleManager.cs index 9a5af1187..5544d024d 100644 --- a/ClassicalSharp/Particles/ParticleManager.cs +++ b/ClassicalSharp/Particles/ParticleManager.cs @@ -81,7 +81,7 @@ namespace ClassicalSharp.Particles { if (partCount == 0) continue; gfx.BindTexture(game.TerrainAtlas1D.TexIds[i]); - gfx.DrawVb_IndexedTris(partCount * 6 / 4, offset * 6 / 4); + gfx.DrawVb_IndexedTris(partCount, offset); offset += partCount; } } diff --git a/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs b/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs index 3e1a5ef62..d5ec38f10 100644 --- a/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs +++ b/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs @@ -55,7 +55,7 @@ namespace ClassicalSharp.Renderers { gfx.BindTexture(sideTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(sidesVb); - gfx.DrawVb_IndexedTris(sidesVertices * 6 / 4); + gfx.DrawVb_IndexedTris(sidesVertices); gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); @@ -78,7 +78,7 @@ namespace ClassicalSharp.Renderers { // Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. float yVisible = Math.Min(0, map.Env.SidesHeight); if (camPos.Y >= yVisible) - gfx.DrawVb_IndexedTris(edgesVertices * 6 / 4); + gfx.DrawVb_IndexedTris(edgesVertices); gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); diff --git a/ClassicalSharp/Rendering/Env/SkyboxRenderer.cs b/ClassicalSharp/Rendering/Env/SkyboxRenderer.cs index fd862f11d..921f5bc36 100644 --- a/ClassicalSharp/Rendering/Env/SkyboxRenderer.cs +++ b/ClassicalSharp/Rendering/Env/SkyboxRenderer.cs @@ -74,7 +74,7 @@ namespace ClassicalSharp.Renderers { game.Graphics.LoadMatrix(ref m); game.Graphics.BindVb(vb); - game.Graphics.DrawVb_IndexedTris(count * 6 / 4); + game.Graphics.DrawVb_IndexedTris(count); game.Graphics.Texturing = false; game.Graphics.LoadMatrix(ref game.View); diff --git a/ClassicalSharp/Rendering/Env/StandardEnvRenderer.cs b/ClassicalSharp/Rendering/Env/StandardEnvRenderer.cs index 564ed8440..aba79bf25 100644 --- a/ClassicalSharp/Rendering/Env/StandardEnvRenderer.cs +++ b/ClassicalSharp/Rendering/Env/StandardEnvRenderer.cs @@ -127,14 +127,14 @@ namespace ClassicalSharp.Renderers { gfx.SetBatchFormat(VertexFormat.P3fC4b); gfx.BindVb(skyVb); if (skyY == normalY) { - gfx.DrawVb_IndexedTris(skyVertices * 6 / 4); + gfx.DrawVb_IndexedTris(skyVertices); } else { Matrix4 m = Matrix4.Identity; m.Row3.Y = skyY - normalY; // Y translation matrix gfx.PushMatrix(); gfx.MultiplyMatrix(ref m); - gfx.DrawVb_IndexedTris(skyVertices * 6 / 4); + gfx.DrawVb_IndexedTris(skyVertices); gfx.PopMatrix(); } RenderClouds(deltaTime); @@ -154,7 +154,7 @@ namespace ClassicalSharp.Renderers { gfx.BindTexture(game.CloudsTex); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(cloudsVb); - gfx.DrawVb_IndexedTris(cloudVertices * 6 / 4); + gfx.DrawVb_IndexedTris(cloudVertices); gfx.AlphaTest = false; gfx.Texturing = false; diff --git a/src/Client/BordersRenderer.c b/src/Client/BordersRenderer.c index 6805d66dc..3c26251b5 100644 --- a/src/Client/BordersRenderer.c +++ b/src/Client/BordersRenderer.c @@ -40,7 +40,7 @@ Gfx_SetTexturing(false); void BordersRenderer_RenderSides(Real64 delta) { BlockID block = WorldEnv_SidesBlock; BordersRenderer_SetupState(block, borders_sideTexId, borders_sidesVb); - Gfx_DrawVb_IndexedTris(ICOUNT(borders_sidesVertices)); + Gfx_DrawVb_IndexedTris(borders_sidesVertices); BordersRenderer_ResetState(block); } @@ -54,7 +54,7 @@ void BordersRenderer_RenderEdges(Real64 delta) { Vector3 camPos = Game_CurrentCameraPos; Int32 yVisible = min(0, WorldEnv_SidesHeight); if (camPos.Y >= yVisible) { - Gfx_DrawVb_IndexedTris(ICOUNT(borders_edgesVertices)); + Gfx_DrawVb_IndexedTris(borders_edgesVertices); } BordersRenderer_ResetState(block); } diff --git a/src/Client/D3D9Api.c b/src/Client/D3D9Api.c index 60756c78b..d4b7f5f9b 100644 --- a/src/Client/D3D9Api.c +++ b/src/Client/D3D9Api.c @@ -640,25 +640,25 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, Int32 vCount) { } void Gfx_DrawVb_Lines(Int32 verticesCount) { - ReturnCode hresult = IDirect3DDevice9_DrawPrimitive(device, D3DPT_LINELIST, 0, verticesCount / 2); + ReturnCode hresult = IDirect3DDevice9_DrawPrimitive(device, D3DPT_LINELIST, 0, verticesCount >> 1); ErrorHandler_CheckOrFail(hresult, "D3D9_DrawVb_Lines"); } -void Gfx_DrawVb_IndexedTris(Int32 indicesCount) { - ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, - 0, VCOUNT(indicesCount), 0, indicesCount / 3); +void Gfx_DrawVb_IndexedTris(Int32 verticesCount) { + ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, + 0, 0, verticesCount, 0, verticesCount >> 1); ErrorHandler_CheckOrFail(hresult, "D3D9_DrawVb_IndexedTris"); } -void Gfx_DrawVb_IndexedTris_Range(Int32 indicesCount, Int32 startIndex) { - ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, - VCOUNT(startIndex), VCOUNT(indicesCount), startIndex, indicesCount / 3); +void Gfx_DrawVb_IndexedTris_Range(Int32 verticesCount, Int32 startVertex) { + ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, + startVertex, 0, verticesCount, 0, verticesCount >> 1); ErrorHandler_CheckOrFail(hresult, "D3D9_DrawVb_IndexedTris"); } void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 verticesCount, Int32 startVertex) { - ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, startVertex, - 0, verticesCount, 0, verticesCount >> 1); + ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, + startVertex, 0, verticesCount, 0, verticesCount >> 1); ErrorHandler_CheckOrFail(hresult, "D3D9_DrawIndexedVb_TrisT2fC4b"); } diff --git a/src/Client/EnvRenderer.c b/src/Client/EnvRenderer.c index 61588685e..7472f8aab 100644 --- a/src/Client/EnvRenderer.c +++ b/src/Client/EnvRenderer.c @@ -79,7 +79,7 @@ void EnvRenderer_RenderClouds(Real64 deltaTime) { Gfx_BindTexture(env_cloudsTex); Gfx_SetBatchFormat(VertexFormat_P3fT2fC4b); Gfx_BindVb(env_cloudsVb); - Gfx_DrawVb_IndexedTris(ICOUNT(env_cloudVertices)); + Gfx_DrawVb_IndexedTris(env_cloudVertices); Gfx_SetAlphaTest(false); Gfx_SetTexturing(false); @@ -96,14 +96,14 @@ void EnvRenderer_RenderMainEnv(Real64 deltaTime) { Gfx_BindVb(env_skyVb); if (skyY == normalY) { - Gfx_DrawVb_IndexedTris(ICOUNT(env_skyVertices)); + Gfx_DrawVb_IndexedTris(env_skyVertices); } else { Matrix m = Matrix_Identity; m.Row3.Y = skyY - normalY; /* Y translation matrix */ Gfx_PushMatrix(); Gfx_MultiplyMatrix(&m); - Gfx_DrawVb_IndexedTris(ICOUNT(env_skyVertices)); + Gfx_DrawVb_IndexedTris(env_skyVertices); Gfx_PopMatrix(); } EnvRenderer_RenderClouds(deltaTime); diff --git a/src/Client/GraphicsAPI.h b/src/Client/GraphicsAPI.h index 51ab0b5be..c3b4bdd2e 100644 --- a/src/Client/GraphicsAPI.h +++ b/src/Client/GraphicsAPI.h @@ -12,8 +12,6 @@ /* Abstracts a 3D graphics rendering API. Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ - -#define VCOUNT(indicesCount) ((indicesCount) / 6 * 4) #define ICOUNT(verticesCount) ((verticesCount) / 4 * 6) /* Initalises this graphics API. */ @@ -125,11 +123,11 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, Int32 vCount); /* Draws the specified subset of the vertices in the current vertex buffer as lines. */ void Gfx_DrawVb_Lines(Int32 verticesCount); /* Draws the specified subset of the vertices in the current vertex buffer as triangles. */ -void Gfx_DrawVb_IndexedTris_Range(Int32 indicesCount, Int32 startIndex); +void Gfx_DrawVb_IndexedTris_Range(Int32 verticesCount, Int32 startVertex); /* Draws the specified subset of the vertices in the current vertex buffer as triangles. */ -void Gfx_DrawVb_IndexedTris(Int32 indicesCount); +void Gfx_DrawVb_IndexedTris(Int32 verticesCount); /* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */ -void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 startIndex); +void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 verticesCount, Int32 startVertex); static Int32 Gfx_strideSizes[2] = { 16, 24 }; /* Sets the matrix type that load/push/pop operations should be applied to. */ diff --git a/src/Client/GraphicsCommon.c b/src/Client/GraphicsCommon.c index 8f9c3888b..0f981738a 100644 --- a/src/Client/GraphicsCommon.c +++ b/src/Client/GraphicsCommon.c @@ -44,7 +44,7 @@ void GfxCommon_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, Int32 vCo void GfxCommon_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, Int32 vCount) { Gfx_SetDynamicVbData(vb, vertices, vCount); - Gfx_DrawVb_IndexedTris(vCount * 6 / 4); + Gfx_DrawVb_IndexedTris(vCount); } void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height, diff --git a/src/Client/SkyboxRenderer.c b/src/Client/SkyboxRenderer.c index 09827a845..94f3315aa 100644 --- a/src/Client/SkyboxRenderer.c +++ b/src/Client/SkyboxRenderer.c @@ -45,7 +45,7 @@ void SkyboxRenderer_Render(Real64 deltaTime) { Gfx_LoadMatrix(&m); Gfx_BindVb(skybox_vb); - Gfx_DrawVb_IndexedTris(ICOUNT(SKYBOX_COUNT)); + Gfx_DrawVb_IndexedTris(SKYBOX_COUNT); Gfx_SetTexturing(false); Gfx_LoadMatrix(&Game_View);