nglVideoMode::nglVideoMode()
{
#ifdef __NGL_MACHO__
  mDisplay = CGMainDisplayID();
#endif  
  Init();

#ifdef __NGL_MACHO__
  CFDictionaryRef displayMode ;
  CFNumberRef number ;

  displayMode = (CFDictionaryRef) CGDisplayCurrentMode((CGDirectDisplayID)mDisplay) ;

  /* Get the height and width of this display mode. Print them out. */
  number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayWidth ) ;
  CFNumberGetValue( number, kCFNumberLongType, &mWidth ) ;
  number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayHeight ) ;
  CFNumberGetValue( number, kCFNumberLongType, &mHeight ) ;
  number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayRefreshRate ) ;
  CFNumberGetValue( number, kCFNumberLongType, &mRate ) ;
  number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayBitsPerPixel ) ;
  CFNumberGetValue( number, kCFNumberLongType, &mBPP ) ;
#else
  mWidth = 800;
  mHeight = 600;
  mBPP = 32;
  mRate = 60;
#endif
}
Esempio n. 2
0
static int Open(void * hwnd)
{
    CGLRendererInfoObj renderer;
    long numRenderer;
	CGDirectDisplayID l[32];
	CGDisplayCount count;

	SYS_ASSERT(g_pCGLC == 0);
	UNUSED(hwnd);
	CGGetActiveDisplayList (sizeof(l), l, &count);

#ifdef _DEBUG
	// Debug in multiple monitor. Use the secondary monitor for rendering
	g_cgDisplayID = l[count-1];
#else
	g_cgDisplayID = CGMainDisplayID ();
#endif

	g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID);
	g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID);

    CGLQueryRendererInfo(CGDisplayIDToOpenGLDisplayMask(g_cgDisplayID), &renderer, &numRenderer);
    CGLDestroyRendererInfo(renderer);

    return 0;
}
Esempio n. 3
0
void QuartzToggler::emitRate() {
	double rate = 0.0;

	CFNumberGetValue(static_cast<CFNumberRef>(CFDictionaryGetValue(CGDisplayCurrentMode(activeDspys[widgetScreen]), kCGDisplayRefreshRate)), kCFNumberDoubleType, &rate);

	emit rateChange(static_cast<int>(rate * 10.0 + 0.5));
}
Esempio n. 4
0
int _glfwPlatformInit( void )
{
    struct timeval tv;
    UInt32 nullDummy = 0;

    _glfwWin.MacWindow = NULL;
    _glfwWin.AGLContext = NULL;
    _glfwWin.WindowFunctions = NULL;
    _glfwWin.MouseUPP = NULL;
    _glfwWin.CommandUPP = NULL;
    _glfwWin.KeyboardUPP = NULL;
    _glfwWin.WindowUPP = NULL;
    
    _glfwInput.Modifiers = 0;
    
    _glfwLibs.OpenGLFramework
        = CFBundleGetBundleWithIdentifier( CFSTR( "com.apple.opengl" ) );
    if( _glfwLibs.OpenGLFramework == NULL )
    {
        return GL_FALSE;
    }

    _glfwDesktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
    if( _glfwDesktopVideoMode == NULL )
    {
        return GL_FALSE;
    }

    _glfwInitThreads();

    if( !_glfwChangeToResourcesDirectory() )
    {
        return GL_FALSE;
    }

    if( !_glfwInstallEventHandlers() )
    {
    	_glfwPlatformTerminate();
        return GL_FALSE;
    }

    // Ugly hack to reduce the nasty jump that occurs at the first non-
    // sys keypress, caused by OS X loading certain meta scripts used
    // for lexical- and raw keycode translation - instead of letting
    // this happen while our application is running, we do some blunt
    // function calls in advance just to get the script caching out of
    // the way, BEFORE our window/screen is opened. These calls might
    // generate err return codes, but we don't care in this case.
    // NOTE: KCHRPtr is declared globally, because we need it later on.
    KCHRPtr = (void *)GetScriptVariable( smCurrentScript, smKCHRCache );
    KeyTranslate( KCHRPtr, 0, &nullDummy );
    UppercaseText( (char *)&nullDummy, 0, smSystemScript );

    gettimeofday( &tv, NULL );
    _glfwTimer.t0 = tv.tv_sec + (double) tv.tv_usec / 1000000.0;

    return GL_TRUE;
}
Esempio n. 5
0
wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const
{
    CFDictionaryRef theValue = CGDisplayCurrentMode( m_id );

    return wxVideoMode(
        wxCFDictKeyToInt( theValue, kCGDisplayWidth ),
        wxCFDictKeyToInt( theValue, kCGDisplayHeight ),
        wxCFDictKeyToInt( theValue, kCGDisplayBitsPerPixel ),
        wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate ));
}
Esempio n. 6
0
QuartzToggler::QuartzToggler() :
originalMode(NULL),
activeDspys(NULL),
widgetScreen(0),
isFull(false)
{
	CGDisplayCount dspyCnt = 0;
	CGGetActiveDisplayList(0, 0, &dspyCnt);

	activeDspys = new CGDirectDisplayID[dspyCnt];
	CGGetActiveDisplayList(dspyCnt, activeDspys, &dspyCnt);

	infoVector.resize(dspyCnt);
	fullResIndex.resize(dspyCnt);
	fullRateIndex.resize(dspyCnt);

	for (CGDisplayCount i = 0; i < dspyCnt; ++i) {
		CGDirectDisplayID display = activeDspys[i];
		CFDictionaryRef currentMode = CGDisplayCurrentMode(display);
		CFArrayRef modesArray = CGDisplayAvailableModes(display);
		CFIndex numModes = CFArrayGetCount(modesArray);
		CFNumberRef bpp = static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel));

		for (CFIndex j = 0; j < numModes; ++j) {
			CFDictionaryRef mode = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(modesArray, j));

			if (CFNumberCompare(bpp, static_cast<CFNumberRef>(CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel)), NULL) == kCFCompareEqualTo) {
				addMode(mode, infoVector[i], NULL, NULL);
			}
		}
	}

	originalMode = CGDisplayCurrentMode(activeDspys[widgetScreen]);

	for (CGDisplayCount i = 0; i < dspyCnt; ++i) {
		unsigned resIndex = 0;
		unsigned rateIndex = 0;
		addMode(CGDisplayCurrentMode(activeDspys[i]), infoVector[i], &resIndex, &rateIndex);
		fullResIndex[i] = resIndex;
		fullRateIndex[i] = rateIndex;
	}
}
Esempio n. 7
0
DisplayMode NPAPICoreMacOSPlatform::GetCurrentDisplayMode()
{
	CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
	
	DisplayMode mode;
	mode.width = GetModeWidth(currentMode);
	mode.height = GetModeHeight(currentMode);
	mode.refreshRate = GetModeRefreshRate(currentMode);
	mode.bpp = GetModeBitsPerPixel(currentMode);
	
	return mode;
}
Esempio n. 8
0
Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
	CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
#else
	CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
#endif

	if(xres)
		*xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay);

	if(yres)
		*yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay);

	if(bpp)
	{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
		// CGDisplayBitsPerPixel was deprecated in OS X 10.6
		CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode);
		if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 32;
		else if (CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 16;
		else if (CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 8;
		else	// error
			*bpp = 0;

		// We're responsible for this
		CFRelease(pixelEncoding);
#else
		CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel);
		CFNumberGetValue(num, kCFNumberIntType, bpp);
#endif
	}

	if(freq)
	{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
		*freq = (int)CGDisplayModeGetRefreshRate(currentMode);
#else
		CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate);
		CFNumberGetValue(num, kCFNumberIntType, freq);
#endif
	}

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
	// We're responsible for this
	CGDisplayModeRelease(currentMode);
#endif

	return INFO::OK;
}
Esempio n. 9
0
static Bool
QuartzRandRCopyCurrentModeInfo(CGDirectDisplayID screenId,
                               QuartzModeInfoPtr pMode)
{
    CFDictionaryRef curModeRef = CGDisplayCurrentMode(screenId);
    if (!curModeRef)
        return FALSE;

    QuartzRandRGetModeInfo(curModeRef, pMode);
    pMode->ref = (void *)curModeRef;
    CFRetain(pMode->ref);
    return TRUE;
}
DisplayMode CoreMacOSPlatform::GetCurrentDisplayMode()
{
	CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
	
	// look at each mode in the available list
	//CFDictionaryRef modeSystem = (CFDictionaryRef)CFArrayGetValueAtIndex(currentMode, mode);

	DisplayMode mode;
	mode.width = GetModeWidth(currentMode);
	mode.height = GetModeHeight(currentMode);
	mode.refreshRate = GetModeRefreshRate(currentMode);
	mode.bpp = GetModeBitsPerPixel(currentMode);
	
	return mode;
}
Esempio n. 11
0
static void modewhacker( CGDirectDisplayID dspy )
{
    int i;
    CFDictionaryRef mode;
    CFDictionaryRef originalMode;
    boolean_t exactMatch;
    CGDisplayErr err;
    
    originalMode = CGDisplayCurrentMode( dspy );
    if ( originalMode == NULL )
    {
        printf( "Display is invalid\n" );
        return;
    }
    
    for ( i = 0; i < (sizeof myModeList / sizeof myModeList[0]); ++i )
    {
        printf( "Display 0x%x: Looking for %ld x %ld, %ld Bits Per Pixel\n",
                (unsigned int)dspy,
                myModeList[i].width,
                myModeList[i].height,
                myModeList[i].bitsPerPixel );

        mode = CGDisplayBestModeForParameters(dspy,
                                              myModeList[i].bitsPerPixel,
                                              myModeList[i].width,
                                              myModeList[i].height,
                                              &exactMatch);
        if ( exactMatch )
            printf( "Found an exact match, switching modes:\n" );
        else
            printf( "Found a mode, switching modes:\n" );
        printDesc( mode );

        sleep( 1 );	// Short pause, then switch
        err = CGDisplaySwitchToMode(dspy, mode);
        if ( err != CGDisplayNoErr )
        {
            printf( "Oops!  Mode switch failed?!?? (%d)\n", err );
            break;
        }
        printf( "Pausing for 5 seconds...\n" );
        sleep( 5 );
    }
    err = CGDisplaySwitchToMode(dspy, originalMode);
    if ( err != CGDisplayNoErr )
        printf( "Oops!  Mode restore failed?!?? (%d)\n", err );
}
Esempio n. 12
0
void gdip_get_display_dpi_carbon (float *h_dpi, float *v_dpi) {
	if (getenv ("MONO_MWF_MAC_DETECT_DPI") != NULL) {
		CFDictionaryRef mode_dict = CGDisplayCurrentMode (kCGDirectMainDisplay);
		io_connect_t display_port = CGDisplayIOServicePort (kCGDirectMainDisplay);
		CFDictionaryRef display_dict = IOCreateDisplayInfoDictionary (display_port, 0);
		const float mmpi = 25.4;
		float h_size = (float) gdip_get_int_from_dict_for_key (display_dict, CFSTR (kDisplayHorizontalImageSize)) / mmpi;
		float v_size = (float) gdip_get_int_from_dict_for_key (display_dict, CFSTR (kDisplayVerticalImageSize)) / mmpi;

		*h_dpi = (float) gdip_get_int_from_dict_for_key (mode_dict, kCGDisplayWidth) / h_size; 
		*v_dpi = (float) gdip_get_int_from_dict_for_key (mode_dict, kCGDisplayHeight) / v_size; 

		CFRelease (display_dict);
	} else {
		*h_dpi = *v_dpi = 96.0f;
	}
}
Esempio n. 13
0
int fs_ml_video_mode_get_current(fs_ml_video_mode *mode) {
    mode->width = 0;
    mode->height = 0;
    mode->fps = 0;
    mode->bpp = 0;
    mode->flags = 0;

#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060
    // CGDisplayCurrentMode is deprecated in Mac OS X 10.6, so we use
    // the new API here
    CGDirectDisplayID currentDisplay = CGDisplayPrimaryDisplay(
            kCGDirectMainDisplay);
    CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(
            currentDisplay);
    mode->width = CGDisplayModeGetWidth(currentMode);
    mode->height = CGDisplayModeGetHeight(currentMode);
    mode->fps = CGDisplayModeGetRefreshRate(currentMode);
    CGDisplayModeRelease(currentMode);
#else
    CFNumberRef number;
    long refresh, width, height;
    CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
    number = CFDictionaryGetValue(currentMode, kCGDisplayWidth);
    CFNumberGetValue(number, kCFNumberLongType, &width);
    number = CFDictionaryGetValue(currentMode, kCGDisplayHeight);
    CFNumberGetValue(number, kCFNumberLongType, &height);
    number = CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate);
    CFNumberGetValue(number, kCFNumberLongType, &refresh);
    mode->width = width;
    mode->height = height;
    mode->fps = refresh;
#endif

    //fs_log("WARNING: assuming 60 Hz refresh rate on Mac OS X\n");
    //mode->fps = 60;

    if (mode->fps == 0) {
        fs_log("WARNING: refresh rate was not detected\n");
        fs_log("full video sync will not be enabled automatically, but can "
                "be forced\n");
    }

    return 0;
}
Esempio n. 14
0
int _glfwPlatformInit( void )
{
    _glfwWin.MacWindow = NULL;
    _glfwWin.AGLContext = NULL;
    _glfwWin.WindowFunctions = NULL;
    _glfwWin.MouseUPP = NULL;
    _glfwWin.CommandUPP = NULL;
    _glfwWin.KeyboardUPP = NULL;
    _glfwWin.WindowUPP = NULL;
    
    _glfwInput.Modifiers = 0;
    
    _glfwLibs.OpenGLFramework
        = CFBundleGetBundleWithIdentifier( CFSTR( "com.apple.opengl" ) );
    if ( _glfwLibs.OpenGLFramework == NULL )
    {
        return GL_FALSE;
    }

    _glfwDesktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
    if ( _glfwDesktopVideoMode == NULL )
    {
        return GL_FALSE;
    }

    _glfwInitThreads();

    if ( !_glfwChangeToResourcesDirectory() )
    {
        return GL_FALSE;
    }

    if ( !_glfwInstallEventHandlers() )
    {
    	_glfwPlatformTerminate();
        return GL_FALSE;
    }

    _glfwTimer.t0 = GetCurrentEventTime();

    return GL_TRUE;
}
Esempio n. 15
0
////////////////////////////////////////////////////////////
/// Get current desktop video mode
////////////////////////////////////////////////////////////
void VideoModeGetDesktopMode(struct VideoMode * Mode)
{
	// Ceylo -- using same implementation as in OSXCarbon
	
	CFDictionaryRef CurrentVideoMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
	
	// Get video mode width
    CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayWidth),
					 kCFNumberIntType,
					 Mode.Width);
	
	// Get video mode height
    CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayHeight),
					 kCFNumberIntType,
					 Mode.Height);
	
	// Get video mode depth
    CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayBitsPerPixel),
					 kCFNumberIntType,
					 Mode.BitsPerPixel);
}
Esempio n. 16
0
void QuartzToggler::setFullMode(const bool enable) {
	CGDirectDisplayID display = activeDspys[widgetScreen];
	CFDictionaryRef currentMode = CGDisplayCurrentMode(display);

	CFDictionaryRef mode = currentMode;

	if (enable) {
		int bpp = 0;
		CFNumberGetValue(static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel)), kCFNumberIntType, &bpp);

		mode = CGDisplayBestModeForParametersAndRefreshRate(
			display,
			bpp,
			infoVector[widgetScreen][fullResIndex[widgetScreen]].w,
			infoVector[widgetScreen][fullResIndex[widgetScreen]].h,
			infoVector[widgetScreen][fullResIndex[widgetScreen]].rates[fullRateIndex[widgetScreen]] / 10.0,
			NULL
		);

		if (!isFull)
			originalMode = currentMode;
	} else if (isFull)
		mode = originalMode;

	if (mode != currentMode) {
		CGDisplaySwitchToMode(display, mode);

		double oldRate = 0.0;
		double newRate = 0.0;

		CFNumberGetValue(static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate)), kCFNumberDoubleType, &oldRate);
		CFNumberGetValue(static_cast<CFNumberRef>(CFDictionaryGetValue(mode, kCGDisplayRefreshRate)), kCFNumberDoubleType, &newRate);

		if (static_cast<int>(oldRate * 10.0 + 0.5) != static_cast<int>(newRate * 10.0 + 0.5))
			emit rateChange(static_cast<int>(newRate * 10.0 + 0.5));
	}

	isFull = enable;
}
Esempio n. 17
0
static int Open(void * hwnd)
{

	CGDirectDisplayID l[32];
	CGDisplayCount count;
	CGGetActiveDisplayList (sizeof(l), l, &count);

	SYS_ASSERT(g_pAGLC == 0);
	SYS_ASSERT(hwnd);
	static Rect rect;
	g_pRect = &rect;
	g_hWnd = (WindowPtr) hwnd;
#ifdef _DEBUG
	// Debug in multiple monitor. Use the secondary monitor for rendering
	g_cgDisplayID = l[count-1];
#else
	g_cgDisplayID = CGMainDisplayID ();
#endif

	g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID);
	g_cgOldDisplayModeRestore = 0;
	g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID);
    return 0;
}
Esempio n. 18
0
static Bool
QuartzRandREnumerateModes(ScreenPtr pScreen,
                          QuartzModeCallback callback,
                          void *data)
{
    Bool retval = FALSE;
    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);

    /* Just an 800x600 fallback if we have no attached heads */
    if (pQuartzScreen->displayIDs) {
        CFDictionaryRef curModeRef, modeRef;
        long curBpp;
        CFArrayRef modes;
        QuartzModeInfo modeInfo;
        int i;
        CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];

        curModeRef = CGDisplayCurrentMode(screenId);
        if (!curModeRef)
            return FALSE;
        curBpp = getDictLong(curModeRef, kCGDisplayBitsPerPixel);

        modes = CGDisplayAvailableModes(screenId);
        if (!modes)
            return FALSE;
        for (i = 0; i < CFArrayGetCount(modes); i++) {
            int cb;
            modeRef = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);

            /* Skip modes that are not usable on the current display or have a
               different pixel encoding than the current mode. */
            if (((unsigned long)getDictLong(modeRef, kCGDisplayIOFlags) &
                 kDisplayModeUsableFlags) != kDisplayModeUsableFlags)
                continue;
            if (getDictLong(modeRef, kCGDisplayBitsPerPixel) != curBpp)
                continue;

            QuartzRandRGetModeInfo(modeRef, &modeInfo);
            modeInfo.ref = (void *)modeRef;
            cb = callback(pScreen, &modeInfo, data);
            if (cb == CALLBACK_CONTINUE)
                retval = TRUE;
            else if (cb == CALLBACK_SUCCESS)
                return TRUE;
            else if (cb == CALLBACK_ERROR)
                return FALSE;
        }
    }

    switch (callback(pScreen, &pQuartzScreen->rootlessMode, data)) {
    case CALLBACK_SUCCESS:
        return TRUE;

    case CALLBACK_ERROR:
        return FALSE;

    case CALLBACK_CONTINUE:
        retval = TRUE;

    default:
        break;
    }

    switch (callback(pScreen, &pQuartzScreen->fullscreenMode, data)) {
    case CALLBACK_SUCCESS:
        return TRUE;

    case CALLBACK_ERROR:
        return FALSE;

    case CALLBACK_CONTINUE:
        retval = TRUE;

    default:
        break;
    }

    return retval;
}
bool macosxSetScreenResolution(QSize resolution, QPoint screenPoint)
{
	CGDirectDisplayID display = displayAtPoint(screenPoint);
	if (display == kCGNullDirectDisplay)
	{
		return false;
	}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	if (CGDisplayCopyAllDisplayModes != NULL)
	{
		bool ok = false;
		CGDisplayModeRef currentMainDisplayMode = CGDisplayCopyDisplayMode(display);
		CFStringRef currentPixelEncoding = CGDisplayModeCopyPixelEncoding(currentMainDisplayMode);
		CFArrayRef displayModes = CGDisplayCopyAllDisplayModes(display, NULL);
		for (CFIndex i = 0, c = CFArrayGetCount(displayModes); i < c; i++)
		{
			bool isEqual = false;
			CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(displayModes, i);
			CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
			if (CFStringCompare(pixelEncoding, currentPixelEncoding, 0) == kCFCompareEqualTo
			    && CGDisplayModeGetWidth(mode) == (size_t)resolution.width()
			    && CGDisplayModeGetHeight(mode) == (size_t)resolution.height())
			{
				isEqual = true;
			}
			CFRelease(pixelEncoding);

			if (isEqual)
			{
				CGDisplaySetDisplayMode(display, mode, NULL);
				ok = true;
				break;
			}
		}
		CFRelease(currentPixelEncoding);
		CFRelease(displayModes);
		return ok;
	}
	else
#endif
	{
		CFDictionaryRef currentMainDisplayMode = CGDisplayCurrentMode(display);
		int bpp;
		dictget(currentMainDisplayMode, Int, kCGDisplayBitsPerPixel, &bpp);
		boolean_t exactMatch = false;
		CFDictionaryRef bestMode = CGDisplayBestModeForParameters(display, bpp, resolution.width(), resolution.height(), &exactMatch);
		if (bestMode != NULL)
		{
			if (!exactMatch)
			{
				qWarning("No optimal display mode for requested parameters.");
			}
			CGDisplaySwitchToMode(display, bestMode);
			return true;
		}
		else
		{
			qWarning("Bad resolution change: Invalid display.");
			return false;
		}
	}
}
Esempio n. 20
0
unsigned char HaveOpenGLCapsChanged (GLCaps aDisplayCaps[], 
                                     CGDisplayCount dspyCnt)
{
  CGDisplayCount maxDisplays = 32;
  CGDirectDisplayID activeDspys[32];
  CGDisplayErr theError;
  short i;
  CGDisplayCount newDspyCnt = 0;
  
  if (NULL == aDisplayCaps) return 1;

  theError = CGGetActiveDisplayList(maxDisplays, activeDspys, &newDspyCnt);
  // if theError getting list mark as changed
  if (theError) return 1; 
  // if number of displays not equal
  if (dspyCnt != newDspyCnt) return 1;
  
  for (i = 0; i < dspyCnt; i++) {
    // get device ids
    if (aDisplayCaps[i].cgDisplayID != activeDspys[i]) return 1;
    if (aDisplayCaps[i].cglDisplayMask !=  
        CGDisplayIDToOpenGLDisplayMask(activeDspys[i])) return 1;
 
    // get current geometry
    {
      CGRect displayRect = CGDisplayBounds (activeDspys[i]);
      // get mode dictionary
      CFDictionaryRef dispMode = CGDisplayCurrentMode (activeDspys[i]);
      // check for all geometry matches 
      if (aDisplayCaps[i].deviceWidth != (long) displayRect.size.width)
        return 1;   
      if (aDisplayCaps[i].deviceHeight != (long) displayRect.size.height) 
        return 1;   
      if (aDisplayCaps[i].deviceOriginX != (long) displayRect.origin.x) 
        return 1;   
      if (aDisplayCaps[i].deviceOriginY != (long) displayRect.origin.y) 
        return 1;   
      if (aDisplayCaps[i].deviceDepth != 
                 (short) _getDictLong (dispMode,  kCGDisplayBitsPerPixel)) 
        return 1;    
      if (aDisplayCaps[i].deviceRefresh != 
          (short)(_getDictDouble (dispMode, kCGDisplayRefreshRate) + 0.5)) 
        return 1; // round to GLint
    }

    // get renderer info based on gDevice
    {
      CGLRendererInfoObj info;
        long j;
      GLint numRenderers = 0, rv = 0;
      CGLError theErr = 0;
      GLint deviceVRAM; // video memory in bytes
      unsigned long rendererID; // renderer ID
      
      theErr = CGLQueryRendererInfo (aDisplayCaps[i].cglDisplayMask, 
                                  &info, &numRenderers);
      if(0 == theErr) {
        CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers);
        for (j = 0; j < numRenderers; j++) {
          // find accelerated renderer (assume only one)
          CGLDescribeRenderer (info, j, kCGLRPAccelerated, &rv); 
          if (true == rv) { // if accelerated
            // what is the renderer ID
            CGLDescribeRenderer (info, j, kCGLRPRendererID, (GLint *)&rendererID); 
            if (rendererID != aDisplayCaps[i].rendererID) // check match
              return 1;
            // what is the VRAM
            CGLDescribeRenderer (info, j, kCGLRPVideoMemory, &deviceVRAM); 
            if (deviceVRAM != aDisplayCaps[i].deviceVRAM) // check match
              return 1;
            break; // done
          }
        }
      }
      CGLDestroyRendererInfo (info);
    }
  }
  return 0;
}
Esempio n. 21
0
void CheckOpenGLCaps (CGDisplayCount maxDspys, 
                      GLCaps dCaps[], 
                      CGDisplayCount * dCnt)
{
  CGLContextObj curr_ctx = 0;
  CGDirectDisplayID dspys[32];
  CGDisplayErr theErr;
  short i;
  short size = sizeof (GLCaps);
  
  // no devices
  *dCnt = 0;
  
  if (maxDspys == 0) { // find number of displays
    *dCnt = 0;
    theErr = CGGetActiveDisplayList (32, dspys, dCnt);
    if (theErr) // theErr getting list
      *dCnt = 0; // 0 displays since can't correctly find any
    // zero list to ensure the routines are used correctly
    memset (dspys, 0, sizeof (CGDirectDisplayID) * *dCnt);
    return; // return dCnt
  }
  if (NULL == dCaps) return;

  theErr = CGGetActiveDisplayList(maxDspys, dspys, dCnt);
  if (theErr) return; // theErr getting list
  if (0 == *dCnt) return; // no displays
  
  memset (dCaps, 0, size * *dCnt); // zero memory
  
  for (i = 0; i < *dCnt; i++) {
    // get device ids
    dCaps[i].cgDisplayID = dspys[i];
    dCaps[i].cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(dspys[i]);
    
    { // get current geometry
      CGRect displayRect = CGDisplayBounds (dspys[i]);
      // get mode dictionary
      CFDictionaryRef dispMode = CGDisplayCurrentMode (dspys[i]); 
      dCaps[i].deviceWidth = (long) displayRect.size.width;   
      dCaps[i].deviceHeight = (long) displayRect.size.height;   
      dCaps[i].deviceOriginX = (long) displayRect.origin.x;   
      dCaps[i].deviceOriginY = (long) displayRect.origin.y;   
      dCaps[i].deviceDepth = (short) _getDictLong (dispMode,  
                                              kCGDisplayBitsPerPixel);    
      dCaps[i].deviceRefresh = (short) (_getDictDouble (dispMode,
                                        kCGDisplayRefreshRate) + 0.5); 
    }    

    { // get renderer info based on gDevice
      CGLRendererInfoObj info;
        long j;
        GLint numRenderers = 0;
        GLint rv = 0;
      CGLError theErr2 = 0;
      
      theErr2 = CGLQueryRendererInfo (dCaps[i].cglDisplayMask, 
                                  &info, 
                                  &numRenderers);
      if(0 == theErr2) {
        CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers);
        for (j = 0; j < numRenderers; j++) {
          // find accelerated renderer (assume only one)
          CGLDescribeRenderer (info, j, kCGLRPAccelerated, &rv); 
          if (true == rv) { // if accelerated
            // what is the renderer ID
            CGLDescribeRenderer (info, j, kCGLRPRendererID,
                                 &dCaps[i].rendererID);
            // can we do full screen?
            CGLDescribeRenderer (info, j, kCGLRPFullScreen, &rv); 
            dCaps[i].fullScreenCapable = (bool) rv;
            // what is the VRAM?
            CGLDescribeRenderer (info, j, kCGLRPVideoMemory,
                                 &dCaps[i].deviceVRAM);
            // what is the current texture memory? 
            CGLDescribeRenderer (info, j, kCGLRPTextureMemory,
                                 &dCaps[i].deviceTextureRAM);
            break; // done
          }
        }
      }
      CGLDestroyRendererInfo (info);
    }

    { // build context and context specific info
      CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask,
                                            dCaps[i].cglDisplayMask, 
                                            (CGLPixelFormatAttribute)0 };
      CGLPixelFormatObj pixelFormat = NULL;
      GLint numPixelFormats = 0;
      CGLContextObj cglContext;
      
      curr_ctx = CGLGetCurrentContext (); // get current CGL context
      CGLChoosePixelFormat (attribs, &pixelFormat, &numPixelFormats);
      if (pixelFormat) {
        CGLCreateContext(pixelFormat, NULL, &cglContext);
        CGLDestroyPixelFormat (pixelFormat);
        CGLSetCurrentContext (cglContext);
        if (cglContext) {
          const GLubyte * strExt;
          const GLubyte * strRend;
          const GLubyte * strVers;
          const GLubyte * strVend;

          // get renderer strings
          strRend = glGetString (GL_RENDERER);
          strncpy (dCaps[i].strRendererName, (char *) strRend, 255);
          strVend = glGetString (GL_VENDOR);
          strncpy (dCaps[i].strRendererVendor, (char *) strVend, 255);
          strVers = glGetString (GL_VERSION);
          strncpy (dCaps[i].strRendererVersion, (char *) strVers, 255);
          { // get BCD version
            short j = 0;
            short shiftVal = 8;
            while (((strVers[j] <= '9') && (strVers[j] >= '0')) ||
                                            (strVers[j] == '.')) { 
            // get only basic version info (until first non-digit or non-.)
              if ((strVers[j] <= '9') && (strVers[j] >= '0')) {
                dCaps[i].glVersion += (strVers[j] - '0') << shiftVal;
                shiftVal -= 4;
              }
              j++;
            }
          }
          strExt = glGetString (GL_EXTENSIONS);

          // get caps
          glGetIntegerv (GL_MAX_TEXTURE_UNITS, 
                         &dCaps[i].textureUnits);
          glGetIntegerv (GL_MAX_TEXTURE_SIZE,
                         &dCaps[i].maxTextureSize); 
          glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE, 
                         &dCaps[i].max3DTextureSize);
          glGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE, 
                         &dCaps[i].maxCubeMapTextureSize);

          // get functionality info
		  dCaps[i].fSpecularVector = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_specular_vector", strExt);
          dCaps[i].fTransformHint = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_transform_hint", strExt);
          dCaps[i].fPackedPixels = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixels", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixel", strExt)  || 
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fClientStorage = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_client_storage", strExt);
          dCaps[i].fYCbCr = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_ycbcr_422", strExt);
          dCaps[i].fTextureRange = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_texture_range", strExt);
          dCaps[i].fFence = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_fence", strExt);
          dCaps[i].fVAR = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_range", strExt);
          dCaps[i].fVAO = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_object", strExt);
          dCaps[i].fElementArray = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_element_array", strExt);
          dCaps[i].fVPEvals = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_program_evaluators",strExt);
          dCaps[i].fFloatPixels = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_float_pixels", strExt);
          dCaps[i].fFlushRenderer = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_render", strExt);
          dCaps[i].fPixelBuffer = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_pixel_buffer", strExt);
          dCaps[i].fImaging = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fTransposeMatrix = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_transpose_matrix", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fMultitexture = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_multitexture", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvAdd = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_add", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_env_add", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvCombine = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_combine", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvDot3 = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_dot3", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvCrossbar = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_crossbar", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTexCubeMap = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_cube_map", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexCompress = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_compression", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fMultisample = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_multisample", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexBorderClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_border_clamp", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fPointParam = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_point_parameters", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fVertexProg = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_program", strExt);
          dCaps[i].fFragmentProg = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program", strExt);
          dCaps[i].fTexMirrorRepeat = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_mirrored_repeat", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fDepthTex = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_depth_texture", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadow = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shadow", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadowAmbient = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shadow_ambient", strExt);
          dCaps[i].fVertexBlend = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_blend", strExt);
          dCaps[i].fWindowPos = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_window_pos", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTex3D = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture3D", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fClipVolHint = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_clip_volume_hint", strExt);
          dCaps[i].fRescaleNorm = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_rescale_normal", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fBlendColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_color", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fBlendMinMax = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_minmax", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fBlendSub = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_subtract", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fCVA = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_compiled_vertex_array", strExt);
          dCaps[i].fTexLODBias = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_lod_bias", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fABGR = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_abgr", strExt);
          dCaps[i].fBGRA = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_bgra", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fTexFilterAniso = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_filter_anisotropic",strExt);
          dCaps[i].fPaletteTex = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_paletted_texture", strExt);
          dCaps[i].fShareTexPalette = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_shared_texture_palette", strExt);
          dCaps[i].fSecColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_secondary_color", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTexCompressS3TC = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_s3tc", strExt);
          dCaps[i].fTexRect = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_rectangle", strExt);
          dCaps[i].fFogCoord = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_fog_coord", strExt);
          dCaps[i].fDrawRangeElements = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_draw_range_elements", strExt);
          dCaps[i].fStencilWrap = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_wrap", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fBlendFuncSep = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_func_separate", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fMultiDrawArrays = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_multi_draw_arrays", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadowFunc = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_shadow_funcs", strExt);
          dCaps[i].fStencil2Side = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_two_side", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fColorSubtable = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_color_subtable", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fConvolution = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_convolution", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fHistogram = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_histogram", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fColorTable = 
			  gluCheckExtension ((const GLubyte *) "GL_SGI_color_table", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fColorMatrix = 
			  gluCheckExtension ((const GLubyte *) "GL_SGI_color_matrix", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fTexEdgeClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_edge_clamp", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fGenMipmap = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_generate_mipmap", strExt);
          dCaps[i].fTexLOD = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_lod", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fPointCull = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_point_cull_mode", strExt);
          dCaps[i].fTexMirrorOnce = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_mirror_once", strExt);
          dCaps[i].fPNtriangles = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_pn_triangles", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ATIX_pn_triangles", strExt);
          dCaps[i].fTextFragShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_text_fragment_shader", strExt);
          dCaps[i].fATIBlendEqSep = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_blend_equation_separate", strExt);
          dCaps[i].fBlendWeightMinMax = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_blend_weighted_minmax", strExt);
          dCaps[i].fCombine3 = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_env_combine3", strExt);
          dCaps[i].fSepStencil = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_separate_stencil", strExt);
          dCaps[i].fArrayRevComps4Byte = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_array_rev_comps_in_4_bytes",strExt);
          dCaps[i].fNVPointSprite = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_point_sprite", strExt);
          dCaps[i].fRegCombiners = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners", strExt);
          dCaps[i].fRegCombiners2 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners2", strExt);
          dCaps[i].fTexEnvCombine4 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_env_combine4", strExt);
          dCaps[i].fBlendSquare = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_blend_square", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fFogDist = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_fog_distance", strExt);
          dCaps[i].fMultisampleFilterHint = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_multisample_filter_hint", strExt);
          dCaps[i].fTexGenReflect = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texgen_reflection", strExt);
          dCaps[i].fTexShader = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader", strExt);
          dCaps[i].fTexShader2 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader2", strExt);
          dCaps[i].fTexShader3 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader3", strExt);
          dCaps[i].fDepthClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_depth_clamp", strExt);
          dCaps[i].fLightMaxExp = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_light_max_exponent", strExt);
          dCaps[i].fRasterPosClip = 
			  gluCheckExtension ((const GLubyte *) "GL_IBM_rasterpos_clip", strExt);
          dCaps[i].fConvBorderModes = 
			  gluCheckExtension ((const GLubyte *) "GL_HP_convolution_border_modes", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
		  dCaps[i].fAuxDeptStencil =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_aux_depth_stencil", strExt);
		  dCaps[i].fFlushBufferRange =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_buffer_range", strExt);
		  dCaps[i].fObjectPurgeable =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_object_purgeable", strExt);
		  dCaps[i].fDrawBuffers =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_draw_buffers", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fFragmentProgShadow =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program_shadow", strExt);
		  dCaps[i].fFragmentShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_shader", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fHalfFloatPixel = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_half_float_pixel", strExt);
		  dCaps[i].fOcclusionQuery = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_occlusion_query", strExt) ||
			  (dCaps[i].glVersion >= 0x0150);
		  dCaps[i].fPBO = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_pixel_buffer_object", strExt) ||
			  (dCaps[i].glVersion >= 0x0210);
		  dCaps[i].fPointSprite = 			
			  gluCheckExtension ((const GLubyte *) "GL_ARB_point_sprite", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fShaderObjects = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shader_objects", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fShaderTextureLOD = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shader_texture_lod", strExt);
		  dCaps[i].fShadingLanguage100 =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shading_language_100", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fTexFloat =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_float", strExt);
		  dCaps[i].fTexNPOT = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_non_power_of_two", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fVBO = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_buffer_object", strExt) ||
			  (dCaps[i].glVersion >= 0x0150);
		  dCaps[i].fVertexShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_shader", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fTexComp3dc = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_compression_3dc", strExt);
		  dCaps[i].fTexATIfloat = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_float", strExt);
		  dCaps[i].fBlendEqSep = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_equation_separate", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fDepthBounds = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_depth_bounds_test", strExt);
		  dCaps[i].fFBOblit =
			  gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_blit", strExt);
		  dCaps[i].fFBO = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_object", strExt);
		  dCaps[i].fGeometryShader4 = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_geometry_shader4", strExt);
		  dCaps[i].fGPUProgParams = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_program_parameters", strExt);
		  dCaps[i].fGPUShader4 = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_shader4", strExt);
		  dCaps[i].fDepthStencil = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_packed_depth_stencil", strExt);
		  dCaps[i].fSepSpecColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_separate_specular_color", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
		  dCaps[i].fTexCompDXT1 =
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_dxt1", strExt);
		  dCaps[i].fTexMirrorClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_mirror_clamp", strExt);
		  dCaps[i].fTexSRGB = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_sRGB", strExt) ||
			  (dCaps[i].glVersion >= 0x0210);		  
		  
		  if (dCaps[i].fTexRect) // only check if extension supported
				glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT,
							   &dCaps[i].maxRectTextureSize);
			else
				dCaps[i].maxRectTextureSize = 0;
			
          CGLDestroyContext (cglContext);
        }
      }
      CGLSetCurrentContext (curr_ctx); // reset current CGL context
    }
  }
}
bool macosxAppendAvailableScreenResolutions(QList<QSize> &resolutions, QSize minSize, QPoint screenPoint)
{
	CGDirectDisplayID display = displayAtPoint(screenPoint);
	if (display == kCGNullDirectDisplay)
	{
		return false;
	}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	bool modern = (CGDisplayCopyAllDisplayModes != NULL); // where 'modern' means >= 10.6
#endif

	CFArrayRef displayModes;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	if (modern)
	{
		displayModes = CGDisplayCopyAllDisplayModes(display, NULL);
	}
	else
#endif
	{
		displayModes = CGDisplayAvailableModes(display);
	}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	CFStringRef currentPixelEncoding = NULL;
#endif
	double currentRefreshRate;
	int curBPP, curBPS, curSPP;

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	if (modern)
	{
		CGDisplayModeRef currentDisplayMode = CGDisplayCopyDisplayMode(display);
		currentRefreshRate = CGDisplayModeGetRefreshRate(currentDisplayMode);
		currentPixelEncoding = CGDisplayModeCopyPixelEncoding(currentDisplayMode);
		CFRelease(currentDisplayMode);
	}
	else
#endif
	{
		CFDictionaryRef currentDisplayMode = CGDisplayCurrentMode(display);
		dictget(currentDisplayMode, Double, kCGDisplayRefreshRate, &currentRefreshRate);
		dictget(currentDisplayMode, Int, kCGDisplayBitsPerPixel, &curBPP);
		dictget(currentDisplayMode, Int, kCGDisplayBitsPerSample, &curBPS);
		dictget(currentDisplayMode, Int, kCGDisplaySamplesPerPixel, &curSPP);
	}

	for (CFIndex j = 0, c = CFArrayGetCount(displayModes); j < c; j++)
	{
		int width, height;
		double refreshRate;
		bool pixelEncodingsEqual;

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
		if (modern)
		{
			CGDisplayModeRef displayMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(displayModes, j);
			width = (int)CGDisplayModeGetWidth(displayMode);
			height = (int)CGDisplayModeGetHeight(displayMode);
			refreshRate = CGDisplayModeGetRefreshRate(displayMode);
			CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(displayMode);
			pixelEncodingsEqual = (CFStringCompare(pixelEncoding, currentPixelEncoding, 0) == kCFCompareEqualTo);
			CFRelease(pixelEncoding);
		}
		else
#endif
		{
			CFDictionaryRef displayMode = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, j);
			dictget(displayMode, Int, kCGDisplayWidth, &width);
			dictget(displayMode, Int, kCGDisplayHeight, &height);
			dictget(displayMode, Double, kCGDisplayRefreshRate, &refreshRate);
			int bpp, bps, spp;
			dictget(displayMode, Int, kCGDisplayBitsPerPixel, &bpp);
			dictget(displayMode, Int, kCGDisplayBitsPerSample, &bps);
			dictget(displayMode, Int, kCGDisplaySamplesPerPixel, &spp);
			pixelEncodingsEqual = (bpp == curBPP && bps == curBPS && spp == curSPP);
		}

		QSize res(width, height);
		if (!resolutions.contains(res)
		    && width >= minSize.width() && height >= minSize.height()
		    && refreshRate == currentRefreshRate && pixelEncodingsEqual)
		{
			resolutions += res;
		}
	}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	if (modern)
	{
		CFRelease(currentPixelEncoding);
		CFRelease(displayModes);
	}
#endif

	return true;
}
Esempio n. 23
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;
}
PsychError SCREENReadNormalizedGammaTable(void)
{
    int		i, screenNumber, numEntries, reallutsize, physicalDisplay, outputId;
    float 	*redTable, *greenTable, *blueTable;
    double	*gammaTable;	

    //all subfunctions should have these two lines
    PsychPushHelp(useString, synopsisString, seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

    PsychErrorExit(PsychCapNumOutputArgs(3));
    PsychErrorExit(PsychCapNumInputArgs(2));

    // Get optional physicalDisplay argument - It defaults to zero:
    physicalDisplay = -1;
    PsychCopyInIntegerArg(2, FALSE, &physicalDisplay);

    // Read in the screen number:
    // On OS/X we also accept screen indices for physical displays (as opposed to active dispays).
    // This only makes a difference in mirror-mode, where there is only 1 active display, but that
    // corresponds to two physical displays which can have different gamma setting requirements:
    if ((PSYCH_SYSTEM == PSYCH_OSX) && (physicalDisplay > 0)) {
        PsychCopyInIntegerArg(1, TRUE, &screenNumber);
	if (screenNumber < 1) PsychErrorExitMsg(PsychError_user, "A 'screenNumber' that is smaller than one provided, although 'physicalDisplay' flag set. This is not allowed!");

	// Invert screenNumber as a sign its a physical display, not an active display:
	screenNumber = -1 * screenNumber;
    }
    else {
        PsychCopyInScreenNumberArg(1, TRUE, &screenNumber);
    }

    if ((PSYCH_SYSTEM == PSYCH_LINUX) && (physicalDisplay > -1)) {
	// Affect one specific display output for given screen:
	outputId = physicalDisplay;
    }
    else {
	// Other OS'es, and Linux with default setting: Affect all outputs
	// for a screen.
	outputId = -1;
    }

    // Retrieve gamma table:
    PsychReadNormalizedGammaTable(screenNumber, outputId, &numEntries, &redTable, &greenTable, &blueTable);
	
    // Copy it out to runtime:
    PsychAllocOutDoubleMatArg(1, FALSE, numEntries, 3, 0, &gammaTable);

    for(i=0;i<numEntries;i++){
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 0, 0)]=(double)redTable[i];
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 1, 0)]=(double)greenTable[i];
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 2, 0)]=(double)blueTable[i];
    }

    // Copy out optional DAC resolution value:
    PsychCopyOutDoubleArg(2, FALSE, (double) PsychGetDacBitsFromDisplay(screenNumber));
	
    // We default to the assumption that the real size of the hardware LUT is identical to
    // the size of the returned LUT:
    reallutsize = numEntries;
	
    #if PSYCH_SYSTEM == PSYCH_OSX
		// On OS-X we query the real LUT size from the OS and return that value:
		CGDirectDisplayID	displayID;
		CFMutableDictionaryRef properties;
		CFNumberRef cfGammaLength;
		SInt32 lutslotcount;
		io_service_t displayService;
		kern_return_t kr;
		CFMutableArrayRef framebufferTimings0 = 0;
		CFDataRef framebufferTimings1 = 0;
		IODetailedTimingInformationV2 *framebufferTiming = NULL;
		
		// Retrieve display handle for screen:
		PsychGetCGDisplayIDFromScreenNumber(&displayID, screenNumber);
		
		if (PsychPrefStateGet_Verbosity()>5) printf("PTB-DEBUG: Screen %i has framebuffer address %p.\n", screenNumber, CGDisplayBaseAddress(displayID));

		// Retrieve low-level IOKit service port for this display:
		displayService = CGDisplayIOServicePort(displayID);
				
		// Obtain the properties from that service
		kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
		if((kr == kIOReturnSuccess) && ((cfGammaLength = (CFNumberRef) CFDictionaryGetValue(properties, CFSTR(kIOFBGammaCountKey)))!=NULL))
		{
			CFNumberGetValue(cfGammaLength, kCFNumberSInt32Type, &lutslotcount);
			CFRelease(properties);
			reallutsize = (int) lutslotcount;
		}
		else {
			// Failed!
			if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query real size of video LUT for screen %i! Will return safe default of %i slots.\n", screenNumber, reallutsize);
		}	

		if (PsychPrefStateGet_Verbosity()>9) {			
			CFDictionaryRef currentMode;
			CFNumberRef n;
			int modeId;
			currentMode = CGDisplayCurrentMode(displayID);
			n=CFDictionaryGetValue(currentMode, kCGDisplayMode);
			CFNumberGetValue(n, kCFNumberIntType, &modeId);
			printf("Current mode has id %i\n\n", modeId);
			kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
			if((kr == kIOReturnSuccess) && ((framebufferTimings0 = (CFMutableArrayRef) CFDictionaryGetValue(properties, CFSTR(kIOFBDetailedTimingsKey) ) )!=NULL))
			{
				for (i=0; i<CFArrayGetCount(framebufferTimings0); i++) {
					if ((framebufferTimings1 = CFArrayGetValueAtIndex(framebufferTimings0, i)) != NULL) {
						if ((framebufferTiming = (IODetailedTimingInformationV2*) CFDataGetBytePtr(framebufferTimings1)) != NULL) {
							printf("[%i] : VActive =  %li, VBL = %li, VSYNC = %li, VSYNCWIDTH = %li , VBORDERBOT = %li, VTOTAL = %li \n", i, framebufferTiming->verticalActive, framebufferTiming->verticalBlanking, framebufferTiming->verticalSyncOffset, framebufferTiming->verticalSyncPulseWidth, framebufferTiming->verticalBorderBottom, framebufferTiming->verticalActive + framebufferTiming->verticalBlanking);
						}
					}
				}

				CFRelease(properties);
			}
			else {
				// Failed!
				if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query STUFF for screen %i --> %p!\n", screenNumber, properties);
			}	
		}
		


    #endif
	
    // Copy out optional real LUT size (number of slots):
    PsychCopyOutDoubleArg(3, FALSE, (double) reallutsize);

    return(PsychError_none);
}
Esempio n. 25
0
DisplayInfo MythDisplay::GetDisplayInfo(int video_rate)
{
    DisplayInfo ret;

#if defined(Q_WS_MAC)
    CGDirectDisplayID disp = GetOSXDisplay(GetWindowID());
    if (!disp)
        return ret;

    CFDictionaryRef ref = CGDisplayCurrentMode(disp);
    float rate = 0.0f;
    if (ref)
        rate = get_float_CF(ref, kCGDisplayRefreshRate);

    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);

    CGSize size_in_mm = CGDisplayScreenSize(disp);
    ret.size = QSize((uint) size_in_mm.width, (uint) size_in_mm.height);

    uint width  = (uint)CGDisplayPixelsWide(disp);
    uint height = (uint)CGDisplayPixelsHigh(disp);
    ret.res     = QSize(width, height);

#elif defined(Q_WS_WIN)
    HDC hdc = GetDC(GetWindowID());
    int rate = 0;
    if (hdc)
    {
        rate       = GetDeviceCaps(hdc, VREFRESH);
        int width  = GetDeviceCaps(hdc, HORZSIZE);
        int height = GetDeviceCaps(hdc, VERTSIZE);
        ret.size   = QSize((uint)width, (uint)height);
        width      = GetDeviceCaps(hdc, HORZRES);
        height     = GetDeviceCaps(hdc, VERTRES);
        ret.res    = QSize((uint)width, (uint)height);
    }

    if (VALID_RATE(rate))
    {
        // see http://support.microsoft.com/kb/2006076
        switch (rate)
        {
        case 23:
            ret.rate = 41708;
            break; // 23.976Hz
        case 29:
            ret.rate = 33367;
            break; // 29.970Hz
        case 47:
            ret.rate = 20854;
            break; // 47.952Hz
        case 59:
            ret.rate = 16683;
            break; // 59.940Hz
        case 71:
            ret.rate = 13903;
            break; // 71.928Hz
        case 119:
            ret.rate = 8342;
            break; // 119.880Hz
        default:
            ret.rate = 1000000.0f / (float)rate;
        }
    }
    else
        ret.rate = fix_rate(video_rate);

#elif USING_X11
    MythXDisplay *disp = OpenMythXDisplay();
    if (!disp)
        return ret;

    float rate = disp->GetRefreshRate();
    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);
    ret.res  = disp->GetDisplaySize();
    ret.size = disp->GetDisplayDimensions();
    delete disp;
#endif
    return ret;
}
Esempio n. 26
0
bool gl_initialize(int screen_wid,int screen_high,bool lock_fps_refresh,int fsaa_mode,bool reset,char *err_str)
{
    GLint				ntxtunit,ntxtsize;
#ifdef D3_OS_MAC
    long				swapint,rect[4];
	CGLContextObj		current_ctx;
	CFDictionaryRef		mode_info;
	CFNumberRef			cf_rate;
#else
	GLenum				glew_error;
#endif
		
		// setup rendering sizes
        
	setup.screen.x_sz=screen_wid;
	setup.screen.y_sz=screen_high;
	
		// normal attributes
		
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
	
		// full screen anti-aliasing attributes
		
	switch (fsaa_mode) {
		case fsaa_mode_low:
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,2);
			break;
		case fsaa_mode_medium:
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4);
			break;
		case fsaa_mode_high:
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,6);
			break;
	}

		// start window or full screen
		
	if (gl_in_window_mode()) {
		surface=SDL_SetVideoMode(setup.screen.x_sz,setup.screen.y_sz,32,SDL_OPENGL|SDL_HWSURFACE);
		SDL_WM_SetCaption("dim3",NULL);
	}
	else {
		surface=SDL_SetVideoMode(setup.screen.x_sz,setup.screen.y_sz,32,SDL_OPENGL|SDL_FULLSCREEN);
	}

	if (surface==NULL) {
		sprintf(err_str,"SDL: Could not set video mode (Error: %s)",SDL_GetError());
		return(FALSE);
	}
	
		// work around the dock losing minimize buttons because
		// of SDL luncancy
		
#ifdef D3_OS_MAC
	if (!gl_in_window_mode()) SetSystemUIMode(kUIModeContentSuppressed,0);
#endif
	
		// use glew on linux and windows
		
#ifndef D3_OS_MAC
	glew_error=glewInit();
	if (glew_error!=GL_NO_ERROR) {
		strcpy(err_str,glewGetErrorString(glew_error));
		return(FALSE);
	}
#endif

		// grab openGL attributes
		
	strncpy(render_info.name,(char*)glGetString(GL_RENDERER),64);
	render_info.name[63]=0x0;
	
	strncpy(render_info.ext_string,(char*)glGetString(GL_EXTENSIONS),8192);
	render_info.ext_string[8191]=0x0;
			
	glGetIntegerv(GL_MAX_TEXTURE_UNITS,&ntxtunit);
	render_info.texture_unit_count=(int)ntxtunit;

	glGetIntegerv(GL_MAX_TEXTURE_SIZE,&ntxtsize);
	render_info.texture_max_size=(int)ntxtsize;

		// in case screen is bigger than desired drawing surface
		
    render_info.monitor_x_sz=surface->w;
	render_info.monitor_y_sz=surface->h;

	render_info.view_x=(render_info.monitor_x_sz-setup.screen.x_sz)>>1;
	render_info.view_y=(render_info.monitor_y_sz-setup.screen.y_sz)>>1;
	
		// determine the referesh rate

	render_info.monitor_refresh_rate=60;				// windows XP has a stuck refresh rate of 60
		
#ifdef D3_OS_MAC
	mode_info=CGDisplayCurrentMode(CGMainDisplayID());
	if (mode_info!=NULL) {
		cf_rate=(CFNumberRef)CFDictionaryGetValue(mode_info,kCGDisplayRefreshRate);
		if (cf_rate) {
			CFNumberGetValue(cf_rate,kCFNumberIntType,&render_info.monitor_refresh_rate);
			if (render_info.monitor_refresh_rate==0) render_info.monitor_refresh_rate=60;
		}
	}
#endif

        // clear the entire window so it doesn't flash
        
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);
   
	SDL_GL_SwapBuffers();

        // setup renderer

#ifdef D3_OS_MAC
	current_ctx=CGLGetCurrentContext();
	
	rect[0]=render_info.view_x;
	rect[1]=render_info.view_y;
	rect[2]=setup.screen.x_sz;
	rect[3]=setup.screen.y_sz;
 
 	CGLSetParameter(current_ctx,kCGLCPSwapRectangle,rect);
	CGLEnable(current_ctx,kCGLCESwapRectangle);

	if (lock_fps_refresh) {
		swapint=1;
		CGLSetParameter(current_ctx,kCGLCPSwapInterval,&swapint);
	}
#endif

	glViewport(render_info.view_x,render_info.view_y,setup.screen.x_sz,setup.screen.y_sz);
	
		// perspective correction
		
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
		
		// smoothing and anti-aliasing
		
	glDisable(GL_DITHER);
	
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
	
	if (fsaa_mode!=fsaa_mode_none) glEnable(GL_MULTISAMPLE);
	
		// texture compression
		
	glHint(GL_TEXTURE_COMPRESSION_HINT,GL_NICEST);
	glHint(GL_GENERATE_MIPMAP_HINT,GL_NICEST);
	
		// all alphas by 8 bit component
		
	glDisable(GL_ALPHA_TEST);

		// texture utility initialize
		
	gl_texture_initialize();
	
		// do an initial draw
		
	if (!reset) {
		glClearColor(0,0,0,0);
		glClear(GL_COLOR_BUFFER_BIT);
		
		SDL_GL_SwapBuffers();
	}
	
	return(TRUE);
}