static void _glitz_agl_context_update (glitz_agl_drawable_t *drawable, glitz_constraint_t constraint) { AGLContext context; drawable->base.flushed = drawable->base.finished = 0; switch (constraint) { case GLITZ_NONE: break; case GLITZ_ANY_CONTEXT_CURRENT: context = aglGetCurrentContext (); if (context == (AGLContext) 0) _glitz_agl_context_make_current (drawable, 0); break; case GLITZ_CONTEXT_CURRENT: context = aglGetCurrentContext (); if (context != drawable->context->context) _glitz_agl_context_make_current (drawable, (context)? 1: 0); break; case GLITZ_DRAWABLE_CURRENT: if (drawable->base.width != drawable->width || drawable->base.height != drawable->height) glitz_agl_drawable_update_size (drawable, drawable->base.width, drawable->base.height); context = aglGetCurrentContext (); if (context != drawable->context->context) { _glitz_agl_context_make_current (drawable, (context)? 1: 0); } else { if (drawable->pbuffer) { AGLPbuffer pbuffer; GLint unused; aglGetPBuffer (drawable->context->context, &pbuffer, &unused, &unused, &unused); if (pbuffer != drawable->pbuffer) _glitz_agl_context_make_current (drawable, (context)? 1: 0); } else if (drawable->drawable) { if (aglGetDrawable (drawable->context->context) != drawable->drawable) _glitz_agl_context_make_current (drawable, (context)? 1: 0); } } break; } }
COffscreenGLContext::COffscreenGLContext() { //FIXME: couldn't test this code myself! (coded from online documentations) AGLContext currentCtx = aglGetCurrentContext(); if (!currentCtx) throw opengl_error("Couldn't create an offscreen GL context: aglGetCurrentContext/aglGetCurrentDrawable failed!"); //! Get PixelFormat int attributeList[] = { AGL_ACCELERATED, AGL_RGBA, //AGL_OFFSCREEN, //AGL_DISPLAY_MASK, 1 //FIXME: detect SDL Window's CGOpenGLDisplayMask AGL_NONE }; pxlfmt = aglChoosePixelFormat(NULL, 0, attributeList); if (!pxlfmt) throw opengl_error("Couldn't create an offscreen GL context: aglChoosePixelFmt failed!"); //! Create Shared Context workerCtx = aglCreateContext(pxlfmt, currentCtx); if (!workerCtx) throw opengl_error("Couldn't create an offscreen GL context: aglCreateContext failed!"); }
void ivis_start( ITunesVis* plugin ) { /* make sure we have a plugin and a visual handler */ if ( !plugin || !plugin->imports.visual_handler ) return; /* if we don't have an offscreen buffer, create one */ if ( ! plugin->screen ) plugin->screen = get_view( plugin->rect.right, plugin->rect.bottom ); /* customize the show window message */ memset( &plugin->visual_message.u.showWindowMessage, 0, sizeof(plugin->visual_message.u.showWindowMessage) ); plugin->visual_message.u.showWindowMessage.GRAPHICS_DEVICE_NAME = plugin->screen; plugin->visual_message.u.showWindowMessage.drawRect = plugin->rect; plugin->visual_message.u.showWindowMessage.options = 0; plugin->visual_message.u.showWindowMessage.totalVisualizerRect = plugin->rect; /* set our start time */ plugin->start_time = ivis_current_time(); /* send the show window message */ CGLContextObj currentContext = CGLGetCurrentContext(); plugin->imports.visual_handler( kVisualPluginEnableMessage, &( plugin->visual_message ), plugin->vis_ref ); plugin->imports.visual_handler( kVisualPluginShowWindowMessage, &( plugin->visual_message ), plugin->vis_ref ); plugin->imports.visual_handler( kVisualPluginUpdateMessage, &( plugin->visual_message ), plugin->vis_ref ); plugin->gl_context = (void*)aglGetCurrentContext(); CGLSetCurrentContext( currentContext ); }
void DoDrag(WindowPtr myWindow, Point mouseloc) { Rect dragBounds; dragBounds = (**GetGrayRgn()).rgnBBox; DragWindow(myWindow,mouseloc,&dragBounds); aglUpdateContext(aglGetCurrentContext()); }
void QGLContext::doneCurrent() { if(aglGetCurrentContext() != (AGLContext) d_func()->cx) return; currentCtx = 0; if (qgl_context_storage.hasLocalData()) qgl_context_storage.localData()->context = 0; aglSetCurrentContext(0); }
Font::Font() { _id = glGenLists(96); #ifdef __APPLE__ Str255 fontName; CopyCStringToPascal("Arial", fontName); _fontType = FMGetFontFamilyFromName(fontName); assert(_fontType != kInvalidFontFamily); aglUseFont(aglGetCurrentContext(), _fontType, bold, 16, 32, 96, _id); #endif }
/////////////////////////////////////////////////////////////////////////////// // Utilities /////////////////////////////////////////////////////////////////////////////// void Window::swap() { # if defined(__X11__) glXSwapBuffers(winSys->dpy, xWindow); # elif defined(__WIN__) SwapBuffers(hDC); # elif defined(__BEWIN__) tWindow->SwapBuffers(); # elif defined(__AGL__) aglSwapBuffers(aglGetCurrentContext()); # endif } // Window::swap
static void DoUpdate(WindowPtr myWindow) { GrafPtr origPort; GetPort(&origPort); SetPort(myWindow); BeginUpdate(myWindow); EndUpdate(myWindow); aglUpdateContext(aglGetCurrentContext()); SetPort(origPort); }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::swapBuffers( bool waitForVSync ) { if(!mIsFullScreen) { if(mAGLContext != aglGetCurrentContext()) aglSetCurrentContext(mAGLContext); aglSwapBuffers(mAGLContext); } else swapCGLBuffers(); if(mHasResized) { windowResized(); mHasResized = false; } }
GLboolean glewCreateContext () { int attrib[] = { AGL_RGBA, AGL_NONE }; AGLPixelFormat pf; /*int major, minor; SetPortWindowPort(wnd); aglGetVersion(&major, &minor); fprintf(stderr, "GL %d.%d\n", major, minor);*/ pf = aglChoosePixelFormat(NULL, 0, attrib); if (NULL == pf) return GL_TRUE; ctx = aglCreateContext(pf, NULL); if (NULL == ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE; aglDestroyPixelFormat(pf); /*aglSetDrawable(ctx, GetWindowPort(wnd));*/ octx = aglGetCurrentContext(); if (NULL == aglSetCurrentContext(ctx)) return GL_TRUE; return GL_FALSE; }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::setVSyncEnabled(bool vsync) { mVSync = vsync; mContext->setCurrent(); CGLContextObj share = NULL; aglGetCGLContext(mAGLContext, (void**)&share); GLint vsyncInterval = mVSync ? 1 : 0; aglSetInteger(mAGLContext, AGL_SWAP_INTERVAL, &vsyncInterval); mContext->endCurrent(); if(!mIsFullScreen) { if(mAGLContext != aglGetCurrentContext()) aglSetCurrentContext(mAGLContext); } else { if(share != CGLGetCurrentContext()) CGLSetCurrentContext(share); } }
AGLContext carbonWrapperCurrentContext(void) { return aglGetCurrentContext(); }
WXGLContext WXGLGetCurrentContext() { return aglGetCurrentContext(); }
TextWriter::TextWriter(int in_x, int in_y, Renderer &in_renderer, bool in_centered, int in_size, std::wstring fontname) : x(in_x), y(in_y), size(in_size), original_x(0), last_line_height(0), centered(in_centered), renderer(in_renderer) { x += renderer.m_xoffset; original_x = x; y += renderer.m_yoffset; #ifdef WIN32 Context c = renderer.m_context; point_size = MulDiv(size, GetDeviceCaps(c, LOGPIXELSY), 72); HFONT font = 0; if (font_size_lookup[in_size] == 0) { // Set up the LOGFONT structure LOGFONT logical_font; logical_font.lfHeight = get_point_size(); logical_font.lfWidth = 0; logical_font.lfEscapement = 0; logical_font.lfOrientation = 0; logical_font.lfWeight = FW_NORMAL; logical_font.lfItalic = false; logical_font.lfUnderline = false; logical_font.lfStrikeOut = false; logical_font.lfCharSet = ANSI_CHARSET; logical_font.lfOutPrecision = OUT_DEFAULT_PRECIS; logical_font.lfClipPrecision = CLIP_DEFAULT_PRECIS; logical_font.lfQuality = PROOF_QUALITY; logical_font.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; lstrcpy(logical_font.lfFaceName, fontname.c_str()); font = CreateFontIndirect(&logical_font); HFONT previous_font = (HFONT)SelectObject(c, font); wglUseFontBitmaps(c, 0, 128, next_call_list_start); font_size_lookup[in_size] = next_call_list_start; font_handle_lookup[in_size] = font; next_call_list_start += 130; SelectObject(c, previous_font); } #else // TODO: is this sufficient? point_size = size; if (font_size_lookup[size] == 0) { int list_start = glGenLists(128); // MACNOTE: Force Trebuchet MS. It's what we mostly use anyway, but // I want to be sure they have it. const CFStringRef font_name = CFSTR("Trebuchet MS"); ATSFontFamilyRef font = ATSFontFamilyFindFromName(font_name, kATSOptionFlagsDefault); if (!font) throw PianoGameError(WSTRING(L"Couldn't get ATSFontFamilyRef for font '" << WideFromMacString(font_name) << L"'.")); AGLContext context = aglGetCurrentContext(); if (!context) throw PianoGameError(L"Couldn't retrieve OpenGL context while creating font."); GLboolean ret = aglUseFont(context, font, normal, size, 0, 128, list_start); if (ret == GL_FALSE) throw PianoGameError(WSTRING(L"aglUseFont() call failed with error code: " << aglGetError())); font_size_lookup[size] = list_start; // Create the ATSU style object that we'll use for calculating text extents and store it for later. ATSUStyle style; OSStatus status = ATSUCreateStyle(&style); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create ATSU style. Error code: " << static_cast<int>(status))); Fixed fixed_size = Long2Fix(size); ATSUAttributeTag tags[] = { kATSUSizeTag }; ByteCount sizes[] = { sizeof(Fixed) }; ATSUAttributeValuePtr values[] = { &fixed_size }; status = ATSUSetAttributes(style, sizeof(sizes) / sizeof(ByteCount), tags, sizes, values); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't set ATSU style attributes. Error code: " << static_cast<int>(status))); atsu_style_lookup[size] = style; } #endif }
static void _glitz_agl_make_current (void *abstract_drawable, void *abstract_context) { glitz_agl_context_t *context = (glitz_agl_context_t *) abstract_context; glitz_agl_drawable_t *drawable = (glitz_agl_drawable_t *) abstract_drawable; int update = 0; if (drawable->base.width != drawable->width || drawable->base.height != drawable->height) glitz_agl_drawable_update_size (drawable, drawable->base.width, drawable->base.height); if (aglGetCurrentContext () != context->context) { update = 1; } else { if (drawable->pbuffer) { AGLPbuffer pbuffer; GLint unused; aglGetPBuffer (context->context, &pbuffer, &unused, &unused, &unused); if (pbuffer != drawable->pbuffer) update = 1; } else if (drawable->drawable) { if (aglGetDrawable (context->context) != drawable->drawable) update = 1; } } if (update) { if (drawable->thread_info->cctx) { glitz_context_t *ctx = drawable->thread_info->cctx; if (ctx->lose_current) ctx->lose_current (ctx->closure); } if (drawable->pbuffer) { aglSetPBuffer (context->context, drawable->pbuffer, 0, 0, aglGetVirtualScreen (context->context)); context->pbuffer = 1; } else { if (context->pbuffer) { aglSetDrawable (context->context, NULL); context->pbuffer = 0; } aglSetDrawable (context->context, drawable->drawable); } aglSetCurrentContext (context->context); } drawable->thread_info->cctx = &context->base; }
SkNativeGLContext::AutoContextRestore::AutoContextRestore() { fOldAGLContext = aglGetCurrentContext(); }
/* Loads the font named by the X resource "res". Returns an XFontStruct. Also converts the font to a set of GL lists and returns the first list. */ void load_font (Display *dpy, char *res, XFontStruct **font_ret, GLuint *dlist_ret) { XFontStruct *f; #ifdef STANDALONE const char *font = get_string_resource (dpy, res, "Font"); #else const char *font = NULL; #endif const char *def1 = "-*-helvetica-medium-r-normal-*-180-*"; const char *def2 = "fixed"; Font id; int first, last; if (!res || !*res) abort(); if (!font_ret && !dlist_ret) abort(); if (!font) font = def1; f = XLoadQueryFont(dpy, font); if (!f && !!strcmp (font, def1)) { fprintf (stderr, "%s: unable to load font \"%s\", using \"%s\"\n", progname, font, def1); font = def1; f = XLoadQueryFont(dpy, font); } if (!f && !!strcmp (font, def2)) { fprintf (stderr, "%s: unable to load font \"%s\", using \"%s\"\n", progname, font, def2); font = def2; f = XLoadQueryFont(dpy, font); } if (!f) { fprintf (stderr, "%s: unable to load fallback font \"%s\" either!\n", progname, font); exit (1); } id = f->fid; first = f->min_char_or_byte2; last = f->max_char_or_byte2; # ifndef HAVE_COCOA /* Xlib version */ if (dlist_ret) { clear_gl_error (); *dlist_ret = glGenLists ((GLuint) last+1); check_gl_error ("glGenLists"); glXUseXFont(id, first, last-first+1, *dlist_ret + first); check_gl_error ("glXUseXFont"); } # else /* HAVE_COCOA */ { int afid, face, size; afid = jwxyz_font_info (id, &size, &face); if (dlist_ret) { clear_gl_error (); *dlist_ret = glGenLists ((GLuint) last+1); check_gl_error ("glGenLists"); AGLContext ctx = aglGetCurrentContext(); if (! aglUseFont (ctx, afid, face, size, first, last-first+1, *dlist_ret + first)) { check_gl_error ("aglUseFont"); abort(); } } } # endif /* HAVE_COCOA */ if (font_ret) *font_ret = f; }