[Xquartz-changes] [319] AppleSGLX/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 19 15:23:12 PDT 2009


Revision: 319
          http://trac.macosforge.org/projects/xquartz/changeset/319
Author:   gstaplin at apple.com
Date:     2009-03-19 15:23:10 -0700 (Thu, 19 Mar 2009)
Log Message:
-----------
Only enable GL_BACK and GL_FRONT translation to RIGHT AND LEFT buffers if
the context's CGLPixelFormatObj has the stereo attribute.

This prevents GL errors with non-stereo contexts, while retaining the 
workaround for systems that need both specified.

Modified Paths:
--------------
    AppleSGLX/trunk/Makefile
    AppleSGLX/trunk/apple_glx_context.c
    AppleSGLX/trunk/apple_glx_context.h
    AppleSGLX/trunk/apple_glx_pixmap.c
    AppleSGLX/trunk/apple_visual.c
    AppleSGLX/trunk/apple_visual.h
    AppleSGLX/trunk/apple_xgl_api_stereo.c
    AppleSGLX/trunk/gen_api_library.tcl

Added Paths:
-----------
    AppleSGLX/trunk/apple_xgl_api_stereo.h

Modified: AppleSGLX/trunk/Makefile
===================================================================
--- AppleSGLX/trunk/Makefile	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/Makefile	2009-03-19 22:23:10 UTC (rev 319)
@@ -33,7 +33,7 @@
     compsize.o apple_visual.o apple_cgl.o glxreply.o glcontextmodes.o \
     apple_xgl_api.o apple_glx_drawable.o xfont.o apple_glx_pbuffer.o \
     apple_glx_pixmap.o apple_xgl_api_read.o glx_empty.o glx_error.o \
-    apple_xgl_api_viewport.o apple_glx_surface.o
+    apple_xgl_api_viewport.o apple_glx_surface.o apple_xgl_api_stereo.o
 
 #This is used for building the tests.
 #The tests don't require installation.
@@ -52,6 +52,7 @@
 apple_xgl_api.o: apple_xgl_api.h apple_xgl_api.c apple_xgl_api_stereo.c include/GL/gl.h
 apple_xgl_api_read.o: apple_xgl_api_read.h apple_xgl_api_read.c apple_xgl_api.h include/GL/gl.h
 apple_xgl_api_viewport.o: apple_xgl_api_viewport.h apple_xgl_api_viewport.c apple_xgl_api.h include/GL/gl.h
+apple_xgl_api_stereo.o: apple_xgl_api_stereo.h apple_xgl_api_stereo.c
 glcontextmodes.o: glcontextmodes.c glcontextmodes.h include/GL/gl.h
 glxext.o: glxext.c include/GL/gl.h
 glxreply.o: glxreply.c include/GL/gl.h

Modified: AppleSGLX/trunk/apple_glx_context.c
===================================================================
--- AppleSGLX/trunk/apple_glx_context.c	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_glx_context.c	2009-03-19 22:23:10 UTC (rev 319)
@@ -139,13 +139,15 @@
     ac->thread_id = pthread_self();
     ac->screen = screen;
     ac->double_buffered = false;
+    ac->uses_stereo = false;
     ac->need_update = false;
     ac->is_current = false;
     ac->made_current = false;
     ac->last_surface_window = None;
     
     apple_visual_create_pfobj(&ac->pixel_format_obj, mode, 
-			      &ac->double_buffered, /*offscreen*/ false);
+			      &ac->double_buffered, &ac->uses_stereo,
+			      /*offscreen*/ false);
     
     error = apple_cgl.create_context(ac->pixel_format_obj, 
 				     sharedac ? sharedac->context_obj : NULL,
@@ -553,3 +555,9 @@
 	}
     }
 }
+
+bool apple_glx_context_uses_stereo(void *ptr) {
+    struct apple_glx_context *ac = ptr;
+
+    return ac->uses_stereo;
+}

Modified: AppleSGLX/trunk/apple_glx_context.h
===================================================================
--- AppleSGLX/trunk/apple_glx_context.h	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_glx_context.h	2009-03-19 22:23:10 UTC (rev 319)
@@ -47,6 +47,7 @@
     pthread_t thread_id;
     int screen;
     bool double_buffered;
+    bool uses_stereo;
     bool need_update;
     bool is_current; /* True if the context is current in some thread. */
     bool made_current; /* True if the context has ever been made current. */
@@ -76,4 +77,6 @@
 
 void apple_glx_context_update(Display *dpy, void *ptr);
 
+bool apple_glx_context_uses_stereo(void *ptr);
+
 #endif /*APPLE_GLX_CONTEXT_H*/

Modified: AppleSGLX/trunk/apple_glx_pixmap.c
===================================================================
--- AppleSGLX/trunk/apple_glx_pixmap.c	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_glx_pixmap.c	2009-03-19 22:23:10 UTC (rev 319)
@@ -117,6 +117,7 @@
     struct apple_glx_drawable *d;
     struct apple_glx_pixmap *p;
     bool double_buffered;
+    bool uses_stereo;
     CGLError error;
     const __GLcontextModes *cmodes = mode;
 
@@ -158,7 +159,7 @@
     }
 
     apple_visual_create_pfobj(&p->pixel_format_obj, mode, &double_buffered,
-			      /*offscreen*/ true);
+			      &uses_stereo, /*offscreen*/ true);
 
     error = apple_cgl.create_context(p->pixel_format_obj, NULL,
 				     &p->context_obj);

Modified: AppleSGLX/trunk/apple_visual.c
===================================================================
--- AppleSGLX/trunk/apple_visual.c	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_visual.c	2009-03-19 22:23:10 UTC (rev 319)
@@ -1,5 +1,5 @@
 /*
- Copyright (c) 2008 Apple Inc.
+ Copyright (c) 2008, 2009 Apple Inc.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
@@ -46,7 +46,8 @@
 
 /*mode is a __GlcontextModes*/
 void apple_visual_create_pfobj(CGLPixelFormatObj *pfobj, const void *mode,
-                               bool *double_buffered, bool offscreen) {
+                               bool *double_buffered, bool *uses_stereo,
+			       bool offscreen) {
     CGLPixelFormatAttribute attr[MAX_ATTR];
     const __GLcontextModes *c = mode;
     int numattr = 0;
@@ -76,9 +77,13 @@
      */
     attr[numattr++] = kCGLPFAClosestPolicy;
     
-    if(c->stereoMode) 
+    if(c->stereoMode) {
         attr[numattr++] = kCGLPFAStereo;
-    
+	*uses_stereo = true;
+    } else {
+	*uses_stereo = false;
+    }
+
     if(c->doubleBufferMode) {
         attr[numattr++] = kCGLPFADoubleBuffer;
         *double_buffered = true;

Modified: AppleSGLX/trunk/apple_visual.h
===================================================================
--- AppleSGLX/trunk/apple_visual.h	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_visual.h	2009-03-19 22:23:10 UTC (rev 319)
@@ -35,6 +35,7 @@
 
 /* mode is expected to be of type __GLcontextModes. */
 void apple_visual_create_pfobj(CGLPixelFormatObj *pfobj, const void *mode,
-			       bool *double_buffered, bool offscreen);
+			       bool *double_buffered, bool *uses_stereo,
+			       bool offscreen);
 
 #endif

Modified: AppleSGLX/trunk/apple_xgl_api_stereo.c
===================================================================
--- AppleSGLX/trunk/apple_xgl_api_stereo.c	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/apple_xgl_api_stereo.c	2009-03-19 22:23:10 UTC (rev 319)
@@ -1,3 +1,37 @@
+/*
+ Copyright (c) 2009 Apple Inc.
+ 
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name(s) of the above
+ copyright holders shall not be used in advertising or otherwise to
+ promote the sale, use or other dealings in this Software without
+ prior written authorization.
+*/
+
+#include <stdbool.h>
+#include "apple_xgl_api_stereo.h"
+#include "apple_xgl_api.h"
+
+extern struct apple_xgl_api __gl_api;
 /* 
  * These are special functions for stereoscopic support 
  * differences in MacOS X.
@@ -3,48 +37,61 @@
  */ 
 void glDrawBuffer(GLenum mode) {
-    GLenum buf[2];
-    GLsizei n = 0;
+    GLXContext gc = __glXGetCurrentContext();
+
+    if(apple_glx_context_uses_stereo(gc->apple)) {
+	GLenum buf[2];
+	GLsizei n = 0;
 	
-    switch(mode) {
-    case GL_BACK:
-	buf[0] = GL_BACK_LEFT;
-	buf[1] = GL_BACK_RIGHT;
-	n = 2;
-	break;
-    case GL_FRONT:
-	buf[0] = GL_FRONT_LEFT;
-	buf[1] = GL_FRONT_RIGHT;
-	n = 2;
-	break;
+	switch(mode) {
+	case GL_BACK:
+	    buf[0] = GL_BACK_LEFT;
+	    buf[1] = GL_BACK_RIGHT;
+	    n = 2;
+	    break;
+	case GL_FRONT:
+	    buf[0] = GL_FRONT_LEFT;
+	    buf[1] = GL_FRONT_RIGHT;
+	    n = 2;
+	    break;
+	    
+	default:
+	    buf[0] = mode;
+	    n = 1;
+	    break;
+	}
 	
-    default:
-	buf[0] = mode;
-	n = 1;
+	__gl_api.DrawBuffers(n, buf);
+    } else {
+	__gl_api.DrawBuffer(mode);
     }
-    
-    __gl_api.DrawBuffers(n, buf);
 }
 
 	 
 void glDrawBuffers(GLsizei n, const GLenum *bufs) {
-    GLenum newbuf[n + 2];
-    GLsizei i, outi = 0;
-    bool have_back = false;
+    GLXContext gc = __glXGetCurrentContext();
+
+    if(apple_glx_context_uses_stereo(gc->apple)) {
+	GLenum newbuf[n + 2];
+	GLsizei i, outi = 0;
+	bool have_back = false;
         
-    for(i = 0; i < n; ++i) {
-	if(GL_BACK == bufs[i]) {
-	    have_back = true;
-	    continue;
-	} else {
-	    newbuf[outi++] = bufs[i];
+	for(i = 0; i < n; ++i) {
+	    if(GL_BACK == bufs[i]) {
+		have_back = true;
+		continue;
+	    } else {
+		newbuf[outi++] = bufs[i];
+	    }
 	}
+	
+	if(have_back) {
+	    newbuf[outi++] = GL_BACK_LEFT;
+	    newbuf[outi++] = GL_BACK_RIGHT;
+	}
+	
+	__gl_api.DrawBuffers(outi, newbuf);
+    } else {
+	__gl_api.DrawBuffers(n, bufs);
     }
-
-    if(have_back) {
-	newbuf[outi++] = GL_BACK_LEFT;
-	newbuf[outi++] = GL_BACK_RIGHT;
-    }
-    
-    __gl_api.DrawBuffers(outi, newbuf);
 }
 

Added: AppleSGLX/trunk/apple_xgl_api_stereo.h
===================================================================
--- AppleSGLX/trunk/apple_xgl_api_stereo.h	                        (rev 0)
+++ AppleSGLX/trunk/apple_xgl_api_stereo.h	2009-03-19 22:23:10 UTC (rev 319)
@@ -0,0 +1,39 @@
+/*
+ Copyright (c) 2009 Apple Inc.
+ 
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name(s) of the above
+ copyright holders shall not be used in advertising or otherwise to
+ promote the sale, use or other dealings in this Software without
+ prior written authorization.
+*/
+
+#include "glxclient.h"
+
+#ifndef APPLE_XGL_API_STEREO_H
+#define APPLE_XGL_API_STEREO_H
+
+extern void glDrawBuffer(GLenum mode);
+extern void glDrawBuffers(GLsizei n, const GLenum *bufs);
+extern void glDrawBuffersARB(GLsizei n, const GLenum *bufs);
+
+#endif

Modified: AppleSGLX/trunk/gen_api_library.tcl
===================================================================
--- AppleSGLX/trunk/gen_api_library.tcl	2009-03-19 21:08:01 UTC (rev 318)
+++ AppleSGLX/trunk/gen_api_library.tcl	2009-03-19 22:23:10 UTC (rev 319)
@@ -180,8 +180,6 @@
         puts $fd "[dict get $attr return] gl[set f]([set pstr]) \{\n\t$body\n\}"
     }
 
-    puts $fd {#include "apple_xgl_api_stereo.c"}
-
     puts $fd $::init_code
     
     puts $fd "void apple_xgl_init_direct(void) \{"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/xquartz-changes/attachments/20090319/c1e7e7e7/attachment-0001.html>


More information about the Xquartz-changes mailing list