mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
tidy up OpenGL backend compatibility code, make the OpenGL 1.1 slightly more unified behaviour
This commit is contained in:
parent
2dab8f427e
commit
c2fc17f0de
@ -138,10 +138,10 @@ CC_API void Gfx_UnlockVb(GfxResourceID vb);
|
|||||||
GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count);
|
GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CC_BUILD_GLMODERN
|
#ifdef CC_BUILD_GLMODERN
|
||||||
/* Special case Gfx_BindVb for map renderer */
|
/* Special case Gfx_BindVb for use with Gfx_DrawIndexedTris_T2fC4b */
|
||||||
void Gfx_BindVb_T2fC4b(GfxResourceID vb);
|
void Gfx_BindVb_Textured(GfxResourceID vb);
|
||||||
#else
|
#else
|
||||||
#define Gfx_BindVb_T2fC4b Gfx_BindVb
|
#define Gfx_BindVb_Textured Gfx_BindVb
|
||||||
#endif
|
#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. */
|
||||||
|
@ -915,7 +915,7 @@ void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
|||||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, NULL);
|
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_BindVb_T2fC4b(GfxResourceID vb) {
|
void Gfx_BindVb_Textured(GfxResourceID vb) {
|
||||||
Gfx_BindVb(vb);
|
Gfx_BindVb(vb);
|
||||||
GL_SetupVbTextured();
|
GL_SetupVbTextured();
|
||||||
}
|
}
|
||||||
@ -1029,6 +1029,81 @@ cc_bool Gfx_WarnIfNecessary(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*-------------------------------------------------------Compatibility-----------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
#ifdef CC_BUILD_GL11
|
||||||
|
static void GL_CheckSupport(void) { MakeIndices(gl_indices, GFX_MAX_INDICES); }
|
||||||
|
#else
|
||||||
|
/* fake vertex buffer objects with client side pointers */
|
||||||
|
typedef struct fake_buffer { cc_uint8* data; } fake_buffer;
|
||||||
|
static fake_buffer* cur_ib;
|
||||||
|
static fake_buffer* cur_vb;
|
||||||
|
#define fake_GetBuffer(target) (target == _GL_ELEMENT_ARRAY_BUFFER ? &cur_ib : &cur_vb);
|
||||||
|
|
||||||
|
static void APIENTRY fake_glBindBuffer(GLenum target, GLuint src) {
|
||||||
|
fake_buffer** buffer = fake_GetBuffer(target);
|
||||||
|
*buffer = (fake_buffer*)src;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void APIENTRY fake_glDeleteBuffers(GLsizei n, const GLuint *buffers) {
|
||||||
|
Mem_Free((void*)buffers[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void APIENTRY fake_glGenBuffers(GLsizei n, GLuint *buffers) {
|
||||||
|
fake_buffer* buffer = (fake_buffer*)Mem_TryAlloc(1, sizeof(fake_buffer));
|
||||||
|
buffer->data = NULL;
|
||||||
|
buffers[0] = (GLuint)buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void APIENTRY fake_glBufferData(GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage) {
|
||||||
|
fake_buffer* buffer = *fake_GetBuffer(target);
|
||||||
|
Mem_Free(buffer->data);
|
||||||
|
|
||||||
|
buffer->data = Mem_TryAlloc(size, 1);
|
||||||
|
if (data) Mem_Copy(buffer->data, data, size);
|
||||||
|
}
|
||||||
|
static void APIENTRY fake_glBufferSubData(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data) {
|
||||||
|
fake_buffer* buffer = *fake_GetBuffer(target);
|
||||||
|
Mem_Copy(buffer->data, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GL_CheckSupport(void) {
|
||||||
|
static const struct DynamicLibSym coreVboFuncs[5] = {
|
||||||
|
DynamicLib_Sym2("glBindBuffer", glBindBuffer), DynamicLib_Sym2("glDeleteBuffers", glDeleteBuffers),
|
||||||
|
DynamicLib_Sym2("glGenBuffers", glGenBuffers), DynamicLib_Sym2("glBufferData", glBufferData),
|
||||||
|
DynamicLib_Sym2("glBufferSubData", glBufferSubData)
|
||||||
|
};
|
||||||
|
static const struct DynamicLibSym arbVboFuncs[5] = {
|
||||||
|
DynamicLib_Sym2("glBindBufferARB", glBindBuffer), DynamicLib_Sym2("glDeleteBuffersARB", glDeleteBuffers),
|
||||||
|
DynamicLib_Sym2("glGenBuffersARB", glGenBuffers), DynamicLib_Sym2("glBufferDataARB", glBufferData),
|
||||||
|
DynamicLib_Sym2("glBufferSubDataARB", glBufferSubData)
|
||||||
|
};
|
||||||
|
static const cc_string vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
|
||||||
|
cc_string extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
||||||
|
const GLubyte* ver = glGetString(GL_VERSION);
|
||||||
|
|
||||||
|
/* Version string is always: x.y. (and whatever afterwards) */
|
||||||
|
int major = ver[0] - '0', minor = ver[2] - '0';
|
||||||
|
|
||||||
|
/* Supported in core since 1.5 */
|
||||||
|
if (major > 1 || (major == 1 && minor >= 5)) {
|
||||||
|
GLContext_GetAll(coreVboFuncs, Array_Elems(coreVboFuncs));
|
||||||
|
} else if (String_CaselessContains(&extensions, &vboExt)) {
|
||||||
|
GLContext_GetAll(arbVboFuncs, Array_Elems(arbVboFuncs));
|
||||||
|
} else {
|
||||||
|
Logger_Abort("Only OpenGL 1.1 supported.\n\n" \
|
||||||
|
"Compile the game with CC_BUILD_GL11, or ask on the ClassiCube forums for it");
|
||||||
|
|
||||||
|
_glBindBuffer = fake_glBindBuffer; _glDeleteBuffers = fake_glDeleteBuffers;
|
||||||
|
_glGenBuffers = fake_glGenBuffers; _glBufferData = fake_glBufferData;
|
||||||
|
_glBufferSubData = fake_glBufferSubData;
|
||||||
|
}
|
||||||
|
customMipmapsLevels = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------------Drawing--------------------------------------------------------*
|
*----------------------------------------------------------Drawing--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
@ -1104,9 +1179,7 @@ void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CC_BUILD_GL11
|
#ifdef CC_BUILD_GL11
|
||||||
void Gfx_DrawIndexedTris_T2fC4b(int list, int ignored) { glCallList(list); }
|
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { glCallList(activeList); }
|
||||||
|
|
||||||
static void GL_CheckSupport(void) { MakeIndices(gl_indices, GFX_MAX_INDICES); }
|
|
||||||
#else
|
#else
|
||||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||||
cc_uint32 offset = startVertex * SIZEOF_VERTEX_TEXTURED;
|
cc_uint32 offset = startVertex * SIZEOF_VERTEX_TEXTURED;
|
||||||
@ -1115,77 +1188,6 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
|||||||
glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, (void*)(VB_PTR + offset + 16));
|
glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, (void*)(VB_PTR + offset + 16));
|
||||||
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR);
|
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, IB_PTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
|
||||||
*-------------------------------------------------------Compatibility-----------------------------------------------------*
|
|
||||||
*#########################################################################################################################*/
|
|
||||||
/* fake vertex buffer objects with client side pointers */
|
|
||||||
typedef struct fake_buffer { cc_uint8* data; } fake_buffer;
|
|
||||||
static fake_buffer* cur_ib;
|
|
||||||
static fake_buffer* cur_vb;
|
|
||||||
#define fake_GetBuffer(target) (target == _GL_ELEMENT_ARRAY_BUFFER ? &cur_ib : &cur_vb);
|
|
||||||
|
|
||||||
static void APIENTRY fake_glBindBuffer(GLenum target, GLuint src) {
|
|
||||||
fake_buffer** buffer = fake_GetBuffer(target);
|
|
||||||
*buffer = (fake_buffer*)src;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void APIENTRY fake_glDeleteBuffers(GLsizei n, const GLuint *buffers) {
|
|
||||||
Mem_Free((void*)buffers[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void APIENTRY fake_glGenBuffers(GLsizei n, GLuint *buffers) {
|
|
||||||
fake_buffer* buffer = (fake_buffer*)Mem_TryAlloc(1, sizeof(fake_buffer));
|
|
||||||
buffer->data = NULL;
|
|
||||||
buffers[0] = (GLuint)buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void APIENTRY fake_glBufferData(GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage) {
|
|
||||||
fake_buffer* buffer = *fake_GetBuffer(target);
|
|
||||||
Mem_Free(buffer->data);
|
|
||||||
|
|
||||||
buffer->data = Mem_TryAlloc(size, 1);
|
|
||||||
if (data) Mem_Copy(buffer->data, data, size);
|
|
||||||
}
|
|
||||||
static void APIENTRY fake_glBufferSubData(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data) {
|
|
||||||
fake_buffer* buffer = *fake_GetBuffer(target);
|
|
||||||
Mem_Copy(buffer->data, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GL_CheckSupport(void) {
|
|
||||||
static const struct DynamicLibSym coreVboFuncs[5] = {
|
|
||||||
DynamicLib_Sym2("glBindBuffer", glBindBuffer), DynamicLib_Sym2("glDeleteBuffers", glDeleteBuffers),
|
|
||||||
DynamicLib_Sym2("glGenBuffers", glGenBuffers), DynamicLib_Sym2("glBufferData", glBufferData),
|
|
||||||
DynamicLib_Sym2("glBufferSubData", glBufferSubData)
|
|
||||||
};
|
|
||||||
static const struct DynamicLibSym arbVboFuncs[5] = {
|
|
||||||
DynamicLib_Sym2("glBindBufferARB", glBindBuffer), DynamicLib_Sym2("glDeleteBuffersARB", glDeleteBuffers),
|
|
||||||
DynamicLib_Sym2("glGenBuffersARB", glGenBuffers), DynamicLib_Sym2("glBufferDataARB", glBufferData),
|
|
||||||
DynamicLib_Sym2("glBufferSubDataARB", glBufferSubData)
|
|
||||||
};
|
|
||||||
static const cc_string vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
|
|
||||||
cc_string extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
|
||||||
const GLubyte* ver = glGetString(GL_VERSION);
|
|
||||||
|
|
||||||
/* Version string is always: x.y. (and whatever afterwards) */
|
|
||||||
int major = ver[0] - '0', minor = ver[2] - '0';
|
|
||||||
|
|
||||||
/* Supported in core since 1.5 */
|
|
||||||
if (major > 1 || (major == 1 && minor >= 5)) {
|
|
||||||
GLContext_GetAll(coreVboFuncs, Array_Elems(coreVboFuncs));
|
|
||||||
} else if (String_CaselessContains(&extensions, &vboExt)) {
|
|
||||||
GLContext_GetAll(arbVboFuncs, Array_Elems(arbVboFuncs));
|
|
||||||
} else {
|
|
||||||
Logger_Abort("Only OpenGL 1.1 supported.\n\n" \
|
|
||||||
"Compile the game with CC_BUILD_GL11, or ask on the ClassiCube forums for it");
|
|
||||||
|
|
||||||
_glBindBuffer = fake_glBindBuffer; _glDeleteBuffers = fake_glDeleteBuffers;
|
|
||||||
_glGenBuffers = fake_glGenBuffers; _glBufferData = fake_glBufferData;
|
|
||||||
_glBufferSubData = fake_glBufferSubData;
|
|
||||||
}
|
|
||||||
customMipmapsLevels = true;
|
|
||||||
}
|
|
||||||
#endif /* !CC_BUILD_GL11 */
|
#endif /* !CC_BUILD_GL11 */
|
||||||
#endif /* !CC_BUILD_GLMODERN */
|
#endif /* !CC_BUILD_GLMODERN */
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,7 +95,7 @@ static void CheckWeather(double delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CC_BUILD_GL11
|
#ifdef CC_BUILD_GL11
|
||||||
#define DrawFace(face, ign) Gfx_DrawIndexedTris_T2fC4b(part.Vbs[face], 0);
|
#define DrawFace(face, ign) Gfx_BindVb(part.Vbs[face]); Gfx_DrawIndexedTris_T2fC4b(0, 0);
|
||||||
#define DrawFaces(f1, f2, ign) DrawFace(f1, ign); DrawFace(f2, ign);
|
#define DrawFaces(f1, f2, ign) DrawFace(f1, ign); DrawFace(f2, ign);
|
||||||
#else
|
#else
|
||||||
#define DrawFace(face, offset) Gfx_DrawIndexedTris_T2fC4b(part.Counts[face], offset);
|
#define DrawFace(face, offset) Gfx_DrawIndexedTris_T2fC4b(part.Counts[face], offset);
|
||||||
@ -132,7 +132,7 @@ static void RenderNormalBatch(int batch) {
|
|||||||
hasNormParts[batch] = true;
|
hasNormParts[batch] = true;
|
||||||
|
|
||||||
#ifndef CC_BUILD_GL11
|
#ifndef CC_BUILD_GL11
|
||||||
Gfx_BindVb_T2fC4b(info->Vb);
|
Gfx_BindVb_Textured(info->Vb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
offset = part.Offset + part.SpriteCount;
|
offset = part.Offset + part.SpriteCount;
|
||||||
@ -236,7 +236,7 @@ static void RenderTranslucentBatch(int batch) {
|
|||||||
hasTranParts[batch] = true;
|
hasTranParts[batch] = true;
|
||||||
|
|
||||||
#ifndef CC_BUILD_GL11
|
#ifndef CC_BUILD_GL11
|
||||||
Gfx_BindVb_T2fC4b(info->Vb);
|
Gfx_BindVb_Textured(info->Vb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
offset = part.Offset;
|
offset = part.Offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user