extern void glo_context_destroy(GloContext *context);
/* Update the context in surface and free previous light-weight context */
-extern int glo_surface_update_context(GloSurface *surface, GloContext *context);
+extern void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags);
/* Link the pixmap associated with surface as texture */
extern void glo_surface_as_texture(GloSurface *surface);
default: fprintf(stderr, "got unsupported stencil %d", s); break;
}
}
- GloContext *context = (GloContext *)malloc(sizeof(*context));
+ GloContext *context = (GloContext *)g_malloc(sizeof(*context));
memset(context, 0, sizeof(*context));
context->formatFlags = formatFlags;
context->pixelFormat = pf;
GloContext *glo_context_create(int formatFlags, GloContext *shareLists)
{
- GloContext *context = __glo_context_create(formatFlags);
- if(!context)
- return NULL;
+ GloContext *context = __glo_context_create(formatFlags);
+ if(!context)
+ return NULL;
- context->context = aglCreateContext(context->pixelFormat, shareLists ? shareLists->context : NULL);
- if (context->context == NULL)
- {
- fprintf(stderr, "aglCreateContext failed: %s", aglErrorString(aglGetError()));
- }
+ context->context = aglCreateContext(context->pixelFormat, shareLists ? shareLists->context : NULL);
+ if (context->context == NULL)
+ {
+ fprintf(stderr, "aglCreateContext failed: %s", aglErrorString(aglGetError()));
+ }
+ else
+ {
+ if(context->pixelFormat != NULL)
+ {
+ aglDestroyPixelFormat(context->pixelFormat);
+ context->pixelFormat = NULL;
+ }
+ }
- TRACE("context=%p", context);
- return context;
+ TRACE("context=%p", context);
+ return context;
}
-
+
/* Destroy a previously created OpenGL context */
void glo_context_destroy(GloContext *context)
{
TRACE("context=%p", context);
if (context)
{
- aglDestroyContext(context->context);
- aglDestroyPixelFormat(context->pixelFormat);
- context->context = NULL;
- context->pixelFormat = NULL;
- free(context);
+ aglDestroyContext(context->context);
+ if(context->pixelFormat != NULL)
+ {
+ aglDestroyPixelFormat(context->pixelFormat);
+ context->pixelFormat = NULL;
+ }
+ context->context = NULL;
+ g_free(context);
}
}
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
{
-
- int prev_context_valid = 0;
-
if ( surface->context )
{
- prev_context_valid = (surface->context->context != 0);
- if ( !prev_context_valid ) /* light-weight context */
- g_free(surface->context);
+ if (free_flags) /* light-weight context */
+ g_free(surface->context);
}
surface->context = context;
-
- return prev_context_valid;
}
GloSurface *surface = NULL;
if (context)
{
- surface = (GloSurface *)malloc(sizeof(*surface));
+ surface = (GloSurface *)g_malloc(sizeof(*surface));
memset(surface, 0, sizeof(*surface));
surface->width = width;
surface->height = height;
{
aglDestroyPBuffer(surface->pbuffer);
surface->pbuffer = NULL;
- free(surface);
+ g_free(surface);
}
}
/* ------------------------------------------------------------------------ */
/* Update the context in surface and handle previous context */
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
{
/* If previous context is light-weight context, just free it. If previous
* context is valid one binded with surface via MakeCurrent, we need unbind
* from original glstate */
- int prev_context_valid = 0;
if ( surface->context )
{
- prev_context_valid = (surface->context->hContext != 0);
- if ( !prev_context_valid ) /* light-weight context */
+ if ( free_flags) /* light-weight context */
g_free(surface->context);
}
surface->context = context;
- return prev_context_valid;
}
/* Create a surface with given width and height, formatflags are from the
/* ------------------------------------------------------------------------ */
/* Update the context in surface and handle previous context */
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
{
/* If previous context is light-weight context, just free it. If previous
* context is valid one binded with surface via MakeCurrent, we need unbind
* from original glstate */
- int prev_context_valid = 0;
if ( surface->context )
{
- prev_context_valid = (surface->context->context != 0);
- if ( !prev_context_valid ) /* light-weight context */
+ if ( free_flags ) /* light-weight context */
g_free(surface->context);
}
surface->context = context;
- return prev_context_valid;
}
/* Create a surface with given width and height, formatflags are from the
SURFACE_PBUFFER,
};
+enum {
+ SURFACE_PENDING, /* Created with light-weight context */
+ SURFACE_ACTIVE, /* Ready after MakeCurrent */
+};
+
typedef struct QGloSurface {
GLState *glstate;
GloSurface *surface;
ClientGLXDrawable *client_drawable;
int type; /* window, pixmap or pbuffer */
int ready;
+ int status;
int ref;
QTAILQ_ENTRY(QGloSurface) next;
} QGloSurface;
QTAILQ_FOREACH(qsurface, &state->qsurfaces, next) {
if(qsurface->client_drawable == client_drawable) {
state->current_qsurface = qsurface;
+ qsurface->glstate = state;
return 1;
}
}
#endif
qsurface->ref = 1;
- if ( glo_surface_update_context(qsurface->surface, glstate->context) )
- unbind_qsurface(qsurface->glstate, qsurface);
+ if(qsurface->status == SURFACE_PENDING)
+ {
+ glo_surface_update_context(qsurface->surface, glstate->context, 1);
+ qsurface->status = SURFACE_ACTIVE;
+ }
+ else
+ {
+ unbind_qsurface(qsurface->glstate, qsurface);
+ glo_surface_update_context(qsurface->surface, glstate->context, 0);
+
+ }
+
bind_qsurface(glstate, qsurface);
return 1;
}
DEBUGF( "glXCreatePixmap: %dX%d.\n", width, height);
qsurface->surface = glo_surface_create(width, height, context);
qsurface->client_drawable = client_drawable;
- qsurface->type = SURFACE_PIXMAP;
+ qsurface->type = SURFACE_PIXMAP;
+ qsurface->status = SURFACE_PENDING;
/* qsurface->ref = 1;*/
/* Keep this surface, will link it with context in MakeCurrent */
glColorPointer(4, GL_UNSIGNED_BYTE, stride,
ptr + 6 * sizeof(float));
glDrawArrays(mode, 0, count);
+
+#ifdef __APPLE__ //only for mac
+ {
+ int prev_fbo;
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+ if ( prev_fbo != 0 )
+ glFlush();
+ }
+#endif
+
+
break;
}
case _glDrawElements_buffer_func:
{
glDrawElements(args[0], args[1], args[2], (void *) args[3]);
+
+#ifdef __APPLE__ //only for mac
+ {
+ int prev_fbo;
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+ if ( prev_fbo != 0 )
+ glFlush();
+ }
+#endif
+
break;
}
#ifndef _WIN32
(int, int *, int, void **, int));
ptr_func_glMultiDrawElements(args[0], (int *) args[1], args[2],
(void **) args[3], args[4]);
+#ifdef __APPLE__ //only for mac
+ {
+ int prev_fbo;
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+ if ( prev_fbo != 0 )
+ glFlush();
+ }
+#endif
+
break;
}
+#ifdef __APPLE__ // only for mac
+ case glDrawArrays_func:
+ {
+ int prev_fbo;
+ glDrawArrays(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]));
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+ if ( prev_fbo != 0 )
+ glFlush();
+ break;
+ }
+ case glDrawElements_func:
+ {
+ int prev_fbo;
+ glDrawElements(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), (const void*)(args[3]));
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+ if ( prev_fbo != 0 )
+ glFlush();
+ break;
+ }
+#endif
case _glGetError_fake_func:
{