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 crStateSwitchContext( CRContext *from, CRContext *to )
|
---|
124 | {
|
---|
125 | CRbitvalue *bitID = to->bitid;
|
---|
126 | CRStateBits *sb = GetCurrentBits();
|
---|
127 |
|
---|
128 | if (CHECKDIRTY(sb->attrib.dirty, bitID))
|
---|
129 | {
|
---|
130 | crStateAttribSwitch(&(sb->attrib), bitID, from, to );
|
---|
131 | }
|
---|
132 | if (CHECKDIRTY(sb->transform.dirty, bitID))
|
---|
133 | {
|
---|
134 | crStateTransformSwitch( &(sb->transform), bitID, from, to );
|
---|
135 | }
|
---|
136 | if (CHECKDIRTY(sb->pixel.dirty, bitID))
|
---|
137 | {
|
---|
138 | crStatePixelSwitch(&(sb->pixel), bitID, from, to );
|
---|
139 | }
|
---|
140 | if (CHECKDIRTY(sb->viewport.dirty, bitID))
|
---|
141 | {
|
---|
142 | crStateViewportSwitch(&(sb->viewport), bitID, from, to );
|
---|
143 | }
|
---|
144 | if (CHECKDIRTY(sb->fog.dirty, bitID))
|
---|
145 | {
|
---|
146 | crStateFogSwitch(&(sb->fog), bitID, from, to );
|
---|
147 | }
|
---|
148 | if (CHECKDIRTY(sb->texture.dirty, bitID))
|
---|
149 | {
|
---|
150 | crStateTextureSwitch( &(sb->texture), bitID, from, to );
|
---|
151 | }
|
---|
152 | if (CHECKDIRTY(sb->lists.dirty, bitID))
|
---|
153 | {
|
---|
154 | crStateListsSwitch(&(sb->lists), bitID, from, to );
|
---|
155 | }
|
---|
156 | if (CHECKDIRTY(sb->buffer.dirty, bitID))
|
---|
157 | {
|
---|
158 | crStateBufferSwitch( &(sb->buffer), bitID, from, to );
|
---|
159 | }
|
---|
160 | #ifdef CR_ARB_vertex_buffer_object
|
---|
161 | if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
|
---|
162 | {
|
---|
163 | crStateBufferObjectSwitch( &(sb->bufferobject), bitID, from, to );
|
---|
164 | }
|
---|
165 | #endif
|
---|
166 | if (CHECKDIRTY(sb->client.dirty, bitID))
|
---|
167 | {
|
---|
168 | crStateClientSwitch( &(sb->client), bitID, from, to );
|
---|
169 | }
|
---|
170 | #if 0
|
---|
171 | if (CHECKDIRTY(sb->hint.dirty, bitID))
|
---|
172 | {
|
---|
173 | crStateHintSwitch( &(sb->hint), bitID, from, to );
|
---|
174 | }
|
---|
175 | #endif
|
---|
176 | if (CHECKDIRTY(sb->lighting.dirty, bitID))
|
---|
177 | {
|
---|
178 | crStateLightingSwitch( &(sb->lighting), bitID, from, to );
|
---|
179 | }
|
---|
180 | if (CHECKDIRTY(sb->occlusion.dirty, bitID))
|
---|
181 | {
|
---|
182 | crStateOcclusionSwitch( &(sb->occlusion), bitID, from, to );
|
---|
183 | }
|
---|
184 | if (CHECKDIRTY(sb->line.dirty, bitID))
|
---|
185 | {
|
---|
186 | crStateLineSwitch( &(sb->line), bitID, from, to );
|
---|
187 | }
|
---|
188 | if (CHECKDIRTY(sb->point.dirty, bitID))
|
---|
189 | {
|
---|
190 | crStatePointSwitch( &(sb->point), bitID, from, to );
|
---|
191 | }
|
---|
192 | if (CHECKDIRTY(sb->polygon.dirty, bitID))
|
---|
193 | {
|
---|
194 | crStatePolygonSwitch( &(sb->polygon), bitID, from, to );
|
---|
195 | }
|
---|
196 | if (CHECKDIRTY(sb->program.dirty, bitID))
|
---|
197 | {
|
---|
198 | crStateProgramSwitch( &(sb->program), bitID, from, to );
|
---|
199 | }
|
---|
200 | if (CHECKDIRTY(sb->stencil.dirty, bitID))
|
---|
201 | {
|
---|
202 | crStateStencilSwitch( &(sb->stencil), bitID, from, to );
|
---|
203 | }
|
---|
204 | if (CHECKDIRTY(sb->eval.dirty, bitID))
|
---|
205 | {
|
---|
206 | crStateEvaluatorSwitch( &(sb->eval), bitID, from, to );
|
---|
207 | }
|
---|
208 | #ifdef CR_ARB_imaging
|
---|
209 | if (CHECKDIRTY(sb->imaging.dirty, bitID))
|
---|
210 | {
|
---|
211 | crStateImagingSwitch( &(sb->imaging), bitID, from, to );
|
---|
212 | }
|
---|
213 | #endif
|
---|
214 | #if 0
|
---|
215 | if (CHECKDIRTY(sb->selection.dirty, bitID))
|
---|
216 | {
|
---|
217 | crStateSelectionSwitch( &(sb->selection), bitID, from, to );
|
---|
218 | }
|
---|
219 | #endif
|
---|
220 | #ifdef CR_NV_register_combiners
|
---|
221 | if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
|
---|
222 | {
|
---|
223 | crStateRegCombinerSwitch( &(sb->regcombiner), bitID, from, to );
|
---|
224 | }
|
---|
225 | #endif
|
---|
226 | #ifdef CR_ARB_multisample
|
---|
227 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
228 | {
|
---|
229 | crStateMultisampleSwitch( &(sb->multisample), bitID, from, to );
|
---|
230 | }
|
---|
231 | #endif
|
---|
232 | #ifdef CR_ARB_multisample
|
---|
233 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
234 | {
|
---|
235 | crStateMultisampleSwitch(&(sb->multisample), bitID, from, to );
|
---|
236 | }
|
---|
237 | #endif
|
---|
238 | #ifdef CR_EXT_framebuffer_object
|
---|
239 | /*Note, this should go after crStateTextureSwitch*/
|
---|
240 | crStateFramebufferObjectSwitch(from, to);
|
---|
241 | #endif
|
---|
242 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
243 | crStateGLSLSwitch(from, to);
|
---|
244 | #endif
|
---|
245 | if (CHECKDIRTY(sb->current.dirty, bitID))
|
---|
246 | {
|
---|
247 | crStateCurrentSwitch( &(sb->current), bitID, from, to );
|
---|
248 | }
|
---|
249 |
|
---|
250 | if (to->pImage)
|
---|
251 | {
|
---|
252 | CRViewportState *pVP = &to->viewport;
|
---|
253 | CRPixelPackState unpack = to->client.unpack;
|
---|
254 |
|
---|
255 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
---|
256 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
---|
257 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
258 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
259 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
|
---|
260 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
|
---|
261 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
|
---|
262 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
|
---|
263 |
|
---|
264 | diff_api.DrawBuffer(GL_FRONT);
|
---|
265 | diff_api.WindowPos2iARB(0, 0);
|
---|
266 | diff_api.DrawPixels(pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, to->pImage);
|
---|
267 |
|
---|
268 | diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
|
---|
269 | diff_api.DrawBuffer(to->framebufferobject.drawFB ?
|
---|
270 | to->framebufferobject.drawFB->drawbuffer[0] : to->buffer.drawBuffer);
|
---|
271 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
|
---|
272 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
|
---|
273 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
|
---|
274 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
|
---|
275 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
|
---|
276 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
|
---|
277 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
|
---|
278 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
|
---|
279 |
|
---|
280 | crFree(to->pImage);
|
---|
281 | to->pImage = NULL;
|
---|
282 | }
|
---|
283 | }
|
---|