Do not use GLEW on OS X

This commit is contained in:
Kovid Goyal 2017-01-12 00:50:44 +05:30
parent 063ec7dc02
commit fea0862a35
2 changed files with 34 additions and 5 deletions

View File

@ -6,13 +6,26 @@
*/
#include "data-types.h"
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#else
#include <GL/glew.h>
#endif
#define STRINGIFY(x) #x
#define METH(name, argtype) {STRINGIFY(gl##name), (PyCFunction)name, argtype, NULL},
static int _enable_error_checking = 1;
#ifndef GL_STACK_UNDERFLOW
#define GL_STACK_UNDERFLOW 0x0504
#endif
#ifndef GL_STACK_OVERFLOW
#define GL_STACK_OVERFLOW 0x0503
#endif
#define SET_GL_ERR \
switch(glGetError()) { \
case GL_NO_ERROR: break; \
@ -122,6 +135,7 @@ CheckError(PyObject UNUSED *self) {
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));
@ -131,6 +145,7 @@ _glewInit(PyObject UNUSED *self) {
PyErr_SetString(PyExc_RuntimeError, "OpenGL is missing the required ARB_texture_storage extension");
return NULL;
}
#endif
Py_RETURN_NONE;
}
@ -432,13 +447,19 @@ TexStorage3D(PyObject UNUSED *self, PyObject *args) {
}
static PyObject*
#if defined(__APPLE__) && !defined(glCopyImageSubData)
CopyImageSubData(PyObject UNUSED *self, UNUSED PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "OpenGL is missing the required ARB_copy_image extension");
return NULL;
}
#else
CopyImageSubData(PyObject UNUSED *self, PyObject *args) {
int src_target, src_level, srcX, srcY, srcZ, dest_target, dest_level, destX, destY, destZ;
unsigned int src, dest, width, height, depth;
if(!GLEW_ARB_copy_image) {
PyErr_SetString(PyExc_RuntimeError, "OpenGL is missing the required ARB_copy_image extension");
return NULL;
}
int src_target, src_level, srcX, srcY, srcZ, dest_target, dest_level, destX, destY, destZ;
unsigned int src, dest, width, height, depth;
if (!PyArg_ParseTuple(args, "IiiiiiIiiiiiIII",
&src, &src_target, &src_level, &srcX, &srcY, &srcZ,
&dest, &dest_target, &dest_level, &destX, &destY, &destZ,
@ -450,6 +471,7 @@ CopyImageSubData(PyObject UNUSED *self, PyObject *args) {
CHECK_ERROR;
Py_RETURN_NONE;
}
#endif
static PyObject*
copy_image_sub_data(PyObject UNUSED *self, PyObject *args) {
@ -511,7 +533,11 @@ NamedBufferData(PyObject UNUSED *self, PyObject *args) {
if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; }
Py_BEGIN_ALLOW_THREADS;
#ifdef glNamedBufferData
#ifdef __APPLE__
if(false) {
#else
if(GLEW_VERSION_4_5) {
#endif
glNamedBufferData(target, size, data, usage);
} else {
glBindBuffer(GL_TEXTURE_BUFFER, target); glBufferData(GL_TEXTURE_BUFFER, size, data, usage); glBindBuffer(GL_TEXTURE_BUFFER, 0);

View File

@ -90,7 +90,7 @@ def init_env(debug=False, asan=False):
ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
cflags.append('-pthread')
if not is_travis and subprocess.Popen([PKGCONFIG, 'glew', '--atleast-version=2']).wait() != 0:
if not is_travis and not isosx and subprocess.Popen([PKGCONFIG, 'glew', '--atleast-version=2']).wait() != 0:
try:
ver = subprocess.check_output([PKGCONFIG, 'glew', '--modversion']).decode('utf-8').strip()
major = int(re.match(r'\d+', ver).group())
@ -99,6 +99,7 @@ def init_env(debug=False, asan=False):
major = 0
if major < 2:
raise SystemExit('glew >= 2.0.0 is required, found version: ' + ver)
if not isosx:
cflags.extend(pkg_config('glew', '--cflags-only-I'))
if isosx:
font_libs = ['-framework', 'CoreText', '-framework', 'CoreGraphics']
@ -110,10 +111,12 @@ def init_env(debug=False, asan=False):
pylib = get_python_flags(cflags)
if isosx:
glfw_ldflags = pkg_config('--libs', '--static', 'glfw3') + ['-framework', 'OpenGL']
glew_libs = []
else:
glfw_ldflags = pkg_config('glfw3', '--libs')
glew_libs = pkg_config('glew', '--libs')
ldpaths = pylib + \
pkg_config('glew', '--libs') + font_libs + glfw_ldflags
glew_libs + font_libs + glfw_ldflags
try:
os.mkdir(build_dir)