2 * GLX implementation that uses Apple's OpenGL.framework
4 * Copyright (c) 2007-2011 Apple Inc.
5 * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
6 * Copyright (c) 2002 Greg Parker. All Rights Reserved.
8 * Portions of this file are copied from Mesa's xf86glx.c,
9 * which contains the following copyright:
11 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
12 * All Rights Reserved.
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
42 #include "glapitable.h"
43 #include "main/dispatch.h"
45 #include "apple_glx.h"
46 #include "apple_xgl_api.h"
48 #ifndef OPENGL_FRAMEWORK_PATH
49 #define OPENGL_FRAMEWORK_PATH "/System/Library/Frameworks/OpenGL.framework/OpenGL"
52 struct _glapi_table
* __ogl_framework_api
= NULL
;
53 struct _glapi_table
* __applegl_api
= NULL
;
55 void apple_glapi_set_dispatch(void) {
57 const char *opengl_framework_path
;
60 _glapi_set_dispatch(__applegl_api
);
64 opengl_framework_path
= getenv("OPENGL_FRAMEWORK_PATH");
65 if (!opengl_framework_path
) {
66 opengl_framework_path
= OPENGL_FRAMEWORK_PATH
;
69 (void) dlerror(); /*drain dlerror */
70 handle
= dlopen(opengl_framework_path
, RTLD_LOCAL
);
73 fprintf(stderr
, "error: unable to dlopen %s : %s\n",
74 opengl_framework_path
, dlerror());
78 __ogl_framework_api
= _glapi_create_table_from_handle(handle
, "gl");
79 assert(__ogl_framework_api
);
81 __applegl_api
= malloc(sizeof(struct _glapi_table
));
82 assert(__applegl_api
);
83 memcpy(__applegl_api
, __ogl_framework_api
, sizeof(struct _glapi_table
));
85 SET_ReadPixels(__applegl_api
, __applegl_glReadPixels
);
86 SET_CopyPixels(__applegl_api
, __applegl_glCopyPixels
);
87 SET_CopyColorTable(__applegl_api
, __applegl_glCopyColorTable
);
88 SET_DrawBuffer(__applegl_api
, __applegl_glDrawBuffer
);
89 SET_DrawBuffersARB(__applegl_api
, __applegl_glDrawBuffersARB
);
90 SET_Viewport(__applegl_api
, __applegl_glViewport
);
92 _glapi_set_dispatch(__applegl_api
);