VirtualBox

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

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

crOpenGL: check proper pointer

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 75.3 KB
Line 
1/* $Id: state_snapshot.c 33734 2010-11-03 16:19:40Z 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->texture.bResyncNeeded==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 if (pContext->shared->refCount>1)
1024 {
1025 bSaveShared = pContext->shared->saveCount==0;
1026
1027 ++pContext->shared->saveCount;
1028 if (pContext->shared->saveCount == pContext->shared->refCount)
1029 {
1030 pContext->shared->saveCount=0;
1031 }
1032 }
1033
1034 /* Save transform state */
1035 rc = SSMR3PutMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
1036 AssertRCReturn(rc, rc);
1037 rc = SSMR3PutMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
1038 AssertRCReturn(rc, rc);
1039 rc = crStateSaveMatrixStack(&pContext->transform.modelViewStack, pSSM);
1040 AssertRCReturn(rc, rc);
1041 rc = crStateSaveMatrixStack(&pContext->transform.projectionStack, pSSM);
1042 AssertRCReturn(rc, rc);
1043 rc = crStateSaveMatrixStack(&pContext->transform.colorStack, pSSM);
1044 AssertRCReturn(rc, rc);
1045 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1046 {
1047 rc = crStateSaveMatrixStack(&pContext->transform.textureStack[i], pSSM);
1048 AssertRCReturn(rc, rc);
1049 }
1050 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1051 {
1052 rc = crStateSaveMatrixStack(&pContext->transform.programStack[i], pSSM);
1053 AssertRCReturn(rc, rc);
1054 }
1055
1056 /* Save textures */
1057 rc = crStateSaveTextureObjData(&pContext->texture.base1D, pSSM);
1058 AssertRCReturn(rc, rc);
1059 rc = crStateSaveTextureObjData(&pContext->texture.base2D, pSSM);
1060 AssertRCReturn(rc, rc);
1061 rc = crStateSaveTextureObjData(&pContext->texture.base3D, pSSM);
1062 AssertRCReturn(rc, rc);
1063 rc = crStateSaveTextureObjData(&pContext->texture.proxy1D, pSSM);
1064 AssertRCReturn(rc, rc);
1065 rc = crStateSaveTextureObjData(&pContext->texture.proxy2D, pSSM);
1066 AssertRCReturn(rc, rc);
1067 rc = crStateSaveTextureObjData(&pContext->texture.proxy3D, pSSM);
1068#ifdef CR_ARB_texture_cube_map
1069 rc = crStateSaveTextureObjData(&pContext->texture.baseCubeMap, pSSM);
1070 AssertRCReturn(rc, rc);
1071 rc = crStateSaveTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
1072 AssertRCReturn(rc, rc);
1073#endif
1074#ifdef CR_NV_texture_rectangle
1075 rc = crStateSaveTextureObjData(&pContext->texture.baseRect, pSSM);
1076 AssertRCReturn(rc, rc);
1077 rc = crStateSaveTextureObjData(&pContext->texture.proxyRect, pSSM);
1078 AssertRCReturn(rc, rc);
1079#endif
1080
1081 /* Save shared textures */
1082 if (bSaveShared)
1083 {
1084 CRASSERT(pContext->shared && pContext->shared->textureTable);
1085 ui32 = crHashtableNumElements(pContext->shared->textureTable);
1086 rc = SSMR3PutU32(pSSM, ui32);
1087 AssertRCReturn(rc, rc);
1088 crHashtableWalk(pContext->shared->textureTable, crStateSaveSharedTextureCB, pSSM);
1089
1090#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
1091 /* Restore previous texture bindings via diff_api */
1092 if (ui32)
1093 {
1094 CRTextureUnit *pTexUnit;
1095
1096 pTexUnit = &pContext->texture.unit[pContext->texture.curTextureUnit];
1097
1098 diff_api.BindTexture(GL_TEXTURE_1D, pTexUnit->currentTexture1D->hwid);
1099 diff_api.BindTexture(GL_TEXTURE_2D, pTexUnit->currentTexture2D->hwid);
1100 diff_api.BindTexture(GL_TEXTURE_3D, pTexUnit->currentTexture3D->hwid);
1101#ifdef CR_ARB_texture_cube_map
1102 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, pTexUnit->currentTextureCubeMap->hwid);
1103#endif
1104#ifdef CR_NV_texture_rectangle
1105 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, pTexUnit->currentTextureRect->hwid);
1106#endif
1107 }
1108#endif
1109 }
1110
1111 /* Save current texture pointers */
1112 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
1113 {
1114 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pSSM);
1115 AssertRCReturn(rc, rc);
1116 }
1117
1118 /* Save lights */
1119 CRASSERT(pContext->lighting.light);
1120 rc = SSMR3PutMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
1121 AssertRCReturn(rc, rc);
1122
1123 /* Save attrib stack*/
1124 /*@todo could go up to used stack depth here?*/
1125 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1126 {
1127 if (pContext->attrib.enableStack[i].clip)
1128 {
1129 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].clip,
1130 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1131 AssertRCReturn(rc, rc);
1132 }
1133
1134 if (pContext->attrib.enableStack[i].light)
1135 {
1136 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].light,
1137 pContext->limits.maxLights*sizeof(GLboolean));
1138 AssertRCReturn(rc, rc);
1139 }
1140
1141 if (pContext->attrib.lightingStack[i].light)
1142 {
1143 rc = SSMR3PutMem(pSSM, pContext->attrib.lightingStack[i].light,
1144 pContext->limits.maxLights*sizeof(CRLight));
1145 AssertRCReturn(rc, rc);
1146 }
1147
1148 for (j=0; j<pContext->limits.maxTextureUnits; ++j)
1149 {
1150 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[j], pSSM);
1151 AssertRCReturn(rc, rc);
1152 }
1153
1154 if (pContext->attrib.transformStack[i].clip)
1155 {
1156 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clip,
1157 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1158 AssertRCReturn(rc, rc);
1159 }
1160
1161 if (pContext->attrib.transformStack[i].clipPlane)
1162 {
1163 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clipPlane,
1164 pContext->limits.maxClipPlanes*sizeof(GLvectord));
1165 AssertRCReturn(rc, rc);
1166 }
1167
1168 rc = crSateSaveEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, pSSM);
1169 AssertRCReturn(rc, rc);
1170 rc = crSateSaveEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, pSSM);
1171 AssertRCReturn(rc, rc);
1172 }
1173
1174 /* Save evaluator coeffs */
1175 rc = crSateSaveEvalCoeffs1D(pContext->eval.eval1D, pSSM);
1176 AssertRCReturn(rc, rc);
1177 rc = crSateSaveEvalCoeffs2D(pContext->eval.eval2D, pSSM);
1178 AssertRCReturn(rc, rc);
1179
1180#ifdef CR_ARB_vertex_buffer_object
1181 /* Save buffer objects */
1182 ui32 = bSaveShared? crHashtableNumElements(pContext->shared->buffersTable):0;
1183 rc = SSMR3PutU32(pSSM, ui32);
1184 AssertRCReturn(rc, rc);
1185
1186 /* Save default one*/
1187 crStateSaveBufferObjectCB(0, pContext->bufferobject.nullBuffer, pSSM);
1188
1189 if (bSaveShared)
1190 {
1191 /* Save all the rest */
1192 crHashtableWalk(pContext->shared->buffersTable, crStateSaveBufferObjectCB, pSSM);
1193 }
1194
1195 /* Restore binding */
1196 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->hwid);
1197
1198 /* Save pointers */
1199 rc = SSMR3PutU32(pSSM, pContext->bufferobject.arrayBuffer->id);
1200 AssertRCReturn(rc, rc);
1201 rc = SSMR3PutU32(pSSM, pContext->bufferobject.elementsBuffer->id);
1202 AssertRCReturn(rc, rc);
1203#ifdef CR_ARB_pixel_buffer_object
1204 rc = SSMR3PutU32(pSSM, pContext->bufferobject.packBuffer->id);
1205 AssertRCReturn(rc, rc);
1206 rc = SSMR3PutU32(pSSM, pContext->bufferobject.unpackBuffer->id);
1207 AssertRCReturn(rc, rc);
1208#endif
1209 /* Save clint pointers and buffer bindings*/
1210 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1211 {
1212 rc = crStateSaveClientPointer(&pContext->client.array, i, pSSM);
1213 AssertRCReturn(rc, rc);
1214 }
1215
1216 crDebug("client.vertexArrayStackDepth %i", pContext->client.vertexArrayStackDepth);
1217 for (i=0; i<pContext->client.vertexArrayStackDepth; ++i)
1218 {
1219 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[i];
1220 for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
1221 {
1222 rc = crStateSaveClientPointer(pArray, j, pSSM);
1223 AssertRCReturn(rc, rc);
1224 }
1225 }
1226#endif /*CR_ARB_vertex_buffer_object*/
1227
1228 /* Save pixel/vertex programs */
1229 ui32 = crHashtableNumElements(pContext->program.programHash);
1230 rc = SSMR3PutU32(pSSM, ui32);
1231 AssertRCReturn(rc, rc);
1232 /* Save defaults programs */
1233 crStateSaveProgramCB(0, pContext->program.defaultVertexProgram, pSSM);
1234 crStateSaveProgramCB(0, pContext->program.defaultFragmentProgram, pSSM);
1235 /* Save all the rest */
1236 crHashtableWalk(pContext->program.programHash, crStateSaveProgramCB, pSSM);
1237 /* Save Pointers */
1238 rc = SSMR3PutU32(pSSM, pContext->program.currentVertexProgram->id);
1239 AssertRCReturn(rc, rc);
1240 rc = SSMR3PutU32(pSSM, pContext->program.currentFragmentProgram->id);
1241 AssertRCReturn(rc, rc);
1242 /* This one is unused it seems*/
1243 CRASSERT(!pContext->program.errorString);
1244
1245#ifdef CR_EXT_framebuffer_object
1246 /* Save FBOs */
1247 if (bSaveShared)
1248 {
1249 ui32 = crHashtableNumElements(pContext->shared->fbTable);
1250 rc = SSMR3PutU32(pSSM, ui32);
1251 AssertRCReturn(rc, rc);
1252 crHashtableWalk(pContext->shared->fbTable, crStateSaveFramebuffersCB, pSSM);
1253 ui32 = crHashtableNumElements(pContext->shared->rbTable);
1254 rc = SSMR3PutU32(pSSM, ui32);
1255 AssertRCReturn(rc, rc);
1256 crHashtableWalk(pContext->shared->rbTable, crStateSaveRenderbuffersCB, pSSM);
1257 }
1258 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.drawFB?pContext->framebufferobject.drawFB->id:0);
1259 AssertRCReturn(rc, rc);
1260 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.readFB?pContext->framebufferobject.readFB->id:0);
1261 AssertRCReturn(rc, rc);
1262 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.renderbuffer?pContext->framebufferobject.renderbuffer->id:0);
1263 AssertRCReturn(rc, rc);
1264#endif
1265
1266#ifdef CR_OPENGL_VERSION_2_0
1267 /* Save GLSL related info */
1268 ui32 = crHashtableNumElements(pContext->glsl.shaders);
1269 rc = SSMR3PutU32(pSSM, ui32);
1270 AssertRCReturn(rc, rc);
1271 crHashtableWalk(pContext->glsl.shaders, crStateSaveGLSLShaderCB, pSSM);
1272 ui32 = crHashtableNumElements(pContext->glsl.programs);
1273 rc = SSMR3PutU32(pSSM, ui32);
1274 AssertRCReturn(rc, rc);
1275 crHashtableWalk(pContext->glsl.programs, crStateSaveGLSLProgramCB, pSSM);
1276 rc = SSMR3PutU32(pSSM, pContext->glsl.activeProgram?pContext->glsl.activeProgram->id:0);
1277 AssertRCReturn(rc, rc);
1278#endif
1279
1280 {
1281 CRViewportState *pVP = &pContext->viewport;
1282 CRPixelPackState packing = pContext->client.pack;
1283 GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
1284 void *pData = crAlloc(cbData);
1285
1286 if (!pData)
1287 {
1288 return VERR_NO_MEMORY;
1289 }
1290
1291 diff_api.PixelStorei(GL_PACK_SKIP_ROWS, 0);
1292 diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, 0);
1293 diff_api.PixelStorei(GL_PACK_ALIGNMENT, 1);
1294 diff_api.PixelStorei(GL_PACK_ROW_LENGTH, 0);
1295 diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
1296 diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, 0);
1297 diff_api.PixelStorei(GL_PACK_SWAP_BYTES, 0);
1298 diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
1299
1300 diff_api.ReadBuffer(GL_FRONT);
1301 diff_api.ReadPixels(0, 0, pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, pData);
1302
1303 diff_api.ReadBuffer(pContext->framebufferobject.readFB ?
1304 pContext->framebufferobject.readFB->readbuffer : pContext->buffer.readBuffer);
1305 diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
1306 diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
1307 diff_api.PixelStorei(GL_PACK_ALIGNMENT, packing.alignment);
1308 diff_api.PixelStorei(GL_PACK_ROW_LENGTH, packing.rowLength);
1309 diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, packing.imageHeight);
1310 diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, packing.skipImages);
1311 diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
1312 diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
1313
1314 rc = SSMR3PutMem(pSSM, pData, cbData);
1315 AssertRCReturn(rc, rc);
1316
1317 crFree(pData);
1318 }
1319
1320 return VINF_SUCCESS;
1321}
1322
1323typedef struct _crFindSharedCtxParms {
1324 CRContext *pSrcCtx, *pDstCtx;
1325} crFindSharedCtxParms_t;
1326
1327static void crStateFindSharedCB(unsigned long key, void *data1, void *data2)
1328{
1329 CRContext *pContext = (CRContext *) data1;
1330 crFindSharedCtxParms_t *pParms = (crFindSharedCtxParms_t *) data2;
1331 (void) key;
1332
1333 if (pContext!=pParms->pSrcCtx && pContext->shared->id==pParms->pSrcCtx->shared->id)
1334 {
1335 pParms->pDstCtx->shared = pContext->shared;
1336 }
1337}
1338
1339#define SLC_COPYPTR(ptr) pTmpContext->ptr = pContext->ptr
1340#define SLC_ASSSERT_NULL_PTR(ptr) CRASSERT(!pContext->ptr)
1341
1342int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PSSMHANDLE pSSM)
1343{
1344 CRContext* pTmpContext;
1345 int32_t rc, i, j;
1346 uint32_t uiNumElems, ui, k;
1347 unsigned long key;
1348 GLboolean bLoadShared = GL_TRUE;
1349
1350 CRASSERT(pContext && pSSM);
1351
1352 /* This one is rather big for stack allocation and causes macs to crash */
1353 pTmpContext = (CRContext*)crAlloc(sizeof(*pTmpContext));
1354 if (!pTmpContext)
1355 return VERR_NO_MEMORY;
1356
1357 rc = SSMR3GetMem(pSSM, pTmpContext, sizeof(*pTmpContext));
1358 AssertRCReturn(rc, rc);
1359
1360 /* Deal with shared state */
1361 {
1362 crFindSharedCtxParms_t parms;
1363
1364 rc = SSMR3GetS32(pSSM, &pContext->shared->id);
1365 AssertRCReturn(rc, rc);
1366
1367 pTmpContext->shared = NULL;
1368 parms.pSrcCtx = pContext;
1369 parms.pDstCtx = pTmpContext;
1370 crHashtableWalk(pCtxTable, crStateFindSharedCB, &parms);
1371
1372 if (pTmpContext->shared)
1373 {
1374 CRASSERT(pContext->shared->refCount==1 && pTmpContext->shared->refCount>1);
1375 bLoadShared = GL_FALSE;
1376 crStateFreeShared(pContext->shared);
1377 pContext->shared = NULL;
1378 }
1379 else
1380 {
1381 SLC_COPYPTR(shared);
1382 }
1383 }
1384
1385 SLC_COPYPTR(flush_func);
1386 SLC_COPYPTR(flush_arg);
1387
1388 /* We're supposed to be loading into an empty context, so those pointers should be NULL */
1389 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1390 {
1391 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].clip);
1392 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].light);
1393
1394 SLC_ASSSERT_NULL_PTR(attrib.lightingStack[i].light);
1395 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clip);
1396 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clipPlane);
1397
1398 for (j=0; j<GLEVAL_TOT; ++j)
1399 {
1400 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval1D[j].coeff);
1401 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval2D[j].coeff);
1402 }
1403 }
1404
1405#ifdef CR_ARB_vertex_buffer_object
1406 SLC_COPYPTR(bufferobject.nullBuffer);
1407#endif
1408
1409/*@todo, that should be removed probably as those should hold the offset values, so loading should be fine
1410 but better check*/
1411#if 0
1412#ifdef CR_EXT_compiled_vertex_array
1413 SLC_COPYPTR(client.array.v.prevPtr);
1414 SLC_COPYPTR(client.array.c.prevPtr);
1415 SLC_COPYPTR(client.array.f.prevPtr);
1416 SLC_COPYPTR(client.array.s.prevPtr);
1417 SLC_COPYPTR(client.array.e.prevPtr);
1418 SLC_COPYPTR(client.array.i.prevPtr);
1419 SLC_COPYPTR(client.array.n.prevPtr);
1420 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1421 {
1422 SLC_COPYPTR(client.array.t[i].prevPtr);
1423 }
1424
1425# ifdef CR_NV_vertex_program
1426 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1427 {
1428 SLC_COPYPTR(client.array.a[i].prevPtr);
1429 }
1430# endif
1431#endif
1432#endif
1433
1434#ifdef CR_ARB_vertex_buffer_object
1435 /*That just sets those pointers to NULL*/
1436 SLC_COPYPTR(client.array.v.buffer);
1437 SLC_COPYPTR(client.array.c.buffer);
1438 SLC_COPYPTR(client.array.f.buffer);
1439 SLC_COPYPTR(client.array.s.buffer);
1440 SLC_COPYPTR(client.array.e.buffer);
1441 SLC_COPYPTR(client.array.i.buffer);
1442 SLC_COPYPTR(client.array.n.buffer);
1443 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1444 {
1445 SLC_COPYPTR(client.array.t[i].buffer);
1446 }
1447# ifdef CR_NV_vertex_program
1448 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1449 {
1450 SLC_COPYPTR(client.array.a[i].buffer);
1451 }
1452# endif
1453#endif /*CR_ARB_vertex_buffer_object*/
1454
1455 /*@todo CR_NV_vertex_program*/
1456 crStateCopyEvalPtrs1D(pTmpContext->eval.eval1D, pContext->eval.eval1D);
1457 crStateCopyEvalPtrs2D(pTmpContext->eval.eval2D, pContext->eval.eval2D);
1458
1459 SLC_COPYPTR(feedback.buffer); /*@todo*/
1460 SLC_COPYPTR(selection.buffer); /*@todo*/
1461
1462 SLC_COPYPTR(lighting.light);
1463
1464 /*This one could be tricky if we're loading snapshot on host with different GPU*/
1465 SLC_COPYPTR(limits.extensions);
1466
1467#if CR_ARB_occlusion_query
1468 SLC_COPYPTR(occlusion.objects); /*@todo*/
1469#endif
1470
1471 SLC_COPYPTR(program.errorString);
1472 SLC_COPYPTR(program.programHash);
1473 SLC_COPYPTR(program.defaultVertexProgram);
1474 SLC_COPYPTR(program.defaultFragmentProgram);
1475
1476 /* Texture pointers */
1477 for (i=0; i<6; ++i)
1478 {
1479 SLC_COPYPTR(texture.base1D.level[i]);
1480 SLC_COPYPTR(texture.base2D.level[i]);
1481 SLC_COPYPTR(texture.base3D.level[i]);
1482 SLC_COPYPTR(texture.proxy1D.level[i]);
1483 SLC_COPYPTR(texture.proxy2D.level[i]);
1484 SLC_COPYPTR(texture.proxy3D.level[i]);
1485#ifdef CR_ARB_texture_cube_map
1486 SLC_COPYPTR(texture.baseCubeMap.level[i]);
1487 SLC_COPYPTR(texture.proxyCubeMap.level[i]);
1488#endif
1489#ifdef CR_NV_texture_rectangle
1490 SLC_COPYPTR(texture.baseRect.level[i]);
1491 SLC_COPYPTR(texture.proxyRect.level[i]);
1492#endif
1493 }
1494
1495 /* Load transform state */
1496 SLC_COPYPTR(transform.clipPlane);
1497 SLC_COPYPTR(transform.clip);
1498 /* Don't have to worry about pContext->transform.current as it'd be set in crStateSetCurrent call */
1499 /*SLC_COPYPTR(transform.currentStack);*/
1500 SLC_COPYPTR(transform.modelViewStack.stack);
1501 SLC_COPYPTR(transform.projectionStack.stack);
1502 SLC_COPYPTR(transform.colorStack.stack);
1503
1504 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1505 {
1506 SLC_COPYPTR(transform.textureStack[i].stack);
1507 }
1508 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1509 {
1510 SLC_COPYPTR(transform.programStack[i].stack);
1511 }
1512
1513#ifdef CR_OPENGL_VERSION_2_0
1514 SLC_COPYPTR(glsl.shaders);
1515 SLC_COPYPTR(glsl.programs);
1516#endif
1517
1518 /* Have to preserve original context id */
1519 CRASSERT(pTmpContext->id == pContext->id);
1520 /* Copy ordinary state to real context */
1521 crMemcpy(pContext, pTmpContext, sizeof(*pTmpContext));
1522 crFree(pTmpContext);
1523 pTmpContext = NULL;
1524
1525 /* Now deal with pointers */
1526
1527 /* Load transform state */
1528 rc = SSMR3GetMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
1529 AssertRCReturn(rc, rc);
1530 rc = SSMR3GetMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
1531 AssertRCReturn(rc, rc);
1532 rc = crStateLoadMatrixStack(&pContext->transform.modelViewStack, pSSM);
1533 AssertRCReturn(rc, rc);
1534 rc = crStateLoadMatrixStack(&pContext->transform.projectionStack, pSSM);
1535 AssertRCReturn(rc, rc);
1536 rc = crStateLoadMatrixStack(&pContext->transform.colorStack, pSSM);
1537 AssertRCReturn(rc, rc);
1538 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1539 {
1540 rc = crStateLoadMatrixStack(&pContext->transform.textureStack[i], pSSM);
1541 AssertRCReturn(rc, rc);
1542 }
1543 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1544 {
1545 rc = crStateLoadMatrixStack(&pContext->transform.programStack[i], pSSM);
1546 AssertRCReturn(rc, rc);
1547 }
1548
1549 /* Load Textures */
1550 rc = crStateLoadTextureObjData(&pContext->texture.base1D, pSSM);
1551 AssertRCReturn(rc, rc);
1552 rc = crStateLoadTextureObjData(&pContext->texture.base2D, pSSM);
1553 AssertRCReturn(rc, rc);
1554 rc = crStateLoadTextureObjData(&pContext->texture.base3D, pSSM);
1555 AssertRCReturn(rc, rc);
1556 rc = crStateLoadTextureObjData(&pContext->texture.proxy1D, pSSM);
1557 AssertRCReturn(rc, rc);
1558 rc = crStateLoadTextureObjData(&pContext->texture.proxy2D, pSSM);
1559 AssertRCReturn(rc, rc);
1560 rc = crStateLoadTextureObjData(&pContext->texture.proxy3D, pSSM);
1561 AssertRCReturn(rc, rc);
1562#ifdef CR_ARB_texture_cube_map
1563 rc = crStateLoadTextureObjData(&pContext->texture.baseCubeMap, pSSM);
1564 AssertRCReturn(rc, rc);
1565 rc = crStateLoadTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
1566 AssertRCReturn(rc, rc);
1567#endif
1568#ifdef CR_NV_texture_rectangle
1569 rc = crStateLoadTextureObjData(&pContext->texture.baseRect, pSSM);
1570 AssertRCReturn(rc, rc);
1571 rc = crStateLoadTextureObjData(&pContext->texture.proxyRect, pSSM);
1572 AssertRCReturn(rc, rc);
1573#endif
1574
1575 if (bLoadShared)
1576 {
1577 /* Load shared textures */
1578 CRASSERT(pContext->shared && pContext->shared->textureTable);
1579 rc = SSMR3GetU32(pSSM, &uiNumElems);
1580 AssertRCReturn(rc, rc);
1581 for (ui=0; ui<uiNumElems; ++ui)
1582 {
1583 CRTextureObj *pTexture;
1584
1585 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1586 AssertRCReturn(rc, rc);
1587
1588 pTexture = (CRTextureObj *) crCalloc(sizeof(CRTextureObj));
1589 if (!pTexture) return VERR_NO_MEMORY;
1590
1591 rc = SSMR3GetMem(pSSM, pTexture, sizeof(*pTexture));
1592 AssertRCReturn(rc, rc);
1593
1594 pTexture->hwid = 0;
1595
1596 /*allocate actual memory*/
1597 for (i=0; i<6; ++i) {
1598 pTexture->level[i] = (CRTextureLevel *) crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
1599 if (!pTexture->level[i]) return VERR_NO_MEMORY;
1600 }
1601
1602 rc = crStateLoadTextureObjData(pTexture, pSSM);
1603 AssertRCReturn(rc, rc);
1604
1605 crHashtableAdd(pContext->shared->textureTable, key, pTexture);
1606 }
1607 }
1608
1609 /* Load current texture pointers */
1610 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
1611 {
1612 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pContext, pSSM);
1613 AssertRCReturn(rc, rc);
1614 }
1615
1616 /* Mark textures for resending to GPU */
1617 pContext->texture.bResyncNeeded = GL_TRUE;
1618
1619 /* Load lights */
1620 CRASSERT(pContext->lighting.light);
1621 rc = SSMR3GetMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
1622 AssertRCReturn(rc, rc);
1623
1624 /* Load attrib stack*/
1625 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1626 {
1627 if (pContext->attrib.enableStack[i].clip)
1628 {
1629 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].clip,
1630 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1631 AssertRCReturn(rc, rc);
1632 }
1633
1634 if (pContext->attrib.enableStack[i].light)
1635 {
1636 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].light,
1637 pContext->limits.maxLights*sizeof(GLboolean));
1638 AssertRCReturn(rc, rc);
1639 }
1640
1641 if (pContext->attrib.lightingStack[i].light)
1642 {
1643 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.lightingStack[i].light,
1644 pContext->limits.maxLights*sizeof(CRLight));
1645 AssertRCReturn(rc, rc);
1646 }
1647
1648 for (k=0; k<pContext->limits.maxTextureUnits; ++k)
1649 {
1650 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[k], pContext, pSSM);
1651 AssertRCReturn(rc, rc);
1652 }
1653
1654 if (pContext->attrib.transformStack[i].clip)
1655 {
1656 rc = crStateAllocAndSSMR3GetMem(pSSM, (void*)&pContext->attrib.transformStack[i].clip,
1657 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1658 AssertRCReturn(rc, rc);
1659 }
1660
1661 if (pContext->attrib.transformStack[i].clipPlane)
1662 {
1663 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.transformStack[i].clipPlane,
1664 pContext->limits.maxClipPlanes*sizeof(GLvectord));
1665 AssertRCReturn(rc, rc);
1666 }
1667 rc = crSateLoadEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, GL_TRUE, pSSM);
1668 AssertRCReturn(rc, rc);
1669 rc = crSateLoadEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, GL_TRUE, pSSM);
1670 AssertRCReturn(rc, rc);
1671 }
1672
1673 /* Load evaluator coeffs */
1674 rc = crSateLoadEvalCoeffs1D(pContext->eval.eval1D, GL_FALSE, pSSM);
1675 AssertRCReturn(rc, rc);
1676 rc = crSateLoadEvalCoeffs2D(pContext->eval.eval2D, GL_FALSE, pSSM);
1677 AssertRCReturn(rc, rc);
1678
1679 /* Load buffer objects */
1680#ifdef CR_ARB_vertex_buffer_object
1681 rc = SSMR3GetU32(pSSM, &uiNumElems);
1682 AssertRCReturn(rc, rc);
1683 for (ui=0; ui<=uiNumElems; ++ui) /*ui<=uiNumElems to load nullBuffer in same loop*/
1684 {
1685 CRBufferObject *pBufferObj;
1686
1687 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1688 AssertRCReturn(rc, rc);
1689
1690 /* default one should be already allocated */
1691 if (key==0)
1692 {
1693 pBufferObj = pContext->bufferobject.nullBuffer;
1694 if (!pBufferObj) return VERR_SSM_UNEXPECTED_DATA;
1695 }
1696 else
1697 {
1698 pBufferObj = (CRBufferObject *) crCalloc(sizeof(*pBufferObj));
1699 if (!pBufferObj) return VERR_NO_MEMORY;
1700 }
1701
1702 rc = SSMR3GetMem(pSSM, pBufferObj, sizeof(*pBufferObj));
1703 AssertRCReturn(rc, rc);
1704
1705 pBufferObj->hwid = 0;
1706
1707 if (pBufferObj->data)
1708 {
1709 CRASSERT(pBufferObj->size>0);
1710 pBufferObj->data = crAlloc(pBufferObj->size);
1711 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
1712 AssertRCReturn(rc, rc);
1713 }
1714 else if (pBufferObj->id!=0 && pBufferObj->size>0)
1715 {
1716 rc = SSMR3GetMem(pSSM, &pBufferObj->data, sizeof(pBufferObj->data));
1717 AssertRCReturn(rc, rc);
1718
1719 if (pBufferObj->data)
1720 {
1721 pBufferObj->data = crAlloc(pBufferObj->size);
1722 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
1723 AssertRCReturn(rc, rc);
1724 }
1725 }
1726
1727
1728 if (key!=0)
1729 crHashtableAdd(pContext->shared->buffersTable, key, pBufferObj);
1730 }
1731 /* Load pointers */
1732#define CRS_GET_BO(name) (((name)==0) ? (pContext->bufferobject.nullBuffer) : crHashtableSearch(pContext->shared->buffersTable, name))
1733 rc = SSMR3GetU32(pSSM, &ui);
1734 AssertRCReturn(rc, rc);
1735 pContext->bufferobject.arrayBuffer = CRS_GET_BO(ui);
1736 rc = SSMR3GetU32(pSSM, &ui);
1737 AssertRCReturn(rc, rc);
1738 pContext->bufferobject.elementsBuffer = CRS_GET_BO(ui);
1739#ifdef CR_ARB_pixel_buffer_object
1740 rc = SSMR3GetU32(pSSM, &ui);
1741 AssertRCReturn(rc, rc);
1742 pContext->bufferobject.packBuffer = CRS_GET_BO(ui);
1743 rc = SSMR3GetU32(pSSM, &ui);
1744 AssertRCReturn(rc, rc);
1745 pContext->bufferobject.unpackBuffer = CRS_GET_BO(ui);
1746#endif
1747#undef CRS_GET_BO
1748
1749 /* Load client pointers and array buffer bindings*/
1750 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1751 {
1752 rc = crStateLoadClientPointer(&pContext->client.array, i, pContext, pSSM);
1753 AssertRCReturn(rc, rc);
1754 }
1755 for (j=0; j<pContext->client.vertexArrayStackDepth; ++j)
1756 {
1757 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[j];
1758 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1759 {
1760 rc = crStateLoadClientPointer(pArray, i, pContext, pSSM);
1761 AssertRCReturn(rc, rc);
1762 }
1763 }
1764
1765 pContext->bufferobject.bResyncNeeded = GL_TRUE;
1766#endif
1767
1768 /* Load pixel/vertex programs */
1769 rc = SSMR3GetU32(pSSM, &uiNumElems);
1770 AssertRCReturn(rc, rc);
1771 /* Load defaults programs */
1772 rc = crStateLoadProgram(&pContext->program.defaultVertexProgram, pSSM);
1773 AssertRCReturn(rc, rc);
1774 rc = crStateLoadProgram(&pContext->program.defaultFragmentProgram, pSSM);
1775 AssertRCReturn(rc, rc);
1776 /* Load all the rest */
1777 for (ui=0; ui<uiNumElems; ++ui)
1778 {
1779 CRProgram *pProgram = NULL;
1780 rc = crStateLoadProgram(&pProgram, pSSM);
1781 AssertRCReturn(rc, rc);
1782 crHashtableAdd(pContext->program.programHash, pProgram->id, pProgram);
1783 //DIRTY(pProgram->dirtyProgram, pContext->neg_bitid);
1784
1785 }
1786 /* Load Pointers */
1787 rc = SSMR3GetU32(pSSM, &ui);
1788 AssertRCReturn(rc, rc);
1789 pContext->program.currentVertexProgram = ui==0 ? pContext->program.defaultVertexProgram
1790 : crHashtableSearch(pContext->program.programHash, ui);
1791 rc = SSMR3GetU32(pSSM, &ui);
1792 AssertRCReturn(rc, rc);
1793 pContext->program.currentFragmentProgram = ui==0 ? pContext->program.defaultFragmentProgram
1794 : crHashtableSearch(pContext->program.programHash, ui);
1795
1796 /* Mark programs for resending to GPU */
1797 pContext->program.bResyncNeeded = GL_TRUE;
1798
1799#ifdef CR_EXT_framebuffer_object
1800 /* Load FBOs */
1801 if (bLoadShared)
1802 {
1803 rc = SSMR3GetU32(pSSM, &uiNumElems);
1804 AssertRCReturn(rc, rc);
1805 for (ui=0; ui<uiNumElems; ++ui)
1806 {
1807 CRFramebufferObject *pFBO;
1808 pFBO = crAlloc(sizeof(*pFBO));
1809 if (!pFBO) return VERR_NO_MEMORY;
1810
1811 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1812 AssertRCReturn(rc, rc);
1813
1814 rc = SSMR3GetMem(pSSM, pFBO, sizeof(*pFBO));
1815 AssertRCReturn(rc, rc);
1816
1817 crHashtableAdd(pContext->shared->fbTable, key, pFBO);
1818 }
1819
1820 rc = SSMR3GetU32(pSSM, &uiNumElems);
1821 AssertRCReturn(rc, rc);
1822 for (ui=0; ui<uiNumElems; ++ui)
1823 {
1824 CRRenderbufferObject *pRBO;
1825 pRBO = crAlloc(sizeof(*pRBO));
1826 if (!pRBO) return VERR_NO_MEMORY;
1827
1828 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1829 AssertRCReturn(rc, rc);
1830
1831 rc = SSMR3GetMem(pSSM, pRBO, sizeof(*pRBO));
1832 AssertRCReturn(rc, rc);
1833
1834 crHashtableAdd(pContext->shared->rbTable, key, pRBO);
1835 }
1836 }
1837
1838 rc = SSMR3GetU32(pSSM, &ui);
1839 AssertRCReturn(rc, rc);
1840 pContext->framebufferobject.drawFB = ui==0 ? NULL
1841 : crHashtableSearch(pContext->shared->fbTable, ui);
1842
1843 rc = SSMR3GetU32(pSSM, &ui);
1844 AssertRCReturn(rc, rc);
1845 pContext->framebufferobject.readFB = ui==0 ? NULL
1846 : crHashtableSearch(pContext->shared->fbTable, ui);
1847
1848 rc = SSMR3GetU32(pSSM, &ui);
1849 AssertRCReturn(rc, rc);
1850 pContext->framebufferobject.renderbuffer = ui==0 ? NULL
1851 : crHashtableSearch(pContext->shared->rbTable, ui);
1852
1853 /* Mark FBOs/RBOs for resending to GPU */
1854 pContext->framebufferobject.bResyncNeeded = GL_TRUE;
1855#endif
1856
1857#ifdef CR_OPENGL_VERSION_2_0
1858 /* Load GLSL related info */
1859 rc = SSMR3GetU32(pSSM, &uiNumElems);
1860 AssertRCReturn(rc, rc);
1861
1862 for (ui=0; ui<uiNumElems; ++ui)
1863 {
1864 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
1865 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
1866 crHashtableAdd(pContext->glsl.shaders, pShader->id, pShader);
1867 }
1868
1869 rc = SSMR3GetU32(pSSM, &uiNumElems);
1870 AssertRCReturn(rc, rc);
1871
1872 for (ui=0; ui<uiNumElems; ++ui)
1873 {
1874 CRGLSLProgram *pProgram;
1875 uint32_t numShaders;
1876
1877 pProgram = crAlloc(sizeof(*pProgram));
1878 if (!pProgram) return VERR_NO_MEMORY;
1879
1880 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1881 AssertRCReturn(rc, rc);
1882
1883 rc = SSMR3GetMem(pSSM, pProgram, sizeof(*pProgram));
1884 AssertRCReturn(rc, rc);
1885
1886 crHashtableAdd(pContext->glsl.programs, key, pProgram);
1887
1888 pProgram->currentState.attachedShaders = crAllocHashtable();
1889
1890 rc = SSMR3GetU32(pSSM, &numShaders);
1891 AssertRCReturn(rc, rc);
1892
1893 for (k=0; k<numShaders; ++k)
1894 {
1895 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
1896 AssertRCReturn(rc, rc);
1897 crHashtableAdd(pProgram->currentState.attachedShaders, key, crHashtableSearch(pContext->glsl.shaders, key));
1898 }
1899
1900 if (pProgram->activeState.attachedShaders)
1901 {
1902 pProgram->activeState.attachedShaders = crAllocHashtable();
1903
1904 rc = SSMR3GetU32(pSSM, &numShaders);
1905 AssertRCReturn(rc, rc);
1906
1907 for (k=0; k<numShaders; ++k)
1908 {
1909 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
1910 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
1911 crHashtableAdd(pProgram->activeState.attachedShaders, pShader->id, pShader);
1912 }
1913 }
1914
1915 if (pProgram->currentState.cAttribs)
1916 pProgram->currentState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->currentState.cAttribs*sizeof(CRGLSLAttrib));
1917 for (k=0; k<pProgram->currentState.cAttribs; ++k)
1918 {
1919 rc = SSMR3GetMem(pSSM, &pProgram->currentState.pAttribs[k].index, sizeof(pProgram->currentState.pAttribs[k].index));
1920 AssertRCReturn(rc, rc);
1921 pProgram->currentState.pAttribs[k].name = crStateLoadString(pSSM);
1922 }
1923
1924 if (pProgram->activeState.cAttribs)
1925 pProgram->activeState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->activeState.cAttribs*sizeof(CRGLSLAttrib));
1926 for (k=0; k<pProgram->activeState.cAttribs; ++k)
1927 {
1928 rc = SSMR3GetMem(pSSM, &pProgram->activeState.pAttribs[k].index, sizeof(pProgram->activeState.pAttribs[k].index));
1929 AssertRCReturn(rc, rc);
1930 pProgram->activeState.pAttribs[k].name = crStateLoadString(pSSM);
1931 }
1932
1933 {
1934 int32_t cUniforms;
1935 rc = SSMR3GetS32(pSSM, &cUniforms);
1936 pProgram->cUniforms = cUniforms;
1937 AssertRCReturn(rc, rc);
1938 }
1939
1940 if (pProgram->cUniforms)
1941 {
1942 pProgram->pUniforms = crAlloc(pProgram->cUniforms*sizeof(CRGLSLUniform));
1943 if (!pProgram->pUniforms) return VERR_NO_MEMORY;
1944
1945 for (k=0; k<pProgram->cUniforms; ++k)
1946 {
1947 size_t itemsize, datasize;
1948
1949 rc = SSMR3GetMem(pSSM, &pProgram->pUniforms[k].type, sizeof(GLenum));
1950 pProgram->pUniforms[k].name = crStateLoadString(pSSM);
1951
1952 if (crStateIsIntUniform(pProgram->pUniforms[k].type))
1953 {
1954 itemsize = sizeof(GLint);
1955 } else itemsize = sizeof(GLfloat);
1956
1957 datasize = crStateGetUniformSize(pProgram->pUniforms[k].type)*itemsize;
1958 pProgram->pUniforms[k].data = crAlloc(datasize);
1959 if (!pProgram->pUniforms[k].data) return VERR_NO_MEMORY;
1960
1961 rc = SSMR3GetMem(pSSM, pProgram->pUniforms[k].data, datasize);
1962 }
1963 }
1964 }
1965
1966 rc = SSMR3GetU32(pSSM, &ui);
1967 AssertRCReturn(rc, rc);
1968 pContext->glsl.activeProgram = ui==0 ? NULL
1969 : crHashtableSearch(pContext->glsl.programs, ui);
1970
1971 /*Mark for resending to GPU*/
1972 pContext->glsl.bResyncNeeded = GL_TRUE;
1973#endif
1974
1975
1976 /*Restore front buffer image*/
1977 {
1978 CRViewportState *pVP = &pContext->viewport;
1979 GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
1980 void *pData = crAlloc(cbData);
1981
1982 if (!pData)
1983 {
1984 pContext->pImage = NULL;
1985 return VERR_NO_MEMORY;
1986 }
1987
1988 rc = SSMR3GetMem(pSSM, pData, cbData);
1989 AssertRCReturn(rc, rc);
1990
1991 pContext->pImage = pData;
1992 }
1993
1994
1995 /*Mark all as dirty to make sure we'd restore correct context state*/
1996 {
1997 CRStateBits *pBits = GetCurrentBits();
1998
1999 FILLDIRTY(pBits->attrib.dirty);
2000
2001 FILLDIRTY(pBits->buffer.dirty);
2002 FILLDIRTY(pBits->buffer.enable);
2003 FILLDIRTY(pBits->buffer.alphaFunc);
2004 FILLDIRTY(pBits->buffer.depthFunc);
2005 FILLDIRTY(pBits->buffer.blendFunc);
2006 FILLDIRTY(pBits->buffer.logicOp);
2007 FILLDIRTY(pBits->buffer.indexLogicOp);
2008 FILLDIRTY(pBits->buffer.drawBuffer);
2009 FILLDIRTY(pBits->buffer.readBuffer);
2010 FILLDIRTY(pBits->buffer.indexMask);
2011 FILLDIRTY(pBits->buffer.colorWriteMask);
2012 FILLDIRTY(pBits->buffer.clearColor);
2013 FILLDIRTY(pBits->buffer.clearIndex);
2014 FILLDIRTY(pBits->buffer.clearDepth);
2015 FILLDIRTY(pBits->buffer.clearAccum);
2016 FILLDIRTY(pBits->buffer.depthMask);
2017#ifdef CR_EXT_blend_color
2018 FILLDIRTY(pBits->buffer.blendColor);
2019#endif
2020#if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
2021 FILLDIRTY(pBits->buffer.blendEquation);
2022#endif
2023#if defined(CR_EXT_blend_func_separate)
2024 FILLDIRTY(pBits->buffer.blendFuncSeparate);
2025#endif
2026
2027#ifdef CR_ARB_vertex_buffer_object
2028 FILLDIRTY(pBits->bufferobject.dirty);
2029 FILLDIRTY(pBits->bufferobject.arrayBinding);
2030 FILLDIRTY(pBits->bufferobject.elementsBinding);
2031# ifdef CR_ARB_pixel_buffer_object
2032 FILLDIRTY(pBits->bufferobject.packBinding);
2033 FILLDIRTY(pBits->bufferobject.unpackBinding);
2034# endif
2035#endif
2036
2037 FILLDIRTY(pBits->client.dirty);
2038 FILLDIRTY(pBits->client.pack);
2039 FILLDIRTY(pBits->client.unpack);
2040 FILLDIRTY(pBits->client.enableClientState);
2041 FILLDIRTY(pBits->client.clientPointer);
2042 FILLDIRTY(pBits->client.v);
2043 FILLDIRTY(pBits->client.n);
2044 FILLDIRTY(pBits->client.c);
2045 FILLDIRTY(pBits->client.i);
2046 FILLDIRTY(pBits->client.e);
2047 FILLDIRTY(pBits->client.s);
2048 FILLDIRTY(pBits->client.f);
2049 for (i=0; i<CR_MAX_TEXTURE_UNITS; i++)
2050 {
2051 FILLDIRTY(pBits->client.t[i]);
2052 }
2053#ifdef CR_NV_vertex_program
2054 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
2055 {
2056 FILLDIRTY(pBits->client.a[i]);
2057 }
2058#endif
2059
2060 FILLDIRTY(pBits->current.dirty);
2061 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; i++)
2062 {
2063 FILLDIRTY(pBits->current.vertexAttrib[i]);
2064 }
2065 FILLDIRTY(pBits->current.edgeFlag);
2066 FILLDIRTY(pBits->current.colorIndex);
2067 FILLDIRTY(pBits->current.rasterPos);
2068
2069
2070 FILLDIRTY(pBits->eval.dirty);
2071 for (i=0; i<GLEVAL_TOT; i++)
2072 {
2073 FILLDIRTY(pBits->eval.eval1D[i]);
2074 FILLDIRTY(pBits->eval.eval2D[i]);
2075 FILLDIRTY(pBits->eval.enable1D[i]);
2076 FILLDIRTY(pBits->eval.enable2D[i]);
2077 }
2078 FILLDIRTY(pBits->eval.enable);
2079 FILLDIRTY(pBits->eval.grid1D);
2080 FILLDIRTY(pBits->eval.grid2D);
2081#ifdef CR_NV_vertex_program
2082 /*@todo Those seems to be unused?
2083 FILLDIRTY(pBits->eval.enableAttrib1D);
2084 FILLDIRTY(pBits->eval.enableAttrib2D);
2085 */
2086#endif
2087
2088 FILLDIRTY(pBits->feedback.dirty);
2089 FILLDIRTY(pBits->selection.dirty);
2090
2091 FILLDIRTY(pBits->fog.dirty);
2092 FILLDIRTY(pBits->fog.color);
2093 FILLDIRTY(pBits->fog.index);
2094 FILLDIRTY(pBits->fog.density);
2095 FILLDIRTY(pBits->fog.start);
2096 FILLDIRTY(pBits->fog.end);
2097 FILLDIRTY(pBits->fog.mode);
2098 FILLDIRTY(pBits->fog.enable);
2099#ifdef CR_NV_fog_distance
2100 FILLDIRTY(pBits->fog.fogDistanceMode);
2101#endif
2102#ifdef CR_EXT_fog_coord
2103 FILLDIRTY(pBits->fog.fogCoordinateSource);
2104#endif
2105
2106 FILLDIRTY(pBits->hint.dirty);
2107 FILLDIRTY(pBits->hint.perspectiveCorrection);
2108 FILLDIRTY(pBits->hint.pointSmooth);
2109 FILLDIRTY(pBits->hint.lineSmooth);
2110 FILLDIRTY(pBits->hint.polygonSmooth);
2111 FILLDIRTY(pBits->hint.fog);
2112#ifdef CR_EXT_clip_volume_hint
2113 FILLDIRTY(pBits->hint.clipVolumeClipping);
2114
2115#endif
2116#ifdef CR_ARB_texture_compression
2117 FILLDIRTY(pBits->hint.textureCompression);
2118#endif
2119#ifdef CR_SGIS_generate_mipmap
2120 FILLDIRTY(pBits->hint.generateMipmap);
2121#endif
2122
2123 FILLDIRTY(pBits->lighting.dirty);
2124 FILLDIRTY(pBits->lighting.shadeModel);
2125 FILLDIRTY(pBits->lighting.colorMaterial);
2126 FILLDIRTY(pBits->lighting.lightModel);
2127 FILLDIRTY(pBits->lighting.material);
2128 FILLDIRTY(pBits->lighting.enable);
2129 for (i=0; i<CR_MAX_LIGHTS; ++i)
2130 {
2131 FILLDIRTY(pBits->lighting.light[i].dirty);
2132 FILLDIRTY(pBits->lighting.light[i].enable);
2133 FILLDIRTY(pBits->lighting.light[i].ambient);
2134 FILLDIRTY(pBits->lighting.light[i].diffuse);
2135 FILLDIRTY(pBits->lighting.light[i].specular);
2136 FILLDIRTY(pBits->lighting.light[i].position);
2137 FILLDIRTY(pBits->lighting.light[i].attenuation);
2138 FILLDIRTY(pBits->lighting.light[i].spot);
2139 }
2140
2141 FILLDIRTY(pBits->line.dirty);
2142 FILLDIRTY(pBits->line.enable);
2143 FILLDIRTY(pBits->line.width);
2144 FILLDIRTY(pBits->line.stipple);
2145
2146 FILLDIRTY(pBits->lists.dirty);
2147 FILLDIRTY(pBits->lists.base);
2148
2149 FILLDIRTY(pBits->multisample.dirty);
2150 FILLDIRTY(pBits->multisample.enable);
2151 FILLDIRTY(pBits->multisample.sampleAlphaToCoverage);
2152 FILLDIRTY(pBits->multisample.sampleAlphaToOne);
2153 FILLDIRTY(pBits->multisample.sampleCoverage);
2154 FILLDIRTY(pBits->multisample.sampleCoverageValue);
2155
2156#if CR_ARB_occlusion_query
2157 FILLDIRTY(pBits->occlusion.dirty);
2158#endif
2159
2160 FILLDIRTY(pBits->pixel.dirty);
2161 FILLDIRTY(pBits->pixel.transfer);
2162 FILLDIRTY(pBits->pixel.zoom);
2163 FILLDIRTY(pBits->pixel.maps);
2164
2165 FILLDIRTY(pBits->point.dirty);
2166 FILLDIRTY(pBits->point.enableSmooth);
2167 FILLDIRTY(pBits->point.size);
2168#ifdef CR_ARB_point_parameters
2169 FILLDIRTY(pBits->point.minSize);
2170 FILLDIRTY(pBits->point.maxSize);
2171 FILLDIRTY(pBits->point.fadeThresholdSize);
2172 FILLDIRTY(pBits->point.distanceAttenuation);
2173#endif
2174#ifdef CR_ARB_point_sprite
2175 FILLDIRTY(pBits->point.enableSprite);
2176 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
2177 {
2178 FILLDIRTY(pBits->point.coordReplacement[i]);
2179 }
2180#endif
2181
2182 FILLDIRTY(pBits->polygon.dirty);
2183 FILLDIRTY(pBits->polygon.enable);
2184 FILLDIRTY(pBits->polygon.offset);
2185 FILLDIRTY(pBits->polygon.mode);
2186 FILLDIRTY(pBits->polygon.stipple);
2187
2188 FILLDIRTY(pBits->program.dirty);
2189 FILLDIRTY(pBits->program.vpEnable);
2190 FILLDIRTY(pBits->program.fpEnable);
2191 FILLDIRTY(pBits->program.vpBinding);
2192 FILLDIRTY(pBits->program.fpBinding);
2193 for (i=0; i<CR_MAX_VERTEX_ATTRIBS; ++i)
2194 {
2195 FILLDIRTY(pBits->program.vertexAttribArrayEnable[i]);
2196 FILLDIRTY(pBits->program.map1AttribArrayEnable[i]);
2197 FILLDIRTY(pBits->program.map2AttribArrayEnable[i]);
2198 }
2199 for (i=0; i<CR_MAX_VERTEX_PROGRAM_ENV_PARAMS; ++i)
2200 {
2201 FILLDIRTY(pBits->program.vertexEnvParameter[i]);
2202 }
2203 for (i=0; i<CR_MAX_FRAGMENT_PROGRAM_ENV_PARAMS; ++i)
2204 {
2205 FILLDIRTY(pBits->program.fragmentEnvParameter[i]);
2206 }
2207 FILLDIRTY(pBits->program.vertexEnvParameters);
2208 FILLDIRTY(pBits->program.fragmentEnvParameters);
2209 for (i=0; i<CR_MAX_VERTEX_PROGRAM_ENV_PARAMS/4; ++i)
2210 {
2211 FILLDIRTY(pBits->program.trackMatrix[i]);
2212 }
2213
2214 FILLDIRTY(pBits->regcombiner.dirty);
2215 FILLDIRTY(pBits->regcombiner.enable);
2216 FILLDIRTY(pBits->regcombiner.regCombinerVars);
2217 FILLDIRTY(pBits->regcombiner.regCombinerColor0);
2218 FILLDIRTY(pBits->regcombiner.regCombinerColor1);
2219 for (i=0; i<CR_MAX_GENERAL_COMBINERS; ++i)
2220 {
2221 FILLDIRTY(pBits->regcombiner.regCombinerStageColor0[i]);
2222 FILLDIRTY(pBits->regcombiner.regCombinerStageColor1[i]);
2223 FILLDIRTY(pBits->regcombiner.regCombinerInput[i]);
2224 FILLDIRTY(pBits->regcombiner.regCombinerOutput[i]);
2225 }
2226 FILLDIRTY(pBits->regcombiner.regCombinerFinalInput);
2227
2228 FILLDIRTY(pBits->stencil.dirty);
2229 FILLDIRTY(pBits->stencil.enable);
2230 FILLDIRTY(pBits->stencil.func);
2231 FILLDIRTY(pBits->stencil.op);
2232 FILLDIRTY(pBits->stencil.clearValue);
2233 FILLDIRTY(pBits->stencil.writeMask);
2234
2235 FILLDIRTY(pBits->texture.dirty);
2236 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
2237 {
2238 FILLDIRTY(pBits->texture.enable[i]);
2239 FILLDIRTY(pBits->texture.current[i]);
2240 FILLDIRTY(pBits->texture.objGen[i]);
2241 FILLDIRTY(pBits->texture.eyeGen[i]);
2242 FILLDIRTY(pBits->texture.genMode[i]);
2243 FILLDIRTY(pBits->texture.envBit[i]);
2244 }
2245
2246 FILLDIRTY(pBits->transform.dirty);
2247 FILLDIRTY(pBits->transform.matrixMode);
2248 FILLDIRTY(pBits->transform.modelviewMatrix);
2249 FILLDIRTY(pBits->transform.projectionMatrix);
2250 FILLDIRTY(pBits->transform.colorMatrix);
2251 FILLDIRTY(pBits->transform.textureMatrix);
2252 FILLDIRTY(pBits->transform.programMatrix);
2253 FILLDIRTY(pBits->transform.clipPlane);
2254 FILLDIRTY(pBits->transform.enable);
2255 FILLDIRTY(pBits->transform.base);
2256
2257 FILLDIRTY(pBits->viewport.dirty);
2258 FILLDIRTY(pBits->viewport.v_dims);
2259 FILLDIRTY(pBits->viewport.s_dims);
2260 FILLDIRTY(pBits->viewport.enable);
2261 FILLDIRTY(pBits->viewport.depth);
2262 }
2263
2264 return VINF_SUCCESS;
2265}
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