VirtualBox

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

Last change on this file since 44802 was 44802, checked in by vboxsync, 12 years ago

crOpenGL: saved state: save depth and stencil buffer data (still needs more testing)

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

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