VirtualBox

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

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

crOpenGL: 1. stencil state fixes, 2. missing gets

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 88.4 KB
Line 
1/* $Id: state_snapshot.c 44326 2013-01-22 08:18:51Z vboxsync $ */
2
3/** @file
4 * VBox Context state saving/loading used by VM snapshot
5 */
6
7/*
8 * Copyright (C) 2008 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "state.h"
20#include "state_internals.h"
21#include "state/cr_statetypes.h"
22#include "state/cr_texture.h"
23#include "cr_mem.h"
24#include "cr_string.h"
25#include "cr_pixeldata.h"
26#include <stdio.h>
27
28#include <iprt/assert.h>
29#include <iprt/types.h>
30#include <iprt/err.h>
31#include <VBox/err.h>
32
33/* @todo
34 * We have two ways of saving/loading states.
35 *
36 * First which is being used atm, just pure saving/loading of structures.
37 * The drawback is we have to deal with all the pointers around those structures,
38 * we'd have to update this code if we'd change state tracking.
39 * On the bright side it's fast, though it's not really needed as it's not that often operation.
40 * It could also worth to split those functions into appropriate parts,
41 * similar to the way context creation is being done.
42 *
43 * Second way would be to implement full dispatch api table and substitute diff_api during saving/loading.
44 * Then if we implement that api in a similar way to packer/unpacker with a change to store/load
45 * via provided pSSM handle instead of pack buffer,
46 * saving state could be done by simple diffing against empty "dummy" context.
47 * Restoring state in such case would look like unpacking commands from pSSM instead of network buffer.
48 * This would be slower (who cares) but most likely will not require any code changes to support in future.
49 * We will reduce amount of saved data as we'd save only changed state parts, but I doubt it'd be that much.
50 * It could be done for the first way as well, but requires tons of bit checks.
51 */
52
53static int32_t crStateAllocAndSSMR3GetMem(PSSMHANDLE pSSM, void **pBuffer, size_t cbBuffer)
54{
55 CRASSERT(pSSM && pBuffer && cbBuffer>0);
56
57 *pBuffer = crAlloc(cbBuffer);
58 if (!*pBuffer)
59 return VERR_NO_MEMORY;
60
61 return SSMR3GetMem(pSSM, *pBuffer, cbBuffer);
62}
63
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 pContext->buffer.storedWidth = pContext->buffer.width;
1401 pContext->buffer.storedHeight = pContext->buffer.height;
1402
1403 CRASSERT(VBoxTlsRefIsFunctional(pContext));
1404
1405 /* make sure the gl error state is captured by our state mechanism to store the correct gl error value */
1406 crStateSyncHWErrorState(pContext);
1407
1408 rc = SSMR3PutMem(pSSM, pContext, sizeof (*pContext));
1409 AssertRCReturn(rc, rc);
1410
1411 if (crHashtableNumElements(pContext->shared->dlistTable)>0)
1412 crWarning("Saving state with %d display lists, unsupported", crHashtableNumElements(pContext->shared->dlistTable));
1413
1414 if (crHashtableNumElements(pContext->program.programHash)>0)
1415 crDebug("Saving state with %d programs", crHashtableNumElements(pContext->program.programHash));
1416
1417 rc = SSMR3PutS32(pSSM, pContext->shared->id);
1418 AssertRCReturn(rc, rc);
1419
1420 rc = SSMR3PutS32(pSSM, crStateContextIsShared(pContext));
1421 AssertRCReturn(rc, rc);
1422
1423 if (pContext->shared->refCount>1)
1424 {
1425 bSaveShared = pContext->shared->saveCount==0;
1426
1427 ++pContext->shared->saveCount;
1428 if (pContext->shared->saveCount == pContext->shared->refCount)
1429 {
1430 pContext->shared->saveCount=0;
1431 }
1432 }
1433
1434 /* Save transform state */
1435 rc = SSMR3PutMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
1436 AssertRCReturn(rc, rc);
1437 rc = SSMR3PutMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
1438 AssertRCReturn(rc, rc);
1439 rc = crStateSaveMatrixStack(&pContext->transform.modelViewStack, pSSM);
1440 AssertRCReturn(rc, rc);
1441 rc = crStateSaveMatrixStack(&pContext->transform.projectionStack, pSSM);
1442 AssertRCReturn(rc, rc);
1443 rc = crStateSaveMatrixStack(&pContext->transform.colorStack, pSSM);
1444 AssertRCReturn(rc, rc);
1445 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1446 {
1447 rc = crStateSaveMatrixStack(&pContext->transform.textureStack[i], pSSM);
1448 AssertRCReturn(rc, rc);
1449 }
1450 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
1451 {
1452 rc = crStateSaveMatrixStack(&pContext->transform.programStack[i], pSSM);
1453 AssertRCReturn(rc, rc);
1454 }
1455
1456 /* Save textures */
1457 rc = crStateSaveTextureObjData(&pContext->texture.base1D, pSSM);
1458 AssertRCReturn(rc, rc);
1459 rc = crStateSaveTextureObjData(&pContext->texture.base2D, pSSM);
1460 AssertRCReturn(rc, rc);
1461 rc = crStateSaveTextureObjData(&pContext->texture.base3D, pSSM);
1462 AssertRCReturn(rc, rc);
1463 rc = crStateSaveTextureObjData(&pContext->texture.proxy1D, pSSM);
1464 AssertRCReturn(rc, rc);
1465 rc = crStateSaveTextureObjData(&pContext->texture.proxy2D, pSSM);
1466 AssertRCReturn(rc, rc);
1467 rc = crStateSaveTextureObjData(&pContext->texture.proxy3D, pSSM);
1468#ifdef CR_ARB_texture_cube_map
1469 rc = crStateSaveTextureObjData(&pContext->texture.baseCubeMap, pSSM);
1470 AssertRCReturn(rc, rc);
1471 rc = crStateSaveTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
1472 AssertRCReturn(rc, rc);
1473#endif
1474#ifdef CR_NV_texture_rectangle
1475 rc = crStateSaveTextureObjData(&pContext->texture.baseRect, pSSM);
1476 AssertRCReturn(rc, rc);
1477 rc = crStateSaveTextureObjData(&pContext->texture.proxyRect, pSSM);
1478 AssertRCReturn(rc, rc);
1479#endif
1480
1481 /* Save shared textures */
1482 if (bSaveShared)
1483 {
1484 CRASSERT(pContext->shared && pContext->shared->textureTable);
1485 ui32 = crHashtableNumElements(pContext->shared->textureTable);
1486 rc = SSMR3PutU32(pSSM, ui32);
1487 AssertRCReturn(rc, rc);
1488 crHashtableWalk(pContext->shared->textureTable, crStateSaveSharedTextureCB, pSSM);
1489
1490#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
1491 /* Restore previous texture bindings via diff_api */
1492 if (ui32)
1493 {
1494 CRTextureUnit *pTexUnit;
1495
1496 pTexUnit = &pContext->texture.unit[pContext->texture.curTextureUnit];
1497
1498 diff_api.BindTexture(GL_TEXTURE_1D, pTexUnit->currentTexture1D->hwid);
1499 diff_api.BindTexture(GL_TEXTURE_2D, pTexUnit->currentTexture2D->hwid);
1500 diff_api.BindTexture(GL_TEXTURE_3D, pTexUnit->currentTexture3D->hwid);
1501#ifdef CR_ARB_texture_cube_map
1502 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, pTexUnit->currentTextureCubeMap->hwid);
1503#endif
1504#ifdef CR_NV_texture_rectangle
1505 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, pTexUnit->currentTextureRect->hwid);
1506#endif
1507 }
1508#endif
1509 }
1510
1511 /* Save current texture pointers */
1512 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
1513 {
1514 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pSSM);
1515 AssertRCReturn(rc, rc);
1516 }
1517
1518 /* Save lights */
1519 CRASSERT(pContext->lighting.light);
1520 rc = SSMR3PutMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
1521 AssertRCReturn(rc, rc);
1522
1523 /* Save attrib stack*/
1524 /*@todo could go up to used stack depth here?*/
1525 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1526 {
1527 if (pContext->attrib.enableStack[i].clip)
1528 {
1529 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].clip,
1530 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1531 AssertRCReturn(rc, rc);
1532 }
1533
1534 if (pContext->attrib.enableStack[i].light)
1535 {
1536 rc = SSMR3PutMem(pSSM, pContext->attrib.enableStack[i].light,
1537 pContext->limits.maxLights*sizeof(GLboolean));
1538 AssertRCReturn(rc, rc);
1539 }
1540
1541 if (pContext->attrib.lightingStack[i].light)
1542 {
1543 rc = SSMR3PutMem(pSSM, pContext->attrib.lightingStack[i].light,
1544 pContext->limits.maxLights*sizeof(CRLight));
1545 AssertRCReturn(rc, rc);
1546 }
1547
1548 for (j=0; j<pContext->limits.maxTextureUnits; ++j)
1549 {
1550 rc = crStateSaveTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[j], pSSM);
1551 AssertRCReturn(rc, rc);
1552 }
1553
1554 if (pContext->attrib.transformStack[i].clip)
1555 {
1556 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clip,
1557 pContext->limits.maxClipPlanes*sizeof(GLboolean));
1558 AssertRCReturn(rc, rc);
1559 }
1560
1561 if (pContext->attrib.transformStack[i].clipPlane)
1562 {
1563 rc = SSMR3PutMem(pSSM, pContext->attrib.transformStack[i].clipPlane,
1564 pContext->limits.maxClipPlanes*sizeof(GLvectord));
1565 AssertRCReturn(rc, rc);
1566 }
1567
1568 rc = crSateSaveEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, pSSM);
1569 AssertRCReturn(rc, rc);
1570 rc = crSateSaveEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, pSSM);
1571 AssertRCReturn(rc, rc);
1572 }
1573
1574 /* Save evaluator coeffs */
1575 rc = crSateSaveEvalCoeffs1D(pContext->eval.eval1D, pSSM);
1576 AssertRCReturn(rc, rc);
1577 rc = crSateSaveEvalCoeffs2D(pContext->eval.eval2D, pSSM);
1578 AssertRCReturn(rc, rc);
1579
1580#ifdef CR_ARB_vertex_buffer_object
1581 /* Save buffer objects */
1582 ui32 = bSaveShared? crHashtableNumElements(pContext->shared->buffersTable):0;
1583 rc = SSMR3PutU32(pSSM, ui32);
1584 AssertRCReturn(rc, rc);
1585
1586 /* Save default one*/
1587 crStateSaveBufferObjectCB(0, pContext->bufferobject.nullBuffer, pSSM);
1588
1589 if (bSaveShared)
1590 {
1591 /* Save all the rest */
1592 crHashtableWalk(pContext->shared->buffersTable, crStateSaveBufferObjectCB, pSSM);
1593 }
1594
1595 /* Restore binding */
1596 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->hwid);
1597
1598 /* Save pointers */
1599 rc = SSMR3PutU32(pSSM, pContext->bufferobject.arrayBuffer->id);
1600 AssertRCReturn(rc, rc);
1601 rc = SSMR3PutU32(pSSM, pContext->bufferobject.elementsBuffer->id);
1602 AssertRCReturn(rc, rc);
1603#ifdef CR_ARB_pixel_buffer_object
1604 rc = SSMR3PutU32(pSSM, pContext->bufferobject.packBuffer->id);
1605 AssertRCReturn(rc, rc);
1606 rc = SSMR3PutU32(pSSM, pContext->bufferobject.unpackBuffer->id);
1607 AssertRCReturn(rc, rc);
1608#endif
1609 /* Save clint pointers and buffer bindings*/
1610 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
1611 {
1612 rc = crStateSaveClientPointer(&pContext->client.array, i, pSSM);
1613 AssertRCReturn(rc, rc);
1614 }
1615
1616 crDebug("client.vertexArrayStackDepth %i", pContext->client.vertexArrayStackDepth);
1617 for (i=0; i<pContext->client.vertexArrayStackDepth; ++i)
1618 {
1619 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[i];
1620 for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
1621 {
1622 rc = crStateSaveClientPointer(pArray, j, pSSM);
1623 AssertRCReturn(rc, rc);
1624 }
1625 }
1626#endif /*CR_ARB_vertex_buffer_object*/
1627
1628 /* Save pixel/vertex programs */
1629 ui32 = crHashtableNumElements(pContext->program.programHash);
1630 rc = SSMR3PutU32(pSSM, ui32);
1631 AssertRCReturn(rc, rc);
1632 /* Save defaults programs */
1633 crStateSaveProgramCB(0, pContext->program.defaultVertexProgram, pSSM);
1634 crStateSaveProgramCB(0, pContext->program.defaultFragmentProgram, pSSM);
1635 /* Save all the rest */
1636 crHashtableWalk(pContext->program.programHash, crStateSaveProgramCB, pSSM);
1637 /* Save Pointers */
1638 rc = SSMR3PutU32(pSSM, pContext->program.currentVertexProgram->id);
1639 AssertRCReturn(rc, rc);
1640 rc = SSMR3PutU32(pSSM, pContext->program.currentFragmentProgram->id);
1641 AssertRCReturn(rc, rc);
1642 /* This one is unused it seems*/
1643 CRASSERT(!pContext->program.errorString);
1644
1645#ifdef CR_EXT_framebuffer_object
1646 /* Save FBOs */
1647 if (bSaveShared)
1648 {
1649 ui32 = crHashtableNumElements(pContext->shared->fbTable);
1650 rc = SSMR3PutU32(pSSM, ui32);
1651 AssertRCReturn(rc, rc);
1652 crHashtableWalk(pContext->shared->fbTable, crStateSaveFramebuffersCB, pSSM);
1653 ui32 = crHashtableNumElements(pContext->shared->rbTable);
1654 rc = SSMR3PutU32(pSSM, ui32);
1655 AssertRCReturn(rc, rc);
1656 crHashtableWalk(pContext->shared->rbTable, crStateSaveRenderbuffersCB, pSSM);
1657 }
1658 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.drawFB?pContext->framebufferobject.drawFB->id:0);
1659 AssertRCReturn(rc, rc);
1660 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.readFB?pContext->framebufferobject.readFB->id:0);
1661 AssertRCReturn(rc, rc);
1662 rc = SSMR3PutU32(pSSM, pContext->framebufferobject.renderbuffer?pContext->framebufferobject.renderbuffer->id:0);
1663 AssertRCReturn(rc, rc);
1664#endif
1665
1666#ifdef CR_OPENGL_VERSION_2_0
1667 /* Save GLSL related info */
1668 ui32 = crHashtableNumElements(pContext->glsl.shaders);
1669 rc = SSMR3PutU32(pSSM, ui32);
1670 AssertRCReturn(rc, rc);
1671 crHashtableWalk(pContext->glsl.shaders, crStateSaveGLSLShaderCB, pSSM);
1672 ui32 = crHashtableNumElements(pContext->glsl.programs);
1673 rc = SSMR3PutU32(pSSM, ui32);
1674 AssertRCReturn(rc, rc);
1675 crHashtableWalk(pContext->glsl.programs, crStateSaveGLSLProgramCB, pSSM);
1676 rc = SSMR3PutU32(pSSM, pContext->glsl.activeProgram?pContext->glsl.activeProgram->id:0);
1677 AssertRCReturn(rc, rc);
1678#endif
1679
1680 return VINF_SUCCESS;
1681}
1682
1683typedef struct _crFindSharedCtxParms {
1684 PFNCRSTATE_CONTEXT_GET pfnCtxGet;
1685 CRContext *pSrcCtx, *pDstCtx;
1686} crFindSharedCtxParms_t;
1687
1688static void crStateFindSharedCB(unsigned long key, void *data1, void *data2)
1689{
1690 crFindSharedCtxParms_t *pParms = (crFindSharedCtxParms_t *) data2;
1691 CRContext *pContext = pParms->pfnCtxGet(data1);
1692 (void) key;
1693
1694 if (pContext!=pParms->pSrcCtx && pContext->shared->id==pParms->pSrcCtx->shared->id)
1695 {
1696 pParms->pDstCtx->shared = pContext->shared;
1697 }
1698}
1699
1700int32_t crStateSaveGlobals(PSSMHANDLE pSSM)
1701{
1702 CRStateBits *pBits;
1703 int rc;
1704
1705 CRASSERT(g_cContexts >= 1);
1706 if (g_cContexts <= 1)
1707 return VINF_SUCCESS;
1708
1709 pBits = GetCurrentBits();
1710#define CRSTATE_BITS_OP(_var, _size) \
1711 rc = SSMR3PutMem(pSSM, (pBits->_var), _size); \
1712 AssertRCReturn(rc, rc);
1713#include "state_bits_globalop.h"
1714#undef CRSTATE_BITS_OP
1715 return VINF_SUCCESS;
1716}
1717
1718int32_t crStateLoadGlobals(PSSMHANDLE pSSM, uint32_t u32Version)
1719{
1720 CRStateBits *pBits;
1721 int rc;
1722 CRASSERT(g_cContexts >= 1);
1723 if (g_cContexts <= 1)
1724 return VINF_SUCCESS;
1725
1726 pBits = GetCurrentBits();
1727
1728 if (u32Version >= SHCROGL_SSM_VERSION_WITH_STATE_BITS)
1729 {
1730#define CRSTATE_BITS_OP(_var, _size) \
1731 rc = SSMR3GetMem(pSSM, (pBits->_var), _size); \
1732 AssertRCReturn(rc, rc);
1733
1734 if (u32Version < SHCROGL_SSM_VERSION_WITH_FIXED_STENCIL)
1735 {
1736#define CRSTATE_BITS_OP_VERSION (SHCROGL_SSM_VERSION_WITH_FIXED_STENCIL - 1)
1737#define CRSTATE_BITS_OP_STENCIL_FUNC_V_33(_i, _var) do {} while (0)
1738#define CRSTATE_BITS_OP_STENCIL_OP_V_33(_i, _var) do {} while (0)
1739#include "state_bits_globalop.h"
1740#undef CRSTATE_BITS_OP_VERSION
1741#undef CRSTATE_BITS_OP_STENCIL_FUNC_V_33
1742#undef CRSTATE_BITS_OP_STENCIL_OP_V_33
1743 }
1744 else
1745 {
1746#include "state_bits_globalop.h"
1747 }
1748#undef CRSTATE_BITS_OP
1749 return VINF_SUCCESS;
1750 }
1751
1752#define CRSTATE_BITS_OP(_var, _size) FILLDIRTY(pBits->_var);
1753#include "state_bits_globalop.h"
1754#undef CRSTATE_BITS_OP
1755 return VINF_SUCCESS;
1756}
1757
1758
1759#define SLC_COPYPTR(ptr) pTmpContext->ptr = pContext->ptr
1760#define SLC_ASSSERT_NULL_PTR(ptr) CRASSERT(!pContext->ptr)
1761
1762AssertCompile(VBOXTLSREFDATA_SIZE() <= CR_MAX_BITARRAY);
1763AssertCompile(VBOXTLSREFDATA_STATE_INITIALIZED != 0);
1764AssertCompile(RT_OFFSETOF(CRContext, shared) >= VBOXTLSREFDATA_OFFSET(CRContext) + VBOXTLSREFDATA_SIZE() + RT_SIZEOFMEMB(CRContext, bitid) + RT_SIZEOFMEMB(CRContext, neg_bitid));
1765
1766int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version)
1767{
1768 CRContext* pTmpContext;
1769 int32_t rc, i, j;
1770 uint32_t uiNumElems, ui, k;
1771 unsigned long key;
1772 GLboolean bLoadShared = GL_TRUE;
1773 GLenum err;
1774
1775 CRASSERT(pContext && pSSM);
1776
1777 /* This one is rather big for stack allocation and causes macs to crash */
1778 pTmpContext = (CRContext*)crAlloc(sizeof(*pTmpContext));
1779 if (!pTmpContext)
1780 return VERR_NO_MEMORY;
1781
1782 CRASSERT(VBoxTlsRefIsFunctional(pContext));
1783
1784 if (u32Version <= SHCROGL_SSM_VERSION_WITH_INVALID_ERROR_STATE)
1785 {
1786 union {
1787 CRbitvalue bitid[CR_MAX_BITARRAY];
1788 struct {
1789 VBOXTLSREFDATA
1790 } tlsRef;
1791 } bitid;
1792
1793 /* do not increment the saved state version due to VBOXTLSREFDATA addition to CRContext */
1794 rc = SSMR3GetMem(pSSM, pTmpContext, VBOXTLSREFDATA_OFFSET(CRContext));
1795 AssertRCReturn(rc, rc);
1796
1797 /* VBox 4.1.8 had a bug that VBOXTLSREFDATA was also stored in the snapshot,
1798 * thus the saved state data format was changed w/o changing the saved state version.
1799 * here we determine whether the saved state contains VBOXTLSREFDATA, and if so, treat it accordingly */
1800 rc = SSMR3GetMem(pSSM, &bitid, sizeof (bitid));
1801 AssertRCReturn(rc, rc);
1802
1803 /* the bitid array has one bit set only. this is why if bitid.tlsRef has both cTlsRefs
1804 * and enmTlsRefState non-zero - this is definitely NOT a bit id and is a VBOXTLSREFDATA */
1805 if (bitid.tlsRef.enmTlsRefState == VBOXTLSREFDATA_STATE_INITIALIZED
1806 && bitid.tlsRef.cTlsRefs)
1807 {
1808 /* VBOXTLSREFDATA is stored, skip it */
1809 crMemcpy(&pTmpContext->bitid, ((uint8_t*)&bitid) + VBOXTLSREFDATA_SIZE(), sizeof (bitid) - VBOXTLSREFDATA_SIZE());
1810 rc = SSMR3GetMem(pSSM, ((uint8_t*)&pTmpContext->bitid) + sizeof (pTmpContext->bitid) - VBOXTLSREFDATA_SIZE(), sizeof (pTmpContext->neg_bitid) + VBOXTLSREFDATA_SIZE());
1811 AssertRCReturn(rc, rc);
1812
1813 ui = VBOXTLSREFDATA_OFFSET(CRContext) + VBOXTLSREFDATA_SIZE() + sizeof (pTmpContext->bitid) + sizeof (pTmpContext->neg_bitid);
1814 ui = RT_OFFSETOF(CRContext, shared) - ui;
1815 }
1816 else
1817 {
1818 /* VBOXTLSREFDATA is NOT stored */
1819 crMemcpy(&pTmpContext->bitid, &bitid, sizeof (bitid));
1820 rc = SSMR3GetMem(pSSM, &pTmpContext->neg_bitid, sizeof (pTmpContext->neg_bitid));
1821 AssertRCReturn(rc, rc);
1822
1823 /* the pre-VBOXTLSREFDATA CRContext structure might have additional allignment bits before the CRContext::shared */
1824 ui = VBOXTLSREFDATA_OFFSET(CRContext) + sizeof (pTmpContext->bitid) + sizeof (pTmpContext->neg_bitid);
1825
1826 ui &= (sizeof (void*) - 1);
1827 }
1828
1829 if (ui)
1830 {
1831 void* pTmp = NULL;
1832 rc = SSMR3GetMem(pSSM, &pTmp, ui);
1833 AssertRCReturn(rc, rc);
1834 }
1835
1836 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS)
1837 {
1838 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, shared, attrib);
1839 rc = crStateLoadAttribState_v_BEFORE_CTXUSAGE_BITS(&pTmpContext->attrib, pSSM);
1840 AssertRCReturn(rc, rc);
1841 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, attrib, buffer);
1842 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, buffer, stencil);
1843 rc = crStateLoadStencilState_v_33(&pTmpContext->stencil, pSSM);
1844 AssertRCReturn(rc, rc);
1845 SHCROGL_CUT_FOR_OLD_TYPE_TO_ENSURE_ALIGNMENT(CRContext, stencil, CRStencilState_v_33, sizeof (void*));
1846 rc = crStateLoadTextureState_v_BEFORE_CTXUSAGE_BITS(&pTmpContext->texture, pSSM);
1847 AssertRCReturn(rc, rc);
1848 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, texture, transform);
1849 SHCROGL_GET_STRUCT_TAIL(pTmpContext, CRContext, transform);
1850 }
1851 else
1852 {
1853 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, shared, attrib);
1854 rc = crStateLoadAttribState_v_33(&pTmpContext->attrib, pSSM);
1855 AssertRCReturn(rc, rc);
1856 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, attrib, buffer);
1857 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, buffer, stencil);
1858 rc = crStateLoadStencilState_v_33(&pTmpContext->stencil, pSSM);
1859 AssertRCReturn(rc, rc);
1860 SHCROGL_CUT_FOR_OLD_TYPE_TO_ENSURE_ALIGNMENT(CRContext, stencil, CRStencilState_v_33, sizeof (void*));
1861 SHCROGL_GET_STRUCT_TAIL(pTmpContext, CRContext, texture);
1862 }
1863
1864 pTmpContext->error = GL_NO_ERROR; /* <- the error state contained some random error data here
1865 * treat as no error */
1866 }
1867 else if (u32Version < SHCROGL_SSM_VERSION_WITH_FIXED_STENCIL)
1868 {
1869 SHCROGL_GET_STRUCT_HEAD(pTmpContext, CRContext, attrib);
1870 rc = crStateLoadAttribState_v_33(&pTmpContext->attrib, pSSM);
1871 AssertRCReturn(rc, rc);
1872 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, attrib, buffer);
1873 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, buffer, stencil);
1874 rc = crStateLoadStencilState_v_33(&pTmpContext->stencil, pSSM);
1875 AssertRCReturn(rc, rc);
1876 SHCROGL_CUT_FOR_OLD_TYPE_TO_ENSURE_ALIGNMENT(CRContext, stencil, CRStencilState_v_33, sizeof (void*));
1877 SHCROGL_GET_STRUCT_TAIL(pTmpContext, CRContext, texture);
1878 }
1879 else
1880 {
1881 rc = SSMR3GetMem(pSSM, pTmpContext, sizeof (*pTmpContext));
1882 AssertRCReturn(rc, rc);
1883 }
1884
1885 /* preserve the error to restore it at the end of context creation,
1886 * it should not normally change, but just in case it it changed */
1887 err = pTmpContext->error;
1888
1889 /* we will later do crMemcpy from entire pTmpContext to pContext,
1890 * for simplicity store the VBOXTLSREFDATA from the pContext to pTmpContext */
1891 VBOXTLSREFDATA_COPY(pTmpContext, pContext);
1892
1893 /* Deal with shared state */
1894 {
1895 crFindSharedCtxParms_t parms;
1896 int32_t shared;
1897
1898 rc = SSMR3GetS32(pSSM, &pContext->shared->id);
1899 AssertRCReturn(rc, rc);
1900
1901 rc = SSMR3GetS32(pSSM, &shared);
1902 AssertRCReturn(rc, rc);
1903
1904 pTmpContext->shared = NULL;
1905 parms.pfnCtxGet = pfnCtxGet;
1906 parms.pSrcCtx = pContext;
1907 parms.pDstCtx = pTmpContext;
1908 crHashtableWalk(pCtxTable, crStateFindSharedCB, &parms);
1909
1910 if (pTmpContext->shared)
1911 {
1912 CRASSERT(pContext->shared->refCount==1);
1913 bLoadShared = GL_FALSE;
1914 crStateFreeShared(pContext, pContext->shared);
1915 pContext->shared = NULL;
1916 pTmpContext->shared->refCount++;
1917 }
1918 else
1919 {
1920 SLC_COPYPTR(shared);
1921 }
1922
1923 if (bLoadShared && shared)
1924 {
1925 crStateSetSharedContext(pTmpContext);
1926 }
1927 }
1928
1929 SLC_COPYPTR(flush_func);
1930 SLC_COPYPTR(flush_arg);
1931
1932 /* We're supposed to be loading into an empty context, so those pointers should be NULL */
1933 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
1934 {
1935 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].clip);
1936 SLC_ASSSERT_NULL_PTR(attrib.enableStack[i].light);
1937
1938 SLC_ASSSERT_NULL_PTR(attrib.lightingStack[i].light);
1939 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clip);
1940 SLC_ASSSERT_NULL_PTR(attrib.transformStack[i].clipPlane);
1941
1942 for (j=0; j<GLEVAL_TOT; ++j)
1943 {
1944 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval1D[j].coeff);
1945 SLC_ASSSERT_NULL_PTR(attrib.evalStack[i].eval2D[j].coeff);
1946 }
1947 }
1948
1949#ifdef CR_ARB_vertex_buffer_object
1950 SLC_COPYPTR(bufferobject.nullBuffer);
1951#endif
1952
1953/*@todo, that should be removed probably as those should hold the offset values, so loading should be fine
1954 but better check*/
1955#if 0
1956#ifdef CR_EXT_compiled_vertex_array
1957 SLC_COPYPTR(client.array.v.prevPtr);
1958 SLC_COPYPTR(client.array.c.prevPtr);
1959 SLC_COPYPTR(client.array.f.prevPtr);
1960 SLC_COPYPTR(client.array.s.prevPtr);
1961 SLC_COPYPTR(client.array.e.prevPtr);
1962 SLC_COPYPTR(client.array.i.prevPtr);
1963 SLC_COPYPTR(client.array.n.prevPtr);
1964 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1965 {
1966 SLC_COPYPTR(client.array.t[i].prevPtr);
1967 }
1968
1969# ifdef CR_NV_vertex_program
1970 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1971 {
1972 SLC_COPYPTR(client.array.a[i].prevPtr);
1973 }
1974# endif
1975#endif
1976#endif
1977
1978#ifdef CR_ARB_vertex_buffer_object
1979 /*That just sets those pointers to NULL*/
1980 SLC_COPYPTR(client.array.v.buffer);
1981 SLC_COPYPTR(client.array.c.buffer);
1982 SLC_COPYPTR(client.array.f.buffer);
1983 SLC_COPYPTR(client.array.s.buffer);
1984 SLC_COPYPTR(client.array.e.buffer);
1985 SLC_COPYPTR(client.array.i.buffer);
1986 SLC_COPYPTR(client.array.n.buffer);
1987 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
1988 {
1989 SLC_COPYPTR(client.array.t[i].buffer);
1990 }
1991# ifdef CR_NV_vertex_program
1992 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
1993 {
1994 SLC_COPYPTR(client.array.a[i].buffer);
1995 }
1996# endif
1997#endif /*CR_ARB_vertex_buffer_object*/
1998
1999 /*@todo CR_NV_vertex_program*/
2000 crStateCopyEvalPtrs1D(pTmpContext->eval.eval1D, pContext->eval.eval1D);
2001 crStateCopyEvalPtrs2D(pTmpContext->eval.eval2D, pContext->eval.eval2D);
2002
2003 SLC_COPYPTR(feedback.buffer); /*@todo*/
2004 SLC_COPYPTR(selection.buffer); /*@todo*/
2005
2006 SLC_COPYPTR(lighting.light);
2007
2008 /*This one could be tricky if we're loading snapshot on host with different GPU*/
2009 SLC_COPYPTR(limits.extensions);
2010
2011#if CR_ARB_occlusion_query
2012 SLC_COPYPTR(occlusion.objects); /*@todo*/
2013#endif
2014
2015 SLC_COPYPTR(program.errorString);
2016 SLC_COPYPTR(program.programHash);
2017 SLC_COPYPTR(program.defaultVertexProgram);
2018 SLC_COPYPTR(program.defaultFragmentProgram);
2019
2020 /* Texture pointers */
2021 for (i=0; i<6; ++i)
2022 {
2023 SLC_COPYPTR(texture.base1D.level[i]);
2024 SLC_COPYPTR(texture.base2D.level[i]);
2025 SLC_COPYPTR(texture.base3D.level[i]);
2026 SLC_COPYPTR(texture.proxy1D.level[i]);
2027 SLC_COPYPTR(texture.proxy2D.level[i]);
2028 SLC_COPYPTR(texture.proxy3D.level[i]);
2029#ifdef CR_ARB_texture_cube_map
2030 SLC_COPYPTR(texture.baseCubeMap.level[i]);
2031 SLC_COPYPTR(texture.proxyCubeMap.level[i]);
2032#endif
2033#ifdef CR_NV_texture_rectangle
2034 SLC_COPYPTR(texture.baseRect.level[i]);
2035 SLC_COPYPTR(texture.proxyRect.level[i]);
2036#endif
2037 }
2038
2039 /* Load transform state */
2040 SLC_COPYPTR(transform.clipPlane);
2041 SLC_COPYPTR(transform.clip);
2042 /* Don't have to worry about pContext->transform.current as it'd be set in crStateSetCurrent call */
2043 /*SLC_COPYPTR(transform.currentStack);*/
2044 SLC_COPYPTR(transform.modelViewStack.stack);
2045 SLC_COPYPTR(transform.projectionStack.stack);
2046 SLC_COPYPTR(transform.colorStack.stack);
2047
2048 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
2049 {
2050 SLC_COPYPTR(transform.textureStack[i].stack);
2051 }
2052 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
2053 {
2054 SLC_COPYPTR(transform.programStack[i].stack);
2055 }
2056
2057#ifdef CR_OPENGL_VERSION_2_0
2058 SLC_COPYPTR(glsl.shaders);
2059 SLC_COPYPTR(glsl.programs);
2060#endif
2061
2062 /* Have to preserve original context id */
2063 CRASSERT(pTmpContext->id == pContext->id);
2064 CRASSERT(VBOXTLSREFDATA_EQUAL(pContext, pTmpContext));
2065 /* Copy ordinary state to real context */
2066 crMemcpy(pContext, pTmpContext, sizeof(*pTmpContext));
2067 crFree(pTmpContext);
2068 pTmpContext = NULL;
2069
2070 /* Now deal with pointers */
2071
2072 /* Load transform state */
2073 rc = SSMR3GetMem(pSSM, pContext->transform.clipPlane, sizeof(GLvectord)*CR_MAX_CLIP_PLANES);
2074 AssertRCReturn(rc, rc);
2075 rc = SSMR3GetMem(pSSM, pContext->transform.clip, sizeof(GLboolean)*CR_MAX_CLIP_PLANES);
2076 AssertRCReturn(rc, rc);
2077 rc = crStateLoadMatrixStack(&pContext->transform.modelViewStack, pSSM);
2078 AssertRCReturn(rc, rc);
2079 rc = crStateLoadMatrixStack(&pContext->transform.projectionStack, pSSM);
2080 AssertRCReturn(rc, rc);
2081 rc = crStateLoadMatrixStack(&pContext->transform.colorStack, pSSM);
2082 AssertRCReturn(rc, rc);
2083 for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
2084 {
2085 rc = crStateLoadMatrixStack(&pContext->transform.textureStack[i], pSSM);
2086 AssertRCReturn(rc, rc);
2087 }
2088 for (i = 0 ; i < CR_MAX_PROGRAM_MATRICES ; i++)
2089 {
2090 rc = crStateLoadMatrixStack(&pContext->transform.programStack[i], pSSM);
2091 AssertRCReturn(rc, rc);
2092 }
2093
2094 /* Load Textures */
2095 rc = crStateLoadTextureObjData(&pContext->texture.base1D, pSSM);
2096 AssertRCReturn(rc, rc);
2097 rc = crStateLoadTextureObjData(&pContext->texture.base2D, pSSM);
2098 AssertRCReturn(rc, rc);
2099 rc = crStateLoadTextureObjData(&pContext->texture.base3D, pSSM);
2100 AssertRCReturn(rc, rc);
2101 rc = crStateLoadTextureObjData(&pContext->texture.proxy1D, pSSM);
2102 AssertRCReturn(rc, rc);
2103 rc = crStateLoadTextureObjData(&pContext->texture.proxy2D, pSSM);
2104 AssertRCReturn(rc, rc);
2105 rc = crStateLoadTextureObjData(&pContext->texture.proxy3D, pSSM);
2106 AssertRCReturn(rc, rc);
2107#ifdef CR_ARB_texture_cube_map
2108 rc = crStateLoadTextureObjData(&pContext->texture.baseCubeMap, pSSM);
2109 AssertRCReturn(rc, rc);
2110 rc = crStateLoadTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
2111 AssertRCReturn(rc, rc);
2112#endif
2113#ifdef CR_NV_texture_rectangle
2114 rc = crStateLoadTextureObjData(&pContext->texture.baseRect, pSSM);
2115 AssertRCReturn(rc, rc);
2116 rc = crStateLoadTextureObjData(&pContext->texture.proxyRect, pSSM);
2117 AssertRCReturn(rc, rc);
2118#endif
2119
2120 if (bLoadShared)
2121 {
2122 /* Load shared textures */
2123 CRASSERT(pContext->shared && pContext->shared->textureTable);
2124 rc = SSMR3GetU32(pSSM, &uiNumElems);
2125 AssertRCReturn(rc, rc);
2126 for (ui=0; ui<uiNumElems; ++ui)
2127 {
2128 CRTextureObj *pTexture;
2129
2130 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2131 AssertRCReturn(rc, rc);
2132
2133 pTexture = (CRTextureObj *) crCalloc(sizeof(CRTextureObj));
2134 if (!pTexture) return VERR_NO_MEMORY;
2135
2136 rc = crStateLoadTextureObj(pTexture, pSSM, u32Version);
2137 AssertRCReturn(rc, rc);
2138
2139 pTexture->hwid = 0;
2140
2141 /*allocate actual memory*/
2142 for (i=0; i<6; ++i) {
2143 pTexture->level[i] = (CRTextureLevel *) crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
2144 if (!pTexture->level[i]) return VERR_NO_MEMORY;
2145 }
2146
2147 rc = crStateLoadTextureObjData(pTexture, pSSM);
2148 AssertRCReturn(rc, rc);
2149
2150 crHashtableAdd(pContext->shared->textureTable, key, pTexture);
2151 }
2152 }
2153
2154 /* Load current texture pointers */
2155 for (i=0; i<CR_MAX_TEXTURE_UNITS; ++i)
2156 {
2157 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->texture.unit[i], pContext, pSSM);
2158 AssertRCReturn(rc, rc);
2159 }
2160
2161 /* Mark textures for resending to GPU */
2162 pContext->shared->bTexResyncNeeded = GL_TRUE;
2163
2164 /* Load lights */
2165 CRASSERT(pContext->lighting.light);
2166 rc = SSMR3GetMem(pSSM, pContext->lighting.light, CR_MAX_LIGHTS * sizeof(*pContext->lighting.light));
2167 AssertRCReturn(rc, rc);
2168
2169 /* Load attrib stack*/
2170 for ( i = 0 ; i < CR_MAX_ATTRIB_STACK_DEPTH ; i++)
2171 {
2172 if (pContext->attrib.enableStack[i].clip)
2173 {
2174 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].clip,
2175 pContext->limits.maxClipPlanes*sizeof(GLboolean));
2176 AssertRCReturn(rc, rc);
2177 }
2178
2179 if (pContext->attrib.enableStack[i].light)
2180 {
2181 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.enableStack[i].light,
2182 pContext->limits.maxLights*sizeof(GLboolean));
2183 AssertRCReturn(rc, rc);
2184 }
2185
2186 if (pContext->attrib.lightingStack[i].light)
2187 {
2188 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.lightingStack[i].light,
2189 pContext->limits.maxLights*sizeof(CRLight));
2190 AssertRCReturn(rc, rc);
2191 }
2192
2193 for (k=0; k<pContext->limits.maxTextureUnits; ++k)
2194 {
2195 rc = crStateLoadTexUnitCurrentTexturePtrs(&pContext->attrib.textureStack[i].unit[k], pContext, pSSM);
2196 AssertRCReturn(rc, rc);
2197 }
2198
2199 if (pContext->attrib.transformStack[i].clip)
2200 {
2201 rc = crStateAllocAndSSMR3GetMem(pSSM, (void*)&pContext->attrib.transformStack[i].clip,
2202 pContext->limits.maxClipPlanes*sizeof(GLboolean));
2203 AssertRCReturn(rc, rc);
2204 }
2205
2206 if (pContext->attrib.transformStack[i].clipPlane)
2207 {
2208 rc = crStateAllocAndSSMR3GetMem(pSSM, (void**)&pContext->attrib.transformStack[i].clipPlane,
2209 pContext->limits.maxClipPlanes*sizeof(GLvectord));
2210 AssertRCReturn(rc, rc);
2211 }
2212 rc = crSateLoadEvalCoeffs1D(pContext->attrib.evalStack[i].eval1D, GL_TRUE, pSSM);
2213 AssertRCReturn(rc, rc);
2214 rc = crSateLoadEvalCoeffs2D(pContext->attrib.evalStack[i].eval2D, GL_TRUE, pSSM);
2215 AssertRCReturn(rc, rc);
2216 }
2217
2218 /* Load evaluator coeffs */
2219 rc = crSateLoadEvalCoeffs1D(pContext->eval.eval1D, GL_FALSE, pSSM);
2220 AssertRCReturn(rc, rc);
2221 rc = crSateLoadEvalCoeffs2D(pContext->eval.eval2D, GL_FALSE, pSSM);
2222 AssertRCReturn(rc, rc);
2223
2224 /* Load buffer objects */
2225#ifdef CR_ARB_vertex_buffer_object
2226 rc = SSMR3GetU32(pSSM, &uiNumElems);
2227 AssertRCReturn(rc, rc);
2228 for (ui=0; ui<=uiNumElems; ++ui) /*ui<=uiNumElems to load nullBuffer in same loop*/
2229 {
2230 CRBufferObject *pBufferObj;
2231
2232 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2233 AssertRCReturn(rc, rc);
2234
2235 /* default one should be already allocated */
2236 if (key==0)
2237 {
2238 pBufferObj = pContext->bufferobject.nullBuffer;
2239 if (!pBufferObj) return VERR_SSM_UNEXPECTED_DATA;
2240 }
2241 else
2242 {
2243 pBufferObj = (CRBufferObject *) crCalloc(sizeof(*pBufferObj));
2244 if (!pBufferObj) return VERR_NO_MEMORY;
2245 }
2246
2247 rc = crStateLoadBufferObject(pBufferObj, pSSM, u32Version);
2248 AssertRCReturn(rc, rc);
2249
2250 pBufferObj->hwid = 0;
2251
2252 if (pBufferObj->data)
2253 {
2254 CRASSERT(pBufferObj->size>0);
2255 pBufferObj->data = crAlloc(pBufferObj->size);
2256 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
2257 AssertRCReturn(rc, rc);
2258 }
2259 else if (pBufferObj->id!=0 && pBufferObj->size>0)
2260 {
2261 rc = SSMR3GetMem(pSSM, &pBufferObj->data, sizeof(pBufferObj->data));
2262 AssertRCReturn(rc, rc);
2263
2264 if (pBufferObj->data)
2265 {
2266 pBufferObj->data = crAlloc(pBufferObj->size);
2267 rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
2268 AssertRCReturn(rc, rc);
2269 }
2270 }
2271
2272
2273 if (key!=0)
2274 crHashtableAdd(pContext->shared->buffersTable, key, pBufferObj);
2275 }
2276 /* Load pointers */
2277#define CRS_GET_BO(name) (((name)==0) ? (pContext->bufferobject.nullBuffer) : crHashtableSearch(pContext->shared->buffersTable, name))
2278 rc = SSMR3GetU32(pSSM, &ui);
2279 AssertRCReturn(rc, rc);
2280 pContext->bufferobject.arrayBuffer = CRS_GET_BO(ui);
2281 rc = SSMR3GetU32(pSSM, &ui);
2282 AssertRCReturn(rc, rc);
2283 pContext->bufferobject.elementsBuffer = CRS_GET_BO(ui);
2284#ifdef CR_ARB_pixel_buffer_object
2285 rc = SSMR3GetU32(pSSM, &ui);
2286 AssertRCReturn(rc, rc);
2287 pContext->bufferobject.packBuffer = CRS_GET_BO(ui);
2288 rc = SSMR3GetU32(pSSM, &ui);
2289 AssertRCReturn(rc, rc);
2290 pContext->bufferobject.unpackBuffer = CRS_GET_BO(ui);
2291#endif
2292#undef CRS_GET_BO
2293
2294 /* Load client pointers and array buffer bindings*/
2295 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
2296 {
2297 rc = crStateLoadClientPointer(&pContext->client.array, i, pContext, pSSM);
2298 AssertRCReturn(rc, rc);
2299 }
2300 for (j=0; j<pContext->client.vertexArrayStackDepth; ++j)
2301 {
2302 CRVertexArrays *pArray = &pContext->client.vertexArrayStack[j];
2303 for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
2304 {
2305 rc = crStateLoadClientPointer(pArray, i, pContext, pSSM);
2306 AssertRCReturn(rc, rc);
2307 }
2308 }
2309
2310 pContext->shared->bVBOResyncNeeded = GL_TRUE;
2311#endif
2312
2313 /* Load pixel/vertex programs */
2314 rc = SSMR3GetU32(pSSM, &uiNumElems);
2315 AssertRCReturn(rc, rc);
2316 /* Load defaults programs */
2317 rc = crStateLoadProgram(&pContext->program.defaultVertexProgram, pSSM);
2318 AssertRCReturn(rc, rc);
2319 rc = crStateLoadProgram(&pContext->program.defaultFragmentProgram, pSSM);
2320 AssertRCReturn(rc, rc);
2321 /* Load all the rest */
2322 for (ui=0; ui<uiNumElems; ++ui)
2323 {
2324 CRProgram *pProgram = NULL;
2325 rc = crStateLoadProgram(&pProgram, pSSM);
2326 AssertRCReturn(rc, rc);
2327 crHashtableAdd(pContext->program.programHash, pProgram->id, pProgram);
2328 //DIRTY(pProgram->dirtyProgram, pContext->neg_bitid);
2329
2330 }
2331 /* Load Pointers */
2332 rc = SSMR3GetU32(pSSM, &ui);
2333 AssertRCReturn(rc, rc);
2334 pContext->program.currentVertexProgram = ui==0 ? pContext->program.defaultVertexProgram
2335 : crHashtableSearch(pContext->program.programHash, ui);
2336 rc = SSMR3GetU32(pSSM, &ui);
2337 AssertRCReturn(rc, rc);
2338 pContext->program.currentFragmentProgram = ui==0 ? pContext->program.defaultFragmentProgram
2339 : crHashtableSearch(pContext->program.programHash, ui);
2340
2341 /* Mark programs for resending to GPU */
2342 pContext->program.bResyncNeeded = GL_TRUE;
2343
2344#ifdef CR_EXT_framebuffer_object
2345 /* Load FBOs */
2346 if (bLoadShared)
2347 {
2348 rc = SSMR3GetU32(pSSM, &uiNumElems);
2349 AssertRCReturn(rc, rc);
2350 for (ui=0; ui<uiNumElems; ++ui)
2351 {
2352 CRFramebufferObject *pFBO;
2353 pFBO = crAlloc(sizeof(*pFBO));
2354 if (!pFBO) return VERR_NO_MEMORY;
2355
2356 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2357 AssertRCReturn(rc, rc);
2358
2359 rc = crStateLoadFramebufferObject(pFBO, pSSM, u32Version);
2360 AssertRCReturn(rc, rc);
2361
2362 Assert(key == pFBO->id);
2363
2364 crHashtableAdd(pContext->shared->fbTable, key, pFBO);
2365 }
2366
2367 rc = SSMR3GetU32(pSSM, &uiNumElems);
2368 AssertRCReturn(rc, rc);
2369 for (ui=0; ui<uiNumElems; ++ui)
2370 {
2371 CRRenderbufferObject *pRBO;
2372 pRBO = crAlloc(sizeof(*pRBO));
2373 if (!pRBO) return VERR_NO_MEMORY;
2374
2375 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2376 AssertRCReturn(rc, rc);
2377
2378 rc = crStateLoadRenderbufferObject(pRBO, pSSM, u32Version);
2379 AssertRCReturn(rc, rc);
2380
2381 crHashtableAdd(pContext->shared->rbTable, key, pRBO);
2382 }
2383 }
2384
2385 rc = SSMR3GetU32(pSSM, &ui);
2386 AssertRCReturn(rc, rc);
2387 pContext->framebufferobject.drawFB = ui==0 ? NULL
2388 : crHashtableSearch(pContext->shared->fbTable, ui);
2389
2390 rc = SSMR3GetU32(pSSM, &ui);
2391 AssertRCReturn(rc, rc);
2392 pContext->framebufferobject.readFB = ui==0 ? NULL
2393 : crHashtableSearch(pContext->shared->fbTable, ui);
2394
2395 rc = SSMR3GetU32(pSSM, &ui);
2396 AssertRCReturn(rc, rc);
2397 pContext->framebufferobject.renderbuffer = ui==0 ? NULL
2398 : crHashtableSearch(pContext->shared->rbTable, ui);
2399
2400 /* Mark FBOs/RBOs for resending to GPU */
2401 pContext->shared->bFBOResyncNeeded = GL_TRUE;
2402#endif
2403
2404#ifdef CR_OPENGL_VERSION_2_0
2405 /* Load GLSL related info */
2406 rc = SSMR3GetU32(pSSM, &uiNumElems);
2407 AssertRCReturn(rc, rc);
2408
2409 for (ui=0; ui<uiNumElems; ++ui)
2410 {
2411 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
2412 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
2413 crHashtableAdd(pContext->glsl.shaders, pShader->id, pShader);
2414 }
2415
2416 rc = SSMR3GetU32(pSSM, &uiNumElems);
2417 AssertRCReturn(rc, rc);
2418
2419 for (ui=0; ui<uiNumElems; ++ui)
2420 {
2421 CRGLSLProgram *pProgram;
2422 uint32_t numShaders;
2423
2424 pProgram = crAlloc(sizeof(*pProgram));
2425 if (!pProgram) return VERR_NO_MEMORY;
2426
2427 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2428 AssertRCReturn(rc, rc);
2429
2430 rc = SSMR3GetMem(pSSM, pProgram, sizeof(*pProgram));
2431 AssertRCReturn(rc, rc);
2432
2433 crHashtableAdd(pContext->glsl.programs, key, pProgram);
2434
2435 pProgram->currentState.attachedShaders = crAllocHashtable();
2436
2437 rc = SSMR3GetU32(pSSM, &numShaders);
2438 AssertRCReturn(rc, rc);
2439
2440 for (k=0; k<numShaders; ++k)
2441 {
2442 rc = SSMR3GetMem(pSSM, &key, sizeof(key));
2443 AssertRCReturn(rc, rc);
2444 crHashtableAdd(pProgram->currentState.attachedShaders, key, crHashtableSearch(pContext->glsl.shaders, key));
2445 }
2446
2447 if (pProgram->activeState.attachedShaders)
2448 {
2449 pProgram->activeState.attachedShaders = crAllocHashtable();
2450
2451 rc = SSMR3GetU32(pSSM, &numShaders);
2452 AssertRCReturn(rc, rc);
2453
2454 for (k=0; k<numShaders; ++k)
2455 {
2456 CRGLSLShader *pShader = crStateLoadGLSLShader(pSSM);
2457 if (!pShader) return VERR_SSM_UNEXPECTED_DATA;
2458 crHashtableAdd(pProgram->activeState.attachedShaders, pShader->id, pShader);
2459 }
2460 }
2461
2462 if (pProgram->currentState.cAttribs)
2463 pProgram->currentState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->currentState.cAttribs*sizeof(CRGLSLAttrib));
2464 for (k=0; k<pProgram->currentState.cAttribs; ++k)
2465 {
2466 rc = SSMR3GetMem(pSSM, &pProgram->currentState.pAttribs[k].index, sizeof(pProgram->currentState.pAttribs[k].index));
2467 AssertRCReturn(rc, rc);
2468 pProgram->currentState.pAttribs[k].name = crStateLoadString(pSSM);
2469 }
2470
2471 if (pProgram->activeState.cAttribs)
2472 pProgram->activeState.pAttribs = (CRGLSLAttrib*) crAlloc(pProgram->activeState.cAttribs*sizeof(CRGLSLAttrib));
2473 for (k=0; k<pProgram->activeState.cAttribs; ++k)
2474 {
2475 rc = SSMR3GetMem(pSSM, &pProgram->activeState.pAttribs[k].index, sizeof(pProgram->activeState.pAttribs[k].index));
2476 AssertRCReturn(rc, rc);
2477 pProgram->activeState.pAttribs[k].name = crStateLoadString(pSSM);
2478 }
2479
2480 {
2481 int32_t cUniforms;
2482 rc = SSMR3GetS32(pSSM, &cUniforms);
2483 pProgram->cUniforms = cUniforms;
2484 AssertRCReturn(rc, rc);
2485 }
2486
2487 if (pProgram->cUniforms)
2488 {
2489 pProgram->pUniforms = crAlloc(pProgram->cUniforms*sizeof(CRGLSLUniform));
2490 if (!pProgram->pUniforms) return VERR_NO_MEMORY;
2491
2492 for (k=0; k<pProgram->cUniforms; ++k)
2493 {
2494 size_t itemsize, datasize;
2495
2496 rc = SSMR3GetMem(pSSM, &pProgram->pUniforms[k].type, sizeof(GLenum));
2497 AssertRCReturn(rc, rc);
2498 pProgram->pUniforms[k].name = crStateLoadString(pSSM);
2499
2500 if (crStateIsIntUniform(pProgram->pUniforms[k].type))
2501 {
2502 itemsize = sizeof(GLint);
2503 } else itemsize = sizeof(GLfloat);
2504
2505 datasize = crStateGetUniformSize(pProgram->pUniforms[k].type)*itemsize;
2506 pProgram->pUniforms[k].data = crAlloc(datasize);
2507 if (!pProgram->pUniforms[k].data) return VERR_NO_MEMORY;
2508
2509 rc = SSMR3GetMem(pSSM, pProgram->pUniforms[k].data, datasize);
2510 AssertRCReturn(rc, rc);
2511 }
2512 }
2513 }
2514
2515 rc = SSMR3GetU32(pSSM, &ui);
2516 AssertRCReturn(rc, rc);
2517 pContext->glsl.activeProgram = ui==0 ? NULL
2518 : crHashtableSearch(pContext->glsl.programs, ui);
2519
2520 /*Mark for resending to GPU*/
2521 pContext->glsl.bResyncNeeded = GL_TRUE;
2522#endif
2523
2524 if (pContext->error != err)
2525 {
2526 crWarning("context error state changed on context restore, was 0x%x, but became 0x%x, resetting to its original value",
2527 err, pContext->error);
2528 pContext->error = err;
2529 }
2530
2531 return VINF_SUCCESS;
2532}
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