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 | #include "cr_pixeldata.h"
|
---|
11 | #include <iprt/err.h>
|
---|
12 | #include <stdio.h>
|
---|
13 |
|
---|
14 | void crStateDiffContext( CRContext *from, CRContext *to )
|
---|
15 | {
|
---|
16 | CRbitvalue *bitID = from->bitid;
|
---|
17 | CRStateBits *sb = GetCurrentBits();
|
---|
18 |
|
---|
19 | /*crDebug( "Diffing two contexts!" ); */
|
---|
20 |
|
---|
21 | if (CHECKDIRTY(sb->transform.dirty, bitID))
|
---|
22 | {
|
---|
23 | crStateTransformDiff( &(sb->transform), bitID, from, to );
|
---|
24 | }
|
---|
25 | if (CHECKDIRTY(sb->pixel.dirty, bitID))
|
---|
26 | {
|
---|
27 | crStatePixelDiff( &(sb->pixel), bitID, from, to );
|
---|
28 | }
|
---|
29 | if (CHECKDIRTY(sb->viewport.dirty, bitID))
|
---|
30 | {
|
---|
31 | crStateViewportDiff( &(sb->viewport), bitID, from, to );
|
---|
32 | }
|
---|
33 | if (CHECKDIRTY(sb->fog.dirty, bitID))
|
---|
34 | {
|
---|
35 | crStateFogDiff( &(sb->fog), bitID, from, to );
|
---|
36 | }
|
---|
37 | if (CHECKDIRTY(sb->texture.dirty, bitID))
|
---|
38 | {
|
---|
39 | crStateTextureDiff( &(sb->texture), bitID, from, to );
|
---|
40 | }
|
---|
41 | if (CHECKDIRTY(sb->lists.dirty, bitID))
|
---|
42 | {
|
---|
43 | crStateListsDiff( &(sb->lists), bitID, from, to );
|
---|
44 | }
|
---|
45 | if (CHECKDIRTY(sb->buffer.dirty, bitID))
|
---|
46 | {
|
---|
47 | crStateBufferDiff( &(sb->buffer), bitID, from, to );
|
---|
48 | }
|
---|
49 | #ifdef CR_ARB_vertex_buffer_object
|
---|
50 | if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
|
---|
51 | {
|
---|
52 | crStateBufferObjectDiff( &(sb->bufferobject), bitID, from, to );
|
---|
53 | }
|
---|
54 | #endif
|
---|
55 | if (CHECKDIRTY(sb->client.dirty, bitID))
|
---|
56 | {
|
---|
57 | crStateClientDiff(&(sb->client), bitID, from, to );
|
---|
58 | }
|
---|
59 | if (CHECKDIRTY(sb->hint.dirty, bitID))
|
---|
60 | {
|
---|
61 | crStateHintDiff( &(sb->hint), bitID, from, to );
|
---|
62 | }
|
---|
63 | if (CHECKDIRTY(sb->lighting.dirty, bitID))
|
---|
64 | {
|
---|
65 | crStateLightingDiff( &(sb->lighting), bitID, from, to );
|
---|
66 | }
|
---|
67 | if (CHECKDIRTY(sb->line.dirty, bitID))
|
---|
68 | {
|
---|
69 | crStateLineDiff( &(sb->line), bitID, from, to );
|
---|
70 | }
|
---|
71 | if (CHECKDIRTY(sb->occlusion.dirty, bitID))
|
---|
72 | {
|
---|
73 | crStateOcclusionDiff( &(sb->occlusion), bitID, from, to );
|
---|
74 | }
|
---|
75 | if (CHECKDIRTY(sb->point.dirty, bitID))
|
---|
76 | {
|
---|
77 | crStatePointDiff( &(sb->point), bitID, from, to );
|
---|
78 | }
|
---|
79 | if (CHECKDIRTY(sb->polygon.dirty, bitID))
|
---|
80 | {
|
---|
81 | crStatePolygonDiff( &(sb->polygon), bitID, from, to );
|
---|
82 | }
|
---|
83 | if (CHECKDIRTY(sb->program.dirty, bitID))
|
---|
84 | {
|
---|
85 | crStateProgramDiff( &(sb->program), bitID, from, to );
|
---|
86 | }
|
---|
87 | if (CHECKDIRTY(sb->stencil.dirty, bitID))
|
---|
88 | {
|
---|
89 | crStateStencilDiff( &(sb->stencil), bitID, from, to );
|
---|
90 | }
|
---|
91 | if (CHECKDIRTY(sb->eval.dirty, bitID))
|
---|
92 | {
|
---|
93 | crStateEvaluatorDiff( &(sb->eval), bitID, from, to );
|
---|
94 | }
|
---|
95 | #ifdef CR_ARB_imaging
|
---|
96 | if (CHECKDIRTY(sb->imaging.dirty, bitID))
|
---|
97 | {
|
---|
98 | crStateImagingDiff( &(sb->imaging), bitID, from, to );
|
---|
99 | }
|
---|
100 | #endif
|
---|
101 | #if 0
|
---|
102 | if (CHECKDIRTY(sb->selection.dirty, bitID))
|
---|
103 | {
|
---|
104 | crStateSelectionDiff( &(sb->selection), bitID, from, to );
|
---|
105 | }
|
---|
106 | #endif
|
---|
107 | #ifdef CR_NV_register_combiners
|
---|
108 | if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
|
---|
109 | {
|
---|
110 | crStateRegCombinerDiff( &(sb->regcombiner), bitID, from, to );
|
---|
111 | }
|
---|
112 | #endif
|
---|
113 | #ifdef CR_ARB_multisample
|
---|
114 | if (CHECKDIRTY(sb->multisample.dirty, bitID) &&
|
---|
115 | from->extensions.ARB_multisample)
|
---|
116 | {
|
---|
117 | crStateMultisampleDiff( &(sb->multisample), bitID, from, to );
|
---|
118 | }
|
---|
119 | #endif
|
---|
120 | if (CHECKDIRTY(sb->current.dirty, bitID))
|
---|
121 | {
|
---|
122 | crStateCurrentDiff( &(sb->current), bitID, from, to );
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | void crStateFreeFBImageLegacy(CRContext *to)
|
---|
127 | {
|
---|
128 | if (to->buffer.pFrontImg)
|
---|
129 | {
|
---|
130 | crFree(to->buffer.pFrontImg);
|
---|
131 | to->buffer.pFrontImg = NULL;
|
---|
132 | }
|
---|
133 | if (to->buffer.pBackImg)
|
---|
134 | {
|
---|
135 | crFree(to->buffer.pBackImg);
|
---|
136 | to->buffer.pBackImg = NULL;
|
---|
137 | }
|
---|
138 |
|
---|
139 | to->buffer.storedWidth = 0;
|
---|
140 | to->buffer.storedHeight = 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | int crStateAcquireFBImage(CRContext *to, CRFBData *data)
|
---|
144 | {
|
---|
145 | /*CRBufferState *pBuf = &to->buffer; - unused */
|
---|
146 | CRPixelPackState packing = to->client.pack;
|
---|
147 | uint32_t i;
|
---|
148 |
|
---|
149 | diff_api.PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
---|
150 | diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
---|
151 | diff_api.PixelStorei(GL_PACK_ALIGNMENT, 1);
|
---|
152 | diff_api.PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
---|
153 | diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
|
---|
154 | diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, 0);
|
---|
155 | diff_api.PixelStorei(GL_PACK_SWAP_BYTES, 0);
|
---|
156 | diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
|
---|
157 |
|
---|
158 | if (to->bufferobject.packBuffer->hwid>0)
|
---|
159 | {
|
---|
160 | diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
---|
161 | }
|
---|
162 |
|
---|
163 | for (i = 0; i < data->cElements; ++i)
|
---|
164 | {
|
---|
165 | CRFBDataElement *el = &data->aElements[i];
|
---|
166 |
|
---|
167 | if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
168 | {
|
---|
169 | if (!to->buffer.depthTest)
|
---|
170 | {
|
---|
171 | diff_api.Enable(GL_DEPTH_TEST);
|
---|
172 | }
|
---|
173 | if (to->pixel.depthScale != 1.0f)
|
---|
174 | {
|
---|
175 | diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
|
---|
176 | }
|
---|
177 | if (to->pixel.depthBias != 0.0f)
|
---|
178 | {
|
---|
179 | diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
|
---|
180 | }
|
---|
181 | }
|
---|
182 | if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
183 | {
|
---|
184 | if (!to->stencil.stencilTest)
|
---|
185 | {
|
---|
186 | diff_api.Enable(GL_STENCIL_TEST);
|
---|
187 | }
|
---|
188 | if (to->pixel.mapStencil)
|
---|
189 | {
|
---|
190 | diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
|
---|
191 | }
|
---|
192 | if (to->pixel.indexOffset)
|
---|
193 | {
|
---|
194 | diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
|
---|
195 | }
|
---|
196 | if (to->pixel.indexShift)
|
---|
197 | {
|
---|
198 | diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, el->idFBO);
|
---|
203 |
|
---|
204 | if (el->enmBuffer)
|
---|
205 | diff_api.ReadBuffer(el->enmBuffer);
|
---|
206 |
|
---|
207 | diff_api.ReadPixels(el->posX, el->posY, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
|
---|
208 | crDebug("Acquired %d;%d;%d;%d;%d;0x%p fb image", el->enmBuffer, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
|
---|
209 |
|
---|
210 | if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
211 | {
|
---|
212 | if (to->pixel.depthScale != 1.0f)
|
---|
213 | {
|
---|
214 | diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
|
---|
215 | }
|
---|
216 | if (to->pixel.depthBias != 0.0f)
|
---|
217 | {
|
---|
218 | diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
|
---|
219 | }
|
---|
220 | if (!to->buffer.depthTest)
|
---|
221 | {
|
---|
222 | diff_api.Disable(GL_DEPTH_TEST);
|
---|
223 | }
|
---|
224 | }
|
---|
225 | if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
226 | {
|
---|
227 | if (to->pixel.indexOffset)
|
---|
228 | {
|
---|
229 | diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
|
---|
230 | }
|
---|
231 | if (to->pixel.indexShift)
|
---|
232 | {
|
---|
233 | diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
|
---|
234 | }
|
---|
235 | if (to->pixel.mapStencil)
|
---|
236 | {
|
---|
237 | diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
|
---|
238 | }
|
---|
239 | if (!to->stencil.stencilTest)
|
---|
240 | {
|
---|
241 | diff_api.Disable(GL_STENCIL_TEST);
|
---|
242 | }
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | if (to->bufferobject.packBuffer->hwid>0)
|
---|
247 | {
|
---|
248 | diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, to->bufferobject.packBuffer->hwid);
|
---|
249 | }
|
---|
250 | if (to->framebufferobject.readFB)
|
---|
251 | {
|
---|
252 | CRASSERT(to->framebufferobject.readFB->hwid);
|
---|
253 | diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB->hwid);
|
---|
254 | diff_api.ReadBuffer(to->framebufferobject.readFB->readbuffer);
|
---|
255 |
|
---|
256 | }
|
---|
257 | else if (data->idOverrrideFBO)
|
---|
258 | {
|
---|
259 | diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, data->idOverrrideFBO);
|
---|
260 | diff_api.ReadBuffer(GL_COLOR_ATTACHMENT0);
|
---|
261 | }
|
---|
262 | else
|
---|
263 | {
|
---|
264 | diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
|
---|
265 | diff_api.ReadBuffer(to->buffer.readBuffer);
|
---|
266 | }
|
---|
267 |
|
---|
268 | diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
|
---|
269 | diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
|
---|
270 | diff_api.PixelStorei(GL_PACK_ALIGNMENT, packing.alignment);
|
---|
271 | diff_api.PixelStorei(GL_PACK_ROW_LENGTH, packing.rowLength);
|
---|
272 | diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, packing.imageHeight);
|
---|
273 | diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, packing.skipImages);
|
---|
274 | diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
|
---|
275 | diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
|
---|
276 | return VINF_SUCCESS;
|
---|
277 | }
|
---|
278 |
|
---|
279 | void crStateApplyFBImage(CRContext *to, CRFBData *data)
|
---|
280 | {
|
---|
281 | {
|
---|
282 | /*CRBufferState *pBuf = &to->buffer; - unused */
|
---|
283 | CRPixelPackState unpack = to->client.unpack;
|
---|
284 | uint32_t i;
|
---|
285 |
|
---|
286 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
---|
287 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
---|
288 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
289 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
290 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
|
---|
291 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
|
---|
292 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
|
---|
293 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
|
---|
294 |
|
---|
295 | if (to->bufferobject.unpackBuffer->hwid>0)
|
---|
296 | {
|
---|
297 | diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
|
---|
298 | }
|
---|
299 |
|
---|
300 | diff_api.Disable(GL_ALPHA_TEST);
|
---|
301 | diff_api.Disable(GL_SCISSOR_TEST);
|
---|
302 | diff_api.Disable(GL_BLEND);
|
---|
303 | diff_api.Disable(GL_COLOR_LOGIC_OP);
|
---|
304 | diff_api.Disable(GL_DEPTH_TEST);
|
---|
305 | diff_api.Disable(GL_STENCIL_TEST);
|
---|
306 |
|
---|
307 | for (i = 0; i < data->cElements; ++i)
|
---|
308 | {
|
---|
309 | CRFBDataElement *el = &data->aElements[i];
|
---|
310 | #if 0
|
---|
311 | char fname[200];
|
---|
312 | sprintf(fname, "./img_apply_%p_%d_%d.tga", to, i, el->enmFormat);
|
---|
313 | crDumpNamedTGA(fname, el->width, el->height, el->pvData);
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | /* Before SSM version SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
|
---|
317 | * saved state file contined invalid DEPTH/STENCIL data. In order to prevent
|
---|
318 | * crashes and improper guest App behavior, this data should be ignored. */
|
---|
319 | if ( data->u32Version < SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
|
---|
320 | && ( el->enmFormat == GL_DEPTH_COMPONENT
|
---|
321 | || el->enmFormat == GL_STENCIL_INDEX
|
---|
322 | || el->enmFormat == GL_DEPTH_STENCIL))
|
---|
323 | continue;
|
---|
324 |
|
---|
325 | if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
326 | {
|
---|
327 | diff_api.Enable(GL_DEPTH_TEST);
|
---|
328 | if (to->pixel.depthScale != 1.0f)
|
---|
329 | {
|
---|
330 | diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
|
---|
331 | }
|
---|
332 | if (to->pixel.depthBias != 0.0f)
|
---|
333 | {
|
---|
334 | diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
|
---|
335 | }
|
---|
336 | }
|
---|
337 | if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
338 | {
|
---|
339 | diff_api.Enable(GL_STENCIL_TEST);
|
---|
340 | if (to->pixel.mapStencil)
|
---|
341 | {
|
---|
342 | diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
|
---|
343 | }
|
---|
344 | if (to->pixel.indexOffset)
|
---|
345 | {
|
---|
346 | diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
|
---|
347 | }
|
---|
348 | if (to->pixel.indexShift)
|
---|
349 | {
|
---|
350 | diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, el->idFBO);
|
---|
355 |
|
---|
356 | if (el->enmBuffer)
|
---|
357 | diff_api.DrawBuffer(el->enmBuffer);
|
---|
358 |
|
---|
359 | diff_api.WindowPos2iARB(el->posX, el->posY);
|
---|
360 | diff_api.DrawPixels(el->width, el->height, el->enmFormat, el->enmType, el->pvData);
|
---|
361 | crDebug("Applied %d;%d;%d;%d;%d;0x%p fb image", el->enmBuffer, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
|
---|
362 |
|
---|
363 | if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
364 | {
|
---|
365 | if (to->pixel.depthScale != 1.0f)
|
---|
366 | {
|
---|
367 | diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
|
---|
368 | }
|
---|
369 | if (to->pixel.depthBias != 0.0f)
|
---|
370 | {
|
---|
371 | diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
|
---|
372 | }
|
---|
373 | diff_api.Disable(GL_DEPTH_TEST);
|
---|
374 | }
|
---|
375 | if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
|
---|
376 | {
|
---|
377 | if (to->pixel.indexOffset)
|
---|
378 | {
|
---|
379 | diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
|
---|
380 | }
|
---|
381 | if (to->pixel.indexShift)
|
---|
382 | {
|
---|
383 | diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
|
---|
384 | }
|
---|
385 | if (to->pixel.mapStencil)
|
---|
386 | {
|
---|
387 | diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
|
---|
388 | }
|
---|
389 | diff_api.Disable(GL_STENCIL_TEST);
|
---|
390 | }
|
---|
391 | }
|
---|
392 |
|
---|
393 | diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
|
---|
394 | if (to->bufferobject.unpackBuffer->hwid>0)
|
---|
395 | {
|
---|
396 | diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->bufferobject.unpackBuffer->hwid);
|
---|
397 | }
|
---|
398 | if (to->framebufferobject.drawFB)
|
---|
399 | {
|
---|
400 | CRASSERT(to->framebufferobject.drawFB->hwid);
|
---|
401 | diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB->hwid);
|
---|
402 | diff_api.DrawBuffer(to->framebufferobject.drawFB->drawbuffer[0]);
|
---|
403 | }
|
---|
404 | else if (data->idOverrrideFBO)
|
---|
405 | {
|
---|
406 | diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, data->idOverrrideFBO);
|
---|
407 | diff_api.DrawBuffer(GL_COLOR_ATTACHMENT0);
|
---|
408 | }
|
---|
409 | else
|
---|
410 | {
|
---|
411 | diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
|
---|
412 | diff_api.DrawBuffer(to->buffer.drawBuffer);
|
---|
413 | }
|
---|
414 | if (to->buffer.alphaTest)
|
---|
415 | {
|
---|
416 | diff_api.Enable(GL_ALPHA_TEST);
|
---|
417 | }
|
---|
418 | if (to->viewport.scissorTest)
|
---|
419 | {
|
---|
420 | diff_api.Enable(GL_SCISSOR_TEST);
|
---|
421 | }
|
---|
422 | if (to->buffer.blend)
|
---|
423 | {
|
---|
424 | diff_api.Enable(GL_BLEND);
|
---|
425 | }
|
---|
426 | if (to->buffer.logicOp)
|
---|
427 | {
|
---|
428 | diff_api.Enable(GL_COLOR_LOGIC_OP);
|
---|
429 | }
|
---|
430 | if (to->buffer.depthTest)
|
---|
431 | {
|
---|
432 | diff_api.Enable(GL_DEPTH_TEST);
|
---|
433 | }
|
---|
434 | if (to->stencil.stencilTest)
|
---|
435 | {
|
---|
436 | diff_api.Enable(GL_STENCIL_TEST);
|
---|
437 | }
|
---|
438 |
|
---|
439 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
|
---|
440 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
|
---|
441 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
|
---|
442 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
|
---|
443 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
|
---|
444 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
|
---|
445 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
|
---|
446 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
|
---|
447 |
|
---|
448 | diff_api.Finish();
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | void crStateSwitchContext( CRContext *from, CRContext *to )
|
---|
453 | {
|
---|
454 | CRbitvalue *bitID = to->bitid;
|
---|
455 | CRStateBits *sb = GetCurrentBits();
|
---|
456 |
|
---|
457 | if (CHECKDIRTY(sb->attrib.dirty, bitID))
|
---|
458 | {
|
---|
459 | crStateAttribSwitch(&(sb->attrib), bitID, from, to );
|
---|
460 | }
|
---|
461 | if (CHECKDIRTY(sb->transform.dirty, bitID))
|
---|
462 | {
|
---|
463 | crStateTransformSwitch( &(sb->transform), bitID, from, to );
|
---|
464 | }
|
---|
465 | if (CHECKDIRTY(sb->pixel.dirty, bitID))
|
---|
466 | {
|
---|
467 | crStatePixelSwitch(&(sb->pixel), bitID, from, to );
|
---|
468 | }
|
---|
469 | if (CHECKDIRTY(sb->viewport.dirty, bitID))
|
---|
470 | {
|
---|
471 | crStateViewportSwitch(&(sb->viewport), bitID, from, to );
|
---|
472 | }
|
---|
473 | if (CHECKDIRTY(sb->fog.dirty, bitID))
|
---|
474 | {
|
---|
475 | crStateFogSwitch(&(sb->fog), bitID, from, to );
|
---|
476 | }
|
---|
477 | if (CHECKDIRTY(sb->texture.dirty, bitID))
|
---|
478 | {
|
---|
479 | crStateTextureSwitch( &(sb->texture), bitID, from, to );
|
---|
480 | }
|
---|
481 | if (CHECKDIRTY(sb->lists.dirty, bitID))
|
---|
482 | {
|
---|
483 | crStateListsSwitch(&(sb->lists), bitID, from, to );
|
---|
484 | }
|
---|
485 | if (CHECKDIRTY(sb->buffer.dirty, bitID))
|
---|
486 | {
|
---|
487 | crStateBufferSwitch( &(sb->buffer), bitID, from, to );
|
---|
488 | }
|
---|
489 | #ifdef CR_ARB_vertex_buffer_object
|
---|
490 | if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
|
---|
491 | {
|
---|
492 | crStateBufferObjectSwitch( &(sb->bufferobject), bitID, from, to );
|
---|
493 | }
|
---|
494 | #endif
|
---|
495 | if (CHECKDIRTY(sb->client.dirty, bitID))
|
---|
496 | {
|
---|
497 | crStateClientSwitch( &(sb->client), bitID, from, to );
|
---|
498 | }
|
---|
499 | #if 0
|
---|
500 | if (CHECKDIRTY(sb->hint.dirty, bitID))
|
---|
501 | {
|
---|
502 | crStateHintSwitch( &(sb->hint), bitID, from, to );
|
---|
503 | }
|
---|
504 | #endif
|
---|
505 | if (CHECKDIRTY(sb->lighting.dirty, bitID))
|
---|
506 | {
|
---|
507 | crStateLightingSwitch( &(sb->lighting), bitID, from, to );
|
---|
508 | }
|
---|
509 | if (CHECKDIRTY(sb->occlusion.dirty, bitID))
|
---|
510 | {
|
---|
511 | crStateOcclusionSwitch( &(sb->occlusion), bitID, from, to );
|
---|
512 | }
|
---|
513 | if (CHECKDIRTY(sb->line.dirty, bitID))
|
---|
514 | {
|
---|
515 | crStateLineSwitch( &(sb->line), bitID, from, to );
|
---|
516 | }
|
---|
517 | if (CHECKDIRTY(sb->point.dirty, bitID))
|
---|
518 | {
|
---|
519 | crStatePointSwitch( &(sb->point), bitID, from, to );
|
---|
520 | }
|
---|
521 | if (CHECKDIRTY(sb->polygon.dirty, bitID))
|
---|
522 | {
|
---|
523 | crStatePolygonSwitch( &(sb->polygon), bitID, from, to );
|
---|
524 | }
|
---|
525 | if (CHECKDIRTY(sb->program.dirty, bitID))
|
---|
526 | {
|
---|
527 | crStateProgramSwitch( &(sb->program), bitID, from, to );
|
---|
528 | }
|
---|
529 | if (CHECKDIRTY(sb->stencil.dirty, bitID))
|
---|
530 | {
|
---|
531 | crStateStencilSwitch( &(sb->stencil), bitID, from, to );
|
---|
532 | }
|
---|
533 | if (CHECKDIRTY(sb->eval.dirty, bitID))
|
---|
534 | {
|
---|
535 | crStateEvaluatorSwitch( &(sb->eval), bitID, from, to );
|
---|
536 | }
|
---|
537 | #ifdef CR_ARB_imaging
|
---|
538 | if (CHECKDIRTY(sb->imaging.dirty, bitID))
|
---|
539 | {
|
---|
540 | crStateImagingSwitch( &(sb->imaging), bitID, from, to );
|
---|
541 | }
|
---|
542 | #endif
|
---|
543 | #if 0
|
---|
544 | if (CHECKDIRTY(sb->selection.dirty, bitID))
|
---|
545 | {
|
---|
546 | crStateSelectionSwitch( &(sb->selection), bitID, from, to );
|
---|
547 | }
|
---|
548 | #endif
|
---|
549 | #ifdef CR_NV_register_combiners
|
---|
550 | if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
|
---|
551 | {
|
---|
552 | crStateRegCombinerSwitch( &(sb->regcombiner), bitID, from, to );
|
---|
553 | }
|
---|
554 | #endif
|
---|
555 | #ifdef CR_ARB_multisample
|
---|
556 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
557 | {
|
---|
558 | crStateMultisampleSwitch( &(sb->multisample), bitID, from, to );
|
---|
559 | }
|
---|
560 | #endif
|
---|
561 | #ifdef CR_ARB_multisample
|
---|
562 | if (CHECKDIRTY(sb->multisample.dirty, bitID))
|
---|
563 | {
|
---|
564 | crStateMultisampleSwitch(&(sb->multisample), bitID, from, to );
|
---|
565 | }
|
---|
566 | #endif
|
---|
567 | #ifdef CR_EXT_framebuffer_object
|
---|
568 | /*Note, this should go after crStateTextureSwitch*/
|
---|
569 | crStateFramebufferObjectSwitch(from, to);
|
---|
570 | #endif
|
---|
571 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
572 | crStateGLSLSwitch(from, to);
|
---|
573 | #endif
|
---|
574 | if (CHECKDIRTY(sb->current.dirty, bitID))
|
---|
575 | {
|
---|
576 | crStateCurrentSwitch( &(sb->current), bitID, from, to );
|
---|
577 | }
|
---|
578 |
|
---|
579 | #ifdef WINDOWS
|
---|
580 | if (to->buffer.pFrontImg)
|
---|
581 | {
|
---|
582 | CRFBData *pLazyData = (CRFBData *)to->buffer.pFrontImg;
|
---|
583 | crStateApplyFBImage(to, pLazyData);
|
---|
584 | crStateFreeFBImageLegacy(to);
|
---|
585 | }
|
---|
586 | #endif
|
---|
587 | }
|
---|
588 |
|
---|
589 | void crStateSyncHWErrorState(CRContext *ctx)
|
---|
590 | {
|
---|
591 | GLenum err;
|
---|
592 | while ((err = diff_api.GetError()) != GL_NO_ERROR)
|
---|
593 | {
|
---|
594 | if (ctx->error != GL_NO_ERROR)
|
---|
595 | ctx->error = err;
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|
599 | GLenum crStateCleanHWErrorState(void)
|
---|
600 | {
|
---|
601 | GLenum err;
|
---|
602 | while ((err = diff_api.GetError()) != GL_NO_ERROR)
|
---|
603 | {
|
---|
604 | static int cErrPrints = 0;
|
---|
605 | #ifndef DEBUG_misha
|
---|
606 | if (cErrPrints < 5)
|
---|
607 | #endif
|
---|
608 | {
|
---|
609 | ++cErrPrints;
|
---|
610 | WARN(("cleaning gl error (0x%x), ignoring.. (%d out of 5) ..", err, cErrPrints));
|
---|
611 | }
|
---|
612 | }
|
---|
613 |
|
---|
614 | return err;
|
---|
615 | }
|
---|
616 |
|
---|
617 |
|
---|
618 | void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO)
|
---|
619 | {
|
---|
620 | if (!fromCtx)
|
---|
621 | return;
|
---|
622 |
|
---|
623 | if (g_bVBoxEnableDiffOnMakeCurrent && toCtx && toCtx != fromCtx)
|
---|
624 | crStateSyncHWErrorState(fromCtx);
|
---|
625 |
|
---|
626 | #ifdef CR_EXT_framebuffer_object
|
---|
627 | crStateFramebufferObjectDisableHW(fromCtx, idDrawFBO, idReadFBO);
|
---|
628 | #endif
|
---|
629 | }
|
---|
630 |
|
---|
631 | void crStateSwitchPostprocess(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO)
|
---|
632 | {
|
---|
633 | if (!toCtx)
|
---|
634 | return;
|
---|
635 |
|
---|
636 | #ifdef CR_EXT_framebuffer_object
|
---|
637 | crStateFramebufferObjectReenableHW(fromCtx, toCtx, idDrawFBO, idReadFBO);
|
---|
638 | #endif
|
---|
639 |
|
---|
640 | if (g_bVBoxEnableDiffOnMakeCurrent && fromCtx && toCtx != fromCtx)
|
---|
641 | {
|
---|
642 | CR_STATE_CLEAN_HW_ERR_WARN("error on make current");
|
---|
643 | }
|
---|
644 | }
|
---|