push 818f085f73990f577927aeb76c81fa65ee9c5568
[wine/hacks.git] / dlls / wined3d / stateblock.c
blobb0cb027677e6039b27acdf8804afaa62661e1429
1 /*
2 * state block implementation
4 * Copyright 2002 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2005 Oliver Stieber
7 * Copyright 2007 Stefan Dösinger for CodeWeavers
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.
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.
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
24 #include "config.h"
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
28 #define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
30 /***************************************
31 * Stateblock helper functions follow
32 **************************************/
34 /** Allocates the correct amount of space for pixel and vertex shader constants,
35 * along with their set/changed flags on the given stateblock object
37 HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
39 IWineD3DStateBlockImpl *This = object;
41 /* Allocate space for floating point constants */
42 object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
43 if (!object->pixelShaderConstantF) goto fail;
45 object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
46 if (!object->changed.pixelShaderConstantsF) goto fail;
48 object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
49 if (!object->vertexShaderConstantF) goto fail;
51 object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
52 if (!object->changed.vertexShaderConstantsF) goto fail;
54 object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
55 if (!object->contained_vs_consts_f) goto fail;
57 object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
58 if (!object->contained_ps_consts_f) goto fail;
60 list_init(&object->set_vconstantsF);
61 list_init(&object->set_pconstantsF);
63 return WINED3D_OK;
65 fail:
66 ERR("Failed to allocate memory\n");
67 HeapFree(GetProcessHeap(), 0, object->pixelShaderConstantF);
68 HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
69 HeapFree(GetProcessHeap(), 0, object->vertexShaderConstantF);
70 HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF);
71 HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f);
72 HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
73 return E_OUTOFMEMORY;
76 /** Copy all members of one stateblock to another */
77 static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *dest, const SAVEDSTATES *source)
79 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
80 unsigned bsize = sizeof(BOOL);
82 /* Single values */
83 dest->indices = source->indices;
84 dest->material = source->material;
85 dest->viewport = source->viewport;
86 dest->vertexDecl = source->vertexDecl;
87 dest->pixelShader = source->pixelShader;
88 dest->vertexShader = source->vertexShader;
89 dest->scissorRect = dest->scissorRect;
91 /* Fixed size arrays */
92 memcpy(dest->streamSource, source->streamSource, bsize * MAX_STREAMS);
93 memcpy(dest->streamFreq, source->streamFreq, bsize * MAX_STREAMS);
94 memcpy(dest->textures, source->textures, bsize * MAX_COMBINED_SAMPLERS);
95 memcpy(dest->transform, source->transform, bsize * (HIGHEST_TRANSFORMSTATE + 1));
96 memcpy(dest->renderState, source->renderState, bsize * (WINEHIGHEST_RENDER_STATE + 1));
97 memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
98 memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
99 memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
100 dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
101 dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
102 dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
103 dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
105 /* Dynamically sized arrays */
106 memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
107 memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
110 /** Set all members of a stateblock savedstate to the given value */
111 void stateblock_savedstates_set(
112 IWineD3DStateBlock* iface,
113 SAVEDSTATES* states,
114 BOOL value) {
116 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
117 unsigned bsize = sizeof(BOOL);
119 /* Single values */
120 states->indices = value;
121 states->material = value;
122 states->viewport = value;
123 states->vertexDecl = value;
124 states->pixelShader = value;
125 states->vertexShader = value;
126 states->scissorRect = value;
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;
142 /* Dynamically sized arrays */
143 memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
144 memset(states->vertexShaderConstantsF, value, bsize * GL_LIMITS(vshader_constantsF));
147 void stateblock_copy(
148 IWineD3DStateBlock* destination,
149 IWineD3DStateBlock* source) {
150 int l;
152 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)source;
153 IWineD3DStateBlockImpl *Dest = (IWineD3DStateBlockImpl *)destination;
155 /* IUnknown fields */
156 Dest->lpVtbl = This->lpVtbl;
157 Dest->ref = This->ref;
159 /* IWineD3DStateBlock information */
160 Dest->parent = This->parent;
161 Dest->wineD3DDevice = This->wineD3DDevice;
162 Dest->blockType = This->blockType;
164 /* Saved states */
165 stateblock_savedstates_copy(source, &Dest->changed, &This->changed);
167 /* Single items */
168 Dest->vertexDecl = This->vertexDecl;
169 Dest->vertexShader = This->vertexShader;
170 Dest->streamIsUP = This->streamIsUP;
171 Dest->pIndexData = This->pIndexData;
172 Dest->baseVertexIndex = This->baseVertexIndex;
173 /* Dest->lights = This->lights; */
174 Dest->clip_status = This->clip_status;
175 Dest->viewport = This->viewport;
176 Dest->material = This->material;
177 Dest->pixelShader = This->pixelShader;
178 Dest->scissorRect = This->scissorRect;
180 /* Lights */
181 memset(This->activeLights, 0, sizeof(This->activeLights));
182 for(l = 0; l < LIGHTMAP_SIZE; l++) {
183 struct list *e1, *e2;
184 LIST_FOR_EACH_SAFE(e1, e2, &Dest->lightMap[l]) {
185 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
186 list_remove(&light->entry);
187 HeapFree(GetProcessHeap(), 0, light);
190 LIST_FOR_EACH(e1, &This->lightMap[l]) {
191 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry), *light2;
192 light2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*light));
193 *light2 = *light;
194 list_add_tail(&Dest->lightMap[l], &light2->entry);
195 if(light2->glIndex != -1) Dest->activeLights[light2->glIndex] = light2;
199 /* Fixed size arrays */
200 memcpy(Dest->vertexShaderConstantB, This->vertexShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
201 memcpy(Dest->vertexShaderConstantI, This->vertexShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
202 memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
203 memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
205 memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
206 memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
207 memcpy(Dest->streamSource, This->streamSource, sizeof(IWineD3DVertexBuffer*) * MAX_STREAMS);
208 memcpy(Dest->streamFreq, This->streamFreq, sizeof(UINT) * MAX_STREAMS);
209 memcpy(Dest->streamFlags, This->streamFlags, sizeof(UINT) * MAX_STREAMS);
210 memcpy(Dest->transforms, This->transforms, sizeof(WINED3DMATRIX) * (HIGHEST_TRANSFORMSTATE + 1));
211 memcpy(Dest->clipplane, This->clipplane, sizeof(double) * MAX_CLIPPLANES * 4);
212 memcpy(Dest->renderState, This->renderState, sizeof(DWORD) * (WINEHIGHEST_RENDER_STATE + 1));
213 memcpy(Dest->textures, This->textures, sizeof(IWineD3DBaseTexture*) * MAX_COMBINED_SAMPLERS);
214 memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
215 memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
217 /* Dynamically sized arrays */
218 memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
219 memcpy(Dest->pixelShaderConstantF, This->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
222 /**********************************************************
223 * IWineD3DStateBlockImpl IUnknown parts follows
224 **********************************************************/
225 static HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,REFIID riid,LPVOID *ppobj)
227 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
228 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
229 if (IsEqualGUID(riid, &IID_IUnknown)
230 || IsEqualGUID(riid, &IID_IWineD3DBase)
231 || IsEqualGUID(riid, &IID_IWineD3DStateBlock)){
232 IUnknown_AddRef(iface);
233 *ppobj = This;
234 return S_OK;
236 *ppobj = NULL;
237 return E_NOINTERFACE;
240 static ULONG WINAPI IWineD3DStateBlockImpl_AddRef(IWineD3DStateBlock *iface) {
241 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
242 ULONG refCount = InterlockedIncrement(&This->ref);
244 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
245 return refCount;
248 static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
249 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
250 ULONG refCount = InterlockedDecrement(&This->ref);
252 TRACE("(%p) : Releasing from %d\n", This, refCount + 1);
254 if (!refCount) {
255 constants_entry *constant, *constant2;
256 int counter;
258 /* type 0 represents the primary stateblock, so free all the resources */
259 if (This->blockType == WINED3DSBT_INIT) {
260 /* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
261 for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) {
262 if (This->textures[counter]) {
263 /* release our 'internal' hold on the texture */
264 if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
265 TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
271 for (counter = 0; counter < MAX_STREAMS; counter++) {
272 if(This->streamSource[counter]) {
273 if(0 != IWineD3DVertexBuffer_Release(This->streamSource[counter])) {
274 TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter, This->streamSource[counter]);
278 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
279 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
280 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
282 for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
283 struct list *e1, *e2;
284 LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) {
285 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
286 list_remove(&light->entry);
287 HeapFree(GetProcessHeap(), 0, light);
291 HeapFree(GetProcessHeap(), 0, This->vertexShaderConstantF);
292 HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
293 HeapFree(GetProcessHeap(), 0, This->pixelShaderConstantF);
294 HeapFree(GetProcessHeap(), 0, This->changed.pixelShaderConstantsF);
295 HeapFree(GetProcessHeap(), 0, This->contained_vs_consts_f);
296 HeapFree(GetProcessHeap(), 0, This->contained_ps_consts_f);
298 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_vconstantsF, constants_entry, entry) {
299 HeapFree(GetProcessHeap(), 0, constant);
302 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_pconstantsF, constants_entry, entry) {
303 HeapFree(GetProcessHeap(), 0, constant);
306 HeapFree(GetProcessHeap(), 0, This);
308 return refCount;
311 /**********************************************************
312 * IWineD3DStateBlockImpl parts follows
313 **********************************************************/
314 static HRESULT WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
315 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
316 IUnknown_AddRef(This->parent);
317 *pParent = This->parent;
318 return WINED3D_OK;
321 static HRESULT WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
323 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
325 *ppDevice = (IWineD3DDevice*)This->wineD3DDevice;
326 IWineD3DDevice_AddRef(*ppDevice);
327 return WINED3D_OK;
331 static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
332 UINT i;
334 /* Lights... For a recorded state block, we just had a chain of actions to perform,
335 * so we need to walk that chain and update any actions which differ
337 for(i = 0; i < LIGHTMAP_SIZE; i++) {
338 struct list *e, *f;
339 LIST_FOR_EACH(e, &This->lightMap[i]) {
340 BOOL updated = FALSE;
341 PLIGHTINFOEL *src = LIST_ENTRY(e, PLIGHTINFOEL, entry), *realLight;
342 if(!src->changed || !src->enabledChanged) continue;
344 /* Look up the light in the destination */
345 LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) {
346 realLight = LIST_ENTRY(f, PLIGHTINFOEL, entry);
347 if(realLight->OriginalIndex == src->OriginalIndex) {
348 if(src->changed) {
349 src->OriginalParms = realLight->OriginalParms;
351 if(src->enabledChanged) {
352 /* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
353 * or disabled -> enabled -> disabled changes
355 if(realLight->glIndex == -1 && src->glIndex != -1) {
356 /* Light disabled */
357 This->activeLights[src->glIndex] = NULL;
358 } else if(realLight->glIndex != -1 && src->glIndex == -1){
359 /* Light enabled */
360 This->activeLights[realLight->glIndex] = src;
362 src->glIndex = realLight->glIndex;
364 updated = TRUE;
365 break;
369 if(updated) {
370 /* Found a light, all done, proceed with next hash entry */
371 continue;
372 } else if(src->changed) {
373 /* Otherwise assign defaul params */
374 src->OriginalParms = WINED3D_default_light;
375 } else {
376 /* Not enabled by default */
377 src->glIndex = -1;
383 static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
385 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
386 IWineD3DStateBlockImpl *targetStateBlock = This->wineD3DDevice->stateBlock;
387 unsigned int i, j;
389 TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This);
391 /* If not recorded, then update can just recapture */
392 if (This->blockType == WINED3DSBT_RECORDED) {
394 /* Recorded => Only update 'changed' values */
395 if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader) {
396 TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
398 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
399 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
400 This->vertexShader = targetStateBlock->vertexShader;
403 /* Vertex Shader Float Constants */
404 for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
405 i = This->contained_vs_consts_f[j];
406 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
407 targetStateBlock->vertexShaderConstantF[i * 4],
408 targetStateBlock->vertexShaderConstantF[i * 4 + 1],
409 targetStateBlock->vertexShaderConstantF[i * 4 + 2],
410 targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
412 This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
413 This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
414 This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
415 This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
418 /* Vertex Shader Integer Constants */
419 for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
420 i = This->contained_vs_consts_i[j];
421 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
422 targetStateBlock->vertexShaderConstantI[i * 4],
423 targetStateBlock->vertexShaderConstantI[i * 4 + 1],
424 targetStateBlock->vertexShaderConstantI[i * 4 + 2],
425 targetStateBlock->vertexShaderConstantI[i * 4 + 3]);
427 This->vertexShaderConstantI[i * 4] = targetStateBlock->vertexShaderConstantI[i * 4];
428 This->vertexShaderConstantI[i * 4 + 1] = targetStateBlock->vertexShaderConstantI[i * 4 + 1];
429 This->vertexShaderConstantI[i * 4 + 2] = targetStateBlock->vertexShaderConstantI[i * 4 + 2];
430 This->vertexShaderConstantI[i * 4 + 3] = targetStateBlock->vertexShaderConstantI[i * 4 + 3];
433 /* Vertex Shader Boolean Constants */
434 for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
435 i = This->contained_vs_consts_b[j];
436 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
437 targetStateBlock->vertexShaderConstantB[i]? "TRUE":"FALSE");
439 This->vertexShaderConstantB[i] = targetStateBlock->vertexShaderConstantB[i];
442 /* Pixel Shader Float Constants */
443 for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
444 i = This->contained_ps_consts_f[j];
445 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
446 targetStateBlock->pixelShaderConstantF[i * 4],
447 targetStateBlock->pixelShaderConstantF[i * 4 + 1],
448 targetStateBlock->pixelShaderConstantF[i * 4 + 2],
449 targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
451 This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
452 This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
453 This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
454 This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
457 /* Pixel Shader Integer Constants */
458 for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
459 i = This->contained_ps_consts_i[j];
460 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
461 targetStateBlock->pixelShaderConstantI[i * 4],
462 targetStateBlock->pixelShaderConstantI[i * 4 + 1],
463 targetStateBlock->pixelShaderConstantI[i * 4 + 2],
464 targetStateBlock->pixelShaderConstantI[i * 4 + 3]);
466 This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4];
467 This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
468 This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
469 This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
472 /* Pixel Shader Boolean Constants */
473 for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
474 i = This->contained_ps_consts_b[j];
475 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
476 targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE");
478 This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i];
481 /* Others + Render & Texture */
482 for (i = 0; i < This->num_contained_transform_states; i++) {
483 TRACE("Updating transform %d\n", i);
484 This->transforms[This->contained_transform_states[i]] =
485 targetStateBlock->transforms[This->contained_transform_states[i]];
488 if (This->changed.indices && ((This->pIndexData != targetStateBlock->pIndexData)
489 || (This->baseVertexIndex != targetStateBlock->baseVertexIndex))) {
490 TRACE("Updating pindexData to %p, baseVertexIndex to %d\n",
491 targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
492 if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
493 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
494 This->pIndexData = targetStateBlock->pIndexData;
495 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
498 if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
499 TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
501 This->vertexDecl = targetStateBlock->vertexDecl;
504 if (This->changed.material && memcmp(&targetStateBlock->material,
505 &This->material,
506 sizeof(WINED3DMATERIAL)) != 0) {
507 TRACE("Updating material\n");
508 This->material = targetStateBlock->material;
511 if (This->changed.viewport && memcmp(&targetStateBlock->viewport,
512 &This->viewport,
513 sizeof(WINED3DVIEWPORT)) != 0) {
514 TRACE("Updating viewport\n");
515 This->viewport = targetStateBlock->viewport;
518 if(This->changed.scissorRect && memcmp(&targetStateBlock->scissorRect,
519 &This->scissorRect,
520 sizeof(targetStateBlock->scissorRect)))
522 TRACE("Updating scissor rect\n");
523 targetStateBlock->scissorRect = This->scissorRect;
526 for (i = 0; i < MAX_STREAMS; i++) {
527 if (This->changed.streamSource[i] &&
528 ((This->streamStride[i] != targetStateBlock->streamStride[i]) ||
529 (This->streamSource[i] != targetStateBlock->streamSource[i]))) {
530 TRACE("Updating stream source %d to %p, stride to %d\n", i, targetStateBlock->streamSource[i],
531 targetStateBlock->streamStride[i]);
532 This->streamStride[i] = targetStateBlock->streamStride[i];
533 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
534 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
535 This->streamSource[i] = targetStateBlock->streamSource[i];
538 if (This->changed.streamFreq[i] &&
539 (This->streamFreq[i] != targetStateBlock->streamFreq[i]
540 || This->streamFlags[i] != targetStateBlock->streamFlags[i])){
541 TRACE("Updating stream frequency %d to %d flags to %d\n", i , targetStateBlock->streamFreq[i] ,
542 targetStateBlock->streamFlags[i]);
543 This->streamFreq[i] = targetStateBlock->streamFreq[i];
544 This->streamFlags[i] = targetStateBlock->streamFlags[i];
548 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
549 if (This->changed.clipplane[i]
550 && memcmp(targetStateBlock->clipplane[i], This->clipplane[i], sizeof(*This->clipplane)))
552 TRACE("Updating clipplane %d\n", i);
553 memcpy(This->clipplane[i], targetStateBlock->clipplane[i], sizeof(*This->clipplane));
557 /* Render */
558 for (i = 0; i < This->num_contained_render_states; i++) {
559 TRACE("Updating renderState %d to %d\n",
560 This->contained_render_states[i], targetStateBlock->renderState[This->contained_render_states[i]]);
561 This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
564 /* Texture states */
565 for (j = 0; j < This->num_contained_tss_states; j++) {
566 DWORD stage = This->contained_tss_states[j].stage;
567 DWORD state = This->contained_tss_states[j].state;
569 TRACE("Updating texturestagestate %d,%d to %d (was %d)\n", stage,state,
570 targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
571 This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
574 /* Samplers */
575 /* TODO: move over to using memcpy */
576 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
577 if (This->changed.textures[j]) {
578 TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]);
579 This->textures[j] = targetStateBlock->textures[j];
583 for (j = 0; j < This->num_contained_sampler_states; j++) {
584 DWORD stage = This->contained_sampler_states[j].stage;
585 DWORD state = This->contained_sampler_states[j].state;
586 TRACE("Updating sampler state %d,%d to %d (was %d)\n",
587 stage, state, targetStateBlock->samplerState[stage][state],
588 This->samplerState[stage][state]);
589 This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
591 if(This->changed.pixelShader && This->pixelShader != targetStateBlock->pixelShader) {
592 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
593 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
594 This->pixelShader = targetStateBlock->pixelShader;
597 record_lights(This, targetStateBlock);
598 } else if(This->blockType == WINED3DSBT_ALL) {
599 This->vertexDecl = targetStateBlock->vertexDecl;
600 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
601 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
602 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
603 memcpy(This->streamStride, targetStateBlock->streamStride, sizeof(This->streamStride));
604 memcpy(This->streamOffset, targetStateBlock->streamOffset, sizeof(This->streamOffset));
605 memcpy(This->streamFreq, targetStateBlock->streamFreq, sizeof(This->streamFreq));
606 memcpy(This->streamFlags, targetStateBlock->streamFlags, sizeof(This->streamFlags));
607 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
608 memcpy(This->transforms, targetStateBlock->transforms, sizeof(This->transforms));
609 record_lights(This, targetStateBlock);
610 memcpy(This->clipplane, targetStateBlock->clipplane, sizeof(This->clipplane));
611 This->clip_status = targetStateBlock->clip_status;
612 This->viewport = targetStateBlock->viewport;
613 This->material = targetStateBlock->material;
614 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
615 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
616 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
617 memcpy(This->renderState, targetStateBlock->renderState, sizeof(This->renderState));
618 memcpy(This->textures, targetStateBlock->textures, sizeof(This->textures));
619 memcpy(This->textureState, targetStateBlock->textureState, sizeof(This->textureState));
620 memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
621 This->scissorRect = targetStateBlock->scissorRect;
623 if(targetStateBlock->pIndexData != This->pIndexData) {
624 if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
625 if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
626 This->pIndexData = targetStateBlock->pIndexData;
628 for(i = 0; i < MAX_STREAMS; i++) {
629 if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
630 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
631 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
632 This->streamSource[i] = targetStateBlock->streamSource[i];
635 if(This->vertexShader != targetStateBlock->vertexShader) {
636 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
637 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
638 This->vertexShader = targetStateBlock->vertexShader;
640 if(This->pixelShader != targetStateBlock->pixelShader) {
641 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
642 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
643 This->pixelShader = targetStateBlock->pixelShader;
645 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
646 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
647 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
648 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
649 record_lights(This, targetStateBlock);
650 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
651 This->renderState[SavedVertexStates_R[i]] = targetStateBlock->renderState[SavedVertexStates_R[i]];
653 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
654 for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
655 This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
658 for (j = 0; j < MAX_TEXTURES; j++) {
659 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
660 This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
663 for(i = 0; i < MAX_STREAMS; i++) {
664 if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
665 if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
666 if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
667 This->streamSource[i] = targetStateBlock->streamSource[i];
670 if(This->vertexShader != targetStateBlock->vertexShader) {
671 if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
672 if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
673 This->vertexShader = targetStateBlock->vertexShader;
675 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
676 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
677 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
678 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
679 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
680 This->renderState[SavedPixelStates_R[i]] = targetStateBlock->renderState[SavedPixelStates_R[i]];
682 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
683 for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
684 This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
687 for (j = 0; j < MAX_TEXTURES; j++) {
688 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
689 This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
692 if(This->pixelShader != targetStateBlock->pixelShader) {
693 if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
694 if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
695 This->pixelShader = targetStateBlock->pixelShader;
699 TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock, This);
701 return WINED3D_OK;
704 static inline void apply_lights(IWineD3DDevice *pDevice, IWineD3DStateBlockImpl *This) {
705 UINT i;
706 for(i = 0; i < LIGHTMAP_SIZE; i++) {
707 struct list *e;
709 LIST_FOR_EACH(e, &This->lightMap[i]) {
710 const PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
712 if(light->changed) {
713 IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
715 if(light->enabledChanged) {
716 IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
722 static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface){
723 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
724 IWineD3DDevice* pDevice = (IWineD3DDevice*)This->wineD3DDevice;
726 /*Copy thing over to updateBlock is isRecording otherwise StateBlock,
727 should really perform a delta so that only the changes get updated*/
729 UINT i;
730 UINT j;
732 TRACE("(%p) : Applying state block %p ------------------v\n", This, pDevice);
734 TRACE("Blocktype: %d\n", This->blockType);
736 if(This->blockType == WINED3DSBT_RECORDED) {
737 if (This->changed.vertexShader) {
738 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
740 /* Vertex Shader Constants */
741 for (i = 0; i < This->num_contained_vs_consts_f; i++) {
742 IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
743 This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
745 for (i = 0; i < This->num_contained_vs_consts_i; i++) {
746 IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
747 This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
749 for (i = 0; i < This->num_contained_vs_consts_b; i++) {
750 IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
751 This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
754 apply_lights(pDevice, This);
756 if (This->changed.pixelShader) {
757 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
759 /* Pixel Shader Constants */
760 for (i = 0; i < This->num_contained_ps_consts_f; i++) {
761 IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
762 This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
764 for (i = 0; i < This->num_contained_ps_consts_i; i++) {
765 IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
766 This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
768 for (i = 0; i < This->num_contained_ps_consts_b; i++) {
769 IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
770 This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
773 /* Render */
774 for (i = 0; i <= This->num_contained_render_states; i++) {
775 IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
776 This->renderState[This->contained_render_states[i]]);
778 /* Texture states */
779 for (i = 0; i < This->num_contained_tss_states; i++) {
780 DWORD stage = This->contained_tss_states[i].stage;
781 DWORD state = This->contained_tss_states[i].state;
782 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state] = This->textureState[stage][state];
783 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.textureState[stage][state] = TRUE;
784 /* TODO: Record a display list to apply all gl states. For now apply by brute force */
785 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state));
787 /* Sampler states */
788 for (i = 0; i < This->num_contained_sampler_states; i++) {
789 DWORD stage = This->contained_sampler_states[i].stage;
790 DWORD state = This->contained_sampler_states[i].state;
791 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state];
792 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage][state] = TRUE;
793 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage));
796 for (i = 0; i < This->num_contained_transform_states; i++) {
797 IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
798 &This->transforms[This->contained_transform_states[i]]);
801 if (This->changed.indices) {
802 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
803 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
806 if (This->changed.vertexDecl) {
807 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
810 if (This->changed.material ) {
811 IWineD3DDevice_SetMaterial(pDevice, &This->material);
814 if (This->changed.viewport) {
815 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
818 if (This->changed.scissorRect) {
819 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
822 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
823 for (i=0; i<MAX_STREAMS; i++) {
824 if (This->changed.streamSource[i])
825 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
827 if (This->changed.streamFreq[i])
828 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
830 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
831 if (This->changed.textures[j]) {
832 if (j < MAX_FRAGMENT_SAMPLERS) {
833 IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
834 } else {
835 IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]);
840 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
841 if (This->changed.clipplane[i]) {
842 float clip[4];
844 clip[0] = This->clipplane[i][0];
845 clip[1] = This->clipplane[i][1];
846 clip[2] = This->clipplane[i][2];
847 clip[3] = This->clipplane[i][3];
848 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
852 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
853 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
854 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
855 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
856 This->vertexShaderConstantF + i * 4, 1);
858 for (i = 0; i < MAX_CONST_I; i++) {
859 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
860 This->vertexShaderConstantI + i * 4, 1);
862 for (i = 0; i < MAX_CONST_B; i++) {
863 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
864 This->vertexShaderConstantB + i, 1);
867 apply_lights(pDevice, This);
869 for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
870 IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
872 for(j = 0; j < MAX_TEXTURES; j++) {
873 for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
874 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
875 This->textureState[j][SavedVertexStates_T[i]]);
879 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
880 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
881 IWineD3DDevice_SetSamplerState(pDevice, j, SavedVertexStates_S[i],
882 This->samplerState[j][SavedVertexStates_S[i]]);
885 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
886 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
887 IWineD3DDevice_SetSamplerState(pDevice,
888 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
889 SavedVertexStates_S[i],
890 This->samplerState[j][SavedVertexStates_S[i]]);
893 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
894 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
895 for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
896 IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
897 This->pixelShaderConstantF + i * 4, 1);
899 for (i = 0; i < MAX_CONST_I; i++) {
900 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
901 This->pixelShaderConstantI + i * 4, 1);
903 for (i = 0; i < MAX_CONST_B; i++) {
904 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
905 This->pixelShaderConstantB + i, 1);
908 for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
909 IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
911 for(j = 0; j < MAX_TEXTURES; j++) {
912 for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
913 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
914 This->textureState[j][SavedPixelStates_T[i]]);
918 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
919 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
920 IWineD3DDevice_SetSamplerState(pDevice, j, SavedPixelStates_S[i],
921 This->samplerState[j][SavedPixelStates_S[i]]);
924 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
925 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
926 IWineD3DDevice_SetSamplerState(pDevice,
927 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
928 SavedPixelStates_S[i],
929 This->samplerState[j][SavedPixelStates_S[i]]);
932 } else if(This->blockType == WINED3DSBT_ALL) {
933 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
934 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
935 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
936 This->vertexShaderConstantF + i * 4, 1);
938 for (i = 0; i < MAX_CONST_I; i++) {
939 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
940 This->vertexShaderConstantI + i * 4, 1);
942 for (i = 0; i < MAX_CONST_B; i++) {
943 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
944 This->vertexShaderConstantB + i, 1);
947 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
948 for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
949 IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
950 This->pixelShaderConstantF + i * 4, 1);
952 for (i = 0; i < MAX_CONST_I; i++) {
953 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
954 This->pixelShaderConstantI + i * 4, 1);
956 for (i = 0; i < MAX_CONST_B; i++) {
957 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
958 This->pixelShaderConstantB + i, 1);
961 apply_lights(pDevice, This);
963 for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
964 IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
966 for(j = 0; j < MAX_TEXTURES; j++) {
967 for(i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE; i++) {
968 IWineD3DDevice_SetTextureStageState(pDevice, j, i, This->textureState[j][i]);
972 /* Skip unused values between TEXTURE8 and WORLD0 ? */
973 for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
974 IWineD3DDevice_SetTransform(pDevice, i, &This->transforms[i]);
976 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
977 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
978 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
979 IWineD3DDevice_SetMaterial(pDevice, &This->material);
980 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
981 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
983 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
984 for (i=0; i<MAX_STREAMS; i++) {
985 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
986 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
988 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
989 UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
991 IWineD3DDevice_SetTexture(pDevice, sampler, This->textures[j]);
992 for(i = 1; i < WINED3D_HIGHEST_SAMPLER_STATE; i++) {
993 IWineD3DDevice_SetSamplerState(pDevice, sampler, i, This->samplerState[j][i]);
996 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
997 float clip[4];
999 clip[0] = This->clipplane[i][0];
1000 clip[1] = This->clipplane[i][1];
1001 clip[2] = This->clipplane[i][2];
1002 clip[3] = This->clipplane[i][3];
1003 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
1007 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
1008 for(j = 0; j < MAX_TEXTURES - 1; j++) {
1009 if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
1010 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = j;
1011 break;
1014 TRACE("(%p) : Applied state block %p ------------------^\n", This, pDevice);
1016 return WINED3D_OK;
1019 static HRESULT WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock* iface) {
1020 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
1021 IWineD3DDevice *device = (IWineD3DDevice *)This->wineD3DDevice;
1022 IWineD3DDeviceImpl *ThisDevice = (IWineD3DDeviceImpl *)device;
1023 union {
1024 WINED3DLINEPATTERN lp;
1025 DWORD d;
1026 } lp;
1027 union {
1028 float f;
1029 DWORD d;
1030 } tmpfloat;
1031 unsigned int i;
1032 IWineD3DSwapChain *swapchain;
1033 IWineD3DSurface *backbuffer;
1034 WINED3DSURFACE_DESC desc = {0};
1035 UINT width, height;
1036 RECT scissorrect;
1037 HRESULT hr;
1039 /* Note this may have a large overhead but it should only be executed
1040 once, in order to initialize the complete state of the device and
1041 all opengl equivalents */
1042 TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
1043 /* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
1044 This->blockType = WINED3DSBT_INIT;
1046 /* Set some of the defaults for lights, transforms etc */
1047 memcpy(&This->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
1048 memcpy(&This->transforms[WINED3DTS_VIEW], identity, sizeof(identity));
1049 for (i = 0; i < 256; ++i) {
1050 memcpy(&This->transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity));
1053 TRACE("Render states\n");
1054 /* Render states: */
1055 if (ThisDevice->auto_depth_stencil_buffer != NULL) {
1056 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_TRUE);
1057 } else {
1058 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_FALSE);
1060 IWineD3DDevice_SetRenderState(device, WINED3DRS_FILLMODE, WINED3DFILL_SOLID);
1061 IWineD3DDevice_SetRenderState(device, WINED3DRS_SHADEMODE, WINED3DSHADE_GOURAUD);
1062 lp.lp.wRepeatFactor = 0;
1063 lp.lp.wLinePattern = 0;
1064 IWineD3DDevice_SetRenderState(device, WINED3DRS_LINEPATTERN, lp.d);
1065 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZWRITEENABLE, TRUE);
1066 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHATESTENABLE, FALSE);
1067 IWineD3DDevice_SetRenderState(device, WINED3DRS_LASTPIXEL, TRUE);
1068 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLEND, WINED3DBLEND_ONE);
1069 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLEND, WINED3DBLEND_ZERO);
1070 IWineD3DDevice_SetRenderState(device, WINED3DRS_CULLMODE, WINED3DCULL_CCW);
1071 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZFUNC, WINED3DCMP_LESSEQUAL);
1072 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAFUNC, WINED3DCMP_ALWAYS);
1073 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAREF, 0);
1074 IWineD3DDevice_SetRenderState(device, WINED3DRS_DITHERENABLE, FALSE);
1075 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHABLENDENABLE, FALSE);
1076 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGENABLE, FALSE);
1077 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARENABLE, FALSE);
1078 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZVISIBLE, 0);
1079 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGCOLOR, 0);
1080 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGTABLEMODE, WINED3DFOG_NONE);
1081 tmpfloat.f = 0.0f;
1082 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGSTART, tmpfloat.d);
1083 tmpfloat.f = 1.0f;
1084 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGEND, tmpfloat.d);
1085 tmpfloat.f = 1.0f;
1086 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGDENSITY, tmpfloat.d);
1087 IWineD3DDevice_SetRenderState(device, WINED3DRS_EDGEANTIALIAS, FALSE);
1088 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZBIAS, 0);
1089 IWineD3DDevice_SetRenderState(device, WINED3DRS_RANGEFOGENABLE, FALSE);
1090 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILENABLE, FALSE);
1091 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1092 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1093 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILPASS, WINED3DSTENCILOP_KEEP);
1094 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILREF, 0);
1095 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILMASK, 0xFFFFFFFF);
1096 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFUNC, WINED3DCMP_ALWAYS);
1097 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
1098 IWineD3DDevice_SetRenderState(device, WINED3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
1099 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP0, 0);
1100 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP1, 0);
1101 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP2, 0);
1102 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP3, 0);
1103 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP4, 0);
1104 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP5, 0);
1105 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP6, 0);
1106 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP7, 0);
1107 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPING, TRUE);
1108 IWineD3DDevice_SetRenderState(device, WINED3DRS_LIGHTING, TRUE);
1109 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENT, 0);
1110 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGVERTEXMODE, WINED3DFOG_NONE);
1111 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORVERTEX, TRUE);
1112 IWineD3DDevice_SetRenderState(device, WINED3DRS_LOCALVIEWER, TRUE);
1113 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALIZENORMALS, FALSE);
1114 IWineD3DDevice_SetRenderState(device, WINED3DRS_DIFFUSEMATERIALSOURCE, WINED3DMCS_COLOR1);
1115 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARMATERIALSOURCE, WINED3DMCS_COLOR2);
1116 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENTMATERIALSOURCE, WINED3DMCS_MATERIAL);
1117 IWineD3DDevice_SetRenderState(device, WINED3DRS_EMISSIVEMATERIALSOURCE, WINED3DMCS_MATERIAL);
1118 IWineD3DDevice_SetRenderState(device, WINED3DRS_VERTEXBLEND, WINED3DVBF_DISABLE);
1119 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPLANEENABLE, 0);
1120 IWineD3DDevice_SetRenderState(device, WINED3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
1121 tmpfloat.f = 1.0f;
1122 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE, tmpfloat.d);
1123 tmpfloat.f = 1.0f;
1124 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN, tmpfloat.d);
1125 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE, FALSE);
1126 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALEENABLE, FALSE);
1127 tmpfloat.f = 1.0f;
1128 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_A, tmpfloat.d);
1129 tmpfloat.f = 0.0f;
1130 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_B, tmpfloat.d);
1131 tmpfloat.f = 0.0f;
1132 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_C, tmpfloat.d);
1133 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEANTIALIAS, TRUE);
1134 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
1135 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHEDGESTYLE, WINED3DPATCHEDGE_DISCRETE);
1136 tmpfloat.f = 1.0f;
1137 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHSEGMENTS, tmpfloat.d);
1138 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEBUGMONITORTOKEN, 0xbaadcafe);
1139 tmpfloat.f = 64.0f;
1140 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MAX, tmpfloat.d);
1141 IWineD3DDevice_SetRenderState(device, WINED3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
1142 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE, 0x0000000F);
1143 tmpfloat.f = 0.0f;
1144 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWEENFACTOR, tmpfloat.d);
1145 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOP, WINED3DBLENDOP_ADD);
1146 IWineD3DDevice_SetRenderState(device, WINED3DRS_POSITIONDEGREE, WINED3DDEGREE_CUBIC);
1147 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALDEGREE, WINED3DDEGREE_LINEAR);
1148 /* states new in d3d9 */
1149 IWineD3DDevice_SetRenderState(device, WINED3DRS_SCISSORTESTENABLE, FALSE);
1150 IWineD3DDevice_SetRenderState(device, WINED3DRS_SLOPESCALEDEPTHBIAS, 0);
1151 tmpfloat.f = 1.0f;
1152 IWineD3DDevice_SetRenderState(device, WINED3DRS_MINTESSELLATIONLEVEL, tmpfloat.d);
1153 IWineD3DDevice_SetRenderState(device, WINED3DRS_MAXTESSELLATIONLEVEL, tmpfloat.d);
1154 IWineD3DDevice_SetRenderState(device, WINED3DRS_ANTIALIASEDLINEENABLE, FALSE);
1155 tmpfloat.f = 0.0f;
1156 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_X, tmpfloat.d);
1157 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Y, tmpfloat.d);
1158 tmpfloat.f = 1.0f;
1159 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Z, tmpfloat.d);
1160 tmpfloat.f = 0.0f;
1161 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_W, tmpfloat.d);
1162 IWineD3DDevice_SetRenderState(device, WINED3DRS_ENABLEADAPTIVETESSELLATION, FALSE);
1163 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWOSIDEDSTENCILMODE, FALSE);
1164 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1165 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1166 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILPASS, WINED3DSTENCILOP_KEEP);
1167 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFUNC, WINED3DCMP_ALWAYS);
1168 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE1, 0x0000000F);
1169 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE2, 0x0000000F);
1170 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE3, 0x0000000F);
1171 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDFACTOR, 0xFFFFFFFF);
1172 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRGBWRITEENABLE, 0);
1173 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEPTHBIAS, 0);
1174 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP8, 0);
1175 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP9, 0);
1176 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP10, 0);
1177 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP11, 0);
1178 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP12, 0);
1179 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP13, 0);
1180 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP14, 0);
1181 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP15, 0);
1182 IWineD3DDevice_SetRenderState(device, WINED3DRS_SEPARATEALPHABLENDENABLE, FALSE);
1183 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLENDALPHA, WINED3DBLEND_ONE);
1184 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLENDALPHA, WINED3DBLEND_ZERO);
1185 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOPALPHA, WINED3DBLENDOP_ADD);
1187 /* clipping status */
1188 This->clip_status.ClipUnion = 0;
1189 This->clip_status.ClipIntersection = 0xFFFFFFFF;
1191 /* Texture Stage States - Put directly into state block, we will call function below */
1192 for (i = 0; i < MAX_TEXTURES; i++) {
1193 TRACE("Setting up default texture states for texture Stage %d\n", i);
1194 memcpy(&This->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
1195 This->textureState[i][WINED3DTSS_COLOROP ] = (i==0)? WINED3DTOP_MODULATE : WINED3DTOP_DISABLE;
1196 This->textureState[i][WINED3DTSS_COLORARG1 ] = WINED3DTA_TEXTURE;
1197 This->textureState[i][WINED3DTSS_COLORARG2 ] = WINED3DTA_CURRENT;
1198 This->textureState[i][WINED3DTSS_ALPHAOP ] = (i==0)? WINED3DTOP_SELECTARG1 : WINED3DTOP_DISABLE;
1199 This->textureState[i][WINED3DTSS_ALPHAARG1 ] = WINED3DTA_TEXTURE;
1200 This->textureState[i][WINED3DTSS_ALPHAARG2 ] = WINED3DTA_CURRENT;
1201 This->textureState[i][WINED3DTSS_BUMPENVMAT00 ] = 0;
1202 This->textureState[i][WINED3DTSS_BUMPENVMAT01 ] = 0;
1203 This->textureState[i][WINED3DTSS_BUMPENVMAT10 ] = 0;
1204 This->textureState[i][WINED3DTSS_BUMPENVMAT11 ] = 0;
1205 This->textureState[i][WINED3DTSS_TEXCOORDINDEX ] = i;
1206 This->textureState[i][WINED3DTSS_BUMPENVLSCALE ] = 0;
1207 This->textureState[i][WINED3DTSS_BUMPENVLOFFSET ] = 0;
1208 This->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS ] = WINED3DTTFF_DISABLE;
1209 This->textureState[i][WINED3DTSS_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1210 This->textureState[i][WINED3DTSS_COLORARG0 ] = WINED3DTA_CURRENT;
1211 This->textureState[i][WINED3DTSS_ALPHAARG0 ] = WINED3DTA_CURRENT;
1212 This->textureState[i][WINED3DTSS_RESULTARG ] = WINED3DTA_CURRENT;
1214 This->lowest_disabled_stage = 1;
1216 /* Sampler states*/
1217 for (i = 0 ; i < MAX_COMBINED_SAMPLERS; i++) {
1218 TRACE("Setting up default samplers states for sampler %d\n", i);
1219 This->samplerState[i][WINED3DSAMP_ADDRESSU ] = WINED3DTADDRESS_WRAP;
1220 This->samplerState[i][WINED3DSAMP_ADDRESSV ] = WINED3DTADDRESS_WRAP;
1221 This->samplerState[i][WINED3DSAMP_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1222 This->samplerState[i][WINED3DSAMP_BORDERCOLOR ] = 0x00;
1223 This->samplerState[i][WINED3DSAMP_MAGFILTER ] = WINED3DTEXF_POINT;
1224 This->samplerState[i][WINED3DSAMP_MINFILTER ] = WINED3DTEXF_POINT;
1225 This->samplerState[i][WINED3DSAMP_MIPFILTER ] = WINED3DTEXF_NONE;
1226 This->samplerState[i][WINED3DSAMP_MIPMAPLODBIAS ] = 0;
1227 This->samplerState[i][WINED3DSAMP_MAXMIPLEVEL ] = 0;
1228 This->samplerState[i][WINED3DSAMP_MAXANISOTROPY ] = 1;
1229 This->samplerState[i][WINED3DSAMP_SRGBTEXTURE ] = 0;
1230 This->samplerState[i][WINED3DSAMP_ELEMENTINDEX ] = 0; /* TODO: Indicates which element of a multielement texture to use */
1231 This->samplerState[i][WINED3DSAMP_DMAPOFFSET ] = 0; /* TODO: Vertex offset in the presampled displacement map */
1234 for(i = 0; i < GL_LIMITS(textures); i++) {
1235 /* Note: This avoids calling SetTexture, so pretend it has been called */
1236 This->changed.textures[i] = TRUE;
1237 This->textures[i] = NULL;
1240 /* Set the default scissor rect values */
1241 desc.Width = &width;
1242 desc.Height = &height;
1244 /* check the return values, because the GetBackBuffer call isn't valid for ddraw */
1245 hr = IWineD3DDevice_GetSwapChain(device, 0, &swapchain);
1246 if( hr == WINED3D_OK && swapchain != NULL) {
1247 hr = IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
1248 if( hr == WINED3D_OK && backbuffer != NULL) {
1249 IWineD3DSurface_GetDesc(backbuffer, &desc);
1250 IWineD3DSurface_Release(backbuffer);
1252 scissorrect.left = 0;
1253 scissorrect.right = width;
1254 scissorrect.top = 0;
1255 scissorrect.bottom = height;
1256 hr = IWineD3DDevice_SetScissorRect(device, &scissorrect);
1257 if( hr != WINED3D_OK ) {
1258 ERR("This should never happen, expect rendering issues!\n");
1261 IWineD3DSwapChain_Release(swapchain);
1264 TRACE("-----------------------> Device defaults now set up...\n");
1265 return WINED3D_OK;
1268 /**********************************************************
1269 * IWineD3DStateBlock VTbl follows
1270 **********************************************************/
1272 const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
1274 /* IUnknown */
1275 IWineD3DStateBlockImpl_QueryInterface,
1276 IWineD3DStateBlockImpl_AddRef,
1277 IWineD3DStateBlockImpl_Release,
1278 /* IWineD3DStateBlock */
1279 IWineD3DStateBlockImpl_GetParent,
1280 IWineD3DStateBlockImpl_GetDevice,
1281 IWineD3DStateBlockImpl_Capture,
1282 IWineD3DStateBlockImpl_Apply,
1283 IWineD3DStateBlockImpl_InitStartupStateBlock