Revision: 167 http://trac.macosforge.org/projects/xquartz/changeset/167 Author: gstaplin@apple.com Date: 2009-02-18 03:23:56 -0800 (Wed, 18 Feb 2009) Log Message: ----------- Make the OffScreen attribute not be enabled for every CGLPixelFormatObj. This works, but could use further testing, especially with context and drawable destruction when the active context was from a GLXPixmap. Modified Paths: -------------- AppleSGLX/trunk/apple_glx_context.c AppleSGLX/trunk/apple_glx_pixmap.c AppleSGLX/trunk/apple_glx_pixmap.h AppleSGLX/trunk/apple_visual.c AppleSGLX/trunk/apple_visual.h AppleSGLX/trunk/glxcmds.c Modified: AppleSGLX/trunk/apple_glx_context.c =================================================================== --- AppleSGLX/trunk/apple_glx_context.c 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/apple_glx_context.c 2009-02-18 11:23:56 UTC (rev 167) @@ -141,7 +141,7 @@ ac->made_current = false; apple_visual_create_pfobj(&ac->pixel_format_obj, mode, - &ac->double_buffered); + &ac->double_buffered, /*offscreen*/ false); error = apple_cgl.create_context(ac->pixel_format_obj, sharedac ? sharedac->context_obj : NULL, @@ -427,17 +427,30 @@ case APPLE_GLX_DRAWABLE_PIXMAP: { int width, height, pitch, bpp; void *ptr; - + CGLContextObj ctxobj; + void *ctxobjptr; apple_cgl.clear_drawable(ac->context_obj); if(false == apple_glx_pixmap_data(dpy, ac->drawable->drawable, &width, &height, &pitch, &bpp, - &ptr)) { + &ptr, &ctxobjptr, + /*mark current*/ true)) { return true; } + + ctxobj = ctxobjptr; - cglerr = apple_cgl.set_off_screen(ac->context_obj, width, height, + cglerr = apple_cgl.set_current_context(ctxobj); + + if(kCGLNoError != cglerr) { + fprintf(stderr, "set current context: %s\n", + apple_cgl.error_string(cglerr)); + + return true; + } + + cglerr = apple_cgl.set_off_screen(ctxobj, width, height, pitch, ptr); if(kCGLNoError != cglerr) { Modified: AppleSGLX/trunk/apple_glx_pixmap.c =================================================================== --- AppleSGLX/trunk/apple_glx_pixmap.c 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/apple_glx_pixmap.c 2009-02-18 11:23:56 UTC (rev 167) @@ -34,6 +34,8 @@ #include <sys/types.h> #include <sys/mman.h> #include <unistd.h> +#include "apple_cgl.h" +#include "apple_visual.h" #include "apple_glx_pixmap.h" #include "appledri.h" @@ -44,6 +46,9 @@ size_t size; char path[PATH_MAX]; int fd; + CGLPixelFormatObj pixel_format_obj; + CGLContextObj context_obj; + bool is_current; struct apple_glx_pixmap *next, *previous; }; @@ -89,9 +94,12 @@ /* Return true if an error occurred. */ -bool apple_glx_pixmap_create(Display *dpy, int screen, Pixmap pixmap) { +bool apple_glx_pixmap_create(Display *dpy, int screen, Pixmap pixmap, + const void *mode) { struct apple_glx_pixmap *p; - + bool double_buffered; + CGLError error; + p = malloc(sizeof(*p)); p->xpixmap = pixmap; @@ -127,6 +135,23 @@ return true; } + apple_visual_create_pfobj(&p->pixel_format_obj, mode, &double_buffered, + /*offscreen*/ true); + + error = apple_cgl.create_context(p->pixel_format_obj, NULL, + &p->context_obj); + + if(kCGLNoError != error) { + (void)apple_cgl.destroy_pixel_format(p->pixel_format_obj); + munmap(p->buffer, p->size); + XAppleDRIDestroyPixmap(dpy, pixmap); + shm_unlink(p->path); + free(p); + return true; + } + + p->is_current = false; + lock_pixmap_list(); p->previous = NULL; @@ -149,11 +174,12 @@ lock_pixmap_list(); if(find_pixmap(pixmap, &p)) { + (void)apple_cgl.destroy_pixel_format(p->pixel_format_obj); + (void)apple_cgl.destroy_context(p->context_obj); XAppleDRIDestroyPixmap(dpy, pixmap); munmap(p->buffer, p->size); close(p->fd); shm_unlink(p->path); - free(p); if(p->previous) { p->previous->next = p->next; @@ -163,6 +189,8 @@ if(p->next) p->next->previous = p->previous; + + free(p); } unlock_pixmap_list(); @@ -183,7 +211,8 @@ } bool apple_glx_pixmap_data(Display *dpy, GLXPixmap pixmap, int *width, - int *height, int *pitch, int *bpp, void **ptr) { + int *height, int *pitch, int *bpp, void **ptr, + void **contextptr, bool mark_current) { struct apple_glx_pixmap *p; bool result = false; @@ -195,6 +224,10 @@ *pitch = p->pitch; *bpp = p->bpp; *ptr = p->buffer; + *contextptr = p->context_obj; + + p->is_current = mark_current; + result = true; } Modified: AppleSGLX/trunk/apple_glx_pixmap.h =================================================================== --- AppleSGLX/trunk/apple_glx_pixmap.h 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/apple_glx_pixmap.h 2009-02-18 11:23:56 UTC (rev 167) @@ -33,8 +33,10 @@ #include <limits.h> #include "GL/glx.h" +/* mode is a __GLcontextModes * */ /* Returns true if an error occurred. */ -bool apple_glx_pixmap_create(Display *dpy, int screen, Pixmap pixmap); +bool apple_glx_pixmap_create(Display *dpy, int screen, Pixmap pixmap, + const void *mode); void apple_glx_pixmap_destroy(Display *dpy, Pixmap pixmap); @@ -42,6 +44,7 @@ /* Returns true if the pixmap is valid, and there is data for it. */ bool apple_glx_pixmap_data(Display *dpy, GLXPixmap pixmap, int *width, - int *height, int *pitch, int *bpp, void **ptr); + int *height, int *pitch, int *bpp, void **ptr, + void **contextptr, bool mark_current); #endif Modified: AppleSGLX/trunk/apple_visual.c =================================================================== --- AppleSGLX/trunk/apple_visual.c 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/apple_visual.c 2009-02-18 11:23:56 UTC (rev 167) @@ -35,24 +35,24 @@ #include <OpenGL/CGLContext.h> #include "glcontextmodes.h" #include "apple_cgl.h" +#include "apple_visual.h" /*mode is a __GlcontextModes*/ void apple_visual_create_pfobj(CGLPixelFormatObj *pfobj, const void *mode, - bool *double_buffered) { + bool *double_buffered, bool offscreen) { CGLPixelFormatAttribute attr[60]; const __GLcontextModes *c = mode; int numattr = 0; GLint vsref = 0; CGLError error = 0; -#if 1 - /*TODO we only need this sometimes -- for GLXPixmaps!*/ - attr[numattr++] = kCGLPFAOffScreen; + if(offscreen) { + attr[numattr++] = kCGLPFAOffScreen; + + attr[numattr++] = kCGLPFAColorSize; + attr[numattr++] = 32; + } - attr[numattr++] = kCGLPFAColorSize; - attr[numattr++] = 32; -#endif - if(c->stereoMode) attr[numattr++] = kCGLPFAStereo; Modified: AppleSGLX/trunk/apple_visual.h =================================================================== --- AppleSGLX/trunk/apple_visual.h 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/apple_visual.h 2009-02-18 11:23:56 UTC (rev 167) @@ -30,10 +30,11 @@ #ifndef APPLE_VISUAL_H #define APPLE_VISUAL_H +#include <stdbool.h> #include <OpenGL/CGLTypes.h> /* mode is expected to be of type __GLcontextModes. */ void apple_visual_create_pfobj(CGLPixelFormatObj *pfobj, const void *mode, - bool *double_buffered); + bool *double_buffered, bool offscreen); #endif Modified: AppleSGLX/trunk/glxcmds.c =================================================================== --- AppleSGLX/trunk/glxcmds.c 2009-02-18 08:07:43 UTC (rev 166) +++ AppleSGLX/trunk/glxcmds.c 2009-02-18 11:23:56 UTC (rev 167) @@ -682,7 +682,13 @@ PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, Pixmap pixmap) { - if(apple_glx_pixmap_create(dpy, vis->screen, pixmap)) + int screen = vis->screen; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + const __GLcontextModes *mode; + + mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + + if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, mode)) return None; return pixmap;
participants (1)
-
source_changes@macosforge.org