VirtualBox

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

最後變更 在這個檔案從34382是 33540,由 vboxsync 提交於 14 年 前

*: spelling fixes, thanks Timeless!

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 11.0 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 if (!cr_server.sharedDisplayLists) {
43 int client = cr_server.curClient->number;
44 return id + client * 100000;
45 }
46 return id;
47}
48
49/* XXXX Note: shared/separate Program ID numbers aren't totally implemented! */
50GLuint crServerTranslateProgramID( GLuint id )
51{
52 if (!cr_server.sharedPrograms && id) {
53 int client = cr_server.curClient->number;
54 return id + client * 100000;
55 }
56 return id;
57}
58
59
60void SERVER_DISPATCH_APIENTRY
61crServerDispatchNewList( GLuint list, GLenum mode )
62{
63 if (mode == GL_COMPILE_AND_EXECUTE)
64 crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
65
66 list = TranslateListID( list );
67 crStateNewList( list, mode );
68 cr_server.head_spu->dispatch_table.NewList( list, mode );
69}
70
71
72void SERVER_DISPATCH_APIENTRY
73crServerDispatchCallList( GLuint list )
74{
75 list = TranslateListID( list );
76
77 if (cr_server.curClient->currentCtx->lists.mode == 0) {
78 /* we're not compiling, so execute the list now */
79 /* Issue the list as-is */
80 cr_server.head_spu->dispatch_table.CallList( list );
81 }
82 else {
83 /* we're compiling glCallList into another list - just pass it through */
84 cr_server.head_spu->dispatch_table.CallList( list );
85 }
86}
87
88
89/**
90 * Translate an array of display list IDs from various datatypes to GLuint
91 * IDs while adding the per-client offset.
92 */
93static void
94TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
95{
96 int offset = cr_server.curClient->number * 100000;
97 GLsizei i;
98 switch (type) {
99 case GL_UNSIGNED_BYTE:
100 {
101 const GLubyte *src = (const GLubyte *) lists;
102 for (i = 0; i < n; i++) {
103 newLists[i] = src[i] + offset;
104 }
105 }
106 break;
107 case GL_BYTE:
108 {
109 const GLbyte *src = (const GLbyte *) lists;
110 for (i = 0; i < n; i++) {
111 newLists[i] = src[i] + offset;
112 }
113 }
114 break;
115 case GL_UNSIGNED_SHORT:
116 {
117 const GLushort *src = (const GLushort *) lists;
118 for (i = 0; i < n; i++) {
119 newLists[i] = src[i] + offset;
120 }
121 }
122 break;
123 case GL_SHORT:
124 {
125 const GLshort *src = (const GLshort *) lists;
126 for (i = 0; i < n; i++) {
127 newLists[i] = src[i] + offset;
128 }
129 }
130 break;
131 case GL_UNSIGNED_INT:
132 {
133 const GLuint *src = (const GLuint *) lists;
134 for (i = 0; i < n; i++) {
135 newLists[i] = src[i] + offset;
136 }
137 }
138 break;
139 case GL_INT:
140 {
141 const GLint *src = (const GLint *) lists;
142 for (i = 0; i < n; i++) {
143 newLists[i] = src[i] + offset;
144 }
145 }
146 break;
147 case GL_FLOAT:
148 {
149 const GLfloat *src = (const GLfloat *) lists;
150 for (i = 0; i < n; i++) {
151 newLists[i] = (GLuint) src[i] + offset;
152 }
153 }
154 break;
155 case GL_2_BYTES:
156 {
157 const GLubyte *src = (const GLubyte *) lists;
158 for (i = 0; i < n; i++) {
159 newLists[i] = (src[i*2+0] * 256 +
160 src[i*2+1]) + offset;
161 }
162 }
163 break;
164 case GL_3_BYTES:
165 {
166 const GLubyte *src = (const GLubyte *) lists;
167 for (i = 0; i < n; i++) {
168 newLists[i] = (src[i*3+0] * 256 * 256 +
169 src[i*3+1] * 256 +
170 src[i*3+2]) + offset;
171 }
172 }
173 break;
174 case GL_4_BYTES:
175 {
176 const GLubyte *src = (const GLubyte *) lists;
177 for (i = 0; i < n; i++) {
178 newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
179 src[i*4+1] * 256 * 256 +
180 src[i*4+2] * 256 +
181 src[i*4+3]) + offset;
182 }
183 }
184 break;
185 default:
186 crWarning("CRServer: invalid display list datatype 0x%x", type);
187 }
188}
189
190
191void SERVER_DISPATCH_APIENTRY
192crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
193{
194 if (!cr_server.sharedDisplayLists) {
195 /* need to translate IDs */
196 GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
197 if (newLists) {
198 TranslateListIDs(n, type, lists, newLists);
199 }
200 lists = newLists;
201 type = GL_UNSIGNED_INT;
202 }
203
204 if (cr_server.curClient->currentCtx->lists.mode == 0) {
205 /* we're not compiling, so execute the list now */
206 /* Issue the list as-is */
207 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
208 }
209 else {
210 /* we're compiling glCallList into another list - just pass it through */
211 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
212 }
213
214 if (!cr_server.sharedDisplayLists) {
215 crFree((void *) lists); /* malloc'd above */
216 }
217}
218
219
220GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
221{
222 GLboolean retval;
223 list = TranslateListID( list );
224 retval = cr_server.head_spu->dispatch_table.IsList( list );
225 crServerReturnValue( &retval, sizeof(retval) );
226 return retval;
227}
228
229
230void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
231{
232 list = TranslateListID( list );
233 crStateDeleteLists( list, range );
234 cr_server.head_spu->dispatch_table.DeleteLists( list, range );
235}
236
237
238void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
239{
240 crStateBindTexture( target, texture );
241 cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(texture));
242}
243
244void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
245{
246 GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
247 GLint i;
248
249 if (!newTextures)
250 {
251 crError("crServerDispatchDeleteTextures: out of memory");
252 return;
253 }
254
255 for (i = 0; i < n; i++)
256 {
257 newTextures[i] = crStateGetTextureHWID(textures[i]);
258 }
259
260 crStateDeleteTextures(n, textures);
261 cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
262 crFree(newTextures);
263}
264
265void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
266{
267 GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
268 GLint i;
269
270 if (!newTextures)
271 {
272 crError("crServerDispatchDeleteTextures: out of memory");
273 return;
274 }
275
276 for (i = 0; i < n; i++)
277 {
278 newTextures[i] = crStateGetTextureHWID(textures[i]);
279 }
280
281 crStatePrioritizeTextures(n, textures, priorities);
282 cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
283 crFree(newTextures);
284}
285
286void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
287{
288 GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
289 GLint i;
290 if (!pLocalProgs) {
291 crError("crServerDispatchDeleteProgramsARB: out of memory");
292 return;
293 }
294 for (i = 0; i < n; i++) {
295 pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
296 }
297 crStateDeleteProgramsARB(n, pLocalProgs);
298 cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
299 crFree(pLocalProgs);
300}
301
302/*@todo will fail for textures loaded from snapshot */
303GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
304{
305 GLboolean retval;
306 retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(texture));
307 crServerReturnValue( &retval, sizeof(retval) );
308 return retval; /* WILL PROBABLY BE IGNORED */
309}
310
311/*@todo will fail for progs loaded from snapshot */
312GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
313{
314 GLboolean retval;
315 program = crServerTranslateProgramID(program);
316 retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
317 crServerReturnValue( &retval, sizeof(retval) );
318 return retval; /* WILL PROBABLY BE IGNORED */
319}
320
321GLboolean SERVER_DISPATCH_APIENTRY
322crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
323 GLboolean *residences)
324{
325 GLboolean retval;
326 GLsizei i;
327 GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
328 GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
329
330 (void) residences;
331
332 for (i = 0; i < n; i++)
333 {
334 textures2[i] = crStateGetTextureHWID(textures[i]);
335 }
336 retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
337
338 crFree(textures2);
339
340 crServerReturnValue(res, n * sizeof(GLboolean));
341
342 crFree(res);
343
344 return retval; /* WILL PROBABLY BE IGNORED */
345}
346
347
348GLboolean SERVER_DISPATCH_APIENTRY
349crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
350 GLboolean *residences)
351{
352 GLboolean retval;
353 GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
354 GLsizei i;
355
356 (void) residences;
357
358 if (!cr_server.sharedTextureObjects) {
359 GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
360 for (i = 0; i < n; i++)
361 programs2[i] = crServerTranslateProgramID(programs[i]);
362 retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
363 crFree(programs2);
364 }
365 else {
366 retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
367 }
368
369 crServerReturnValue(res, n * sizeof(GLboolean));
370 crFree(res);
371
372 return retval; /* WILL PROBABLY BE IGNORED */
373}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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