apple: Change ifdefs for DRI to be DRI && !APPLE
[mesa.git] / src / glx / apple / apple_xgl_api_stereo.c
1 /*
2 Copyright (c) 2009 Apple Inc.
3
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation files
6 (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge,
8 publish, distribute, sublicense, and/or sell copies of the Software,
9 and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name(s) of the above
25 copyright holders shall not be used in advertising or otherwise to
26 promote the sale, use or other dealings in this Software without
27 prior written authorization.
28 */
29
30 #include <stdbool.h>
31 #include "apple_xgl_api_stereo.h"
32 #include "apple_xgl_api.h"
33 #include "apple_glx_context.h"
34
35 extern struct apple_xgl_api __gl_api;
36 /*
37 * These are special functions for stereoscopic support
38 * differences in MacOS X.
39 */
40 void
41 glDrawBuffer(GLenum mode)
42 {
43 GLXContext gc = glXGetCurrentContext();
44
45 if (gc && apple_glx_context_uses_stereo(gc->driContext)) {
46 GLenum buf[2];
47 GLsizei n = 0;
48
49 switch (mode) {
50 case GL_BACK:
51 buf[0] = GL_BACK_LEFT;
52 buf[1] = GL_BACK_RIGHT;
53 n = 2;
54 break;
55 case GL_FRONT:
56 buf[0] = GL_FRONT_LEFT;
57 buf[1] = GL_FRONT_RIGHT;
58 n = 2;
59 break;
60
61 default:
62 buf[0] = mode;
63 n = 1;
64 break;
65 }
66
67 __gl_api.DrawBuffers(n, buf);
68 }
69 else {
70 __gl_api.DrawBuffer(mode);
71 }
72 }
73
74
75 void
76 glDrawBuffers(GLsizei n, const GLenum * bufs)
77 {
78 GLXContext gc = glXGetCurrentContext();
79
80 if (gc && apple_glx_context_uses_stereo(gc->driContext)) {
81 GLenum newbuf[n + 2];
82 GLsizei i, outi = 0;
83 bool have_back = false;
84 bool have_front = false;
85
86 for (i = 0; i < n; ++i) {
87 if (GL_BACK == bufs[i]) {
88 have_back = true;
89 }
90 else if (GL_FRONT == bufs[i]) {
91 have_back = true;
92 }
93 else {
94 newbuf[outi++] = bufs[i];
95 }
96 }
97
98 if (have_back) {
99 newbuf[outi++] = GL_BACK_LEFT;
100 newbuf[outi++] = GL_BACK_RIGHT;
101 }
102
103 if (have_front) {
104 newbuf[outi++] = GL_FRONT_LEFT;
105 newbuf[outi++] = GL_FRONT_RIGHT;
106 }
107
108 __gl_api.DrawBuffers(outi, newbuf);
109 }
110 else {
111 __gl_api.DrawBuffers(n, bufs);
112 }
113 }
114
115 void
116 glDrawBuffersARB(GLsizei n, const GLenum * bufs)
117 {
118 glDrawBuffers(n, bufs);
119 }