void QGLExtensions::init() { static bool init_done = false; if (init_done) return; init_done = true; GLint attribs[] = { AGL_RGBA, AGL_NONE }; AGLPixelFormat fmt = aglChoosePixelFormat(0, 0, attribs); if (!fmt) { qDebug("QGLExtensions: Couldn't find any RGB visuals"); return; } AGLContext ctx = aglCreateContext(fmt, 0); if (!ctx) { qDebug("QGLExtensions: Unable to create context"); } else { aglSetCurrentContext(ctx); init_extensions(); aglSetCurrentContext(0); aglDestroyContext(ctx); } aglDestroyPixelFormat(fmt); }
void OSXCarbonContext::setCurrent() { // Apple's docs claim that you may need to force the context to null // before setting current, especially when using pBuffers. aglSetCurrentContext(NULL); aglSetCurrentContext(mAGLContext); }
glitz_status_t glitz_agl_query_extensions (glitz_agl_thread_info_t *thread_info) { GLint attrib[] = { AGL_RGBA, AGL_NO_RECOVERY, AGL_NONE }; AGLPixelFormat pf; AGLContext context; thread_info->agl_feature_mask = 0; pf = aglChoosePixelFormat (NULL, 0, attrib); context = aglCreateContext (pf, NULL); if (context) { const char *gl_extensions_string; aglSetCurrentContext (context); gl_extensions_string = (const char *) glGetString (GL_EXTENSIONS); thread_info->agl_feature_mask = glitz_extensions_query (0.0, gl_extensions_string, agl_extensions); if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_MULTISAMPLE_MASK) { const char *vendor; vendor = glGetString (GL_VENDOR); if (vendor) { /* NVIDIA's driver seem to support multisample with pbuffers */ if (!strncmp ("NVIDIA", vendor, 6)) thread_info->agl_feature_mask |= GLITZ_AGL_FEATURE_PBUFFER_MULTISAMPLE_MASK; } } aglSetCurrentContext (NULL); aglDestroyContext (context); } aglDestroyPixelFormat (pf); return GLITZ_STATUS_SUCCESS; }
static void init_gl(WindowRef wref) { GLint major, minor; aglGetVersion(&major, &minor); SkDebugf("---- agl version %d %d\n", major, minor); const GLint pixelAttrs[] = { AGL_RGBA, AGL_DEPTH_SIZE, 32, AGL_OFFSCREEN, AGL_NONE }; AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); SkDebugf("----- agl format %p\n", format); gAGLContext = aglCreateContext(format, NULL); SkDebugf("----- agl context %p\n", gAGLContext); aglDestroyPixelFormat(format); aglEnable(gAGLContext, GL_BLEND); aglEnable(gAGLContext, GL_LINE_SMOOTH); aglEnable(gAGLContext, GL_POINT_SMOOTH); aglEnable(gAGLContext, GL_POLYGON_SMOOTH); aglSetCurrentContext(gAGLContext); }
void _glfwPlatformCloseWindow( void ) { if( _glfwWin.WindowFunctions != NULL ) { if( _glfwWin.WindowUPP != NULL ) { DisposeEventHandlerUPP( _glfwWin.WindowUPP ); _glfwWin.WindowUPP = NULL; } _glfwWin.WindowFunctions->CloseWindow(); if( _glfwWin.AGLContext != NULL ) { aglSetCurrentContext( NULL ); aglSetDrawable( _glfwWin.AGLContext, NULL ); aglDestroyContext( _glfwWin.AGLContext ); _glfwWin.AGLContext = NULL; } if( _glfwWin.MacWindow != NULL ) { ReleaseWindow( _glfwWin.MacWindow ); _glfwWin.MacWindow = NULL; } _glfwWin.WindowFunctions = NULL; } }
AGLContext create_gl(WindowRef wref) { GLint major, minor; AGLContext ctx; aglGetVersion(&major, &minor); SkDebugf("---- agl version %d %d\n", major, minor); const GLint pixelAttrs[] = { AGL_RGBA, AGL_STENCIL_SIZE, 8, #if USE_MSAA AGL_SAMPLE_BUFFERS_ARB, 1, AGL_MULTISAMPLE, AGL_SAMPLES_ARB, 8, #endif AGL_ACCELERATED, AGL_DOUBLEBUFFER, AGL_NONE }; AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs); //AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); SkDebugf("----- agl format %p\n", format); ctx = aglCreateContext(format, NULL); SkDebugf("----- agl context %p\n", ctx); aglDestroyPixelFormat(format); static const GLint interval = 1; aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval); aglSetCurrentContext(ctx); return ctx; }
Error ContextGL_OSX::initialize() { if ((Ptr)kUnresolvedCFragSymbolAddress == (Ptr)aglChoosePixelFormat) return FAILED; GLint attributes[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 32, AGL_NO_RECOVERY, AGL_NONE, AGL_NONE }; AGLPixelFormat format = NULL; format = aglChoosePixelFormat(NULL, 0, attributes); if (!format) return FAILED; context = aglCreateContext(format, 0); if (!context) return FAILED; aglDestroyPixelFormat(format); aglSetWindowRef(context, window); GLint swapInterval = 1; aglSetInteger(context, AGL_SWAP_INTERVAL, &swapInterval); aglSetCurrentContext(context); return OK; }
/** * fv_bind_GLcontext: attache the OpenGL context to the main window. * TODO: finish implementation for Mac and Windows. */ bool fv_bind_GLcontext() { fwl_thread_dump(); #if defined(TARGET_X11) || defined(TARGET_MOTIF) if (!Xwin) { ERROR_MSG("window not initialized, can't initialize OpenGL context.\n"); return FALSE; } if (!glXMakeCurrent(Xdpy, GLwin, GLcx)) { /* ERROR_MSG("fv_bind_GLcontext: can't set OpenGL context for this thread %d (glXMakeCurrent: %s).\n", fw_thread_id(), GL_ERROR_MSG); */ ERROR_MSG("fv_bind_GLcontext: can't set OpenGL context for this thread %d , glGetError=%d).\n", fw_thread_id(), glGetError()); return FALSE; } #endif #if defined(TARGET_AQUA) return aglSetCurrentContext(aqglobalContext); #endif #if defined(TARGET_WIN32) return wglMakeCurrent(ghDC, ghRC); #endif return TRUE; }
void Window::configExit() { WindowRef window = getCarbonWindow(); setCarbonWindow( 0 ); AGLContext context = getAGLContext(); if( getIAttribute( WindowSettings::IATTR_HINT_FULLSCREEN ) == ON ) { LBASSERT( !window ); exitEventHandler(); } else if( window ) { Global::enterCarbon(); aglSetWindowRef( context, 0 ); DisposeWindow( window ); Global::leaveCarbon(); } configExitFBO(); exitGLEW(); if( context ) { Global::enterCarbon(); aglSetCurrentContext( 0 ); aglDestroyContext( context ); Global::leaveCarbon(); setAGLContext( 0 ); } LBVERB << "Destroyed AGL window and context" << std::endl; }
bool wxGLContext::SetCurrent(const wxGLCanvas& win) const { if ( !m_glContext ) return false; AGLDrawable drawable = (AGLDrawable)GetWindowPort( MAC_WXHWND(win.MacGetTopLevelWindowRef())); GLint bufnummer = win.GetAglBufferName(); aglSetInteger(m_glContext, AGL_BUFFER_NAME, &bufnummer); //win.SetLastContext(m_glContext); const_cast<wxGLCanvas&>(win).SetViewport(); if ( !aglSetDrawable(m_glContext, drawable) ) { wxLogAGLError("aglSetDrawable"); return false; } if ( !aglSetCurrentContext(m_glContext) ) { wxLogAGLError("aglSetCurrentContext"); return false; } return true; }
bool AquaOglGlue::init(int argc, char **argv[]) { // GNASH_REPORT_FUNCTION; #ifdef FIX_I810_LOD_BIAS int c = getopt (argc, *argv, "m:"); if (c == 'm') { _tex_lod_bias = (float) strtof(optarg, NULL); } #endif const GLint glattribs[] = { AGL_RGBA, AGL_ACCELERATED, AGL_DEPTH_SIZE, 32, AGL_ACCUM_RED_SIZE, 8, AGL_ACCUM_GREEN_SIZE, 8, AGL_ACCUM_RED_SIZE, 8, AGL_ACCUM_ALPHA_SIZE, 8, AGL_DOUBLEBUFFER, AGL_NONE }; AGLPixelFormat pixfmt = aglChoosePixelFormat ( NULL, 0, glattribs); _context = aglCreateContext (pixfmt, NULL); if (!_context) { aglDestroyPixelFormat(pixfmt); return false; } bool ret = aglSetCurrentContext(_context); aglDestroyPixelFormat(pixfmt); return ret; }
wxGLContext::wxGLContext( AGLPixelFormat fmt, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; #ifndef __LP64__ m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef())); #endif m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); GLboolean b; #ifndef __LP64__ b = aglSetDrawable(m_glContext, m_drawable); aglEnable(m_glContext , AGL_BUFFER_RECT ) ; #else b = aglSetHIViewRef(m_glContext, (HIViewRef) win->GetHandle()); #endif wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); b = aglSetCurrentContext(m_glContext); wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); }
void CL_DisplayWindow_OpenGL::destroy_window() { install_event_handler(0, 1); if (context) aglSetCurrentContext(0); if (fs_context) { aglDestroyContext(fs_context); fs_context = 0; } if (win_context) { aglDestroyContext(win_context); win_context = 0; } keyboard = CL_InputDevice(); mouse = CL_InputDevice(); get_ic()->clear(); if (window_ref) ReleaseWindow(window_ref); window_ref = 0; }
bool OPENGL_PBUFFER:: Create(int width, int height) { if (pbuffer) { LOG::cerr << "Destroying old pbuffer before creating new one" << std::endl; Destroy(); } GLint attributes[] = {AGL_RGBA,AGL_DOUBLEBUFFER,AGL_NONE}; AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, attributes); if(format==NULL){ LOG::cout<<"Could not set up the pixel format"<<std::endl;return false;} AGLContext context = aglCreateContext(format, NULL); if(context==NULL){ LOG::cout<<"Could not set up the pbuffer context"<<std::endl;return false;} aglSetCurrentContext(context); if(!aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0, &pbuffer)){ LOG::cout<<"Error: couldn't create pbuffer"<<std::endl; LOG::cout<<aglErrorString(aglGetError()); return false; } if(!aglSetPBuffer(context, pbuffer, 0, 0, aglGetVirtualScreen(context))){ LOG::cout<<"Error: couldn't set pbuffer"<<std::endl; LOG::cout<<aglErrorString(aglGetError()); return false; } return true; /* Success!! */ }
AGLContext Window::createAGLContext( AGLPixelFormat pixelFormat ) { if( !pixelFormat ) { sendError( ERROR_SYSTEMWINDOW_NO_PIXELFORMAT ); return 0; } const WindowIF* aglShareWindow = dynamic_cast< const WindowIF* >( getSharedContextWindow( )); AGLContext shareCtx = aglShareWindow ? aglShareWindow->getAGLContext() : 0; Global::enterCarbon(); AGLContext context = aglCreateContext( pixelFormat, shareCtx ); if( !context ) { sendError( ERROR_AGLWINDOW_CREATECONTEXT_FAILED ) << aglError(); Global::leaveCarbon(); return 0; } _initSwapSync( context ); aglSetCurrentContext( context ); Global::leaveCarbon(); LBVERB << "Created AGL context " << context << " shared with " << shareCtx << std::endl; return context; }
void wxGLContext::SetCurrent() { if (m_glContext) { aglSetCurrentContext(m_glContext); } }
void Window::doneCurrent() const { if( !isCurrent( )) return; aglSetCurrentContext( 0 ); WindowIF::doneCurrent(); }
void windowResize(GLWindow *glw, uint32 newH, uint32 newW) { glw->winH = newH; glw->winW = newW; aglSetCurrentContext(glw->glCtx); aglSetDrawable(glw->glCtx, NULL); aglSetDrawable(glw->glCtx, GetWindowPort(glw->pWin)); }
void AquaOglGlue::render() { GNASH_REPORT_FUNCTION; assert(aglSetCurrentContext(_context)); aglUpdateContext(_context); aglSwapBuffers(_context); }
wxGLContext::~wxGLContext() { if (m_glContext) { aglSetCurrentContext(NULL); aglDestroyContext(m_glContext); } }
static void deleteContext(AGLContext ctx) { if (g_Window.fs) { aglSetFullScreen(ctx, 0, 0, 0, 0); } else { aglSetWindowRef(ctx, 0); } aglSetCurrentContext(0); aglDestroyContext(ctx); }
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); }
bool WXGLSetCurrentContext(WXGLContext context) { if ( !aglSetCurrentContext(context) ) { wxLogAGLError("aglSetCurrentContext"); return false; } return true; }
bool SkEGLContext::init(int width, int height) { GLint major, minor; AGLContext ctx; aglGetVersion(&major, &minor); //SkDebugf("---- agl version %d %d\n", major, minor); const GLint pixelAttrs[] = { AGL_RGBA, AGL_STENCIL_SIZE, 8, /* AGL_SAMPLE_BUFFERS_ARB, 1, AGL_MULTISAMPLE, AGL_SAMPLES_ARB, 2, */ AGL_ACCELERATED, AGL_NONE }; AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs); //AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); //SkDebugf("----- agl format %p\n", format); ctx = aglCreateContext(format, NULL); //SkDebugf("----- agl context %p\n", ctx); aglDestroyPixelFormat(format); /* static const GLint interval = 1; aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval); */ aglSetCurrentContext(ctx); this->context = ctx; // Now create our FBO render target GLuint fboID; GLuint cbID; GLuint dsID; glGenFramebuffersEXT(1, &fboID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID); glGenRenderbuffers(1, &cbID); glBindRenderbuffer(GL_RENDERBUFFER, cbID); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cbID); glGenRenderbuffers(1, &dsID); glBindRenderbuffer(GL_RENDERBUFFER, dsID); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, dsID); glViewport(0, 0, width, height); glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); return GL_FRAMEBUFFER_COMPLETE == status; }
static void RLXAPI ReleaseSurfaces(void) { if (!g_pAGLC) return; aglSetCurrentContext(NULL); aglSetDrawable(g_pAGLC, NULL); aglDestroyContext(g_pAGLC); g_pAGLC = 0; g_pRLX->pGX->Surfaces.maxSurface = 0; }
/* Make the current context active */ int Mac_GL_MakeCurrent(_THIS) { int retval; retval = 0; if( ! aglSetCurrentContext(glContext) ) { SDL_SetError("Unable to make GL context current"); retval = -1; } return(retval); }
void Mac_GL_Quit(_THIS) { #ifdef HAVE_OPENGL if ( glContext != NULL ) { aglSetCurrentContext(NULL); aglSetDrawable(glContext, NULL); aglDestroyContext(glContext); glContext = NULL; } #endif }
void windowClear(GLWindow *glw) { if(glw->glCtx) aglSetCurrentContext(glw->glCtx); else return; //glCam.Initialize(glw->pWin); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); aglSwapBuffers(glw->glCtx); }
static OSStatus handleKeyEvent(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus err; // Try to determine the size of the text input ::UInt32 actualSize; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, 0, &actualSize, 0); if (err != noErr) return err; // The input can actually consist of more than one character. // We are only interested in single character input if (actualSize == sizeof(UniChar)) { // Get the character unicode UniChar c; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, sizeof(UniChar), 0, &c); if (err != noErr) return err; // Handle different keyboard commands aglSetCurrentContext(win->getContext()); switch (c) { case kEscapeCharCode: QuitApplicationEventLoop(); break; case 'a': glDisable( GL_LIGHTING ); redraw(); break; case 's': glEnable( GL_LIGHTING ); redraw(); break; case 'z': glPolygonMode( GL_FRONT_AND_BACK, GL_POINT); redraw(); break; case 'x': glPolygonMode( GL_FRONT_AND_BACK, GL_LINE); redraw(); break; case 'c': glPolygonMode( GL_FRONT_AND_BACK, GL_FILL); redraw(); break; } } return noErr; }
void Window::makeCurrent( const bool cache ) const { if( cache && isCurrent( )) return; aglSetCurrentContext( _impl->aglContext ); WindowIF::makeCurrent(); if( _impl->aglContext ) { EQ_GL_ERROR( "After aglSetCurrentContext" ); } }