Use simpler GLContext_GetAll for loading OpenGL 1.5/1.2 functions

This commit is contained in:
UnknownShadow200 2020-07-17 17:18:51 +10:00
parent 188ea885ee
commit 79a22ff18c
3 changed files with 26 additions and 13 deletions

View File

@ -2103,6 +2103,16 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
}
static void GL_CheckSupport(void) {
static const struct DynamicLibSym coreVboFuncs[5] = {
{ "glBindBuffer", (void**)&_glBindBuffer }, { "glDeleteBuffers", (void**)&_glDeleteBuffers },
{ "glGenBuffers", (void**)&_glGenBuffers }, { "glBufferData", (void**)&_glBufferData },
{ "glBufferSubData", (void**)&_glBufferSubData }
};
static const struct DynamicLibSym arbVboFuncs[5] = {
{ "glBindBufferARB", (void**)&_glBindBuffer }, { "glDeleteBuffersARB", (void**)&_glDeleteBuffers },
{ "glGenBuffersARB", (void**)&_glGenBuffers }, { "glBufferDataARB", (void**)&_glBufferData },
{ "glBufferSubDataARB", (void**)&_glBufferSubData }
};
static const String vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
String extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
const GLubyte* ver = glGetString(GL_VERSION);
@ -2112,17 +2122,9 @@ static void GL_CheckSupport(void) {
/* Supported in core since 1.5 */
if (major > 1 || (major == 1 && minor >= 5)) {
_glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBuffer");
_glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffers");
_glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffers");
_glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferData");
_glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubData");
GLContext_GetAll(coreVboFuncs, Array_Elems(coreVboFuncs));
} else if (String_CaselessContains(&extensions, &vboExt)) {
_glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBufferARB");
_glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffersARB");
_glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffersARB");
_glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferDataARB");
_glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubDataARB");
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");

View File

@ -3887,6 +3887,15 @@ void Window_DisableRawMouse(void) { DefaultDisableRawMouse(); }
#ifdef CC_BUILD_GL
/* OpenGL contexts are heavily tied to the window, so for simplicitly are also included here */
/* SDL and EGL are platform agnostic, other OpenGL context backends are tied to one windowing system. */
#define GLCONTEXT_DEFAULT_DEPTH 24
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
int i;
for (i = 0; i < count; i++) {
*syms[i].symAddr = GLContext_GetAddress(syms[i].name);
}
}
/*########################################################################################################################*
*-------------------------------------------------------SDL OpenGL--------------------------------------------------------*

View File

@ -31,6 +31,7 @@
OTHER DEALINGS IN THE SOFTWARE.
*/
struct DynamicLibSym;
/* The states the window can be in. */
enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_MINIMISED, WINDOW_STATE_FULLSCREEN };
/* Can't name these Window/Display, because it conflicts with X11's Window/Display typedef */
@ -161,12 +162,13 @@ cc_bool GLContext_TryRestore(void);
/* NOTE: This also unattaches the OpenGL context from the window. */
void GLContext_Free(void);
#define GLCONTEXT_DEFAULT_DEPTH 24
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
/* Returns the address of a function pointer for the given OpenGL function. */
/* NOTE: The implementation may still return an address for unsupported functions. */
/* NOTE: The implementation may still return an address for unsupported functions! */
/* You MUST check the OpenGL version and/or GL_EXTENSIONS string for actual support! */
void* GLContext_GetAddress(const char* function);
/* Loads all OpenGL function pointers using GLContext_GetAddress in the given list */
void GLContext_GetAll(const struct DynamicLibSym* syms, int count);
/* Swaps the front and back buffer, displaying the back buffer on screen. */
cc_bool GLContext_SwapBuffers(void);
/* Sets whether synchronisation with the monitor is enabled. */