mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Reduce glVertexAttribPointer calls to improve performance in
web client when low performance is due to gl call overhead. Examples of FPS differences: -- CR 83/FF 78/IE 11 (Win7 desktop nvidia, 512 viewdist) ------------------------------------------------------- NA2 FB : 60->60, 38->47, 25->39 PR main: 90->100, 60->76, 42->70 TGA FB : 60->80, 49->62, 35->56 NB FB : 60->60, 44->47, 32->37 Au70 FB: 140->167, 72->92, 60->99 Lag map: 30->60, 25->40, 15->30 CR FB : 160->162, 100->108, 112->124 Fltgras: 200->200, 185->185, 310->320 -- CR 83/IE 11 (Win 7 laptop intel, 256 viewdist) NA2 FB : 40-70 -> 50-80 , 14->24 PR main: 25-35 -> 25-40 , 22->27 TGA FB : 20-30 -> 20-40 , 18->22 NB FB : 40-50 -> 40-80 , 17->55 Au70 FB: 30-70 -> 40-80 , 20->35 Lag map: 20-30 -> 30-60 , 10->20 CR FB : 70-120-> 70-130, 30->45 Fltgras: 150-170-> 150-170, 66->66 -- CR/FF mobile (Android, 128 viewdist) PR main: 16->17, 8-> 8 TGA FB : 50->60, 20-> 22 Au70 FB: 70->80, 30-> 30 Lag map: 17->23, 8-> 11 Fltgras: 150->150, 57->60 So to the best of my knowledge, there are no performance regressions. Raspberry pi/android should also improve a little bit, but untested. (benefit will be less as GLES calls are much cheaper compared to WebGL calls) These measurements should be looked at as relative percent improvements, not as absolute FPS comparisons. I did not try to properly benchmark here - especially for the laptop, where FPS wildly varied. All these are averages.
This commit is contained in:
parent
c45442554f
commit
24e37d0658
@ -839,7 +839,7 @@ void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
|
||||
startVertex, 0, verticesCount, 0, verticesCount >> 1);
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||
IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
|
||||
startVertex, 0, verticesCount, 0, verticesCount >> 1);
|
||||
}
|
||||
@ -1913,12 +1913,20 @@ void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, NULL);
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
cc_uint32 offset = startVertex * SIZEOF_VERTEX_TEXTURED;
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, false, SIZEOF_VERTEX_TEXTURED, (void*)(offset));
|
||||
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, SIZEOF_VERTEX_TEXTURED, (void*)(offset + 12));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, false, SIZEOF_VERTEX_TEXTURED, (void*)(offset + 16));
|
||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, NULL);
|
||||
void Gfx_BindVb_T2fC4b(GfxResourceID vb) {
|
||||
Gfx_BindVb(vb);
|
||||
GL_SetupVbTextured();
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||
if (startVertex + verticesCount > GFX_MAX_VERTICES) {
|
||||
GL_SetupVbTextured_Range(startVertex);
|
||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, NULL);
|
||||
GL_SetupVbTextured();
|
||||
} else {
|
||||
/* ICOUNT(startVertex) * 2 = startVertex * 3 */
|
||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, (void*)(startVertex * 3));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2086,7 +2094,7 @@ void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
||||
}
|
||||
|
||||
#ifndef CC_BUILD_GL11
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||
cc_uint32 offset = startVertex * SIZEOF_VERTEX_TEXTURED;
|
||||
glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, (void*)(offset));
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, (void*)(offset + 12));
|
||||
@ -2122,7 +2130,7 @@ static void GL_CheckSupport(void) {
|
||||
customMipmapsLevels = true;
|
||||
}
|
||||
#else
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int list, int ignored) { glCallList(list); }
|
||||
void Gfx_DrawIndexedTris_T2fC4b(int list, int ignored) { glCallList(list); }
|
||||
|
||||
static void GL_CheckSupport(void) {
|
||||
MakeIndices(gl_indices, GFX_MAX_INDICES);
|
||||
|
@ -126,12 +126,18 @@ CC_API void Gfx_DeleteVb(GfxResourceID* vb);
|
||||
CC_API void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count);
|
||||
/* Submits the changed contents of a vertex buffer. */
|
||||
CC_API void Gfx_UnlockVb(GfxResourceID vb);
|
||||
|
||||
/* TODO: How to make LockDynamicVb work with OpenGL 1.1 Builder stupidity.. */
|
||||
/* TODO: Cleanup the D3D9 Init and remove the if (i == count) stuff. */
|
||||
#ifdef CC_BUILD_GL11
|
||||
/* Special case of Gfx_Create/LockVb for building chunks in Builder.c */
|
||||
GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count);
|
||||
#endif
|
||||
#ifdef CC_BUILD_GLMODERN
|
||||
/* Special case Gfx_BindVb for map renderer */
|
||||
void Gfx_BindVb_T2fC4b(GfxResourceID vb);
|
||||
#else
|
||||
#define Gfx_BindVb_T2fC4b Gfx_BindVb
|
||||
#endif
|
||||
|
||||
/* Creates a new dynamic vertex buffer, whose contents can be updated later. */
|
||||
CC_API GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices);
|
||||
@ -161,7 +167,7 @@ CC_API void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex);
|
||||
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
|
||||
CC_API void Gfx_DrawVb_IndexedTris(int verticesCount);
|
||||
/* Special case Gfx_DrawVb_IndexedTris_Range for map renderer */
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
|
||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex);
|
||||
|
||||
/* Loads the given matrix over the currently active matrix. */
|
||||
CC_API void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix);
|
||||
|
@ -99,11 +99,11 @@ static void CheckWeather(double delta) {
|
||||
}
|
||||
|
||||
#ifdef CC_BUILD_GL11
|
||||
#define DrawFace(face, ign) Gfx_DrawIndexedVb_TrisT2fC4b(part.Vbs[face], 0);
|
||||
#define DrawFace(face, ign) Gfx_DrawIndexedTris_T2fC4b(part.Vbs[face], 0);
|
||||
#define DrawFaces(f1, f2, ign) DrawFace(f1, ign); DrawFace(f2, ign);
|
||||
#else
|
||||
#define DrawFace(face, offset) Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[face], offset);
|
||||
#define DrawFaces(f1, f2, offset) Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[f1] + part.Counts[f2], offset);
|
||||
#define DrawFace(face, offset) Gfx_DrawIndexedTris_T2fC4b(part.Counts[face], offset);
|
||||
#define DrawFaces(f1, f2, offset) Gfx_DrawIndexedTris_T2fC4b(part.Counts[f1] + part.Counts[f2], offset);
|
||||
#endif
|
||||
|
||||
#define DrawNormalFaces(minFace, maxFace) \
|
||||
@ -136,7 +136,7 @@ static void RenderNormalBatch(int batch) {
|
||||
hasNormParts[batch] = true;
|
||||
|
||||
#ifndef CC_BUILD_GL11
|
||||
Gfx_BindVb(info->Vb);
|
||||
Gfx_BindVb_T2fC4b(info->Vb);
|
||||
#endif
|
||||
|
||||
offset = part.Offset + part.SpriteCount;
|
||||
@ -161,25 +161,25 @@ static void RenderNormalBatch(int batch) {
|
||||
Gfx_SetFaceCulling(true);
|
||||
/* TODO: fix to not render them all */
|
||||
#ifdef CC_BUILD_GL11
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.Vbs[FACE_COUNT], 0);
|
||||
Gfx_DrawIndexedTris_T2fC4b(part.Vbs[FACE_COUNT], 0);
|
||||
Game_Vertices += count * 4;
|
||||
Gfx_SetFaceCulling(false);
|
||||
continue;
|
||||
#endif
|
||||
if (info->DrawXMax || info->DrawZMin) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(count, offset); Game_Vertices += count;
|
||||
Gfx_DrawIndexedTris_T2fC4b(count, offset); Game_Vertices += count;
|
||||
} offset += count;
|
||||
|
||||
if (info->DrawXMin || info->DrawZMax) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(count, offset); Game_Vertices += count;
|
||||
Gfx_DrawIndexedTris_T2fC4b(count, offset); Game_Vertices += count;
|
||||
} offset += count;
|
||||
|
||||
if (info->DrawXMin || info->DrawZMin) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(count, offset); Game_Vertices += count;
|
||||
Gfx_DrawIndexedTris_T2fC4b(count, offset); Game_Vertices += count;
|
||||
} offset += count;
|
||||
|
||||
if (info->DrawXMax || info->DrawZMax) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(count, offset); Game_Vertices += count;
|
||||
Gfx_DrawIndexedTris_T2fC4b(count, offset); Game_Vertices += count;
|
||||
}
|
||||
Gfx_SetFaceCulling(false);
|
||||
}
|
||||
@ -240,7 +240,7 @@ static void RenderTranslucentBatch(int batch) {
|
||||
hasTranParts[batch] = true;
|
||||
|
||||
#ifndef CC_BUILD_GL11
|
||||
Gfx_BindVb(info->Vb);
|
||||
Gfx_BindVb_T2fC4b(info->Vb);
|
||||
#endif
|
||||
|
||||
offset = part.Offset;
|
||||
|
Loading…
x
Reference in New Issue
Block a user