diff options
author | Jeremy Huddleston <jeremyhu@apple.com> | 2010-04-01 11:01:31 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2010-04-27 11:26:50 -0700 |
commit | ad503c41557606d15b0420c824369456f6d20a8f (patch) | |
tree | 7155272412f9b20b559fa172a1718fd8dfe6e98a /src/glx/glxcmds.c | |
parent | f1381880a8e0e0cdd96c4c725ff35a28b250b09d (diff) |
apple: Initial import of libGL for OSX from AppleSGLX svn repository.
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'src/glx/glxcmds.c')
-rw-r--r-- | src/glx/glxcmds.c | 184 |
1 files changed, 170 insertions, 14 deletions
diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index e2c47812d7a..50802b7e1fe 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -34,11 +34,17 @@ */ #include "glxclient.h" +#ifdef GLX_USE_APPLEGL +#include "apple_glx_context.h" +#include "apple_glx.h" +#include "glx_error.h" +#else #include "glapi.h" +#endif #include "glxextensions.h" #include "glcontextmodes.h" -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) #include <sys/time.h> #include <X11/extensions/xf86vmode.h> #include "xf86dri.h" @@ -344,6 +350,12 @@ AllocateGLXContext(Display * dpy) bufSize = __GLX_MAX_RENDER_CMD_SIZE; } gc->maxSmallRenderCommandSize = bufSize; + +#ifdef GLX_USE_APPLEGL + gc->apple = NULL; + gc->do_destroy = False; +#endif + return gc; } @@ -368,7 +380,11 @@ CreateContext(Display * dpy, int generic_id, #ifdef GLX_DIRECT_RENDERING __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); #endif - +#ifdef GLX_USE_APPLEGL + int errorcode; + bool x11error; +#endif + if (dpy == NULL) return NULL; @@ -379,6 +395,7 @@ CreateContext(Display * dpy, int generic_id, if (!gc) return NULL; +#ifndef GLX_USE_APPLEGL #ifdef GLX_DIRECT_RENDERING if (allowDirect && psc->driScreen) { gc->driContext = psc->driScreen->createContext(psc, fbconfig, gc, @@ -455,9 +472,24 @@ CreateContext(Display * dpy, int generic_id, UnlockDisplay(dpy); SyncHandle(); +#endif gc->imported = GL_FALSE; +#ifdef GLX_USE_APPLEGL + if(apple_glx_create_context(&gc->apple, dpy, screen, fbconfig, + shareList ? shareList->apple : NULL, + &errorcode, &x11error)) { + __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); + __glXFreeContext(gc); + return NULL; + } + + gc->currentContextTag = -1; + gc->mode = fbconfig; + gc->isDirect = allowDirect; +#else gc->renderType = renderType; +#endif return gc; } @@ -469,7 +501,7 @@ glXCreateContext(Display * dpy, XVisualInfo * vis, const __GLcontextModes *mode = NULL; int renderType = 0; -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL) __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen); mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); @@ -504,7 +536,9 @@ __glXFreeContext(__GLXcontext * gc) XFree((char *) gc->version); if (gc->extensions) XFree((char *) gc->extensions); +#ifndef GLX_USE_APPLEGL __glFreeAttributeState(gc); +#endif XFree((char *) gc->buf); Xfree((char *) gc->client_state_private); XFree((char *) gc); @@ -517,6 +551,7 @@ __glXFreeContext(__GLXcontext * gc) static void DestroyContext(Display * dpy, GLXContext gc) { +#ifndef GLX_USE_APPLEGL xGLXDestroyContextReq *req; GLXContextID xid; CARD8 opcode; @@ -552,17 +587,31 @@ DestroyContext(Display * dpy, GLXContext gc) #endif __glXFreeVertexArrayState(gc); +#else + __glXLock(); +#endif /* GLX_USE_APPLEGL */ if (gc->currentDpy) { +#ifdef GLX_USE_APPLEGL + /* + * Set the Bool that indicates that we should destroy this GLX context + * when the context is no longer current. + */ + gc->do_destroy = True; +#endif /* Have to free later cuz it's in use now */ __glXUnlock(); } else { /* Destroy the handle if not current to anybody */ __glXUnlock(); +#ifdef GLX_USE_APPLEGL + if(gc->apple) + apple_glx_destroy_context(&gc->apple, dpy); +#endif __glXFreeContext(gc); } - +#ifndef GLX_USE_APPLEGL if (!imported) { /* ** This dpy also created the server side part of the context. @@ -576,6 +625,7 @@ DestroyContext(Display * dpy, GLXContext gc) UnlockDisplay(dpy); SyncHandle(); } +#endif } PUBLIC void @@ -630,7 +680,9 @@ glXQueryExtension(Display * dpy, int *errorBase, int *eventBase) PUBLIC void glXWaitGL(void) { +#ifndef GLX_USE_APPLEGL xGLXWaitGLReq *req; +#endif GLXContext gc = __glXGetCurrentContext(); Display *dpy = gc->currentDpy; @@ -639,7 +691,9 @@ glXWaitGL(void) /* Flush any pending commands out */ __glXFlushRenderBuffer(gc, gc->pc); - +#ifdef GLX_USE_APPLEGL + glFinish(); +#else #ifdef GLX_DIRECT_RENDERING if (gc->driContext) { int screen; @@ -664,6 +718,7 @@ glXWaitGL(void) req->contextTag = gc->currentContextTag; UnlockDisplay(dpy); SyncHandle(); +#endif /* GLX_USE_APPLEGL */ } /* @@ -673,7 +728,9 @@ glXWaitGL(void) PUBLIC void glXWaitX(void) { +#ifndef GLX_USE_APPLEGL xGLXWaitXReq *req; +#endif GLXContext gc = __glXGetCurrentContext(); Display *dpy = gc->currentDpy; @@ -683,6 +740,9 @@ glXWaitX(void) /* Flush any pending commands out */ __glXFlushRenderBuffer(gc, gc->pc); +#ifdef GLX_USE_APPLEGL + apple_glx_waitx(dpy, gc->apple); +#else #ifdef GLX_DIRECT_RENDERING if (gc->driContext) { int screen; @@ -710,12 +770,15 @@ glXWaitX(void) req->contextTag = gc->currentContextTag; UnlockDisplay(dpy); SyncHandle(); +#endif /* GLX_USE_APPLEGL */ } PUBLIC void glXUseXFont(Font font, int first, int count, int listBase) { +#ifndef GLX_USE_APPLEGL xGLXUseXFontReq *req; +#endif GLXContext gc = __glXGetCurrentContext(); Display *dpy = gc->currentDpy; @@ -724,7 +787,9 @@ glXUseXFont(Font font, int first, int count, int listBase) /* Flush any pending commands out */ (void) __glXFlushRenderBuffer(gc, gc->pc); - +#ifdef GLX_USE_APPLEGL + DRI_glXUseXFont(font, first, count, listBase); +#else #ifdef GLX_DIRECT_RENDERING if (gc->driContext) { DRI_glXUseXFont(font, first, count, listBase); @@ -744,6 +809,7 @@ glXUseXFont(Font font, int first, int count, int listBase) req->listBase = listBase; UnlockDisplay(dpy); SyncHandle(); +#endif /* GLX_USE_APPLEGL */ } /************************************************************************/ @@ -756,6 +822,17 @@ PUBLIC void glXCopyContext(Display * dpy, GLXContext source, GLXContext dest, unsigned long mask) { +#ifdef GLX_USE_APPLEGL + GLXContext gc = __glXGetCurrentContext(); + int errorcode; + bool x11error; + + if(apple_glx_copy_context(gc->apple, source->apple, dest->apple, + mask, &errorcode, &x11error)) { + __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error); + } + +#else xGLXCopyContextReq *req; GLXContext gc = __glXGetCurrentContext(); GLXContextTag tag; @@ -794,9 +871,11 @@ glXCopyContext(Display * dpy, GLXContext source, req->contextTag = tag; UnlockDisplay(dpy); SyncHandle(); +#endif /* GLX_USE_APPLEGL */ } +#ifndef GLX_USE_APPLEGL /** * Determine if a context uses direct rendering. * @@ -844,6 +923,7 @@ __glXIsDirect(Display * dpy, GLXContextID contextID) return reply.isDirect; #endif /* USE_XCB */ } +#endif /* GLX_USE_APPLEGL */ /** * \todo @@ -854,6 +934,17 @@ __glXIsDirect(Display * dpy, GLXContextID contextID) PUBLIC Bool glXIsDirect(Display * dpy, GLXContext gc) { +#ifdef GLX_USE_APPLEGL + /* + * This isn't an ideal test. + * glXIsDirect should probably search a list of contexts. + */ + if(NULL == gc) { + __glXSendError(dpy, GLXBadContext, 0, X_GLXIsDirect, false); + return False; + } + return gc->isDirect; +#else if (!gc) { return GL_FALSE; } @@ -861,11 +952,24 @@ glXIsDirect(Display * dpy, GLXContext gc) return GL_TRUE; } return __glXIsDirect(dpy, gc->xid); +#endif /* GLX_USE_APPLEGL */ } PUBLIC GLXPixmap glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) { +#ifdef GLX_USE_APPLEGL + int screen = vis->screen; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + const __GLcontextModes *modes; + + modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + + if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, modes)) + return None; + + return pixmap; +#else xGLXCreateGLXPixmapReq *req; GLXPixmap xid; CARD8 opcode; @@ -915,6 +1019,7 @@ glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) #endif return xid; +#endif } /* @@ -923,6 +1028,10 @@ glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) PUBLIC void glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap) { +#ifdef GLX_USE_APPLEGL + if(apple_glx_pixmap_destroy(dpy, glxpixmap)) + __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false); +#else xGLXDestroyGLXPixmapReq *req; CARD8 opcode; @@ -953,11 +1062,20 @@ glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap) } } #endif +#endif /* GLX_USE_APPLEGL */ } PUBLIC void glXSwapBuffers(Display * dpy, GLXDrawable drawable) { +#ifdef GLX_USE_APPLEGL + GLXContext gc = glXGetCurrentContext(); + if(gc && apple_glx_is_current_drawable(dpy, gc->apple, drawable)) { + apple_glx_swap_buffers(gc->apple); + } else { + __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false); + } +#else GLXContext gc; GLXContextTag tag; CARD8 opcode; @@ -1012,6 +1130,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable) SyncHandle(); XFlush(dpy); #endif /* USE_XCB */ +#endif /* GLX_USE_APPLEGL */ } @@ -1440,6 +1559,12 @@ glXChooseVisual(Display * dpy, int screen, int *attribList) } } +#ifdef GLX_USE_APPLEGL + if(visualList && getenv("LIBGL_DUMP_VISUALID")) { + printf("visualid 0x%lx\n", visualList[0].visualid); + } +#endif + return visualList; } @@ -1573,6 +1698,7 @@ PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), glXGetCurrentDisplay) +#ifndef GLX_USE_APPLEGL /** * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests * to the X-server. @@ -1684,9 +1810,12 @@ static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) return retval; } +#endif + PUBLIC int glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value) { +#ifndef GLX_USE_APPLEGL int retVal; /* get the information from the server if we don't have it already */ @@ -1699,13 +1828,17 @@ glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value) if (Success != retVal) return retVal; } +#endif + switch (attribute) { - case GLX_SHARE_CONTEXT_EXT: +#ifndef GLX_USE_APPLEGL + case GLX_SHARE_CONTEXT_EXT: *value = (int) (ctx->share_xid); break; case GLX_VISUAL_ID_EXT: *value = ctx->mode ? ctx->mode->visualID : None; break; +#endif case GLX_SCREEN: *value = (int) (ctx->screen); break; @@ -1734,6 +1867,9 @@ PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) PUBLIC GLXContext glXImportContextEXT(Display * dpy, GLXContextID contextID) { +#ifdef GLX_USE_APPLEGL + return NULL; +#else GLXContext ctx; if (contextID == None) { @@ -1754,6 +1890,7 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID) } } return ctx; +#endif } PUBLIC void @@ -1881,7 +2018,7 @@ glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config) return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count); } - +#ifndef GLX_USE_APPLEGL /* ** GLX_SGI_swap_control */ @@ -2236,6 +2373,7 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) return GLX_BAD_CONTEXT; } +#endif /* GLX_USE_APPLEGL */ /* ** GLX_SGIX_fbconfig @@ -2262,17 +2400,24 @@ glXCreateGLXPixmapWithConfigSGIX(Display * dpy, GLXFBConfigSGIX config, Pixmap pixmap) { +#ifndef GLX_USE_APPLEGL xGLXVendorPrivateWithReplyReq *vpreq; xGLXCreateGLXPixmapWithConfigSGIXReq *req; GLXPixmap xid = None; CARD8 opcode; - const __GLcontextModes *const fbconfig = (__GLcontextModes *) config; __GLXscreenConfigs *psc; +#endif + const __GLcontextModes *const fbconfig = (__GLcontextModes *) config; if ((dpy == NULL) || (config == NULL)) { return None; } +#ifdef GLX_USE_APPLEGL + if(apple_glx_pixmap_create(dpy, fbconfig->screen, pixmap, fbconfig)) + return None; + return pixmap; +#else psc = GetGLXScreenConfigs(dpy, fbconfig->screen); if ((psc != NULL) @@ -2300,6 +2445,7 @@ glXCreateGLXPixmapWithConfigSGIX(Display * dpy, } return xid; +#endif } PUBLIC GLXContext @@ -2345,7 +2491,7 @@ glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis) return NULL; } - +#ifndef GLX_USE_APPLEGL /* ** GLX_SGIX_swap_group */ @@ -2963,6 +3109,8 @@ __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer) /*@}*/ +#endif /* GLX_USE_APPLEGL */ + /** * \c strdup is actually not a standard ANSI C or POSIX routine. * Irix will not define it if ANSI mode is in effect. @@ -3040,6 +3188,7 @@ static const struct name_address_pair GLX_functions[] = { GLX_FUNCTION(glXQueryDrawable), GLX_FUNCTION(glXSelectEvent), +#ifndef GLX_USE_APPLEGL /*** GLX_SGI_swap_control ***/ GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI), @@ -3057,6 +3206,7 @@ static const struct name_address_pair GLX_functions[] = { GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay), GLX_FUNCTION(glXImportContextEXT), GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext), +#endif /*** GLX_SGIX_fbconfig ***/ GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib), @@ -3066,6 +3216,7 @@ static const struct name_address_pair GLX_functions[] = { GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig), GLX_FUNCTION(glXGetFBConfigFromVisualSGIX), +#ifndef GLX_USE_APPLEGL /*** GLX_SGIX_pbuffer ***/ GLX_FUNCTION(glXCreateGLXPbufferSGIX), GLX_FUNCTION(glXDestroyGLXPbufferSGIX), @@ -3103,6 +3254,7 @@ static const struct name_address_pair GLX_functions[] = { GLX_FUNCTION2(glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA), GLX_FUNCTION2(glXGetFrameUsageMESA, __glXGetFrameUsageMESA), GLX_FUNCTION2(glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA), +#endif /*** GLX_ARB_get_proc_address ***/ GLX_FUNCTION(glXGetProcAddressARB), @@ -3110,6 +3262,7 @@ static const struct name_address_pair GLX_functions[] = { /*** GLX 1.4 ***/ GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB), +#ifndef GLX_USE_APPLEGL /*** GLX_OML_sync_control ***/ GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML), GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML), @@ -3120,6 +3273,7 @@ static const struct name_address_pair GLX_functions[] = { /*** GLX_EXT_texture_from_pixmap ***/ GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT), GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT), +#endif #ifdef GLX_DIRECT_RENDERING /*** DRI configuration ***/ @@ -3130,7 +3284,7 @@ static const struct name_address_pair GLX_functions[] = { {NULL, NULL} /* end of list */ }; - +#ifndef GLX_USE_APPLEGL static const GLvoid * get_glx_proc_address(const char *funcName) { @@ -3144,7 +3298,7 @@ get_glx_proc_address(const char *funcName) return NULL; } - +#endif /** * Get the address of a named GL function. This is the pre-GLX 1.4 name for @@ -3167,13 +3321,15 @@ PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void) * DRI based drivers from searching the core GL function table for * internal API functions. */ - +#ifdef GLX_USE_APPLEGL + f = (gl_function) apple_glx_get_proc_address(procName); +#else f = (gl_function) get_glx_proc_address((const char *) procName); if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') && (procName[2] != 'X')) { f = (gl_function) _glapi_get_proc_address((const char *) procName); } - +#endif return f; } |