Migrate GL setup and error handling code

This commit is contained in:
Kovid Goyal
2017-09-10 15:05:39 +05:30
parent a1c9c90fc8
commit d3f2620caf
2 changed files with 81 additions and 32 deletions

View File

@@ -49,12 +49,6 @@ static bool _enable_error_checking = 1;
#define CHECK_ERROR if (_enable_error_checking) { SET_GL_ERR; if (PyErr_Occurred()) return NULL; }
static PyObject*
enable_automatic_error_checking(PyObject UNUSED *self, PyObject *val) {
_enable_error_checking = PyObject_IsTrue(val) ? true : false;
Py_RETURN_NONE;
}
static PyObject*
Viewport(PyObject UNUSED *self, PyObject *args) {
unsigned int x, y, w, h;
@@ -165,25 +159,6 @@ CheckError(PyObject UNUSED *self) {
CHECK_ERROR; Py_RETURN_NONE;
}
static PyObject*
_glewInit(PyObject UNUSED *self) {
#ifndef __APPLE__
GLenum err = glewInit();
if (err != GLEW_OK) {
PyErr_Format(PyExc_RuntimeError, "GLEW init failed: %s", glewGetErrorString(err));
return NULL;
}
#define ARB_TEST(name) \
if (!GLEW_ARB_##name) { \
PyErr_Format(PyExc_RuntimeError, "The OpenGL driver on this system is missing the required extension: ARB_%s", #name); \
return NULL; \
}
ARB_TEST(texture_storage);
#undef ARB_TEST
#endif
Py_RETURN_NONE;
}
static PyObject*
GetString(PyObject UNUSED *self, PyObject *val) {
const unsigned char *ans = glGetString(PyLong_AsUnsignedLong(val));
@@ -805,10 +780,8 @@ check_for_extensions(PyObject UNUSED *self) {
}
static PyMethodDef module_methods[] = {
{"enable_automatic_opengl_error_checking", (PyCFunction)enable_automatic_error_checking, METH_O, NULL},
{"copy_image_sub_data", (PyCFunction)copy_image_sub_data, METH_VARARGS, NULL},
{"replace_or_create_buffer", (PyCFunction)replace_or_create_buffer, METH_VARARGS, NULL},
{"glewInit", (PyCFunction)_glewInit, METH_NOARGS, NULL},
{"check_for_extensions", (PyCFunction)check_for_extensions, METH_NOARGS, NULL},
{"get_uniform_block_size", (PyCFunction)get_uniform_block_size, METH_VARARGS, NULL},
{"get_uniform_block_offsets", (PyCFunction)get_uniform_block_offsets, METH_VARARGS, NULL},