Ejemplo n.º 1
0
bool Window::configInitAGLFullscreen()
{
    AGLContext context = getAGLContext();
    if( !context )
    {
        sendError( ERROR_AGLWINDOW_NO_CONTEXT );
        return false;
    }

    Global::enterCarbon();
    aglEnable( context, AGL_FS_CAPTURE_SINGLE );

    const PixelViewport& pvp = getPixelViewport();
    if( !aglSetFullScreen( context, pvp.w, pvp.h, 0, 0 ))
        LBWARN << "aglSetFullScreen to " << pvp << " failed: " << aglError()
               << std::endl;

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

    Global::leaveCarbon();

    setPixelViewport( pvp );

    if( getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) != OFF )
        initEventHandler();
    return true;
}
Ejemplo n.º 2
0
static void deleteContext(AGLContext ctx) {
    if (g_Window.fs) {
        aglSetFullScreen(ctx, 0, 0, 0, 0);
    } else {
        aglSetWindowRef(ctx, 0);
    }
    aglSetCurrentContext(0);
    aglDestroyContext(ctx);
}
void CL_DisplayWindow_OpenGL::set_fullscreen(int width, int height, int bpp, int refresh_rate)
{
	if(fullscreen)
		return;

	CGCaptureAllDisplays();
	
	aglSetCurrentContext(fs_context);
	aglSetFullScreen(fs_context, width, height, refresh_rate, 0);

	context = fs_context;
	install_event_handler(GetApplicationEventTarget());
	
	fullscreen = true;
	focus = true;

	//After toggling to the fullscreen context, nothing is going draw unless
	//we reapply the GL states/properties -mrfun 6-2-2006
	CL_GLStateChecker::from_gc(get_gc())->reinitialize_asap();
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
void QGLContext::updatePaintDevice()
{
    Q_D(QGLContext);
    d->update = false;
#if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
        if(d->paintDevice->devType() == QInternal::Widget) {
            QWidget *w = (QWidget *)d->paintDevice;
            aglSetHIViewRef((AGLContext)d->cx, (HIViewRef)w->winId());
        } else if(d->paintDevice->devType() == QInternal::Pixmap) {
            QPixmap *pm = (QPixmap *)d->paintDevice;
            aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(),
                            qt_mac_pixmap_get_bytes_per_line(pm), qt_mac_pixmap_get_base(pm));
        } else {
            qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
        }
    } else
#endif
    {
#ifndef Q_OS_MAC64
        if(d->paintDevice->devType() == QInternal::Widget) {
            //get control information
            QWidget *w = (QWidget *)d->paintDevice;
            HIViewRef hiview = (HIViewRef)w->winId();
            WindowPtr window = qt_mac_window_for(hiview);
#ifdef DEBUG_OPENGL_REGION_UPDATE
            static int serial_no_gl = 0;
            qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w,
                   w->metaObject()->className(), w->objectName().toLatin1().constData(),
                   hiview, window, w->handle() ? "Inside" : "Outside");
#endif

            //update drawable
            if(0 && w->isWindow() && w->isFullScreen()) {
                aglSetDrawable((AGLContext)d->cx, 0);
                aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w));
                w->hide();
            } else {
                AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window);
                if(old_draw != new_draw)
                    aglSetDrawable((AGLContext)d->cx, new_draw);
            }

            if(!w->isWindow()) {
                QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area

#ifdef DEBUG_OPENGL_REGION_UPDATE
                if(clp.isEmpty()) {
                    qDebug("  Empty area!");
                } else {
                    QVector<QRect> rs = clp.rects();
                    for(int i = 0; i < rs.count(); i++)
                        qDebug("  %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height());
                }
#endif
                //update the clip
                if(!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT))
                    aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT);
                if(clp.isEmpty()) {
                    GLint offs[4] = { 0, 0, 0, 0 };
                    aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
                    if(aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
                        aglDisable((AGLContext)d->cx, AGL_CLIP_REGION);
                } else {
                    HIPoint origin = { 0., 0. };
                    HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0);
                    const GLint offs[4] = { qRound(origin.x),
                                            w->window()->frameGeometry().height()
                                                    - (qRound(origin.y) + w->height()),
                                            w->width(), w->height() };
                    aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
                    aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)clp.handle(true));
                    if(!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
                        aglEnable((AGLContext)d->cx, AGL_CLIP_REGION);
                }
            }
        } else if(d->paintDevice->devType() == QInternal::Pixmap) {
            QPixmap *pm = (QPixmap *)d->paintDevice;
            PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle());
            aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(),
                            GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm));
        } else {
            qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
        }
#endif // Q_OS_MAC64
    }
    aglUpdateContext((AGLContext)d->cx);
}
Ejemplo n.º 7
0
int  _glfwPlatformOpenWindow( int width,
                              int height,
                              int redbits,
                              int greenbits,
                              int bluebits,
                              int alphabits,
                              int depthbits,
                              int stencilbits,
                              int mode,
                              int accumredbits,
                              int accumgreenbits,
                              int accumbluebits,
                              int accumalphabits,
                              int auxbuffers,
                              int stereo,
                              int refreshrate )
{
    OSStatus error;

    // TO DO: Refactor this function!

    _glfwWin.WindowFunctions = (mode == GLFW_FULLSCREEN ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions);

    // create pixel format attribute list

    GLint pixelFormatAttributes[256];
    int numAttrs = 0;

    pixelFormatAttributes[numAttrs++] = AGL_RGBA;
    pixelFormatAttributes[numAttrs++] = AGL_DOUBLEBUFFER;

    if ( mode == GLFW_FULLSCREEN )
    {
        pixelFormatAttributes[numAttrs++] = AGL_FULLSCREEN;
    }

    if ( stereo )
    {
        pixelFormatAttributes[numAttrs++] = AGL_STEREO;
    }

    _setAGLAttribute( AGL_AUX_BUFFERS,      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,   accumredbits );
    _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, accumgreenbits );
    _setAGLAttribute( AGL_ACCUM_BLUE_SIZE,  accumbluebits );
    _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, accumalphabits );

    pixelFormatAttributes[numAttrs++] = AGL_NONE;

    // create pixel format.

    AGLDevice mainMonitor = GetMainDevice();
    AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor,
                                                       1,
                                                       pixelFormatAttributes );
    if ( pixelFormat == NULL )
    {
        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 );
    _glfwWin.RefreshRate = refreshrate;

    // create AGL context

    _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL );

    aglDestroyPixelFormat( pixelFormat );

    if ( _glfwWin.AGLContext == NULL )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // create window

    Rect windowContentBounds;
    windowContentBounds.left = 0;
    windowContentBounds.top = 0;
    windowContentBounds.right = width;
    windowContentBounds.bottom = height;

    error = CreateNewWindow( kDocumentWindowClass,
                             GLFW_WINDOW_ATTRIBUTES,
                             &windowContentBounds,
                             &( _glfwWin.MacWindow ) );
    if ( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    if ( !_glfwWin.Fullscreen )
    {
      _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler );

      error = InstallWindowEventHandler( _glfwWin.MacWindow,
                                         _glfwWin.WindowUPP,
                                         GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ),
                                         GLFW_WINDOW_EVENT_TYPES,
                                         NULL,
                                         NULL );
      if ( error != noErr )
      {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
      }
    }

    // Don't care if we fail here
    (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) );
    (void)RepositionWindow( _glfwWin.MacWindow,
                            NULL,
                            kWindowCenterOnMainScreen );

    // TO DO: put this somewhere else; this is a bit too soon
    ShowWindow( _glfwWin.MacWindow );

    // show window, attach OpenGL context, &c

    if ( mode == GLFW_FULLSCREEN )
    {
        CGDisplayErr cgError;

        cgError = CGCaptureAllDisplays();
        if ( cgError != CGDisplayNoErr )
        {
            _glfwPlatformCloseWindow();
            return GL_FALSE;
        }

        HideMenuBar();

        // I have no idea if this will work at all, particularly on
        // multi-monitor systems.  Might need to use CGL for full-screen
        // setup and AGL for windowed (ugh!).
        if ( !aglSetFullScreen( _glfwWin.AGLContext,
                                width,
                                height,
                                refreshrate,
                                0 ) )
        {
            _glfwPlatformCloseWindow();
            return GL_FALSE;
        }
    }
    else
    {
        if ( !aglSetDrawable( _glfwWin.AGLContext,
                              GetWindowPort( _glfwWin.MacWindow ) ) )
        {
            _glfwPlatformCloseWindow();
            return GL_FALSE;
        }
    }

    // Make OpenGL context current;

    if ( !aglSetCurrentContext( _glfwWin.AGLContext ) )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    return GL_TRUE;
}
Ejemplo n.º 8
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;
}