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