Exemplo n.º 1
0
    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;
        }
    }
Exemplo n.º 2
0
/**
 * Find best pixel format.
 *
 * \param[in,out] red_size desired red channel bits
 * \param[in,out] green_size desired green channel bits
 * \param[in,out] blue_size desired blue channel bits
 * \param[in,out] alpha_size desired alpha channel bits
 * \param[in,out] depth_size desired depth channel bits
 * \param[in,out] stencil_size desired stencil channel bits
 *
 * \return best pixel format
 */
static GrPixelFormat_t
findPixelFormat (int *red_size, int *green_size, int *blue_size,
		 int *alpha_size, int *depth_size, int *stencil_size)
{
    int colorDepth = *red_size + *green_size + *blue_size;
    int depthDepth = *depth_size;

    GrPixelFormat_t pixFmt = 0;

    int numChips = getInteger(GR_NUM_FB);
    int fsaa = getFSAA(numChips);

    if (hwext_pixext && colorDepth < 16) {
	/* Napalm_Spec.pdf, page 121
	 * There is no capability when running in 15 BPP rendering mode to
	 * selectively disable writes to only the RGB or the alpha planes - both
	 * the RGB planes and the 1-bit alpha plane are controlled together by
	 * fbzMode bit(9).
	 * Note that when running in 15 BPP rendering mode, the auxiliary buffer
	 * must be setup as a depth buffer (fbzMode bit(18)=0) and thus fbzMode
	 * bit(10) is used to enable writes to the depth buffer - fbzMode bit(9)
	 * is then used to enable writes to the 1-bit alpha plane.
	 *
	 * Unfortunately, the 15bpp mode is not reliable:
	 *	gsst.c: renderMode must be OR'ed with SST_RM_ALPHA_MSB
	 *	gglide.c: grBufferClear MUST use zaColor to fastfill 1-bit alpha
	 */
	*red_size = 5;
	*green_size = 5;
	*blue_size = 5;
	*alpha_size = 1;
	*depth_size = 16;
	*stencil_size = 0;
	switch (fsaa) {
	    case 8:
		pixFmt = GR_PIXFMT_AA_8_ARGB_1555;
		break;
	    case 4:
		pixFmt = GR_PIXFMT_AA_4_ARGB_1555;
		break;
	    case 2:
		pixFmt = GR_PIXFMT_AA_2_ARGB_1555;
		break;
	    default:
		pixFmt = GR_PIXFMT_ARGB_1555;
	}
    } else if (hwext_pixext && colorDepth > 16) {
	*red_size = 8;
	*green_size = 8;
	*blue_size = 8;
	*alpha_size = 8;
	*depth_size = 24;
	*stencil_size = 8;
	switch (fsaa) {
	    case 8:
		pixFmt = GR_PIXFMT_AA_8_ARGB_8888;
		break;
	    case 4:
		pixFmt = GR_PIXFMT_AA_4_ARGB_8888;
		break;
	    case 2:
		pixFmt = GR_PIXFMT_AA_2_ARGB_8888;
		break;
	    default:
		pixFmt = GR_PIXFMT_ARGB_8888;
	}
    } else {
	/* grBufferClear has a bug in Windowed or SDRAM alphabuffer clears
	 *	depth = (depth << 8) | depth
	 *
	 * To enable alphabuffer, we need:
	 *	grDepthMask(FXFALSE);
	 *	grDepthBufferMode(GR_DEPTHBUFFER_DISABLE);
	 * and never EVER enable depthmask
	 */
	*red_size = 5;
	*green_size = 6;
	*blue_size = 5;
	*alpha_size = depthDepth ? 0 : 8;
	*depth_size = depthDepth ? 16 : 0;
	*stencil_size = 0;
	switch (fsaa) {
	    case 8:
		pixFmt = GR_PIXFMT_AA_8_RGB_565;
		break;
	    case 4:
		pixFmt = GR_PIXFMT_AA_4_RGB_565;
		break;
	    case 2:
		pixFmt = GR_PIXFMT_AA_2_RGB_565;
		break;
	    default:
		pixFmt = GR_PIXFMT_RGB_565;
	}
    }

    return pixFmt;
}