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