renderspu_cocoa.c revision 15b99330b4c33559d5dd2ca2ba6afa1213970204
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots/** @file
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots *
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * VirtualBox OpenGL Cocoa Window System implementation
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots */
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots/*
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * Copyright (C) 2009 Sun Microsystems, Inc.
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots *
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * This file is part of VirtualBox Open Source Edition (OSE), as
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * available from http://www.virtualbox.org. This file is free software;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * you can redistribute it and/or modify it under the terms of the GNU
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * General Public License (GPL) as published by the Free Software
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * Foundation, in version 2 as it comes in the "COPYING" file of the
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots *
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * Clara, CA 95054 USA or visit http://www.sun.com if you need
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots * additional information or have any questions.
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots */
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots#include <OpenGL/OpenGL.h>
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots#include "renderspu.h"
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd KlootsGLboolean renderspu_SystemInitVisual(VisualInfo *pVisInfo)
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots{
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots CRASSERT(pVisInfo);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots/* cocoaGLVisualCreate(&pCtxInfo->context);*/
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots return GL_TRUE;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots}
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd KlootsGLboolean renderspu_SystemCreateContext(VisualInfo *pVisInfo, ContextInfo *pCtxInfo, ContextInfo *pShharedCtxInfo)
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots{
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots CRASSERT(pVisInfo);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots CRASSERT(pCtxInfo);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots pCtxInfo->currentWindow = NULL;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots cocoaGLCtxCreate(&pCtxInfo->context, pVisInfo->visAttribs);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots return GL_TRUE;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots}
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Klootsvoid renderspu_SystemDestroyContext(ContextInfo *pCtxInfo)
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots{
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots if(!pCtxInfo)
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots return;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots if(pCtxInfo->context)
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots {
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaGLCtxDestroy(pCtxInfo->context);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots pCtxInfo->context = NULL;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots }
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspuFullscreen(WindowInfo *pWinInfo, GLboolean fFullscreen)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots /* Real fullscreen isn't supported by VirtualBox */
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd KlootsGLboolean renderspu_SystemVBoxCreateWindow(VisualInfo *pVisInfo, GLboolean fShowIt, WindowInfo *pWinInfo)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pVisInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots pWinInfo->visual = pVisInfo;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots pWinInfo->window = NULL;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots pWinInfo->nativeWindow = NULL;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots pWinInfo->currentCtx = NULL;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots#ifdef __LP64__
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots NativeViewRef pParentWin = (NativeViewRef)render_spu_parent_window_id;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots#else /* __LP64__ */
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots NativeViewRef pParentWin = (NativeViewRef)(uint32_t)render_spu_parent_window_id;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots#endif /* __LP64__ */
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots/* if (!pParentWin)*/
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots/* return GL_FALSE;*/
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewCreate(&pWinInfo->window, pParentWin, pVisInfo->visAttribs);
de413b3e25c9cba63ab4b3003f5a4524d49f9f05Todd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots if (fShowIt)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots renderspu_SystemShowWindow(pWinInfo, fShowIt);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots return GL_TRUE;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Klootsvoid renderspu_SystemDestroyWindow(WindowInfo *pWinInfo)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewDestroy(pWinInfo->window);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemWindowPosition(WindowInfo *pWinInfo, GLint x, GLint y)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
de413b3e25c9cba63ab4b3003f5a4524d49f9f05Todd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots#ifdef __LP64__
de413b3e25c9cba63ab4b3003f5a4524d49f9f05Todd Kloots NativeViewRef pParentWin = (NativeViewRef)render_spu_parent_window_id;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots#else /* __LP64__ */
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots NativeViewRef pParentWin = (NativeViewRef)(uint32_t)render_spu_parent_window_id;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots#endif /* __LP64__ */
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots cocoaViewSetPosition(pWinInfo->window, pParentWin, x, y);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Klootsvoid renderspu_SystemWindowSize(WindowInfo *pWinInfo, GLint w, GLint h)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewSetSize(pWinInfo->window, w, h);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemGetWindowGeometry(WindowInfo *pWinInfo, GLint *pX, GLint *pY, GLint *pW, GLint *pH)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewGetGeometry(pWinInfo->window, pX, pY, pW, pH);
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemGetMaxWindowSize(WindowInfo *pWinInfo, GLint *pW, GLint *pH)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots *pW = 10000;
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots *pH = 10000;
9a2430d08e4d1b8b870cd3ba6c17ffc7881d16a6Todd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemShowWindow(WindowInfo *pWinInfo, GLboolean fShowIt)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewShow(pWinInfo->window, fShowIt);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemMakeCurrent(WindowInfo *pWinInfo, GLint nativeWindow, ContextInfo *pCtxInfo)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pCtxInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots/* if(pWinInfo->visual != pCtxInfo->visual)*/
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots/* printf ("visual mismatch .....................\n");*/
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewMakeCurrentContext(pWinInfo->window, pCtxInfo->context);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemSwapBuffers(WindowInfo *pWinInfo, GLint flags)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewDisplay(pWinInfo->window);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemWindowVisibleRegion(WindowInfo *pWinInfo, GLint cRects, GLint* paRects)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots CRASSERT(pWinInfo);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaViewSetVisibleRegion(pWinInfo->window, cRects, paRects);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *paRects)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemWindowApplyVisibleRegion(WindowInfo *pWinInfo)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemFlush()
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaFlush();
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemFinish()
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaFinish();
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Klootsvoid renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer)
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots{
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots cocoaBindFramebufferEXT(target, framebuffer);
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots}
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots
5f40f927dba3cf399373572f6ed6fe59a376376eTodd Kloots