#include "glcontextmodes.h"
#ifdef GLX_DIRECT_RENDERING
+#ifdef GLX_USE_APPLEGL
+#include "apple_glx_context.h"
+#include "apple_glx.h"
+#include "glx_error.h"
+#define GC_IS_DIRECT(gc) ((gc)->isDirect)
+#else
#include <sys/time.h>
#include <X11/extensions/xf86vmode.h>
#include "xf86dri.h"
#define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
+#endif
#else
#define GC_IS_DIRECT(gc) (0)
#endif
/****************************************************************************/
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
static Bool windowExistsFlag;
static int
bufSize = __GLX_MAX_RENDER_CMD_SIZE;
}
gc->maxSmallRenderCommandSize = bufSize;
+
+#ifdef GLX_USE_APPLEGL
+ gc->driContext = NULL;
+ gc->do_destroy = False;
+#endif
+
return gc;
}
{
GLXContext gc;
#ifdef GLX_DIRECT_RENDERING
+#ifdef GLX_USE_APPLEGL
+ int errorcode;
+ bool x11error;
+#else
__GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
#endif
-
+#endif
+
if (dpy == NULL)
return NULL;
if (!gc)
return NULL;
+#ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */
#ifdef GLX_DIRECT_RENDERING
if (allowDirect && psc->driScreen) {
gc->driContext = psc->driScreen->createContext(psc, fbconfig, gc,
UnlockDisplay(dpy);
SyncHandle();
+#endif
gc->imported = GL_FALSE;
gc->renderType = renderType;
+ /* TODO: darwin: Integrate with above to do indirect */
+#ifdef GLX_USE_APPLEGL
+ if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig,
+ shareList ? shareList->driContext : NULL,
+ &errorcode, &x11error)) {
+ __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error);
+ __glXFreeContext(gc);
+ return NULL;
+ }
+
+ gc->currentContextTag = -1;
+ gc->mode = fbconfig;
+ gc->isDirect = allowDirect;
+#endif
+
return gc;
}
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);
static void
DestroyContext(Display * dpy, GLXContext gc)
{
+#ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */
xGLXDestroyContextReq *req;
GLXContextID xid;
CARD8 opcode;
return;
}
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
/* Destroy the direct rendering context */
if (gc->driContext) {
(*gc->driContext->destroyContext) (gc->driContext, gc->psc, dpy);
#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->driContext)
+ apple_glx_destroy_context(&gc->driContext, dpy);
+#endif
__glXFreeContext(gc);
}
-
+#ifndef GLX_USE_APPLEGL
if (!imported) {
/*
** This dpy also created the server side part of the context.
UnlockDisplay(dpy);
SyncHandle();
}
+#endif
}
PUBLIC void
PUBLIC void
glXWaitGL(void)
{
+#ifndef GLX_USE_APPLEGL
xGLXWaitGLReq *req;
+#endif
GLXContext gc = __glXGetCurrentContext();
Display *dpy = gc->currentDpy;
/* Flush any pending commands out */
__glXFlushRenderBuffer(gc, gc->pc);
-
-#ifdef GLX_DIRECT_RENDERING
+#ifdef GLX_USE_APPLEGL
+ glFinish();
+#else
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
int screen;
__GLXDRIdrawable *pdraw =
req->contextTag = gc->currentContextTag;
UnlockDisplay(dpy);
SyncHandle();
+#endif /* GLX_USE_APPLEGL */
}
/*
PUBLIC void
glXWaitX(void)
{
+#ifndef GLX_USE_APPLEGL
xGLXWaitXReq *req;
+#endif
GLXContext gc = __glXGetCurrentContext();
Display *dpy = gc->currentDpy;
/* Flush any pending commands out */
__glXFlushRenderBuffer(gc, gc->pc);
-#ifdef GLX_DIRECT_RENDERING
+#ifdef GLX_USE_APPLEGL
+ apple_glx_waitx(dpy, gc->driContext);
+#else
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
int screen;
__GLXDRIdrawable *pdraw =
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;
/* Flush any pending commands out */
(void) __glXFlushRenderBuffer(gc, gc->pc);
-
-#ifdef GLX_DIRECT_RENDERING
+#ifdef GLX_USE_APPLEGL
+ DRI_glXUseXFont(font, first, count, listBase);
+#else
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
DRI_glXUseXFont(font, first, count, listBase);
return;
req->listBase = listBase;
UnlockDisplay(dpy);
SyncHandle();
+#endif /* GLX_USE_APPLEGL */
}
/************************************************************************/
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->driContext, source->driContext, dest->driContext,
+ mask, &errorcode, &x11error)) {
+ __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
+ }
+
+#else
xGLXCopyContextReq *req;
GLXContext gc = __glXGetCurrentContext();
GLXContextTag tag;
return;
}
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
/* NOT_DONE: This does not work yet */
}
req->contextTag = tag;
UnlockDisplay(dpy);
SyncHandle();
+#endif /* GLX_USE_APPLEGL */
}
static Bool
__glXIsDirect(Display * dpy, GLXContextID contextID)
{
+#ifndef GLX_USE_APPLEGL /* TODO: apple indirect */
+ return GC_IS_DIRECT(gc);
+#else
#if !defined(USE_XCB)
xGLXIsDirectReq *req;
xGLXIsDirectReply reply;
return reply.isDirect;
#endif /* USE_XCB */
+#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;
UnlockDisplay(dpy);
SyncHandle();
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
do {
/* FIXME: Maybe delay __DRIdrawable creation until the drawable
* is actually bound to a context... */
#endif
return xid;
+#endif
}
/*
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;
UnlockDisplay(dpy);
SyncHandle();
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
{
int screen;
__GLXdisplayPrivate *const priv = __glXInitialize(dpy);
}
}
#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->driContext, drawable)) {
+ apple_glx_swap_buffers(gc->driContext);
+ } else {
+ __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
+ }
+#else
GLXContext gc;
GLXContextTag tag;
CARD8 opcode;
xGLXSwapBuffersReq *req;
#endif
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
if (pdraw != NULL) {
SyncHandle();
XFlush(dpy);
#endif /* USE_XCB */
+#endif /* GLX_USE_APPLEGL */
}
}
}
+#ifdef GLX_USE_APPLEGL
+ if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
+ printf("visualid 0x%lx\n", visualList[0].visualid);
+ }
+#endif
+
return visualList;
}
}
__glXCalculateUsableExtensions(psc,
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
(psc->driScreen != NULL),
#else
GL_FALSE,
GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
glXGetCurrentDisplay)
+#ifndef GLX_USE_APPLEGL
/**
* Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
* to the X-server.
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 */
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (!ctx->driContext && (ctx->mode == NULL)) {
#else
if (ctx->mode == NULL) {
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;
PUBLIC GLXContext
glXImportContextEXT(Display * dpy, GLXContextID contextID)
{
+#ifdef GLX_USE_APPLEGL
+ return NULL;
+#else
GLXContext ctx;
if (contextID == None) {
}
}
return ctx;
+#endif
}
PUBLIC void
return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
}
-
+#ifndef GLX_USE_APPLEGL
/*
** GLX_SGI_swap_control
*/
return GLX_BAD_CONTEXT;
}
+#endif /* GLX_USE_APPLEGL */
/*
** GLX_SGIX_fbconfig
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)
}
return xid;
+#endif
}
PUBLIC GLXContext
return NULL;
}
-
+#ifndef GLX_USE_APPLEGL
/*
** GLX_SGIX_swap_group
*/
return False;
}
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
_X_HIDDEN GLboolean
__driGetMscRateOML(__DRIdrawable * draw,
int32_t * numerator, int32_t * denominator, void *private)
i++;
}
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
/*@}*/
+#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.
GLX_FUNCTION(glXQueryDrawable),
GLX_FUNCTION(glXSelectEvent),
+#ifndef GLX_USE_APPLEGL
/*** GLX_SGI_swap_control ***/
GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
GLX_FUNCTION(glXImportContextEXT),
GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
+#endif
/*** GLX_SGIX_fbconfig ***/
GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
+#ifndef GLX_USE_APPLEGL
/*** GLX_SGIX_pbuffer ***/
GLX_FUNCTION(glXCreateGLXPbufferSGIX),
GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
GLX_FUNCTION2(glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA),
GLX_FUNCTION2(glXGetFrameUsageMESA, __glXGetFrameUsageMESA),
GLX_FUNCTION2(glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA),
+#endif
/*** GLX_ARB_get_proc_address ***/
GLX_FUNCTION(glXGetProcAddressARB),
/*** GLX 1.4 ***/
GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
+#ifndef GLX_USE_APPLEGL
/*** GLX_OML_sync_control ***/
GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
/*** GLX_EXT_texture_from_pixmap ***/
GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
+#endif
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
/*** DRI configuration ***/
GLX_FUNCTION(glXGetScreenDriver),
GLX_FUNCTION(glXGetDriverConfig),
{NULL, NULL} /* end of list */
};
-
+#ifndef GLX_USE_APPLEGL
static const GLvoid *
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
* 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;
}
#endif /* __GNUC__ */
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
/**
* Get the unadjusted system time (UST). Currently, the UST is measured in
* microseconds since Epoc. The actual resolution of the UST may vary from