1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "server_dispatch.h"
|
---|
8 | #include "server.h"
|
---|
9 | #include "cr_error.h"
|
---|
10 | #include "cr_mem.h"
|
---|
11 |
|
---|
12 | void SERVER_DISPATCH_APIENTRY crServerDispatchSelectBuffer( GLsizei size, GLuint *buffer )
|
---|
13 | {
|
---|
14 | (void) size;
|
---|
15 | (void) buffer;
|
---|
16 | crError( "Unsupported network glSelectBuffer call." );
|
---|
17 | }
|
---|
18 |
|
---|
19 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetChromiumParametervCR(GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values)
|
---|
20 | {
|
---|
21 | GLubyte local_storage[4096];
|
---|
22 | GLint bytes = 0;
|
---|
23 |
|
---|
24 | switch (type) {
|
---|
25 | case GL_BYTE:
|
---|
26 | case GL_UNSIGNED_BYTE:
|
---|
27 | bytes = count * sizeof(GLbyte);
|
---|
28 | break;
|
---|
29 | case GL_SHORT:
|
---|
30 | case GL_UNSIGNED_SHORT:
|
---|
31 | bytes = count * sizeof(GLshort);
|
---|
32 | break;
|
---|
33 | case GL_INT:
|
---|
34 | case GL_UNSIGNED_INT:
|
---|
35 | bytes = count * sizeof(GLint);
|
---|
36 | break;
|
---|
37 | case GL_FLOAT:
|
---|
38 | bytes = count * sizeof(GLfloat);
|
---|
39 | break;
|
---|
40 | case GL_DOUBLE:
|
---|
41 | bytes = count * sizeof(GLdouble);
|
---|
42 | break;
|
---|
43 | default:
|
---|
44 | crError("Bad type in crServerDispatchGetChromiumParametervCR");
|
---|
45 | }
|
---|
46 |
|
---|
47 | CRASSERT(bytes >= 0);
|
---|
48 | CRASSERT(bytes < 4096);
|
---|
49 |
|
---|
50 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR( target, index, type, count, local_storage );
|
---|
51 |
|
---|
52 | crServerReturnValue( local_storage, bytes );
|
---|
53 | }
|
---|
54 |
|
---|
55 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParametervCR(GLenum target, GLenum type, GLsizei count, const GLvoid *values)
|
---|
56 | {
|
---|
57 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
58 | static int gather_connect_count = 0;
|
---|
59 |
|
---|
60 | switch (target) {
|
---|
61 | case GL_SET_MAX_VIEWPORT_CR:
|
---|
62 | {
|
---|
63 | GLint *maxDims = (GLint *)values;
|
---|
64 | cr_server.limits.maxViewportDims[0] = maxDims[0];
|
---|
65 | cr_server.limits.maxViewportDims[1] = maxDims[1];
|
---|
66 | }
|
---|
67 | break;
|
---|
68 |
|
---|
69 | case GL_TILE_INFO_CR:
|
---|
70 | /* message from tilesort SPU to set new tile bounds */
|
---|
71 | {
|
---|
72 | GLint numTiles, muralWidth, muralHeight, server, tiles;
|
---|
73 | GLint *tileBounds;
|
---|
74 | CRASSERT(count >= 4);
|
---|
75 | CRASSERT((count - 4) % 4 == 0); /* must be multiple of four */
|
---|
76 | CRASSERT(type == GL_INT);
|
---|
77 | numTiles = (count - 4) / 4;
|
---|
78 | tileBounds = (GLint *) values;
|
---|
79 | server = tileBounds[0];
|
---|
80 | muralWidth = tileBounds[1];
|
---|
81 | muralHeight = tileBounds[2];
|
---|
82 | tiles = tileBounds[3];
|
---|
83 | CRASSERT(tiles == numTiles);
|
---|
84 | tileBounds += 4; /* skip over header values */
|
---|
85 | /*crServerNewMuralTiling(mural, muralWidth, muralHeight, numTiles, tileBounds);
|
---|
86 | mural->viewportValidated = GL_FALSE;*/
|
---|
87 | }
|
---|
88 | break;
|
---|
89 |
|
---|
90 | case GL_GATHER_DRAWPIXELS_CR:
|
---|
91 | if (cr_server.only_swap_once && cr_server.curClient != cr_server.clients[0])
|
---|
92 | break;
|
---|
93 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
94 | break;
|
---|
95 |
|
---|
96 | case GL_GATHER_CONNECT_CR:
|
---|
97 | /*
|
---|
98 | * We want the last connect to go through,
|
---|
99 | * otherwise we might deadlock in CheckWindowSize()
|
---|
100 | * in the readback spu
|
---|
101 | */
|
---|
102 | gather_connect_count++;
|
---|
103 | if (cr_server.only_swap_once && (gather_connect_count != cr_server.numClients))
|
---|
104 | {
|
---|
105 | break;
|
---|
106 | }
|
---|
107 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
108 | gather_connect_count = 0;
|
---|
109 | break;
|
---|
110 |
|
---|
111 | case GL_SERVER_VIEW_MATRIX_CR:
|
---|
112 | /* Set this server's view matrix which will get premultiplied onto the
|
---|
113 | * modelview matrix. For non-planar tilesort and stereo.
|
---|
114 | */
|
---|
115 | CRASSERT(count == 18);
|
---|
116 | CRASSERT(type == GL_FLOAT);
|
---|
117 | /* values[0] is the server index. Ignored here but used in tilesort SPU */
|
---|
118 | /* values[1] is the left/right eye index (0 or 1) */
|
---|
119 | {
|
---|
120 | const GLfloat *v = (const GLfloat *) values;
|
---|
121 | const int eye = v[1] == 0.0 ? 0 : 1;
|
---|
122 | crMatrixInitFromFloats(&cr_server.viewMatrix[eye], v + 2);
|
---|
123 |
|
---|
124 | crDebug("Got GL_SERVER_VIEW_MATRIX_CR:\n"
|
---|
125 | " %f %f %f %f\n"
|
---|
126 | " %f %f %f %f\n"
|
---|
127 | " %f %f %f %f\n"
|
---|
128 | " %f %f %f %f",
|
---|
129 | cr_server.viewMatrix[eye].m00,
|
---|
130 | cr_server.viewMatrix[eye].m10,
|
---|
131 | cr_server.viewMatrix[eye].m20,
|
---|
132 | cr_server.viewMatrix[eye].m30,
|
---|
133 | cr_server.viewMatrix[eye].m01,
|
---|
134 | cr_server.viewMatrix[eye].m11,
|
---|
135 | cr_server.viewMatrix[eye].m21,
|
---|
136 | cr_server.viewMatrix[eye].m31,
|
---|
137 | cr_server.viewMatrix[eye].m02,
|
---|
138 | cr_server.viewMatrix[eye].m12,
|
---|
139 | cr_server.viewMatrix[eye].m22,
|
---|
140 | cr_server.viewMatrix[eye].m32,
|
---|
141 | cr_server.viewMatrix[eye].m03,
|
---|
142 | cr_server.viewMatrix[eye].m13,
|
---|
143 | cr_server.viewMatrix[eye].m23,
|
---|
144 | cr_server.viewMatrix[eye].m33);
|
---|
145 | }
|
---|
146 | cr_server.viewOverride = GL_TRUE;
|
---|
147 | break;
|
---|
148 |
|
---|
149 | case GL_SERVER_PROJECTION_MATRIX_CR:
|
---|
150 | /* Set this server's projection matrix which will get replace the user's
|
---|
151 | * projection matrix. For non-planar tilesort and stereo.
|
---|
152 | */
|
---|
153 | CRASSERT(count == 18);
|
---|
154 | CRASSERT(type == GL_FLOAT);
|
---|
155 | /* values[0] is the server index. Ignored here but used in tilesort SPU */
|
---|
156 | /* values[1] is the left/right eye index (0 or 1) */
|
---|
157 | {
|
---|
158 | const GLfloat *v = (const GLfloat *) values;
|
---|
159 | const int eye = v[1] == 0.0 ? 0 : 1;
|
---|
160 | crMatrixInitFromFloats(&cr_server.projectionMatrix[eye], v + 2);
|
---|
161 |
|
---|
162 | crDebug("Got GL_SERVER_PROJECTION_MATRIX_CR:\n"
|
---|
163 | " %f %f %f %f\n"
|
---|
164 | " %f %f %f %f\n"
|
---|
165 | " %f %f %f %f\n"
|
---|
166 | " %f %f %f %f",
|
---|
167 | cr_server.projectionMatrix[eye].m00,
|
---|
168 | cr_server.projectionMatrix[eye].m10,
|
---|
169 | cr_server.projectionMatrix[eye].m20,
|
---|
170 | cr_server.projectionMatrix[eye].m30,
|
---|
171 | cr_server.projectionMatrix[eye].m01,
|
---|
172 | cr_server.projectionMatrix[eye].m11,
|
---|
173 | cr_server.projectionMatrix[eye].m21,
|
---|
174 | cr_server.projectionMatrix[eye].m31,
|
---|
175 | cr_server.projectionMatrix[eye].m02,
|
---|
176 | cr_server.projectionMatrix[eye].m12,
|
---|
177 | cr_server.projectionMatrix[eye].m22,
|
---|
178 | cr_server.projectionMatrix[eye].m32,
|
---|
179 | cr_server.projectionMatrix[eye].m03,
|
---|
180 | cr_server.projectionMatrix[eye].m13,
|
---|
181 | cr_server.projectionMatrix[eye].m23,
|
---|
182 | cr_server.projectionMatrix[eye].m33);
|
---|
183 |
|
---|
184 | if (cr_server.projectionMatrix[eye].m33 == 0.0f) {
|
---|
185 | float x = cr_server.projectionMatrix[eye].m00;
|
---|
186 | float y = cr_server.projectionMatrix[eye].m11;
|
---|
187 | float a = cr_server.projectionMatrix[eye].m20;
|
---|
188 | float b = cr_server.projectionMatrix[eye].m21;
|
---|
189 | float c = cr_server.projectionMatrix[eye].m22;
|
---|
190 | float d = cr_server.projectionMatrix[eye].m32;
|
---|
191 | float znear = -d / (1.0f - c);
|
---|
192 | float zfar = (c - 1.0f) * znear / (c + 1.0f);
|
---|
193 | float left = znear * (a - 1.0f) / x;
|
---|
194 | float right = 2.0f * znear / x + left;
|
---|
195 | float bottom = znear * (b - 1.0f) / y;
|
---|
196 | float top = 2.0f * znear / y + bottom;
|
---|
197 | crDebug("Frustum: left, right, bottom, top, near, far: %f, %f, %f, %f, %f, %f", left, right, bottom, top, znear, zfar);
|
---|
198 | }
|
---|
199 | else {
|
---|
200 | /* Todo: Add debug output for orthographic projection*/
|
---|
201 | }
|
---|
202 |
|
---|
203 | }
|
---|
204 | cr_server.projectionOverride = GL_TRUE;
|
---|
205 | break;
|
---|
206 |
|
---|
207 | default:
|
---|
208 | /* Pass the parameter info to the head SPU */
|
---|
209 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
210 | break;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameteriCR(GLenum target, GLint value)
|
---|
216 | {
|
---|
217 | switch (target) {
|
---|
218 | case GL_SHARED_DISPLAY_LISTS_CR:
|
---|
219 | cr_server.sharedDisplayLists = value;
|
---|
220 | break;
|
---|
221 | case GL_SHARED_TEXTURE_OBJECTS_CR:
|
---|
222 | cr_server.sharedTextureObjects = value;
|
---|
223 | break;
|
---|
224 | case GL_SHARED_PROGRAMS_CR:
|
---|
225 | cr_server.sharedPrograms = value;
|
---|
226 | break;
|
---|
227 | case GL_SERVER_CURRENT_EYE_CR:
|
---|
228 | cr_server.currentEye = value ? 1 : 0;
|
---|
229 | break;
|
---|
230 | default:
|
---|
231 | /* Pass the parameter info to the head SPU */
|
---|
232 | cr_server.head_spu->dispatch_table.ChromiumParameteriCR( target, value );
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameterfCR(GLenum target, GLfloat value)
|
---|
238 | {
|
---|
239 | switch (target) {
|
---|
240 | case GL_SHARED_DISPLAY_LISTS_CR:
|
---|
241 | cr_server.sharedDisplayLists = (int) value;
|
---|
242 | break;
|
---|
243 | case GL_SHARED_TEXTURE_OBJECTS_CR:
|
---|
244 | cr_server.sharedTextureObjects = (int) value;
|
---|
245 | break;
|
---|
246 | case GL_SHARED_PROGRAMS_CR:
|
---|
247 | cr_server.sharedPrograms = (int) value;
|
---|
248 | break;
|
---|
249 | default:
|
---|
250 | /* Pass the parameter info to the head SPU */
|
---|
251 | cr_server.head_spu->dispatch_table.ChromiumParameterfCR( target, value );
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | void crServerCreateInfoDeleteCB(void *data)
|
---|
256 | {
|
---|
257 | CRCreateInfo_t *pCreateInfo = (CRCreateInfo_t *) data;
|
---|
258 | if (pCreateInfo->pszDpyName)
|
---|
259 | crFree(pCreateInfo->pszDpyName);
|
---|
260 | }
|
---|
261 |
|
---|
262 | GLint crServerGenerateID(GLint *pCounter)
|
---|
263 | {
|
---|
264 | return (*pCounter)++;
|
---|
265 | }
|
---|
266 |
|
---|