VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_lists.c@ 65457

最後變更 在這個檔案從65457是 56946,由 vboxsync 提交於 9 年 前

Host 3D: Display Lists: fix list IDs translation on crServer layer; glCallLists() passed simple local tests.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 7.9 KB
 
1/* Copyright (c) 2001-2003, Stanford University
2 All rights reserved.
3
4 See the file LICENSE.txt for information on redistributing this software. */
5
6#include "server_dispatch.h"
7#include "server.h"
8#include "cr_mem.h"
9
10
11/*
12 * Notes on ID translation:
13 *
14 * If a server has multiple clients (in the case of parallel applications)
15 * and N of the clients all create a display list with ID K, does K name
16 * one display list or N different display lists?
17 *
18 * By default, there is one display list named K. If the clients put
19 * identical commands into list K, then this is fine. But if the clients
20 * each put something different into list K when they created it, then this
21 * is a serious problem.
22 *
23 * By zeroing the 'shared_display_lists' configuration option, we can tell
24 * the server to make list K be unique for all N clients. We do this by
25 * translating K into a new, unique ID dependent on which client we're
26 * talking to (curClient->number).
27 *
28 * Same story for texture objects, vertex programs, etc.
29 *
30 * The application can also dynamically switch between shared and private
31 * display lists with:
32 * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_TRUE)
33 * and
34 * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_FALSE)
35 *
36 */
37
38
39
40static GLuint TranslateListID( GLuint id )
41{
42#ifndef VBOX_WITH_CR_DISPLAY_LISTS
43 if (!cr_server.sharedDisplayLists) {
44 int client = cr_server.curClient->number;
45 return id + client * 100000;
46 }
47#endif
48 return id;
49}
50
51
52GLuint SERVER_DISPATCH_APIENTRY crServerDispatchGenLists( GLsizei range )
53{
54 GLuint retval;
55 retval = cr_server.head_spu->dispatch_table.GenLists( range );
56 crServerReturnValue( &retval, sizeof(retval) );
57 return retval; /* WILL PROBABLY BE IGNORED */
58}
59
60
61void SERVER_DISPATCH_APIENTRY
62crServerDispatchNewList( GLuint list, GLenum mode )
63{
64 if (mode == GL_COMPILE_AND_EXECUTE)
65 crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
66
67 list = TranslateListID( list );
68 crStateNewList( list, mode );
69 cr_server.head_spu->dispatch_table.NewList( list, mode );
70}
71
72static void crServerQueryHWState()
73{
74 if (!cr_server.bUseMultipleContexts)
75 {
76 GLuint fbFbo, bbFbo;
77 CRClient *client = cr_server.curClient;
78 CRMuralInfo *mural = client ? client->currentMural : NULL;
79 if (mural && mural->fRedirected)
80 {
81 fbFbo = mural->aidFBOs[CR_SERVER_FBO_FB_IDX(mural)];
82 bbFbo = mural->aidFBOs[CR_SERVER_FBO_BB_IDX(mural)];
83 }
84 else
85 {
86 fbFbo = bbFbo = 0;
87 }
88 crStateQueryHWState(fbFbo, bbFbo);
89 }
90}
91
92void SERVER_DISPATCH_APIENTRY crServerDispatchEndList(void)
93{
94 CRContext *g = crStateGetCurrent();
95 CRListsState *l = &(g->lists);
96
97 cr_server.head_spu->dispatch_table.EndList();
98 crStateEndList();
99
100#ifndef IN_GUEST
101 if (l->mode==GL_COMPILE)
102 {
103 crServerQueryHWState();
104 }
105#endif
106}
107
108void SERVER_DISPATCH_APIENTRY
109crServerDispatchCallList( GLuint list )
110{
111 list = TranslateListID( list );
112
113 if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
114 /* we're not compiling, so execute the list now */
115 /* Issue the list as-is */
116 cr_server.head_spu->dispatch_table.CallList( list );
117 crServerQueryHWState();
118 }
119 else {
120 /* we're compiling glCallList into another list - just pass it through */
121 cr_server.head_spu->dispatch_table.CallList( list );
122 }
123}
124
125
126#ifndef VBOX_WITH_CR_DISPLAY_LISTS
127/**
128 * Translate an array of display list IDs from various datatypes to GLuint
129 * IDs while adding the per-client offset.
130 */
131static void
132TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
133{
134 int offset = cr_server.curClient->number * 100000;
135 GLsizei i;
136 switch (type) {
137 case GL_UNSIGNED_BYTE:
138 {
139 const GLubyte *src = (const GLubyte *) lists;
140 for (i = 0; i < n; i++) {
141 newLists[i] = src[i] + offset;
142 }
143 }
144 break;
145 case GL_BYTE:
146 {
147 const GLbyte *src = (const GLbyte *) lists;
148 for (i = 0; i < n; i++) {
149 newLists[i] = src[i] + offset;
150 }
151 }
152 break;
153 case GL_UNSIGNED_SHORT:
154 {
155 const GLushort *src = (const GLushort *) lists;
156 for (i = 0; i < n; i++) {
157 newLists[i] = src[i] + offset;
158 }
159 }
160 break;
161 case GL_SHORT:
162 {
163 const GLshort *src = (const GLshort *) lists;
164 for (i = 0; i < n; i++) {
165 newLists[i] = src[i] + offset;
166 }
167 }
168 break;
169 case GL_UNSIGNED_INT:
170 {
171 const GLuint *src = (const GLuint *) lists;
172 for (i = 0; i < n; i++) {
173 newLists[i] = src[i] + offset;
174 }
175 }
176 break;
177 case GL_INT:
178 {
179 const GLint *src = (const GLint *) lists;
180 for (i = 0; i < n; i++) {
181 newLists[i] = src[i] + offset;
182 }
183 }
184 break;
185 case GL_FLOAT:
186 {
187 const GLfloat *src = (const GLfloat *) lists;
188 for (i = 0; i < n; i++) {
189 newLists[i] = (GLuint) src[i] + offset;
190 }
191 }
192 break;
193 case GL_2_BYTES:
194 {
195 const GLubyte *src = (const GLubyte *) lists;
196 for (i = 0; i < n; i++) {
197 newLists[i] = (src[i*2+0] * 256 +
198 src[i*2+1]) + offset;
199 }
200 }
201 break;
202 case GL_3_BYTES:
203 {
204 const GLubyte *src = (const GLubyte *) lists;
205 for (i = 0; i < n; i++) {
206 newLists[i] = (src[i*3+0] * 256 * 256 +
207 src[i*3+1] * 256 +
208 src[i*3+2]) + offset;
209 }
210 }
211 break;
212 case GL_4_BYTES:
213 {
214 const GLubyte *src = (const GLubyte *) lists;
215 for (i = 0; i < n; i++) {
216 newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
217 src[i*4+1] * 256 * 256 +
218 src[i*4+2] * 256 +
219 src[i*4+3]) + offset;
220 }
221 }
222 break;
223 default:
224 crWarning("CRServer: invalid display list datatype 0x%x", type);
225 }
226}
227#endif
228
229void SERVER_DISPATCH_APIENTRY
230crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
231{
232#ifndef VBOX_WITH_CR_DISPLAY_LISTS
233 if (!cr_server.sharedDisplayLists) {
234 /* need to translate IDs */
235 GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
236 if (newLists) {
237 TranslateListIDs(n, type, lists, newLists);
238 }
239 lists = newLists;
240 type = GL_UNSIGNED_INT;
241 }
242#endif
243
244 if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
245 /* we're not compiling, so execute the list now */
246 /* Issue the list as-is */
247 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
248 crServerQueryHWState();
249 }
250 else {
251 /* we're compiling glCallList into another list - just pass it through */
252 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
253 }
254
255#ifndef VBOX_WITH_CR_DISPLAY_LISTS
256 if (!cr_server.sharedDisplayLists) {
257 crFree((void *) lists); /* malloc'd above */
258 }
259#endif
260}
261
262
263GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
264{
265 GLboolean retval;
266 list = TranslateListID( list );
267 retval = cr_server.head_spu->dispatch_table.IsList( list );
268 crServerReturnValue( &retval, sizeof(retval) );
269 return retval;
270}
271
272
273void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
274{
275 list = TranslateListID( list );
276 crStateDeleteLists( list, range );
277 cr_server.head_spu->dispatch_table.DeleteLists( list, range );
278}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette