Beispiel #1
0
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;
}
Beispiel #2
0
bool SkOSWindow::attachGL()
{
    if (NULL == fAGLCtx) {
        fAGLCtx = create_gl((WindowRef)fHWND);
        if (NULL == fAGLCtx) {
            return false;
        }
    }

    GLboolean success = true;

    int width, height;

    success = aglSetWindowRef((AGLContext)fAGLCtx, (WindowRef)fHWND);
    width = this->width();
    height = this->height();

    GLenum err = aglGetError();
    if (err) {
        SkDebugf("---- aglSetWindowRef %d %d %s [%d %d]\n", success, err,
                 aglErrorString(err), width, height);
    }

    if (success) {
        glViewport(0, 0, width, height);
        glClearColor(0, 0, 0, 0);
        glClearStencil(0);
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    }
    return success;
}
Beispiel #3
0
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;
}
Beispiel #4
0
static void setup_offscreen_gl(const SkBitmap& offscreen, WindowRef wref) {
    GLboolean success = true;

#ifdef USE_OFFSCREEN
    success = aglSetOffScreen(gAGLContext,
                              offscreen.width(),
                              offscreen.height(),
                              offscreen.rowBytes(),
                              offscreen.getPixels());
#else
    success = aglSetWindowRef(gAGLContext, wref);
#endif

    GLenum err = aglGetError();
    if (err) {
        SkDebugf("---- setoffscreen %d %d %s [%d %d]\n", success, err,
                 aglErrorString(err), offscreen.width(), offscreen.height());
    }

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    glEnable(GL_TEXTURE_2D);

    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
}
Beispiel #5
0
bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
{
    if ( !m_glContext )
        return false;

    GLint bufnummer = win.GetAglBufferName();
    aglSetInteger(m_glContext, AGL_BUFFER_NAME, &bufnummer);
    //win.SetLastContext(m_glContext);

    const_cast<wxGLCanvas&>(win).SetViewport();

    
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
    if ( UMAGetSystemVersion() >= 0x1050 )
    {
        aglSetWindowRef(m_glContext, win.MacGetTopLevelWindowRef());
    }
    else
#endif
    {
        AGLDrawable drawable = (AGLDrawable)GetWindowPort(
                                                      MAC_WXHWND(win.MacGetTopLevelWindowRef()));
    
        if ( !aglSetDrawable(m_glContext, drawable) )
        {
            wxLogAGLError("aglSetDrawable");
            return false;
        }
    }

    return WXGLSetCurrentContext(m_glContext);
}
Beispiel #6
0
static void deleteContext(AGLContext ctx) {
    if (g_Window.fs) {
        aglSetFullScreen(ctx, 0, 0, 0, 0);
    } else {
        aglSetWindowRef(ctx, 0);
    }
    aglSetCurrentContext(0);
    aglDestroyContext(ctx);
}
Beispiel #7
0
bool wxGLCanvas::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxPoint& pos,
                        const wxSize& size,
                        long style,
                        const wxString& name,
                        const int *attribList,
                        const wxPalette& WXUNUSED(palette))
{
    m_needsUpdate = false;
    m_macCanvasIsShown = false;

    m_glFormat = WXGLChoosePixelFormat(attribList);
    if ( !m_glFormat )
        return false;

    if ( !wxWindow::Create(parent, id, pos, size, style, name) )
        return false;

    m_dummyContext = WXGLCreateContext(m_glFormat, NULL);

    static GLint gCurrentBufferName = 1;
    m_bufferName = gCurrentBufferName++;
    aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName);

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
    if ( UMAGetSystemVersion() >= 0x1050 )
    {
        aglSetWindowRef(m_dummyContext, MacGetTopLevelWindowRef());
    }
    else
#endif
    {
        AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef()));
        aglSetDrawable(m_dummyContext, drawable);
    }

    m_macCanvasIsShown = true;

    return true;
}
Beispiel #8
0
SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
#ifdef SK_SUPPORT_GL
#ifndef USE_OFFSCREEN
    aglSetWindowRef(gAGLContext, NULL);
#endif
#endif
    switch (fCanvasType) {
    case kRaster_CanvasType:
        canvas = this->INHERITED::beforeChildren(canvas);
        break;
    case kPicture_CanvasType:
        fPicture = new SkPicture;
        canvas = fPicture->beginRecording(9999, 9999);
        break;
#ifdef SK_SUPPORT_GL
    case kOpenGL_CanvasType: {
        //SkGLCanvas::DeleteAllTextures();  // just for testing
        SkDevice* device = canvas->getDevice();
        const SkBitmap& bitmap = device->accessBitmap(true);
        // first clear the raster bitmap, so we don't see any leftover bits
        bitmap.eraseColor(0);
        // now setup our glcanvas
        setup_offscreen_gl(bitmap, (WindowRef)this->getHWND());
        fGLCanvas = new SkGLCanvas;
        fGLCanvas->setViewport(bitmap.width(), bitmap.height());
        canvas = fGLCanvas;
        break;
    }
#endif
    }

    if (fUseClip) {
        canvas->drawColor(0xFFFF88FF);
        canvas->clipPath(fClipPath);
    }

    return canvas;
}
Beispiel #9
0
bool Window::configInitAGLWindow()
{
    AGLContext context = getAGLContext();
    if( !context )
    {
        sendError( ERROR_AGLWINDOW_NO_CONTEXT );
        return false;
    }

    // window
    const bool decoration =
        getIAttribute(WindowSettings::IATTR_HINT_DECORATION) != OFF;
    WindowAttributes winAttributes = ( decoration ?
                                       kWindowStandardDocumentAttributes :
                                       kWindowNoTitleBarAttribute |
                                       kWindowNoShadowAttribute   |
                                       kWindowResizableAttribute  ) |
                                     kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute;

    // top, left, bottom, right
    const PixelViewport& pvp = getPixelViewport();
    const int32_t menuHeight = decoration ? EQ_AGL_MENUBARHEIGHT : 0 ;
    Rect windowRect = { short( pvp.y + menuHeight ), short( pvp.x ),
                        short( pvp.getYEnd() + menuHeight ),
                        short( pvp.getXEnd( ))
                      };
    WindowRef windowRef;

    Global::enterCarbon();
    const OSStatus status = CreateNewWindow( kDocumentWindowClass,
                            winAttributes,
                            &windowRect, &windowRef );
    if( status != noErr )
    {
        sendError( ERROR_AGLWINDOW_CREATEWINDOW_FAILED )
                << lexical_cast< std::string >( status );
        Global::leaveCarbon();
        return false;
    }

    // window title
    const std::string& name = getName();
    std::stringstream windowTitle;

    if( name.empty( ))
    {
        windowTitle << "Equalizer";
#ifndef NDEBUG
        windowTitle << " (" << getpid() << ")";
#endif
    }
    else
        windowTitle << name;

    CFStringRef title = CFStringCreateWithCString( kCFAllocatorDefault,
                        windowTitle.str().c_str(),
                        kCFStringEncodingMacRoman );
    SetWindowTitleWithCFString( windowRef, title );
    CFRelease( title );

    if( !aglSetWindowRef( context, windowRef ))
    {
        sendError( ERROR_AGLWINDOW_SETWINDOW_FAILED ) << aglError();
        Global::leaveCarbon();
        return false;
    }

    // show
    ShowWindow( windowRef );

    // Do focus hell
    ProcessSerialNumber selfProcess = { 0, kCurrentProcess };
    SetFrontProcess( &selfProcess );

    Global::leaveCarbon();
    setCarbonWindow( windowRef );

    return true;
}
    void OSXCarbonWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
    {
        if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight)
        {
            // Set the full screen flag
            mIsFullScreen = fullScreen;

            createAGLContext(mFSAA, mColourDepth);

            if (mIsFullScreen)
            {
                GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());

                CGLContextObj share = NULL;
                aglGetCGLContext(mAGLContext, (void**)&share);

                // Create the CGL context object if it doesn't already exist, sharing the AGL context.
                if(!mCGLContext)
                {
                    void *cglPixFormat;
                    aglGetCGLPixelFormat(mAGLPixelFormat, (void **)&cglPixFormat);
                    mCGLContext = OGRE_NEW OSXCGLContext(mCGLContextObj, (CGLPixelFormatObj) cglPixFormat);
                }

                // Create the context, keeping the current colour depth and FSAA settings
                createCGLFullscreen(width, height, getColourDepth(), getFSAA(), share);
                rs->_switchContext(mContext);

                // Hide the Carbon window
                HideWindow(mWindow);

                // And tell the rendersystem to stop rendering to it too
                WindowEventUtilities::_removeRenderWindow(this);
            }
            else
            {
                // Create a new AGL context and pixel format if necessary
                createAGLContext(mFSAA, mColourDepth);

                // Create a window if we haven't already, existence check is done within the functions
                if(!mWindow)
                {
                    if(mIsExternal)
                        createWindowFromExternal(mView);
                    else
                        createNewWindow(width, height, mWindowTitle);
                }

                // Destroy the current CGL context, we will create a new one when/if we go back to full screen
                destroyCGLFullscreen();

                // Set the drawable, and current context
                // If you do this last, there is a moment before the rendering window pops-up
                #if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
                    aglSetDrawable(mAGLContext, GetWindowPort(mWindow));
                #else
                    aglSetWindowRef(mAGLContext, mWindow);
                #endif
                aglSetCurrentContext(mAGLContext);

                if(!mCarbonContext)
                {
                    mCarbonContext = OGRE_NEW OSXCarbonContext(mAGLContext, mAGLPixelFormat);
                }
                
                GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
                mContext = mCarbonContext;
                rs->_switchContext(mContext);

                WindowEventUtilities::_addRenderWindow(this);

                ShowWindow(mWindow);
                SelectWindow(mWindow);
                RepositionWindow(mWindow, NULL, kWindowCenterOnMainScreen);
            }
            mWidth = width;
            mHeight = height;
        }
    }
    //-------------------------------------------------------------------------------------------------//
    void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height,
                    bool fullScreen, const NameValuePairList *miscParams )
    {
        bool hasDepthBuffer = false;
        String title = name;
        size_t fsaa_samples = 0;
        int left = 0;
        int top = 0;
        bool vsync = false;
        bool hidden = false;
        int depth = 32;

        if( miscParams )
        {
            NameValuePairList::const_iterator opt(NULL);
            NameValuePairList::const_iterator end = miscParams->end();

            // Full screen anti aliasing
            if((opt = miscParams->find("FSAA")) != end) 
                fsaa_samples = StringConverter::parseUnsignedInt( opt->second );

            if((opt = miscParams->find("left")) != end) 
                left = StringConverter::parseUnsignedInt( opt->second );

            if((opt = miscParams->find("top")) != end) 
                top = StringConverter::parseUnsignedInt( opt->second );

            if((opt = miscParams->find("title")) != end) 
                title = opt->second;

            if((opt = miscParams->find("vsync")) != end) 
                vsync = StringConverter::parseBool(opt->second);

            if((opt = miscParams->find("hidden")) != end) 
                hidden = StringConverter::parseBool(opt->second);

            if((opt = miscParams->find("gamma")) != end) 
				mHwGamma = StringConverter::parseBool(opt->second);

            if((opt = miscParams->find("depthBuffer")) != end) 
                hasDepthBuffer = StringConverter::parseBool( opt->second );
            
            if((opt = miscParams->find("colourDepth")) != end) 
                depth = StringConverter::parseUnsignedInt( opt->second );

            if((opt = miscParams->find("Full Screen")) != end) 
                fullScreen = StringConverter::parseBool( opt->second );
        }

        if(fullScreen)
        {
            setFullscreen(fullScreen, width, height);
        }
        else
        {
            createAGLContext(fsaa_samples, depth);

            NameValuePairList::const_iterator opt(NULL);
            if(miscParams)
                opt = miscParams->find("externalWindowHandle");

            if(!miscParams || opt == miscParams->end())
                createNewWindow(width, height, title.c_str());
            else
                createWindowFromExternal((HIViewRef)StringConverter::parseUnsignedLong(opt->second));

            // 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.
    #if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
            aglSetDrawable(mAGLContext, GetWindowPort(mWindow));
    #else
            aglSetWindowRef(mAGLContext, mWindow);
    #endif
            aglSetCurrentContext(mAGLContext);

            // Give a copy of our context to the render system
            if(!mCarbonContext)
            {
                mCarbonContext = OGRE_NEW OSXCarbonContext(mAGLContext, mAGLPixelFormat);
                mContext = mCarbonContext;
            }
        }

        // Apply vsync settings. call setVSyncInterval first to avoid 
		// setting vsync more than once.
        setVSyncEnabled(vsync);
        setHidden(hidden);

        mName = name;
        mWidth = width;
        mHeight = height;
        mColourDepth = depth;
        mFSAA = fsaa_samples;
        mIsFullScreen = fullScreen;
        mActive = true;
        mClosed = false;
        mCreated = true;
    }
Beispiel #12
0
void SkOSWindow::detachGL() {
    aglSetWindowRef((AGLContext)fAGLCtx, NULL);
}
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;
}
Beispiel #14
0
static AGLContext createContext(WindowRef window) {
    AGLPixelFormat pf;
    AGLContext ctx;
    GDHandle gdh;
    CFDictionaryRef refMode;
    GLenum error;

    CGDirectDisplayID mainDisplay = CGMainDisplayID();

    GLint attrs[] = {
        AGL_RGBA,
        AGL_DOUBLEBUFFER,
        AGL_RED_SIZE, 4,
        AGL_GREEN_SIZE, 4,
        AGL_BLUE_SIZE, 4,
        AGL_DEPTH_SIZE, 16,
        AGL_NONE
    };

    GLint fullscreen_attrs[] = {
        AGL_FULLSCREEN,
        AGL_RGBA,
        AGL_DOUBLEBUFFER,
        AGL_RED_SIZE, 4,
        AGL_GREEN_SIZE, 4,
        AGL_BLUE_SIZE, 4,
        AGL_DEPTH_SIZE, 16,
        AGL_NONE
    };

    g_Window.double_buffered = true;

    if (!g_Window.fs) {
        pf = aglChoosePixelFormat(NULL, 0, attrs);
    } else {
        CGDisplayCapture(mainDisplay);
        refMode = CGDisplayBestModeForParameters(mainDisplay, 32,
                                                 g_Window.width, g_Window.height, NULL);
        CGDisplaySwitchToMode(mainDisplay, refMode);
        DMGetGDeviceByDisplayID(mainDisplay, &gdh, false);
        pf = aglChoosePixelFormat(&gdh, 1, fullscreen_attrs);

        error = aglGetError();
        if (error != AGL_NO_ERROR) {
            printf("%s\n", aglErrorString(error));
            return 0;
        }
    }

    if (!pf) {
        printf("Error choosing pixel format\n");
        return 0;
    }

    ctx = aglCreateContext(pf, 0);
    if (!ctx) {
        printf("%s\n", aglErrorString(aglGetError()));
        return 0;
    }

    aglDestroyPixelFormat(pf);
    aglSetCurrentContext(ctx);

    if (g_Window.fs) {
        aglSetFullScreen(ctx, g_Window.width, g_Window.height, 0, 0);
    } else {
        aglSetWindowRef(ctx, window);
    }

    return ctx;
}