1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox OpenGL Cocoa Window System implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.215389.xyz. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <OpenGL/OpenGL.h>
|
---|
19 |
|
---|
20 | #include "renderspu.h"
|
---|
21 | #include <iprt/process.h>
|
---|
22 | #include <iprt/string.h>
|
---|
23 | #include <iprt/path.h>
|
---|
24 |
|
---|
25 | GLboolean renderspu_SystemInitVisual(VisualInfo *pVisInfo)
|
---|
26 | {
|
---|
27 | CRASSERT(pVisInfo);
|
---|
28 |
|
---|
29 | /* cocoaGLVisualCreate(&pCtxInfo->context);*/
|
---|
30 |
|
---|
31 | return GL_TRUE;
|
---|
32 | }
|
---|
33 |
|
---|
34 | GLboolean renderspu_SystemCreateContext(VisualInfo *pVisInfo, ContextInfo *pCtxInfo, ContextInfo *pShharedCtxInfo)
|
---|
35 | {
|
---|
36 | CRASSERT(pVisInfo);
|
---|
37 | CRASSERT(pCtxInfo);
|
---|
38 |
|
---|
39 | pCtxInfo->currentWindow = NULL;
|
---|
40 |
|
---|
41 | cocoaGLCtxCreate(&pCtxInfo->context, pVisInfo->visAttribs);
|
---|
42 |
|
---|
43 | return GL_TRUE;
|
---|
44 | }
|
---|
45 |
|
---|
46 | void renderspu_SystemDestroyContext(ContextInfo *pCtxInfo)
|
---|
47 | {
|
---|
48 | if(!pCtxInfo)
|
---|
49 | return;
|
---|
50 |
|
---|
51 | if(pCtxInfo->context)
|
---|
52 | {
|
---|
53 | cocoaGLCtxDestroy(pCtxInfo->context);
|
---|
54 | pCtxInfo->context = NULL;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | void renderspuFullscreen(WindowInfo *pWinInfo, GLboolean fFullscreen)
|
---|
59 | {
|
---|
60 | /* Real fullscreen isn't supported by VirtualBox */
|
---|
61 | }
|
---|
62 |
|
---|
63 | GLboolean renderspu_SystemVBoxCreateWindow(VisualInfo *pVisInfo, GLboolean fShowIt, WindowInfo *pWinInfo)
|
---|
64 | {
|
---|
65 | CRASSERT(pVisInfo);
|
---|
66 | CRASSERT(pWinInfo);
|
---|
67 |
|
---|
68 | /* VirtualBox is the only frontend which support 3D right now. */
|
---|
69 | char pszName[256];
|
---|
70 | if (RTProcGetExecutableName(pszName, sizeof(pszName)))
|
---|
71 | /* Check for VirtualBox and VirtualBoxVM */
|
---|
72 | if (RTStrNICmp(RTPathFilename(pszName), "VirtualBox", 10) != 0)
|
---|
73 | return GL_FALSE;
|
---|
74 |
|
---|
75 | pWinInfo->visual = pVisInfo;
|
---|
76 | pWinInfo->window = NULL;
|
---|
77 | pWinInfo->nativeWindow = NULL;
|
---|
78 | pWinInfo->currentCtx = NULL;
|
---|
79 |
|
---|
80 | #ifdef __LP64__
|
---|
81 | NativeViewRef pParentWin = (NativeViewRef)render_spu_parent_window_id;
|
---|
82 | #else /* __LP64__ */
|
---|
83 | NativeViewRef pParentWin = (NativeViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
84 | #endif /* __LP64__ */
|
---|
85 |
|
---|
86 | cocoaViewCreate(&pWinInfo->window, pParentWin, pVisInfo->visAttribs);
|
---|
87 |
|
---|
88 | if (fShowIt)
|
---|
89 | renderspu_SystemShowWindow(pWinInfo, fShowIt);
|
---|
90 |
|
---|
91 | return GL_TRUE;
|
---|
92 | }
|
---|
93 |
|
---|
94 | void renderspu_SystemReparentWindow(WindowInfo *pWinInfo)
|
---|
95 | {
|
---|
96 | #ifdef __LP64__
|
---|
97 | NativeViewRef pParentWin = (NativeViewRef)render_spu_parent_window_id;
|
---|
98 | #else /* __LP64__ */
|
---|
99 | NativeViewRef pParentWin = (NativeViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
100 | #endif /* __LP64__ */
|
---|
101 | cocoaViewReparent(pWinInfo->window, pParentWin);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void renderspu_SystemDestroyWindow(WindowInfo *pWinInfo)
|
---|
105 | {
|
---|
106 | CRASSERT(pWinInfo);
|
---|
107 |
|
---|
108 | cocoaViewDestroy(pWinInfo->window);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void renderspu_SystemWindowPosition(WindowInfo *pWinInfo, GLint x, GLint y)
|
---|
112 | {
|
---|
113 | CRASSERT(pWinInfo);
|
---|
114 |
|
---|
115 | #ifdef __LP64__
|
---|
116 | NativeViewRef pParentWin = (NativeViewRef)render_spu_parent_window_id;
|
---|
117 | #else /* __LP64__ */
|
---|
118 | NativeViewRef pParentWin = (NativeViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
119 | #endif /* __LP64__ */
|
---|
120 |
|
---|
121 | cocoaViewSetPosition(pWinInfo->window, pParentWin, x, y);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void renderspu_SystemWindowSize(WindowInfo *pWinInfo, GLint w, GLint h)
|
---|
125 | {
|
---|
126 | CRASSERT(pWinInfo);
|
---|
127 |
|
---|
128 | cocoaViewSetSize(pWinInfo->window, w, h);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void renderspu_SystemGetWindowGeometry(WindowInfo *pWinInfo, GLint *pX, GLint *pY, GLint *pW, GLint *pH)
|
---|
132 | {
|
---|
133 | CRASSERT(pWinInfo);
|
---|
134 |
|
---|
135 | cocoaViewGetGeometry(pWinInfo->window, pX, pY, pW, pH);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void renderspu_SystemGetMaxWindowSize(WindowInfo *pWinInfo, GLint *pW, GLint *pH)
|
---|
139 | {
|
---|
140 | CRASSERT(pWinInfo);
|
---|
141 |
|
---|
142 | *pW = 10000;
|
---|
143 | *pH = 10000;
|
---|
144 | }
|
---|
145 |
|
---|
146 | void renderspu_SystemShowWindow(WindowInfo *pWinInfo, GLboolean fShowIt)
|
---|
147 | {
|
---|
148 | CRASSERT(pWinInfo);
|
---|
149 |
|
---|
150 | cocoaViewShow(pWinInfo->window, fShowIt);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void renderspu_SystemMakeCurrent(WindowInfo *pWinInfo, GLint nativeWindow, ContextInfo *pCtxInfo)
|
---|
154 | {
|
---|
155 | CRASSERT(pWinInfo);
|
---|
156 | CRASSERT(pCtxInfo);
|
---|
157 |
|
---|
158 | /* if(pWinInfo->visual != pCtxInfo->visual)*/
|
---|
159 | /* printf ("visual mismatch .....................\n");*/
|
---|
160 |
|
---|
161 | cocoaViewMakeCurrentContext(pWinInfo->window, pCtxInfo->context);
|
---|
162 | }
|
---|
163 |
|
---|
164 | void renderspu_SystemSwapBuffers(WindowInfo *pWinInfo, GLint flags)
|
---|
165 | {
|
---|
166 | CRASSERT(pWinInfo);
|
---|
167 |
|
---|
168 | cocoaViewDisplay(pWinInfo->window);
|
---|
169 | }
|
---|
170 |
|
---|
171 | void renderspu_SystemWindowVisibleRegion(WindowInfo *pWinInfo, GLint cRects, GLint* paRects)
|
---|
172 | {
|
---|
173 | CRASSERT(pWinInfo);
|
---|
174 |
|
---|
175 | cocoaViewSetVisibleRegion(pWinInfo->window, cRects, paRects);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *paRects)
|
---|
179 | {
|
---|
180 | }
|
---|
181 |
|
---|
182 | void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *pWinInfo)
|
---|
183 | {
|
---|
184 | }
|
---|
185 |
|
---|
186 | void renderspu_SystemFlush()
|
---|
187 | {
|
---|
188 | cocoaFlush();
|
---|
189 | }
|
---|
190 |
|
---|
191 | void renderspu_SystemFinish()
|
---|
192 | {
|
---|
193 | cocoaFinish();
|
---|
194 | }
|
---|
195 |
|
---|
196 | void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer)
|
---|
197 | {
|
---|
198 | cocoaBindFramebufferEXT(target, framebuffer);
|
---|
199 | }
|
---|
200 |
|
---|