No user left behind. Fix the OpenGL 1.1 build to work too.

This commit is contained in:
UnknownShadow200 2020-02-10 12:45:05 +11:00
parent dff59b8f9f
commit f64300532b
3 changed files with 40 additions and 19 deletions

View File

@ -393,6 +393,9 @@ static cc_bool BuildChunk(int x1, int y1, int z1, struct ChunkInfo* info) {
#ifndef CC_BUILD_GL11 #ifndef CC_BUILD_GL11
/* add an extra element to fix crashing on some GPUs */ /* add an extra element to fix crashing on some GPUs */
Builder_Vertices = Gfx_CreateAndLockVb(VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1, &info->Vb); Builder_Vertices = Gfx_CreateAndLockVb(VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1, &info->Vb);
#else
/* NOTE: Relies on assumption vb is ignored by GL11 Gfx_LockVb implementation */
Builder_Vertices = Gfx_LockVb(0, VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1);
#endif #endif
Builder_PostStretchTiles(); Builder_PostStretchTiles();

View File

@ -986,9 +986,9 @@ void Gfx_OnWindowResize(void) { Gfx_LoseContext(" (resizing window)"); }
#endif #endif
#if defined CC_BUILD_GL11 #if defined CC_BUILD_GL11
static GLuint gfx_activeList; static GLuint activeList;
#define gl_DYNAMICLISTID 1234567891 #define gl_DYNAMICLISTID 1234567891
static void* gfx_dynamicListData; static void* dynamicListData;
static cc_uint16 gl_indices[GFX_MAX_INDICES]; static cc_uint16 gl_indices[GFX_MAX_INDICES];
#elif defined CC_BUILD_GLMODERN #elif defined CC_BUILD_GLMODERN
#define _glBindBuffer(t,b) glBindBuffer(t,b) #define _glBindBuffer(t,b) glBindBuffer(t,b)
@ -1250,14 +1250,12 @@ void Gfx_UnlockVb(GfxResourceID vb) {
_glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW); _glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW);
} }
#else #else
GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count) { static void UpdateDisplayList(GLuint list, void* vertices, VertexFormat fmt, int count) {
GLuint list = glGenLists(1);
/* We need to restore client state afer building the list */ /* We need to restore client state afer building the list */
int curFormat = gfx_batchFormat; int curFormat = gfx_batchFormat;
void* dyn_data = gfx_dynamicListData; void* dyn_data = dynamicListData;
Gfx_SetVertexFormat(fmt); Gfx_SetVertexFormat(fmt);
gfx_dynamicListData = vertices; dynamicListData = vertices;
glNewList(list, GL_COMPILE); glNewList(list, GL_COMPILE);
gfx_setupVBFunc(); gfx_setupVBFunc();
@ -1265,17 +1263,37 @@ GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count) {
glEndList(); glEndList();
Gfx_SetVertexFormat(curFormat); Gfx_SetVertexFormat(curFormat);
gfx_dynamicListData = dyn_data; dynamicListData = dyn_data;
return list;
} }
void Gfx_BindVb(GfxResourceID vb) { gfx_activeList = (GLuint)vb; } GfxResourceID Gfx_CreateVb(VertexFormat fmt, int count) { return glGenLists(1); }
void Gfx_BindVb(GfxResourceID vb) { activeList = (GLuint)vb; }
void Gfx_DeleteVb(GfxResourceID* vb) { void Gfx_DeleteVb(GfxResourceID* vb) {
GLuint id = (GLuint)(*vb); GLuint id = (GLuint)(*vb);
if (id) glDeleteLists(id, 1); if (id) glDeleteLists(id, 1);
*vb = 0; *vb = 0;
} }
/* NOTE! Building chunk in Builder.c relies on vb being ignored */
/* If that changes, you must fix Builder.c to properly call Gfx_LockVb */
static VertexFormat tmpFormat;
static int tmpCount;
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
tmpFormat = fmt;
tmpCount = count;
return FastAllocTempMem(count * gfx_strideSizes[fmt]);
}
void Gfx_UnlockVb(GfxResourceID vb) {
UpdateDisplayList((GLuint)vb, tmpData, tmpFormat, tmpCount);
}
GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count) {
GLuint list = glGenLists(1);
UpdateDisplayList(list, vertices, fmt, count);
return list;
}
#endif #endif
@ -1314,8 +1332,8 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
} }
void Gfx_BindDynamicVb(GfxResourceID vb) { void Gfx_BindDynamicVb(GfxResourceID vb) {
gfx_activeList = gl_DYNAMICLISTID; activeList = gl_DYNAMICLISTID;
gfx_dynamicListData = (void*)vb; dynamicListData = (void*)vb;
} }
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { void Gfx_DeleteDynamicVb(GfxResourceID* vb) {
@ -1901,7 +1919,7 @@ cc_bool Gfx_WarnIfNecessary(void) {
*#########################################################################################################################*/ *#########################################################################################################################*/
#ifdef CC_BUILD_GL11 #ifdef CC_BUILD_GL11
/* point to client side dynamic array */ /* point to client side dynamic array */
#define VB_PTR ((cc_uint8*)gfx_dynamicListData) #define VB_PTR ((cc_uint8*)dynamicListData)
#define IB_PTR gl_indices #define IB_PTR gl_indices
#else #else
/* no client side array, use vertex buffer object */ /* no client side array, use vertex buffer object */
@ -1956,7 +1974,7 @@ void Gfx_DrawVb_Lines(int verticesCount) {
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
#ifdef CC_BUILD_GL11 #ifdef CC_BUILD_GL11
if (gfx_activeList != gl_DYNAMICLISTID) { glCallList(gfx_activeList); return; } if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
#endif #endif
gfx_setupVBRangeFunc(startVertex); gfx_setupVBRangeFunc(startVertex);
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR); glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR);
@ -1964,7 +1982,7 @@ void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
void Gfx_DrawVb_IndexedTris(int verticesCount) { void Gfx_DrawVb_IndexedTris(int verticesCount) {
#ifdef CC_BUILD_GL11 #ifdef CC_BUILD_GL11
if (gfx_activeList != gl_DYNAMICLISTID) { glCallList(gfx_activeList); return; } if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
#endif #endif
gfx_setupVBFunc(); gfx_setupVBFunc();
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR); glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR);

View File

@ -106,8 +106,6 @@ CC_API void Gfx_BindIb(GfxResourceID ib);
/* Deletes the given index buffer, then sets it to 0. */ /* Deletes the given index buffer, then sets it to 0. */
CC_API void Gfx_DeleteIb(GfxResourceID* ib); CC_API void Gfx_DeleteIb(GfxResourceID* ib);
/* Creates a new vertex buffer and fills out its contents. */
CC_API GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count);
/* Creates a new vertex buffer. */ /* Creates a new vertex buffer. */
CC_API GfxResourceID Gfx_CreateVb(VertexFormat fmt, int count); CC_API GfxResourceID Gfx_CreateVb(VertexFormat fmt, int count);
/* Sets the currently active vertex buffer. */ /* Sets the currently active vertex buffer. */
@ -118,10 +116,12 @@ CC_API void Gfx_DeleteVb(GfxResourceID* vb);
CC_API void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count); CC_API void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count);
/* Submits the changed contents of a vertex buffer. */ /* Submits the changed contents of a vertex buffer. */
CC_API void Gfx_UnlockVb(GfxResourceID vb); CC_API void Gfx_UnlockVb(GfxResourceID vb);
/* TODO: Reuse memory for OpenGL, don't allocate mem all the time! */
/* TODO: How to make LockDynamicVb work with OpenGL 1.1 Builder stupidity.. */ /* TODO: How to make LockDynamicVb work with OpenGL 1.1 Builder stupidity.. */
/* TODO: Cleanup the D3D9 Init and remove the if (i == count) stuff. */ /* TODO: Cleanup the D3D9 Init and remove the if (i == count) stuff. */
/* TODO: Maybe need a Gfx_CreateAndLockVb for common usage? */ #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
/* Creates a new dynamic vertex buffer, whose contents can be updated later. */ /* Creates a new dynamic vertex buffer, whose contents can be updated later. */
CC_API GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices); CC_API GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices);