summary refs log tree commit diff
path: root/pkgs/development/libraries/mesa-darwin
diff options
context:
space:
mode:
authorCharles Strahan <charles.c.strahan@gmail.com>2014-08-12 20:40:57 -0400
committerCharles Strahan <charles.c.strahan@gmail.com>2014-08-12 20:40:57 -0400
commit5ea8497933da0dbee5fa5a31c97843e2c6baac17 (patch)
tree6fd331d811fab9c904b1f724692a6c24d633fe1d /pkgs/development/libraries/mesa-darwin
parent48c5574f5a5caa50358ba8e4837fcadce9f1b375 (diff)
downloadnixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar.gz
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar.bz2
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar.lz
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar.xz
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.tar.zst
nixlib-5ea8497933da0dbee5fa5a31c97843e2c6baac17.zip
get xorg/x11 working on Darwin
Diffstat (limited to 'pkgs/development/libraries/mesa-darwin')
-rw-r--r--pkgs/development/libraries/mesa-darwin/default.nix62
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0003-mesa-fix-per-level-max-texture-size-error-checking.patch147
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0008-glsl-initialise-const-force-glsl-extension-warning-i.patch33
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0009-mesa-test-for-GL_EXT_framebuffer_sRGB-in-glPopAttrib.patch28
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0011-Apple-glFlush-is-not-needed-with-CGLFlushDrawable.patch29
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0012-glapi-Avoid-heap-corruption-in-_glapi_table.patch28
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/0013-darwin-Fix-test-for-kCGLPFAOpenGLProfile-support-at-.patch40
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/1001-appleglx-Improve-error-reporting-if-CGLChoosePixelFo.patch30
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/1002-darwin-Write-errors-in-choosing-the-pixel-format-to-.patch55
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/1003-darwin-Guard-Core-Profile-usage-behind-a-testing-env.patch69
-rw-r--r--pkgs/development/libraries/mesa-darwin/patches/patch-src-mapi-vgapi-Makefile.diff11
11 files changed, 532 insertions, 0 deletions
diff --git a/pkgs/development/libraries/mesa-darwin/default.nix b/pkgs/development/libraries/mesa-darwin/default.nix
new file mode 100644
index 000000000000..98936904be59
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/default.nix
@@ -0,0 +1,62 @@
+{ stdenv, stdenvAdapters, gccApple, fetchurl, pkgconfig, intltool, flex, bison
+, python, libxml2Python, file, expat, makedepend, xorg, llvm, libffi, libvdpau
+, enableTextureFloats ? false # Texture floats are patented, see docs/patents.txt
+, enableExtraFeatures ? false # not maintained
+}:
+
+let
+  version = "8.0.5";
+  self = stdenv.mkDerivation rec {
+    name = "mesa-${version}";
+
+    src =  fetchurl {
+      url = "ftp://ftp.freedesktop.org/pub/mesa/older-versions/8.x/${version}/MesaLib-${version}.tar.bz2";
+      sha256 = "0pjs8x51c0i6mawgd4w03lxpyx5fnx7rc8plr8jfsscf9yiqs6si";
+    };
+
+    nativeBuildInputs = [ pkgconfig python makedepend flex bison ];
+
+    buildInputs = with xorg; [
+      glproto dri2proto libXfixes libXi libXmu
+      intltool expat libxml2Python llvm
+      presentproto
+      libX11 libXext libxcb libXt libxshmfence
+      libffi libvdpau
+    ];
+
+    postUnpack = ''
+      ln -s darwin $sourceRoot/configs/current
+    '';
+
+    patches = [
+      ./patches/0003-mesa-fix-per-level-max-texture-size-error-checking.patch
+      ./patches/0008-glsl-initialise-const-force-glsl-extension-warning-i.patch
+      ./patches/0009-mesa-test-for-GL_EXT_framebuffer_sRGB-in-glPopAttrib.patch
+      ./patches/0011-Apple-glFlush-is-not-needed-with-CGLFlushDrawable.patch
+      ./patches/0012-glapi-Avoid-heap-corruption-in-_glapi_table.patch
+      ./patches/0013-darwin-Fix-test-for-kCGLPFAOpenGLProfile-support-at-.patch
+      ./patches/1001-appleglx-Improve-error-reporting-if-CGLChoosePixelFo.patch
+      ./patches/1002-darwin-Write-errors-in-choosing-the-pixel-format-to-.patch
+      ./patches/1003-darwin-Guard-Core-Profile-usage-behind-a-testing-env.patch
+      ./patches/patch-src-mapi-vgapi-Makefile.diff
+    ];
+
+    postPatch = "patchShebangs .";
+
+    configurePhase = ":";
+
+    makeFlags = "INSTALL_DIR=\${out} CC=cc CXX=c++";
+
+    enableParallelBuilding = true;
+
+    passthru = { inherit version; };
+
+    meta = {
+      description = "An open source implementation of OpenGL";
+      homepage = http://www.mesa3d.org/;
+      license = "bsd";
+      platforms = stdenv.lib.platforms.darwin;
+      maintainers = with stdenv.lib.maintainers; [ cstrahan ];
+    };
+  };
+in self // { driverLink = self; }
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0003-mesa-fix-per-level-max-texture-size-error-checking.patch b/pkgs/development/libraries/mesa-darwin/patches/0003-mesa-fix-per-level-max-texture-size-error-checking.patch
new file mode 100644
index 000000000000..5466ffc90858
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0003-mesa-fix-per-level-max-texture-size-error-checking.patch
@@ -0,0 +1,147 @@
+From 9cf1afbf8ae87ddbb29b24a0f9f2724e9e2935c1 Mon Sep 17 00:00:00 2001
+From: Brian Paul <brianp@vmware.com>
+Date: Tue, 4 Sep 2012 20:17:15 -0600
+Subject: [PATCH 03/13] mesa: fix per-level max texture size error checking
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This is a long-standing omission in Mesa's texture image size checking.
+We need to take the mipmap level into consideration when checking if the
+width, height and depth are too large.
+
+Fixes the new piglit max-texture-size-level test.
+Thanks to Stéphane Marchesin for finding this problem.
+
+Note: This is a candidate for the stable branches.
+
+Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
+(cherry picked from commit 771e7b6d884bb4294a89f276a904d90b28efb90a)
+---
+ src/mesa/main/teximage.c | 36 +++++++++++++++++++++---------------
+ 1 file changed, 21 insertions(+), 15 deletions(-)
+
+diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
+index 3aecc0f..ed22fa9 100644
+--- a/src/mesa/main/teximage.c
++++ b/src/mesa/main/teximage.c
+@@ -1251,11 +1251,12 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+ 
+    switch (target) {
+    case GL_PROXY_TEXTURE_1D:
+-      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+-      if (width < 2 * border || width > 2 * border + maxSize)
+-         return GL_FALSE;
+       if (level >= ctx->Const.MaxTextureLevels)
+          return GL_FALSE;
++      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); /* level zero size */
++      maxSize >>= level;  /* level size */
++      if (width < 2 * border || width > 2 * border + maxSize)
++         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+@@ -1263,13 +1264,14 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_2D:
++      if (level >= ctx->Const.MaxTextureLevels)
++         return GL_FALSE;
+       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
++      maxSize >>= level;
+       if (width < 2 * border || width > 2 * border + maxSize)
+          return GL_FALSE;
+       if (height < 2 * border || height > 2 * border + maxSize)
+          return GL_FALSE;
+-      if (level >= ctx->Const.MaxTextureLevels)
+-         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+@@ -1279,15 +1281,16 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_3D:
++      if (level >= ctx->Const.Max3DTextureLevels)
++         return GL_FALSE;
+       maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
++      maxSize >>= level;
+       if (width < 2 * border || width > 2 * border + maxSize)
+          return GL_FALSE;
+       if (height < 2 * border || height > 2 * border + maxSize)
+          return GL_FALSE;
+       if (depth < 2 * border || depth > 2 * border + maxSize)
+          return GL_FALSE;
+-      if (level >= ctx->Const.Max3DTextureLevels)
+-         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+@@ -1299,23 +1302,24 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_RECTANGLE_NV:
++      if (level != 0)
++         return GL_FALSE;
+       maxSize = ctx->Const.MaxTextureRectSize;
+       if (width < 0 || width > maxSize)
+          return GL_FALSE;
+       if (height < 0 || height > maxSize)
+          return GL_FALSE;
+-      if (level != 0)
+-         return GL_FALSE;
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
++      if (level >= ctx->Const.MaxCubeTextureLevels)
++         return GL_FALSE;
+       maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
++      maxSize >>= level;
+       if (width < 2 * border || width > 2 * border + maxSize)
+          return GL_FALSE;
+       if (height < 2 * border || height > 2 * border + maxSize)
+          return GL_FALSE;
+-      if (level >= ctx->Const.MaxCubeTextureLevels)
+-         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+@@ -1325,13 +1329,14 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
++      if (level >= ctx->Const.MaxTextureLevels)
++         return GL_FALSE;
+       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
++      maxSize >>= level;
+       if (width < 2 * border || width > 2 * border + maxSize)
+          return GL_FALSE;
+       if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
+          return GL_FALSE;
+-      if (level >= ctx->Const.MaxTextureLevels)
+-         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+@@ -1339,15 +1344,16 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+       return GL_TRUE;
+ 
+    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
++      if (level >= ctx->Const.MaxTextureLevels)
++         return GL_FALSE;
+       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
++      maxSize >>= level;
+       if (width < 2 * border || width > 2 * border + maxSize)
+          return GL_FALSE;
+       if (height < 2 * border || height > 2 * border + maxSize)
+          return GL_FALSE;
+       if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
+          return GL_FALSE;
+-      if (level >= ctx->Const.MaxTextureLevels)
+-         return GL_FALSE;
+       if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+          if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+             return GL_FALSE;
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0008-glsl-initialise-const-force-glsl-extension-warning-i.patch b/pkgs/development/libraries/mesa-darwin/patches/0008-glsl-initialise-const-force-glsl-extension-warning-i.patch
new file mode 100644
index 000000000000..ff933b2ec284
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0008-glsl-initialise-const-force-glsl-extension-warning-i.patch
@@ -0,0 +1,33 @@
+From db8cb2250335a93cad6e877e634116e5cd6b42fc Mon Sep 17 00:00:00 2001
+From: Dave Airlie <airlied@redhat.com>
+Date: Tue, 13 Mar 2012 14:53:25 +0000
+Subject: [PATCH 08/13] glsl: initialise const force glsl extension warning in
+ fake ctx
+
+valgrind complained about an uninitialised value being used in
+glsl_parser_extras.cpp, and this was the one it was giving out about.
+
+Just initialise the value in the fakectx.
+
+Signed-off-by: Dave Airlie <airlied@redhat.com>
+Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48057
+(cherry picked from commit b78a77f979b21a84aecb6fa4f19a2ed51a48c306)
+---
+ src/glsl/builtins/tools/generate_builtins.py | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
+index 72d12bb..bd15c4d 100755
+--- a/src/glsl/builtins/tools/generate_builtins.py
++++ b/src/glsl/builtins/tools/generate_builtins.py
+@@ -156,6 +156,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne
+    fakeCtx.API = API_OPENGL;
+    fakeCtx.Const.GLSLVersion = 130;
+    fakeCtx.Extensions.ARB_ES2_compatibility = true;
++   fakeCtx.Const.ForceGLSLExtensionsWarn = false;
+    gl_shader *sh = _mesa_new_shader(NULL, 0, target);
+    struct _mesa_glsl_parse_state *st =
+       new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh);
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0009-mesa-test-for-GL_EXT_framebuffer_sRGB-in-glPopAttrib.patch b/pkgs/development/libraries/mesa-darwin/patches/0009-mesa-test-for-GL_EXT_framebuffer_sRGB-in-glPopAttrib.patch
new file mode 100644
index 000000000000..919443045e46
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0009-mesa-test-for-GL_EXT_framebuffer_sRGB-in-glPopAttrib.patch
@@ -0,0 +1,28 @@
+From 2286bd68a832a4d4908d50e1a4496853e1f3305a Mon Sep 17 00:00:00 2001
+From: Brian Paul <brianp@vmware.com>
+Date: Mon, 27 Aug 2012 21:52:07 -0600
+Subject: [PATCH 09/13] mesa: test for GL_EXT_framebuffer_sRGB in glPopAttrib()
+
+To avoid spurious GL_INVALID_ENUM errors if the extension isn't supported.
+(cherry picked from commit 1aee8803f83f7ae24d9c2150c70afff2b1ee4c2f)
+---
+ src/mesa/main/attrib.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
+index 225ac89..cc384c7 100644
+--- a/src/mesa/main/attrib.c
++++ b/src/mesa/main/attrib.c
+@@ -993,7 +993,8 @@ _mesa_PopAttrib(void)
+                _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB, color->ClampReadColor);
+ 
+                /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
+-               _mesa_set_enable(ctx, GL_FRAMEBUFFER_SRGB, color->sRGBEnabled);
++               if (ctx->Extensions.EXT_framebuffer_sRGB)
++                  _mesa_set_enable(ctx, GL_FRAMEBUFFER_SRGB, color->sRGBEnabled);
+             }
+             break;
+          case GL_CURRENT_BIT:
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0011-Apple-glFlush-is-not-needed-with-CGLFlushDrawable.patch b/pkgs/development/libraries/mesa-darwin/patches/0011-Apple-glFlush-is-not-needed-with-CGLFlushDrawable.patch
new file mode 100644
index 000000000000..565d5e6c2737
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0011-Apple-glFlush-is-not-needed-with-CGLFlushDrawable.patch
@@ -0,0 +1,29 @@
+From 9c50093adff0c7531ab32a7ec9ce3b91712b4d20 Mon Sep 17 00:00:00 2001
+From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Date: Sat, 20 Jul 2013 10:25:28 -0700
+Subject: [PATCH 11/13] Apple: glFlush() is not needed with CGLFlushDrawable()
+
+<rdar://problem/14496373>
+
+Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+(cherry picked from commit fa5ed99d8e809fb86e486a40273a4a6971055398)
+---
+ src/glx/apple/apple_glx.c | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/src/glx/apple/apple_glx.c b/src/glx/apple/apple_glx.c
+index 56cff64..4e2aa33 100644
+--- a/src/glx/apple/apple_glx.c
++++ b/src/glx/apple/apple_glx.c
+@@ -132,8 +132,6 @@ apple_glx_swap_buffers(void *ptr)
+ {
+    struct apple_glx_context *ac = ptr;
+ 
+-   /* This may not be needed with CGLFlushDrawable: */
+-   glFlush();
+    apple_cgl.flush_drawable(ac->context_obj);
+ }
+ 
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0012-glapi-Avoid-heap-corruption-in-_glapi_table.patch b/pkgs/development/libraries/mesa-darwin/patches/0012-glapi-Avoid-heap-corruption-in-_glapi_table.patch
new file mode 100644
index 000000000000..58ac66bd5511
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0012-glapi-Avoid-heap-corruption-in-_glapi_table.patch
@@ -0,0 +1,28 @@
+From 629600450b3845a768c0edc92ea3f444d03a2738 Mon Sep 17 00:00:00 2001
+From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Date: Tue, 20 May 2014 01:37:58 -0700
+Subject: [PATCH 12/13] glapi: Avoid heap corruption in _glapi_table
+
+Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Reviewed-by: Chia-I Wu <olv@lunarg.com>
+(cherry picked from commit ff5456d1acf6f627a6837be3f3f37c6a268c9e8e)
+---
+ src/mapi/glapi/gen/gl_gentable.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/mapi/glapi/gen/gl_gentable.py b/src/mapi/glapi/gen/gl_gentable.py
+index 5657e32..0d0a02d 100644
+--- a/src/mapi/glapi/gen/gl_gentable.py
++++ b/src/mapi/glapi/gen/gl_gentable.py
+@@ -111,7 +111,7 @@ __glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
+ 
+ struct _glapi_table *
+ _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
+-    struct _glapi_table *disp = calloc(1, sizeof(struct _glapi_table));
++    struct _glapi_table *disp = calloc(1, _glapi_get_dispatch_table_size() * sizeof(_glapi_proc));
+     char symboln[512];
+ 
+     if(!disp)
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/0013-darwin-Fix-test-for-kCGLPFAOpenGLProfile-support-at-.patch b/pkgs/development/libraries/mesa-darwin/patches/0013-darwin-Fix-test-for-kCGLPFAOpenGLProfile-support-at-.patch
new file mode 100644
index 000000000000..5ec0d9024eff
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/0013-darwin-Fix-test-for-kCGLPFAOpenGLProfile-support-at-.patch
@@ -0,0 +1,40 @@
+From ba59a779ed41e08fa16805c1c60da39885546d0e Mon Sep 17 00:00:00 2001
+From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Date: Tue, 20 May 2014 10:53:00 -0700
+Subject: [PATCH 13/13] darwin: Fix test for kCGLPFAOpenGLProfile support at
+ runtime
+
+Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+(cherry picked from commit 7a109268ab5b3544e7f7b99e84ef1fdf54023fb4)
+---
+ src/glx/apple/apple_visual.c | 14 +++++++++-----
+ 1 file changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/src/glx/apple/apple_visual.c b/src/glx/apple/apple_visual.c
+index 282934f..238c248 100644
+--- a/src/glx/apple/apple_visual.c
++++ b/src/glx/apple/apple_visual.c
+@@ -73,11 +73,15 @@ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * m
+    GLint vsref = 0;
+    CGLError error = 0;
+ 
+-   /* Request an OpenGL 3.2 profile if one is available */
+-   if(apple_cgl.version_major > 1 || (apple_cgl.version_major == 1 && apple_cgl.version_minor >= 3)) {
+-      attr[numattr++] = kCGLPFAOpenGLProfile;
+-      attr[numattr++] = kCGLOGLPVersion_3_2_Core;
+-   }
++   /* Request an OpenGL 3.2 profile if one is available and supported */
++   attr[numattr++] = kCGLPFAOpenGLProfile;
++   attr[numattr++] = kCGLOGLPVersion_3_2_Core;
++
++   /* Test for kCGLPFAOpenGLProfile support at runtime and roll it out if not supported */
++   attr[numattr] = 0;
++   error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref);
++   if (error == kCGLBadAttribute)
++      numattr -= 2;
+ 
+    if (offscreen) {
+       apple_glx_diagnostic
+-- 
+1.9.2
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/1001-appleglx-Improve-error-reporting-if-CGLChoosePixelFo.patch b/pkgs/development/libraries/mesa-darwin/patches/1001-appleglx-Improve-error-reporting-if-CGLChoosePixelFo.patch
new file mode 100644
index 000000000000..372ce4a27a39
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/1001-appleglx-Improve-error-reporting-if-CGLChoosePixelFo.patch
@@ -0,0 +1,30 @@
+From f0702d6e631bb912a230c081463bb51a0dde1bff Mon Sep 17 00:00:00 2001
+From: Jon TURNEY <jon.turney@dronecode.org.uk>
+Date: Mon, 12 May 2014 15:38:26 +0100
+Subject: [PATCH 1001/1003] appleglx: Improve error reporting if
+ CGLChoosePixelFormat() didn't find any matching pixel formats.
+
+Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
+Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+(cherry picked from commit 002a3a74273b81dfb226e1c3f0a8c18525ed0af4)
+---
+ src/glx/apple/apple_visual.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/src/glx/apple/apple_visual.c b/src/glx/apple/apple_visual.c
+index 238c248..c6ede51 100644
+--- a/src/glx/apple/apple_visual.c
++++ b/src/glx/apple/apple_visual.c
+@@ -167,4 +167,9 @@ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * m
+       fprintf(stderr, "error: %s\n", apple_cgl.error_string(error));
+       abort();
+    }
++
++   if (!*pfobj) {
++      fprintf(stderr, "No matching pixelformats found, perhaps try using LIBGL_ALLOW_SOFTWARE\n");
++      abort();
++   }
+ }
+-- 
+1.9.2 (Apple Git-49)
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/1002-darwin-Write-errors-in-choosing-the-pixel-format-to-.patch b/pkgs/development/libraries/mesa-darwin/patches/1002-darwin-Write-errors-in-choosing-the-pixel-format-to-.patch
new file mode 100644
index 000000000000..4818ee63d4c9
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/1002-darwin-Write-errors-in-choosing-the-pixel-format-to-.patch
@@ -0,0 +1,55 @@
+From 1b2f877c8ef052b183c1f20ece6c6e4a7bfd237c Mon Sep 17 00:00:00 2001
+From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Date: Sat, 24 May 2014 14:13:33 -0700
+Subject: [PATCH 1002/1003] darwin: Write errors in choosing the pixel format
+ to the crash log
+
+Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+(cherry picked from commit 9eb1d36c978a9b15ae2e999c630492dfffd7f165)
+---
+ src/glx/apple/apple_visual.c | 18 ++++++++++++++++--
+ 1 file changed, 16 insertions(+), 2 deletions(-)
+
+diff --git a/src/glx/apple/apple_visual.c b/src/glx/apple/apple_visual.c
+index c6ede51..951b213 100644
+--- a/src/glx/apple/apple_visual.c
++++ b/src/glx/apple/apple_visual.c
+@@ -63,6 +63,16 @@ enum
+    MAX_ATTR = 60
+ };
+ 
++static char __crashreporter_info_buff__[4096] = { 0 };
++static const char *__crashreporter_info__ __attribute__((__used__)) =
++    &__crashreporter_info_buff__[0];
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
++// This is actually a toolchain requirement, but I'm not sure the correct check,
++// but it should be fine to just only include it for Leopard and later.  This line
++// just tells the linker to never strip this symbol (such as for space optimization)
++__asm__ (".desc ___crashreporter_info__, 0x10");
++#endif
++
+ void
+ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * mode,
+                           bool * double_buffered, bool * uses_stereo,
+@@ -164,12 +174,16 @@ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * m
+    error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref);
+ 
+    if (error) {
+-      fprintf(stderr, "error: %s\n", apple_cgl.error_string(error));
++      snprintf(__crashreporter_info_buff__, sizeof(__crashreporter_info_buff__),
++               "CGLChoosePixelFormat error: %s\n", apple_cgl.error_string(error));
++      fprintf(stderr, "%s", __crashreporter_info_buff__);
+       abort();
+    }
+ 
+    if (!*pfobj) {
+-      fprintf(stderr, "No matching pixelformats found, perhaps try using LIBGL_ALLOW_SOFTWARE\n");
++      snprintf(__crashreporter_info_buff__, sizeof(__crashreporter_info_buff__),
++               "No matching pixelformats found, perhaps try using LIBGL_ALLOW_SOFTWARE\n");
++      fprintf(stderr, "%s", __crashreporter_info_buff__);
+       abort();
+    }
+ }
+-- 
+1.9.2 (Apple Git-49)
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/1003-darwin-Guard-Core-Profile-usage-behind-a-testing-env.patch b/pkgs/development/libraries/mesa-darwin/patches/1003-darwin-Guard-Core-Profile-usage-behind-a-testing-env.patch
new file mode 100644
index 000000000000..72841e2a2cce
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/1003-darwin-Guard-Core-Profile-usage-behind-a-testing-env.patch
@@ -0,0 +1,69 @@
+From 9d6e12eb6b06202519e48a7321f32944d7a34b0f Mon Sep 17 00:00:00 2001
+From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+Date: Sat, 24 May 2014 14:08:16 -0700
+Subject: [PATCH 1003/1003] darwin: Guard Core Profile usage behind a testing
+ envvar
+
+Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
+(cherry picked from commit 04ce3be4010305902cc5ae81e8e0c8550d043a1e)
+---
+ src/glx/apple/apple_visual.c | 30 ++++++++++++++++++++----------
+ 1 file changed, 20 insertions(+), 10 deletions(-)
+
+diff --git a/src/glx/apple/apple_visual.c b/src/glx/apple/apple_visual.c
+index 951b213..046581b 100644
+--- a/src/glx/apple/apple_visual.c
++++ b/src/glx/apple/apple_visual.c
+@@ -82,16 +82,7 @@ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * m
+    int numattr = 0;
+    GLint vsref = 0;
+    CGLError error = 0;
+-
+-   /* Request an OpenGL 3.2 profile if one is available and supported */
+-   attr[numattr++] = kCGLPFAOpenGLProfile;
+-   attr[numattr++] = kCGLOGLPVersion_3_2_Core;
+-
+-   /* Test for kCGLPFAOpenGLProfile support at runtime and roll it out if not supported */
+-   attr[numattr] = 0;
+-   error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref);
+-   if (error == kCGLBadAttribute)
+-      numattr -= 2;
++   bool use_core_profile = getenv("LIBGL_PROFILE_CORE");
+ 
+    if (offscreen) {
+       apple_glx_diagnostic
+@@ -167,12 +158,31 @@ apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const struct glx_config * m
+       attr[numattr++] = mode->samples;
+    }
+ 
++   /* Debugging support for Core profiles to support newer versions of OpenGL */
++   if (use_core_profile) {
++      attr[numattr++] = kCGLPFAOpenGLProfile;
++      attr[numattr++] = kCGLOGLPVersion_3_2_Core;
++   }
++
+    attr[numattr++] = 0;
+ 
+    assert(numattr < MAX_ATTR);
+ 
+    error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref);
+ 
++   if ((error == kCGLBadAttribute || vsref == 0) && use_core_profile) {
++      apple_glx_diagnostic
++         ("Trying again without CoreProfile: error=%s, vsref=%d\n", apple_cgl.error_string(error), vsref);
++
++      if (!error)
++         apple_cgl.destroy_pixel_format(*pfobj);
++
++      numattr -= 3;
++      attr[numattr++] = 0;
++
++      error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref);
++   }
++
+    if (error) {
+       snprintf(__crashreporter_info_buff__, sizeof(__crashreporter_info_buff__),
+                "CGLChoosePixelFormat error: %s\n", apple_cgl.error_string(error));
+-- 
+1.9.2 (Apple Git-49)
+
diff --git a/pkgs/development/libraries/mesa-darwin/patches/patch-src-mapi-vgapi-Makefile.diff b/pkgs/development/libraries/mesa-darwin/patches/patch-src-mapi-vgapi-Makefile.diff
new file mode 100644
index 000000000000..e29a8464076d
--- /dev/null
+++ b/pkgs/development/libraries/mesa-darwin/patches/patch-src-mapi-vgapi-Makefile.diff
@@ -0,0 +1,11 @@
+--- a/src/mapi/vgapi/Makefile	2012-11-30 12:06:24.000000000 -0500
++++ b/src/mapi/vgapi/Makefile	2012-11-30 12:06:52.000000000 -0500
+@@ -75,6 +75,8 @@
+ install-headers:
+ 	$(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/VG
+ 	$(INSTALL) -m 644 $(TOP)/include/VG/*.h $(DESTDIR)$(INSTALL_INC_DIR)/VG
++	$(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR
++	$(INSTALL) -m 644 $(TOP)/include/KHR/*.h $(DESTDIR)$(INSTALL_INC_DIR)/KHR
+ 
+ install: default install-headers install-pc
+ 	$(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)