VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c@ 37775

Last change on this file since 37775 was 37613, checked in by vboxsync, 13 years ago

wddm/3d: fix snapshots with aero

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "state.h"
8#include "cr_error.h"
9#include "cr_mem.h"
10#include "cr_pixeldata.h"
11
12void crStateDiffContext( CRContext *from, CRContext *to )
13{
14 CRbitvalue *bitID = from->bitid;
15 CRStateBits *sb = GetCurrentBits();
16
17 /*crDebug( "Diffing two contexts!" ); */
18
19 if (CHECKDIRTY(sb->transform.dirty, bitID))
20 {
21 crStateTransformDiff( &(sb->transform), bitID, from, to );
22 }
23 if (CHECKDIRTY(sb->pixel.dirty, bitID))
24 {
25 crStatePixelDiff( &(sb->pixel), bitID, from, to );
26 }
27 if (CHECKDIRTY(sb->viewport.dirty, bitID))
28 {
29 crStateViewportDiff( &(sb->viewport), bitID, from, to );
30 }
31 if (CHECKDIRTY(sb->fog.dirty, bitID))
32 {
33 crStateFogDiff( &(sb->fog), bitID, from, to );
34 }
35 if (CHECKDIRTY(sb->texture.dirty, bitID))
36 {
37 crStateTextureDiff( &(sb->texture), bitID, from, to );
38 }
39 if (CHECKDIRTY(sb->lists.dirty, bitID))
40 {
41 crStateListsDiff( &(sb->lists), bitID, from, to );
42 }
43 if (CHECKDIRTY(sb->buffer.dirty, bitID))
44 {
45 crStateBufferDiff( &(sb->buffer), bitID, from, to );
46 }
47#ifdef CR_ARB_vertex_buffer_object
48 if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
49 {
50 crStateBufferObjectDiff( &(sb->bufferobject), bitID, from, to );
51 }
52#endif
53 if (CHECKDIRTY(sb->client.dirty, bitID))
54 {
55 crStateClientDiff(&(sb->client), bitID, from, to );
56 }
57 if (CHECKDIRTY(sb->hint.dirty, bitID))
58 {
59 crStateHintDiff( &(sb->hint), bitID, from, to );
60 }
61 if (CHECKDIRTY(sb->lighting.dirty, bitID))
62 {
63 crStateLightingDiff( &(sb->lighting), bitID, from, to );
64 }
65 if (CHECKDIRTY(sb->line.dirty, bitID))
66 {
67 crStateLineDiff( &(sb->line), bitID, from, to );
68 }
69 if (CHECKDIRTY(sb->occlusion.dirty, bitID))
70 {
71 crStateOcclusionDiff( &(sb->occlusion), bitID, from, to );
72 }
73 if (CHECKDIRTY(sb->point.dirty, bitID))
74 {
75 crStatePointDiff( &(sb->point), bitID, from, to );
76 }
77 if (CHECKDIRTY(sb->polygon.dirty, bitID))
78 {
79 crStatePolygonDiff( &(sb->polygon), bitID, from, to );
80 }
81 if (CHECKDIRTY(sb->program.dirty, bitID))
82 {
83 crStateProgramDiff( &(sb->program), bitID, from, to );
84 }
85 if (CHECKDIRTY(sb->stencil.dirty, bitID))
86 {
87 crStateStencilDiff( &(sb->stencil), bitID, from, to );
88 }
89 if (CHECKDIRTY(sb->eval.dirty, bitID))
90 {
91 crStateEvaluatorDiff( &(sb->eval), bitID, from, to );
92 }
93#ifdef CR_ARB_imaging
94 if (CHECKDIRTY(sb->imaging.dirty, bitID))
95 {
96 crStateImagingDiff( &(sb->imaging), bitID, from, to );
97 }
98#endif
99#if 0
100 if (CHECKDIRTY(sb->selection.dirty, bitID))
101 {
102 crStateSelectionDiff( &(sb->selection), bitID, from, to );
103 }
104#endif
105#ifdef CR_NV_register_combiners
106 if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
107 {
108 crStateRegCombinerDiff( &(sb->regcombiner), bitID, from, to );
109 }
110#endif
111#ifdef CR_ARB_multisample
112 if (CHECKDIRTY(sb->multisample.dirty, bitID) &&
113 from->extensions.ARB_multisample)
114 {
115 crStateMultisampleDiff( &(sb->multisample), bitID, from, to );
116 }
117#endif
118 if (CHECKDIRTY(sb->current.dirty, bitID))
119 {
120 crStateCurrentDiff( &(sb->current), bitID, from, to );
121 }
122}
123
124void crStateApplyFBImage(CRContext *to)
125{
126 if (to->buffer.pFrontImg || to->buffer.pBackImg)
127 {
128 CRBufferState *pBuf = &to->buffer;
129 CRPixelPackState unpack = to->client.unpack;
130
131 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
132 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
133 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
134 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
135 diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
136 diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
137 diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
138 diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
139
140 if (to->framebufferobject.drawFB)
141 {
142 diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
143 }
144
145 if (to->bufferobject.unpackBuffer->hwid>0)
146 {
147 diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
148 }
149
150 diff_api.Disable(GL_ALPHA_TEST);
151 diff_api.Disable(GL_SCISSOR_TEST);
152 diff_api.Disable(GL_BLEND);
153 diff_api.Disable(GL_COLOR_LOGIC_OP);
154
155 if (pBuf->pFrontImg)
156 {
157 diff_api.DrawBuffer(GL_FRONT);
158 diff_api.WindowPos2iARB(0, 0);
159 diff_api.DrawPixels(pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBuf->pFrontImg);
160 crDebug("Applied %ix%i fb image", pBuf->storedWidth, pBuf->storedHeight);
161 crFree(pBuf->pFrontImg);
162 pBuf->pFrontImg = NULL;
163 }
164
165 if (pBuf->pBackImg)
166 {
167 diff_api.DrawBuffer(GL_BACK);
168 diff_api.WindowPos2iARB(0, 0);
169 diff_api.DrawPixels(pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBuf->pBackImg);
170 crDebug("Applied %ix%i bb image", pBuf->storedWidth, pBuf->storedHeight);
171 crFree(pBuf->pBackImg);
172 pBuf->pBackImg = NULL;
173 }
174
175 diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
176 if (to->bufferobject.unpackBuffer->hwid>0)
177 {
178 diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->bufferobject.unpackBuffer->hwid);
179 }
180 if (to->framebufferobject.drawFB)
181 {
182 diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB->hwid);
183 }
184 diff_api.DrawBuffer(to->framebufferobject.drawFB ?
185 to->framebufferobject.drawFB->drawbuffer[0] : to->buffer.drawBuffer);
186 if (to->buffer.alphaTest)
187 {
188 diff_api.Enable(GL_ALPHA_TEST);
189 }
190 if (to->viewport.scissorTest)
191 {
192 diff_api.Enable(GL_SCISSOR_TEST);
193 }
194 if (to->buffer.blend)
195 {
196 diff_api.Enable(GL_BLEND);
197 }
198 if (to->buffer.logicOp)
199 {
200 diff_api.Enable(GL_COLOR_LOGIC_OP);
201 }
202
203 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
204 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
205 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
206 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
207 diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
208 diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
209 diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
210 diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
211
212 diff_api.Finish();
213 }
214}
215
216void crStateSwitchContext( CRContext *from, CRContext *to )
217{
218 CRbitvalue *bitID = to->bitid;
219 CRStateBits *sb = GetCurrentBits();
220
221 if (CHECKDIRTY(sb->attrib.dirty, bitID))
222 {
223 crStateAttribSwitch(&(sb->attrib), bitID, from, to );
224 }
225 if (CHECKDIRTY(sb->transform.dirty, bitID))
226 {
227 crStateTransformSwitch( &(sb->transform), bitID, from, to );
228 }
229 if (CHECKDIRTY(sb->pixel.dirty, bitID))
230 {
231 crStatePixelSwitch(&(sb->pixel), bitID, from, to );
232 }
233 if (CHECKDIRTY(sb->viewport.dirty, bitID))
234 {
235 crStateViewportSwitch(&(sb->viewport), bitID, from, to );
236 }
237 if (CHECKDIRTY(sb->fog.dirty, bitID))
238 {
239 crStateFogSwitch(&(sb->fog), bitID, from, to );
240 }
241 if (CHECKDIRTY(sb->texture.dirty, bitID))
242 {
243 crStateTextureSwitch( &(sb->texture), bitID, from, to );
244 }
245 if (CHECKDIRTY(sb->lists.dirty, bitID))
246 {
247 crStateListsSwitch(&(sb->lists), bitID, from, to );
248 }
249 if (CHECKDIRTY(sb->buffer.dirty, bitID))
250 {
251 crStateBufferSwitch( &(sb->buffer), bitID, from, to );
252 }
253#ifdef CR_ARB_vertex_buffer_object
254 if (CHECKDIRTY(sb->bufferobject.dirty, bitID))
255 {
256 crStateBufferObjectSwitch( &(sb->bufferobject), bitID, from, to );
257 }
258#endif
259 if (CHECKDIRTY(sb->client.dirty, bitID))
260 {
261 crStateClientSwitch( &(sb->client), bitID, from, to );
262 }
263#if 0
264 if (CHECKDIRTY(sb->hint.dirty, bitID))
265 {
266 crStateHintSwitch( &(sb->hint), bitID, from, to );
267 }
268#endif
269 if (CHECKDIRTY(sb->lighting.dirty, bitID))
270 {
271 crStateLightingSwitch( &(sb->lighting), bitID, from, to );
272 }
273 if (CHECKDIRTY(sb->occlusion.dirty, bitID))
274 {
275 crStateOcclusionSwitch( &(sb->occlusion), bitID, from, to );
276 }
277 if (CHECKDIRTY(sb->line.dirty, bitID))
278 {
279 crStateLineSwitch( &(sb->line), bitID, from, to );
280 }
281 if (CHECKDIRTY(sb->point.dirty, bitID))
282 {
283 crStatePointSwitch( &(sb->point), bitID, from, to );
284 }
285 if (CHECKDIRTY(sb->polygon.dirty, bitID))
286 {
287 crStatePolygonSwitch( &(sb->polygon), bitID, from, to );
288 }
289 if (CHECKDIRTY(sb->program.dirty, bitID))
290 {
291 crStateProgramSwitch( &(sb->program), bitID, from, to );
292 }
293 if (CHECKDIRTY(sb->stencil.dirty, bitID))
294 {
295 crStateStencilSwitch( &(sb->stencil), bitID, from, to );
296 }
297 if (CHECKDIRTY(sb->eval.dirty, bitID))
298 {
299 crStateEvaluatorSwitch( &(sb->eval), bitID, from, to );
300 }
301#ifdef CR_ARB_imaging
302 if (CHECKDIRTY(sb->imaging.dirty, bitID))
303 {
304 crStateImagingSwitch( &(sb->imaging), bitID, from, to );
305 }
306#endif
307#if 0
308 if (CHECKDIRTY(sb->selection.dirty, bitID))
309 {
310 crStateSelectionSwitch( &(sb->selection), bitID, from, to );
311 }
312#endif
313#ifdef CR_NV_register_combiners
314 if (CHECKDIRTY(sb->regcombiner.dirty, bitID) && to->extensions.NV_register_combiners)
315 {
316 crStateRegCombinerSwitch( &(sb->regcombiner), bitID, from, to );
317 }
318#endif
319#ifdef CR_ARB_multisample
320 if (CHECKDIRTY(sb->multisample.dirty, bitID))
321 {
322 crStateMultisampleSwitch( &(sb->multisample), bitID, from, to );
323 }
324#endif
325#ifdef CR_ARB_multisample
326 if (CHECKDIRTY(sb->multisample.dirty, bitID))
327 {
328 crStateMultisampleSwitch(&(sb->multisample), bitID, from, to );
329 }
330#endif
331#ifdef CR_EXT_framebuffer_object
332 /*Note, this should go after crStateTextureSwitch*/
333 crStateFramebufferObjectSwitch(from, to);
334#endif
335#ifdef CR_OPENGL_VERSION_2_0
336 crStateGLSLSwitch(from, to);
337#endif
338 if (CHECKDIRTY(sb->current.dirty, bitID))
339 {
340 crStateCurrentSwitch( &(sb->current), bitID, from, to );
341 }
342
343#ifdef WINDOWS
344 crStateApplyFBImage(to);
345#endif
346}
Note: See TracBrowser for help on using the repository browser.

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