Fix OpenGL 1.1 build to not always draw all 6 faces in a chunk.

This also improves performance a bit, which is pretty important since this backend is for incredibly weak or non-existent GPUs.
This commit is contained in:
UnknownShadow200 2019-12-21 15:23:53 +11:00
parent 5fb7817c76
commit 02f65b1c5d
4 changed files with 64 additions and 32 deletions

View File

@ -97,6 +97,31 @@ static void Builder_AddVertices(BlockID block, Face face) {
part->fCount[face] += 4;
}
#ifdef CC_BUILD_GL11
static void BuildPartVbs(struct ChunkPartInfo* info) {
/* Sprites vertices are stored before chunk face sides */
int i, count, offset = info->Offset + info->SpriteCount;
for (i = 0; i < FACE_COUNT; i++) {
count = info->Counts[i];
if (count) {
info->Vbs[i] = Gfx_CreateVb(&Builder_Vertices[offset], VERTEX_FORMAT_P3FT2FC4B, count);
offset += count;
} else {
info->Vbs[i] = 0;
}
}
count = info->SpriteCount;
offset = info->Offset;
if (count) {
info->Vbs[i] = Gfx_CreateVb(&Builder_Vertices[offset], VERTEX_FORMAT_P3FT2FC4B, count);
} else {
info->Vbs[i] = 0;
}
}
#endif
static void Builder_SetPartInfo(struct Builder1DPart* part, int* offset, struct ChunkPartInfo* info, cc_bool* hasParts) {
int vCount = Builder1DPart_VerticesCount(part);
info->Offset = -1;
@ -106,10 +131,6 @@ static void Builder_SetPartInfo(struct Builder1DPart* part, int* offset, struct
*offset += vCount;
*hasParts = true;
#ifdef CC_BUILD_GL11
info->Vb = Gfx_CreateVb(&Builder_Vertices[info->Offset], VERTEX_FORMAT_P3FT2FC4B, vCount);
#endif
info->Counts[FACE_XMIN] = part->fCount[FACE_XMIN];
info->Counts[FACE_XMAX] = part->fCount[FACE_XMAX];
info->Counts[FACE_ZMIN] = part->fCount[FACE_ZMIN];
@ -117,6 +138,10 @@ static void Builder_SetPartInfo(struct Builder1DPart* part, int* offset, struct
info->Counts[FACE_YMIN] = part->fCount[FACE_YMIN];
info->Counts[FACE_YMAX] = part->fCount[FACE_YMAX];
info->SpriteCount = part->sCount;
#ifdef CC_BUILD_GL11
BuildPartVbs(info);
#endif
}

View File

@ -1880,14 +1880,12 @@ static void GL_CheckSupport(void) {
}
#else
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
/* Need to get rid of the 1 extra element, see comment in chunk mesh builder for why */
count &= ~0x01;
GLuint list = glGenLists(1);
/* We need to setup client state properly when building the list */
int curFormat = gfx_batchFormat;
/* We need to restore client state afer building the list */
int curFormat = gfx_batchFormat;
void* dyn_data = gfx_dynamicListData;
Gfx_SetVertexFormat(fmt);
void* dyn_data = gfx_dynamicListData;
gfx_dynamicListData = vertices;
glNewList(list, GL_COMPILE);
@ -1931,13 +1929,7 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
Mem_Copy((void*)vb, vertices, vCount * gfx_batchStride);
}
static GLuint gl_lastPartialList;
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
/* TODO: This renders the whole map, bad performance!! FIX FIX */
if (gfx_activeList == gl_lastPartialList) return;
glCallList(gfx_activeList);
gl_lastPartialList = gfx_activeList;
}
void Gfx_DrawIndexedVb_TrisT2fC4b(int list, int ignored) { glCallList(list); }
static void GL_CheckSupport(void) {
Gfx_MakeIndices(gl_indices, GFX_MAX_INDICES);

View File

@ -100,17 +100,25 @@ static void MapRenderer_CheckWeather(double delta) {
Gfx_SetAlphaBlending(false);
}
#ifdef CC_BUILD_GL11
#define MapRenderer_DrawFace(face, ign) Gfx_DrawIndexedVb_TrisT2fC4b(part.Vbs[face], 0);
#define MapRenderer_DrawFaces(f1, f2, ign) MapRenderer_DrawFace(f1, ign); MapRenderer_DrawFace(f2, ign);
#else
#define MapRenderer_DrawFace(face, offset) Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[face], offset);
#define MapRenderer_DrawFaces(f1, f2, offset) Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[f1] + part.Counts[f2], offset);
#endif
#define MapRenderer_DrawNormalFaces(minFace, maxFace) \
if (drawMin && drawMax) { \
Gfx_SetFaceCulling(true); \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[minFace] + part.Counts[maxFace], offset); \
MapRenderer_DrawFaces(minFace, maxFace, offset); \
Gfx_SetFaceCulling(false); \
Game_Vertices += (part.Counts[minFace] + part.Counts[maxFace]); \
} else if (drawMin) { \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[minFace], offset); \
MapRenderer_DrawFace(minFace, offset); \
Game_Vertices += part.Counts[minFace]; \
} else if (drawMax) { \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[maxFace], offset + part.Counts[minFace]); \
MapRenderer_DrawFace(maxFace, offset + part.Counts[minFace]); \
Game_Vertices += part.Counts[maxFace]; \
}
@ -131,8 +139,6 @@ static void MapRenderer_RenderNormalBatch(int batch) {
#ifndef CC_BUILD_GL11
Gfx_BindVb(info->Vb);
#else
Gfx_BindVb(part.Vb);
#endif
offset = part.Offset + part.SpriteCount;
@ -155,6 +161,13 @@ static void MapRenderer_RenderNormalBatch(int batch) {
count = part.SpriteCount >> 2; /* 4 per sprite */
Gfx_SetFaceCulling(true);
/* TODO: fix to not render them all */
#ifdef CC_BUILD_GL11
Gfx_DrawIndexedVb_TrisT2fC4b(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;
} offset += count;
@ -203,13 +216,13 @@ void MapRenderer_RenderNormal(double delta) {
#define MapRenderer_DrawTranslucentFaces(minFace, maxFace) \
if (drawMin && drawMax) { \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[minFace] + part.Counts[maxFace], offset); \
MapRenderer_DrawFaces(minFace, maxFace, offset); \
Game_Vertices += (part.Counts[minFace] + part.Counts[maxFace]); \
} else if (drawMin) { \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[minFace], offset); \
MapRenderer_DrawFace(minFace, offset); \
Game_Vertices += part.Counts[minFace]; \
} else if (drawMax) { \
Gfx_DrawIndexedVb_TrisT2fC4b(part.Counts[maxFace], offset + part.Counts[minFace]); \
MapRenderer_DrawFace(maxFace, offset + part.Counts[minFace]); \
Game_Vertices += part.Counts[maxFace]; \
}
@ -230,8 +243,6 @@ static void MapRenderer_RenderTranslucentBatch(int batch) {
#ifndef CC_BUILD_GL11
Gfx_BindVb(info->Vb);
#else
Gfx_BindVb(part.Vb);
#endif
offset = part.Offset;
@ -633,15 +644,17 @@ void MapRenderer_RefreshChunk(int cx, int cy, int cz) {
void MapRenderer_DeleteChunk(struct ChunkInfo* info) {
struct ChunkPartInfo* ptr;
int i;
#ifdef CC_BUILD_GL11
int j;
#else
Gfx_DeleteVb(&info->Vb);
#endif
info->Empty = false; info->AllAir = false;
#ifdef OCCLUSION
info.OcclusionFlags = 0;
info.OccludedFlags = 0;
#endif
#ifndef CC_BUILD_GL11
Gfx_DeleteVb(&info->Vb);
#endif
if (info->NormalParts) {
ptr = info->NormalParts;
@ -649,7 +662,7 @@ void MapRenderer_DeleteChunk(struct ChunkInfo* info) {
if (ptr->Offset < 0) continue;
normPartsCount[i]--;
#ifdef CC_BUILD_GL11
Gfx_DeleteVb(&ptr->Vb);
for (j = 0; j < CHUNKPART_MAX_VBS; j++) Gfx_DeleteVb(&ptr->Vbs[j]);
#endif
}
info->NormalParts = NULL;
@ -661,7 +674,7 @@ void MapRenderer_DeleteChunk(struct ChunkInfo* info) {
if (ptr->Offset < 0) continue;
tranPartsCount[i]--;
#ifdef CC_BUILD_GL11
Gfx_DeleteVb(&ptr->Vb);
for (j = 0; j < CHUNKPART_MAX_VBS; j++) Gfx_DeleteVb(&ptr->Vbs[j]);
#endif
}
info->TranslucentParts = NULL;

View File

@ -29,7 +29,9 @@ extern struct ChunkPartInfo* MapRenderer_PartsTranslucent;
/* Describes a portion of the data needed for rendering a chunk. */
struct ChunkPartInfo {
#ifdef CC_BUILD_GL11
GfxResourceID Vb;
/* 1 VB per face, another VB for sprites */
#define CHUNKPART_MAX_VBS (FACE_COUNT + 1)
GfxResourceID Vbs[CHUNKPART_MAX_VBS];
#endif
int Offset; /* -1 if no vertices at all */
int SpriteCount; /* Sprite vertices count */