apple_xgl_api_stereo.c revision 22613d1670e3aafcfd3b95191b908a0adabe3eb9
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/* This should be removed once stereo hardware bugs are fixed
31 * <rdar://problem/6729006>
32 */
33
34#include <stdbool.h>
35
36#define GL_GLEXT_PROTOTYPES
37#include <GL/gl.h>
38#include <GL/glext.h>
39
40#include "glxclient.h"
41#include "apple_glx_context.h"
42#include "apple_xgl_api.h"
43
44extern struct apple_xgl_api __gl_api;
45/*
46 * These are special functions for stereoscopic support
47 * differences in MacOS X.
48 */
49void
50glDrawBuffer(GLenum mode)
51{
52   struct glx_context * gc = __glXGetCurrentContext();
53
54   if (gc && apple_glx_context_uses_stereo(gc->driContext)) {
55      GLenum buf[2];
56      GLsizei n = 0;
57
58      switch (mode) {
59      case GL_BACK:
60         buf[0] = GL_BACK_LEFT;
61         buf[1] = GL_BACK_RIGHT;
62         n = 2;
63         break;
64      case GL_FRONT:
65         buf[0] = GL_FRONT_LEFT;
66         buf[1] = GL_FRONT_RIGHT;
67         n = 2;
68         break;
69
70      default:
71         buf[0] = mode;
72         n = 1;
73         break;
74      }
75
76      __gl_api.DrawBuffers(n, buf);
77   }
78   else {
79      __gl_api.DrawBuffer(mode);
80   }
81}
82
83
84void
85glDrawBuffers(GLsizei n, const GLenum * bufs)
86{
87   struct glx_context * gc = __glXGetCurrentContext();
88
89   if (gc && apple_glx_context_uses_stereo(gc->driContext)) {
90      GLenum newbuf[n + 2];
91      GLsizei i, outi = 0;
92      bool have_back = false;
93      bool have_front = false;
94
95      for (i = 0; i < n; ++i) {
96         if (GL_BACK == bufs[i]) {
97            have_back = true;
98         }
99         else if (GL_FRONT == bufs[i]) {
100            have_back = true;
101         }
102         else {
103            newbuf[outi++] = bufs[i];
104         }
105      }
106
107      if (have_back) {
108         newbuf[outi++] = GL_BACK_LEFT;
109         newbuf[outi++] = GL_BACK_RIGHT;
110      }
111
112      if (have_front) {
113         newbuf[outi++] = GL_FRONT_LEFT;
114         newbuf[outi++] = GL_FRONT_RIGHT;
115      }
116
117      __gl_api.DrawBuffers(outi, newbuf);
118   }
119   else {
120      __gl_api.DrawBuffers(n, bufs);
121   }
122}
123
124void
125glDrawBuffersARB(GLsizei n, const GLenum * bufs)
126{
127   glDrawBuffers(n, bufs);
128}
129