diff --git a/src/Graphics.c b/src/Graphics.c index 4a62f9572..4220cc7c7 100644 --- a/src/Graphics.c +++ b/src/Graphics.c @@ -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); diff --git a/src/Graphics.h b/src/Graphics.h index ea14a4678..61aa20811 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -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); diff --git a/src/MapRenderer.c b/src/MapRenderer.c index bb8ab431b..9fbb1d01d 100644 --- a/src/MapRenderer.c +++ b/src/MapRenderer.c @@ -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;