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 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); }
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 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; }
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; }
void OSXCarbonWindow::createAGLContext(size_t fsaa_samples, int depth) { if(!mAGLContext) { int i = 0; GLint attribs[ 20 ]; attribs[ i++ ] = AGL_NO_RECOVERY; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_ACCELERATED; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_RGBA; attribs[ i++ ] = AGL_DOUBLEBUFFER; attribs[ i++ ] = AGL_ALPHA_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_STENCIL_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_DEPTH_SIZE; attribs[ i++ ] = depth; if(fsaa_samples > 1) { attribs[ i++ ] = AGL_MULTISAMPLE; attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB; attribs[ i++ ] = 1; attribs[ i++ ] = AGL_SAMPLES_ARB; attribs[ i++ ] = fsaa_samples; } attribs[ i++ ] = AGL_NONE; mAGLPixelFormat = aglChoosePixelFormat( NULL, 0, attribs ); if(!mAGLPixelFormat) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create a valid pixel format with selected attributes.", "OSXCarbonWindow::createAGLContext" ); } // Create the AGLContext from our pixel format // Share it with main GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() ); if(mainContext == 0 || !(mainContext->getContextType() == "AGL")) { mAGLContext = aglCreateContext(mAGLPixelFormat, NULL); } else { OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() ); mAGLContext = aglCreateContext(mAGLPixelFormat, context->getContext()); } } }
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; }
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; }
void find (const int *alistp) { const int *blist; int list[32]; if (alistp) blist = alistp; else { list[3] = 42; blist = list; } aglChoosePixelFormat ((GLint *) blist); }
void OSXPBuffer::createPBuffer() { LogManager::getSingleton().logMessage( "OSXPBuffer::createPBuffer()" ); GLint attrib[] = { AGL_NO_RECOVERY, GL_TRUE, AGL_ACCELERATED, GL_TRUE, AGL_RGBA, AGL_NONE }; AGLPixelFormat pixelFormat = aglChoosePixelFormat(NULL, 0, attrib); mAGLContext = aglCreateContext(pixelFormat, NULL); //mAGLContext = aglGetCurrentContext(); aglCreatePBuffer( mWidth, mHeight, GL_TEXTURE_2D, GL_RGBA, 0, &mPBuffer ); GLint vs = aglGetVirtualScreen( mAGLContext ); aglSetPBuffer( mAGLContext, mPBuffer, 0, 0, vs ); mContext = OGRE_NEW OSXCarbonContext(mAGLContext, pixelFormat); }
static AGLContext HIOpenGLViewGetContext (HIOpenGLViewData* inData) { // If the OpenGL context hasn't been set up yet, then do so now. if (inData->mContext == nil) { GLint attrib[] = { AGL_RGBA , AGL_DOUBLEBUFFER, AGL_NONE }; AGLPixelFormat fmt = aglChoosePixelFormat(nil, 0, attrib); inData->mContext = aglCreateContext(fmt, nil); aglDestroyPixelFormat(fmt); assert(inData->mContext != nil); HIOpenGLViewSetContextWindowAndBounds(inData); aglSetCurrentContext(inData->mContext); } return inData->mContext; }
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 OSXWindowImpl::init_gl() { GLint attributes[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_LEVEL, 1, AGL_WINDOW, GL_TRUE, AGL_DEPTH_SIZE, 1, AGL_NONE }; AGLPixelFormat pf = aglChoosePixelFormat(NULL,0,attributes); assert(pf); mGLContext = aglCreateContext( pf, NULL ); assert(mGLContext); GLboolean b = aglSetDrawable( mGLContext, GetWindowPort(mWindowRef) ); assert(b); aglSetCurrentContext(mGLContext); }
const GrGLInterface* SkNativeGLContext::createGLContext() { GLint major, minor; AGLContext ctx; aglGetVersion(&major, &minor); //SkDebugf("---- agl version %d %d\n", major, minor); const GLint pixelAttrs[] = { AGL_RGBA, AGL_ACCELERATED, AGL_NONE }; AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs); if (NULL == format) { SkDebugf("Format could not be found.\n"); this->destroyGLContext(); return NULL; } fContext = aglCreateContext(format, NULL); if (NULL == fContext) { SkDebugf("Context could not be created.\n"); this->destroyGLContext(); return NULL; } aglDestroyPixelFormat(format); aglSetCurrentContext(fContext); const GrGLInterface* interface = GrGLCreateNativeInterface(); if (NULL == interface) { SkDebugf("Context could not create GL interface.\n"); this->destroyGLContext(); return NULL; } return interface; }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams ) { bool hasDepthBuffer; String title = name; size_t fsaa_samples = 0; int left = 0; int top = 0; int depth = 32; if( miscParams ) { NameValuePairList::const_iterator opt = NULL; // Full screen anti aliasing opt = miscParams->find( "FSAA" ); if( opt != miscParams->end() ) fsaa_samples = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "left" ); if( opt != miscParams->end() ) left = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "top" ); if( opt != miscParams->end() ) top = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "title" ); if( opt != miscParams->end() ) title = opt->second; opt = miscParams->find( "depthBuffer" ); if( opt != miscParams->end() ) hasDepthBuffer = StringConverter::parseBool( opt->second ); opt = miscParams->find( "colourDepth" ); if( opt != miscParams->end() ) depth = StringConverter::parseUnsignedInt( opt->second ); } if(fullScreen) { GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext *mainContext = (OSXContext*)rs->_getMainContext(); CGLContextObj share = NULL; if(mainContext == 0) { share = NULL; } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* aglShare = static_cast<OSXCarbonContext*>(mainContext); aglGetCGLContext(aglShare->getContext(), &((void*)share)); } else if(mainContext->getContextType() == "CGL") { OSXCGLContext* cglShare = static_cast<OSXCGLContext*>(mainContext); share = cglShare->getContext(); } // create the context createCGLFullscreen(width, height, depth, fsaa_samples, share); } else { int i = 0; AGLPixelFormat pixelFormat; GLint attribs[ 20 ]; attribs[ i++ ] = AGL_NO_RECOVERY; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_ACCELERATED; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_RGBA; attribs[ i++ ] = AGL_DOUBLEBUFFER; attribs[ i++ ] = AGL_ALPHA_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_STENCIL_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_DEPTH_SIZE; attribs[ i++ ] = depth; if(fsaa_samples > 1) { attribs[ i++ ] = AGL_MULTISAMPLE; attribs[ i++ ] = 1; attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB; attribs[ i++ ] = fsaa_samples; } attribs[ i++ ] = AGL_NONE; pixelFormat = aglChoosePixelFormat( NULL, 0, attribs ); // Create the AGLContext from our pixel format // Share it with main GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() ); if(mainContext == 0) { mAGLContext = aglCreateContext(pixelFormat, NULL); } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() ); AGLContext shared = context->getContext(); mAGLContext = aglCreateContext(pixelFormat, context->getContext()); } else { // If we do not have an AGL, we can not clone it using this window LogManager::getSingleton().logMessage( "Warning: You asked to create a second window, " "when the previous window was not of this type. OgreOSXCarbonWindow can only share " "with an AGL context."); } NameValuePairList::const_iterator opt = 0; if(miscParams) opt = miscParams->find("externalWindowHandle"); if(!miscParams || opt == miscParams->end()) { // create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = width; windowRect.bottom = height; // set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize" if (miscParams) { opt = miscParams->find("border"); if( opt != miscParams->end() ) { String borderType = opt->second; if( borderType == "none" ) windowAttrs = kWindowNoTitleBarAttribute; else if( borderType == "fixed" ) windowAttrs = kWindowStandardFloatingAttributes; } } windowAttrs |= kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowHideOnFullScreenAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow); // Color the window background black SetThemeWindowBackground (mWindow, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindow, titleRef ); // Center our window on the screen RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen ); // Get our view HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView ); // Set up our UPP for Window Events EventTypeSpec eventSpecs[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowShown}, {kEventClassWindow, kEventWindowHidden}, {kEventClassWindow, kEventWindowDragCompleted}, {kEventClassWindow, kEventWindowBoundsChanged}, {kEventClassWindow, kEventWindowExpanded}, {kEventClassWindow, kEventWindowCollapsed}, {kEventClassWindow, kEventWindowClosed}, {kEventClassWindow, kEventWindowClose} }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler); // Install the standard event handler for the window EventTargetRef target = GetWindowEventTarget(mWindow); InstallStandardEventHandler(target); // We also need to install the WindowEvent Handler, we pass along the window with our requests InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef); // Display and select our window ShowWindow(mWindow); SelectWindow(mWindow); // Add our window to the window event listener class WindowEventUtilities::_addRenderWindow(this); } else { // TODO: The Contol is going to report the incorrect location with a // Metalic / Textured window. The default windows work just fine. // First get the HIViewRef / ControlRef mView = (HIViewRef)StringConverter::parseUnsignedLong(opt->second); mWindow = GetControlOwner(mView); // Lets try hiding the HIView //HIViewSetVisible(mView, false); // Get the rect bounds ::Rect ctrlBounds; GetControlBounds(mView, &ctrlBounds); GLint bufferRect[4]; bufferRect[0] = ctrlBounds.left; // left edge bufferRect[1] = ctrlBounds.bottom; // bottom edge bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable (mAGLContext, AGL_BUFFER_RECT); mIsExternal = true; } // Set the drawable, and current context // If you do this last, there is a moment before the rendering window pops-up // This could go once inside each case above, before the window is displayed, // if desired. aglSetDrawable(mAGLContext, GetWindowPort(mWindow)); aglSetCurrentContext(mAGLContext); // Give a copy of our context to the render system mContext = new OSXCarbonContext(mAGLContext, pixelFormat); } mName = name; mWidth = width; mHeight = height; mActive = true; mClosed = false; mCreated = true; mIsFullScreen = fullScreen; }
/* krat: adding OpenGL support */ int Mac_GL_Init(_THIS) { #ifdef HAVE_OPENGL AGLPixelFormat format; int i = 0; GLint attributes [ 24 ]; /* 24 is max possible in this setup */ GLboolean noerr; attributes[i++] = AGL_RGBA; if ( this->gl_config.red_size != 0 && this->gl_config.blue_size != 0 && this->gl_config.green_size != 0 ) { attributes[i++] = AGL_RED_SIZE; attributes[i++] = this->gl_config.red_size; attributes[i++] = AGL_GREEN_SIZE; attributes[i++] = this->gl_config.green_size; attributes[i++] = AGL_BLUE_SIZE; attributes[i++] = this->gl_config.blue_size; attributes[i++] = AGL_ALPHA_SIZE; attributes[i++] = this->gl_config.alpha_size; } if ( this->gl_config.double_buffer ) { attributes[i++] = AGL_DOUBLEBUFFER; } if ( this->gl_config.depth_size != 0 ) { attributes[i++] = AGL_DEPTH_SIZE; attributes[i++] = this->gl_config.depth_size; } if ( this->gl_config.stencil_size != 0 ) { attributes[i++] = AGL_STENCIL_SIZE; attributes[i++] = this->gl_config.stencil_size; } if ( this->gl_config.accum_red_size != 0 && this->gl_config.accum_blue_size != 0 && this->gl_config.accum_green_size != 0 ) { attributes[i++] = AGL_ACCUM_RED_SIZE; attributes[i++] = this->gl_config.accum_red_size; attributes[i++] = AGL_ACCUM_GREEN_SIZE; attributes[i++] = this->gl_config.accum_green_size; attributes[i++] = AGL_ACCUM_BLUE_SIZE; attributes[i++] = this->gl_config.accum_blue_size; attributes[i++] = AGL_ACCUM_ALPHA_SIZE; attributes[i++] = this->gl_config.accum_alpha_size; } if ( this->gl_config.stereo ) { attributes[i++] = AGL_STEREO; } #if defined(AGL_SAMPLE_BUFFERS_ARB) && defined(AGL_SAMPLES_ARB) if ( this->gl_config.multisamplebuffers != 0 ) { attributes[i++] = AGL_SAMPLE_BUFFERS_ARB; attributes[i++] = this->gl_config.multisamplebuffers; } if ( this->gl_config.multisamplesamples != 0 ) { attributes[i++] = AGL_SAMPLES_ARB; attributes[i++] = this->gl_config.multisamplesamples; } #endif attributes[i++] = AGL_ALL_RENDERERS; attributes[i] = AGL_NONE; format = aglChoosePixelFormat(NULL, 0, attributes); if ( format == NULL ) { SDL_SetError("Couldn't match OpenGL desired format"); return(-1); } glContext = aglCreateContext(format, NULL); if ( glContext == NULL ) { SDL_SetError("Couldn't create OpenGL context"); return(-1); } aglDestroyPixelFormat(format); #if TARGET_API_MAC_CARBON noerr = aglSetDrawable(glContext, GetWindowPort(SDL_Window)); #else noerr = aglSetDrawable(glContext, (AGLDrawable)SDL_Window); #endif if(!noerr) { SDL_SetError("Unable to bind GL context to window"); return(-1); } return(0); #else SDL_SetError("OpenGL support not configured"); return(-1); #endif }
int _glfwPlatformOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode, _GLFWhints* hints ) { OSStatus error; ProcessSerialNumber psn; unsigned int windowAttributes; // TO DO: Refactor this function! _glfwWin.WindowFunctions = ( _glfwWin.Fullscreen ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions ); // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( !_glfwWin.Fullscreen ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; if( hints->Stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, hints->AuxBuffers); _setAGLAttribute( AGL_RED_SIZE, redbits ); _setAGLAttribute( AGL_GREEN_SIZE, greenbits ); _setAGLAttribute( AGL_BLUE_SIZE, bluebits ); _setAGLAttribute( AGL_ALPHA_SIZE, alphabits ); _setAGLAttribute( AGL_DEPTH_SIZE, depthbits ); _setAGLAttribute( AGL_STENCIL_SIZE, stencilbits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, hints->AccumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, hints->AccumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, hints->AccumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, hints->AccumAlphaBits ); if( hints->Samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, hints->Samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( pixelFormat == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a pixel format\n" ); return GL_FALSE; } // store pixel format's values for _glfwPlatformGetWindowParam's use _getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated ); _getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits ); _getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits ); _getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits ); _getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits ); _getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits ); _getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits ); _getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits ); _getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits ); _getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits ); _getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits ); _getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers ); _getAGLAttribute( AGL_STEREO, _glfwWin.Stereo ); _getAGLAttribute( AGL_SAMPLES_ARB, _glfwWin.Samples ); _glfwWin.RefreshRate = hints->RefreshRate; // create AGL context _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL ); aglDestroyPixelFormat( pixelFormat ); if( _glfwWin.AGLContext == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create an OpenGL context\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if (_glfwLibrary.Unbundled) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't get its PSN\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } /* Keith Bauer 2007-07-12 - I don't believe this is desirable if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } */ } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute \ | kWindowCollapseBoxAttribute \ | kWindowStandardHandlerAttribute ); if( hints->WindowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.MacWindow ) ); if( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler ); error = InstallWindowEventHandler( _glfwWin.MacWindow, _glfwWin.WindowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't install window event handlers\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.MacWindow, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.AGLContext, GetWindowPort( _glfwWin.MacWindow ) ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't draw to the window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.AGLContext ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't make the OpenGL context current\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // show window ShowWindow( _glfwWin.MacWindow ); return GL_TRUE; } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; CGLPixelFormatObj CGLpfObj; long numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; GLint rgbaAccumDepth = 0; int rgbChannelDepth = 0; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( hints->Stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( hints->Samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)hints->Samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( hints->AccumRedBits \ + hints->AccumGreenBits \ + hints->AccumBlueBits \ + hints->AccumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphabits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)depthbits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)stencilbits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)hints->AuxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &CGLpfObj, &numCGLvs ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( CGLpfObj, NULL, &_glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAColorSize, &rgbColorDepth ); if( rgbColorDepth == 24 || rgbColorDepth == 32 ) { rgbChannelDepth = 8; } if( rgbColorDepth == 16 ) { rgbChannelDepth = 5; } // get pixel depth of accumulator - I haven't got the slightest idea // how this number conforms to any other channel depth than 8 bits, // so this might end up giving completely knackered results... (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAAccumSize, &rgbaAccumDepth ); if( rgbaAccumDepth == 32 ) { rgbaAccumDepth = 8; } // store values of pixel format for _glfwPlatformGetWindowParam's use _getCGLAttribute( kCGLPFAAccelerated, _glfwWin.Accelerated ); _getCGLAttribute( rgbChannelDepth, _glfwWin.RedBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.GreenBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.BlueBits ); _getCGLAttribute( kCGLPFAAlphaSize, _glfwWin.AlphaBits ); _getCGLAttribute( kCGLPFADepthSize, _glfwWin.DepthBits ); _getCGLAttribute( kCGLPFAStencilSize, _glfwWin.StencilBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumRedBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumGreenBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumBlueBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumAlphaBits ); _getCGLAttribute( kCGLPFAAuxBuffers, _glfwWin.AuxBuffers ); _getCGLAttribute( kCGLPFAStereo, _glfwWin.Stereo ); _glfwWin.RefreshRate = hints->RefreshRate; // destroy our pixel format (void)CGLDestroyPixelFormat( CGLpfObj ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, /* Check further to the right -> */ height, hints->RefreshRate, NULL, NULL ); if( optimalMode == NULL ) { return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } return GL_TRUE; } }
WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList) { GLint data[512]; const GLint defaultAttribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_MINIMUM_POLICY, // never choose less than requested AGL_DEPTH_SIZE, 1, // use largest available depth buffer AGL_RED_SIZE, 1, AGL_GREEN_SIZE, 1, AGL_BLUE_SIZE, 1, AGL_ALPHA_SIZE, 0, AGL_NONE }; const GLint *attribs; if ( !attribList ) { attribs = defaultAttribs; } else { unsigned p = 0; data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX for ( unsigned arg = 0; attribList[arg] !=0 && p < WXSIZEOF(data); ) { switch ( attribList[arg++] ) { case WX_GL_RGBA: data[p++] = AGL_RGBA; break; case WX_GL_BUFFER_SIZE: data[p++] = AGL_BUFFER_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_LEVEL: data[p++]=AGL_LEVEL; data[p++]=attribList[arg++]; break; case WX_GL_DOUBLEBUFFER: data[p++] = AGL_DOUBLEBUFFER; break; case WX_GL_STEREO: data[p++] = AGL_STEREO; break; case WX_GL_AUX_BUFFERS: data[p++] = AGL_AUX_BUFFERS; data[p++] = attribList[arg++]; break; case WX_GL_MIN_RED: data[p++] = AGL_RED_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_GREEN: data[p++] = AGL_GREEN_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_BLUE: data[p++] = AGL_BLUE_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_ALPHA: data[p++] = AGL_ALPHA_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_DEPTH_SIZE: data[p++] = AGL_DEPTH_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_STENCIL_SIZE: data[p++] = AGL_STENCIL_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_ACCUM_RED: data[p++] = AGL_ACCUM_RED_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_ACCUM_GREEN: data[p++] = AGL_ACCUM_GREEN_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_ACCUM_BLUE: data[p++] = AGL_ACCUM_BLUE_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_MIN_ACCUM_ALPHA: data[p++] = AGL_ACCUM_ALPHA_SIZE; data[p++] = attribList[arg++]; break; case WX_GL_SAMPLE_BUFFERS: if ( !wxGLCanvas::IsAGLMultiSampleAvailable() ) { if ( !attribList[arg++] ) break; return false; } data[p++] = AGL_SAMPLE_BUFFERS_ARB; if ( (data[p++] = attribList[arg++]) == true ) { // don't use software fallback data[p++] = AGL_NO_RECOVERY; } break; case WX_GL_SAMPLES: if ( !wxGLCanvas::IsAGLMultiSampleAvailable() ) { if ( !attribList[arg++] ) break; return false; } data[p++] = AGL_SAMPLES_ARB; data[p++] = attribList[arg++]; break; } } data[p] = AGL_NONE; attribs = data; } return aglChoosePixelFormat(NULL, 0, attribs); }
void CL_DisplayWindow_OpenGL::create_window(const CL_DisplayWindowDescription &desc) { OSStatus result; const CL_OpenGLWindowDescription_Generic *gl_desc = 0; gl_desc = dynamic_cast<const CL_OpenGLWindowDescription_Generic*>(desc.impl.get()); fullscreen_width = desc.get_size().width; fullscreen_height = desc.get_size().height; disp_ref_count++; GLint gl_attribs_single[] = { AGL_RGBA, AGL_RED_SIZE, 4, AGL_GREEN_SIZE, 4, AGL_BLUE_SIZE, 4, AGL_DEPTH_SIZE, 16, AGL_NONE }; GLint gl_attribs[32]; int i = 0; if( gl_desc ) { if( gl_desc->rgba ) gl_attribs[i++] = AGL_RGBA; if( gl_desc->doublebuffer ) gl_attribs[i++] = AGL_DOUBLEBUFFER; //if( gl_desc->stereo ) gl_attribs[i++] = AGL_STEREO; gl_attribs[i++] = AGL_BUFFER_SIZE; gl_attribs[i++] = gl_desc->buffer_size; gl_attribs[i++] = AGL_LEVEL; gl_attribs[i++] = gl_desc->level; gl_attribs[i++] = AGL_AUX_BUFFERS; gl_attribs[i++] = gl_desc->aux_buffers; gl_attribs[i++] = AGL_RED_SIZE; gl_attribs[i++] = gl_desc->red_size; gl_attribs[i++] = AGL_GREEN_SIZE; gl_attribs[i++] = gl_desc->green_size; gl_attribs[i++] = AGL_BLUE_SIZE; gl_attribs[i++] = gl_desc->blue_size; gl_attribs[i++] = AGL_DEPTH_SIZE; gl_attribs[i++] = gl_desc->depth_size; gl_attribs[i++] = AGL_STENCIL_SIZE; gl_attribs[i++] = gl_desc->stencil_size; gl_attribs[i++] = AGL_ACCUM_RED_SIZE; gl_attribs[i++] = gl_desc->accum_red_size; gl_attribs[i++] = AGL_ACCUM_GREEN_SIZE; gl_attribs[i++] = gl_desc->accum_green_size; gl_attribs[i++] = AGL_ACCUM_BLUE_SIZE; gl_attribs[i++] = gl_desc->accum_blue_size; gl_attribs[i++] = AGL_ACCUM_ALPHA_SIZE; gl_attribs[i++] = gl_desc->accum_alpha_size; gl_attribs[i++] = AGL_ACCUM_RED_SIZE; gl_attribs[i++] = gl_desc->accum_red_size; // gl_attribs[i++] = AGL_FULLSCREEN; } else { gl_attribs[i++] = AGL_RGBA; gl_attribs[i++] = AGL_NO_RECOVERY; gl_attribs[i++] = AGL_DOUBLEBUFFER; gl_attribs[i++] = AGL_DEPTH_SIZE; gl_attribs[i++] = 16; } /* else { gl_attribs[i++] = AGL_RGBA; gl_attribs[i++] = AGL_DOUBLEBUFFER; gl_attribs[i++] = AGL_RED_SIZE; gl_attribs[i++] = 4; gl_attribs[i++] = AGL_GREEN_SIZE; gl_attribs[i++] = 4; gl_attribs[i++] = AGL_BLUE_SIZE; gl_attribs[i++] = 4; gl_attribs[i++] = AGL_DEPTH_SIZE; gl_attribs[i++] = 16; // gl_attribs[i++] = AGL_FULLSCREEN; } */ gl_attribs[i] = AGL_NONE; CGDirectDisplayID display = CGMainDisplayID(); GDHandle gdhDisplay, *pgdhDisplay; int numDisplay; pgdhDisplay = &gdhDisplay; if (noErr == DMGetGDeviceByDisplayID ((DisplayIDType)display, pgdhDisplay, false)) numDisplay = 1; else { pgdhDisplay = 0; numDisplay = 0; } AGLPixelFormat pixelformat; pixelformat = aglChoosePixelFormat(pgdhDisplay, numDisplay, gl_attribs); win_context = aglCreateContext(pixelformat, share_context); if (!share_context) share_context = win_context; aglDestroyPixelFormat(pixelformat); gl_attribs[i++] = AGL_FULLSCREEN; gl_attribs[i] = AGL_NONE; pixelformat = aglChoosePixelFormat(pgdhDisplay, numDisplay, gl_attribs); fs_context = aglCreateContext(pixelformat, win_context); aglDestroyPixelFormat(pixelformat); if (!(win_context && fs_context)) { printf("Requested visual not supported by your OpenGL implementation. Falling back on singlebuffered Visual!\n"); pixelformat = aglChoosePixelFormat(0, 0, gl_attribs_single); win_context = aglCreateContext(pixelformat, share_context); aglDestroyPixelFormat(pixelformat); fs_context = 0; } WindowAttributes style = kWindowCloseBoxAttribute | kWindowStandardHandlerAttribute; if (desc.get_allow_resize()) style |= kWindowResizableAttribute | kWindowFullZoomAttribute; Rect window_rect; SetRect(&window_rect, 50, 50, 50+desc.get_size().width, 50+desc.get_size().height); result = CreateNewWindow(kDocumentWindowClass, style, &window_rect, &window_ref); if (result != noErr) printf("Could not create window, due to error %d\n", (int)result); // set title of window: set_title(desc.get_title()); // Set standard arrow cursor: InitCursor(); // do we need to do this? -- iMBN, 13. may 2004 // Create input devices for window: keyboard = CL_InputDevice(new CL_InputDevice_MacKeyboard(this)); mouse = CL_InputDevice(new CL_InputDevice_MacMouse(this)); get_ic()->clear(); get_ic()->add_keyboard(keyboard); get_ic()->add_mouse(mouse); // buffer_front = CL_PixelBuffer(new CL_PixelBuffer_OpenGL_Frame(CL_FRONT, gc)); // buffer_back = CL_PixelBuffer(new CL_PixelBuffer_OpenGL_Frame(CL_BACK, gc)); if (!aglSetDrawable(win_context, GetWindowPort(window_ref))) { printf("Unable to set drawable"); } if (desc.is_fullscreen()) set_fullscreen(desc.get_size().width, desc.get_size().height, desc.get_bpp(), desc.get_refresh_rate()); else { fullscreen = true; // not really, but need to fool set_windowed set_windowed(); } ShowWindow(window_ref); }
static int RLXAPI CreateSurface(int numberOfSparePages) { static GLint attrib[32]; GLint *pAttrib = attrib; *pAttrib = AGL_RGBA; pAttrib++; *pAttrib = AGL_DOUBLEBUFFER; pAttrib++; *pAttrib = AGL_NONE; pAttrib++; AGLPixelFormat fmt; GLboolean ok; g_pRLX->pGX->View.lpBackBuffer = NULL; /* Choose an rgb pixel format */ GDHandle gdhDisplay; ok = DMGetGDeviceByDisplayID((DisplayIDType)g_cgDisplayID, &gdhDisplay, false); SYS_ASSERT(ok == noErr); fmt = aglChoosePixelFormat(&gdhDisplay, 1, attrib); SYS_AGLTRACE(0); if(fmt == NULL) { ok = SYS_AGLTRACE(aglGetError()); return -1; } /* Create an AGL context */ g_pAGLC = aglCreateContext(fmt, NULL); SYS_AGLTRACE(0); if(g_pAGLC == NULL) return -2; /* Attach the window to the context */ ok = SYS_AGLTRACE(aglSetDrawable(g_pAGLC, GetWindowPort(g_hWnd))); if(!ok) return -3; /* Make the context the current context */ ok = SYS_AGLTRACE(aglSetCurrentContext(g_pAGLC)); if(!ok) return -4; SizeWindow(g_hWnd, gl_lx, gl_ly, true); if ((g_pRLX->Video.Config & RLXVIDEO_Windowed)) CenterWindow(g_hWnd); ShowWindow(g_hWnd); // copy portRect GetPortBounds(GetWindowPort(g_hWnd), g_pRect); /* Pixel format is no more needed */ aglDestroyPixelFormat(fmt); if (!(g_pRLX->Video.Config & RLXVIDEO_Windowed)) { HideMenuBar(); aglSetFullScreen(g_pAGLC, 0, 0, 0, 0); GLint swap = !!(g_pRLX->pGX->View.Flags & GX_CAPS_VSYNC); aglSetInteger(g_pAGLC, AGL_SWAP_INTERVAL, &swap); SYS_AGLTRACE(0); } // Reset engine GL_InstallExtensions(); GL_ResetViewport(); g_pRLX->pGX->Surfaces.maxSurface = numberOfSparePages;; if (g_pRLX->pGX->View.Flags & GX_CAPS_MULTISAMPLING) { glEnable(GL_MULTISAMPLE_ARB); } return 0; }
bool nglContext::Build(WindowRef Win, const nglContextInfo& rInfo, const nglContext* pShared, bool Fullscreen) { mTargetAPI = rInfo.TargetAPI; #ifndef __NOGLCONTEXT__ mFullscreen = Fullscreen; std::vector<GLint> attribs; attribs.push_back(AGL_RGBA); if (rInfo.FrameCnt != 1) attribs.push_back(AGL_DOUBLEBUFFER); attribs.push_back(AGL_DEPTH_SIZE); attribs.push_back(rInfo.DepthBits); attribs.push_back(AGL_STENCIL_SIZE); attribs.push_back(rInfo.StencilBits); if (rInfo.AuxCnt) { attribs.push_back(AGL_AUX_BUFFERS); attribs.push_back(rInfo.AuxCnt); } if (rInfo.AABufferCnt) { attribs.push_back(AGL_SAMPLE_BUFFERS_ARB); attribs.push_back(rInfo.AABufferCnt); attribs.push_back(AGL_SAMPLES_ARB); attribs.push_back(rInfo.AASampleCnt); } attribs.push_back(AGL_RED_SIZE); attribs.push_back(rInfo.FrameBitsR); attribs.push_back(AGL_GREEN_SIZE); attribs.push_back(rInfo.FrameBitsG); attribs.push_back(AGL_BLUE_SIZE); attribs.push_back(rInfo.FrameBitsB); attribs.push_back(AGL_ALPHA_SIZE); attribs.push_back(rInfo.FrameBitsA); attribs.push_back(AGL_PIXEL_SIZE); attribs.push_back(rInfo.FrameBitsR + rInfo.FrameBitsG + rInfo.FrameBitsB + rInfo.FrameBitsA); if (rInfo.AccumBitsR || rInfo.AccumBitsG || rInfo.AccumBitsB || rInfo.AccumBitsA) { attribs.push_back(AGL_ACCUM_RED_SIZE); attribs.push_back(rInfo.AccumBitsR); attribs.push_back(AGL_ACCUM_GREEN_SIZE); attribs.push_back(rInfo.AccumBitsG); attribs.push_back(AGL_ACCUM_BLUE_SIZE); attribs.push_back(rInfo.AccumBitsB); attribs.push_back(AGL_ACCUM_ALPHA_SIZE); attribs.push_back(rInfo.AccumBitsA); } if (rInfo.Stereo) attribs.push_back(AGL_STEREO); attribs.push_back(AGL_MINIMUM_POLICY); attribs.push_back(AGL_NO_RECOVERY); if (rInfo.CopyOnSwap) attribs.push_back(AGL_BACKING_STORE); attribs.push_back(AGL_NONE); /* Choose pixel format */ AGLPixelFormat Format = aglChoosePixelFormat(NULL, 0, &attribs[0]); //NGL_OUT("Pixel Format: 0x%x\n", Format); if (!Format) { if (rInfo.CopyOnSwap) { attribs[attribs.size() - 2] = AGL_NONE; Format = aglChoosePixelFormat(NULL, 0, &attribs[0]); } if (!Format) { SetError(_T("context"), NGL_CONTEXT_ENOMATCH); return false; } } //DumpFormat(Format); /* Create an AGL context */ mCtx = aglCreateContext(Format, pShared?pShared->mCtx:NULL); long err = aglGetError(); GLint value; aglDescribePixelFormat(Format, AGL_DOUBLEBUFFER, &value); mContextInfo.FrameCnt = value ? 2 : 1; ///< Number of frame buffers (two means double-buffering) aglDescribePixelFormat(Format, AGL_RED_SIZE, (GLint*)&mContextInfo.FrameBitsR); ///< Bits per red component (frame buffer) aglDescribePixelFormat(Format, AGL_GREEN_SIZE, (GLint*)&mContextInfo.FrameBitsG); ///< Bits per green component (frame buffer) aglDescribePixelFormat(Format, AGL_BLUE_SIZE, (GLint*)&mContextInfo.FrameBitsB); ///< Bits per blue component (frame buffer) aglDescribePixelFormat(Format, AGL_ALPHA_SIZE, (GLint*)&mContextInfo.FrameBitsA); ///< Bits per alpha component (frame buffer) aglDescribePixelFormat(Format, AGL_DEPTH_SIZE, (GLint*)&mContextInfo.DepthBits); ///< Depth buffer resolution (ie. Z buffer, 0 means no Z buffer) aglDescribePixelFormat(Format, AGL_STENCIL_SIZE, (GLint*)&mContextInfo.StencilBits); ///< Stencil buffer resolution (0 means no stencil) aglDescribePixelFormat(Format, AGL_ACCUM_RED_SIZE, (GLint*)&mContextInfo.AccumBitsR); ///< Bits per red component (accumulator buffer) aglDescribePixelFormat(Format, AGL_ACCUM_GREEN_SIZE, (GLint*)&mContextInfo.AccumBitsG); ///< Bits per green component (accumulator buffer) aglDescribePixelFormat(Format, AGL_ACCUM_BLUE_SIZE, (GLint*)&mContextInfo.AccumBitsB); ///< Bits per blue component (accumulator buffer) aglDescribePixelFormat(Format, AGL_ACCUM_ALPHA_SIZE, (GLint*)&mContextInfo.AccumBitsA); ///< Bits per alpha component (accumulator buffer) aglDescribePixelFormat(Format, AGL_AUX_BUFFERS, (GLint*)&mContextInfo.AuxCnt); ///< Number of auxiliary buffers aglDescribePixelFormat(Format, AGL_SAMPLE_BUFFERS_ARB, (GLint*)&mContextInfo.AABufferCnt); ///< Number of anti-aliasing buffers aglDescribePixelFormat(Format, AGL_SAMPLES_ARB, (GLint*)&mContextInfo.AASampleCnt); ///< Anti-alisaing oversampling count aglDescribePixelFormat(Format, AGL_STEREO, &value); ///< Stereoscopic display mContextInfo.Stereo = value != 0; mContextInfo.Offscreen = false; ///< This context can render in memory instead of to a window. (false by default). mContextInfo.RenderToTexture = false; ///< This context must be able to be bound as a texture. (false by default) aglDescribePixelFormat(Format, AGL_BACKING_STORE, &value); ///< This context must be able to use copy the back buffer to the front buffer instead of swaping them. (false by default) mContextInfo.CopyOnSwap = value != 0; if (rInfo.CopyOnSwap && !mContextInfo.CopyOnSwap) mValidBackBufferRequestedNotGranted = true; aglDestroyPixelFormat(Format); if (!mCtx) { SetError(_T("context"), NGL_CONTEXT_EGLCTX); /* switch (err) { case AGL_BAD_MATCH: NGL_OUT("AGL Error: Bad Context Match (shared context incompatible with requested pixel format).\n"); break; case AGL_BAD_CONTEXT: NGL_OUT("AGL Error: Bad Shared Context.\n"); break; case AGL_BAD_PIXELFMT: NGL_OUT("AGL Error: Bad Pixel Format.\n"); break; default: NGL_OUT("AGL Error: Unknown error\n"); break; } */ return false; } /* Attach the context to the window */ if (!aglSetDrawable(mCtx, GetWindowPort (Win))) { SetError(_T("context"), NGL_CONTEXT_EBIND); return false; } { CGLError err = kCGLNoError; CGLContextObj ctx = CGLGetCurrentContext(); // Enable the multi-threading //err = CGLEnable( ctx, kCGLCEMPEngine); if (err != kCGLNoError ) { // Multi-threaded execution is possibly not available // Insert your code to take appropriate action } } GLint vsync = rInfo.VerticalSync ? 1 : 0; aglSetInteger(mCtx, AGL_SWAP_INTERVAL, &vsync); InitPainter(); MakeCurrent(Win); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); return true; }
int main(int argc, char *argv[]) { AGLPixelFormat format; /* OpenGL pixel format */ WindowPtr window; /* Window */ int winattrs; /* Window attributes */ Str255 title; /* Title of window */ Rect rect; /* Rectangle definition */ EventHandlerUPP handler; /* Event handler */ EventLoopTimerUPP thandler; /* Timer handler */ EventLoopTimerRef timer; /* Timer for animating the window */ ProcessSerialNumber psn; /* Process serial number */ static EventTypeSpec events[] = /* Events we are interested in... */ { { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowShown }, { kEventClassWindow, kEventWindowHidden }, { kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowBoundsChanged }, { kCoreEventClass, kAEOpenApplication } }; static GLint attributes[] = /* OpenGL attributes */ { AGL_RGBA, AGL_GREEN_SIZE, 1, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 16, AGL_NONE }; //Set initial values for window const int origWinHeight = 628; const int origWinWidth = 850; const int origWinXOffset = 50; const int origWinYOffset = 50; // Create the window... aglContext = 0; WindowVisible = 0; SetRect(&rect, origWinXOffset, origWinYOffset, origWinWidth, origWinHeight); winattrs = kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowFullZoomAttribute | kWindowResizableAttribute | kWindowLiveResizeAttribute; winattrs &= GetAvailableWindowAttributes(kDocumentWindowClass); strcpy((char *)(title + 1), "Rigid Body Dynamics"); title[0] = strlen((char *)(title + 1)); CreateNewWindow(kDocumentWindowClass, winattrs, &rect, &window); SetWTitle(window, title); handler = NewEventHandlerUPP(EventHandler); InstallWindowEventHandler(window, handler, sizeof(events) / sizeof(events[0]), events, NULL, 0L); thandler = NewEventLoopTimerUPP((void (*)(EventLoopTimerRef, void *))IdleFunc); InstallEventLoopTimer(GetMainEventLoop(), 0, 0, thandler, 0, &timer); GetCurrentProcess(&psn); SetFrontProcess(&psn); DrawGrowIcon(window); ShowWindow(window); // Create the OpenGL context and bind it to the window... format = aglChoosePixelFormat(NULL, 0, attributes); aglContext = aglCreateContext(format, NULL); aglSetCurrentContext(aglContext); if (aglContext == NULL) { printf("Unable to create OpenGL context.\n"); return 1; } aglDestroyPixelFormat(format); aglSetDrawable(aglContext, GetWindowPort(window)); // Set the initial size of the cube altEngine.init((void *)&window, (void *)&aglContext); altEngine.resize(origWinWidth - origWinXOffset, origWinHeight - origWinYOffset); for (;;) { if (WindowVisible) SetEventLoopTimerNextFireTime(timer, 0.05); RunApplicationEventLoop(); if (WindowVisible) { altEngine.step(); //render frame, must pass a message to event handler altEngine.render(); } } }
// Note that this function has to be called once. To recreate textures, call the renewTex() member function. int appleMultiContext::init(struct sageDisplayConfig &cfg) { // Make this a "faceful app" that can receive input events: ProcessSerialNumber psn; OSStatus s; s = GetCurrentProcess(&psn); assert(s == noErr); s = TransformProcessType(&psn,kProcessTransformToForegroundApplication); assert(s == noErr); s = SetFrontProcess(&psn); assert(s == noErr); singleContext = false; configStruct = cfg; tileNum = cfg.dimX * cfg.dimY; if (tileNum > MAX_TILES_PER_NODE) { sage::printLog("displayContext::init() : The tile number exceeds the maximum"); return -1; } if (!winCreatFlag) { // // Set up us the OpenGL: // Choose global pixel format: static GLint agl_fmt_list[] = { AGL_RGBA, AGL_RED_SIZE, 8, AGL_GREEN_SIZE, 8, AGL_BLUE_SIZE, 8, AGL_ALPHA_SIZE, 8, AGL_DEPTH_SIZE, 24, AGL_DOUBLEBUFFER, AGL_NONE }; agl_fmt = aglChoosePixelFormat(0,0,agl_fmt_list); if (agl_fmt == 0) { fprintf(stderr,"failed to choose OpenGL pixel format\n"); abort(); } // The critical region object MPCreateCriticalRegion(&cr); // Install event handlers // EventTargetRef target = GetApplicationEventTarget(); EventTypeSpec eventTypes[] = { { kEventClassKeyboard, kEventRawKeyDown } }; InstallEventHandler(target,NewEventHandlerUPP(keyboard_handler), sizeof(eventTypes) / sizeof(EventTypeSpec),eventTypes, 0,0); // Create Windows for (int k = 0; k < tileNum; k++) { int tileX = (k % cfg.dimX) * cfg.tileRect[k].width; int tileY = (k / cfg.dimX) * cfg.tileRect[k].height; Rect wrect; wrect.left = tileX; // cfg.tileRect[k].x; wrect.top = tileY; // cfg.tileRect[k].y; wrect.right = wrect.left + cfg.tileRect[k].width; wrect.bottom = wrect.top + cfg.tileRect[k].height; //fprintf(stderr,"Create window %d at %i,%i,%i,%i\n",k, wrect.left,wrect.top,wrect.right,wrect.bottom); windows[k] = new Window(wrect, configStruct.fullScreenFlag); windows[k]->beginGL(); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); } winCreatFlag = true; } return 0; } // End of appleMultiContext::init()
void glitz_agl_query_formats (glitz_agl_thread_info_t *thread_info) { glitz_int_drawable_format_t format; AGLPixelFormat pixel_format, *new_pfs; int n_attribs_list, i; format.types = GLITZ_DRAWABLE_TYPE_WINDOW_MASK; format.d.id = 0; format.d.color.fourcc = GLITZ_FOURCC_RGB; n_attribs_list = sizeof (_attribs_list) / sizeof (GLint *); for (i = 0; i < n_attribs_list; i++) { GLint value; pixel_format = aglChoosePixelFormat (NULL, 0, _attribs_list[i]); /* Stereo is not supported yet */ if (!(aglDescribePixelFormat (pixel_format, AGL_STEREO, &value)) || value) { aglDestroyPixelFormat (pixel_format); continue; } format.d.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN; aglDescribePixelFormat (pixel_format, AGL_DOUBLEBUFFER, &value); format.d.doublebuffer = (value)? 1: 0; aglDescribePixelFormat (pixel_format, AGL_RED_SIZE, &value); format.d.color.red_size = (unsigned short) value; aglDescribePixelFormat (pixel_format, AGL_GREEN_SIZE, &value); format.d.color.green_size = (unsigned short) value; aglDescribePixelFormat (pixel_format, AGL_BLUE_SIZE, &value); format.d.color.blue_size = (unsigned short) value; format.d.depth = format.d.color.red_size + format.d.color.green_size + value; aglDescribePixelFormat (pixel_format, AGL_ALPHA_SIZE, &value); format.d.color.alpha_size = (unsigned short) value; aglDescribePixelFormat (pixel_format, AGL_DEPTH_SIZE, &value); format.d.depth_size = (unsigned short) value; aglDescribePixelFormat (pixel_format, AGL_STENCIL_SIZE, &value); format.d.stencil_size = (unsigned short) value; if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_MULTISAMPLE_MASK) { aglDescribePixelFormat (pixel_format, AGL_SAMPLE_BUFFERS_ARB, &value); if (value) { aglDescribePixelFormat (pixel_format, AGL_SAMPLES_ARB, &value); format.d.samples = (unsigned short) (value > 1)? value: 1; } else format.d.samples = 1; } else format.d.samples = 1; format.types |= GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; if ((thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_MASK) == 0) format.types &= ~GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; else if (format.d.color.red_size == 0 || format.d.color.green_size == 0 || format.d.color.blue_size == 0 || format.d.color.alpha_size == 0) format.types &= ~GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; else if ((thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_DOUBLEBUFFER_MASK) == 0 && format.d.doublebuffer) format.types &= ~GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; else if ((thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_MULTISAMPLE_MASK) == 0 && format.d.samples > 1) format.types &= ~GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; else if ((thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_DEPTH_STENCIL_MASK) == 0 && (format.d.depth_size > 0 || format.d.stencil_size > 0)) format.types &= ~GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; if (format.d.color.red_size || format.d.color.green_size || format.d.color.blue_size || format.d.color.alpha_size) _glitz_agl_add_format (thread_info, &format, pixel_format); } if (!thread_info->n_formats) return; qsort (thread_info->formats, thread_info->n_formats, sizeof (glitz_int_drawable_format_t), _glitz_agl_format_compare); /* * Update AGLPixelFormat list so that it matches the sorted format list. */ new_pfs = malloc (sizeof (AGLPixelFormat) * thread_info->n_formats); if (!new_pfs) { thread_info->n_formats = 0; return; } for (i = 0; i < thread_info->n_formats; i++) { new_pfs[i] = thread_info->pixel_formats[thread_info->formats[i].d.id]; thread_info->formats[i].d.id = i; } free (thread_info->pixel_formats); thread_info->pixel_formats = new_pfs; }
bool OpenGLApp::initAPI(){ initialMode = CGDisplayCurrentMode(kCGDirectMainDisplay); dmodes = CGDisplayAvailableModes(kCGDirectMainDisplay); int count = CFArrayGetCount(dmodes); Array <DispRes> modes; int foundMode = -1; for (int i = 0; i < count; i++){ CFDictionaryRef mode = (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, i); long bitsPerPixel = GetDictionaryLong(mode, kCGDisplayBitsPerPixel); Boolean safeForHardware = GetDictionaryBoolean(mode, kCGDisplayModeIsSafeForHardware); Boolean stretched = GetDictionaryBoolean(mode, kCGDisplayModeIsStretched); if (bitsPerPixel < colorBits || !safeForHardware || stretched) continue; long width = GetDictionaryLong(mode, kCGDisplayWidth); long height = GetDictionaryLong(mode, kCGDisplayHeight); long refreshRate = GetDictionaryLong(mode, kCGDisplayRefreshRate); // printf("Mode: %dx%dx%d @ %d\n", width, height, bitsPerPixel, refreshRate); if (width >= 640 && height >= 480){ modes.add(newRes(width, height, i)); if (width == fullscreenWidth && height == fullscreenHeight){ foundMode = i; } } } resolution->clear(); modes.sort(dComp); char str[64]; for (uint i = 0; i < modes.getCount(); i++){ sprintf(str, "%dx%d", modes[i].w, modes[i].h); int index = resolution->addItemUnique(str); if (modes[i].index == foundMode) resolution->selectItem(index); } if (fullscreen){ if (foundMode < 0 || CGDisplaySwitchToMode(kCGDirectMainDisplay, (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, foundMode)) != kCGErrorSuccess){ sprintf(str, "Couldn't set fullscreen to %dx%d.", fullscreenWidth, fullscreenHeight); ErrorMsg(str); fullscreen = false; } } Rect rect; if (fullscreen){ rect.left = 0; rect.top = 0; } else { long w = GetDictionaryLong(initialMode, kCGDisplayWidth); long h = GetDictionaryLong(initialMode, kCGDisplayHeight); rect.left = (w - width) / 2; rect.top = (h - height) / 2; } rect.right = rect.left + width; rect.bottom = rect.top + height; WindowAttributes attributes = fullscreen? (kWindowNoTitleBarAttribute | kWindowNoShadowAttribute) : (kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute); OSStatus error = CreateNewWindow(kDocumentWindowClass, attributes, &rect, &window); if (error != noErr || window == NULL){ ErrorMsg("Couldn't create window"); return false; } GDHandle screen = GetGWorldDevice(GetWindowPort(window)); if (screen == NULL){ ErrorMsg("Couldn't get device"); ReleaseWindow(window); return false; } AGLPixelFormat pixelFormat; while (true){ GLint attributes[] = { fullscreen? AGL_FULLSCREEN : AGL_WINDOW, AGL_RGBA, AGL_DOUBLEBUFFER, AGL_RED_SIZE, 8, AGL_GREEN_SIZE, 8, AGL_BLUE_SIZE, 8, AGL_ALPHA_SIZE, (colorBits > 24)? 8 : 0, AGL_DEPTH_SIZE, depthBits, AGL_STENCIL_SIZE, stencilBits, AGL_SAMPLE_BUFFERS_ARB, (antiAliasSamples > 0), AGL_SAMPLES_ARB, antiAliasSamples, AGL_NONE }; pixelFormat = aglChoosePixelFormat(&screen, 1, attributes); if (pixelFormat != NULL) break; antiAliasSamples -= 2; if (antiAliasSamples < 0){ ErrorMsg("No suitable pixel format"); ReleaseWindow(window); return false; } } glContext = aglCreateContext(pixelFormat, NULL); aglDestroyPixelFormat(pixelFormat); if (glContext == NULL){ ErrorMsg("Couldn't create context"); ReleaseWindow(window); return false; } if (fullscreen){ CGCaptureAllDisplays(); aglSetFullScreen(glContext, 0, 0, 0, 0); } else { if (!aglSetDrawable(glContext, GetWindowPort(window))){ ErrorMsg("Couldn't set drawable"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } } if (!aglSetCurrentContext(glContext)){ ErrorMsg("Couldn't make context current"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } setWindowTitle(getTitle()); ShowWindow(window); initExtensions(); if (antiAliasSamples > 0){ glEnable(GL_MULTISAMPLE_ARB); } if (fullscreen) captureMouse(!configDialog->isVisible()); renderer = new OpenGLRenderer(glContext); renderer->setViewport(width, height); antiAlias->selectItem(antiAliasSamples / 2); linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP); defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp); blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); noDepthTest = renderer->addDepthState(false, false); noDepthWrite = renderer->addDepthState(true, false); cullNone = renderer->addRasterizerState(CULL_NONE); cullBack = renderer->addRasterizerState(CULL_BACK); cullFront = renderer->addRasterizerState(CULL_FRONT); return true; }
bool CSMNativeWindow::init(void) { osx_AllowForeground(); CSMDrawer *pDrawer = this->getParent(); CarbonWindowUnrecPtr pCarbonWindow = OSG::CarbonWindow::create(); AGLPixelFormat pixelFormat = NULL; std::vector<int> pfForm; pfForm.push_back(AGL_RGBA); pfForm.push_back(AGL_DEPTH_SIZE); pfForm.push_back(16); pfForm.push_back(AGL_DOUBLEBUFFER); if(_sfRequestSamples.getValue() > 0) { pfForm.push_back(AGL_SAMPLE_BUFFERS_ARB); pfForm.push_back(1); pfForm.push_back(AGL_SAMPLES_ARB); pfForm.push_back(_sfRequestSamples.getValue()); } if(this->requestStereoVisual() == true) { fprintf(stderr, "Choose stereo format\n"); pfForm.push_back(AGL_STEREO); } pfForm.push_back(AGL_NONE); pixelFormat = aglChoosePixelFormat(NULL, 0, &(pfForm.front())); fprintf(stderr, "Got pf : %p\n", pixelFormat); if(pixelFormat == NULL) { fprintf(stderr, "no RGB visual with depth buffer : :0.0"); exit(0); } _pContext = aglCreateContext(pixelFormat, 0); aglDestroyPixelFormat(pixelFormat); UInt32 uiWidth; UInt32 uiHeight; Int32 iXPos = 0; Int32 iYPos = 0; if(this->getXPos() > 0.f && this->getYPos() > 0.f) { iXPos = Int32(this->getXPos()); iYPos = Int32(this->getYPos()); } if(this->getXSize() >= 1.f) { uiWidth = UInt32(this->getXSize()); } else if(this->getXSize() <= 0.f) { uiWidth = 300; //DisplayWidth(_pDisplay, vi->screen); } else { uiWidth = 300; //UInt32(Real32(DisplayWidth(_pDisplay, vi->screen)) * // this->getXSize()); } if(this->getYSize() >= 1.f) { uiHeight = UInt32(this->getYSize()); } else if(this->getYSize() <= 0.f) { uiHeight = 300; //DisplayHeight(_pDisplay, vi->screen); } else { uiHeight = 300; //UInt32(Real32(DisplayHeight(_pDisplay, vi->screen)) * // this->getYSize()); } WindowAttributes windowAttrs = (kWindowStandardDocumentAttributes | kWindowLiveResizeAttribute | kWindowStandardHandlerAttribute ); Rect contentRect; SetRect(&contentRect, iXPos, iYPos, iXPos + uiWidth, iYPos + uiHeight); CreateNewWindow(kDocumentWindowClass, windowAttrs, &contentRect, &_pLocalWindow); SetWindowTitleWithCFString(_pLocalWindow, CFSTR("OpenSG - CSM")); // Install event handler _pEventHandler = NewEventHandlerUPP(eventHandler); EventTypeSpec eventList[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseDragged }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged } }; InstallWindowEventHandler(_pLocalWindow, _pEventHandler, GetEventTypeCount(eventList), eventList, this, 0); aglSetWindowRef(_pContext, _pLocalWindow); _pCarbWindow = pCarbonWindow; _pCarbWindow->setContext(_pContext); _pCarbWindow->init ( ); _pCarbWindow->resize ( uiWidth, uiHeight); std::string windowName(" OpenSG - CSM - "); _pCarbWindow->activate(); windowName += reinterpret_cast<const char *>(glGetString(GL_VERSION)); windowName += " - "; windowName += reinterpret_cast<const char *>(glGetString(GL_RENDERER)); _pCarbWindow->deactivate(); SetWTitle(_pLocalWindow, reinterpret_cast<const unsigned char *>(windowName.c_str())); // Show window RepositionWindow(_pLocalWindow, 0, kWindowCascadeOnMainScreen); ShowWindow (_pLocalWindow ); if(ComplexSceneManager::the() != NULL) ComplexSceneManager::the()->setMainloop( &CSMNativeWindow::carbonMainLoop); _pWindow = _pCarbWindow; _bRun = true; Inherited::init(); return true; }
static bool InitializeOpenGL () { bool hasGLSL = false; #if GOT_GFX #ifdef _MSC_VER // setup minimal required GL HWND wnd = CreateWindowA( "STATIC", "GL", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 16, 16, NULL, NULL, GetModuleHandle(NULL), NULL ); HDC dc = GetDC( wnd ); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int fmt = ChoosePixelFormat( dc, &pfd ); SetPixelFormat( dc, fmt, &pfd ); HGLRC rc = wglCreateContext( dc ); wglMakeCurrent( dc, rc ); #else GLint attributes[16]; int i = 0; attributes[i++]=AGL_RGBA; attributes[i++]=AGL_PIXEL_SIZE; attributes[i++]=32; attributes[i++]=AGL_NO_RECOVERY; attributes[i++]=AGL_NONE; AGLPixelFormat pixelFormat = aglChoosePixelFormat(NULL,0,attributes); AGLContext agl = aglCreateContext(pixelFormat, NULL); aglSetCurrentContext (agl); #endif // check if we have GLSL const char* extensions = (const char*)glGetString(GL_EXTENSIONS); hasGLSL = strstr(extensions, "GL_ARB_shader_objects") && strstr(extensions, "GL_ARB_vertex_shader") && strstr(extensions, "GL_ARB_fragment_shader"); #ifdef _MSC_VER if (hasGLSL) { glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB"); glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB"); glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB"); glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB"); glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB"); glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB"); } #endif #endif return hasGLSL; }
int _glfwPlatformOpenWindow( int width, int height, const _GLFWwndconfig *wndconfig, const _GLFWfbconfig *fbconfig ) { OSStatus error; unsigned int windowAttributes; ProcessSerialNumber psn; // TODO: Break up this function! _glfwWin.windowUPP = NULL; _glfwWin.mouseUPP = NULL; _glfwWin.keyboardUPP = NULL; _glfwWin.commandUPP = NULL; _glfwWin.window = NULL; _glfwWin.aglContext = NULL; _glfwWin.aglPixelFormat = NULL; _glfwWin.cglContext = NULL; _glfwWin.cglPixelFormat = NULL; _glfwWin.refreshRate = wndconfig->refreshRate; // Fail if OpenGL 3.0 or above was requested if( wndconfig->glMajor > 2 ) { fprintf( stderr, "OpenGL 3.0+ is not yet supported on Mac OS X\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( _glfwLibrary.Unbundled ) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to get the process serial number\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "Failed to become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( wndconfig->mode == GLFW_FULLSCREEN ) { if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } } } if( !installEventHandlers() ) { fprintf( stderr, "Failed to install Carbon application event handlers\n" ); _glfwPlatformTerminate(); return GL_FALSE; } // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( wndconfig->mode == GLFW_WINDOW ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_CLOSEST_POLICY; if( fbconfig->stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, fbconfig->auxBuffers); _setAGLAttribute( AGL_RED_SIZE, fbconfig->redBits ); _setAGLAttribute( AGL_GREEN_SIZE, fbconfig->greenBits ); _setAGLAttribute( AGL_BLUE_SIZE, fbconfig->blueBits ); _setAGLAttribute( AGL_ALPHA_SIZE, fbconfig->alphaBits ); _setAGLAttribute( AGL_DEPTH_SIZE, fbconfig->depthBits ); _setAGLAttribute( AGL_STENCIL_SIZE, fbconfig->stencilBits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, fbconfig->accumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, fbconfig->accumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, fbconfig->accumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, fbconfig->accumAlphaBits ); if( fbconfig->samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, fbconfig->samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); _glfwWin.aglPixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( _glfwWin.aglPixelFormat == NULL ) { fprintf( stderr, "Failed to choose AGL pixel format: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create AGL context _glfwWin.aglContext = aglCreateContext( _glfwWin.aglPixelFormat, NULL ); if( _glfwWin.aglContext == NULL ) { fprintf( stderr, "Failed to create AGL context: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute ); if( wndconfig->windowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.window ) ); if( ( error != noErr ) || ( _glfwWin.window == NULL ) ) { fprintf( stderr, "Failed to create Carbon window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.windowUPP = NewEventHandlerUPP( windowEventHandler ); error = InstallWindowEventHandler( _glfwWin.window, _glfwWin.windowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "Failed to install Carbon window event handler\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.window, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.aglContext, GetWindowPort( _glfwWin.window ) ) ) { fprintf( stderr, "Failed to set the AGL context as the Carbon window drawable: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.aglContext ) ) { fprintf( stderr, "Failed to make AGL context current: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } ShowWindow( _glfwWin.window ); } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; GLint numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( fbconfig->stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( fbconfig->samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)fbconfig->samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( fbconfig->accumRedBits \ + fbconfig->accumGreenBits \ + fbconfig->accumBlueBits \ + fbconfig->accumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)fbconfig->alphaBits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)fbconfig->depthBits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)fbconfig->stencilBits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)fbconfig->auxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &_glfwWin.cglPixelFormat, &numCGLvs ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to choose CGL pixel format: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( _glfwWin.cglPixelFormat, NULL, &_glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to create CGL context: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( _glfwWin.cglPixelFormat, 0, kCGLPFAColorSize, &rgbColorDepth ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to capture Core Graphics displays\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, height, wndconfig->refreshRate, NULL, NULL ); if( optimalMode == NULL ) { fprintf( stderr, "Failed to retrieve Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to switch to Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to make CGL context current: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to set CGL fullscreen mode: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } } return GL_TRUE; }
static AGLPixelFormat ChoosePixelFormat(const int *attribList) { GLint data[512]; GLint defaultAttribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_MINIMUM_POLICY, AGL_DEPTH_SIZE, 1, // use largest available depth buffer AGL_RED_SIZE, 1, AGL_GREEN_SIZE, 1, AGL_BLUE_SIZE, 1, AGL_ALPHA_SIZE, 0, AGL_NONE }; GLint *attribs; if (!attribList) { attribs = defaultAttribs; } else { int arg=0, p=0; data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX while( (attribList[arg]!=0) && (p<512) ) { switch( attribList[arg++] ) { case WX_GL_RGBA: data[p++] = AGL_RGBA; break; case WX_GL_BUFFER_SIZE: data[p++]=AGL_BUFFER_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_LEVEL: data[p++]=AGL_LEVEL; data[p++]=attribList[arg++]; break; case WX_GL_DOUBLEBUFFER: data[p++] = AGL_DOUBLEBUFFER; break; case WX_GL_STEREO: data[p++] = AGL_STEREO; break; case WX_GL_AUX_BUFFERS: data[p++]=AGL_AUX_BUFFERS; data[p++]=attribList[arg++]; break; case WX_GL_MIN_RED: data[p++]=AGL_RED_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_GREEN: data[p++]=AGL_GREEN_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_BLUE: data[p++]=AGL_BLUE_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_ALPHA: data[p++]=AGL_ALPHA_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_DEPTH_SIZE: data[p++]=AGL_DEPTH_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_STENCIL_SIZE: data[p++]=AGL_STENCIL_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_ACCUM_RED: data[p++]=AGL_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_ACCUM_GREEN: data[p++]=AGL_ACCUM_GREEN_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_ACCUM_BLUE: data[p++]=AGL_ACCUM_BLUE_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_MIN_ACCUM_ALPHA: data[p++]=AGL_ACCUM_ALPHA_SIZE; data[p++]=attribList[arg++]; break; default: break; } } data[p] = 0; attribs = data; } return aglChoosePixelFormat(NULL, 0, attribs); }
/* ** OS Specific windowing context creation - essential for creating the OpenGL drawing context */ AESDK_OpenGL_Err AESDK_OpenGL_Startup(AESDK_OpenGL_EffectCommonData& inData) { AESDK_OpenGL_Err result = AESDK_OpenGL_OK; inData.mUsingShaderB = false; //default value try { #ifdef AE_OS_WIN WNDCLASSEX winClass; MSG uMsg; ::memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "AESDK_OpenGL_Win_Class"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = ::DefWindowProc; winClass.hInstance = NULL; winClass.hIcon = NULL; winClass.hIconSm = NULL; winClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); winClass.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH); winClass.lpszMenuName = NULL; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; if( !(::RegisterClassEx(&winClass)) ) GL_CHECK(AESDK_OpenGL_OS_Load_Err); inData.mHWnd = ::CreateWindowEx( NULL, "AESDK_OpenGL_Win_Class", "OpenGL-using FBOs in AE", 0,0, 0, 50, 50, NULL, NULL, NULL, NULL ); if( inData.mHWnd == NULL ) GL_CHECK(AESDK_OpenGL_OS_Load_Err); GLuint PixelFormat; PIXELFORMATDESCRIPTOR pfd; ::ZeroMemory( &pfd, sizeof( pfd ) ); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER ; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 8; inData.mHDC = ::GetDC( inData.mHWnd ); PixelFormat = ChoosePixelFormat( inData.mHDC, &pfd ); SetPixelFormat( inData.mHDC, PixelFormat, &pfd); inData.mHRC = wglCreateContext( inData.mHDC ); wglMakeCurrent( inData.mHDC, inData.mHRC ); //check for the appropriate extensions - EXT_framebuffer_object char *ext = (char*)glGetString( GL_EXTENSIONS ); if( ::strstr( ext, "EXT_framebuffer_object" ) == NULL ) { GL_CHECK(AESDK_OpenGL_Extensions_Err); } else { glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC)GetProcAddress("glIsRenderbufferEXT"); glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)GetProcAddress("glBindRenderbufferEXT"); glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)GetProcAddress("glDeleteRenderbuffersEXT"); glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)GetProcAddress("glGenRenderbuffersEXT"); glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)GetProcAddress("glRenderbufferStorageEXT"); glGetRenderbufferParameterivEXT = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC)GetProcAddress("glGetRenderbufferParameterivEXT"); glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC)GetProcAddress("glIsFramebufferEXT"); glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)GetProcAddress("glBindFramebufferEXT"); glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)GetProcAddress("glDeleteFramebuffersEXT"); glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)GetProcAddress("glGenFramebuffersEXT"); glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)GetProcAddress("glCheckFramebufferStatusEXT"); glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC)GetProcAddress("glFramebufferTexture1DEXT"); glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)GetProcAddress("glFramebufferTexture2DEXT"); glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC)GetProcAddress("glFramebufferTexture3DEXT"); glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)GetProcAddress("glFramebufferRenderbufferEXT"); glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC)GetProcAddress("glGetFramebufferAttachmentParameterivEXT"); glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC)GetProcAddress("glGenerateMipmapEXT"); glActiveTexture = (PFNGLACTIVETEXTUREPROC)GetProcAddress("glActiveTexture"); if( !glIsRenderbufferEXT || !glBindRenderbufferEXT || !glDeleteRenderbuffersEXT || !glGenRenderbuffersEXT || !glRenderbufferStorageEXT || !glGetRenderbufferParameterivEXT || !glIsFramebufferEXT || !glBindFramebufferEXT || !glDeleteFramebuffersEXT || !glGenFramebuffersEXT || !glCheckFramebufferStatusEXT || !glFramebufferTexture1DEXT || !glFramebufferTexture2DEXT || !glFramebufferTexture3DEXT || !glFramebufferRenderbufferEXT|| !glGetFramebufferAttachmentParameterivEXT || !glGenerateMipmapEXT || !glActiveTexture) { GL_CHECK(AESDK_OpenGL_Extensions_Err); } } char *extP = (char*)glGetString( GL_EXTENSIONS ); if( ::strstr( extP, "GL_ARB_shading_language_100" ) == NULL ) { //This extension string indicates that the OpenGL Shading Language, // version 1.00, is supported. GL_CHECK(AESDK_OpenGL_ShaderInit_Err); } //check for the appropriate extensions - EXT_framebuffer_object if( ::strstr( extP, "GL_ARB_shader_objects" ) == NULL ) { GL_CHECK(AESDK_OpenGL_Extensions_Err); } else { glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GetProcAddress("glCreateProgramObjectARB"); glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)GetProcAddress("glDeleteObjectARB"); glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GetProcAddress("glUseProgramObjectARB"); glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GetProcAddress("glCreateShaderObjectARB"); glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GetProcAddress("glShaderSourceARB"); glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GetProcAddress("glCompileShaderARB"); glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)GetProcAddress("glGetObjectParameterivARB"); glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GetProcAddress("glAttachObjectARB"); glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)GetProcAddress("glGetInfoLogARB"); glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GetProcAddress("glLinkProgramARB"); glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)GetProcAddress("glGetUniformLocationARB"); glUniform4fARB = (PFNGLUNIFORM4FARBPROC)GetProcAddress("glUniform4fARB"); glUniform1iARB = (PFNGLUNIFORM1IARBPROC)GetProcAddress("glUniform1iARB"); if( !glCreateProgramObjectARB || !glDeleteObjectARB || !glUseProgramObjectARB || !glCreateShaderObjectARB || !glCreateShaderObjectARB || !glCompileShaderARB || !glGetObjectParameterivARB || !glAttachObjectARB || !glGetInfoLogARB || !glLinkProgramARB || !glGetUniformLocationARB || !glUniform4fARB || !glUniform1iARB ) { GL_CHECK(AESDK_OpenGL_Extensions_Err); } } #elif defined(AE_OS_MAC) Rect rect; SetRect(&rect, 0, 0, 50, 50); if ( noErr != CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes, &rect, &inData.mMacWnd)) GL_CHECK(AESDK_OpenGL_OS_Load_Err); GLint aAttribs[64]; u_short nIndexS= -1; // NO color index support aAttribs[++nIndexS]= AGL_RGBA; // double buffering aAttribs[++nIndexS]=AGL_DOUBLEBUFFER; // color aAttribs[++nIndexS] = AGL_RED_SIZE; aAttribs[++nIndexS] = 8; aAttribs[++nIndexS] = AGL_GREEN_SIZE; aAttribs[++nIndexS] = 8; aAttribs[++nIndexS] = AGL_BLUE_SIZE; aAttribs[++nIndexS] = 8; aAttribs[++nIndexS] = AGL_ALPHA_SIZE; aAttribs[++nIndexS] = 8; aAttribs[++nIndexS] = AGL_NONE; // get an appropriate pixel format AGLPixelFormat oPixelFormat = aglChoosePixelFormat( NULL, 0, aAttribs); if( oPixelFormat == NULL ) GL_CHECK(AESDK_OpenGL_OS_Load_Err); // create the context from the pixel format inData.mAGLContext = aglCreateContext(oPixelFormat,NULL); if( NULL == inData.mAGLContext ) GL_CHECK(AESDK_OpenGL_Extensions_Err); // otherwise clean-up the pixel format aglDestroyPixelFormat(oPixelFormat); //attach the window if ( !aglSetDrawable (inData.mAGLContext, GetWindowPort(inData.mMacWnd)) ) GL_CHECK(AESDK_OpenGL_Extensions_Err); glFlush(); aglSetCurrentContext(inData.mAGLContext); #endif } catch(AESDK_OpenGL_Err& err) { result = err; } return result; }