push 4d5485f9b89f417d46b39b93e8d940437007f325
[wine/hacks.git] / dlls / wined3d / stateblock.c
blobb7b64a5f0b7f6eb6e945572818e75cf10b953a9d
1 /*
2 * state block implementation
4 * Copyright 2002 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
29 /***************************************
30 * Stateblock helper functions follow
31 **************************************/
33 /** Allocates the correct amount of space for pixel and vertex shader constants,
34 * along with their set/changed flags on the given stateblock object
36 HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
38 IWineD3DStateBlockImpl *This = object;
40 #define WINED3D_MEMCHECK(_object) if (NULL == _object) { FIXME("Out of memory!\n"); return E_OUTOFMEMORY; }
42 /* Allocate space for floating point constants */
43 object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
44 WINED3D_MEMCHECK(object->pixelShaderConstantF);
45 object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
46 WINED3D_MEMCHECK(object->changed.pixelShaderConstantsF);
47 object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
48 WINED3D_MEMCHECK(object->vertexShaderConstantF);
49 object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
50 WINED3D_MEMCHECK(object->changed.vertexShaderConstantsF);
51 object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
52 WINED3D_MEMCHECK(object->contained_vs_consts_f);
53 object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
54 WINED3D_MEMCHECK(object->contained_ps_consts_f);
56 list_init(&object->set_vconstantsF);
57 list_init(&object->set_pconstantsF);
59 #undef WINED3D_MEMCHECK
61 return WINED3D_OK;
64 /** Copy all members of one stateblock to another */
65 void stateblock_savedstates_copy(
66 IWineD3DStateBlock* iface,
67 SAVEDSTATES* dest,
68 SAVEDSTATES* source) {
70 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
71 unsigned bsize = sizeof(BOOL);
73 /* Single values */
74 dest->indices = source->indices;
75 dest->material = source->material;
76 dest->fvf = source->fvf;
77 dest->viewport = source->viewport;
78 dest->vertexDecl = source->vertexDecl;
79 dest->pixelShader = source->pixelShader;
80 dest->vertexShader = source->vertexShader;
81 dest->scissorRect = dest->scissorRect;
83 /* Fixed size arrays */
84 memcpy(dest->streamSource, source->streamSource, bsize * MAX_STREAMS);
85 memcpy(dest->streamFreq, source->streamFreq, bsize * MAX_STREAMS);
86 memcpy(dest->textures, source->textures, bsize * MAX_COMBINED_SAMPLERS);
87 memcpy(dest->transform, source->transform, bsize * (HIGHEST_TRANSFORMSTATE + 1));
88 memcpy(dest->renderState, source->renderState, bsize * (WINEHIGHEST_RENDER_STATE + 1));
89 memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
90 memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
91 memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
92 memcpy(dest->pixelShaderConstantsB, source->pixelShaderConstantsB, bsize * MAX_CONST_B);
93 memcpy(dest->pixelShaderConstantsI, source->pixelShaderConstantsI, bsize * MAX_CONST_I);
94 memcpy(dest->vertexShaderConstantsB, source->vertexShaderConstantsB, bsize * MAX_CONST_B);
95 memcpy(dest->vertexShaderConstantsI, source->vertexShaderConstantsI, bsize * MAX_CONST_I);
97 /* Dynamically sized arrays */
98 memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
99 memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
102 /** Set all members of a stateblock savedstate to the given value */
103 void stateblock_savedstates_set(
104 IWineD3DStateBlock* iface,
105 SAVEDSTATES* states,
106 BOOL value) {
108 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
109 unsigned bsize = sizeof(BOOL);
111 /* Single values */
112 states->indices = value;
113 states->material = value;
114 states->fvf = value;
115 states->viewport = value;
116 states->vertexDecl = value;
117 states->pixelShader = value;
118 states->vertexShader = value;
119 states->scissorRect = value;
121 /* Fixed size arrays */
122 memset(states->streamSource, value, bsize * MAX_STREAMS);
123 memset(states->streamFreq, value, bsize * MAX_STREAMS);
124 memset(states->textures, value, bsize * MAX_COMBINED_SAMPLERS);
125 memset(states->transform, value, bsize * (HIGHEST_TRANSFORMSTATE + 1));
126 memset(states->renderState, value, bsize * (WINEHIGHEST_RENDER_STATE + 1));
127 memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
128 memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
129 memset(states->clipplane, value, bsize * MAX_CLIPPLANES);
130 memset(states->pixelShaderConstantsB, value, bsize * MAX_CONST_B);
131 memset(states->pixelShaderConstantsI, value, bsize * MAX_CONST_I);
132 memset(states->vertexShaderConstantsB, value, bsize * MAX_CONST_B);
133 memset(states->vertexShaderConstantsI, value, bsize * MAX_CONST_I);
135 /* Dynamically sized arrays */
136 memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
137 memset(states->vertexShaderConstantsF, value, bsize * GL_LIMITS(vshader_constantsF));
140 void stateblock_copy(
141 IWineD3DStateBlock* destination,
142 IWineD3DStateBlock* source) {
143 int l;
145 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)source;
146 IWineD3DStateBlockImpl *Dest = (IWineD3DStateBlockImpl *)destination;
148 /* IUnknown fields */
149 Dest->lpVtbl = This->lpVtbl;
150 Dest->ref = This->ref;
152 /* IWineD3DStateBlock information */
153 Dest->parent = This->parent;
154 Dest->wineD3DDevice = This->wineD3DDevice;
155 Dest->blockType = This->blockType;
157 /* Saved states */
158 stateblock_savedstates_copy(source, &Dest->changed, &This->changed);
160 /* Single items */
161 Dest->fvf = This->fvf;
162 Dest->vertexDecl = This->vertexDecl;
163 Dest->vertexShader = This->vertexShader;
164 Dest->streamIsUP = This->streamIsUP;
165 Dest->pIndexData = This->pIndexData;
166 Dest->baseVertexIndex = This->baseVertexIndex;
167 /* Dest->lights = This->lights; */
168 Dest->clip_status = This->clip_status;
169 Dest->viewport = This->viewport;
170 Dest->material = This->material;
171 Dest->pixelShader = This->pixelShader;
172 Dest->glsl_program = This->glsl_program;
173 memcpy(&Dest->scissorRect, &This->scissorRect, sizeof(Dest->scissorRect));
175 /* Lights */
176 memset(This->activeLights, 0, sizeof(This->activeLights));
177 for(l = 0; l < LIGHTMAP_SIZE; l++) {
178 struct list *e1, *e2;
179 LIST_FOR_EACH_SAFE(e1, e2, &Dest->lightMap[l]) {
180 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
181 list_remove(&light->entry);
182 HeapFree(GetProcessHeap(), 0, light);
185 LIST_FOR_EACH(e1, &This->lightMap[l]) {
186 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry), *light2;
187 light2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*light));
188 memcpy(light2, light, sizeof(*light));
189 list_add_tail(&This->lightMap[l], &light2->entry);
190 if(light2->glIndex != -1) This->activeLights[light2->glIndex] = light2;
194 /* Fixed size arrays */
195 memcpy(Dest->vertexShaderConstantB, This->vertexShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
196 memcpy(Dest->vertexShaderConstantI, This->vertexShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
197 memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
198 memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
200 memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
201 memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
202 memcpy(Dest->streamSource, This->streamSource, sizeof(IWineD3DVertexBuffer*) * MAX_STREAMS);
203 memcpy(Dest->streamFreq, This->streamFreq, sizeof(UINT) * MAX_STREAMS);
204 memcpy(Dest->streamFlags, This->streamFlags, sizeof(UINT) * MAX_STREAMS);
205 memcpy(Dest->transforms, This->transforms, sizeof(WINED3DMATRIX) * (HIGHEST_TRANSFORMSTATE + 1));
206 memcpy(Dest->clipplane, This->clipplane, sizeof(double) * MAX_CLIPPLANES * 4);
207 memcpy(Dest->renderState, This->renderState, sizeof(DWORD) * (WINEHIGHEST_RENDER_STATE + 1));
208 memcpy(Dest->textures, This->textures, sizeof(IWineD3DBaseTexture*) * MAX_COMBINED_SAMPLERS);
209 memcpy(Dest->textureDimensions, This->textureDimensions, sizeof(int) * MAX_COMBINED_SAMPLERS);
210 memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
211 memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
213 /* Dynamically sized arrays */
214 memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
215 memcpy(Dest->pixelShaderConstantF, This->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
218 /**********************************************************
219 * IWineD3DStateBlockImpl IUnknown parts follows
220 **********************************************************/
221 static HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,REFIID riid,LPVOID *ppobj)
223 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
224 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
225 if (IsEqualGUID(riid, &IID_IUnknown)
226 || IsEqualGUID(riid, &IID_IWineD3DBase)
227 || IsEqualGUID(riid, &IID_IWineD3DStateBlock)){
228 IUnknown_AddRef(iface);
229 *ppobj = This;
230 return S_OK;
232 *ppobj = NULL;
233 return E_NOINTERFACE;
236 static ULONG WINAPI IWineD3DStateBlockImpl_AddRef(IWineD3DStateBlock *iface) {
237 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
238 ULONG refCount = InterlockedIncrement(&This->ref);
240 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
241 return refCount;
244 static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
245 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
246 ULONG refCount = InterlockedDecrement(&This->ref);
248 TRACE("(%p) : Releasing from %d\n", This, refCount + 1);
250 if (!refCount) {
251 constants_entry *constant, *constant2;
252 int counter;
254 /* type 0 represents the primary stateblock, so free all the resources */
255 if (This->blockType == WINED3DSBT_INIT) {
256 /* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
257 for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) {
258 if (This->textures[counter]) {
259 /* release our 'internal' hold on the texture */
260 if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
261 TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
268 for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
269 struct list *e1, *e2;
270 LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) {
271 PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
272 list_remove(&light->entry);
273 HeapFree(GetProcessHeap(), 0, light);
277 HeapFree(GetProcessHeap(), 0, This->vertexShaderConstantF);
278 HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
279 HeapFree(GetProcessHeap(), 0, This->pixelShaderConstantF);
280 HeapFree(GetProcessHeap(), 0, This->changed.pixelShaderConstantsF);
281 HeapFree(GetProcessHeap(), 0, This->contained_vs_consts_f);
282 HeapFree(GetProcessHeap(), 0, This->contained_ps_consts_f);
284 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_vconstantsF, constants_entry, entry) {
285 HeapFree(GetProcessHeap(), 0, constant);
288 LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_pconstantsF, constants_entry, entry) {
289 HeapFree(GetProcessHeap(), 0, constant);
292 HeapFree(GetProcessHeap(), 0, This);
294 return refCount;
297 /**********************************************************
298 * IWineD3DStateBlockImpl parts follows
299 **********************************************************/
300 static HRESULT WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
301 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
302 IUnknown_AddRef(This->parent);
303 *pParent = This->parent;
304 return WINED3D_OK;
307 static HRESULT WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
309 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
311 *ppDevice = (IWineD3DDevice*)This->wineD3DDevice;
312 IWineD3DDevice_AddRef(*ppDevice);
313 return WINED3D_OK;
317 static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
318 UINT i;
320 /* Lights... For a recorded state block, we just had a chain of actions to perform,
321 * so we need to walk that chain and update any actions which differ
323 for(i = 0; i < LIGHTMAP_SIZE; i++) {
324 struct list *e, *f;
325 LIST_FOR_EACH(e, &This->lightMap[i]) {
326 BOOL updated = FALSE;
327 PLIGHTINFOEL *src = LIST_ENTRY(e, PLIGHTINFOEL, entry), *realLight;
328 if(!src->changed || !src->enabledChanged) continue;
330 /* Look up the light in the destination */
331 LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) {
332 realLight = LIST_ENTRY(f, PLIGHTINFOEL, entry);
333 if(realLight->OriginalIndex == src->OriginalIndex) {
334 if(src->changed) {
335 memcpy(&src->OriginalParms, &realLight->OriginalParms, sizeof(src->OriginalParms));
337 if(src->enabledChanged) {
338 /* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
339 * or disabled -> enabled -> disabled changes
341 if(realLight->glIndex == -1 && src->glIndex != -1) {
342 /* Light disabled */
343 This->activeLights[src->glIndex] = NULL;
344 } else if(realLight->glIndex != -1 && src->glIndex == -1){
345 /* Light enabled */
346 This->activeLights[realLight->glIndex] = src;
348 src->glIndex = realLight->glIndex;
350 updated = TRUE;
351 break;
355 if(updated) {
356 /* Found a light, all done, proceed with next hash entry */
357 continue;
358 } else if(src->changed) {
359 /* Otherwise assign defaul params */
360 memcpy(&src->OriginalParms, &WINED3D_default_light, sizeof(src->OriginalParms));
361 } else {
362 /* Not enabled by default */
363 src->glIndex = -1;
369 static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
371 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
372 IWineD3DStateBlockImpl *targetStateBlock = This->wineD3DDevice->stateBlock;
373 unsigned int i, j;
375 TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This);
377 /* If not recorded, then update can just recapture */
378 if (This->blockType == WINED3DSBT_RECORDED) {
380 /* Recorded => Only update 'changed' values */
381 if (This->vertexShader != targetStateBlock->vertexShader) {
382 TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
384 This->vertexShader = targetStateBlock->vertexShader;
387 /* Vertex Shader Float Constants */
388 for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
389 i = This->contained_vs_consts_f[j];
390 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
391 targetStateBlock->vertexShaderConstantF[i * 4],
392 targetStateBlock->vertexShaderConstantF[i * 4 + 1],
393 targetStateBlock->vertexShaderConstantF[i * 4 + 2],
394 targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
396 This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
397 This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
398 This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
399 This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
402 /* Vertex Shader Integer Constants */
403 for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
404 i = This->contained_vs_consts_i[j];
405 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
406 targetStateBlock->vertexShaderConstantI[i * 4],
407 targetStateBlock->vertexShaderConstantI[i * 4 + 1],
408 targetStateBlock->vertexShaderConstantI[i * 4 + 2],
409 targetStateBlock->vertexShaderConstantI[i * 4 + 3]);
411 This->vertexShaderConstantI[i * 4] = targetStateBlock->vertexShaderConstantI[i * 4];
412 This->vertexShaderConstantI[i * 4 + 1] = targetStateBlock->vertexShaderConstantI[i * 4 + 1];
413 This->vertexShaderConstantI[i * 4 + 2] = targetStateBlock->vertexShaderConstantI[i * 4 + 2];
414 This->vertexShaderConstantI[i * 4 + 3] = targetStateBlock->vertexShaderConstantI[i * 4 + 3];
417 /* Vertex Shader Boolean Constants */
418 for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
419 i = This->contained_vs_consts_b[j];
420 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
421 targetStateBlock->vertexShaderConstantB[i]? "TRUE":"FALSE");
423 This->vertexShaderConstantB[i] = targetStateBlock->vertexShaderConstantB[i];
426 /* Recorded => Only update 'changed' values */
427 if (This->pixelShader != targetStateBlock->pixelShader) {
428 TRACE("Updating pixel shader from %p to %p\n", This->pixelShader, targetStateBlock->pixelShader);
430 This->pixelShader = targetStateBlock->pixelShader;
433 /* Pixel Shader Float Constants */
434 for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
435 i = This->contained_ps_consts_f[j];
436 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
437 targetStateBlock->pixelShaderConstantF[i * 4],
438 targetStateBlock->pixelShaderConstantF[i * 4 + 1],
439 targetStateBlock->pixelShaderConstantF[i * 4 + 2],
440 targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
442 This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
443 This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
444 This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
445 This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
448 /* Pixel Shader Integer Constants */
449 for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
450 i = This->contained_ps_consts_i[j];
451 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
452 targetStateBlock->pixelShaderConstantI[i * 4],
453 targetStateBlock->pixelShaderConstantI[i * 4 + 1],
454 targetStateBlock->pixelShaderConstantI[i * 4 + 2],
455 targetStateBlock->pixelShaderConstantI[i * 4 + 3]);
457 This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4];
458 This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
459 This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
460 This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
463 /* Pixel Shader Boolean Constants */
464 for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
465 i = This->contained_ps_consts_b[j];
466 TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
467 targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE");
469 This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i];
472 /* Others + Render & Texture */
473 for (i = 0; i < This->num_contained_transform_states; i++) {
474 TRACE("Updating transform %d\n", i);
475 memcpy(&This->transforms[This->contained_transform_states[i]],
476 &targetStateBlock->transforms[This->contained_transform_states[i]],
477 sizeof(WINED3DMATRIX));
480 if (This->changed.indices && ((This->pIndexData != targetStateBlock->pIndexData)
481 || (This->baseVertexIndex != targetStateBlock->baseVertexIndex))) {
482 TRACE("Updating pindexData to %p, baseVertexIndex to %d\n",
483 targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
484 This->pIndexData = targetStateBlock->pIndexData;
485 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
488 if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
489 TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
491 This->vertexDecl = targetStateBlock->vertexDecl;
494 if(This->changed.fvf && This->fvf != targetStateBlock->fvf){
495 This->fvf = targetStateBlock->fvf;
498 if (This->changed.material && memcmp(&targetStateBlock->material,
499 &This->material,
500 sizeof(WINED3DMATERIAL)) != 0) {
501 TRACE("Updating material\n");
502 memcpy(&This->material, &targetStateBlock->material, sizeof(WINED3DMATERIAL));
505 if (This->changed.viewport && memcmp(&targetStateBlock->viewport,
506 &This->viewport,
507 sizeof(WINED3DVIEWPORT)) != 0) {
508 TRACE("Updating viewport\n");
509 memcpy(&This->viewport, &targetStateBlock->viewport, sizeof(WINED3DVIEWPORT));
512 if(This->changed.scissorRect && memcmp(&targetStateBlock->scissorRect,
513 &This->scissorRect,
514 sizeof(targetStateBlock->scissorRect)))
516 TRACE("Updating scissor rect\n");
517 memcpy(&targetStateBlock->scissorRect, &This->scissorRect, sizeof(targetStateBlock->scissorRect));
520 for (i = 0; i < MAX_STREAMS; i++) {
521 if (This->changed.streamSource[i] &&
522 ((This->streamStride[i] != targetStateBlock->streamStride[i]) ||
523 (This->streamSource[i] != targetStateBlock->streamSource[i]))) {
524 TRACE("Updating stream source %d to %p, stride to %d\n", i, targetStateBlock->streamSource[i],
525 targetStateBlock->streamStride[i]);
526 This->streamStride[i] = targetStateBlock->streamStride[i];
527 This->streamSource[i] = targetStateBlock->streamSource[i];
530 if (This->changed.streamFreq[i] &&
531 (This->streamFreq[i] != targetStateBlock->streamFreq[i]
532 || This->streamFlags[i] != targetStateBlock->streamFlags[i])){
533 TRACE("Updating stream frequency %d to %d flags to %d\n", i , targetStateBlock->streamFreq[i] ,
534 targetStateBlock->streamFlags[i]);
535 This->streamFreq[i] = targetStateBlock->streamFreq[i];
536 This->streamFlags[i] = targetStateBlock->streamFlags[i];
540 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
541 if (This->changed.clipplane[i] && memcmp(&targetStateBlock->clipplane[i],
542 &This->clipplane[i],
543 sizeof(This->clipplane)) != 0) {
545 TRACE("Updating clipplane %d\n", i);
546 memcpy(&This->clipplane[i], &targetStateBlock->clipplane[i],
547 sizeof(This->clipplane));
551 /* Render */
552 for (i = 0; i < This->num_contained_render_states; i++) {
553 TRACE("Updating renderState %d to %d\n",
554 This->contained_render_states[i], targetStateBlock->renderState[This->contained_render_states[i]]);
555 This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
558 /* Texture states */
559 for (j = 0; j < This->num_contained_tss_states; j++) {
560 DWORD stage = This->contained_tss_states[j].stage;
561 DWORD state = This->contained_tss_states[j].state;
563 TRACE("Updating texturestagestate %d,%d to %d (was %d)\n", stage,state,
564 targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
565 This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
568 /* Samplers */
569 /* TODO: move over to using memcpy */
570 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
571 if (This->changed.textures[j]) {
572 TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]);
573 This->textures[j] = targetStateBlock->textures[j];
577 for (j = 0; j < This->num_contained_sampler_states; j++) {
578 DWORD stage = This->contained_sampler_states[j].stage;
579 DWORD state = This->contained_sampler_states[j].state;
580 TRACE("Updating sampler state %d,%d to %d (was %d)\n",
581 stage, state, targetStateBlock->samplerState[stage][state],
582 This->samplerState[stage][state]);
583 This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
586 record_lights(This, targetStateBlock);
587 } else if(This->blockType == WINED3DSBT_ALL) {
588 This->vertexDecl = targetStateBlock->vertexDecl;
589 This->vertexShader = targetStateBlock->vertexShader;
590 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
591 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
592 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
593 memcpy(This->streamStride, targetStateBlock->streamStride, sizeof(This->streamStride));
594 memcpy(This->streamOffset, targetStateBlock->streamOffset, sizeof(This->streamOffset));
595 memcpy(This->streamSource, targetStateBlock->streamSource, sizeof(This->streamSource));
596 memcpy(This->streamFreq, targetStateBlock->streamFreq, sizeof(This->streamFreq));
597 memcpy(This->streamFlags, targetStateBlock->streamFlags, sizeof(This->streamFlags));
598 This->pIndexData = targetStateBlock->pIndexData;
599 This->baseVertexIndex = targetStateBlock->baseVertexIndex;
600 memcpy(This->transforms, targetStateBlock->transforms, sizeof(This->transforms));
601 record_lights(This, targetStateBlock);
602 memcpy(This->clipplane, targetStateBlock->clipplane, sizeof(This->clipplane));
603 This->clip_status = targetStateBlock->clip_status;
604 This->viewport = targetStateBlock->viewport;
605 This->material = targetStateBlock->material;
606 This->pixelShader = targetStateBlock->pixelShader;
607 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
608 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
609 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
610 memcpy(This->renderState, targetStateBlock->renderState, sizeof(This->renderState));
611 memcpy(This->textures, targetStateBlock->textures, sizeof(This->textures));
612 memcpy(This->textureDimensions, targetStateBlock->textureDimensions, sizeof(This->textureDimensions));
613 memcpy(This->textureState, targetStateBlock->textureState, sizeof(This->textureState));
614 memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
615 This->scissorRect = targetStateBlock->scissorRect;
616 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
617 This->vertexShader = targetStateBlock->vertexShader;
618 memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
619 memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
620 memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
621 record_lights(This, targetStateBlock);
622 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
623 This->renderState[SavedVertexStates_R[i]] = targetStateBlock->renderState[SavedVertexStates_R[i]];
625 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
626 for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
627 This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
630 for (j = 0; j < MAX_TEXTURES; j++) {
631 for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
632 This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
635 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
636 This->pixelShader = targetStateBlock->pixelShader;
637 memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
638 memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
639 memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
640 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
641 This->renderState[SavedPixelStates_R[i]] = targetStateBlock->renderState[SavedPixelStates_R[i]];
643 for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
644 for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
645 This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
648 for (j = 0; j < MAX_TEXTURES; j++) {
649 for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
650 This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
655 TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock, This);
657 return WINED3D_OK;
660 static inline void apply_lights(IWineD3DDevice *pDevice, IWineD3DStateBlockImpl *This) {
661 UINT i;
662 for(i = 0; i < LIGHTMAP_SIZE; i++) {
663 struct list *e;
665 LIST_FOR_EACH(e, &This->lightMap[i]) {
666 PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
668 if(light->changed) {
669 IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
671 if(light->enabledChanged) {
672 IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
678 static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface){
679 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
680 IWineD3DDevice* pDevice = (IWineD3DDevice*)This->wineD3DDevice;
682 /*Copy thing over to updateBlock is isRecording otherwise StateBlock,
683 should really perform a delta so that only the changes get updated*/
685 UINT i;
686 UINT j;
688 TRACE("(%p) : Applying state block %p ------------------v\n", This, pDevice);
690 TRACE("Blocktype: %d\n", This->blockType);
692 if(This->blockType == WINED3DSBT_RECORDED) {
693 if (This->changed.vertexShader) {
694 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
696 /* Vertex Shader Constants */
697 for (i = 0; i < This->num_contained_vs_consts_f; i++) {
698 IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
699 This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
701 for (i = 0; i < This->num_contained_vs_consts_i; i++) {
702 IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
703 This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
705 for (i = 0; i < This->num_contained_vs_consts_b; i++) {
706 IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
707 This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
710 apply_lights(pDevice, This);
712 if (This->changed.pixelShader) {
713 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
715 /* Pixel Shader Constants */
716 for (i = 0; i < This->num_contained_ps_consts_f; i++) {
717 IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
718 This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
720 for (i = 0; i < This->num_contained_ps_consts_i; i++) {
721 IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
722 This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
724 for (i = 0; i < This->num_contained_ps_consts_b; i++) {
725 IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
726 This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
729 /* Render */
730 for (i = 0; i <= This->num_contained_render_states; i++) {
731 IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
732 This->renderState[This->contained_render_states[i]]);
734 /* Texture states */
735 for (i = 0; i < This->num_contained_tss_states; i++) {
736 DWORD stage = This->contained_tss_states[i].stage;
737 DWORD state = This->contained_tss_states[i].state;
738 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state] = This->textureState[stage][state];
739 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.textureState[stage][state] = TRUE;
740 /* TODO: Record a display list to apply all gl states. For now apply by brute force */
741 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state));
743 /* Sampler states */
744 for (i = 0; i < This->num_contained_sampler_states; i++) {
745 DWORD stage = This->contained_sampler_states[i].stage;
746 DWORD state = This->contained_sampler_states[i].state;
747 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state];
748 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage][state] = TRUE;
749 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage));
752 for (i = 0; i < This->num_contained_transform_states; i++) {
753 IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
754 &This->transforms[This->contained_transform_states[i]]);
757 if (This->changed.indices) {
758 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
759 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
762 if (This->changed.fvf) {
763 IWineD3DDevice_SetFVF(pDevice, This->fvf);
766 if (This->changed.vertexDecl) {
767 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
770 if (This->changed.material ) {
771 IWineD3DDevice_SetMaterial(pDevice, &This->material);
774 if (This->changed.viewport) {
775 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
778 if (This->changed.scissorRect) {
779 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
782 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
783 for (i=0; i<MAX_STREAMS; i++) {
784 if (This->changed.streamSource[i])
785 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
787 if (This->changed.streamFreq[i])
788 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
790 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
791 if (This->changed.textures[j]) {
792 if (j < MAX_FRAGMENT_SAMPLERS) {
793 IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
794 } else {
795 IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]);
800 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
801 if (This->changed.clipplane[i]) {
802 float clip[4];
804 clip[0] = This->clipplane[i][0];
805 clip[1] = This->clipplane[i][1];
806 clip[2] = This->clipplane[i][2];
807 clip[3] = This->clipplane[i][3];
808 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
812 } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
813 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
814 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
815 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
816 This->vertexShaderConstantF + i * 4, 1);
818 for (i = 0; i < MAX_CONST_I; i++) {
819 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
820 This->vertexShaderConstantI + i * 4, 1);
822 for (i = 0; i < MAX_CONST_B; i++) {
823 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
824 This->vertexShaderConstantB + i, 1);
827 apply_lights(pDevice, This);
829 for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
830 IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
832 for(j = 0; j < MAX_TEXTURES; j++) {
833 for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
834 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
835 This->textureState[j][SavedVertexStates_T[i]]);
839 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
840 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
841 IWineD3DDevice_SetSamplerState(pDevice, j, SavedVertexStates_S[i],
842 This->samplerState[j][SavedVertexStates_S[i]]);
845 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
846 for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
847 IWineD3DDevice_SetSamplerState(pDevice,
848 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
849 SavedVertexStates_S[i],
850 This->samplerState[j][SavedVertexStates_S[i]]);
853 } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
854 IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
855 for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
856 IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
857 This->pixelShaderConstantF + i * 4, 1);
859 for (i = 0; i < MAX_CONST_I; i++) {
860 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
861 This->pixelShaderConstantI + i * 4, 1);
863 for (i = 0; i < MAX_CONST_B; i++) {
864 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
865 This->pixelShaderConstantB + i, 1);
868 for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
869 IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
871 for(j = 0; j < MAX_TEXTURES; j++) {
872 for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
873 IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
874 This->textureState[j][SavedPixelStates_T[i]]);
878 for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
879 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
880 IWineD3DDevice_SetSamplerState(pDevice, j, SavedPixelStates_S[i],
881 This->samplerState[j][SavedPixelStates_S[i]]);
884 for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
885 for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
886 IWineD3DDevice_SetSamplerState(pDevice,
887 WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
888 SavedPixelStates_S[i],
889 This->samplerState[j][SavedPixelStates_S[i]]);
892 } else if(This->blockType == WINED3DSBT_ALL) {
893 IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
894 for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
895 IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
896 This->vertexShaderConstantF + i * 4, 1);
898 for (i = 0; i < MAX_CONST_I; i++) {
899 IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
900 This->vertexShaderConstantI + i * 4, 1);
902 for (i = 0; i < MAX_CONST_B; i++) {
903 IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
904 This->vertexShaderConstantB + i, 1);
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);
912 for (i = 0; i < MAX_CONST_I; i++) {
913 IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
914 This->pixelShaderConstantI + i * 4, 1);
916 for (i = 0; i < MAX_CONST_B; i++) {
917 IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
918 This->pixelShaderConstantB + i, 1);
921 apply_lights(pDevice, This);
923 for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
924 IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
926 for(j = 0; j < MAX_TEXTURES; j++) {
927 for(i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE; i++) {
928 IWineD3DDevice_SetTextureStageState(pDevice, j, i, This->textureState[j][i]);
932 /* Skip unused values between TEXTURE8 and WORLD0 ? */
933 for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
934 IWineD3DDevice_SetTransform(pDevice, i, &This->transforms[i]);
936 IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
937 IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
938 IWineD3DDevice_SetFVF(pDevice, This->fvf);
939 IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
940 IWineD3DDevice_SetMaterial(pDevice, &This->material);
941 IWineD3DDevice_SetViewport(pDevice, &This->viewport);
942 IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
944 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
945 for (i=0; i<MAX_STREAMS; i++) {
946 IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
947 IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
949 for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
950 UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
952 IWineD3DDevice_SetTexture(pDevice, sampler, This->textures[j]);
953 for(i = 1; i < WINED3D_HIGHEST_SAMPLER_STATE; i++) {
954 IWineD3DDevice_SetSamplerState(pDevice, sampler, i, This->samplerState[j][i]);
957 for (i = 0; i < GL_LIMITS(clipplanes); i++) {
958 float clip[4];
960 clip[0] = This->clipplane[i][0];
961 clip[1] = This->clipplane[i][1];
962 clip[2] = This->clipplane[i][2];
963 clip[3] = This->clipplane[i][3];
964 IWineD3DDevice_SetClipPlane(pDevice, i, clip);
968 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
969 for(j = 0; j < MAX_TEXTURES - 1; j++) {
970 if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
971 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = j;
972 break;
975 TRACE("(%p) : Applied state block %p ------------------^\n", This, pDevice);
977 return WINED3D_OK;
980 static HRESULT WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock* iface) {
981 IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
982 IWineD3DDevice *device = (IWineD3DDevice *)This->wineD3DDevice;
983 IWineD3DDeviceImpl *ThisDevice = (IWineD3DDeviceImpl *)device;
984 union {
985 WINED3DLINEPATTERN lp;
986 DWORD d;
987 } lp;
988 union {
989 float f;
990 DWORD d;
991 } tmpfloat;
992 unsigned int i;
994 /* Note this may have a large overhead but it should only be executed
995 once, in order to initialize the complete state of the device and
996 all opengl equivalents */
997 TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
998 /* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
999 This->blockType = WINED3DSBT_INIT;
1001 /* Set some of the defaults for lights, transforms etc */
1002 memcpy(&This->transforms[WINED3DTS_PROJECTION], &identity, sizeof(identity));
1003 memcpy(&This->transforms[WINED3DTS_VIEW], &identity, sizeof(identity));
1004 for (i = 0; i < 256; ++i) {
1005 memcpy(&This->transforms[WINED3DTS_WORLDMATRIX(i)], &identity, sizeof(identity));
1008 TRACE("Render states\n");
1009 /* Render states: */
1010 if (ThisDevice->depthStencilBuffer != NULL) {
1011 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_TRUE);
1012 } else {
1013 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_FALSE);
1015 IWineD3DDevice_SetRenderState(device, WINED3DRS_FILLMODE, WINED3DFILL_SOLID);
1016 IWineD3DDevice_SetRenderState(device, WINED3DRS_SHADEMODE, WINED3DSHADE_GOURAUD);
1017 lp.lp.wRepeatFactor = 0;
1018 lp.lp.wLinePattern = 0;
1019 IWineD3DDevice_SetRenderState(device, WINED3DRS_LINEPATTERN, lp.d);
1020 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZWRITEENABLE, TRUE);
1021 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHATESTENABLE, FALSE);
1022 IWineD3DDevice_SetRenderState(device, WINED3DRS_LASTPIXEL, TRUE);
1023 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLEND, WINED3DBLEND_ONE);
1024 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLEND, WINED3DBLEND_ZERO);
1025 IWineD3DDevice_SetRenderState(device, WINED3DRS_CULLMODE, WINED3DCULL_CCW);
1026 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZFUNC, WINED3DCMP_LESSEQUAL);
1027 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAFUNC, WINED3DCMP_ALWAYS);
1028 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAREF, 0);
1029 IWineD3DDevice_SetRenderState(device, WINED3DRS_DITHERENABLE, FALSE);
1030 IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHABLENDENABLE, FALSE);
1031 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGENABLE, FALSE);
1032 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARENABLE, FALSE);
1033 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZVISIBLE, 0);
1034 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGCOLOR, 0);
1035 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGTABLEMODE, WINED3DFOG_NONE);
1036 tmpfloat.f = 0.0f;
1037 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGSTART, tmpfloat.d);
1038 tmpfloat.f = 1.0f;
1039 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGEND, tmpfloat.d);
1040 tmpfloat.f = 1.0f;
1041 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGDENSITY, tmpfloat.d);
1042 IWineD3DDevice_SetRenderState(device, WINED3DRS_EDGEANTIALIAS, FALSE);
1043 IWineD3DDevice_SetRenderState(device, WINED3DRS_ZBIAS, 0);
1044 IWineD3DDevice_SetRenderState(device, WINED3DRS_RANGEFOGENABLE, FALSE);
1045 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILENABLE, FALSE);
1046 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1047 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1048 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILPASS, WINED3DSTENCILOP_KEEP);
1049 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILREF, 0);
1050 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILMASK, 0xFFFFFFFF);
1051 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFUNC, WINED3DCMP_ALWAYS);
1052 IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
1053 IWineD3DDevice_SetRenderState(device, WINED3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
1054 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP0, 0);
1055 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP1, 0);
1056 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP2, 0);
1057 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP3, 0);
1058 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP4, 0);
1059 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP5, 0);
1060 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP6, 0);
1061 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP7, 0);
1062 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPING, TRUE);
1063 IWineD3DDevice_SetRenderState(device, WINED3DRS_LIGHTING, TRUE);
1064 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENT, 0);
1065 IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGVERTEXMODE, WINED3DFOG_NONE);
1066 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORVERTEX, TRUE);
1067 IWineD3DDevice_SetRenderState(device, WINED3DRS_LOCALVIEWER, TRUE);
1068 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALIZENORMALS, FALSE);
1069 IWineD3DDevice_SetRenderState(device, WINED3DRS_DIFFUSEMATERIALSOURCE, WINED3DMCS_COLOR1);
1070 IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARMATERIALSOURCE, WINED3DMCS_COLOR2);
1071 IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENTMATERIALSOURCE, WINED3DMCS_MATERIAL);
1072 IWineD3DDevice_SetRenderState(device, WINED3DRS_EMISSIVEMATERIALSOURCE, WINED3DMCS_MATERIAL);
1073 IWineD3DDevice_SetRenderState(device, WINED3DRS_VERTEXBLEND, WINED3DVBF_DISABLE);
1074 IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPLANEENABLE, 0);
1075 IWineD3DDevice_SetRenderState(device, WINED3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
1076 tmpfloat.f = 1.0f;
1077 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE, tmpfloat.d);
1078 tmpfloat.f = 1.0f;
1079 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN, tmpfloat.d);
1080 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE, FALSE);
1081 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALEENABLE, FALSE);
1082 tmpfloat.f = 1.0f;
1083 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_A, tmpfloat.d);
1084 tmpfloat.f = 0.0f;
1085 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_B, tmpfloat.d);
1086 tmpfloat.f = 0.0f;
1087 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_C, tmpfloat.d);
1088 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEANTIALIAS, TRUE);
1089 IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
1090 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHEDGESTYLE, WINED3DPATCHEDGE_DISCRETE);
1091 tmpfloat.f = 1.0f;
1092 IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHSEGMENTS, tmpfloat.d);
1093 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEBUGMONITORTOKEN, 0xbaadcafe);
1094 tmpfloat.f = 64.0f;
1095 IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MAX, tmpfloat.d);
1096 IWineD3DDevice_SetRenderState(device, WINED3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
1097 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE, 0x0000000F);
1098 tmpfloat.f = 0.0f;
1099 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWEENFACTOR, tmpfloat.d);
1100 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOP, WINED3DBLENDOP_ADD);
1101 IWineD3DDevice_SetRenderState(device, WINED3DRS_POSITIONDEGREE, WINED3DDEGREE_CUBIC);
1102 IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALDEGREE, WINED3DDEGREE_LINEAR);
1103 /* states new in d3d9 */
1104 IWineD3DDevice_SetRenderState(device, WINED3DRS_SCISSORTESTENABLE, FALSE);
1105 IWineD3DDevice_SetRenderState(device, WINED3DRS_SLOPESCALEDEPTHBIAS, 0);
1106 tmpfloat.f = 1.0f;
1107 IWineD3DDevice_SetRenderState(device, WINED3DRS_MINTESSELLATIONLEVEL, tmpfloat.d);
1108 IWineD3DDevice_SetRenderState(device, WINED3DRS_MAXTESSELLATIONLEVEL, tmpfloat.d);
1109 IWineD3DDevice_SetRenderState(device, WINED3DRS_ANTIALIASEDLINEENABLE, FALSE);
1110 tmpfloat.f = 0.0f;
1111 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_X, tmpfloat.d);
1112 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Y, tmpfloat.d);
1113 tmpfloat.f = 1.0f;
1114 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Z, tmpfloat.d);
1115 tmpfloat.f = 0.0f;
1116 IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_W, tmpfloat.d);
1117 IWineD3DDevice_SetRenderState(device, WINED3DRS_ENABLEADAPTIVETESSELLATION, FALSE);
1118 IWineD3DDevice_SetRenderState(device, WINED3DRS_TWOSIDEDSTENCILMODE, FALSE);
1119 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFAIL, WINED3DSTENCILOP_KEEP);
1120 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
1121 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILPASS, WINED3DSTENCILOP_KEEP);
1122 IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFUNC, WINED3DCMP_ALWAYS);
1123 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE1, 0x0000000F);
1124 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE2, 0x0000000F);
1125 IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE3, 0x0000000F);
1126 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDFACTOR, 0xFFFFFFFF);
1127 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRGBWRITEENABLE, 0);
1128 IWineD3DDevice_SetRenderState(device, WINED3DRS_DEPTHBIAS, 0);
1129 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP8, 0);
1130 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP9, 0);
1131 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP10, 0);
1132 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP11, 0);
1133 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP12, 0);
1134 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP13, 0);
1135 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP14, 0);
1136 IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP15, 0);
1137 IWineD3DDevice_SetRenderState(device, WINED3DRS_SEPARATEALPHABLENDENABLE, FALSE);
1138 IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLENDALPHA, WINED3DBLEND_ONE);
1139 IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLENDALPHA, WINED3DBLEND_ZERO);
1140 IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOPALPHA, WINED3DBLENDOP_ADD);
1142 /* clipping status */
1143 This->clip_status.ClipUnion = 0;
1144 This->clip_status.ClipIntersection = 0xFFFFFFFF;
1146 /* Texture Stage States - Put directly into state block, we will call function below */
1147 for (i = 0; i < MAX_TEXTURES; i++) {
1148 TRACE("Setting up default texture states for texture Stage %d\n", i);
1149 memcpy(&This->transforms[WINED3DTS_TEXTURE0 + i], &identity, sizeof(identity));
1150 This->textureState[i][WINED3DTSS_COLOROP ] = (i==0)? WINED3DTOP_MODULATE : WINED3DTOP_DISABLE;
1151 This->textureState[i][WINED3DTSS_COLORARG1 ] = WINED3DTA_TEXTURE;
1152 This->textureState[i][WINED3DTSS_COLORARG2 ] = WINED3DTA_CURRENT;
1153 This->textureState[i][WINED3DTSS_ALPHAOP ] = (i==0)? WINED3DTOP_SELECTARG1 : WINED3DTOP_DISABLE;
1154 This->textureState[i][WINED3DTSS_ALPHAARG1 ] = WINED3DTA_TEXTURE;
1155 This->textureState[i][WINED3DTSS_ALPHAARG2 ] = WINED3DTA_CURRENT;
1156 This->textureState[i][WINED3DTSS_BUMPENVMAT00 ] = (DWORD) 0.0;
1157 This->textureState[i][WINED3DTSS_BUMPENVMAT01 ] = (DWORD) 0.0;
1158 This->textureState[i][WINED3DTSS_BUMPENVMAT10 ] = (DWORD) 0.0;
1159 This->textureState[i][WINED3DTSS_BUMPENVMAT11 ] = (DWORD) 0.0;
1160 This->textureState[i][WINED3DTSS_TEXCOORDINDEX ] = i;
1161 This->textureState[i][WINED3DTSS_BUMPENVLSCALE ] = (DWORD) 0.0;
1162 This->textureState[i][WINED3DTSS_BUMPENVLOFFSET ] = (DWORD) 0.0;
1163 This->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS ] = WINED3DTTFF_DISABLE;
1164 This->textureState[i][WINED3DTSS_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1165 This->textureState[i][WINED3DTSS_COLORARG0 ] = WINED3DTA_CURRENT;
1166 This->textureState[i][WINED3DTSS_ALPHAARG0 ] = WINED3DTA_CURRENT;
1167 This->textureState[i][WINED3DTSS_RESULTARG ] = WINED3DTA_CURRENT;
1169 This->lowest_disabled_stage = 1;
1171 /* Sampler states*/
1172 for (i = 0 ; i < MAX_COMBINED_SAMPLERS; i++) {
1173 TRACE("Setting up default samplers states for sampler %d\n", i);
1174 This->samplerState[i][WINED3DSAMP_ADDRESSU ] = WINED3DTADDRESS_WRAP;
1175 This->samplerState[i][WINED3DSAMP_ADDRESSV ] = WINED3DTADDRESS_WRAP;
1176 This->samplerState[i][WINED3DSAMP_ADDRESSW ] = WINED3DTADDRESS_WRAP;
1177 This->samplerState[i][WINED3DSAMP_BORDERCOLOR ] = 0x00;
1178 This->samplerState[i][WINED3DSAMP_MAGFILTER ] = WINED3DTEXF_POINT;
1179 This->samplerState[i][WINED3DSAMP_MINFILTER ] = WINED3DTEXF_POINT;
1180 This->samplerState[i][WINED3DSAMP_MIPFILTER ] = WINED3DTEXF_NONE;
1181 This->samplerState[i][WINED3DSAMP_MIPMAPLODBIAS ] = 0;
1182 This->samplerState[i][WINED3DSAMP_MAXMIPLEVEL ] = 0;
1183 This->samplerState[i][WINED3DSAMP_MAXANISOTROPY ] = 1;
1184 This->samplerState[i][WINED3DSAMP_SRGBTEXTURE ] = 0;
1185 This->samplerState[i][WINED3DSAMP_ELEMENTINDEX ] = 0; /* TODO: Indicates which element of a multielement texture to use */
1186 This->samplerState[i][WINED3DSAMP_DMAPOFFSET ] = 0; /* TODO: Vertex offset in the presampled displacement map */
1189 /* Under DirectX you can have texture stage operations even if no texture is
1190 bound, whereas opengl will only do texture operations when a valid texture is
1191 bound. We emulate this by creating dummy textures and binding them to each
1192 texture stage, but disable all stages by default. Hence if a stage is enabled
1193 then the default texture will kick in until replaced by a SetTexture call */
1194 ENTER_GL();
1196 if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
1197 /* The dummy texture does not have client storage backing */
1198 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
1199 checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
1201 for (i = 0; i < GL_LIMITS(textures); i++) {
1202 GLubyte white = 255;
1204 /* Note this avoids calling settexture, so pretend it has been called */
1205 This->changed.textures[i] = TRUE;
1206 This->textures[i] = NULL;
1208 /* Make appropriate texture active */
1209 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1210 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
1211 checkGLcall("glActiveTextureARB");
1212 } else if (i > 0) {
1213 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1216 /* Generate an opengl texture name */
1217 glGenTextures(1, &ThisDevice->dummyTextureName[i]);
1218 checkGLcall("glGenTextures");
1219 TRACE("Dummy Texture %d given name %d\n", i, ThisDevice->dummyTextureName[i]);
1221 /* Generate a dummy 2d texture (not using 1d because they cause many
1222 * DRI drivers fall back to sw) */
1223 This->textureDimensions[i] = GL_TEXTURE_2D;
1224 glBindTexture(GL_TEXTURE_2D, ThisDevice->dummyTextureName[i]);
1225 checkGLcall("glBindTexture");
1227 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &white);
1228 checkGLcall("glTexImage2D");
1230 if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
1231 /* Reenable because if supported it is enabled by default */
1232 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
1233 checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
1236 LEAVE_GL();
1239 /* Defaulting palettes - Note these are device wide but reinitialized here for convenience*/
1240 for (i = 0; i < MAX_PALETTES; ++i) {
1241 int j;
1242 for (j = 0; j < 256; ++j) {
1243 This->wineD3DDevice->palettes[i][j].peRed = 0xFF;
1244 This->wineD3DDevice->palettes[i][j].peGreen = 0xFF;
1245 This->wineD3DDevice->palettes[i][j].peBlue = 0xFF;
1246 This->wineD3DDevice->palettes[i][j].peFlags = 0xFF;
1249 This->wineD3DDevice->currentPalette = 0;
1251 /* Set default GLSL program to NULL. We won't actually create one
1252 * until the app sets a vertex or pixel shader */
1253 This->glsl_program = NULL;
1255 TRACE("-----------------------> Device defaults now set up...\n");
1256 return WINED3D_OK;
1259 /**********************************************************
1260 * IWineD3DStateBlock VTbl follows
1261 **********************************************************/
1263 const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
1265 /* IUnknown */
1266 IWineD3DStateBlockImpl_QueryInterface,
1267 IWineD3DStateBlockImpl_AddRef,
1268 IWineD3DStateBlockImpl_Release,
1269 /* IWineD3DStateBlock */
1270 IWineD3DStateBlockImpl_GetParent,
1271 IWineD3DStateBlockImpl_GetDevice,
1272 IWineD3DStateBlockImpl_Capture,
1273 IWineD3DStateBlockImpl_Apply,
1274 IWineD3DStateBlockImpl_InitStartupStateBlock