apple_xgl_api_stereo.c revision 88cec591706ff63870c9c2a04394034b6f761f9c
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/* 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Copyright (c) 2009 Apple Inc. 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Permission is hereby granted, free of charge, to any person 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) obtaining a copy of this software and associated documentation files 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (the "Software"), to deal in the Software without restriction, 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) including without limitation the rights to use, copy, modify, merge, 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) publish, distribute, sublicense, and/or sell copies of the Software, 9e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch and to permit persons to whom the Software is furnished to do so, 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) subject to the following conditions: 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) The above copyright notice and this permission notice shall be 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) included in all copies or substantial portions of the Software. 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DEALINGS IN THE SOFTWARE. 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Except as contained in this notice, the name(s) of the above 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) copyright holders shall not be used in advertising or otherwise to 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) promote the sale, use or other dealings in this Software without 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prior written authorization. 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)*/ 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/* This should be removed once stereo hardware bugs are fixed 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * <rdar://problem/6729006> 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) */ 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <stdbool.h> 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define GL_GLEXT_PROTOTYPES 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <GL/gl.h> 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <GL/glext.h> 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "glxclient.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "apple_glx_context.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "apple_xgl_api.h" 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)extern struct apple_xgl_api __ogl_framework_api; 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/* 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * These are special functions for stereoscopic support 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * differences in MacOS X. 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) */ 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)glDrawBuffer(GLenum mode) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles){ 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct glx_context * gc = __glXGetCurrentContext(); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gc && apple_glx_context_uses_stereo(gc->driContext)) { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GLenum buf[2]; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GLsizei n = 0; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switch (mode) { 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case GL_BACK: 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buf[0] = GL_BACK_LEFT; 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buf[1] = GL_BACK_RIGHT; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) n = 2; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case GL_FRONT: 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buf[0] = GL_FRONT_LEFT; 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buf[1] = GL_FRONT_RIGHT; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) n = 2; 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) break; 69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) default: 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) buf[0] = mode; 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) n = 1; 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci break; 741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) __ogl_framework_api.DrawBuffers(n, buf); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else { 79 __ogl_framework_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 __ogl_framework_api.DrawBuffers(outi, newbuf); 118 } 119 else { 120 __ogl_framework_api.DrawBuffers(n, bufs); 121 } 122} 123 124void 125glDrawBuffersARB(GLsizei n, const GLenum * bufs) 126{ 127 glDrawBuffers(n, bufs); 128} 129