OpenGLTestDarwin.cpp revision ccaa684759e6cdb707fe6f4b134fc77a7483a99b
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/* $Id$ */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** @file
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * VBox host opengl support test
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync */
c1d279fc0865b91a40b30eda02ed14f6533fe1a4vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * available from http://www.virtualbox.org. This file is free software;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * you can redistribute it and/or modify it under the terms of the GNU
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * General Public License (GPL) as published by the Free Software
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * additional information or have any questions.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#include <OpenGL/OpenGL.h>
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#include <ApplicationServices/ApplicationServices.h>
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#include <OpenGL/gl.h>
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#ifdef VBOX_WITH_COCOA_QT
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync# include <OpenGL/glu.h>
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync# include <iprt/log.h>
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#endif /* VBOX_WITH_COCOA_QT */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
7220367ea1944fa8a7694534401321ad86eb70c6vboxsyncbool is3DAccelerationSupported()
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync{
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGDirectDisplayID display = CGMainDisplayID ();
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask (display);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGLPixelFormatObj pixelFormat = NULL;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync GLint numPixelFormats = 0;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGLPixelFormatAttribute attribs[] = {
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync kCGLPFADisplayMask,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync (CGLPixelFormatAttribute)cglDisplayMask,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync kCGLPFAAccelerated,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync kCGLPFADoubleBuffer,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync kCGLPFAWindow,
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync (CGLPixelFormatAttribute)NULL
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync };
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync display = CGMainDisplayID();
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(display);
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats);
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync if (pixelFormat)
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync {
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGLContextObj cglContext = 0;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGLCreateContext(pixelFormat, NULL, &cglContext);
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync CGLDestroyPixelFormat(pixelFormat);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync if (cglContext)
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync {
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync GLboolean isSupported = GL_TRUE;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#ifdef VBOX_WITH_COCOA_QT
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /* On the Cocoa port we depend on the GL_EXT_framebuffer_object &
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * the GL_EXT_texture_rectangle extension. If they are not
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * available, disable 3D support. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync CGLSetCurrentContext(cglContext);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync const GLubyte* strExt;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync strExt = glGetString(GL_EXTENSIONS);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync if (isSupported)
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync {
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_texture_rectangle", strExt);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync if (!isSupported)
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync LogRel(("OpenGL Info: GL_EXT_texture_rectangle extension not supported\n"));
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync }
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync else
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync LogRel(("OpenGL Info: GL_EXT_framebuffer_object extension not supported\n"));
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#endif /* VBOX_WITH_COCOA_QT */
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync CGLDestroyContext(cglContext);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync return isSupported == GL_TRUE ? true : false;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync }
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync }
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync return false;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync}
1e29d016a09a61485fda74f7fca39e171ff5dda8vboxsync
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync