Skip to content

Commit e51dbca

Browse files
committed
Update gl_get_proc function
- Import ctypes directly in display.c - Don't use SDL_GetError when SDL_GL_GetProcAddress returns NULL
1 parent bd98dae commit e51dbca

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

src_c/display.c

+34-19
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ pg_message_box(PyObject *self, PyObject *arg, PyObject *kwargs)
29382938
return NULL;
29392939
}
29402940

2941-
static PyObject *pg_gl_proc_from_address = NULL;
2941+
static PyObject *ctypes_functype = NULL;
29422942

29432943
static PyObject *
29442944
pg_gl_get_proc(PyObject *self, PyObject *arg)
@@ -2958,17 +2958,45 @@ pg_gl_get_proc(PyObject *self, PyObject *arg)
29582958
#endif
29592959
proc_addr = SDL_GL_GetProcAddress(proc_name);
29602960
if (!proc_addr) {
2961-
return RAISE(pgExc_SDLError, SDL_GetError());
2961+
PyErr_Format(pgExc_SDLError, "Unable to get OpenGL function '%s'",
2962+
proc_name);
2963+
return NULL;
29622964
}
29632965
PyObject *proc_addr_obj = PyLong_FromVoidPtr(proc_addr);
29642966
if (!proc_addr_obj) {
29652967
return NULL;
29662968
}
2967-
if (!pg_gl_proc_from_address) {
2968-
return RAISE(PyExc_TypeError, "'_proc_from_address' object is NULL");
2969+
2970+
// load ctypes_functype if it's NULL
2971+
if (!ctypes_functype) {
2972+
PyObject *ctypes_module = PyImport_ImportModule("ctypes");
2973+
if (!ctypes_module) {
2974+
return NULL;
2975+
}
2976+
2977+
PyObject *ctypes_functype_factory;
2978+
#if defined(_WIN32)
2979+
// gl proc need to be called with WINFUNCTYPE (stdcall) on win32
2980+
ctypes_functype_factory =
2981+
PyObject_GetAttrString(ctypes_module, "WINFUNCTYPE");
2982+
#else
2983+
ctypes_functype_factory =
2984+
PyObject_GetAttrString(ctypes_module, "CFUNCTYPE");
2985+
#endif
2986+
Py_DECREF(ctypes_module);
2987+
if (!ctypes_functype_factory) {
2988+
return NULL;
2989+
}
2990+
2991+
ctypes_functype =
2992+
PyObject_CallOneArg(ctypes_functype_factory, Py_None);
2993+
Py_DECREF(ctypes_functype_factory);
2994+
if (!ctypes_functype) {
2995+
return NULL;
2996+
}
29692997
}
2970-
PyObject *retv =
2971-
PyObject_CallFunction(pg_gl_proc_from_address, "(O)", proc_addr_obj);
2998+
2999+
PyObject *retv = PyObject_CallOneArg(ctypes_functype, proc_addr_obj);
29723000
Py_DECREF(proc_addr_obj);
29733001
return retv;
29743002
}
@@ -3101,19 +3129,6 @@ MODINIT_DEFINE(display)
31013129
return NULL;
31023130
}
31033131

3104-
/* load _ffi module for display.get_gl_proc function */
3105-
PyObject *pg_ffi_module = PyImport_ImportModule("pygame._ffi");
3106-
if (!pg_ffi_module) {
3107-
return NULL;
3108-
}
3109-
3110-
pg_gl_proc_from_address =
3111-
PyObject_GetAttrString(pg_ffi_module, "_gl_proc_from_address");
3112-
if (!pg_gl_proc_from_address) {
3113-
return NULL;
3114-
}
3115-
Py_DECREF(pg_ffi_module);
3116-
31173132
/* create the module */
31183133
module = PyModule_Create(&_module);
31193134
if (module == NULL) {

src_py/_ffi.py

-9
This file was deleted.

src_py/meson.build

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ python_sources = files(
44
'_camera_opencv.py',
55
'_data_classes.py',
66
'_debug.py',
7-
'_ffi.py',
87
'_sprite.py',
98
'camera.py',
109
'colordict.py',

0 commit comments

Comments
 (0)