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 "state.h"
|
---|
8 | #include "cr_error.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 |
|
---|
11 | void crStateDiffContext( CRContext *from, CRContext *to )
|
---|
12 | {
|
---|
13 | CRbitvalue *bitID = from->bitid;
|
---|
14 | CRStateBits *sb = GetCurrentBits();
|
---|
15 |
|
---|
16 | /*crDebug( "Diffing two contexts!" ); */
|
---|
17 |
|
---|
18 | if (CHECKDIRTY(sb->transform.dirty, bitID))
|
---|
19 | {
|
---|
20 | crStateTransformDiff( &(sb->transform), bitID, from, to );
|
---|
21 | }
|
---|
22 | if (CHECKDIRTY(sb->pixel.dirty, bitID))
|
---|
23 | {
|
---|
24 | crStatePixelDiff( &(sb->pixel), bitID, from, to );
|
---|
25 | }
|
---|
26 | if (CHECKDIRTY(sb->viewport.dirty, bitID))
|
---|
27 | {
|
---|
28 | crStateViewportDiff( &(sb->viewport), bitID, from, to );
|
---|
29 | }
|
---|
30 | if (CHECKDIRTY(sb->fog.dirty, bitID))
|
---|
31 | {
|
---|
32 | crStateFogDiff( &(sb->fog), bitID, from, to );
|
---|
33 | }
|
---|
34 | if (CHECKDIRTY(sb->texture.dirty, bitID))
|
---|
35 | {
|
---|
36 | crStateTextureDiff( &(sb->texture), bitID, from, to );
|
---|
37 | }
|
---|
38 | if (CHECKDIRTY(sb->lists.dirty, bitID))
|
---|
39 | {
|
---|
40 | crStateListsDiff( &(sb->lists), bitID, from, to );
|
---|
41 | }
|
---|
42 | if (CHECKDIRTY(sb->buffer.dirty, bitID))
|
---|
43 | {
|
---|
44 | crStateBufferDiff( &(sb->buffer), bitID, from, to );
|
---|
45 | }
|
---|
46 | #ifdef CR_ARB_vertex_buffer_object
|
---|
47 | if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
|
---|
48 | {
|
---|
49 | crStateBufferObjectDiff( &(sb->bufferobject), bitID, from, to );
|
---|
50 | }
|
---|
51 | #endif
|
---|
52 | if (CHECKDIRTY(sb->client.dirty, bitID))
|
---|
53 | {
|
---|
54 | crStateClientDiff(&(sb->client), bitID, from, to );
|
---|
55 | }
|
---|
56 | if (CHECKDIRTY(sb->hint.dirty, bitID))
|
---|
57 | {
|
---|
58 | crStateHintDiff( &(sb->hint), bitID, from, to );
|
---|
59 | }
|
---|
60 | if (CHECKDIRTY(sb->lighting.dirty, bitID))
|
---|
61 | {
|
---|
62 | crStateLightingDiff( &(sb->lighting), bitID, from, to );
|
---|
63 | }
|
---|
64 | if (CHECKDIRTY(sb->line.dirty, bitID))
|
---|
65 | {
|
---|
66 | crStateLineDiff( &(sb->line), bitID, from, to );
|
---|
67 | }
|
---|
68 | if (CHECKDIRTY(sb->occlusion.dirty, bitID))
|
---|
69 | {
|
---|
70 | crStateOcclusionDiff( &(sb->occlusion), bitID, from, to );
|
---|
71 | }
|
---|
72 | if (CHECKDIRTY(sb->point.dirty, bitID))
|
---|
73 | {
|
---|
74 | crStatePointDiff( &(sb->point), bitID, from, to );
|
---|
75 | }
|
---|
76 | if (CHECKDIRTY(sb->polygon.dirty, bitID))
|
---|
77 | {
|
---|
78 | crStatePolygonDiff( &(sb->polygon), bitID, from, to );
|
---|
79 | }
|
---|
80 | if (CHECKDIRTY(sb->program.dirty, bitID))
|
---|
81 | {
|
---|
82 | crStateProgramDiff( &(sb->program), bitID, from, to );
|
---|
83 | }
|
---|
84 | if (CHECKDIRTY(sb->stencil.dirty, bitID))
|
---|
85 | {
|
---|
86 | crStateStencilDiff( &(sb->stencil), bitID, from, to );
|
---|
87 | }
|
---|
88 | if (CHECKDIRTY(sb->eval.dirty, bitID))
|
---|
89 | {
|
---|
90 | crStateEvaluatorDiff( &(sb->eval), bitID, from, to );
|
---|
91 | }
|
---|
92 | #ifdef CR_ARB_imaging
|
---|
93 | if (CHECKDIRTY(sb->imaging.dirty, bitID))
|
---|
94 | {
|
---|
95 | crStateImagingDiff( &(sb->imaging), bitID, from, to );
|
---|
96 | }
|
---|
97 | #endif
|
---|
98 | #if 0
|
---|
99 | if (CHECKDIRTY(sb->selection.dirty, bitID))
|
---|
100 | {
|
---|
101 | crStateSelectionDiff( &(sb->selection), bitID, from, to );
|
---|
102 | }
|
---|
103 | #endif
|
---|
104 | #ifdef CR_NV_register_combiners
|
---|
105 | if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
|
---|
106 | {
|
---|
107 | crStateRegCombinerDiff( &(sb->regcombiner), bitID, from, to );
|
---|
108 | }
|
---|
109 | #endif
|
---|
110 | #ifdef CR_ARB_multisample
|
---|
111 | if (CHECKDIRTY(sb->multisample.dirty, bitID) &&
|
---|
112 | from->extensions.ARB_multisample)
|
---|
113 | {
|
---|
114 | crStateMultisampleDiff( &(sb->multisample), bitID, from, to );
|
---|
115 | }
|
---|
116 | #endif
|
---|
117 | if (CHECKDIRTY(sb->current.dirty, bitID))
|
---|
118 | {
|
---|
119 | crStateCurrentDiff( &(sb->current), bitID, from, to );
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | void crStateApplyFBImage(CRContext *to)
|
---|
124 | {
|
---|
125 | if (to->pImage)
|
---|
126 | {
|
---|
127 | CRViewportState *pVP = &to->viewport;
|
---|
128 | CRPixelPackState unpack = to->client.unpack;
|
---|
129 |
|
---|
130 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
---|
131 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
---|
132 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
133 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
134 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
|
---|
135 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
|
---|
136 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
|
---|
137 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
|
---|
138 |
|
---|
139 | diff_api.DrawBuffer(GL_FRONT);
|
---|
140 | diff_api.WindowPos2iARB(0, 0);
|
---|
141 | diff_api.DrawPixels(pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, to->pImage);
|
---|
142 |
|
---|
143 | diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
|
---|
144 | diff_api.DrawBuffer(to->framebufferobject.drawFB ?
|
---|
145 | to->framebufferobject.drawFB->drawbuffer[0] : to->buffer.drawBuffer);
|
---|
146 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
|
---|
147 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
|
---|
148 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
|
---|
149 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
|
---|
150 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
|
---|
151 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
|
---|
152 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
|
---|
153 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
|
---|
154 |
|
---|
155 | diff_api.Finish();
|
---|
156 |
|
---|
157 | crDebug("Applied %ix%i fb image", pVP->viewportW, pVP->viewportH);
|
---|
158 |
|
---|
159 | crFree(to->pImage);
|
---|
160 | to->pImage = NULL;
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | void crStateSwitchContext( CRContext *from, CRContext *to )
|
---|
165 | {
|
---|
166 | CRbitvalue *bitID = to->bitid;
|
---|
167 | CRStateBits *sb = GetCurrentBits();
|
---|
168 |
|
---|
169 | if (CHECKDIRTY(sb->attrib.dirty, bitID))
|
---|
170 | {
|
---|
171 | crStateAttribSwitch(&(sb->attrib), bitID, from, to );
|
---|
172 | }
|
---|
173 | if (CHECKDIRTY(sb->transform.dirty, bitID))
|
---|
174 | {
|
---|
175 | crStateTransformSwitch( &(sb->transform), bitID, from, to );
|
---|
176 | }
|
---|
177 | if (CHECKDIRTY(sb->pixel.dirty, bitID))
|
---|
178 | {
|
---|
179 | crStatePixelSwitch(&(sb->pixel), bitID, from, to );
|
---|
180 | }
|
---|
181 | if (CHECKDIRTY(sb->viewport.dirty, bitID))
|
---|
182 | {
|
---|
183 | crStateViewportSwitch(&(sb->viewport), bitID, from, to );
|
---|
184 | }
|
---|
185 | if (CHECKDIRTY(sb->fog.dirty, bitID))
|
---|
186 | {
|
---|
187 | crStateFogSwitch(&(sb->fog), bitID, from, to );
|
---|
188 | }
|
---|
189 | if (CHECKDIRTY(sb->texture.dirty, bitID))
|
---|
190 | {
|
---|
191 | crStateTextureSwitch( &(sb->texture), bitID, from, to );
|
---|
192 | }
|
---|
193 | if (CHECKDIRTY(sb->lists.dirty, bitID))
|
---|
194 | {
|
---|
195 | crStateListsSwitch(&(sb->lists), bitID, from, to );
|
---|
196 | }
|
---|
197 | if (CHECKDIRTY(sb->buffer.dirty, bitID))
|
---|
198 | {
|
---|
199 | crStateBufferSwitch( &(sb->buffer), bitID, from, to );
|
---|
200 | }
|
---|
201 | #ifdef CR_ARB_vertex_buffer_object
|
---|
202 | if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
|
---|
203 | {
|
---|
204 | crStateBufferObjectSwitch( &(sb->bufferobject), bitID, from, to );
|
---|
205 | }
|
---|
206 | #endif
|
---|
207 | if (CHECKDIRTY(sb->client.dirty, bitID))
|
---|
208 | {
|
---|
209 | crStateClientSwitch( &(sb->client), bitID, from, to );
|
---|
210 | }
|
---|
211 | #if 0
|
---|
212 | if (CHECKDIRTY(sb->hint.dirty, bitID))
|
---|
213 | {
|
---|
214 | crStateHintSwitch( &(sb->hint), bitID, from, to );
|
---|
215 | }
|
---|
216 | #endif
|
---|
217 | if (CHECKDIRTY(sb->lighting.dirty, bitID))
|
---|
218 | {
|
---|
219 | crStateLightingSwitch( &(sb->lighting), bitID, from, to );
|
---|
220 | }
|
---|
221 | if (CHECKDIRTY(sb->occlusion.dirty, bitID))
|
---|
222 | {
|
---|
223 | crStateOcclusionSwitch( &(sb->occlusion), bitID, from, to );
|
---|
224 | }
|
---|
225 | if (CHECKDIRTY(sb->line.dirty, bitID))
|
---|
226 | {
|
---|
227 | crStateLineSwitch( &(sb->line), bitID, from, to );
|
---|
228 | }
|
---|
229 | if (CHECKDIRTY(sb->point.dirty, bitID))
|
---|
230 | {
|
---|
231 | crStatePointSwitch( &(sb->point), bitID, from, to );
|
---|
232 | }
|
---|
233 | if (CHECKDIRTY(sb->polygon.dirty, bitID))
|
---|
234 | {
|
---|
235 | crStatePolygonSwitch( &(sb->polygon), bitID, from, to );
|
---|
236 | }
|
---|
237 | if (CHECKDIRTY(sb->program.dirty, bitID))
|
---|
238 | {
|
---|
239 | crStateProgramSwitch( &(sb->program), bitID, from, to );
|
---|
240 | }
|
---|
241 | if (CHECKDIRTY(sb->stencil.dirty, bitID))
|
---|
242 | {
|
---|
243 | crStateStencilSwitch( &(sb->stencil), bitID, from, to );
|
---|
244 | }
|
---|
245 | if (CHECKDIRTY(sb->eval.dirty, bitID))
|
---|
246 | {
|
---|
247 | crStateEvaluatorSwitch( &(sb->eval), bitID, from, to );
|
---|
248 | }
|
---|
249 | #ifdef CR_ARB_imaging
|
---|
250 | if (CHECKDIRTY(sb->imaging.dirty, bitID))
|
---|
251 | {
|
---|
252 | crStateImagingSwitch( &(sb->imaging), bitID, from, to );
|
---|
253 | }
|
---|
254 | #endif
|
---|
255 | #if 0
|
---|
256 | if (CHECKDIRTY(sb->selection.dirty, bitID))
|
---|
257 | {
|
---|
258 | crStateSelectionSwitch( &(sb->selection), bitID, from, to );
|
---|
259 | }
|
---|
260 | #endif
|
---|
261 | #ifdef CR_NV_register_combiners
|
---|
262 | if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
|
---|
263 | {
|
---|
264 | crStateRegCombinerSwitch( &(sb->regcombiner), bitID, from, to );
|
---|
265 | }
|
---|
266 | #endif
|
---|
267 | #ifdef CR_ARB_multisample
|
---|
268 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
269 | {
|
---|
270 | crStateMultisampleSwitch( &(sb->multisample), bitID, from, to );
|
---|
271 | }
|
---|
272 | #endif
|
---|
273 | #ifdef CR_ARB_multisample
|
---|
274 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
275 | {
|
---|
276 | crStateMultisampleSwitch(&(sb->multisample), bitID, from, to );
|
---|
277 | }
|
---|
278 | #endif
|
---|
279 | #ifdef CR_EXT_framebuffer_object
|
---|
280 | /*Note, this should go after crStateTextureSwitch*/
|
---|
281 | crStateFramebufferObjectSwitch(from, to);
|
---|
282 | #endif
|
---|
283 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
284 | crStateGLSLSwitch(from, to);
|
---|
285 | #endif
|
---|
286 | if (CHECKDIRTY(sb->current.dirty, bitID))
|
---|
287 | {
|
---|
288 | crStateCurrentSwitch( &(sb->current), bitID, from, to );
|
---|
289 | }
|
---|
290 |
|
---|
291 | #ifdef WINDOWS
|
---|
292 | crStateApplyFBImage(to);
|
---|
293 | #endif
|
---|
294 | }
|
---|