VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c@ 36300

Last change on this file since 36300 was 34107, checked in by vboxsync, 14 years ago

crOpenGL/wddm: resync shared data only once

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 75.6 KB
Line 
1/* $Id: state_snapshot.c 34107 2010-11-16 11:37:51Z vboxsync $ */
2
3/** @file
4 * VBox Context state saving/loading used by VM snapshot
5 */
6
7/*
8 * Copyright (C) 2008 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "state.h"
20#include "state_internals.h"
21#include "state/cr_statetypes.h"
22#include "state/cr_texture.h"
23#include "cr_mem.h"
24#include "cr_string.h"
25#include "cr_pixeldata.h"
26#include <stdio.h>
27
28#include <iprt/assert.h>
29#include <iprt/types.h>
30#include <iprt/err.h>
31#include <VBox/err.h>
32
33/* @todo
34 * We have two ways of saving/loading states.
35 *
36 * First which is being used atm, just pure saving/loading of structures.
37 * The drawback is we have to deal with all the pointers around those structures,
38 * we'd have to update this code if we'd change state tracking.
39 * On the bright side it's fast, though it's not really needed as it's not that often operation.
40 * It could also worth to split those functions into appropriate parts,
41 * similar to the way context creation is being done.
42 *
43 * Second way would be to implement full dispatch api table and substitute diff_api during saving/loading.
44 * Then if we implement that api in a similar way to packer/unpacker with a change to store/load
45 * via provided pSSM handle instead of pack buffer,
46 * saving state could be done by simple diffing against empty "dummy" context.
47 * Restoring state in such case would look like unpacking commands from pSSM instead of network buffer.
48 * This would be slower (who cares) but most likely will not require any code changes to support in future.
49 * We will reduce amount of saved data as we'd save only changed state parts, but I doubt it'd be that much.
50 * It could be done for the first way as well, but requires tons of bit checks.
51 */
52
53static int32_t crStateAllocAndSSMR3GetMem(PSSMHANDLE pSSM, void **pBuffer, size_t cbBuffer)
54{
55 CRASSERT(pSSM && pBuffer && cbBuffer>0);
56
57 *pBuffer = crAlloc(cbBuffer);
58 if (!*pBuffer)
59 return VERR_NO_MEMORY;
60
61 return SSMR3GetMem(pSSM, *pBuffer, cbBuffer);
62}
63
64static int32_t crStateSaveTextureObjData(CRTextureObj *pTexture, PSSMHANDLE pSSM)
65{
66 int32_t rc, face, i;
67 GLboolean bound = GL_FALSE;
68
69 CRASSERT(pTexture && pSSM);
70
71 crDebug("crStateSaveTextureObjData %u. START", pTexture->id);
72
73 for (face = 0; face < 6; face++) {
74 CRASSERT(pTexture->level[face]);
75
76 for (i = 0; i < CR_MAX_MIPMAP_LEVELS; i++) {
77 CRTextureLevel *ptl = &(pTexture->level[face][i]);
78 rc = SSMR3PutMem(pSSM, ptl, sizeof(*ptl));
79 AssertRCReturn(rc, rc);
80 if (ptl->img)
81 {
82 CRASSERT(ptl->bytes);
83 rc = SSMR3PutMem(pSSM, ptl->img, ptl->bytes);
84 AssertRCReturn(rc, rc);
85 }
86#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
87 /* Note, this is not a bug.
88 * Even with CR_STATE_NO_TEXTURE_IMAGE_STORE defined, it's possible that ptl->img!=NULL.
89 * For ex. we're saving snapshot right after it was loaded
90 * and some context hasn't been used by the guest application yet
91 * (pContext->shared->bTexResyncNeeded==GL_TRUE).
92 */
93 else if (ptl->bytes)
94 {
95 char *pImg;
96 GLenum target;
97
98 if (!bound)
99 {
100 diff_api.BindTexture(pTexture->target, pTexture->hwid);
101 bound = GL_TRUE;
102 }
103
104 if (pTexture->target!=GL_TEXTURE_CUBE_MAP_ARB)
105 {
106 target = pTexture->target;
107 }
108 else
109 {
110 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
111 }
112
113#ifdef DEBUG
114 pImg = crAlloc(ptl->bytes+4);
115#else
116 pImg = crAlloc(ptl->bytes);
117#endif
118 if (!pImg) return VERR_NO_MEMORY;
119
120#ifdef DEBUG
121 {
122 GLint w,h=0;
123 *(int*)((char*)pImg+ptl->bytes) = 0xDEADDEAD;
124 crDebug("get image: compressed %i, face %i, level %i, width %i, height %i, bytes %i",
125 ptl->compressed, face, i, ptl->width, ptl->height, ptl->bytes);
126 diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_WIDTH, &w);
127 diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_HEIGHT, &h);
128 if (w!=ptl->width || h!=ptl->height)
129 {
130 crWarning("!!!tex size mismatch %i, %i!!!", w, h);
131 }
132 }
133#endif
134
135 /*@todo: ugly workaround for crashes inside ati driver,
136 * they overwrite their own allocated memory in cases where texlevel >=4
137 and width or height <=2.
138 */
139 if (i<4 || (ptl->width>2 && ptl->height>2))
140 {
141 if (!ptl->compressed)
142 {
143 diff_api.GetTexImage(target, i, ptl->format, ptl->type, pImg);
144 }
145 else
146 {
147 diff_api.GetCompressedTexImageARB(target, i, pImg);
148 }
149 }
150
151#ifdef DEBUG
152 if (*(int*)((char*)pImg+ptl->bytes) != 0xDEADDEAD)
153 {
154 crWarning("Texture is bigger than expected!!!");
155 }
156#endif
157
158 rc = SSMR3PutMem(pSSM, pImg, ptl->bytes);
159 crFree(pImg);
160 AssertRCReturn(rc, rc);
161 }
162#endif
163 }
164 }
165
166 crDebug("crStateSaveTextureObjData %u. END", pTexture->id);
167
168 return VINF_SUCCESS;
169}
170
171static int32_t crStateLoadTextureObjData(CRTextureObj *pTexture, PSSMHANDLE pSSM)
172{
173 int32_t rc, face, i;
174
175 CRASSERT(pTexture && pSSM);
176
177 for (face = 0; face < 6; face++) {
178 CRASSERT(pTexture->level[face]);
179
180 for (i = 0; i < CR_MAX_MIPMAP_LEVELS; i++) {
181 CRTextureLevel *ptl = &(pTexture->level[face][i]);
182 CRASSERT(!ptl->img);
183
184 rc = SSMR3GetMem(pSSM, ptl, sizeof(*ptl));
185 AssertRCReturn(rc, rc);
186 if (ptl->img)
187 {
188 CRASSERT(ptl->bytes);
189
190 ptl->img = crAlloc(ptl->bytes);
191 if (!ptl->img) return VERR_NO_MEMORY;
192
193 rc = SSMR3GetMem(pSSM, ptl->img, ptl->bytes);
194 AssertRCReturn(rc, rc);
195 }
196#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
197 /* Same story as in crStateSaveTextureObjData */
198 else if (ptl->bytes)
199 {
200 ptl->img = crAlloc(ptl->bytes);
201 if (!ptl->img) return VERR_NO_MEMORY;
202
203 rc = SSMR3GetMem(pSSM, ptl->img, ptl->bytes);
204 AssertRCReturn(rc, rc);
205 }
206#endif
207 crStateTextureInitTextureFormat(ptl, ptl->internalFormat);
208 }
209 }
210
211 return VINF_SUCCESS;
212}
213
214static void crStateSaveSharedTextureCB(unsigned long key, void *data1, void *data2)
215{
216 CRTextureObj *pTexture = (CRTextureObj *) data1;
217 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
218 int32_t rc;
219
220 CRASSERT(pTexture && pSSM);
221
222 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
223 CRASSERT(rc == VINF_SUCCESS);
224 rc = SSMR3PutMem(pSSM, pTexture, sizeof(*pTexture));
225 CRASSERT(rc == VINF_SUCCESS);
226 rc = crStateSaveTextureObjData(pTexture, pSSM);
227 CRASSERT(rc == VINF_SUCCESS);
228}
229
230static int32_t crStateSaveMatrixStack(CRMatrixStack *pStack, PSSMHANDLE pSSM)
231{
232 return SSMR3PutMem(pSSM, pStack->stack, sizeof(CRmatrix) * pStack->maxDepth);
233}
234
235static int32_t crStateLoadMatrixStack(CRMatrixStack *pStack, PSSMHANDLE pSSM)
236{
237 int32_t rc;
238
239 CRASSERT(pStack && pSSM);
240
241 rc = SSMR3GetMem(pSSM, pStack->stack, sizeof(CRmatrix) * pStack->maxDepth);
242 /* fixup stack top pointer */
243 pStack->top = &pStack->stack[pStack->depth];
244 return rc;
245}
246
247static int32_t crStateSaveTextureObjPtr(CRTextureObj *pTexture, PSSMHANDLE pSSM)
248{
249 /* Current texture pointer can't be NULL for real texture unit states,
250 * but it could be NULL for unused attribute stack depths.
251 */
252 if (pTexture)
253 return SSMR3PutU32(pSSM, pTexture->id);
254 else
255 return VINF_SUCCESS;
256}
257
258static int32_t crStateLoadTextureObjPtr(CRTextureObj **pTexture, CRContext *pContext, GLenum target, PSSMHANDLE pSSM)
259{
260 uint32_t texName;
261 int32_t rc;
262
263 /* We're loading attrib stack with unused state */
264 if (!*pTexture)
265 return VINF_SUCCESS;
266
267 rc = SSMR3GetU32(pSSM, &texName);
268 AssertRCReturn(rc, rc);
269
270 if (texName)
271 {
272 *pTexture = (CRTextureObj *) crHashtableSearch(pContext->shared->textureTable, texName);
273 }
274 else
275 {
276 switch (target)
277 {
278 case GL_TEXTURE_1D:
279 *pTexture = &(pContext->texture.base1D);
280 break;
281 case GL_TEXTURE_2D:
282 *pTexture = &(pContext->texture.base2D);
283 break;
284#ifdef CR_OPENGL_VERSION_1_2
285 case GL_TEXTURE_3D:
286 *pTexture = &(pContext->texture.base3D);
287 break;
288#endif
289#ifdef CR_ARB_texture_cube_map
290 case GL_TEXTURE_CUBE_MAP_ARB:
291 *pTexture = &(pContext->texture.baseCubeMap);
292 break;
293#endif
294#ifdef CR_NV_texture_rectangle
295 case GL_TEXTURE_RECTANGLE_NV:
296 *pTexture = &(pContext->texture.baseRect);
297 break;
298#endif
299 default:
300 crError("LoadTextureObjPtr: Unknown texture target %d", target);
301 }
302 }
303
304 return rc;
305}
306
307static int32_t crStateSaveTexUnitCurrentTexturePtrs(CRTextureUnit *pTexUnit, PSSMHANDLE pSSM)
308{
309 int32_t rc;
310
311 rc = crStateSaveTextureObjPtr(pTexUnit->currentTexture1D, pSSM);
312 AssertRCReturn(rc, rc);
313 rc = crStateSaveTextureObjPtr(pTexUnit->currentTexture2D, pSSM);
314 AssertRCReturn(rc, rc);
315 rc = crStateSaveTextureObjPtr(pTexUnit->currentTexture3D, pSSM);
316 AssertRCReturn(rc, rc);
317#ifdef CR_ARB_texture_cube_map
318 rc = crStateSaveTextureObjPtr(pTexUnit->currentTextureCubeMap, pSSM);
319 AssertRCReturn(rc, rc);
320#endif
321#ifdef CR_NV_texture_rectangle
322 rc = crStateSaveTextureObjPtr(pTexUnit->currentTextureRect, pSSM);
323 AssertRCReturn(rc, rc);
324#endif
325
326 return rc;
327}
328
329static int32_t crStateLoadTexUnitCurrentTexturePtrs(CRTextureUnit *pTexUnit, CRContext *pContext, PSSMHANDLE pSSM)
330{
331 int32_t rc;
332
333 rc = crStateLoadTextureObjPtr(&pTexUnit->currentTexture1D, pContext, GL_TEXTURE_1D, pSSM);
334 AssertRCReturn(rc, rc);
335 rc = crStateLoadTextureObjPtr(&pTexUnit->currentTexture2D, pContext, GL_TEXTURE_1D, pSSM);
336 AssertRCReturn(rc, rc);
337 rc = crStateLoadTextureObjPtr(&pTexUnit->currentTexture3D, pContext, GL_TEXTURE_2D, pSSM);
338 AssertRCReturn(rc, rc);
339#ifdef CR_ARB_texture_cube_map
340 rc = crStateLoadTextureObjPtr(&pTexUnit->currentTextureCubeMap, pContext, GL_TEXTURE_CUBE_MAP_ARB, pSSM);
341 AssertRCReturn(rc, rc);
342#endif
343#ifdef CR_NV_texture_rectangle
344 rc = crStateLoadTextureObjPtr(&pTexUnit->currentTextureRect, pContext, GL_TEXTURE_RECTANGLE_NV, pSSM);
345 AssertRCReturn(rc, rc);
346#endif
347
348 return rc;
349}
350
351static int32_t crSateSaveEvalCoeffs1D(CREvaluator1D *pEval, PSSMHANDLE pSSM)
352{
353 int32_t rc, i;
354
355 for (i=0; i<GLEVAL_TOT; ++i)
356 {
357 if (pEval[i].coeff)
358 {
359 rc = SSMR3PutMem(pSSM, pEval[i].coeff, pEval[i].order * gleval_sizes[i] * sizeof(GLfloat));
360 AssertRCReturn(rc, rc);
361 }
362 }
363
364 return VINF_SUCCESS;
365}
366
367static int32_t crSateSaveEvalCoeffs2D(CREvaluator2D *pEval, PSSMHANDLE pSSM)
368{
369 int32_t rc, i;
370
371 for (i=0; i<GLEVAL_TOT; ++i)
372 {
373 if (pEval[i].coeff)
374 {
375 rc = SSMR3PutMem(pSSM, pEval[i].coeff, pEval[i].uorder * pEval[i].vorder * gleval_sizes[i] * sizeof(GLfloat));
376 AssertRCReturn(rc, rc);
377 }
378 }
379
380 return VINF_SUCCESS;
381}
382
383static int32_t crSateLoadEvalCoeffs1D(CREvaluator1D *pEval, GLboolean bReallocMem, PSSMHANDLE pSSM)
384{
385 int32_t rc, i;
386 size_t size;
387
388 for (i=0; i<GLEVAL_TOT; ++i)
389 {
390 if (pEval[i].coeff)
391 {
392 size = pEval[i].order * gleval_sizes[i] * sizeof(GLfloat);
393 if (bReallocMem)
394 {
395 pEval[i].coeff = (GLfloat*) crAlloc(size);
396 if (!pEval[i].coeff) return VERR_NO_MEMORY;
397 }
398 rc = SSMR3GetMem(pSSM, pEval[i].coeff, size);
399 AssertRCReturn(rc, rc);
400 }
401 }
402
403 return VINF_SUCCESS;
404}
405
406static int32_t crSateLoadEvalCoeffs2D(CREvaluator2D *pEval, GLboolean bReallocMem, PSSMHANDLE pSSM)
407{
408 int32_t rc, i;
409 size_t size;
410
411 for (i=0; i<GLEVAL_TOT; ++i)
412 {
413 if (pEval[i].coeff)
414 {
415 size = pEval[i].uorder * pEval[i].vorder * gleval_sizes[i] * sizeof(GLfloat);
416 if (bReallocMem)
417 {
418 pEval[i].coeff = (GLfloat*) crAlloc(size);
419 if (!pEval[i].coeff) return VERR_NO_MEMORY;
420 }
421 rc = SSMR3GetMem(pSSM, pEval[i].coeff, size);
422 AssertRCReturn(rc, rc);
423 }
424 }
425
426 return VINF_SUCCESS;
427}
428
429static void crStateCopyEvalPtrs1D(CREvaluator1D *pDst, CREvaluator1D *pSrc)
430{
431 int32_t i;
432
433 for (i=0; i<GLEVAL_TOT; ++i)
434 pDst[i].coeff = pSrc[i].coeff;
435
436 /*
437 pDst[GL_MAP1_VERTEX_3-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_VERTEX_3-GL_MAP1_COLOR_4].coeff;
438 pDst[GL_MAP1_VERTEX_4-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_VERTEX_4-GL_MAP1_COLOR_4].coeff;
439 pDst[GL_MAP1_INDEX-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_INDEX-GL_MAP1_COLOR_4].coeff;
440 pDst[GL_MAP1_COLOR_4-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_COLOR_4-GL_MAP1_COLOR_4].coeff;
441 pDst[GL_MAP1_NORMAL-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_NORMAL-GL_MAP1_COLOR_4].coeff;
442 pDst[GL_MAP1_TEXTURE_COORD_1-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_TEXTURE_COORD_1-GL_MAP1_COLOR_4].coeff;
443 pDst[GL_MAP1_TEXTURE_COORD_2-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_TEXTURE_COORD_2-GL_MAP1_COLOR_4].coeff;
444 pDst[GL_MAP1_TEXTURE_COORD_3-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_TEXTURE_COORD_3-GL_MAP1_COLOR_4].coeff;
445 pDst[GL_MAP1_TEXTURE_COORD_4-GL_MAP1_COLOR_4].coeff = pSrc[GL_MAP1_TEXTURE_COORD_4-GL_MAP1_COLOR_4].coeff;
446 */
447}
448
449static void crStateCopyEvalPtrs2D(CREvaluator2D *pDst, CREvaluator2D *pSrc)
450{
451 int32_t i;
452
453 for (i=0; i<GLEVAL_TOT; ++i)
454 pDst[i].coeff = pSrc[i].coeff;
455
456 /*
457 pDst[GL_MAP2_VERTEX_3-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_VERTEX_3-GL_MAP2_COLOR_4].coeff;
458 pDst[GL_MAP2_VERTEX_4-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_VERTEX_4-GL_MAP2_COLOR_4].coeff;
459 pDst[GL_MAP2_INDEX-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_INDEX-GL_MAP2_COLOR_4].coeff;
460 pDst[GL_MAP2_COLOR_4-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_COLOR_4-GL_MAP2_COLOR_4].coeff;
461 pDst[GL_MAP2_NORMAL-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_NORMAL-GL_MAP2_COLOR_4].coeff;
462 pDst[GL_MAP2_TEXTURE_COORD_1-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_TEXTURE_COORD_1-GL_MAP2_COLOR_4].coeff;
463 pDst[GL_MAP2_TEXTURE_COORD_2-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_TEXTURE_COORD_2-GL_MAP2_COLOR_4].coeff;
464 pDst[GL_MAP2_TEXTURE_COORD_3-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_TEXTURE_COORD_3-GL_MAP2_COLOR_4].coeff;
465 pDst[GL_MAP2_TEXTURE_COORD_4-GL_MAP2_COLOR_4].coeff = pSrc[GL_MAP2_TEXTURE_COORD_4-GL_MAP2_COLOR_4].coeff;
466 */
467}
468
469static void crStateSaveBufferObjectCB(unsigned long key, void *data1, void *data2)
470{
471 CRBufferObject *pBufferObj = (CRBufferObject *) data1;
472 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
473 int32_t rc;
474
475 CRASSERT(pBufferObj && pSSM);
476
477 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
478 CRASSERT(rc == VINF_SUCCESS);
479 rc = SSMR3PutMem(pSSM, pBufferObj, sizeof(*pBufferObj));
480 CRASSERT(rc == VINF_SUCCESS);
481
482 if (pBufferObj->data)
483 {
484 /*We could get here even though retainBufferData is false on host side, in case when we're taking snapshot
485 after state load and before this context was ever made current*/
486 CRASSERT(pBufferObj->size>0);
487 rc = SSMR3PutMem(pSSM, pBufferObj->data, pBufferObj->size);
488 CRASSERT(rc == VINF_SUCCESS);
489 }
490 else if (pBufferObj->id!=0 && pBufferObj->size>0)
491 {
492 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->hwid);
493 pBufferObj->pointer = diff_api.MapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB);
494 rc = SSMR3PutMem(pSSM, &pBufferObj->pointer, sizeof(pBufferObj->pointer));
495 CRASSERT(rc == VINF_SUCCESS);
496 if (pBufferObj->pointer)
497 {
498 rc = SSMR3PutMem(pSSM, pBufferObj->pointer, pBufferObj->size);
499 CRASSERT(rc == VINF_SUCCESS);
500 }
501 diff_api.UnmapBufferARB(GL_ARRAY_BUFFER_ARB);
502 pBufferObj->pointer = NULL;
503 }
504}
505
506static void crStateSaveProgramCB(unsigned long key, void *data1, void *data2)
507{
508 CRProgram *pProgram = (CRProgram *) data1;
509 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
510 CRProgramSymbol *pSymbol;
511 int32_t rc;
512
513 CRASSERT(pProgram && pSSM);
514
515 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
516 CRASSERT(rc == VINF_SUCCESS);
517 rc = SSMR3PutMem(pSSM, pProgram, sizeof(*pProgram));
518 CRASSERT(rc == VINF_SUCCESS);
519 if (pProgram->string)
520 {
521 CRASSERT(pProgram->length);
522 rc = SSMR3PutMem(pSSM, pProgram->string, pProgram->length);
523 CRASSERT(rc == VINF_SUCCESS);
524 }
525
526 for (pSymbol = pProgram->symbolTable; pSymbol; pSymbol=pSymbol->next)
527 {
528 rc = SSMR3PutMem(pSSM, pSymbol, sizeof(*pSymbol));
529 CRASSERT(rc == VINF_SUCCESS);
530 if (pSymbol->name)
531 {
532 CRASSERT(pSymbol->cbName>0);
533 rc = SSMR3PutMem(pSSM, pSymbol->name, pSymbol->cbName);
534 CRASSERT(rc == VINF_SUCCESS);
535 }
536 }
537}
538
539static void crStateSaveFramebuffersCB(unsigned long key, void *data1, void *data2)
540{
541 CRFramebufferObject *pFBO = (CRFramebufferObject*) data1;
542 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
543 int32_t rc;
544
545 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
546 CRASSERT(rc == VINF_SUCCESS);
547
548 rc = SSMR3PutMem(pSSM, pFBO, sizeof(*pFBO));
549 CRASSERT(rc == VINF_SUCCESS);
550}
551
552static void crStateSaveRenderbuffersCB(unsigned long key, void *data1, void *data2)
553{
554 CRRenderbufferObject *pRBO = (CRRenderbufferObject*) data1;
555 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
556 int32_t rc;
557
558 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
559 CRASSERT(rc == VINF_SUCCESS);
560
561 rc = SSMR3PutMem(pSSM, pRBO, sizeof(*pRBO));
562 CRASSERT(rc == VINF_SUCCESS);
563}
564
565static int32_t crStateLoadProgram(CRProgram **ppProgram, PSSMHANDLE pSSM)
566{
567 CRProgramSymbol **ppSymbol;
568 int32_t rc;
569 unsigned long key;
570
571 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
572 AssertRCReturn(rc, rc);
573
574 /* we're loading default vertex or pixel program*/
575 if (*ppProgram)
576 {
577 if (key!=0) return VERR_SSM_UNEXPECTED_DATA;
578 }
579 else
580 {
581 *ppProgram = (CRProgram*) crAlloc(sizeof(CRProgram));
582 if (!ppProgram) return VERR_NO_MEMORY;
583 if (key==0) return VERR_SSM_UNEXPECTED_DATA;
584 }
585
586 rc = SSMR3GetMem(pSSM, *ppProgram, sizeof(**ppProgram));
587 AssertRCReturn(rc, rc);
588
589 if ((*ppProgram)->string)
590 {
591 CRASSERT((*ppProgram)->length);
592 (*ppProgram)->string = crAlloc((*ppProgram)->length);
593 if (!(*ppProgram)->string) return VERR_NO_MEMORY;
594 rc = SSMR3GetMem(pSSM, (void*) (*ppProgram)->string, (*ppProgram)->length);
595 AssertRCReturn(rc, rc);
596 }
597
598 for (ppSymbol = &(*ppProgram)->symbolTable; *ppSymbol; ppSymbol=&(*ppSymbol)->next)
599 {
600 *ppSymbol = crAlloc(sizeof(CRProgramSymbol));
601 if (!ppSymbol) return VERR_NO_MEMORY;
602
603 rc = SSMR3GetMem(pSSM, *ppSymbol, sizeof(**ppSymbol));
604 AssertRCReturn(rc, rc);
605
606 if ((*ppSymbol)->name)
607 {
608 CRASSERT((*ppSymbol)->cbName>0);
609 (*ppSymbol)->name = crAlloc((*ppSymbol)->cbName);
610 if (!(*ppSymbol)->name) return VERR_NO_MEMORY;
611
612 rc = SSMR3GetMem(pSSM, (void*) (*ppSymbol)->name, (*ppSymbol)->cbName);
613 AssertRCReturn(rc, rc);
614 }
615 }
616
617 return VINF_SUCCESS;
618}
619
620static void crStateSaveString(const char *pStr, PSSMHANDLE pSSM)
621{
622 int32_t len;
623 int32_t rc;
624
625 if (pStr)
626 {
627 len = crStrlen(pStr)+1;
628
629 rc = SSMR3PutS32(pSSM, len);
630 CRASSERT(rc == VINF_SUCCESS);
631
632 rc = SSMR3PutMem(pSSM, pStr, len*sizeof(*pStr));
633 CRASSERT(rc == VINF_SUCCESS);
634 }
635 else
636 {
637 rc = SSMR3PutS32(pSSM, 0);
638 CRASSERT(rc == VINF_SUCCESS);
639 }
640}
641
642static char* crStateLoadString(PSSMHANDLE pSSM)
643{
644 int32_t len, rc;
645 char* pStr = NULL;
646
647 rc = SSMR3GetS32(pSSM, &len);
648 CRASSERT(rc == VINF_SUCCESS);
649
650 if (len!=0)
651 {
652 pStr = crAlloc(len*sizeof(*pStr));
653
654 rc = SSMR3GetMem(pSSM, pStr, len*sizeof(*pStr));
655 CRASSERT(rc == VINF_SUCCESS);
656 }
657
658 return pStr;
659}
660
661static void crStateSaveGLSLShaderCB(unsigned long key, void *data1, void *data2)
662{
663 CRGLSLShader *pShader = (CRGLSLShader*) data1;
664 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
665 int32_t rc;
666
667 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
668 CRASSERT(rc == VINF_SUCCESS);
669
670 rc = SSMR3PutMem(pSSM, pShader, sizeof(*pShader));
671 CRASSERT(rc == VINF_SUCCESS);
672
673 if (pShader->source)
674 {
675 crStateSaveString(pShader->source, pSSM);
676 }
677 else
678 {
679 GLint sLen=0;
680 GLchar *source=NULL;
681
682 diff_api.GetShaderiv(pShader->hwid, GL_SHADER_SOURCE_LENGTH, &sLen);
683 if (sLen>0)
684 {
685 source = (GLchar*) crAlloc(sLen);
686 diff_api.GetShaderSource(pShader->hwid, sLen, NULL, source);
687 }
688
689 crStateSaveString(source, pSSM);
690 if (source) crFree(source);
691 }
692}
693
694static CRGLSLShader* crStateLoadGLSLShader(PSSMHANDLE pSSM)
695{
696 CRGLSLShader *pShader;
697 int32_t rc;
698 unsigned long key;
699
700 pShader = crAlloc(sizeof(*pShader));
701 if (!pShader) return NULL;
702
703 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
704 CRASSERT(rc == VINF_SUCCESS);
705
706 rc = SSMR3GetMem(pSSM, pShader, sizeof(*pShader));
707 CRASSERT(rc == VINF_SUCCESS);
708
709 pShader->source = crStateLoadString(pSSM);
710
711 return pShader;
712}
713
714
715static void crStateSaveGLSLShaderKeyCB(unsigned long key, void *data1, void *data2)
716{
717 CRGLSLShader *pShader = (CRGLSLShader*) data1;
718 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
719 int32_t rc;
720
721 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
722 CRASSERT(rc == VINF_SUCCESS);
723}
724
725static void crStateSaveGLSLProgramAttribs(CRGLSLProgramState *pState, PSSMHANDLE pSSM)
726{
727 GLuint i;
728 int32_t rc;
729
730 for (i=0; i<pState->cAttribs; ++i)
731 {
732 rc = SSMR3PutMem(pSSM, &pState->pAttribs[i].index, sizeof(pState->pAttribs[i].index));
733 CRASSERT(rc == VINF_SUCCESS);
734 crStateSaveString(pState->pAttribs[i].name, pSSM);
735 }
736}
737
738static void crStateSaveGLSLProgramCB(unsigned long key, void *data1, void *data2)
739{
740 CRGLSLProgram *pProgram = (CRGLSLProgram*) data1;
741 PSSMHANDLE pSSM = (PSSMHANDLE) data2;
742 int32_t rc;
743 uint32_t ui32;
744 GLint maxUniformLen, activeUniforms=0, uniformsCount=0, i, j;
745 GLchar *name = NULL;
746 GLenum type;
747 GLint size, location;
748
749 rc = SSMR3PutMem(pSSM, &key, sizeof(key));
750 CRASSERT(rc == VINF_SUCCESS);
751
752 rc = SSMR3PutMem(pSSM, pProgram, sizeof(*pProgram));
753 CRASSERT(rc == VINF_SUCCESS);
754
755 ui32 = crHashtableNumElements(pProgram->currentState.attachedShaders);
756 rc = SSMR3PutU32(pSSM, ui32);
757 CRASSERT(rc == VINF_SUCCESS);
758
759 crHashtableWalk(pProgram->currentState.attachedShaders, crStateSaveGLSLShaderKeyCB, pSSM);
760
761 if (pProgram->activeState.attachedShaders)
762 {
763 ui32 = crHashtableNumElements(pProgram->activeState.attachedShaders);
764 rc = SSMR3PutU32(pSSM, ui32);
765 CRASSERT(rc == VINF_SUCCESS);
766 crHashtableWalk(pProgram->currentState.attachedShaders, crStateSaveGLSLShaderCB, pSSM);
767 }
768
769 crStateSaveGLSLProgramAttribs(&pProgram->currentState, pSSM);
770 crStateSaveGLSLProgramAttribs(&pProgram->activeState, pSSM);
771
772 diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
773 diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);
774
775 if (activeUniforms>0)
776 {
777 name = (GLchar *) crAlloc((maxUniformLen+8)*sizeof(GLchar));
778
779 if (!name)
780 {
781 crWarning("crStateSaveGLSLProgramCB: out of memory");
782 return;
783 }
784 }
785
786 for (i=0; i<activeUniforms; ++i)
787 {
788 diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
789 uniformsCount += size;
790 }
791 CRASSERT(uniformsCount>=activeUniforms);
792
793 rc = SSMR3PutS32(pSSM, uniformsCount);
794 CRASSERT(rc == VINF_SUCCESS);
795
796 if (activeUniforms>0)
797 {
798 GLfloat fdata[16];
799 GLint idata[16];
800 char *pIndexStr=NULL;
801
802 for (i=0; i<activeUniforms; ++i)
803 {
804 diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
805
806 if (size>1)
807 {
808 pIndexStr = crStrchr(name, '[');
809 if (!pIndexStr)
810 {
811 pIndexStr = name+crStrlen(name);
812 }
813 }
814
815 for (j=0; j<size; ++j)
816 {
817 if (size>1)
818 {
819 sprintf(pIndexStr, "[%i]", j);
820 }
821 location = diff_api.GetUniformLocation(pProgram->hwid, name);
822
823 rc = SSMR3PutMem(pSSM, &type, sizeof(type));
824 CRASSERT(rc == VINF_SUCCESS);
825
826 crStateSaveString(name, pSSM);
827
828 if (crStateIsIntUniform(type))
829 {
830 diff_api.GetUniformiv(pProgram->hwid, location, &idata[0]);
831 rc = SSMR3PutMem(pSSM, &idata[0], crStateGetUniformSize(type)*sizeof(idata[0]));
832 CRASSERT(rc == VINF_SUCCESS);
833 }
834 else
835 {
836 diff_api.GetUniformfv(pProgram->hwid, location, &fdata[0]);
837 rc = SSMR3PutMem(pSSM, &fdata[0], crStateGetUniformSize(type)*sizeof(fdata[0]));
838 CRASSERT(rc == VINF_SUCCESS);
839 }
840 }
841 }
842
843 crFree(name);
844 }
845}
846
847static int32_t crStateSaveClientPointer(CRVertexArrays *pArrays, int32_t index, PSSMHANDLE pSSM)
848{
849 int32_t rc;
850 CRClientPointer *cp;
851
852 cp = crStateGetClientPointerByIndex(index, pArrays);
853
854 rc = SSMR3PutU32(pSSM, cp->buffer->id);
855 AssertRCReturn(rc, rc);
856
857#ifdef CR_EXT_compiled_vertex_array
858 if (cp->locked)
859 {
860 CRASSERT(cp->p);
861 rc = SSMR3PutMem(pSSM, cp->p, cp->stride*(pArrays->lockFirst+pArrays->lockCount));
862 AssertRCReturn(rc, rc);
863 }
864#endif
865
866 return VINF_SUCCESS;
867}
868
869static int32_t crStateLoadClientPointer(CRVertexArrays *pArrays, int32_t index, CRContext *pContext, PSSMHANDLE pSSM)
870{
871 int32_t rc;
872 uint32_t ui;
873 CRClientPointer *cp;
874
875 cp = crStateGetClientPointerByIndex(index, pArrays);
876
877 rc = SSMR3GetU32(pSSM, &ui);
878 AssertRCReturn(rc, rc);
879 cp->buffer = ui==0 ? pContext->bufferobject.nullBuffer : crHashtableSearch(pContext->shared->buffersTable, ui);
880
881#ifdef CR_EXT_compiled_vertex_array
882 if (cp->locked)
883 {
884 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&cp->p, cp->stride*(pArrays->lockFirst+pArrays->lockCount));
885 AssertRCReturn(rc, rc);
886 }
887#endif
888
889 return VINF_SUCCESS;
890}
891
892static int32_t crStateSaveCurrentBits(CRStateBits *pBits, PSSMHANDLE pSSM)
893{
894 int32_t rc, i;
895
896 rc = SSMR3PutMem(pSSM, pBits, sizeof(*pBits));
897 AssertRCReturn(rc, rc);
898
899 rc = SSMR3PutMem(pSSM, pBits->client.v, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
900 AssertRCReturn(rc, rc);
901 rc = SSMR3PutMem(pSSM, pBits->client.n, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
902 AssertRCReturn(rc, rc);
903 rc = SSMR3PutMem(pSSM, pBits->client.c, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
904 AssertRCReturn(rc, rc);
905 rc = SSMR3PutMem(pSSM, pBits->client.s, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
906 AssertRCReturn(rc, rc);
907 rc = SSMR3PutMem(pSSM, pBits->client.i, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
908 AssertRCReturn(rc, rc);
909 for (i=0; i<CR_MAX_TEXTURE_UNITS; i++)
910 {
911 rc = SSMR3PutMem(pSSM, pBits->client.t[i], GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
912 AssertRCReturn(rc, rc);
913 }
914 rc = SSMR3PutMem(pSSM, pBits->client.e, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
915 AssertRCReturn(rc, rc);
916 rc = SSMR3PutMem(pSSM, pBits->client.f, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
917 AssertRCReturn(rc, rc);
918#ifdef CR_NV_vertex_program
919 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
920 {
921 rc = SSMR3PutMem(pSSM, pBits->client.a[i], GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
922 AssertRCReturn(rc, rc);
923 }
924#endif
925
926 rc = SSMR3PutMem(pSSM, pBits->lighting.light, CR_MAX_LIGHTS*sizeof(pBits->lighting.light));
927 AssertRCReturn(rc, rc);
928
929 return VINF_SUCCESS;
930}
931
932static int32_t crStateLoadCurrentBits(CRStateBits *pBits, PSSMHANDLE pSSM)
933{
934 int32_t rc, i;
935 CRClientBits client;
936 CRLightingBits lighting;
937
938 CRASSERT(pBits);
939
940 client.v = pBits->client.v;
941 client.n = pBits->client.n;
942 client.c = pBits->client.c;
943 client.s = pBits->client.s;
944 client.i = pBits->client.i;
945 client.e = pBits->client.e;
946 client.f = pBits->client.f;
947 for (i=0; i<CR_MAX_TEXTURE_UNITS; i++)
948 {
949 client.t[i] = pBits->client.t[i];
950 }
951#ifdef CR_NV_vertex_program
952 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
953 {
954 client.a[i] = pBits->client.a[i];
955 }
956#endif
957 lighting.light = pBits->lighting.light;
958
959 rc = SSMR3GetMem(pSSM, pBits, sizeof(*pBits));
960 AssertRCReturn(rc, rc);
961
962 pBits->client.v = client.v;
963 rc = SSMR3GetMem(pSSM, pBits->client.v, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
964 AssertRCReturn(rc, rc);
965 pBits->client.n = client.n;
966 rc = SSMR3GetMem(pSSM, pBits->client.n, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
967 AssertRCReturn(rc, rc);
968 pBits->client.c = client.c;
969 rc = SSMR3GetMem(pSSM, pBits->client.c, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
970 AssertRCReturn(rc, rc);
971 pBits->client.s = client.s;
972 rc = SSMR3GetMem(pSSM, pBits->client.s, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
973 AssertRCReturn(rc, rc);
974 pBits->client.i = client.i;
975 rc = SSMR3GetMem(pSSM, pBits->client.i, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
976 AssertRCReturn(rc, rc);
977 pBits->client.e = client.e;
978 rc = SSMR3GetMem(pSSM, pBits->client.e, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
979 AssertRCReturn(rc, rc);
980 pBits->client.f = client.f;
981 rc = SSMR3GetMem(pSSM, pBits->client.f, GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
982 AssertRCReturn(rc, rc);
983 for (i=0; i<CR_MAX_TEXTURE_UNITS; i++)
984 {
985 pBits->client.t[i] = client.t[i];
986 rc = SSMR3GetMem(pSSM, pBits->client.t[i], GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
987 AssertRCReturn(rc, rc);
988 }
989#ifdef CR_NV_vertex_program
990 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
991 {
992 pBits->client.a[i] = client.a[i];
993 rc = SSMR3GetMem(pSSM, pBits->client.a[i], GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
994 AssertRCReturn(rc, rc);
995 }
996#endif
997
998 pBits->lighting.light = lighting.light;
999 rc = SSMR3GetMem(pSSM, pBits->lighting.light, CR_MAX_LIGHTS*sizeof(pBits->lighting.light));
1000 AssertRCReturn(rc, rc);
1001
1002 return VINF_SUCCESS;
1003}
1004
1005int32_t crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM)
1006{
1007 int32_t rc, i;
1008 uint32_t ui32, j;
1009 GLboolean bSaveShared = GL_TRUE;
1010
1011 CRASSERT(pContext && pSSM);
1012
1013 rc = SSMR3PutMem(pSSM, pContext, sizeof(*pContext));
1014 AssertRCReturn(rc, rc);
1015
1016 if (crHashtableNumElements(pContext->shared->dlistTable)>0)
1017 crWarning("Saving state with %d display lists, unsupported", crHashtableNumElements(pContext->shared->dlistTable));
1018
1019 if (crHashtableNumElements(pContext->program.programHash)>0)
1020 crDebug("Saving state with %d programs", crHashtableNumElements(pContext->program.programHash));
1021
1022 rc = SSMR3PutS32(pSSM, pContext->shared->id);
1023 AssertRCReturn(rc, rc);
1024
1025 rc = SSMR3PutS32(pSSM, crStateContextIsShared(pContext));
1026 AssertRCReturn(rc, rc);
1027
1028 if (pContext->shared->refCount>1)
1029 {
1030 bSaveShared = pContext->shared->saveCount==0;
1031
1032 ++pContext->shared->saveCount;
1033 if (pContext->shared->saveCount == pContext->shared->refCount)
1034 {
1035 pContext->shared->saveCount=0;
1036 }
1037 }
1038
1039 /* Save transform state */
1040 rc = SSMR3PutMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
1041 AssertRCReturn(rc, rc);
1042 rc = SSMR3PutMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
1043 AssertRCReturn(rc, rc);
1044 rc = crStateSaveMatrixStack(&pContext->transform.modelViewStack, pSSM);
1045 AssertRCReturn(rc, rc);
1046 rc = crStateSaveMatrixStack(&pContext->transform.projectionStack, pSSM);
1047 AssertRCReturn(rc, rc);
1048 rc = crStateSaveMatrixStack(&pContext->transform.colorStack, pSSM);
1049 AssertRCReturn(rc, rc);
1050 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1051 {
1052 rc = crStateSaveMatrixStack(&pContext->transform.textureStack[i], pSSM);
1053 AssertRCReturn(rc, rc);
1054 }
1055 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1056 {
1057 rc = crStateSaveMatrixStack(&pContext->transform.programStack[i], pSSM);
1058 AssertRCReturn(rc, rc);
1059 }
1060
1061 /* Save textures */
1062 rc = crStateSaveTextureObjData(&pContext->texture.base1D, pSSM);
1063 AssertRCReturn(rc, rc);
1064 rc = crStateSaveTextureObjData(&pContext->texture.base2D, pSSM);
1065 AssertRCReturn(rc, rc);
1066 rc = crStateSaveTextureObjData(&pContext->texture.base3D, pSSM);
1067 AssertRCReturn(rc, rc);
1068 rc = crStateSaveTextureObjData(&pContext->texture.proxy1D, pSSM);
1069 AssertRCReturn(rc, rc);
1070 rc = crStateSaveTextureObjData(&pContext->texture.proxy2D, pSSM);
1071 AssertRCReturn(rc, rc);
1072 rc = crStateSaveTextureObjData(&pContext->texture.proxy3D, pSSM);
1073#ifdef CR_ARB_texture_cube_map
1074 rc = crStateSaveTextureObjData(&pContext->texture.baseCubeMap, pSSM);
1075 AssertRCReturn(rc, rc);
1076 rc = crStateSaveTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
1077 AssertRCReturn(rc, rc);
1078#endif
1079#ifdef CR_NV_texture_rectangle
1080 rc = crStateSaveTextureObjData(&pContext->texture.baseRect, pSSM);
1081 AssertRCReturn(rc, rc);
1082 rc = crStateSaveTextureObjData(&pContext->texture.proxyRect, pSSM);
1083 AssertRCReturn(rc, rc);
1084#endif
1085
1086 /* Save shared textures */
1087 if (bSaveShared)
1088 {
1089 CRASSERT(pContext->shared && pContext->shared->textureTable);
1090 ui32 = crHashtableNumElements(pContext->shared->textureTable);
1091 rc = SSMR3PutU32(pSSM, ui32);
1092 AssertRCReturn(rc, rc);
1093 crHashtableWalk(pContext->shared->textureTable, crStateSaveSharedTextureCB, pSSM);
1094
1095#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
1096 /* Restore previous texture bindings via diff_api */
1097 if (ui32)
1098 {
1099 CRTextureUnit *pTexUnit;
1100
1101 pTexUnit = &pContext->texture.unit[pContext->texture.curTextureUnit];
1102
1103 diff_api.BindTexture(GL_TEXTURE_1D, pTexUnit->currentTexture1D->hwid);
1104 diff_api.BindTexture(GL_TEXTURE_2D, pTexUnit->currentTexture2D->hwid);
1105 diff_api.BindTexture(GL_TEXTURE_3D, pTexUnit->currentTexture3D->hwid);
1106#ifdef CR_ARB_texture_cube_map
1107 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, pTexUnit->currentTextureCubeMap->hwid);
1108#endif
1109#ifdef CR_NV_texture_rectangle
1110 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, pTexUnit->currentTextureRect->hwid);
1111#endif
1112 }
1113#endif
1114 }
1115
1116 /* Save current texture pointers */
1117 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
1118 {
1119 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pSSM);
1120 AssertRCReturn(rc, rc);
1121 }
1122
1123 /* Save lights */
1124 CRASSERT(pContext->lighting.light);
1125 rc = SSMR3PutMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
1126 AssertRCReturn(rc, rc);
1127
1128 /* Save attrib stack*/
1129 /*@todo could go up to used stack depth here?*/
1130 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1131 {
1132 if (pContext->attrib.enableStack[i].clip)
1133 {
1134 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].clip,
1135 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1136 AssertRCReturn(rc, rc);
1137 }
1138
1139 if (pContext->attrib.enableStack[i].light)
1140 {
1141 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].light,
1142 pContext->limits.maxLights*sizeof(GLboolean));
1143 AssertRCReturn(rc, rc);
1144 }
1145
1146 if (pContext->attrib.lightingStack[i].light)
1147 {
1148 rc = SSMR3PutMem(pSSM, pContext->attrib.lightingStack[i].light,
1149 pContext->limits.maxLights*sizeof(CRLight));
1150 AssertRCReturn(rc, rc);
1151 }
1152
1153 for (j=0; j<pContext->limits.maxTextureUnits; ++j)
1154 {
1155 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[j], pSSM);
1156 AssertRCReturn(rc, rc);
1157 }
1158
1159 if (pContext->attrib.transformStack[i].clip)
1160 {
1161 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clip,
1162 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1163 AssertRCReturn(rc, rc);
1164 }
1165
1166 if (pContext->attrib.transformStack[i].clipPlane)
1167 {
1168 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clipPlane,
1169 pContext->limits.maxClipPlanes*sizeof(GLvectord));
1170 AssertRCReturn(rc, rc);
1171 }
1172
1173 rc = crSateSaveEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, pSSM);
1174 AssertRCReturn(rc, rc);
1175 rc = crSateSaveEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, pSSM);
1176 AssertRCReturn(rc, rc);
1177 }
1178
1179 /* Save evaluator coeffs */
1180 rc = crSateSaveEvalCoeffs1D(pContext->eval.eval1D, pSSM);
1181 AssertRCReturn(rc, rc);
1182 rc = crSateSaveEvalCoeffs2D(pContext->eval.eval2D, pSSM);
1183 AssertRCReturn(rc, rc);
1184
1185#ifdef CR_ARB_vertex_buffer_object
1186 /* Save buffer objects */
1187 ui32 = bSaveShared? crHashtableNumElements(pContext->shared->buffersTable):0;
1188 rc = SSMR3PutU32(pSSM, ui32);
1189 AssertRCReturn(rc, rc);
1190
1191 /* Save default one*/
1192 crStateSaveBufferObjectCB(0, pContext->bufferobject.nullBuffer, pSSM);
1193
1194 if (bSaveShared)
1195 {
1196 /* Save all the rest */
1197 crHashtableWalk(pContext->shared->buffersTable, crStateSaveBufferObjectCB, pSSM);
1198 }
1199
1200 /* Restore binding */
1201 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->hwid);
1202
1203 /* Save pointers */
1204 rc = SSMR3PutU32(pSSM, pContext->bufferobject.arrayBuffer->id);
1205 AssertRCReturn(rc, rc);
1206 rc = SSMR3PutU32(pSSM, pContext->bufferobject.elementsBuffer->id);
1207 AssertRCReturn(rc, rc);
1208#ifdef CR_ARB_pixel_buffer_object
1209 rc = SSMR3PutU32(pSSM, pContext->bufferobject.packBuffer->id);
1210 AssertRCReturn(rc, rc);
1211 rc = SSMR3PutU32(pSSM, pContext->bufferobject.unpackBuffer->id);
1212 AssertRCReturn(rc, rc);
1213#endif
1214 /* Save clint pointers and buffer bindings*/
1215 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1216 {
1217 rc = crStateSaveClientPointer(&pContext->client.array, i, pSSM);
1218 AssertRCReturn(rc, rc);
1219 }
1220
1221 crDebug("client.vertexArrayStackDepth %i", pContext->client.vertexArrayStackDepth);
1222 for (i=0; i<pContext->client.vertexArrayStackDepth; ++i)
1223 {
1224 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[i];
1225 for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
1226 {
1227 rc = crStateSaveClientPointer(pArray, j, pSSM);
1228 AssertRCReturn(rc, rc);
1229 }
1230 }
1231#endif /*CR_ARB_vertex_buffer_object*/
1232
1233 /* Save pixel/vertex programs */
1234 ui32 = crHashtableNumElements(pContext->program.programHash);
1235 rc = SSMR3PutU32(pSSM, ui32);
1236 AssertRCReturn(rc, rc);
1237 /* Save defaults programs */
1238 crStateSaveProgramCB(0, pContext->program.defaultVertexProgram, pSSM);
1239 crStateSaveProgramCB(0, pContext->program.defaultFragmentProgram, pSSM);
1240 /* Save all the rest */
1241 crHashtableWalk(pContext->program.programHash, crStateSaveProgramCB, pSSM);
1242 /* Save Pointers */
1243 rc = SSMR3PutU32(pSSM, pContext->program.currentVertexProgram->id);
1244 AssertRCReturn(rc, rc);
1245 rc = SSMR3PutU32(pSSM, pContext->program.currentFragmentProgram->id);
1246 AssertRCReturn(rc, rc);
1247 /* This one is unused it seems*/
1248 CRASSERT(!pContext->program.errorString);
1249
1250#ifdef CR_EXT_framebuffer_object
1251 /* Save FBOs */
1252 if (bSaveShared)
1253 {
1254 ui32 = crHashtableNumElements(pContext->shared->fbTable);
1255 rc = SSMR3PutU32(pSSM, ui32);
1256 AssertRCReturn(rc, rc);
1257 crHashtableWalk(pContext->shared->fbTable, crStateSaveFramebuffersCB, pSSM);
1258 ui32 = crHashtableNumElements(pContext->shared->rbTable);
1259 rc = SSMR3PutU32(pSSM, ui32);
1260 AssertRCReturn(rc, rc);
1261 crHashtableWalk(pContext->shared->rbTable, crStateSaveRenderbuffersCB, pSSM);
1262 }
1263 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.drawFB?pContext->framebufferobject.drawFB->id:0);
1264 AssertRCReturn(rc, rc);
1265 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.readFB?pContext->framebufferobject.readFB->id:0);
1266 AssertRCReturn(rc, rc);
1267 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.renderbuffer?pContext->framebufferobject.renderbuffer->id:0);
1268 AssertRCReturn(rc, rc);
1269#endif
1270
1271#ifdef CR_OPENGL_VERSION_2_0
1272 /* Save GLSL related info */
1273 ui32 = crHashtableNumElements(pContext->glsl.shaders);
1274 rc = SSMR3PutU32(pSSM, ui32);
1275 AssertRCReturn(rc, rc);
1276 crHashtableWalk(pContext->glsl.shaders, crStateSaveGLSLShaderCB, pSSM);
1277 ui32 = crHashtableNumElements(pContext->glsl.programs);
1278 rc = SSMR3PutU32(pSSM, ui32);
1279 AssertRCReturn(rc, rc);
1280 crHashtableWalk(pContext->glsl.programs, crStateSaveGLSLProgramCB, pSSM);
1281 rc = SSMR3PutU32(pSSM, pContext->glsl.activeProgram?pContext->glsl.activeProgram->id:0);
1282 AssertRCReturn(rc, rc);
1283#endif
1284
1285 {
1286 CRViewportState *pVP = &pContext->viewport;
1287 CRPixelPackState packing = pContext->client.pack;
1288 GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
1289 void *pData = crAlloc(cbData);
1290
1291 if (!pData)
1292 {
1293 return VERR_NO_MEMORY;
1294 }
1295
1296 diff_api.PixelStorei(GL_PACK_SKIP_ROWS, 0);
1297 diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, 0);
1298 diff_api.PixelStorei(GL_PACK_ALIGNMENT, 1);
1299 diff_api.PixelStorei(GL_PACK_ROW_LENGTH, 0);
1300 diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
1301 diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, 0);
1302 diff_api.PixelStorei(GL_PACK_SWAP_BYTES, 0);
1303 diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
1304
1305 diff_api.ReadBuffer(GL_FRONT);
1306 diff_api.ReadPixels(0, 0, pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, pData);
1307
1308 diff_api.ReadBuffer(pContext->framebufferobject.readFB ?
1309 pContext->framebufferobject.readFB->readbuffer : pContext->buffer.readBuffer);
1310 diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
1311 diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
1312 diff_api.PixelStorei(GL_PACK_ALIGNMENT, packing.alignment);
1313 diff_api.PixelStorei(GL_PACK_ROW_LENGTH, packing.rowLength);
1314 diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, packing.imageHeight);
1315 diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, packing.skipImages);
1316 diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
1317 diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
1318
1319 rc = SSMR3PutMem(pSSM, pData, cbData);
1320 AssertRCReturn(rc, rc);
1321
1322 crFree(pData);
1323 }
1324
1325 return VINF_SUCCESS;
1326}
1327
1328typedef struct _crFindSharedCtxParms {
1329 CRContext *pSrcCtx, *pDstCtx;
1330} crFindSharedCtxParms_t;
1331
1332static void crStateFindSharedCB(unsigned long key, void *data1, void *data2)
1333{
1334 CRContext *pContext = (CRContext *) data1;
1335 crFindSharedCtxParms_t *pParms = (crFindSharedCtxParms_t *) data2;
1336 (void) key;
1337
1338 if (pContext!=pParms->pSrcCtx && pContext->shared->id==pParms->pSrcCtx->shared->id)
1339 {
1340 pParms->pDstCtx->shared = pContext->shared;
1341 }
1342}
1343
1344#define SLC_COPYPTR(ptr) pTmpContext->ptr = pContext->ptr
1345#define SLC_ASSSERT_NULL_PTR(ptr) CRASSERT(!pContext->ptr)
1346
1347int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PSSMHANDLE pSSM)
1348{
1349 CRContext* pTmpContext;
1350 int32_t rc, i, j;
1351 uint32_t uiNumElems, ui, k;
1352 unsigned long key;
1353 GLboolean bLoadShared = GL_TRUE;
1354
1355 CRASSERT(pContext && pSSM);
1356
1357 /* This one is rather big for stack allocation and causes macs to crash */
1358 pTmpContext = (CRContext*)crAlloc(sizeof(*pTmpContext));
1359 if (!pTmpContext)
1360 return VERR_NO_MEMORY;
1361
1362 rc = SSMR3GetMem(pSSM, pTmpContext, sizeof(*pTmpContext));
1363 AssertRCReturn(rc, rc);
1364
1365 /* Deal with shared state */
1366 {
1367 crFindSharedCtxParms_t parms;
1368 int32_t shared;
1369
1370 rc = SSMR3GetS32(pSSM, &pContext->shared->id);
1371 AssertRCReturn(rc, rc);
1372
1373 rc = SSMR3GetS32(pSSM, &shared);
1374 AssertRCReturn(rc, rc);
1375
1376 pTmpContext->shared = NULL;
1377 parms.pSrcCtx = pContext;
1378 parms.pDstCtx = pTmpContext;
1379 crHashtableWalk(pCtxTable, crStateFindSharedCB, &parms);
1380
1381 if (pTmpContext->shared)
1382 {
1383 CRASSERT(pContext->shared->refCount==1);
1384 bLoadShared = GL_FALSE;
1385 crStateFreeShared(pContext->shared);
1386 pContext->shared = NULL;
1387 pTmpContext->shared->refCount++;
1388 }
1389 else
1390 {
1391 SLC_COPYPTR(shared);
1392 }
1393
1394 if (bLoadShared && shared)
1395 {
1396 crStateSetSharedContext(pTmpContext);
1397 }
1398 }
1399
1400 SLC_COPYPTR(flush_func);
1401 SLC_COPYPTR(flush_arg);
1402
1403 /* We're supposed to be loading into an empty context, so those pointers should be NULL */
1404 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1405 {
1406 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].clip);
1407 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].light);
1408
1409 SLC_ASSSERT_NULL_PTR(attrib.lightingStack[i].light);
1410 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clip);
1411 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clipPlane);
1412
1413 for (j=0; j<GLEVAL_TOT; ++j)
1414 {
1415 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval1D[j].coeff);
1416 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval2D[j].coeff);
1417 }
1418 }
1419
1420#ifdef CR_ARB_vertex_buffer_object
1421 SLC_COPYPTR(bufferobject.nullBuffer);
1422#endif
1423
1424/*@todo, that should be removed probably as those should hold the offset values, so loading should be fine
1425 but better check*/
1426#if 0
1427#ifdef CR_EXT_compiled_vertex_array
1428 SLC_COPYPTR(client.array.v.prevPtr);
1429 SLC_COPYPTR(client.array.c.prevPtr);
1430 SLC_COPYPTR(client.array.f.prevPtr);
1431 SLC_COPYPTR(client.array.s.prevPtr);
1432 SLC_COPYPTR(client.array.e.prevPtr);
1433 SLC_COPYPTR(client.array.i.prevPtr);
1434 SLC_COPYPTR(client.array.n.prevPtr);
1435 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1436 {
1437 SLC_COPYPTR(client.array.t[i].prevPtr);
1438 }
1439
1440# ifdef CR_NV_vertex_program
1441 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1442 {
1443 SLC_COPYPTR(client.array.a[i].prevPtr);
1444 }
1445# endif
1446#endif
1447#endif
1448
1449#ifdef CR_ARB_vertex_buffer_object
1450 /*That just sets those pointers to NULL*/
1451 SLC_COPYPTR(client.array.v.buffer);
1452 SLC_COPYPTR(client.array.c.buffer);
1453 SLC_COPYPTR(client.array.f.buffer);
1454 SLC_COPYPTR(client.array.s.buffer);
1455 SLC_COPYPTR(client.array.e.buffer);
1456 SLC_COPYPTR(client.array.i.buffer);
1457 SLC_COPYPTR(client.array.n.buffer);
1458 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1459 {
1460 SLC_COPYPTR(client.array.t[i].buffer);
1461 }
1462# ifdef CR_NV_vertex_program
1463 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1464 {
1465 SLC_COPYPTR(client.array.a[i].buffer);
1466 }
1467# endif
1468#endif /*CR_ARB_vertex_buffer_object*/
1469
1470 /*@todo CR_NV_vertex_program*/
1471 crStateCopyEvalPtrs1D(pTmpContext->eval.eval1D, pContext->eval.eval1D);
1472 crStateCopyEvalPtrs2D(pTmpContext->eval.eval2D, pContext->eval.eval2D);
1473
1474 SLC_COPYPTR(feedback.buffer); /*@todo*/
1475 SLC_COPYPTR(selection.buffer); /*@todo*/
1476
1477 SLC_COPYPTR(lighting.light);
1478
1479 /*This one could be tricky if we're loading snapshot on host with different GPU*/
1480 SLC_COPYPTR(limits.extensions);
1481
1482#if CR_ARB_occlusion_query
1483 SLC_COPYPTR(occlusion.objects); /*@todo*/
1484#endif
1485
1486 SLC_COPYPTR(program.errorString);
1487 SLC_COPYPTR(program.programHash);
1488 SLC_COPYPTR(program.defaultVertexProgram);
1489 SLC_COPYPTR(program.defaultFragmentProgram);
1490
1491 /* Texture pointers */
1492 for (i=0; i<6; ++i)
1493 {
1494 SLC_COPYPTR(texture.base1D.level[i]);
1495 SLC_COPYPTR(texture.base2D.level[i]);
1496 SLC_COPYPTR(texture.base3D.level[i]);
1497 SLC_COPYPTR(texture.proxy1D.level[i]);
1498 SLC_COPYPTR(texture.proxy2D.level[i]);
1499 SLC_COPYPTR(texture.proxy3D.level[i]);
1500#ifdef CR_ARB_texture_cube_map
1501 SLC_COPYPTR(texture.baseCubeMap.level[i]);
1502 SLC_COPYPTR(texture.proxyCubeMap.level[i]);
1503#endif
1504#ifdef CR_NV_texture_rectangle
1505 SLC_COPYPTR(texture.baseRect.level[i]);
1506 SLC_COPYPTR(texture.proxyRect.level[i]);
1507#endif
1508 }
1509
1510 /* Load transform state */
1511 SLC_COPYPTR(transform.clipPlane);
1512 SLC_COPYPTR(transform.clip);
1513 /* Don't have to worry about pContext->transform.current as it'd be set in crStateSetCurrent call */
1514 /*SLC_COPYPTR(transform.currentStack);*/
1515 SLC_COPYPTR(transform.modelViewStack.stack);
1516 SLC_COPYPTR(transform.projectionStack.stack);
1517 SLC_COPYPTR(transform.colorStack.stack);
1518
1519 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1520 {
1521 SLC_COPYPTR(transform.textureStack[i].stack);
1522 }
1523 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1524 {
1525 SLC_COPYPTR(transform.programStack[i].stack);
1526 }
1527
1528#ifdef CR_OPENGL_VERSION_2_0
1529 SLC_COPYPTR(glsl.shaders);
1530 SLC_COPYPTR(glsl.programs);
1531#endif
1532
1533 /* Have to preserve original context id */
1534 CRASSERT(pTmpContext->id == pContext->id);
1535 /* Copy ordinary state to real context */
1536 crMemcpy(pContext, pTmpContext, sizeof(*pTmpContext));
1537 crFree(pTmpContext);
1538 pTmpContext = NULL;
1539
1540 /* Now deal with pointers */
1541
1542 /* Load transform state */
1543 rc = SSMR3GetMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
1544 AssertRCReturn(rc, rc);
1545 rc = SSMR3GetMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
1546 AssertRCReturn(rc, rc);
1547 rc = crStateLoadMatrixStack(&pContext->transform.modelViewStack, pSSM);
1548 AssertRCReturn(rc, rc);
1549 rc = crStateLoadMatrixStack(&pContext->transform.projectionStack, pSSM);
1550 AssertRCReturn(rc, rc);
1551 rc = crStateLoadMatrixStack(&pContext->transform.colorStack, pSSM);
1552 AssertRCReturn(rc, rc);
1553 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1554 {
1555 rc = crStateLoadMatrixStack(&pContext->transform.textureStack[i], pSSM);
1556 AssertRCReturn(rc, rc);
1557 }
1558 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1559 {
1560 rc = crStateLoadMatrixStack(&pContext->transform.programStack[i], pSSM);
1561 AssertRCReturn(rc, rc);
1562 }
1563
1564 /* Load Textures */
1565 rc = crStateLoadTextureObjData(&pContext->texture.base1D, pSSM);
1566 AssertRCReturn(rc, rc);
1567 rc = crStateLoadTextureObjData(&pContext->texture.base2D, pSSM);
1568 AssertRCReturn(rc, rc);
1569 rc = crStateLoadTextureObjData(&pContext->texture.base3D, pSSM);
1570 AssertRCReturn(rc, rc);
1571 rc = crStateLoadTextureObjData(&pContext->texture.proxy1D, pSSM);
1572 AssertRCReturn(rc, rc);
1573 rc = crStateLoadTextureObjData(&pContext->texture.proxy2D, pSSM);
1574 AssertRCReturn(rc, rc);
1575 rc = crStateLoadTextureObjData(&pContext->texture.proxy3D, pSSM);
1576 AssertRCReturn(rc, rc);
1577#ifdef CR_ARB_texture_cube_map
1578 rc = crStateLoadTextureObjData(&pContext->texture.baseCubeMap, pSSM);
1579 AssertRCReturn(rc, rc);
1580 rc = crStateLoadTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
1581 AssertRCReturn(rc, rc);
1582#endif
1583#ifdef CR_NV_texture_rectangle
1584 rc = crStateLoadTextureObjData(&pContext->texture.baseRect, pSSM);
1585 AssertRCReturn(rc, rc);
1586 rc = crStateLoadTextureObjData(&pContext->texture.proxyRect, pSSM);
1587 AssertRCReturn(rc, rc);
1588#endif
1589
1590 if (bLoadShared)
1591 {
1592 /* Load shared textures */
1593 CRASSERT(pContext->shared && pContext->shared->textureTable);
1594 rc = SSMR3GetU32(pSSM, &uiNumElems);
1595 AssertRCReturn(rc, rc);
1596 for (ui=0; ui<uiNumElems; ++ui)
1597 {
1598 CRTextureObj *pTexture;
1599
1600 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1601 AssertRCReturn(rc, rc);
1602
1603 pTexture = (CRTextureObj *) crCalloc(sizeof(CRTextureObj));
1604 if (!pTexture) return VERR_NO_MEMORY;
1605
1606 rc = SSMR3GetMem(pSSM, pTexture, sizeof(*pTexture));
1607 AssertRCReturn(rc, rc);
1608
1609 pTexture->hwid = 0;
1610
1611 /*allocate actual memory*/
1612 for (i=0; i<6; ++i) {
1613 pTexture->level[i] = (CRTextureLevel *) crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
1614 if (!pTexture->level[i]) return VERR_NO_MEMORY;
1615 }
1616
1617 rc = crStateLoadTextureObjData(pTexture, pSSM);
1618 AssertRCReturn(rc, rc);
1619
1620 crHashtableAdd(pContext->shared->textureTable, key, pTexture);
1621 }
1622 }
1623
1624 /* Load current texture pointers */
1625 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
1626 {
1627 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pContext, pSSM);
1628 AssertRCReturn(rc, rc);
1629 }
1630
1631 /* Mark textures for resending to GPU */
1632 pContext->shared->bTexResyncNeeded = GL_TRUE;
1633
1634 /* Load lights */
1635 CRASSERT(pContext->lighting.light);
1636 rc = SSMR3GetMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
1637 AssertRCReturn(rc, rc);
1638
1639 /* Load attrib stack*/
1640 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1641 {
1642 if (pContext->attrib.enableStack[i].clip)
1643 {
1644 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].clip,
1645 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1646 AssertRCReturn(rc, rc);
1647 }
1648
1649 if (pContext->attrib.enableStack[i].light)
1650 {
1651 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].light,
1652 pContext->limits.maxLights*sizeof(GLboolean));
1653 AssertRCReturn(rc, rc);
1654 }
1655
1656 if (pContext->attrib.lightingStack[i].light)
1657 {
1658 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.lightingStack[i].light,
1659 pContext->limits.maxLights*sizeof(CRLight));
1660 AssertRCReturn(rc, rc);
1661 }
1662
1663 for (k=0; k<pContext->limits.maxTextureUnits; ++k)
1664 {
1665 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[k], pContext, pSSM);
1666 AssertRCReturn(rc, rc);
1667 }
1668
1669 if (pContext->attrib.transformStack[i].clip)
1670 {
1671 rc = crStateAllocAndSSMR3GetMem(pSSM, (void*)&pContext->attrib.transformStack[i].clip,
1672 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1673 AssertRCReturn(rc, rc);
1674 }
1675
1676 if (pContext->attrib.transformStack[i].clipPlane)
1677 {
1678 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.transformStack[i].clipPlane,
1679 pContext->limits.maxClipPlanes*sizeof(GLvectord));
1680 AssertRCReturn(rc, rc);
1681 }
1682 rc = crSateLoadEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, GL_TRUE, pSSM);
1683 AssertRCReturn(rc, rc);
1684 rc = crSateLoadEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, GL_TRUE, pSSM);
1685 AssertRCReturn(rc, rc);
1686 }
1687
1688 /* Load evaluator coeffs */
1689 rc = crSateLoadEvalCoeffs1D(pContext->eval.eval1D, GL_FALSE, pSSM);
1690 AssertRCReturn(rc, rc);
1691 rc = crSateLoadEvalCoeffs2D(pContext->eval.eval2D, GL_FALSE, pSSM);
1692 AssertRCReturn(rc, rc);
1693
1694 /* Load buffer objects */
1695#ifdef CR_ARB_vertex_buffer_object
1696 rc = SSMR3GetU32(pSSM, &uiNumElems);
1697 AssertRCReturn(rc, rc);
1698 for (ui=0; ui<=uiNumElems; ++ui) /*ui<=uiNumElems to load nullBuffer in same loop*/
1699 {
1700 CRBufferObject *pBufferObj;
1701
1702 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1703 AssertRCReturn(rc, rc);
1704
1705 /* default one should be already allocated */
1706 if (key==0)
1707 {
1708 pBufferObj = pContext->bufferobject.nullBuffer;
1709 if (!pBufferObj) return VERR_SSM_UNEXPECTED_DATA;
1710 }
1711 else
1712 {
1713 pBufferObj = (CRBufferObject *) crCalloc(sizeof(*pBufferObj));
1714 if (!pBufferObj) return VERR_NO_MEMORY;
1715 }
1716
1717 rc = SSMR3GetMem(pSSM, pBufferObj, sizeof(*pBufferObj));
1718 AssertRCReturn(rc, rc);
1719
1720 pBufferObj->hwid = 0;
1721
1722 if (pBufferObj->data)
1723 {
1724 CRASSERT(pBufferObj->size>0);
1725 pBufferObj->data = crAlloc(pBufferObj->size);
1726 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
1727 AssertRCReturn(rc, rc);
1728 }
1729 else if (pBufferObj->id!=0 && pBufferObj->size>0)
1730 {
1731 rc = SSMR3GetMem(pSSM, &pBufferObj->data, sizeof(pBufferObj->data));
1732 AssertRCReturn(rc, rc);
1733
1734 if (pBufferObj->data)
1735 {
1736 pBufferObj->data = crAlloc(pBufferObj->size);
1737 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
1738 AssertRCReturn(rc, rc);
1739 }
1740 }
1741
1742
1743 if (key!=0)
1744 crHashtableAdd(pContext->shared->buffersTable, key, pBufferObj);
1745 }
1746 /* Load pointers */
1747#define CRS_GET_BO(name) (((name)==0) ? (pContext->bufferobject.nullBuffer) : crHashtableSearch(pContext->shared->buffersTable, name))
1748 rc = SSMR3GetU32(pSSM, &ui);
1749 AssertRCReturn(rc, rc);
1750 pContext->bufferobject.arrayBuffer = CRS_GET_BO(ui);
1751 rc = SSMR3GetU32(pSSM, &ui);
1752 AssertRCReturn(rc, rc);
1753 pContext->bufferobject.elementsBuffer = CRS_GET_BO(ui);
1754#ifdef CR_ARB_pixel_buffer_object
1755 rc = SSMR3GetU32(pSSM, &ui);
1756 AssertRCReturn(rc, rc);
1757 pContext->bufferobject.packBuffer = CRS_GET_BO(ui);
1758 rc = SSMR3GetU32(pSSM, &ui);
1759 AssertRCReturn(rc, rc);
1760 pContext->bufferobject.unpackBuffer = CRS_GET_BO(ui);
1761#endif
1762#undef CRS_GET_BO
1763
1764 /* Load client pointers and array buffer bindings*/
1765 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1766 {
1767 rc = crStateLoadClientPointer(&pContext->client.array, i, pContext, pSSM);
1768 AssertRCReturn(rc, rc);
1769 }
1770 for (j=0; j<pContext->client.vertexArrayStackDepth; ++j)
1771 {
1772 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[j];
1773 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1774 {
1775 rc = crStateLoadClientPointer(pArray, i, pContext, pSSM);
1776 AssertRCReturn(rc, rc);
1777 }
1778 }
1779
1780 pContext->shared->bVBOResyncNeeded = GL_TRUE;
1781#endif
1782
1783 /* Load pixel/vertex programs */
1784 rc = SSMR3GetU32(pSSM, &uiNumElems);
1785 AssertRCReturn(rc, rc);
1786 /* Load defaults programs */
1787 rc = crStateLoadProgram(&pContext->program.defaultVertexProgram, pSSM);
1788 AssertRCReturn(rc, rc);
1789 rc = crStateLoadProgram(&pContext->program.defaultFragmentProgram, pSSM);
1790 AssertRCReturn(rc, rc);
1791 /* Load all the rest */
1792 for (ui=0; ui<uiNumElems; ++ui)
1793 {
1794 CRProgram *pProgram = NULL;
1795 rc = crStateLoadProgram(&pProgram, pSSM);
1796 AssertRCReturn(rc, rc);
1797 crHashtableAdd(pContext->program.programHash, pProgram->id, pProgram);
1798 //DIRTY(pProgram->dirtyProgram, pContext->neg_bitid);
1799
1800 }
1801 /* Load Pointers */
1802 rc = SSMR3GetU32(pSSM, &ui);
1803 AssertRCReturn(rc, rc);
1804 pContext->program.currentVertexProgram = ui==0 ? pContext->program.defaultVertexProgram
1805 : crHashtableSearch(pContext->program.programHash, ui);
1806 rc = SSMR3GetU32(pSSM, &ui);
1807 AssertRCReturn(rc, rc);
1808 pContext->program.currentFragmentProgram = ui==0 ? pContext->program.defaultFragmentProgram
1809 : crHashtableSearch(pContext->program.programHash, ui);
1810
1811 /* Mark programs for resending to GPU */
1812 pContext->program.bResyncNeeded = GL_TRUE;
1813
1814#ifdef CR_EXT_framebuffer_object
1815 /* Load FBOs */
1816 if (bLoadShared)
1817 {
1818 rc = SSMR3GetU32(pSSM, &uiNumElems);
1819 AssertRCReturn(rc, rc);
1820 for (ui=0; ui<uiNumElems; ++ui)
1821 {
1822 CRFramebufferObject *pFBO;
1823 pFBO = crAlloc(sizeof(*pFBO));
1824 if (!pFBO) return VERR_NO_MEMORY;
1825
1826 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1827 AssertRCReturn(rc, rc);
1828
1829 rc = SSMR3GetMem(pSSM, pFBO, sizeof(*pFBO));
1830 AssertRCReturn(rc, rc);
1831
1832 crHashtableAdd(pContext->shared->fbTable, key, pFBO);
1833 }
1834
1835 rc = SSMR3GetU32(pSSM, &uiNumElems);
1836 AssertRCReturn(rc, rc);
1837 for (ui=0; ui<uiNumElems; ++ui)
1838 {
1839 CRRenderbufferObject *pRBO;
1840 pRBO = crAlloc(sizeof(*pRBO));
1841 if (!pRBO) return VERR_NO_MEMORY;
1842
1843 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1844 AssertRCReturn(rc, rc);
1845
1846 rc = SSMR3GetMem(pSSM, pRBO, sizeof(*pRBO));
1847 AssertRCReturn(rc, rc);
1848
1849 crHashtableAdd(pContext->shared->rbTable, key, pRBO);
1850 }
1851 }
1852
1853 rc = SSMR3GetU32(pSSM, &ui);
1854 AssertRCReturn(rc, rc);
1855 pContext->framebufferobject.drawFB = ui==0 ? NULL
1856 : crHashtableSearch(pContext->shared->fbTable, ui);
1857
1858 rc = SSMR3GetU32(pSSM, &ui);
1859 AssertRCReturn(rc, rc);
1860 pContext->framebufferobject.readFB = ui==0 ? NULL
1861 : crHashtableSearch(pContext->shared->fbTable, ui);
1862
1863 rc = SSMR3GetU32(pSSM, &ui);
1864 AssertRCReturn(rc, rc);
1865 pContext->framebufferobject.renderbuffer = ui==0 ? NULL
1866 : crHashtableSearch(pContext->shared->rbTable, ui);
1867
1868 /* Mark FBOs/RBOs for resending to GPU */
1869 pContext->shared->bFBOResyncNeeded = GL_TRUE;
1870#endif
1871
1872#ifdef CR_OPENGL_VERSION_2_0
1873 /* Load GLSL related info */
1874 rc = SSMR3GetU32(pSSM, &uiNumElems);
1875 AssertRCReturn(rc, rc);
1876
1877 for (ui=0; ui<uiNumElems; ++ui)
1878 {
1879 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
1880 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
1881 crHashtableAdd(pContext->glsl.shaders, pShader->id, pShader);
1882 }
1883
1884 rc = SSMR3GetU32(pSSM, &uiNumElems);
1885 AssertRCReturn(rc, rc);
1886
1887 for (ui=0; ui<uiNumElems; ++ui)
1888 {
1889 CRGLSLProgram *pProgram;
1890 uint32_t numShaders;
1891
1892 pProgram = crAlloc(sizeof(*pProgram));
1893 if (!pProgram) return VERR_NO_MEMORY;
1894
1895 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1896 AssertRCReturn(rc, rc);
1897
1898 rc = SSMR3GetMem(pSSM, pProgram, sizeof(*pProgram));
1899 AssertRCReturn(rc, rc);
1900
1901 crHashtableAdd(pContext->glsl.programs, key, pProgram);
1902
1903 pProgram->currentState.attachedShaders = crAllocHashtable();
1904
1905 rc = SSMR3GetU32(pSSM, &numShaders);
1906 AssertRCReturn(rc, rc);
1907
1908 for (k=0; k<numShaders; ++k)
1909 {
1910 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1911 AssertRCReturn(rc, rc);
1912 crHashtableAdd(pProgram->currentState.attachedShaders, key, crHashtableSearch(pContext->glsl.shaders, key));
1913 }
1914
1915 if (pProgram->activeState.attachedShaders)
1916 {
1917 pProgram->activeState.attachedShaders = crAllocHashtable();
1918
1919 rc = SSMR3GetU32(pSSM, &numShaders);
1920 AssertRCReturn(rc, rc);
1921
1922 for (k=0; k<numShaders; ++k)
1923 {
1924 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
1925 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
1926 crHashtableAdd(pProgram->activeState.attachedShaders, pShader->id, pShader);
1927 }
1928 }
1929
1930 if (pProgram->currentState.cAttribs)
1931 pProgram->currentState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->currentState.cAttribs*sizeof(CRGLSLAttrib));
1932 for (k=0; k<pProgram->currentState.cAttribs; ++k)
1933 {
1934 rc = SSMR3GetMem(pSSM, &pProgram->currentState.pAttribs[k].index, sizeof(pProgram->currentState.pAttribs[k].index));
1935 AssertRCReturn(rc, rc);
1936 pProgram->currentState.pAttribs[k].name = crStateLoadString(pSSM);
1937 }
1938
1939 if (pProgram->activeState.cAttribs)
1940 pProgram->activeState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->activeState.cAttribs*sizeof(CRGLSLAttrib));
1941 for (k=0; k<pProgram->activeState.cAttribs; ++k)
1942 {
1943 rc = SSMR3GetMem(pSSM, &pProgram->activeState.pAttribs[k].index, sizeof(pProgram->activeState.pAttribs[k].index));
1944 AssertRCReturn(rc, rc);
1945 pProgram->activeState.pAttribs[k].name = crStateLoadString(pSSM);
1946 }
1947
1948 {
1949 int32_t cUniforms;
1950 rc = SSMR3GetS32(pSSM, &cUniforms);
1951 pProgram->cUniforms = cUniforms;
1952 AssertRCReturn(rc, rc);
1953 }
1954
1955 if (pProgram->cUniforms)
1956 {
1957 pProgram->pUniforms = crAlloc(pProgram->cUniforms*sizeof(CRGLSLUniform));
1958 if (!pProgram->pUniforms) return VERR_NO_MEMORY;
1959
1960 for (k=0; k<pProgram->cUniforms; ++k)
1961 {
1962 size_t itemsize, datasize;
1963
1964 rc = SSMR3GetMem(pSSM, &pProgram->pUniforms[k].type, sizeof(GLenum));
1965 pProgram->pUniforms[k].name = crStateLoadString(pSSM);
1966
1967 if (crStateIsIntUniform(pProgram->pUniforms[k].type))
1968 {
1969 itemsize = sizeof(GLint);
1970 } else itemsize = sizeof(GLfloat);
1971
1972 datasize = crStateGetUniformSize(pProgram->pUniforms[k].type)*itemsize;
1973 pProgram->pUniforms[k].data = crAlloc(datasize);
1974 if (!pProgram->pUniforms[k].data) return VERR_NO_MEMORY;
1975
1976 rc = SSMR3GetMem(pSSM, pProgram->pUniforms[k].data, datasize);
1977 }
1978 }
1979 }
1980
1981 rc = SSMR3GetU32(pSSM, &ui);
1982 AssertRCReturn(rc, rc);
1983 pContext->glsl.activeProgram = ui==0 ? NULL
1984 : crHashtableSearch(pContext->glsl.programs, ui);
1985
1986 /*Mark for resending to GPU*/
1987 pContext->glsl.bResyncNeeded = GL_TRUE;
1988#endif
1989
1990
1991 /*Restore front buffer image*/
1992 {
1993 CRViewportState *pVP = &pContext->viewport;
1994 GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
1995 void *pData = crAlloc(cbData);
1996
1997 if (!pData)
1998 {
1999 pContext->pImage = NULL;
2000 return VERR_NO_MEMORY;
2001 }
2002
2003 rc = SSMR3GetMem(pSSM, pData, cbData);
2004 AssertRCReturn(rc, rc);
2005
2006 pContext->pImage = pData;
2007 }
2008
2009
2010 /*Mark all as dirty to make sure we'd restore correct context state*/
2011 {
2012 CRStateBits *pBits = GetCurrentBits();
2013
2014 FILLDIRTY(pBits->attrib.dirty);
2015
2016 FILLDIRTY(pBits->buffer.dirty);
2017 FILLDIRTY(pBits->buffer.enable);
2018 FILLDIRTY(pBits->buffer.alphaFunc);
2019 FILLDIRTY(pBits->buffer.depthFunc);
2020 FILLDIRTY(pBits->buffer.blendFunc);
2021 FILLDIRTY(pBits->buffer.logicOp);
2022 FILLDIRTY(pBits->buffer.indexLogicOp);
2023 FILLDIRTY(pBits->buffer.drawBuffer);
2024 FILLDIRTY(pBits->buffer.readBuffer);
2025 FILLDIRTY(pBits->buffer.indexMask);
2026 FILLDIRTY(pBits->buffer.colorWriteMask);
2027 FILLDIRTY(pBits->buffer.clearColor);
2028 FILLDIRTY(pBits->buffer.clearIndex);
2029 FILLDIRTY(pBits->buffer.clearDepth);
2030 FILLDIRTY(pBits->buffer.clearAccum);
2031 FILLDIRTY(pBits->buffer.depthMask);
2032#ifdef CR_EXT_blend_color
2033 FILLDIRTY(pBits->buffer.blendColor);
2034#endif
2035#if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
2036 FILLDIRTY(pBits->buffer.blendEquation);
2037#endif
2038#if defined(CR_EXT_blend_func_separate)
2039 FILLDIRTY(pBits->buffer.blendFuncSeparate);
2040#endif
2041
2042#ifdef CR_ARB_vertex_buffer_object
2043 FILLDIRTY(pBits->bufferobject.dirty);
2044 FILLDIRTY(pBits->bufferobject.arrayBinding);
2045 FILLDIRTY(pBits->bufferobject.elementsBinding);
2046# ifdef CR_ARB_pixel_buffer_object
2047 FILLDIRTY(pBits->bufferobject.packBinding);
2048 FILLDIRTY(pBits->bufferobject.unpackBinding);
2049# endif
2050#endif
2051
2052 FILLDIRTY(pBits->client.dirty);
2053 FILLDIRTY(pBits->client.pack);
2054 FILLDIRTY(pBits->client.unpack);
2055 FILLDIRTY(pBits->client.enableClientState);
2056 FILLDIRTY(pBits->client.clientPointer);
2057 FILLDIRTY(pBits->client.v);
2058 FILLDIRTY(pBits->client.n);
2059 FILLDIRTY(pBits->client.c);
2060 FILLDIRTY(pBits->client.i);
2061 FILLDIRTY(pBits->client.e);
2062 FILLDIRTY(pBits->client.s);
2063 FILLDIRTY(pBits->client.f);
2064 for (i=0; i<CR_MAX_TEXTURE_UNITS; i++)
2065 {
2066 FILLDIRTY(pBits->client.t[i]);
2067 }
2068#ifdef CR_NV_vertex_program
2069 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
2070 {
2071 FILLDIRTY(pBits->client.a[i]);
2072 }
2073#endif
2074
2075 FILLDIRTY(pBits->current.dirty);
2076 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
2077 {
2078 FILLDIRTY(pBits->current.vertexAttrib[i]);
2079 }
2080 FILLDIRTY(pBits->current.edgeFlag);
2081 FILLDIRTY(pBits->current.colorIndex);
2082 FILLDIRTY(pBits->current.rasterPos);
2083
2084
2085 FILLDIRTY(pBits->eval.dirty);
2086 for (i=0; i<GLEVAL_TOT; i++)
2087 {
2088 FILLDIRTY(pBits->eval.eval1D[i]);
2089 FILLDIRTY(pBits->eval.eval2D[i]);
2090 FILLDIRTY(pBits->eval.enable1D[i]);
2091 FILLDIRTY(pBits->eval.enable2D[i]);
2092 }
2093 FILLDIRTY(pBits->eval.enable);
2094 FILLDIRTY(pBits->eval.grid1D);
2095 FILLDIRTY(pBits->eval.grid2D);
2096#ifdef CR_NV_vertex_program
2097 /*@todo Those seems to be unused?
2098 FILLDIRTY(pBits->eval.enableAttrib1D);
2099 FILLDIRTY(pBits->eval.enableAttrib2D);
2100 */
2101#endif
2102
2103 FILLDIRTY(pBits->feedback.dirty);
2104 FILLDIRTY(pBits->selection.dirty);
2105
2106 FILLDIRTY(pBits->fog.dirty);
2107 FILLDIRTY(pBits->fog.color);
2108 FILLDIRTY(pBits->fog.index);
2109 FILLDIRTY(pBits->fog.density);
2110 FILLDIRTY(pBits->fog.start);
2111 FILLDIRTY(pBits->fog.end);
2112 FILLDIRTY(pBits->fog.mode);
2113 FILLDIRTY(pBits->fog.enable);
2114#ifdef CR_NV_fog_distance
2115 FILLDIRTY(pBits->fog.fogDistanceMode);
2116#endif
2117#ifdef CR_EXT_fog_coord
2118 FILLDIRTY(pBits->fog.fogCoordinateSource);
2119#endif
2120
2121 FILLDIRTY(pBits->hint.dirty);
2122 FILLDIRTY(pBits->hint.perspectiveCorrection);
2123 FILLDIRTY(pBits->hint.pointSmooth);
2124 FILLDIRTY(pBits->hint.lineSmooth);
2125 FILLDIRTY(pBits->hint.polygonSmooth);
2126 FILLDIRTY(pBits->hint.fog);
2127#ifdef CR_EXT_clip_volume_hint
2128 FILLDIRTY(pBits->hint.clipVolumeClipping);
2129
2130#endif
2131#ifdef CR_ARB_texture_compression
2132 FILLDIRTY(pBits->hint.textureCompression);
2133#endif
2134#ifdef CR_SGIS_generate_mipmap
2135 FILLDIRTY(pBits->hint.generateMipmap);
2136#endif
2137
2138 FILLDIRTY(pBits->lighting.dirty);
2139 FILLDIRTY(pBits->lighting.shadeModel);
2140 FILLDIRTY(pBits->lighting.colorMaterial);
2141 FILLDIRTY(pBits->lighting.lightModel);
2142 FILLDIRTY(pBits->lighting.material);
2143 FILLDIRTY(pBits->lighting.enable);
2144 for (i=0; i<CR_MAX_LIGHTS; ++i)
2145 {
2146 FILLDIRTY(pBits->lighting.light[i].dirty);
2147 FILLDIRTY(pBits->lighting.light[i].enable);
2148 FILLDIRTY(pBits->lighting.light[i].ambient);
2149 FILLDIRTY(pBits->lighting.light[i].diffuse);
2150 FILLDIRTY(pBits->lighting.light[i].specular);
2151 FILLDIRTY(pBits->lighting.light[i].position);
2152 FILLDIRTY(pBits->lighting.light[i].attenuation);
2153 FILLDIRTY(pBits->lighting.light[i].spot);
2154 }
2155
2156 FILLDIRTY(pBits->line.dirty);
2157 FILLDIRTY(pBits->line.enable);
2158 FILLDIRTY(pBits->line.width);
2159 FILLDIRTY(pBits->line.stipple);
2160
2161 FILLDIRTY(pBits->lists.dirty);
2162 FILLDIRTY(pBits->lists.base);
2163
2164 FILLDIRTY(pBits->multisample.dirty);
2165 FILLDIRTY(pBits->multisample.enable);
2166 FILLDIRTY(pBits->multisample.sampleAlphaToCoverage);
2167 FILLDIRTY(pBits->multisample.sampleAlphaToOne);
2168 FILLDIRTY(pBits->multisample.sampleCoverage);
2169 FILLDIRTY(pBits->multisample.sampleCoverageValue);
2170
2171#if CR_ARB_occlusion_query
2172 FILLDIRTY(pBits->occlusion.dirty);
2173#endif
2174
2175 FILLDIRTY(pBits->pixel.dirty);
2176 FILLDIRTY(pBits->pixel.transfer);
2177 FILLDIRTY(pBits->pixel.zoom);
2178 FILLDIRTY(pBits->pixel.maps);
2179
2180 FILLDIRTY(pBits->point.dirty);
2181 FILLDIRTY(pBits->point.enableSmooth);
2182 FILLDIRTY(pBits->point.size);
2183#ifdef CR_ARB_point_parameters
2184 FILLDIRTY(pBits->point.minSize);
2185 FILLDIRTY(pBits->point.maxSize);
2186 FILLDIRTY(pBits->point.fadeThresholdSize);
2187 FILLDIRTY(pBits->point.distanceAttenuation);
2188#endif
2189#ifdef CR_ARB_point_sprite
2190 FILLDIRTY(pBits->point.enableSprite);
2191 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
2192 {
2193 FILLDIRTY(pBits->point.coordReplacement[i]);
2194 }
2195#endif
2196
2197 FILLDIRTY(pBits->polygon.dirty);
2198 FILLDIRTY(pBits->polygon.enable);
2199 FILLDIRTY(pBits->polygon.offset);
2200 FILLDIRTY(pBits->polygon.mode);
2201 FILLDIRTY(pBits->polygon.stipple);
2202
2203 FILLDIRTY(pBits->program.dirty);
2204 FILLDIRTY(pBits->program.vpEnable);
2205 FILLDIRTY(pBits->program.fpEnable);
2206 FILLDIRTY(pBits->program.vpBinding);
2207 FILLDIRTY(pBits->program.fpBinding);
2208 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; ++i)
2209 {
2210 FILLDIRTY(pBits->program.vertexAttribArrayEnable[i]);
2211 FILLDIRTY(pBits->program.map1AttribArrayEnable[i]);
2212 FILLDIRTY(pBits->program.map2AttribArrayEnable[i]);
2213 }
2214 for (i=0; i<CR_MAX_VERTEX_PROGRAM_ENV_PARAMS; ++i)
2215 {
2216 FILLDIRTY(pBits->program.vertexEnvParameter[i]);
2217 }
2218 for (i=0; i<CR_MAX_FRAGMENT_PROGRAM_ENV_PARAMS; ++i)
2219 {
2220 FILLDIRTY(pBits->program.fragmentEnvParameter[i]);
2221 }
2222 FILLDIRTY(pBits->program.vertexEnvParameters);
2223 FILLDIRTY(pBits->program.fragmentEnvParameters);
2224 for (i=0; i<CR_MAX_VERTEX_PROGRAM_ENV_PARAMS/4; ++i)
2225 {
2226 FILLDIRTY(pBits->program.trackMatrix[i]);
2227 }
2228
2229 FILLDIRTY(pBits->regcombiner.dirty);
2230 FILLDIRTY(pBits->regcombiner.enable);
2231 FILLDIRTY(pBits->regcombiner.regCombinerVars);
2232 FILLDIRTY(pBits->regcombiner.regCombinerColor0);
2233 FILLDIRTY(pBits->regcombiner.regCombinerColor1);
2234 for (i=0; i<CR_MAX_GENERAL_COMBINERS; ++i)
2235 {
2236 FILLDIRTY(pBits->regcombiner.regCombinerStageColor0[i]);
2237 FILLDIRTY(pBits->regcombiner.regCombinerStageColor1[i]);
2238 FILLDIRTY(pBits->regcombiner.regCombinerInput[i]);
2239 FILLDIRTY(pBits->regcombiner.regCombinerOutput[i]);
2240 }
2241 FILLDIRTY(pBits->regcombiner.regCombinerFinalInput);
2242
2243 FILLDIRTY(pBits->stencil.dirty);
2244 FILLDIRTY(pBits->stencil.enable);
2245 FILLDIRTY(pBits->stencil.func);
2246 FILLDIRTY(pBits->stencil.op);
2247 FILLDIRTY(pBits->stencil.clearValue);
2248 FILLDIRTY(pBits->stencil.writeMask);
2249
2250 FILLDIRTY(pBits->texture.dirty);
2251 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
2252 {
2253 FILLDIRTY(pBits->texture.enable[i]);
2254 FILLDIRTY(pBits->texture.current[i]);
2255 FILLDIRTY(pBits->texture.objGen[i]);
2256 FILLDIRTY(pBits->texture.eyeGen[i]);
2257 FILLDIRTY(pBits->texture.genMode[i]);
2258 FILLDIRTY(pBits->texture.envBit[i]);
2259 }
2260
2261 FILLDIRTY(pBits->transform.dirty);
2262 FILLDIRTY(pBits->transform.matrixMode);
2263 FILLDIRTY(pBits->transform.modelviewMatrix);
2264 FILLDIRTY(pBits->transform.projectionMatrix);
2265 FILLDIRTY(pBits->transform.colorMatrix);
2266 FILLDIRTY(pBits->transform.textureMatrix);
2267 FILLDIRTY(pBits->transform.programMatrix);
2268 FILLDIRTY(pBits->transform.clipPlane);
2269 FILLDIRTY(pBits->transform.enable);
2270 FILLDIRTY(pBits->transform.base);
2271
2272 FILLDIRTY(pBits->viewport.dirty);
2273 FILLDIRTY(pBits->viewport.v_dims);
2274 FILLDIRTY(pBits->viewport.s_dims);
2275 FILLDIRTY(pBits->viewport.enable);
2276 FILLDIRTY(pBits->viewport.depth);
2277 }
2278
2279 return VINF_SUCCESS;
2280}
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