Path: blob/21.2-virgl/src/glx/apple/apple_xgl_api_stereo.c
4560 views
/*1Copyright (c) 2009-2011 Apple Inc.23Permission is hereby granted, free of charge, to any person4obtaining a copy of this software and associated documentation files5(the "Software"), to deal in the Software without restriction,6including without limitation the rights to use, copy, modify, merge,7publish, distribute, sublicense, and/or sell copies of the Software,8and to permit persons to whom the Software is furnished to do so,9subject to the following conditions:1011The above copyright notice and this permission notice shall be12included in all copies or substantial portions of the Software.1314THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT18HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,19WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21DEALINGS IN THE SOFTWARE.2223Except as contained in this notice, the name(s) of the above24copyright holders shall not be used in advertising or otherwise to25promote the sale, use or other dealings in this Software without26prior written authorization.27*/2829/* This should be removed once stereo hardware bugs are fixed30* <rdar://problem/6729006>31*/3233#include <stdbool.h>3435#define GL_GLEXT_PROTOTYPES36#include <GL/gl.h>37#include <GL/glext.h>3839#include "glxclient.h"40#include "apple_glx_context.h"41#include "apple_xgl_api.h"42#include "main/glheader.h"43#include "glapitable.h"4445extern struct _glapi_table * __ogl_framework_api;4647/*48* These are special functions for stereoscopic support49* differences in MacOS X.50*/51void52__applegl_glDrawBuffer(GLenum mode)53{54struct glx_context * gc = __glXGetCurrentContext();5556if (gc != &dummyContext && apple_glx_context_uses_stereo(gc->driContext)) {57GLenum buf[2];58GLsizei n = 0;5960switch (mode) {61case GL_BACK:62buf[0] = GL_BACK_LEFT;63buf[1] = GL_BACK_RIGHT;64n = 2;65break;66case GL_FRONT:67buf[0] = GL_FRONT_LEFT;68buf[1] = GL_FRONT_RIGHT;69n = 2;70break;7172default:73buf[0] = mode;74n = 1;75break;76}7778__ogl_framework_api->DrawBuffers(n, buf);79}80else {81__ogl_framework_api->DrawBuffer(mode);82}83}848586void87__applegl_glDrawBuffers(GLsizei n, const GLenum * bufs)88{89struct glx_context * gc = __glXGetCurrentContext();9091if (gc != &dummyContext && apple_glx_context_uses_stereo(gc->driContext)) {92GLenum newbuf[n + 2];93GLsizei i, outi = 0;94bool have_back = false;95bool have_front = false;9697for (i = 0; i < n; ++i) {98if (GL_BACK == bufs[i]) {99have_back = true;100}101else if (GL_FRONT == bufs[i]) {102have_back = true;103}104else {105newbuf[outi++] = bufs[i];106}107}108109if (have_back) {110newbuf[outi++] = GL_BACK_LEFT;111newbuf[outi++] = GL_BACK_RIGHT;112}113114if (have_front) {115newbuf[outi++] = GL_FRONT_LEFT;116newbuf[outi++] = GL_FRONT_RIGHT;117}118119__ogl_framework_api->DrawBuffers(outi, newbuf);120}121else {122__ogl_framework_api->DrawBuffers(n, bufs);123}124}125126127