VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c@ 16477

Last change on this file since 16477 was 16477, checked in by vboxsync, 16 years ago

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 66.6 KB
Line 
1/*
2 * state block implementation
3 *
4 * Copyright 2002 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2005 Oliver Stieber
7 * Copyright 2007 Stefan Dösinger for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24/*
25 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
26 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
27 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
28 * a choice of LGPL license versions is made available with the language indicating
29 * that LGPLv2 or any later version may be used, or where a choice of which version
30 * of the LGPL is applied is otherwise unspecified.
31 */
32
33#include "config.h"
34#include "wined3d_private.h"
35
36WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
38
39/***************************************
40 * Stateblock helper functions follow
41 **************************************/
42
43/** Allocates the correct amount of space for pixel and vertex shader constants,
44 * along with their set/changed flags on the given stateblock object
45 */
46HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
47
48 IWineD3DStateBlockImpl *This = object;
49
50#define WINED3D_MEMCHECK(_object) if (NULL == _object) { FIXME("Out of memory!\n"); return E_OUTOFMEMORY; }
51
52 /* Allocate space for floating point constants */
53 object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
54 WINED3D_MEMCHECK(object->pixelShaderConstantF);
55 object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
56 WINED3D_MEMCHECK(object->changed.pixelShaderConstantsF);
57 object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
58 WINED3D_MEMCHECK(object->vertexShaderConstantF);
59 object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
60 WINED3D_MEMCHECK(object->changed.vertexShaderConstantsF);
61 object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
62 WINED3D_MEMCHECK(object->contained_vs_consts_f);
63 object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
64 WINED3D_MEMCHECK(object->contained_ps_consts_f);
65
66 list_init(&object->set_vconstantsF);
67 list_init(&object->set_pconstantsF);
68
69#undef WINED3D_MEMCHECK
70
71 return WINED3D_OK;
72}
73
74/** Copy all members of one stateblock to another */
75static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *dest, const SAVEDSTATES *source)
76{
77 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
78 unsigned bsize = sizeof(BOOL);
79
80 /* Single values */
81 dest->indices = source->indices;
82 dest->material = source->material;
83 dest->fvf = source->fvf;
84 dest->viewport = source->viewport;
85 dest->vertexDecl = source->vertexDecl;
86 dest->pixelShader = source->pixelShader;
87 dest->vertexShader = source->vertexShader;
88 dest->scissorRect = dest->scissorRect;
89
90 /* Fixed size arrays */
91 memcpy(dest->streamSource, source->streamSource, bsize * MAX_STREAMS);
92 memcpy(dest->streamFreq, source->streamFreq, bsize * MAX_STREAMS);
93 memcpy(dest->textures, source->textures, bsize * MAX_COMBINED_SAMPLERS);
94 memcpy(dest->transform, source->transform, bsize * (HIGHEST_TRANSFORMSTATE + 1));
95 memcpy(dest->renderState, source->renderState, bsize * (WINEHIGHEST_RENDER_STATE + 1));
96 memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
97 memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
98 memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
99 dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
100 dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
101 dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
102 dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
103
104 /* Dynamically sized arrays */
105 memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
106 memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
107}
108
109/** Set all members of a stateblock savedstate to the given value */
110void stateblock_savedstates_set(
111 IWineD3DStateBlock* iface,
112 SAVEDSTATES* states,
113 BOOL value) {
114
115 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
116 unsigned bsize = sizeof(BOOL);
117
118 /* Single values */
119 states->indices = value;
120 states->material = value;
121 states->fvf = value;
122 states->viewport = value;
123 states->vertexDecl = value;
124 states->pixelShader = value;
125 states->vertexShader = value;
126 states->scissorRect = value;
127
128 /* Fixed size arrays */
129 memset(states->streamSource, value, bsize * MAX_STREAMS);
130 memset(states->streamFreq, value, bsize * MAX_STREAMS);
131 memset(states->textures, value, bsize * MAX_COMBINED_SAMPLERS);
132 memset(states->transform, value, bsize * (HIGHEST_TRANSFORMSTATE + 1));
133 memset(states->renderState, value, bsize * (WINEHIGHEST_RENDER_STATE + 1));
134 memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
135 memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
136 memset(states->clipplane, value, bsize * MAX_CLIPPLANES);
137 states->pixelShaderConstantsB = value ? 0xffff : 0;
138 states->pixelShaderConstantsI = value ? 0xffff : 0;
139 states->vertexShaderConstantsB = value ? 0xffff : 0;
140 states->vertexShaderConstantsI = value ? 0xffff : 0;
141
142 /* Dynamically sized arrays */
143 memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
144 memset(states->vertexShaderConstantsF, value, bsize * GL_LIMITS(vshader_constantsF));
145}
146
147void stateblock_copy(
148 IWineD3DStateBlock* destination,
149 IWineD3DStateBlock* source) {
150 int l;
151
152 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)source;
153 IWineD3DStateBlockImpl *Dest = (IWineD3DStateBlockImpl *)destination;
154
155 /* IUnknown fields */
156 Dest->lpVtbl = This->lpVtbl;
157 Dest->ref = This->ref;
158
159 /* IWineD3DStateBlock information */
160 Dest->parent = This->parent;
161 Dest->wineD3DDevice = This->wineD3DDevice;
162 Dest->blockType = This->blockType;
163
164 /* Saved states */
165 stateblock_savedstates_copy(source, &Dest->changed, &This->changed);
166
167 /* Single items */
168 Dest->fvf = This->fvf;
169 Dest->vertexDecl = This->vertexDecl;
170 Dest->vertexShader = This->vertexShader;
171 Dest->streamIsUP = This->streamIsUP;
172 Dest->pIndexData = This->pIndexData;
173 Dest->baseVertexIndex = This->baseVertexIndex;
174 /* Dest->lights = This->lights; */
175 Dest->clip_status = This->clip_status;
176 Dest->viewport = This->viewport;
177 Dest->material = This->material;
178 Dest->pixelShader = This->pixelShader;
179 Dest->scissorRect = This->scissorRect;
180
181 /* Lights */
182 memset(This->activeLights, 0, sizeof(This->activeLights));
183 for(l = 0; l < LIGHTMAP_SIZE; l++) {
184 struct list *e1, *e2;
185 LIST_FOR_EACH_SAFE(e1, e2, &Dest->lightMap[l]) {
186 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
187 list_remove(&light->entry);
188 HeapFree(GetProcessHeap(), 0, light);
189 }
190
191 LIST_FOR_EACH(e1, &This->lightMap[l]) {
192 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry), *light2;
193 light2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*light));
194 *light2 = *light;
195 list_add_tail(&Dest->lightMap[l], &light2->entry);
196 if(light2->glIndex != -1) Dest->activeLights[light2->glIndex] = light2;
197 }
198 }
199
200 /* Fixed size arrays */
201 memcpy(Dest->vertexShaderConstantB, This->vertexShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
202 memcpy(Dest->vertexShaderConstantI, This->vertexShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
203 memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
204 memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
205
206 memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
207 memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
208 memcpy(Dest->streamSource, This->streamSource, sizeof(IWineD3DVertexBuffer*) * MAX_STREAMS);
209 memcpy(Dest->streamFreq, This->streamFreq, sizeof(UINT) * MAX_STREAMS);
210 memcpy(Dest->streamFlags, This->streamFlags, sizeof(UINT) * MAX_STREAMS);
211 memcpy(Dest->transforms, This->transforms, sizeof(WINED3DMATRIX) * (HIGHEST_TRANSFORMSTATE + 1));
212 memcpy(Dest->clipplane, This->clipplane, sizeof(double) * MAX_CLIPPLANES * 4);
213 memcpy(Dest->renderState, This->renderState, sizeof(DWORD) * (WINEHIGHEST_RENDER_STATE + 1));
214 memcpy(Dest->textures, This->textures, sizeof(IWineD3DBaseTexture*) * MAX_COMBINED_SAMPLERS);
215 memcpy(Dest->textureDimensions, This->textureDimensions, sizeof(int) * MAX_COMBINED_SAMPLERS);
216 memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
217 memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
218
219 /* Dynamically sized arrays */
220 memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
221 memcpy(Dest->pixelShaderConstantF, This->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
222}
223
224/**********************************************************
225 * IWineD3DStateBlockImpl IUnknown parts follows
226 **********************************************************/
227static HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,REFIID riid,LPVOID *ppobj)
228{
229 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
230 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
231 if (IsEqualGUID(riid, &IID_IUnknown)
232 || IsEqualGUID(riid, &IID_IWineD3DBase)
233 || IsEqualGUID(riid, &IID_IWineD3DStateBlock)){
234 IUnknown_AddRef(iface);
235 *ppobj = This;
236 return S_OK;
237 }
238 *ppobj = NULL;
239 return E_NOINTERFACE;
240}
241
242static ULONG WINAPI IWineD3DStateBlockImpl_AddRef(IWineD3DStateBlock *iface) {
243 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
244 ULONG refCount = InterlockedIncrement(&This->ref);
245
246 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
247 return refCount;
248}
249
250static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
251 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
252 ULONG refCount = InterlockedDecrement(&This->ref);
253
254 TRACE("(%p) : Releasing from %d\n", This, refCount + 1);
255
256 if (!refCount) {
257 constants_entry *constant, *constant2;
258 int counter;
259
260 /* type 0 represents the primary stateblock, so free all the resources */
261 if (This->blockType == WINED3DSBT_INIT) {
262 /* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
263 for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) {
264 if (This->textures[counter]) {
265 /* release our 'internal' hold on the texture */
266 if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
267 TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
268 }
269 }
270 }
271 }
272
273 for (counter = 0; counter < MAX_STREAMS; counter++) {
274 if(This->streamSource[counter]) {
275 if(0 != IWineD3DVertexBuffer_Release(This->streamSource[counter])) {
276 TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter, This->streamSource[counter]);
277 }
278 }
279 }
280 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
281 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
282 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
283
284 for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
285 struct list *e1, *e2;
286 LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) {
287 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
288 list_remove(&light->entry);
289 HeapFree(GetProcessHeap(), 0, light);
290 }
291 }
292
293 HeapFree(GetProcessHeap(), 0, This->vertexShaderConstantF);
294 HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
295 HeapFree(GetProcessHeap(), 0, This->pixelShaderConstantF);
296 HeapFree(GetProcessHeap(), 0, This->changed.pixelShaderConstantsF);
297 HeapFree(GetProcessHeap(), 0, This->contained_vs_consts_f);
298 HeapFree(GetProcessHeap(), 0, This->contained_ps_consts_f);
299
300 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_vconstantsF, constants_entry, entry) {
301 HeapFree(GetProcessHeap(), 0, constant);
302 }
303
304 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_pconstantsF, constants_entry, entry) {
305 HeapFree(GetProcessHeap(), 0, constant);
306 }
307
308 HeapFree(GetProcessHeap(), 0, This);
309 }
310 return refCount;
311}
312
313/**********************************************************
314 * IWineD3DStateBlockImpl parts follows
315 **********************************************************/
316static HRESULT WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
317 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
318 IUnknown_AddRef(This->parent);
319 *pParent = This->parent;
320 return WINED3D_OK;
321}
322
323static HRESULT WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
324
325 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
326
327 *ppDevice = (IWineD3DDevice*)This->wineD3DDevice;
328 IWineD3DDevice_AddRef(*ppDevice);
329 return WINED3D_OK;
330
331}
332
333static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
334 UINT i;
335
336 /* Lights... For a recorded state block, we just had a chain of actions to perform,
337 * so we need to walk that chain and update any actions which differ
338 */
339 for(i = 0; i < LIGHTMAP_SIZE; i++) {
340 struct list *e, *f;
341 LIST_FOR_EACH(e, &This->lightMap[i]) {
342 BOOL updated = FALSE;
343 PLIGHTINFOEL *src = LIST_ENTRY(e, PLIGHTINFOEL, entry), *realLight;
344 if(!src->changed || !src->enabledChanged) continue;
345
346 /* Look up the light in the destination */
347 LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) {
348 realLight = LIST_ENTRY(f, PLIGHTINFOEL, entry);
349 if(realLight->OriginalIndex == src->OriginalIndex) {
350 if(src->changed) {
351 src->OriginalParms = realLight->OriginalParms;
352 }
353 if(src->enabledChanged) {
354 /* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
355 * or disabled -> enabled -> disabled changes
356 */
357 if(realLight->glIndex == -1 && src->glIndex != -1) {
358 /* Light disabled */
359 This->activeLights[src->glIndex] = NULL;
360 } else if(realLight->glIndex != -1 && src->glIndex == -1){
361 /* Light enabled */
362 This->activeLights[realLight->glIndex] = src;
363 }
364 src->glIndex = realLight->glIndex;
365 }
366 updated = TRUE;
367 break;
368 }
369 }
370
371 if(updated) {
372 /* Found a light, all done, proceed with next hash entry */
373 continue;
374 } else if(src->changed) {
375 /* Otherwise assign defaul params */
376 src->OriginalParms = WINED3D_default_light;
377 } else {
378 /* Not enabled by default */
379 src->glIndex = -1;
380 }
381 }
382 }
383}
384
385static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
386
387 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
388 IWineD3DStateBlockImpl *targetStateBlock = This->wineD3DDevice->stateBlock;
389 unsigned int i, j;
390
391 TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This);
392
393 /* If not recorded, then update can just recapture */
394 if (This->blockType == WINED3DSBT_RECORDED) {
395
396 /* Recorded => Only update 'changed' values */
397 if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader) {
398 TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
399
400 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
401 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
402 This->vertexShader = targetStateBlock->vertexShader;
403 }
404
405 /* Vertex Shader Float Constants */
406 for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
407 i = This->contained_vs_consts_f[j];
408 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
409 targetStateBlock->vertexShaderConstantF[i * 4],
410 targetStateBlock->vertexShaderConstantF[i * 4 + 1],
411 targetStateBlock->vertexShaderConstantF[i * 4 + 2],
412 targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
413
414 This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
415 This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
416 This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
417 This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
418 }
419
420 /* Vertex Shader Integer Constants */
421 for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
422 i = This->contained_vs_consts_i[j];
423 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
424 targetStateBlock->vertexShaderConstantI[i * 4],
425 targetStateBlock->vertexShaderConstantI[i * 4 + 1],
426 targetStateBlock->vertexShaderConstantI[i * 4 + 2],
427 targetStateBlock->vertexShaderConstantI[i * 4 + 3]);
428
429 This->vertexShaderConstantI[i * 4] = targetStateBlock->vertexShaderConstantI[i * 4];
430 This->vertexShaderConstantI[i * 4 + 1] = targetStateBlock->vertexShaderConstantI[i * 4 + 1];
431 This->vertexShaderConstantI[i * 4 + 2] = targetStateBlock->vertexShaderConstantI[i * 4 + 2];
432 This->vertexShaderConstantI[i * 4 + 3] = targetStateBlock->vertexShaderConstantI[i * 4 + 3];
433 }
434
435 /* Vertex Shader Boolean Constants */
436 for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
437 i = This->contained_vs_consts_b[j];
438 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
439 targetStateBlock->vertexShaderConstantB[i]? "TRUE":"FALSE");
440
441 This->vertexShaderConstantB[i] = targetStateBlock->vertexShaderConstantB[i];
442 }
443
444 /* Pixel Shader Float Constants */
445 for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
446 i = This->contained_ps_consts_f[j];
447 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
448 targetStateBlock->pixelShaderConstantF[i * 4],
449 targetStateBlock->pixelShaderConstantF[i * 4 + 1],
450 targetStateBlock->pixelShaderConstantF[i * 4 + 2],
451 targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
452
453 This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
454 This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
455 This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
456 This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
457 }
458
459 /* Pixel Shader Integer Constants */
460 for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
461 i = This->contained_ps_consts_i[j];
462 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
463 targetStateBlock->pixelShaderConstantI[i * 4],
464 targetStateBlock->pixelShaderConstantI[i * 4 + 1],
465 targetStateBlock->pixelShaderConstantI[i * 4 + 2],
466 targetStateBlock->pixelShaderConstantI[i * 4 + 3]);
467
468 This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4];
469 This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
470 This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
471 This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
472 }
473
474 /* Pixel Shader Boolean Constants */
475 for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
476 i = This->contained_ps_consts_b[j];
477 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
478 targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE");
479
480 This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i];
481 }
482
483 /* Others + Render & Texture */
484 for (i = 0; i < This->num_contained_transform_states; i++) {
485 TRACE("Updating transform %d\n", i);
486 This->transforms[This->contained_transform_states[i]] =
487 targetStateBlock->transforms[This->contained_transform_states[i]];
488 }
489
490 if (This->changed.indices && ((This->pIndexData != targetStateBlock->pIndexData)
491 || (This->baseVertexIndex != targetStateBlock->baseVertexIndex))) {
492 TRACE("Updating pindexData to %p, baseVertexIndex to %d\n",
493 targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
494 if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
495 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
496 This->pIndexData = targetStateBlock->pIndexData;
497 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
498 }
499
500 if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
501 TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
502
503 This->vertexDecl = targetStateBlock->vertexDecl;
504 }
505
506 if(This->changed.fvf && This->fvf != targetStateBlock->fvf){
507 This->fvf = targetStateBlock->fvf;
508 }
509
510 if (This->changed.material && memcmp(&targetStateBlock->material,
511 &This->material,
512 sizeof(WINED3DMATERIAL)) != 0) {
513 TRACE("Updating material\n");
514 This->material = targetStateBlock->material;
515 }
516
517 if (This->changed.viewport && memcmp(&targetStateBlock->viewport,
518 &This->viewport,
519 sizeof(WINED3DVIEWPORT)) != 0) {
520 TRACE("Updating viewport\n");
521 This->viewport = targetStateBlock->viewport;
522 }
523
524 if(This->changed.scissorRect && memcmp(&targetStateBlock->scissorRect,
525 &This->scissorRect,
526 sizeof(targetStateBlock->scissorRect)))
527 {
528 TRACE("Updating scissor rect\n");
529 targetStateBlock->scissorRect = This->scissorRect;
530 }
531
532 for (i = 0; i < MAX_STREAMS; i++) {
533 if (This->changed.streamSource[i] &&
534 ((This->streamStride[i] != targetStateBlock->streamStride[i]) ||
535 (This->streamSource[i] != targetStateBlock->streamSource[i]))) {
536 TRACE("Updating stream source %d to %p, stride to %d\n", i, targetStateBlock->streamSource[i],
537 targetStateBlock->streamStride[i]);
538 This->streamStride[i] = targetStateBlock->streamStride[i];
539 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
540 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
541 This->streamSource[i] = targetStateBlock->streamSource[i];
542 }
543
544 if (This->changed.streamFreq[i] &&
545 (This->streamFreq[i] != targetStateBlock->streamFreq[i]
546 || This->streamFlags[i] != targetStateBlock->streamFlags[i])){
547 TRACE("Updating stream frequency %d to %d flags to %d\n", i , targetStateBlock->streamFreq[i] ,
548 targetStateBlock->streamFlags[i]);
549 This->streamFreq[i] = targetStateBlock->streamFreq[i];
550 This->streamFlags[i] = targetStateBlock->streamFlags[i];
551 }
552 }
553
554 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
555 if (This->changed.clipplane[i] && memcmp(&targetStateBlock->clipplane[i],
556 &This->clipplane[i],
557 sizeof(This->clipplane)) != 0) {
558
559 TRACE("Updating clipplane %d\n", i);
560 memcpy(&This->clipplane[i], &targetStateBlock->clipplane[i],
561 sizeof(This->clipplane));
562 }
563 }
564
565 /* Render */
566 for (i = 0; i < This->num_contained_render_states; i++) {
567 TRACE("Updating renderState %d to %d\n",
568 This->contained_render_states[i], targetStateBlock->renderState[This->contained_render_states[i]]);
569 This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
570 }
571
572 /* Texture states */
573 for (j = 0; j < This->num_contained_tss_states; j++) {
574 DWORD stage = This->contained_tss_states[j].stage;
575 DWORD state = This->contained_tss_states[j].state;
576
577 TRACE("Updating texturestagestate %d,%d to %d (was %d)\n", stage,state,
578 targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
579 This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
580 }
581
582 /* Samplers */
583 /* TODO: move over to using memcpy */
584 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
585 if (This->changed.textures[j]) {
586 TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]);
587 This->textures[j] = targetStateBlock->textures[j];
588 }
589 }
590
591 for (j = 0; j < This->num_contained_sampler_states; j++) {
592 DWORD stage = This->contained_sampler_states[j].stage;
593 DWORD state = This->contained_sampler_states[j].state;
594 TRACE("Updating sampler state %d,%d to %d (was %d)\n",
595 stage, state, targetStateBlock->samplerState[stage][state],
596 This->samplerState[stage][state]);
597 This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
598 }
599 if(This->changed.pixelShader && This->pixelShader != targetStateBlock->pixelShader) {
600 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
601 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
602 This->pixelShader = targetStateBlock->pixelShader;
603 }
604
605 record_lights(This, targetStateBlock);
606 } else if(This->blockType == WINED3DSBT_ALL) {
607 This->vertexDecl = targetStateBlock->vertexDecl;
608 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
609 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
610 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
611 memcpy(This->streamStride, targetStateBlock->streamStride, sizeof(This->streamStride));
612 memcpy(This->streamOffset, targetStateBlock->streamOffset, sizeof(This->streamOffset));
613 memcpy(This->streamFreq, targetStateBlock->streamFreq, sizeof(This->streamFreq));
614 memcpy(This->streamFlags, targetStateBlock->streamFlags, sizeof(This->streamFlags));
615 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
616 memcpy(This->transforms, targetStateBlock->transforms, sizeof(This->transforms));
617 record_lights(This, targetStateBlock);
618 memcpy(This->clipplane, targetStateBlock->clipplane, sizeof(This->clipplane));
619 This->clip_status = targetStateBlock->clip_status;
620 This->viewport = targetStateBlock->viewport;
621 This->material = targetStateBlock->material;
622 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
623 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
624 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
625 memcpy(This->renderState, targetStateBlock->renderState, sizeof(This->renderState));
626 memcpy(This->textures, targetStateBlock->textures, sizeof(This->textures));
627 memcpy(This->textureDimensions, targetStateBlock->textureDimensions, sizeof(This->textureDimensions));
628 memcpy(This->textureState, targetStateBlock->textureState, sizeof(This->textureState));
629 memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
630 This->scissorRect = targetStateBlock->scissorRect;
631
632 if(targetStateBlock->pIndexData != This->pIndexData) {
633 if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
634 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
635 This->pIndexData = targetStateBlock->pIndexData;
636 }
637 for(i = 0; i < MAX_STREAMS; i++) {
638 if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
639 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
640 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
641 This->streamSource[i] = targetStateBlock->streamSource[i];
642 }
643 }
644 if(This->vertexShader != targetStateBlock->vertexShader) {
645 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
646 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
647 This->vertexShader = targetStateBlock->vertexShader;
648 }
649 if(This->pixelShader != targetStateBlock->pixelShader) {
650 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
651 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
652 This->pixelShader = targetStateBlock->pixelShader;
653 }
654 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
655 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
656 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
657 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
658 record_lights(This, targetStateBlock);
659 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
660 This->renderState[SavedVertexStates_R[i]] = targetStateBlock->renderState[SavedVertexStates_R[i]];
661 }
662 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
663 for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
664 This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
665 }
666 }
667 for (j = 0; j < MAX_TEXTURES; j++) {
668 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
669 This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
670 }
671 }
672 for(i = 0; i < MAX_STREAMS; i++) {
673 if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
674 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
675 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
676 This->streamSource[i] = targetStateBlock->streamSource[i];
677 }
678 }
679 if(This->vertexShader != targetStateBlock->vertexShader) {
680 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
681 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
682 This->vertexShader = targetStateBlock->vertexShader;
683 }
684 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
685 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
686 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
687 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
688 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
689 This->renderState[SavedPixelStates_R[i]] = targetStateBlock->renderState[SavedPixelStates_R[i]];
690 }
691 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
692 for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
693 This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
694 }
695 }
696 for (j = 0; j < MAX_TEXTURES; j++) {
697 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
698 This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
699 }
700 }
701 if(This->pixelShader != targetStateBlock->pixelShader) {
702 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
703 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
704 This->pixelShader = targetStateBlock->pixelShader;
705 }
706 }
707
708 TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock, This);
709
710 return WINED3D_OK;
711}
712
713static inline void apply_lights(IWineD3DDevice *pDevice, IWineD3DStateBlockImpl *This) {
714 UINT i;
715 for(i = 0; i < LIGHTMAP_SIZE; i++) {
716 struct list *e;
717
718 LIST_FOR_EACH(e, &This->lightMap[i]) {
719 const PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
720
721 if(light->changed) {
722 IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
723 }
724 if(light->enabledChanged) {
725 IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
726 }
727 }
728 }
729}
730
731static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface){
732 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
733 IWineD3DDevice* pDevice = (IWineD3DDevice*)This->wineD3DDevice;
734
735/*Copy thing over to updateBlock is isRecording otherwise StateBlock,
736should really perform a delta so that only the changes get updated*/
737
738 UINT i;
739 UINT j;
740
741 TRACE("(%p) : Applying state block %p ------------------v\n", This, pDevice);
742
743 TRACE("Blocktype: %d\n", This->blockType);
744
745 if(This->blockType == WINED3DSBT_RECORDED) {
746 if (This->changed.vertexShader) {
747 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
748 }
749 /* Vertex Shader Constants */
750 for (i = 0; i < This->num_contained_vs_consts_f; i++) {
751 IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
752 This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
753 }
754 for (i = 0; i < This->num_contained_vs_consts_i; i++) {
755 IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
756 This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
757 }
758 for (i = 0; i < This->num_contained_vs_consts_b; i++) {
759 IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
760 This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
761 }
762
763 apply_lights(pDevice, This);
764
765 if (This->changed.pixelShader) {
766 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
767 }
768 /* Pixel Shader Constants */
769 for (i = 0; i < This->num_contained_ps_consts_f; i++) {
770 IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
771 This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
772 }
773 for (i = 0; i < This->num_contained_ps_consts_i; i++) {
774 IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
775 This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
776 }
777 for (i = 0; i < This->num_contained_ps_consts_b; i++) {
778 IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
779 This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
780 }
781
782 /* Render */
783 for (i = 0; i <= This->num_contained_render_states; i++) {
784 IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
785 This->renderState[This->contained_render_states[i]]);
786 }
787 /* Texture states */
788 for (i = 0; i < This->num_contained_tss_states; i++) {
789 DWORD stage = This->contained_tss_states[i].stage;
790 DWORD state = This->contained_tss_states[i].state;
791 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state] = This->textureState[stage][state];
792 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.textureState[stage][state] = TRUE;
793 /* TODO: Record a display list to apply all gl states. For now apply by brute force */
794 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state));
795 }
796 /* Sampler states */
797 for (i = 0; i < This->num_contained_sampler_states; i++) {
798 DWORD stage = This->contained_sampler_states[i].stage;
799 DWORD state = This->contained_sampler_states[i].state;
800 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state];
801 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage][state] = TRUE;
802 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage));
803 }
804
805 for (i = 0; i < This->num_contained_transform_states; i++) {
806 IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
807 &This->transforms[This->contained_transform_states[i]]);
808 }
809
810 if (This->changed.indices) {
811 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
812 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
813 }
814
815 if (This->changed.fvf) {
816 IWineD3DDevice_SetFVF(pDevice, This->fvf);
817 }
818
819 if (This->changed.vertexDecl) {
820 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
821 }
822
823 if (This->changed.material ) {
824 IWineD3DDevice_SetMaterial(pDevice, &This->material);
825 }
826
827 if (This->changed.viewport) {
828 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
829 }
830
831 if (This->changed.scissorRect) {
832 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
833 }
834
835 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
836 for (i=0; i<MAX_STREAMS; i++) {
837 if (This->changed.streamSource[i])
838 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
839
840 if (This->changed.streamFreq[i])
841 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
842 }
843 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
844 if (This->changed.textures[j]) {
845 if (j < MAX_FRAGMENT_SAMPLERS) {
846 IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
847 } else {
848 IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]);
849 }
850 }
851 }
852
853 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
854 if (This->changed.clipplane[i]) {
855 float clip[4];
856
857 clip[0] = This->clipplane[i][0];
858 clip[1] = This->clipplane[i][1];
859 clip[2] = This->clipplane[i][2];
860 clip[3] = This->clipplane[i][3];
861 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
862 }
863 }
864
865 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
866 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
867 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
868 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
869 This->vertexShaderConstantF + i * 4, 1);
870 }
871 for (i = 0; i < MAX_CONST_I; i++) {
872 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
873 This->vertexShaderConstantI + i * 4, 1);
874 }
875 for (i = 0; i < MAX_CONST_B; i++) {
876 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
877 This->vertexShaderConstantB + i, 1);
878 }
879
880 apply_lights(pDevice, This);
881
882 for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
883 IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
884 }
885 for(j = 0; j < MAX_TEXTURES; j++) {
886 for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
887 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
888 This->textureState[j][SavedVertexStates_T[i]]);
889 }
890 }
891
892 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
893 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
894 IWineD3DDevice_SetSamplerState(pDevice, j, SavedVertexStates_S[i],
895 This->samplerState[j][SavedVertexStates_S[i]]);
896 }
897 }
898 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
899 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
900 IWineD3DDevice_SetSamplerState(pDevice,
901 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
902 SavedVertexStates_S[i],
903 This->samplerState[j][SavedVertexStates_S[i]]);
904 }
905 }
906 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
907 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
908 for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
909 IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
910 This->pixelShaderConstantF + i * 4, 1);
911 }
912 for (i = 0; i < MAX_CONST_I; i++) {
913 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
914 This->pixelShaderConstantI + i * 4, 1);
915 }
916 for (i = 0; i < MAX_CONST_B; i++) {
917 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
918 This->pixelShaderConstantB + i, 1);
919 }
920
921 for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
922 IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
923 }
924 for(j = 0; j < MAX_TEXTURES; j++) {
925 for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
926 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
927 This->textureState[j][SavedPixelStates_T[i]]);
928 }
929 }
930
931 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
932 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
933 IWineD3DDevice_SetSamplerState(pDevice, j, SavedPixelStates_S[i],
934 This->samplerState[j][SavedPixelStates_S[i]]);
935 }
936 }
937 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
938 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
939 IWineD3DDevice_SetSamplerState(pDevice,
940 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
941 SavedPixelStates_S[i],
942 This->samplerState[j][SavedPixelStates_S[i]]);
943 }
944 }
945 } else if(This->blockType == WINED3DSBT_ALL) {
946 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
947 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
948 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
949 This->vertexShaderConstantF + i * 4, 1);
950 }
951 for (i = 0; i < MAX_CONST_I; i++) {
952 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
953 This->vertexShaderConstantI + i * 4, 1);
954 }
955 for (i = 0; i < MAX_CONST_B; i++) {
956 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
957 This->vertexShaderConstantB + i, 1);
958 }
959
960 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
961 for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
962 IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
963 This->pixelShaderConstantF + i * 4, 1);
964 }
965 for (i = 0; i < MAX_CONST_I; i++) {
966 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
967 This->pixelShaderConstantI + i * 4, 1);
968 }
969 for (i = 0; i < MAX_CONST_B; i++) {
970 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
971 This->pixelShaderConstantB + i, 1);
972 }
973
974 apply_lights(pDevice, This);
975
976 for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
977 IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
978 }
979 for(j = 0; j < MAX_TEXTURES; j++) {
980 for(i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE; i++) {
981 IWineD3DDevice_SetTextureStageState(pDevice, j, i, This->textureState[j][i]);
982 }
983 }
984
985 /* Skip unused values between TEXTURE8 and WORLD0 ? */
986 for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
987 IWineD3DDevice_SetTransform(pDevice, i, &This->transforms[i]);
988 }
989 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
990 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
991 IWineD3DDevice_SetFVF(pDevice, This->fvf);
992 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
993 IWineD3DDevice_SetMaterial(pDevice, &This->material);
994 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
995 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
996
997 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
998 for (i=0; i<MAX_STREAMS; i++) {
999 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
1000 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
1001 }
1002 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
1003 UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
1004
1005 IWineD3DDevice_SetTexture(pDevice, sampler, This->textures[j]);
1006 for(i = 1; i < WINED3D_HIGHEST_SAMPLER_STATE; i++) {
1007 IWineD3DDevice_SetSamplerState(pDevice, sampler, i, This->samplerState[j][i]);
1008 }
1009 }
1010 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
1011 float clip[4];
1012
1013 clip[0] = This->clipplane[i][0];
1014 clip[1] = This->clipplane[i][1];
1015 clip[2] = This->clipplane[i][2];
1016 clip[3] = This->clipplane[i][3];
1017 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
1018 }
1019 }
1020
1021 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
1022 for(j = 0; j < MAX_TEXTURES - 1; j++) {
1023 if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
1024 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = j;
1025 break;
1026 }
1027 }
1028 TRACE("(%p) : Applied state block %p ------------------^\n", This, pDevice);
1029
1030 return WINED3D_OK;
1031}
1032
1033static HRESULT WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock* iface) {
1034 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
1035 IWineD3DDevice *device = (IWineD3DDevice *)This->wineD3DDevice;
1036 IWineD3DDeviceImpl *ThisDevice = (IWineD3DDeviceImpl *)device;
1037 union {
1038 WINED3DLINEPATTERN lp;
1039 DWORD d;
1040 } lp;
1041 union {
1042 float f;
1043 DWORD d;
1044 } tmpfloat;
1045 unsigned int i;
1046 IWineD3DSwapChain *swapchain;
1047 IWineD3DSurface *backbuffer;
1048 WINED3DSURFACE_DESC desc = {0};
1049 UINT width, height;
1050 RECT scissorrect;
1051 HRESULT hr;
1052
1053 /* Note this may have a large overhead but it should only be executed
1054 once, in order to initialize the complete state of the device and
1055 all opengl equivalents */
1056 TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
1057 /* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
1058 This->blockType = WINED3DSBT_INIT;
1059
1060 /* Set some of the defaults for lights, transforms etc */
1061 memcpy(&This->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
1062 memcpy(&This->transforms[WINED3DTS_VIEW], identity, sizeof(identity));
1063 for (i = 0; i < 256; ++i) {
1064 memcpy(&This->transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity));
1065 }
1066
1067 TRACE("Render states\n");
1068 /* Render states: */
1069 if (ThisDevice->auto_depth_stencil_buffer != NULL) {
1070 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_TRUE);
1071 } else {
1072 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_FALSE);
1073 }
1074 IWineD3DDevice_SetRenderState(device, WINED3DRS_FILLMODE, WINED3DFILL_SOLID);
1075 IWineD3DDevice_SetRenderState(device, WINED3DRS_SHADEMODE, WINED3DSHADE_GOURAUD);
1076 lp.lp.wRepeatFactor = 0;
1077 lp.lp.wLinePattern = 0;
1078 IWineD3DDevice_SetRenderState(device, WINED3DRS_LINEPATTERN, lp.d);
1079 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZWRITEENABLE, TRUE);
1080 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHATESTENABLE, FALSE);
1081 IWineD3DDevice_SetRenderState(device, WINED3DRS_LASTPIXEL, TRUE);
1082 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLEND, WINED3DBLEND_ONE);
1083 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLEND, WINED3DBLEND_ZERO);
1084 IWineD3DDevice_SetRenderState(device, WINED3DRS_CULLMODE, WINED3DCULL_CCW);
1085 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZFUNC, WINED3DCMP_LESSEQUAL);
1086 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAFUNC, WINED3DCMP_ALWAYS);
1087 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAREF, 0);
1088 IWineD3DDevice_SetRenderState(device, WINED3DRS_DITHERENABLE, FALSE);
1089 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHABLENDENABLE, FALSE);
1090 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGENABLE, FALSE);
1091 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARENABLE, FALSE);
1092 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZVISIBLE, 0);
1093 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGCOLOR, 0);
1094 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGTABLEMODE, WINED3DFOG_NONE);
1095 tmpfloat.f = 0.0f;
1096 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGSTART, tmpfloat.d);
1097 tmpfloat.f = 1.0f;
1098 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGEND, tmpfloat.d);
1099 tmpfloat.f = 1.0f;
1100 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGDENSITY, tmpfloat.d);
1101 IWineD3DDevice_SetRenderState(device, WINED3DRS_EDGEANTIALIAS, FALSE);
1102 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZBIAS, 0);
1103 IWineD3DDevice_SetRenderState(device, WINED3DRS_RANGEFOGENABLE, FALSE);
1104 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILENABLE, FALSE);
1105 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1106 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1107 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILPASS, WINED3DSTENCILOP_KEEP);
1108 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILREF, 0);
1109 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILMASK, 0xFFFFFFFF);
1110 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFUNC, WINED3DCMP_ALWAYS);
1111 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
1112 IWineD3DDevice_SetRenderState(device, WINED3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
1113 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP0, 0);
1114 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP1, 0);
1115 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP2, 0);
1116 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP3, 0);
1117 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP4, 0);
1118 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP5, 0);
1119 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP6, 0);
1120 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP7, 0);
1121 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPING, TRUE);
1122 IWineD3DDevice_SetRenderState(device, WINED3DRS_LIGHTING, TRUE);
1123 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENT, 0);
1124 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGVERTEXMODE, WINED3DFOG_NONE);
1125 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORVERTEX, TRUE);
1126 IWineD3DDevice_SetRenderState(device, WINED3DRS_LOCALVIEWER, TRUE);
1127 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALIZENORMALS, FALSE);
1128 IWineD3DDevice_SetRenderState(device, WINED3DRS_DIFFUSEMATERIALSOURCE, WINED3DMCS_COLOR1);
1129 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARMATERIALSOURCE, WINED3DMCS_COLOR2);
1130 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENTMATERIALSOURCE, WINED3DMCS_MATERIAL);
1131 IWineD3DDevice_SetRenderState(device, WINED3DRS_EMISSIVEMATERIALSOURCE, WINED3DMCS_MATERIAL);
1132 IWineD3DDevice_SetRenderState(device, WINED3DRS_VERTEXBLEND, WINED3DVBF_DISABLE);
1133 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPLANEENABLE, 0);
1134 IWineD3DDevice_SetRenderState(device, WINED3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
1135 tmpfloat.f = 1.0f;
1136 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE, tmpfloat.d);
1137 tmpfloat.f = 1.0f;
1138 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN, tmpfloat.d);
1139 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE, FALSE);
1140 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALEENABLE, FALSE);
1141 tmpfloat.f = 1.0f;
1142 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_A, tmpfloat.d);
1143 tmpfloat.f = 0.0f;
1144 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_B, tmpfloat.d);
1145 tmpfloat.f = 0.0f;
1146 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_C, tmpfloat.d);
1147 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEANTIALIAS, TRUE);
1148 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
1149 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHEDGESTYLE, WINED3DPATCHEDGE_DISCRETE);
1150 tmpfloat.f = 1.0f;
1151 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHSEGMENTS, tmpfloat.d);
1152 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEBUGMONITORTOKEN, 0xbaadcafe);
1153 tmpfloat.f = 64.0f;
1154 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MAX, tmpfloat.d);
1155 IWineD3DDevice_SetRenderState(device, WINED3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
1156 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE, 0x0000000F);
1157 tmpfloat.f = 0.0f;
1158 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWEENFACTOR, tmpfloat.d);
1159 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOP, WINED3DBLENDOP_ADD);
1160 IWineD3DDevice_SetRenderState(device, WINED3DRS_POSITIONDEGREE, WINED3DDEGREE_CUBIC);
1161 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALDEGREE, WINED3DDEGREE_LINEAR);
1162 /* states new in d3d9 */
1163 IWineD3DDevice_SetRenderState(device, WINED3DRS_SCISSORTESTENABLE, FALSE);
1164 IWineD3DDevice_SetRenderState(device, WINED3DRS_SLOPESCALEDEPTHBIAS, 0);
1165 tmpfloat.f = 1.0f;
1166 IWineD3DDevice_SetRenderState(device, WINED3DRS_MINTESSELLATIONLEVEL, tmpfloat.d);
1167 IWineD3DDevice_SetRenderState(device, WINED3DRS_MAXTESSELLATIONLEVEL, tmpfloat.d);
1168 IWineD3DDevice_SetRenderState(device, WINED3DRS_ANTIALIASEDLINEENABLE, FALSE);
1169 tmpfloat.f = 0.0f;
1170 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_X, tmpfloat.d);
1171 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Y, tmpfloat.d);
1172 tmpfloat.f = 1.0f;
1173 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Z, tmpfloat.d);
1174 tmpfloat.f = 0.0f;
1175 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_W, tmpfloat.d);
1176 IWineD3DDevice_SetRenderState(device, WINED3DRS_ENABLEADAPTIVETESSELLATION, FALSE);
1177 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWOSIDEDSTENCILMODE, FALSE);
1178 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1179 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1180 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILPASS, WINED3DSTENCILOP_KEEP);
1181 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFUNC, WINED3DCMP_ALWAYS);
1182 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE1, 0x0000000F);
1183 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE2, 0x0000000F);
1184 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE3, 0x0000000F);
1185 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDFACTOR, 0xFFFFFFFF);
1186 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRGBWRITEENABLE, 0);
1187 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEPTHBIAS, 0);
1188 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP8, 0);
1189 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP9, 0);
1190 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP10, 0);
1191 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP11, 0);
1192 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP12, 0);
1193 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP13, 0);
1194 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP14, 0);
1195 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP15, 0);
1196 IWineD3DDevice_SetRenderState(device, WINED3DRS_SEPARATEALPHABLENDENABLE, FALSE);
1197 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLENDALPHA, WINED3DBLEND_ONE);
1198 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLENDALPHA, WINED3DBLEND_ZERO);
1199 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOPALPHA, WINED3DBLENDOP_ADD);
1200
1201 /* clipping status */
1202 This->clip_status.ClipUnion = 0;
1203 This->clip_status.ClipIntersection = 0xFFFFFFFF;
1204
1205 /* Texture Stage States - Put directly into state block, we will call function below */
1206 for (i = 0; i < MAX_TEXTURES; i++) {
1207 TRACE("Setting up default texture states for texture Stage %d\n", i);
1208 memcpy(&This->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
1209 This->textureState[i][WINED3DTSS_COLOROP ] = (i==0)? WINED3DTOP_MODULATE : WINED3DTOP_DISABLE;
1210 This->textureState[i][WINED3DTSS_COLORARG1 ] = WINED3DTA_TEXTURE;
1211 This->textureState[i][WINED3DTSS_COLORARG2 ] = WINED3DTA_CURRENT;
1212 This->textureState[i][WINED3DTSS_ALPHAOP ] = (i==0)? WINED3DTOP_SELECTARG1 : WINED3DTOP_DISABLE;
1213 This->textureState[i][WINED3DTSS_ALPHAARG1 ] = WINED3DTA_TEXTURE;
1214 This->textureState[i][WINED3DTSS_ALPHAARG2 ] = WINED3DTA_CURRENT;
1215 This->textureState[i][WINED3DTSS_BUMPENVMAT00 ] = 0;
1216 This->textureState[i][WINED3DTSS_BUMPENVMAT01 ] = 0;
1217 This->textureState[i][WINED3DTSS_BUMPENVMAT10 ] = 0;
1218 This->textureState[i][WINED3DTSS_BUMPENVMAT11 ] = 0;
1219 This->textureState[i][WINED3DTSS_TEXCOORDINDEX ] = i;
1220 This->textureState[i][WINED3DTSS_BUMPENVLSCALE ] = 0;
1221 This->textureState[i][WINED3DTSS_BUMPENVLOFFSET ] = 0;
1222 This->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS ] = WINED3DTTFF_DISABLE;
1223 This->textureState[i][WINED3DTSS_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1224 This->textureState[i][WINED3DTSS_COLORARG0 ] = WINED3DTA_CURRENT;
1225 This->textureState[i][WINED3DTSS_ALPHAARG0 ] = WINED3DTA_CURRENT;
1226 This->textureState[i][WINED3DTSS_RESULTARG ] = WINED3DTA_CURRENT;
1227 }
1228 This->lowest_disabled_stage = 1;
1229
1230 /* Sampler states*/
1231 for (i = 0 ; i < MAX_COMBINED_SAMPLERS; i++) {
1232 TRACE("Setting up default samplers states for sampler %d\n", i);
1233 This->samplerState[i][WINED3DSAMP_ADDRESSU ] = WINED3DTADDRESS_WRAP;
1234 This->samplerState[i][WINED3DSAMP_ADDRESSV ] = WINED3DTADDRESS_WRAP;
1235 This->samplerState[i][WINED3DSAMP_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1236 This->samplerState[i][WINED3DSAMP_BORDERCOLOR ] = 0x00;
1237 This->samplerState[i][WINED3DSAMP_MAGFILTER ] = WINED3DTEXF_POINT;
1238 This->samplerState[i][WINED3DSAMP_MINFILTER ] = WINED3DTEXF_POINT;
1239 This->samplerState[i][WINED3DSAMP_MIPFILTER ] = WINED3DTEXF_NONE;
1240 This->samplerState[i][WINED3DSAMP_MIPMAPLODBIAS ] = 0;
1241 This->samplerState[i][WINED3DSAMP_MAXMIPLEVEL ] = 0;
1242 This->samplerState[i][WINED3DSAMP_MAXANISOTROPY ] = 1;
1243 This->samplerState[i][WINED3DSAMP_SRGBTEXTURE ] = 0;
1244 This->samplerState[i][WINED3DSAMP_ELEMENTINDEX ] = 0; /* TODO: Indicates which element of a multielement texture to use */
1245 This->samplerState[i][WINED3DSAMP_DMAPOFFSET ] = 0; /* TODO: Vertex offset in the presampled displacement map */
1246 }
1247
1248 for(i = 0; i < GL_LIMITS(textures); i++) {
1249 /* Note: This avoids calling SetTexture, so pretend it has been called */
1250 This->changed.textures[i] = TRUE;
1251 This->textures[i] = NULL;
1252 }
1253
1254 /* Set the default scissor rect values */
1255 desc.Width = &width;
1256 desc.Height = &height;
1257
1258 /* check the return values, because the GetBackBuffer call isn't valid for ddraw */
1259 hr = IWineD3DDevice_GetSwapChain(device, 0, &swapchain);
1260 if( hr == WINED3D_OK && swapchain != NULL) {
1261 hr = IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
1262 if( hr == WINED3D_OK && backbuffer != NULL) {
1263 IWineD3DSurface_GetDesc(backbuffer, &desc);
1264 IWineD3DSurface_Release(backbuffer);
1265
1266 scissorrect.left = 0;
1267 scissorrect.right = width;
1268 scissorrect.top = 0;
1269 scissorrect.bottom = height;
1270 hr = IWineD3DDevice_SetScissorRect(device, &scissorrect);
1271 if( hr != WINED3D_OK ) {
1272 ERR("This should never happen, expect rendering issues!\n");
1273 }
1274 }
1275 IWineD3DSwapChain_Release(swapchain);
1276 }
1277
1278 TRACE("-----------------------> Device defaults now set up...\n");
1279 return WINED3D_OK;
1280}
1281
1282/**********************************************************
1283 * IWineD3DStateBlock VTbl follows
1284 **********************************************************/
1285
1286const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
1287{
1288 /* IUnknown */
1289 IWineD3DStateBlockImpl_QueryInterface,
1290 IWineD3DStateBlockImpl_AddRef,
1291 IWineD3DStateBlockImpl_Release,
1292 /* IWineD3DStateBlock */
1293 IWineD3DStateBlockImpl_GetParent,
1294 IWineD3DStateBlockImpl_GetDevice,
1295 IWineD3DStateBlockImpl_Capture,
1296 IWineD3DStateBlockImpl_Apply,
1297 IWineD3DStateBlockImpl_InitStartupStateBlock
1298};
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