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 "cr_spu.h"
|
---|
8 | #include "chromium.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 | #include "cr_net.h"
|
---|
11 | #include "server_dispatch.h"
|
---|
12 | #include "server.h"
|
---|
13 |
|
---|
14 |
|
---|
15 | void SERVER_DISPATCH_APIENTRY crServerDispatchClear( GLenum mask )
|
---|
16 | {
|
---|
17 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
18 | const RunQueue *q = cr_server.run_queue;
|
---|
19 |
|
---|
20 | if (cr_server.only_swap_once)
|
---|
21 | {
|
---|
22 | /* NOTE: we only do the clear for the _last_ client in the list.
|
---|
23 | * This is because in multi-threaded apps the zeroeth client may
|
---|
24 | * be idle and never call glClear at all. See threadtest.c
|
---|
25 | * It's pretty likely that the last client will be active.
|
---|
26 | */
|
---|
27 | if ((mask & GL_COLOR_BUFFER_BIT) &&
|
---|
28 | (cr_server.curClient != cr_server.clients[cr_server.numClients - 1]))
|
---|
29 | return;
|
---|
30 | }
|
---|
31 |
|
---|
32 | if (mural->numExtents == 0)
|
---|
33 | {
|
---|
34 | cr_server.head_spu->dispatch_table.Clear( mask );
|
---|
35 | }
|
---|
36 | else
|
---|
37 | {
|
---|
38 | int scissor_on, i;
|
---|
39 |
|
---|
40 | if (!mural->viewportValidated) {
|
---|
41 | crServerComputeViewportBounds(&(cr_server.curClient->currentCtx->viewport), mural);
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | scissor_on = q->client->currentCtx->viewport.scissorTest;
|
---|
46 |
|
---|
47 | if (!scissor_on)
|
---|
48 | {
|
---|
49 | cr_server.head_spu->dispatch_table.Enable( GL_SCISSOR_TEST );
|
---|
50 | }
|
---|
51 |
|
---|
52 | for ( i = 0; i < mural->numExtents; i++ )
|
---|
53 | {
|
---|
54 | crServerSetOutputBounds( mural, i );
|
---|
55 | cr_server.head_spu->dispatch_table.Clear( mask );
|
---|
56 | }
|
---|
57 | if (!scissor_on)
|
---|
58 | {
|
---|
59 | cr_server.head_spu->dispatch_table.Disable( GL_SCISSOR_TEST );
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | static void __draw_poly(CRPoly *p)
|
---|
65 | {
|
---|
66 | int b;
|
---|
67 |
|
---|
68 | cr_server.head_spu->dispatch_table.Begin(GL_POLYGON);
|
---|
69 | for (b=0; b<p->npoints; b++)
|
---|
70 | cr_server.head_spu->dispatch_table.Vertex2dv(p->points+2*b);
|
---|
71 | cr_server.head_spu->dispatch_table.End();
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | void SERVER_DISPATCH_APIENTRY
|
---|
76 | crServerDispatchSwapBuffers( GLint window, GLint flags )
|
---|
77 | {
|
---|
78 | CRMuralInfo *mural;
|
---|
79 |
|
---|
80 | mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
81 | if (!mural) {
|
---|
82 | return;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | if (cr_server.only_swap_once)
|
---|
87 | {
|
---|
88 | /* NOTE: we only do the clear for the _last_ client in the list.
|
---|
89 | * This is because in multi-threaded apps the zeroeth client may
|
---|
90 | * be idle and never call glClear at all. See threadtest.c
|
---|
91 | * It's pretty likely that the last client will be active.
|
---|
92 | */
|
---|
93 | if (cr_server.curClient != cr_server.clients[cr_server.numClients - 1])
|
---|
94 | {
|
---|
95 | return;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (cr_server.overlapBlending)
|
---|
100 | {
|
---|
101 | int a;
|
---|
102 | CRPoly *p;
|
---|
103 | GLboolean lighting, fog, blend, cull, tex[3];
|
---|
104 | GLenum mm, blendSrc, blendDst;
|
---|
105 | GLcolorf col;
|
---|
106 | CRContext *ctx = crStateGetCurrent();
|
---|
107 | const CRmatrix *baseProj;
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * I've probably missed some state here, or it
|
---|
111 | * might be easier just to push/pop it....
|
---|
112 | */
|
---|
113 | lighting = ctx->lighting.lighting;
|
---|
114 | fog = ctx->fog.enable;
|
---|
115 | tex[0] = 0;
|
---|
116 | for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
|
---|
117 | {
|
---|
118 | if (!ctx->texture.unit[a].enabled1D) continue;
|
---|
119 |
|
---|
120 | tex[0] = 1;
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | tex[1] = 0;
|
---|
124 | for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
|
---|
125 | {
|
---|
126 | if (!ctx->texture.unit[a].enabled2D) continue;
|
---|
127 |
|
---|
128 | tex[1] = 1;
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | tex[2] = 0;
|
---|
132 | for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
|
---|
133 | {
|
---|
134 | if (!ctx->texture.unit[a].enabled3D) continue;
|
---|
135 |
|
---|
136 | tex[2] = 1;
|
---|
137 | break;
|
---|
138 | }
|
---|
139 |
|
---|
140 | cull = ctx->polygon.cullFace;
|
---|
141 | blend = ctx->buffer.blend;
|
---|
142 | blendSrc = ctx->buffer.blendSrcRGB;
|
---|
143 | blendDst = ctx->buffer.blendDstRGB;
|
---|
144 | mm = ctx->transform.matrixMode;
|
---|
145 | col.r = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][0];
|
---|
146 | col.g = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][1];
|
---|
147 | col.b = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][2];
|
---|
148 | col.a = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][3];
|
---|
149 |
|
---|
150 | baseProj = &(cr_server.curClient->currentMural->extents[0].baseProjection);
|
---|
151 |
|
---|
152 | switch(mm)
|
---|
153 | {
|
---|
154 | case GL_PROJECTION:
|
---|
155 | cr_server.head_spu->dispatch_table.PushMatrix();
|
---|
156 | cr_server.head_spu->dispatch_table.LoadMatrixf((GLfloat *) baseProj);
|
---|
157 | cr_server.head_spu->dispatch_table.MultMatrixf(cr_server.unnormalized_alignment_matrix);
|
---|
158 | cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
|
---|
159 | cr_server.head_spu->dispatch_table.PushMatrix();
|
---|
160 | cr_server.head_spu->dispatch_table.LoadIdentity();
|
---|
161 | break;
|
---|
162 |
|
---|
163 | default:
|
---|
164 | cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
|
---|
165 | /* fall through */
|
---|
166 |
|
---|
167 | case GL_MODELVIEW:
|
---|
168 | cr_server.head_spu->dispatch_table.PushMatrix();
|
---|
169 | cr_server.head_spu->dispatch_table.LoadIdentity();
|
---|
170 | cr_server.head_spu->dispatch_table.MatrixMode(GL_PROJECTION);
|
---|
171 | cr_server.head_spu->dispatch_table.PushMatrix();
|
---|
172 | cr_server.head_spu->dispatch_table.LoadMatrixf((GLfloat *) baseProj);
|
---|
173 | cr_server.head_spu->dispatch_table.MultMatrixf(cr_server.unnormalized_alignment_matrix);
|
---|
174 | break;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* fix state */
|
---|
178 | if (lighting)
|
---|
179 | cr_server.head_spu->dispatch_table.Disable(GL_LIGHTING);
|
---|
180 | if (fog)
|
---|
181 | cr_server.head_spu->dispatch_table.Disable(GL_FOG);
|
---|
182 | if (tex[0])
|
---|
183 | cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_1D);
|
---|
184 | if (tex[1])
|
---|
185 | cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_2D);
|
---|
186 | if (tex[2])
|
---|
187 | cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_3D);
|
---|
188 | if (cull)
|
---|
189 | cr_server.head_spu->dispatch_table.Disable(GL_CULL_FACE);
|
---|
190 |
|
---|
191 | /* Regular Blending */
|
---|
192 | if (cr_server.overlapBlending == 1)
|
---|
193 | {
|
---|
194 | if (!blend)
|
---|
195 | cr_server.head_spu->dispatch_table.Enable(GL_BLEND);
|
---|
196 | if ((blendSrc != GL_ZERO) && (blendDst != GL_SRC_ALPHA))
|
---|
197 | cr_server.head_spu->dispatch_table.BlendFunc(GL_ZERO, GL_SRC_ALPHA);
|
---|
198 |
|
---|
199 | /* draw the blends */
|
---|
200 | for (a=1; a<cr_server.num_overlap_levels; a++)
|
---|
201 | {
|
---|
202 | if (a-1 < cr_server.num_overlap_intens)
|
---|
203 | {
|
---|
204 | cr_server.head_spu->dispatch_table.Color4f(0, 0, 0,
|
---|
205 | cr_server.overlap_intens[a-1]);
|
---|
206 | }
|
---|
207 | else
|
---|
208 | {
|
---|
209 | cr_server.head_spu->dispatch_table.Color4f(0, 0, 0, 1);
|
---|
210 | }
|
---|
211 |
|
---|
212 | p = cr_server.overlap_geom[a];
|
---|
213 | while (p)
|
---|
214 | {
|
---|
215 | /* hopefully this isnt concave... */
|
---|
216 | __draw_poly(p);
|
---|
217 | p = p->next;
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 | if (!blend)
|
---|
222 | cr_server.head_spu->dispatch_table.Disable(GL_BLEND);
|
---|
223 | if ((blendSrc != GL_ZERO) && (blendDst != GL_SRC_ALPHA))
|
---|
224 | cr_server.head_spu->dispatch_table.BlendFunc(blendSrc, blendDst);
|
---|
225 | }
|
---|
226 | else
|
---|
227 | /* Knockout Blending */
|
---|
228 | {
|
---|
229 | cr_server.head_spu->dispatch_table.Color4f(0, 0, 0, 1);
|
---|
230 |
|
---|
231 | if (blend)
|
---|
232 | cr_server.head_spu->dispatch_table.Disable(GL_BLEND);
|
---|
233 | p = cr_server.overlap_knockout;
|
---|
234 | while (p)
|
---|
235 | {
|
---|
236 | __draw_poly(p);
|
---|
237 | p = p->next;
|
---|
238 | }
|
---|
239 | if (blend)
|
---|
240 | cr_server.head_spu->dispatch_table.Enable(GL_BLEND);
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | /* return things to normal */
|
---|
245 | switch (mm)
|
---|
246 | {
|
---|
247 | case GL_PROJECTION:
|
---|
248 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
249 | cr_server.head_spu->dispatch_table.MatrixMode(GL_PROJECTION);
|
---|
250 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
251 | break;
|
---|
252 | case GL_MODELVIEW:
|
---|
253 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
254 | cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
|
---|
255 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
256 | break;
|
---|
257 | default:
|
---|
258 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
259 | cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
|
---|
260 | cr_server.head_spu->dispatch_table.PopMatrix();
|
---|
261 | cr_server.head_spu->dispatch_table.MatrixMode(mm);
|
---|
262 | break;
|
---|
263 | }
|
---|
264 |
|
---|
265 | if (lighting)
|
---|
266 | cr_server.head_spu->dispatch_table.Enable(GL_LIGHTING);
|
---|
267 | if (fog)
|
---|
268 | cr_server.head_spu->dispatch_table.Enable(GL_FOG);
|
---|
269 | if (tex[0])
|
---|
270 | cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_1D);
|
---|
271 | if (tex[1])
|
---|
272 | cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_2D);
|
---|
273 | if (tex[2])
|
---|
274 | cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_3D);
|
---|
275 | if (cull)
|
---|
276 | cr_server.head_spu->dispatch_table.Enable(GL_CULL_FACE);
|
---|
277 |
|
---|
278 | cr_server.head_spu->dispatch_table.Color4f(col.r, col.g, col.b, col.a);
|
---|
279 | }
|
---|
280 |
|
---|
281 | /* Check if using a file network */
|
---|
282 | if (!cr_server.clients[0]->conn->actual_network && window == MAGIC_OFFSET)
|
---|
283 | window = 0;
|
---|
284 |
|
---|
285 | cr_server.head_spu->dispatch_table.SwapBuffers( mural->spuWindow, flags );
|
---|
286 | }
|
---|