mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
For consistency, always use verticesCount in 3D graphics APIs, instead of mixing vertices and indices count
This commit is contained in:
parent
39aa37a83d
commit
7d9dd4ec1e
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -45,7 +45,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
/// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. </summary>
|
||||
public void UpdateDynamicVb_IndexedTris<T>(int vb, T[] vertices, int vCount) where T : struct {
|
||||
SetDynamicVbData(vb, vertices, vCount);
|
||||
DrawVb_IndexedTris(vCount * 6 / 4);
|
||||
DrawVb_IndexedTris(vCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,10 +186,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
public abstract void DrawVb_Lines(int verticesCount);
|
||||
|
||||
/// <summary> Draws the specified subset of the vertices in the current vertex buffer as triangles. </summary>
|
||||
public abstract void DrawVb_IndexedTris(int indicesCount, int startIndex);
|
||||
public abstract void DrawVb_IndexedTris(int verticesCount, int startVertex);
|
||||
|
||||
/// <summary> Draws the specified subset of the vertices in the current vertex buffer as triangles. </summary>
|
||||
public abstract void DrawVb_IndexedTris(int indicesCount);
|
||||
public abstract void DrawVb_IndexedTris(int verticesCount);
|
||||
|
||||
/// <summary> Optimised version of DrawIndexedVb for VertexFormat.Pos3fTex2fCol4b </summary>
|
||||
internal abstract void DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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. */
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user