From 356917292d17b25d001760ed88a162a8c7d8a274 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 18 Sep 2011 23:32:18 +0000 Subject: [PATCH] osx: link with the proper OpenGL libraries on OS X. --- configure.ac | 26 ++++++++++++-------------- src/debug/quad.cpp | 8 ++++---- src/gradient.cpp | 8 ++++---- src/lolgl.h | 14 +++++++++++--- src/scene.cpp | 12 ++++++------ src/video.cpp | 12 +++++++----- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/configure.ac b/configure.ac index 931fbb29..85d61ee9 100644 --- a/configure.ac +++ b/configure.ac @@ -104,6 +104,18 @@ AC_CHECK_LIB(sysmodule_stub, cellSysmoduleLoadModule, AM_CONDITIONAL(USE_MAKE_FSELF, test "${MAKE_FSELF}" != "no") +LIBS_save="$LIBS" +LIBS="$LIBS -Wl,-framework -Wl,OpenGL" +AC_MSG_CHECKING(for -framework OpenGL) +AC_TRY_LINK([], [], + [ac_cv_my_have_cocoa="yes" + AC_MSG_RESULT(yes) + GL_LIBS="${GL_LIBS} -framework OpenGL" + CXXFLAGS="${CXXFLAGS} -ObjC++"], + [AC_MSG_RESULT(no)]) +LIBS="$LIBS_save" + + dnl Which version of OpenGL to use? ac_cv_my_have_gl="no" PKG_CHECK_MODULES(GLES2, glesv2, @@ -232,20 +244,6 @@ AM_CONDITIONAL(USE_SDL_MIXER, test "${ac_cv_my_have_sdl_mixer}" = "yes") AM_CONDITIONAL(USE_SDL_IMAGE, test "${ac_cv_my_have_sdl_image}" = "yes") -dnl Use Cocoa? -ac_cv_my_have_cocoa="no" -LIBS_save="$LIBS" -LIBS="$LIBS -Wl,-framework -Wl,Cocoa" -AC_MSG_CHECKING(for -framework Cocoa) -AC_TRY_LINK([], [], - [ac_cv_my_have_cocoa="yes" - AC_MSG_RESULT(yes) - CXXFLAGS="${CXXFLAGS} -ObjC++"], - [AC_MSG_RESULT(no)]) -LIBS="$LIBS_save" -AM_CONDITIONAL(USE_COCOA, test "${ac_cv_my_have_cocoa}" != "no") - - dnl Use EGL? ac_cv_my_have_egl="no" PKG_CHECK_MODULES(EGL, egl, [ac_cv_my_have_egl="yes"], [:]) diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index 993e6423..8e28becd 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -153,7 +153,7 @@ void DebugQuad::TickDraw(float deltams) if (!data->initialised && !IsDestroying()) { -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ glGenVertexArrays(NUM_ARRAYS, data->array); #endif glGenBuffers(NUM_BUFFERS, data->buffer); @@ -183,7 +183,7 @@ void DebugQuad::TickDraw(float deltams) } else if (data->initialised && IsDestroying()) { -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ glDeleteVertexArrays(NUM_ARRAYS, data->array); #endif glDeleteBuffers(NUM_BUFFERS, data->buffer); @@ -915,7 +915,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors xored with an * animated distorted checkerboard. */ -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ if (!shader[0]) { shader[0] = Shader::Create( @@ -985,7 +985,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors xored with an * animated distorted checkerboard. */ -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ if (!shader[0]) { shader[0] = Shader::Create( diff --git a/src/gradient.cpp b/src/gradient.cpp index 8440ac31..c9b05ff4 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -33,7 +33,7 @@ class GradientData private: Shader *shader; GLuint bufs[2]; -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ GLuint vaos[1]; #endif }; @@ -154,7 +154,7 @@ void Gradient::TickDraw(float deltams) #endif #if !defined __CELLOS_LV2__ glGenBuffers(2, data->bufs); -# if defined HAVE_GL_2X +# if defined HAVE_GL_2X && !defined __APPLE__ glGenVertexArrays(1, data->vaos); # endif #endif @@ -195,7 +195,7 @@ void Gradient::TickDraw(float deltams) /* Bind vertex, color and texture coordinate buffers */ #if !defined __CELLOS_LV2__ -# if defined HAVE_GL_2X +# if defined HAVE_GL_2X && !defined __APPLE__ glBindVertexArray(data->vaos[0]); # endif glEnableVertexAttribArray(attr_pos); @@ -222,7 +222,7 @@ void Gradient::TickDraw(float deltams) glDrawArrays(GL_TRIANGLES, 0, 6); #if !defined __CELLOS_LV2__ -# if defined HAVE_GL_2X +# if defined HAVE_GL_2X && !defined __APPLE__ glBindVertexArray(0); # endif glDisableVertexAttribArray(attr_pos); diff --git a/src/lolgl.h b/src/lolgl.h index 8902ae62..31794a16 100644 --- a/src/lolgl.h +++ b/src/lolgl.h @@ -23,12 +23,20 @@ # undef HAVE_GLES_2X #endif -/* Include GL */ -#if defined USE_GLEW +/* Include GL development headers. + * Do not include glew.h on OS X, because the version shipped with Fink + * links with X11 whereas we want the system’s Cocoa-friendly GL libs. */ +#if defined USE_GLEW && !defined __APPLE__ # include #elif defined HAVE_GL_2X -# if defined __APPLE__ && defined __MACH__ +# if defined __APPLE__ && defined __MACH__ && defined __arm__ +# include +# elif defined __APPLE__ && defined __MACH__ +# define MACOS_OPENGL +# define GL_GLEXT_PROTOTYPES +# include # include +# include # else # define GL_GLEXT_PROTOTYPES # include diff --git a/src/scene.cpp b/src/scene.cpp index 77674db1..dec0c722 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -59,7 +59,7 @@ private: int ntiles; float angle; -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ GLuint vao; #endif GLuint *bufs; @@ -84,7 +84,7 @@ Scene::Scene(float angle) data->bufs = 0; data->nbufs = 0; -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glGenVertexArrays(1, &data->vao); #endif } @@ -96,7 +96,7 @@ Scene::~Scene() /* XXX: The test is necessary because of a crash with PSGL. */ if (data->nbufs > 0) glDeleteBuffers(data->nbufs, data->bufs); -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glDeleteVertexArrays(1, &data->vao); #endif free(data->bufs); @@ -320,7 +320,7 @@ void Scene::Render() // XXX: rename to Blit() glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GEQUAL, 0.01f); #endif @@ -359,7 +359,7 @@ void Scene::Render() // XXX: rename to Blit() data->tiles[i].tileset->Bind(); /* Bind vertex, color and texture coordinate buffers */ -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glBindVertexArray(data->vao); #endif #if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. @@ -386,7 +386,7 @@ void Scene::Render() // XXX: rename to Blit() /* Draw arrays */ glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glBindVertexArray(0); #endif #if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. diff --git a/src/video.cpp b/src/video.cpp index 6efcf506..8cb1b71c 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -33,7 +33,7 @@ class VideoData private: static mat4 proj_matrix, view_matrix; -#if defined __ANDROID__ || defined __CELLOS_LV2__ +#if defined __ANDROID__ || defined __CELLOS_LV2__ || defined __APPLE__ static ivec2 saved_viewport; #endif }; @@ -41,7 +41,7 @@ private: mat4 VideoData::proj_matrix; mat4 VideoData::view_matrix; -#if defined __ANDROID__ || defined __CELLOS_LV2__ +#if defined __ANDROID__ || defined __CELLOS_LV2__ || defined __APPLE__ ivec2 VideoData::saved_viewport = 0; #endif @@ -51,7 +51,7 @@ ivec2 VideoData::saved_viewport = 0; void Video::Setup(ivec2 size) { -#if defined USE_GLEW +#if defined USE_GLEW && !defined __APPLE__ /* Initialise GLEW if necessary */ GLenum glerr = glewInit(); if (glerr != GLEW_OK) @@ -64,14 +64,14 @@ void Video::Setup(ivec2 size) /* Initialise OpenGL */ glViewport(0, 0, size.x, size.y); -#if defined __ANDROID__ || defined __CELLOS_LV2__ +#if defined __ANDROID__ || defined __CELLOS_LV2__ || defined __APPLE__ VideoData::saved_viewport = size; #endif glClearColor(0.1f, 0.2f, 0.3f, 0.0f); glClearDepth(1.0); -#if defined HAVE_GL_2X +#if defined HAVE_GL_2X && !defined __APPLE__ glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); #endif @@ -183,6 +183,8 @@ ivec2 Video::GetSize() #elif defined __CELLOS_LV2__ // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions return VideoData::saved_viewport; +#elif defined __APPLE__ + return VideoData::saved_viewport; #else GLint v[4]; glGetIntegerv(GL_VIEWPORT, v);