VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c@ 78375

Last change on this file since 78375 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette