From 71efc34d2f70527d585bc5bef81b7e7208848a70 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 6 May 2020 22:50:26 +1000 Subject: [PATCH] Cast result of Gfx_CreateAndLockVb for better C++ compatibility --- src/Builder.c | 6 ++++-- src/EnvRenderer.c | 15 ++++++++++----- src/Graphics.c | 2 +- src/Graphics.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Builder.c b/src/Builder.c index e81af0c91..b64057ec1 100644 --- a/src/Builder.c +++ b/src/Builder.c @@ -393,10 +393,12 @@ static cc_bool BuildChunk(int x1, int y1, int z1, struct ChunkInfo* info) { #ifndef CC_BUILD_GL11 /* add an extra element to fix crashing on some GPUs */ - Builder_Vertices = Gfx_CreateAndLockVb(VERTEX_FORMAT_TEXTURED, totalVerts + 1, &info->Vb); + Builder_Vertices = (struct VertexTextured*)Gfx_CreateAndLockVb(&info->Vb, + VERTEX_FORMAT_TEXTURED, totalVerts + 1); #else /* NOTE: Relies on assumption vb is ignored by GL11 Gfx_LockVb implementation */ - Builder_Vertices = Gfx_LockVb(0, VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1); + Builder_Vertices = (struct VertexTextured*)Gfx_LockVb(0, + VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1); #endif Builder_PostStretchTiles(); diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 36a3bb61b..bae918fd8 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -195,7 +195,8 @@ static void UpdateClouds(void) { z1 = -extent; z2 = World.Length + extent; clouds_vertices = CalcNumVertices(x2 - x1, z2 - z1); - data = Gfx_CreateAndLockVb(VERTEX_FORMAT_TEXTURED, clouds_vertices, &clouds_vb); + data = (struct VertexTextured*)Gfx_CreateAndLockVb(&clouds_vb, + VERTEX_FORMAT_TEXTURED, clouds_vertices); DrawCloudsY(x1, z1, x2, z2, Env.CloudsHeight, data); Gfx_UnlockVb(clouds_vb); } @@ -266,7 +267,8 @@ static void UpdateSky(void) { z1 = -extent; z2 = World.Length + extent; sky_vertices = CalcNumVertices(x2 - x1, z2 - z1); - data = Gfx_CreateAndLockVb(VERTEX_FORMAT_COLOURED, sky_vertices, &sky_vb); + data = (struct VertexColoured*)Gfx_CreateAndLockVb(&sky_vb, + VERTEX_FORMAT_COLOURED, sky_vertices); height = max((World.Height + 2), Env.CloudsHeight) + 6; DrawSkyY(x1, z1, x2, z2, height, data); Gfx_UnlockVb(sky_vb); @@ -339,7 +341,8 @@ static void UpdateSkybox(void) { if (Gfx.LostContext) return; if (EnvRenderer_Minimal) return; - data = Gfx_CreateAndLockVb(VERTEX_FORMAT_TEXTURED, SKYBOX_COUNT, &skybox_vb); + data = (struct VertexTextured*)Gfx_CreateAndLockVb(&skybox_vb, + VERTEX_FORMAT_TEXTURED, SKYBOX_COUNT); Mem_Copy(data, vertices, sizeof(vertices)); for (i = 0; i < SKYBOX_COUNT; i++) { data[i].Col = Env.SkyboxCol; } Gfx_UnlockVb(skybox_vb); @@ -689,7 +692,8 @@ static void UpdateMapSides(void) { sides_vertices += CalcNumVertices(World.Width, World.Length); /* YQuads beneath map */ sides_vertices += 2 * CalcNumVertices(World.Width, Math_AbsI(y)); /* ZQuads */ sides_vertices += 2 * CalcNumVertices(World.Length, Math_AbsI(y)); /* XQuads */ - data = Gfx_CreateAndLockVb(VERTEX_FORMAT_TEXTURED, sides_vertices, &sides_vb); + data = (struct VertexTextured*)Gfx_CreateAndLockVb(&sides_vb, + VERTEX_FORMAT_TEXTURED, sides_vertices); sides_fullBright = Blocks.FullBright[block]; col = sides_fullBright ? white : Env.ShadowCol; @@ -734,7 +738,8 @@ static void UpdateMapEdges(void) { r = rects[i]; edges_vertices += CalcNumVertices(r.Width, r.Height); /* YPlanes outside */ } - data = Gfx_CreateAndLockVb(VERTEX_FORMAT_TEXTURED, edges_vertices, &edges_vb); + data = (struct VertexTextured*)Gfx_CreateAndLockVb(&edges_vb, + VERTEX_FORMAT_TEXTURED, edges_vertices); edges_fullBright = Blocks.FullBright[block]; col = edges_fullBright ? white : Env.SunCol; diff --git a/src/Graphics.c b/src/Graphics.c index 40b66230c..51cf54758 100644 --- a/src/Graphics.c +++ b/src/Graphics.c @@ -115,7 +115,7 @@ void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCoun Gfx_DrawVb_IndexedTris(vCount); } -void* Gfx_CreateAndLockVb(VertexFormat fmt, int count, GfxResourceID* vb) { +void* Gfx_CreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count) { *vb = Gfx_CreateVb(fmt, count); return Gfx_LockVb(*vb, fmt, count); } diff --git a/src/Graphics.h b/src/Graphics.h index fab137b25..a97fee9cf 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -197,7 +197,7 @@ cc_bool Gfx_TryRestoreContext(void); /* NOTE: This replaces the dynamic vertex buffer's data first with the given vertices before drawing. */ void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount); /* Shorthand for Gfx_CreateVb followed by Gfx_LockVb */ -void* Gfx_CreateAndLockVb(VertexFormat fmt, int count, GfxResourceID* vb); +void* Gfx_CreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count); /* Renders a 2D flat coloured rectangle. */ void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol col);