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.virtualbox.org. 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 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
82 | #else /* __LP64__ */
|
---|
83 | NativeNSViewRef pParentWin = (NativeNSViewRef)(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 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
98 | #else /* __LP64__ */
|
---|
99 | NativeNSViewRef pParentWin = (NativeNSViewRef)(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 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
117 | #else /* __LP64__ */
|
---|
118 | NativeNSViewRef pParentWin = (NativeNSViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
119 | #endif /* __LP64__ */
|
---|
120 |
|
---|
121 | /*pParentWin is unused in the call, overwise it might hold incorrect value if for ex. last reparent call was for
|
---|
122 | a different screen*/
|
---|
123 | cocoaViewSetPosition(pWinInfo->window, pParentWin, x, y);
|
---|
124 | }
|
---|
125 |
|
---|
126 | void renderspu_SystemWindowSize(WindowInfo *pWinInfo, GLint w, GLint h)
|
---|
127 | {
|
---|
128 | CRASSERT(pWinInfo);
|
---|
129 |
|
---|
130 | cocoaViewSetSize(pWinInfo->window, w, h);
|
---|
131 | }
|
---|
132 |
|
---|
133 | void renderspu_SystemGetWindowGeometry(WindowInfo *pWinInfo, GLint *pX, GLint *pY, GLint *pW, GLint *pH)
|
---|
134 | {
|
---|
135 | CRASSERT(pWinInfo);
|
---|
136 |
|
---|
137 | cocoaViewGetGeometry(pWinInfo->window, pX, pY, pW, pH);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void renderspu_SystemGetMaxWindowSize(WindowInfo *pWinInfo, GLint *pW, GLint *pH)
|
---|
141 | {
|
---|
142 | CRASSERT(pWinInfo);
|
---|
143 |
|
---|
144 | *pW = 10000;
|
---|
145 | *pH = 10000;
|
---|
146 | }
|
---|
147 |
|
---|
148 | void renderspu_SystemShowWindow(WindowInfo *pWinInfo, GLboolean fShowIt)
|
---|
149 | {
|
---|
150 | CRASSERT(pWinInfo);
|
---|
151 |
|
---|
152 | cocoaViewShow(pWinInfo->window, fShowIt);
|
---|
153 | }
|
---|
154 |
|
---|
155 | void renderspu_SystemMakeCurrent(WindowInfo *pWinInfo, GLint nativeWindow, ContextInfo *pCtxInfo)
|
---|
156 | {
|
---|
157 | CRASSERT(pWinInfo);
|
---|
158 | CRASSERT(pCtxInfo);
|
---|
159 |
|
---|
160 | /* if(pWinInfo->visual != pCtxInfo->visual)*/
|
---|
161 | /* printf ("visual mismatch .....................\n");*/
|
---|
162 |
|
---|
163 | cocoaViewMakeCurrentContext(pWinInfo->window, pCtxInfo->context);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void renderspu_SystemSwapBuffers(WindowInfo *pWinInfo, GLint flags)
|
---|
167 | {
|
---|
168 | CRASSERT(pWinInfo);
|
---|
169 |
|
---|
170 | cocoaViewDisplay(pWinInfo->window);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void renderspu_SystemWindowVisibleRegion(WindowInfo *pWinInfo, GLint cRects, GLint* paRects)
|
---|
174 | {
|
---|
175 | CRASSERT(pWinInfo);
|
---|
176 |
|
---|
177 | cocoaViewSetVisibleRegion(pWinInfo->window, cRects, paRects);
|
---|
178 | }
|
---|
179 |
|
---|
180 | void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *paRects)
|
---|
181 | {
|
---|
182 | }
|
---|
183 |
|
---|
184 | void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *pWinInfo)
|
---|
185 | {
|
---|
186 | }
|
---|
187 |
|
---|
188 | void renderspu_SystemFlush()
|
---|
189 | {
|
---|
190 | cocoaFlush();
|
---|
191 | }
|
---|
192 |
|
---|
193 | void renderspu_SystemFinish()
|
---|
194 | {
|
---|
195 | cocoaFinish();
|
---|
196 | }
|
---|
197 |
|
---|
198 | void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer)
|
---|
199 | {
|
---|
200 | cocoaBindFramebufferEXT(target, framebuffer);
|
---|
201 | }
|
---|
202 |
|
---|