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
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
64 /** Copy all members of one stateblock to another */
65 void stateblock_savedstates_copy(
66 IWineD3DStateBlock
* iface
,
68 SAVEDSTATES
* source
) {
70 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
71 unsigned bsize
= sizeof(BOOL
);
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
,
108 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
109 unsigned bsize
= sizeof(BOOL
);
112 states
->indices
= value
;
113 states
->material
= 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
) {
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
;
158 stateblock_savedstates_copy(source
, &Dest
->changed
, &This
->changed
);
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
));
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
);
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);
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);
251 constants_entry
*constant
, *constant2
;
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
]);
265 for (counter
= 0; counter
< MAX_STREAMS
; counter
++) {
266 if(This
->streamSource
[counter
]) {
267 if(0 != IWineD3DVertexBuffer_Release(This
->streamSource
[counter
])) {
268 TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter
, This
->streamSource
[counter
]);
272 if(This
->pIndexData
) IWineD3DIndexBuffer_Release(This
->pIndexData
);
276 for(counter
= 0; counter
< LIGHTMAP_SIZE
; counter
++) {
277 struct list
*e1
, *e2
;
278 LIST_FOR_EACH_SAFE(e1
, e2
, &This
->lightMap
[counter
]) {
279 PLIGHTINFOEL
*light
= LIST_ENTRY(e1
, PLIGHTINFOEL
, entry
);
280 list_remove(&light
->entry
);
281 HeapFree(GetProcessHeap(), 0, light
);
285 HeapFree(GetProcessHeap(), 0, This
->vertexShaderConstantF
);
286 HeapFree(GetProcessHeap(), 0, This
->changed
.vertexShaderConstantsF
);
287 HeapFree(GetProcessHeap(), 0, This
->pixelShaderConstantF
);
288 HeapFree(GetProcessHeap(), 0, This
->changed
.pixelShaderConstantsF
);
289 HeapFree(GetProcessHeap(), 0, This
->contained_vs_consts_f
);
290 HeapFree(GetProcessHeap(), 0, This
->contained_ps_consts_f
);
292 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant2
, &This
->set_vconstantsF
, constants_entry
, entry
) {
293 HeapFree(GetProcessHeap(), 0, constant
);
296 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant2
, &This
->set_pconstantsF
, constants_entry
, entry
) {
297 HeapFree(GetProcessHeap(), 0, constant
);
300 HeapFree(GetProcessHeap(), 0, This
);
305 /**********************************************************
306 * IWineD3DStateBlockImpl parts follows
307 **********************************************************/
308 static HRESULT WINAPI
IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock
*iface
, IUnknown
**pParent
) {
309 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
310 IUnknown_AddRef(This
->parent
);
311 *pParent
= This
->parent
;
315 static HRESULT WINAPI
IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock
*iface
, IWineD3DDevice
** ppDevice
){
317 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
319 *ppDevice
= (IWineD3DDevice
*)This
->wineD3DDevice
;
320 IWineD3DDevice_AddRef(*ppDevice
);
325 static inline void record_lights(IWineD3DStateBlockImpl
*This
, IWineD3DStateBlockImpl
*targetStateBlock
) {
328 /* Lights... For a recorded state block, we just had a chain of actions to perform,
329 * so we need to walk that chain and update any actions which differ
331 for(i
= 0; i
< LIGHTMAP_SIZE
; i
++) {
333 LIST_FOR_EACH(e
, &This
->lightMap
[i
]) {
334 BOOL updated
= FALSE
;
335 PLIGHTINFOEL
*src
= LIST_ENTRY(e
, PLIGHTINFOEL
, entry
), *realLight
;
336 if(!src
->changed
|| !src
->enabledChanged
) continue;
338 /* Look up the light in the destination */
339 LIST_FOR_EACH(f
, &targetStateBlock
->lightMap
[i
]) {
340 realLight
= LIST_ENTRY(f
, PLIGHTINFOEL
, entry
);
341 if(realLight
->OriginalIndex
== src
->OriginalIndex
) {
343 memcpy(&src
->OriginalParms
, &realLight
->OriginalParms
, sizeof(src
->OriginalParms
));
345 if(src
->enabledChanged
) {
346 /* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
347 * or disabled -> enabled -> disabled changes
349 if(realLight
->glIndex
== -1 && src
->glIndex
!= -1) {
351 This
->activeLights
[src
->glIndex
] = NULL
;
352 } else if(realLight
->glIndex
!= -1 && src
->glIndex
== -1){
354 This
->activeLights
[realLight
->glIndex
] = src
;
356 src
->glIndex
= realLight
->glIndex
;
364 /* Found a light, all done, proceed with next hash entry */
366 } else if(src
->changed
) {
367 /* Otherwise assign defaul params */
368 memcpy(&src
->OriginalParms
, &WINED3D_default_light
, sizeof(src
->OriginalParms
));
370 /* Not enabled by default */
377 static HRESULT WINAPI
IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock
*iface
){
379 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
380 IWineD3DStateBlockImpl
*targetStateBlock
= This
->wineD3DDevice
->stateBlock
;
383 TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock
, This
);
385 /* If not recorded, then update can just recapture */
386 if (This
->blockType
== WINED3DSBT_RECORDED
) {
388 /* Recorded => Only update 'changed' values */
389 if (This
->vertexShader
!= targetStateBlock
->vertexShader
) {
390 TRACE("Updating vertex shader from %p to %p\n", This
->vertexShader
, targetStateBlock
->vertexShader
);
392 This
->vertexShader
= targetStateBlock
->vertexShader
;
395 /* Vertex Shader Float Constants */
396 for (j
= 0; j
< This
->num_contained_vs_consts_f
; ++j
) {
397 i
= This
->contained_vs_consts_f
[j
];
398 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This
, targetStateBlock
, i
,
399 targetStateBlock
->vertexShaderConstantF
[i
* 4],
400 targetStateBlock
->vertexShaderConstantF
[i
* 4 + 1],
401 targetStateBlock
->vertexShaderConstantF
[i
* 4 + 2],
402 targetStateBlock
->vertexShaderConstantF
[i
* 4 + 3]);
404 This
->vertexShaderConstantF
[i
* 4] = targetStateBlock
->vertexShaderConstantF
[i
* 4];
405 This
->vertexShaderConstantF
[i
* 4 + 1] = targetStateBlock
->vertexShaderConstantF
[i
* 4 + 1];
406 This
->vertexShaderConstantF
[i
* 4 + 2] = targetStateBlock
->vertexShaderConstantF
[i
* 4 + 2];
407 This
->vertexShaderConstantF
[i
* 4 + 3] = targetStateBlock
->vertexShaderConstantF
[i
* 4 + 3];
410 /* Vertex Shader Integer Constants */
411 for (j
= 0; j
< This
->num_contained_vs_consts_i
; ++j
) {
412 i
= This
->contained_vs_consts_i
[j
];
413 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This
, targetStateBlock
, i
,
414 targetStateBlock
->vertexShaderConstantI
[i
* 4],
415 targetStateBlock
->vertexShaderConstantI
[i
* 4 + 1],
416 targetStateBlock
->vertexShaderConstantI
[i
* 4 + 2],
417 targetStateBlock
->vertexShaderConstantI
[i
* 4 + 3]);
419 This
->vertexShaderConstantI
[i
* 4] = targetStateBlock
->vertexShaderConstantI
[i
* 4];
420 This
->vertexShaderConstantI
[i
* 4 + 1] = targetStateBlock
->vertexShaderConstantI
[i
* 4 + 1];
421 This
->vertexShaderConstantI
[i
* 4 + 2] = targetStateBlock
->vertexShaderConstantI
[i
* 4 + 2];
422 This
->vertexShaderConstantI
[i
* 4 + 3] = targetStateBlock
->vertexShaderConstantI
[i
* 4 + 3];
425 /* Vertex Shader Boolean Constants */
426 for (j
= 0; j
< This
->num_contained_vs_consts_b
; ++j
) {
427 i
= This
->contained_vs_consts_b
[j
];
428 TRACE("Setting %p from %p %d to %s\n", This
, targetStateBlock
, i
,
429 targetStateBlock
->vertexShaderConstantB
[i
]? "TRUE":"FALSE");
431 This
->vertexShaderConstantB
[i
] = targetStateBlock
->vertexShaderConstantB
[i
];
434 /* Recorded => Only update 'changed' values */
435 if (This
->pixelShader
!= targetStateBlock
->pixelShader
) {
436 TRACE("Updating pixel shader from %p to %p\n", This
->pixelShader
, targetStateBlock
->pixelShader
);
438 This
->pixelShader
= targetStateBlock
->pixelShader
;
441 /* Pixel Shader Float Constants */
442 for (j
= 0; j
< This
->num_contained_ps_consts_f
; ++j
) {
443 i
= This
->contained_ps_consts_f
[j
];
444 TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This
, targetStateBlock
, i
,
445 targetStateBlock
->pixelShaderConstantF
[i
* 4],
446 targetStateBlock
->pixelShaderConstantF
[i
* 4 + 1],
447 targetStateBlock
->pixelShaderConstantF
[i
* 4 + 2],
448 targetStateBlock
->pixelShaderConstantF
[i
* 4 + 3]);
450 This
->pixelShaderConstantF
[i
* 4] = targetStateBlock
->pixelShaderConstantF
[i
* 4];
451 This
->pixelShaderConstantF
[i
* 4 + 1] = targetStateBlock
->pixelShaderConstantF
[i
* 4 + 1];
452 This
->pixelShaderConstantF
[i
* 4 + 2] = targetStateBlock
->pixelShaderConstantF
[i
* 4 + 2];
453 This
->pixelShaderConstantF
[i
* 4 + 3] = targetStateBlock
->pixelShaderConstantF
[i
* 4 + 3];
456 /* Pixel Shader Integer Constants */
457 for (j
= 0; j
< This
->num_contained_ps_consts_i
; ++j
) {
458 i
= This
->contained_ps_consts_i
[j
];
459 TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This
, targetStateBlock
, i
,
460 targetStateBlock
->pixelShaderConstantI
[i
* 4],
461 targetStateBlock
->pixelShaderConstantI
[i
* 4 + 1],
462 targetStateBlock
->pixelShaderConstantI
[i
* 4 + 2],
463 targetStateBlock
->pixelShaderConstantI
[i
* 4 + 3]);
465 This
->pixelShaderConstantI
[i
* 4] = targetStateBlock
->pixelShaderConstantI
[i
* 4];
466 This
->pixelShaderConstantI
[i
* 4 + 1] = targetStateBlock
->pixelShaderConstantI
[i
* 4 + 1];
467 This
->pixelShaderConstantI
[i
* 4 + 2] = targetStateBlock
->pixelShaderConstantI
[i
* 4 + 2];
468 This
->pixelShaderConstantI
[i
* 4 + 3] = targetStateBlock
->pixelShaderConstantI
[i
* 4 + 3];
471 /* Pixel Shader Boolean Constants */
472 for (j
= 0; j
< This
->num_contained_ps_consts_b
; ++j
) {
473 i
= This
->contained_ps_consts_b
[j
];
474 TRACE("Setting %p from %p %d to %s\n", This
, targetStateBlock
, i
,
475 targetStateBlock
->pixelShaderConstantB
[i
]? "TRUE":"FALSE");
477 This
->pixelShaderConstantB
[i
] = targetStateBlock
->pixelShaderConstantB
[i
];
480 /* Others + Render & Texture */
481 for (i
= 0; i
< This
->num_contained_transform_states
; i
++) {
482 TRACE("Updating transform %d\n", i
);
483 memcpy(&This
->transforms
[This
->contained_transform_states
[i
]],
484 &targetStateBlock
->transforms
[This
->contained_transform_states
[i
]],
485 sizeof(WINED3DMATRIX
));
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 This
->pIndexData
= targetStateBlock
->pIndexData
;
493 This
->baseVertexIndex
= targetStateBlock
->baseVertexIndex
;
496 if(This
->changed
.vertexDecl
&& This
->vertexDecl
!= targetStateBlock
->vertexDecl
){
497 TRACE("Updating vertex declaration from %p to %p\n", This
->vertexDecl
, targetStateBlock
->vertexDecl
);
499 This
->vertexDecl
= targetStateBlock
->vertexDecl
;
502 if(This
->changed
.fvf
&& This
->fvf
!= targetStateBlock
->fvf
){
503 This
->fvf
= targetStateBlock
->fvf
;
506 if (This
->changed
.material
&& memcmp(&targetStateBlock
->material
,
508 sizeof(WINED3DMATERIAL
)) != 0) {
509 TRACE("Updating material\n");
510 memcpy(&This
->material
, &targetStateBlock
->material
, sizeof(WINED3DMATERIAL
));
513 if (This
->changed
.viewport
&& memcmp(&targetStateBlock
->viewport
,
515 sizeof(WINED3DVIEWPORT
)) != 0) {
516 TRACE("Updating viewport\n");
517 memcpy(&This
->viewport
, &targetStateBlock
->viewport
, sizeof(WINED3DVIEWPORT
));
520 if(This
->changed
.scissorRect
&& memcmp(&targetStateBlock
->scissorRect
,
522 sizeof(targetStateBlock
->scissorRect
)))
524 TRACE("Updating scissor rect\n");
525 memcpy(&targetStateBlock
->scissorRect
, &This
->scissorRect
, sizeof(targetStateBlock
->scissorRect
));
528 for (i
= 0; i
< MAX_STREAMS
; i
++) {
529 if (This
->changed
.streamSource
[i
] &&
530 ((This
->streamStride
[i
] != targetStateBlock
->streamStride
[i
]) ||
531 (This
->streamSource
[i
] != targetStateBlock
->streamSource
[i
]))) {
532 TRACE("Updating stream source %d to %p, stride to %d\n", i
, targetStateBlock
->streamSource
[i
],
533 targetStateBlock
->streamStride
[i
]);
534 This
->streamStride
[i
] = targetStateBlock
->streamStride
[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
] && memcmp(&targetStateBlock
->clipplane
[i
],
551 sizeof(This
->clipplane
)) != 0) {
553 TRACE("Updating clipplane %d\n", i
);
554 memcpy(&This
->clipplane
[i
], &targetStateBlock
->clipplane
[i
],
555 sizeof(This
->clipplane
));
560 for (i
= 0; i
< This
->num_contained_render_states
; i
++) {
561 TRACE("Updating renderState %d to %d\n",
562 This
->contained_render_states
[i
], targetStateBlock
->renderState
[This
->contained_render_states
[i
]]);
563 This
->renderState
[This
->contained_render_states
[i
]] = targetStateBlock
->renderState
[This
->contained_render_states
[i
]];
567 for (j
= 0; j
< This
->num_contained_tss_states
; j
++) {
568 DWORD stage
= This
->contained_tss_states
[j
].stage
;
569 DWORD state
= This
->contained_tss_states
[j
].state
;
571 TRACE("Updating texturestagestate %d,%d to %d (was %d)\n", stage
,state
,
572 targetStateBlock
->textureState
[stage
][state
], This
->textureState
[stage
][state
]);
573 This
->textureState
[stage
][state
] = targetStateBlock
->textureState
[stage
][state
];
577 /* TODO: move over to using memcpy */
578 for (j
= 0; j
< MAX_COMBINED_SAMPLERS
; j
++) {
579 if (This
->changed
.textures
[j
]) {
580 TRACE("Updating texture %d to %p (was %p)\n", j
, targetStateBlock
->textures
[j
], This
->textures
[j
]);
581 This
->textures
[j
] = targetStateBlock
->textures
[j
];
585 for (j
= 0; j
< This
->num_contained_sampler_states
; j
++) {
586 DWORD stage
= This
->contained_sampler_states
[j
].stage
;
587 DWORD state
= This
->contained_sampler_states
[j
].state
;
588 TRACE("Updating sampler state %d,%d to %d (was %d)\n",
589 stage
, state
, targetStateBlock
->samplerState
[stage
][state
],
590 This
->samplerState
[stage
][state
]);
591 This
->samplerState
[stage
][state
] = targetStateBlock
->samplerState
[stage
][state
];
594 record_lights(This
, targetStateBlock
);
595 } else if(This
->blockType
== WINED3DSBT_ALL
) {
596 This
->vertexDecl
= targetStateBlock
->vertexDecl
;
597 This
->vertexShader
= targetStateBlock
->vertexShader
;
598 memcpy(This
->vertexShaderConstantB
, targetStateBlock
->vertexShaderConstantB
, sizeof(This
->vertexShaderConstantI
));
599 memcpy(This
->vertexShaderConstantI
, targetStateBlock
->vertexShaderConstantI
, sizeof(This
->vertexShaderConstantF
));
600 memcpy(This
->vertexShaderConstantF
, targetStateBlock
->vertexShaderConstantF
, sizeof(float) * GL_LIMITS(vshader_constantsF
) * 4);
601 memcpy(This
->streamStride
, targetStateBlock
->streamStride
, sizeof(This
->streamStride
));
602 memcpy(This
->streamOffset
, targetStateBlock
->streamOffset
, sizeof(This
->streamOffset
));
603 memcpy(This
->streamSource
, targetStateBlock
->streamSource
, sizeof(This
->streamSource
));
604 memcpy(This
->streamFreq
, targetStateBlock
->streamFreq
, sizeof(This
->streamFreq
));
605 memcpy(This
->streamFlags
, targetStateBlock
->streamFlags
, sizeof(This
->streamFlags
));
606 This
->pIndexData
= targetStateBlock
->pIndexData
;
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 This
->pixelShader
= targetStateBlock
->pixelShader
;
615 memcpy(This
->pixelShaderConstantB
, targetStateBlock
->pixelShaderConstantB
, sizeof(This
->pixelShaderConstantI
));
616 memcpy(This
->pixelShaderConstantI
, targetStateBlock
->pixelShaderConstantI
, sizeof(This
->pixelShaderConstantF
));
617 memcpy(This
->pixelShaderConstantF
, targetStateBlock
->pixelShaderConstantF
, sizeof(float) * GL_LIMITS(pshader_constantsF
) * 4);
618 memcpy(This
->renderState
, targetStateBlock
->renderState
, sizeof(This
->renderState
));
619 memcpy(This
->textures
, targetStateBlock
->textures
, sizeof(This
->textures
));
620 memcpy(This
->textureDimensions
, targetStateBlock
->textureDimensions
, sizeof(This
->textureDimensions
));
621 memcpy(This
->textureState
, targetStateBlock
->textureState
, sizeof(This
->textureState
));
622 memcpy(This
->samplerState
, targetStateBlock
->samplerState
, sizeof(This
->samplerState
));
623 This
->scissorRect
= targetStateBlock
->scissorRect
;
624 } else if(This
->blockType
== WINED3DSBT_VERTEXSTATE
) {
625 This
->vertexShader
= targetStateBlock
->vertexShader
;
626 memcpy(This
->vertexShaderConstantB
, targetStateBlock
->vertexShaderConstantB
, sizeof(This
->vertexShaderConstantI
));
627 memcpy(This
->vertexShaderConstantI
, targetStateBlock
->vertexShaderConstantI
, sizeof(This
->vertexShaderConstantF
));
628 memcpy(This
->vertexShaderConstantF
, targetStateBlock
->vertexShaderConstantF
, sizeof(float) * GL_LIMITS(vshader_constantsF
) * 4);
629 record_lights(This
, targetStateBlock
);
630 for (i
= 0; i
< NUM_SAVEDVERTEXSTATES_R
; i
++) {
631 This
->renderState
[SavedVertexStates_R
[i
]] = targetStateBlock
->renderState
[SavedVertexStates_R
[i
]];
633 for (j
= 0; j
< MAX_COMBINED_SAMPLERS
; j
++) {
634 for (i
= 0; i
< NUM_SAVEDVERTEXSTATES_S
; i
++) {
635 This
->samplerState
[j
][SavedVertexStates_S
[i
]] = targetStateBlock
->samplerState
[j
][SavedVertexStates_S
[i
]];
638 for (j
= 0; j
< MAX_TEXTURES
; j
++) {
639 for (i
= 0; i
< NUM_SAVEDVERTEXSTATES_R
; i
++) {
640 This
->textureState
[j
][SavedVertexStates_R
[i
]] = targetStateBlock
->textureState
[j
][SavedVertexStates_R
[i
]];
643 } else if(This
->blockType
== WINED3DSBT_PIXELSTATE
) {
644 This
->pixelShader
= targetStateBlock
->pixelShader
;
645 memcpy(This
->pixelShaderConstantB
, targetStateBlock
->pixelShaderConstantB
, sizeof(This
->pixelShaderConstantI
));
646 memcpy(This
->pixelShaderConstantI
, targetStateBlock
->pixelShaderConstantI
, sizeof(This
->pixelShaderConstantF
));
647 memcpy(This
->pixelShaderConstantF
, targetStateBlock
->pixelShaderConstantF
, sizeof(float) * GL_LIMITS(pshader_constantsF
) * 4);
648 for (i
= 0; i
< NUM_SAVEDPIXELSTATES_R
; i
++) {
649 This
->renderState
[SavedPixelStates_R
[i
]] = targetStateBlock
->renderState
[SavedPixelStates_R
[i
]];
651 for (j
= 0; j
< MAX_COMBINED_SAMPLERS
; j
++) {
652 for (i
= 0; i
< NUM_SAVEDPIXELSTATES_S
; i
++) {
653 This
->samplerState
[j
][SavedPixelStates_S
[i
]] = targetStateBlock
->samplerState
[j
][SavedPixelStates_S
[i
]];
656 for (j
= 0; j
< MAX_TEXTURES
; j
++) {
657 for (i
= 0; i
< NUM_SAVEDPIXELSTATES_R
; i
++) {
658 This
->textureState
[j
][SavedPixelStates_R
[i
]] = targetStateBlock
->textureState
[j
][SavedPixelStates_R
[i
]];
663 TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock
, This
);
668 static inline void apply_lights(IWineD3DDevice
*pDevice
, IWineD3DStateBlockImpl
*This
) {
670 for(i
= 0; i
< LIGHTMAP_SIZE
; i
++) {
673 LIST_FOR_EACH(e
, &This
->lightMap
[i
]) {
674 PLIGHTINFOEL
*light
= LIST_ENTRY(e
, PLIGHTINFOEL
, entry
);
677 IWineD3DDevice_SetLight(pDevice
, light
->OriginalIndex
, &light
->OriginalParms
);
679 if(light
->enabledChanged
) {
680 IWineD3DDevice_SetLightEnable(pDevice
, light
->OriginalIndex
, light
->glIndex
!= -1);
686 static HRESULT WINAPI
IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock
*iface
){
687 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
688 IWineD3DDevice
* pDevice
= (IWineD3DDevice
*)This
->wineD3DDevice
;
690 /*Copy thing over to updateBlock is isRecording otherwise StateBlock,
691 should really perform a delta so that only the changes get updated*/
696 TRACE("(%p) : Applying state block %p ------------------v\n", This
, pDevice
);
698 TRACE("Blocktype: %d\n", This
->blockType
);
700 if(This
->blockType
== WINED3DSBT_RECORDED
) {
701 if (This
->changed
.vertexShader
) {
702 IWineD3DDevice_SetVertexShader(pDevice
, This
->vertexShader
);
704 /* Vertex Shader Constants */
705 for (i
= 0; i
< This
->num_contained_vs_consts_f
; i
++) {
706 IWineD3DDevice_SetVertexShaderConstantF(pDevice
, This
->contained_vs_consts_f
[i
],
707 This
->vertexShaderConstantF
+ This
->contained_vs_consts_f
[i
] * 4, 1);
709 for (i
= 0; i
< This
->num_contained_vs_consts_i
; i
++) {
710 IWineD3DDevice_SetVertexShaderConstantI(pDevice
, This
->contained_vs_consts_i
[i
],
711 This
->vertexShaderConstantI
+ This
->contained_vs_consts_i
[i
] * 4, 1);
713 for (i
= 0; i
< This
->num_contained_vs_consts_b
; i
++) {
714 IWineD3DDevice_SetVertexShaderConstantB(pDevice
, This
->contained_vs_consts_b
[i
],
715 This
->vertexShaderConstantB
+ This
->contained_vs_consts_b
[i
], 1);
718 apply_lights(pDevice
, This
);
720 if (This
->changed
.pixelShader
) {
721 IWineD3DDevice_SetPixelShader(pDevice
, This
->pixelShader
);
723 /* Pixel Shader Constants */
724 for (i
= 0; i
< This
->num_contained_ps_consts_f
; i
++) {
725 IWineD3DDevice_SetPixelShaderConstantF(pDevice
, This
->contained_ps_consts_f
[i
],
726 This
->pixelShaderConstantF
+ This
->contained_ps_consts_f
[i
] * 4, 1);
728 for (i
= 0; i
< This
->num_contained_ps_consts_i
; i
++) {
729 IWineD3DDevice_SetPixelShaderConstantI(pDevice
, This
->contained_ps_consts_i
[i
],
730 This
->pixelShaderConstantI
+ This
->contained_ps_consts_i
[i
] * 4, 1);
732 for (i
= 0; i
< This
->num_contained_ps_consts_b
; i
++) {
733 IWineD3DDevice_SetPixelShaderConstantB(pDevice
, This
->contained_ps_consts_b
[i
],
734 This
->pixelShaderConstantB
+ This
->contained_ps_consts_b
[i
], 1);
738 for (i
= 0; i
<= This
->num_contained_render_states
; i
++) {
739 IWineD3DDevice_SetRenderState(pDevice
, This
->contained_render_states
[i
],
740 This
->renderState
[This
->contained_render_states
[i
]]);
743 for (i
= 0; i
< This
->num_contained_tss_states
; i
++) {
744 DWORD stage
= This
->contained_tss_states
[i
].stage
;
745 DWORD state
= This
->contained_tss_states
[i
].state
;
746 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->textureState
[stage
][state
] = This
->textureState
[stage
][state
];
747 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->changed
.textureState
[stage
][state
] = TRUE
;
748 /* TODO: Record a display list to apply all gl states. For now apply by brute force */
749 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl
*)pDevice
, STATE_TEXTURESTAGE(stage
, state
));
752 for (i
= 0; i
< This
->num_contained_sampler_states
; i
++) {
753 DWORD stage
= This
->contained_sampler_states
[i
].stage
;
754 DWORD state
= This
->contained_sampler_states
[i
].state
;
755 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->samplerState
[stage
][state
] = This
->samplerState
[stage
][state
];
756 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->changed
.samplerState
[stage
][state
] = TRUE
;
757 IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl
*)pDevice
, STATE_SAMPLER(stage
));
760 for (i
= 0; i
< This
->num_contained_transform_states
; i
++) {
761 IWineD3DDevice_SetTransform(pDevice
, This
->contained_transform_states
[i
],
762 &This
->transforms
[This
->contained_transform_states
[i
]]);
765 if (This
->changed
.indices
) {
766 IWineD3DDevice_SetIndices(pDevice
, This
->pIndexData
);
767 IWineD3DDevice_SetBaseVertexIndex(pDevice
, This
->baseVertexIndex
);
770 if (This
->changed
.fvf
) {
771 IWineD3DDevice_SetFVF(pDevice
, This
->fvf
);
774 if (This
->changed
.vertexDecl
) {
775 IWineD3DDevice_SetVertexDeclaration(pDevice
, This
->vertexDecl
);
778 if (This
->changed
.material
) {
779 IWineD3DDevice_SetMaterial(pDevice
, &This
->material
);
782 if (This
->changed
.viewport
) {
783 IWineD3DDevice_SetViewport(pDevice
, &This
->viewport
);
786 if (This
->changed
.scissorRect
) {
787 IWineD3DDevice_SetScissorRect(pDevice
, &This
->scissorRect
);
790 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
791 for (i
=0; i
<MAX_STREAMS
; i
++) {
792 if (This
->changed
.streamSource
[i
])
793 IWineD3DDevice_SetStreamSource(pDevice
, i
, This
->streamSource
[i
], 0, This
->streamStride
[i
]);
795 if (This
->changed
.streamFreq
[i
])
796 IWineD3DDevice_SetStreamSourceFreq(pDevice
, i
, This
->streamFreq
[i
] | This
->streamFlags
[i
]);
798 for (j
= 0 ; j
< MAX_COMBINED_SAMPLERS
; j
++){
799 if (This
->changed
.textures
[j
]) {
800 if (j
< MAX_FRAGMENT_SAMPLERS
) {
801 IWineD3DDevice_SetTexture(pDevice
, j
, This
->textures
[j
]);
803 IWineD3DDevice_SetTexture(pDevice
, WINED3DVERTEXTEXTURESAMPLER0
+ j
- MAX_FRAGMENT_SAMPLERS
, This
->textures
[j
]);
808 for (i
= 0; i
< GL_LIMITS(clipplanes
); i
++) {
809 if (This
->changed
.clipplane
[i
]) {
812 clip
[0] = This
->clipplane
[i
][0];
813 clip
[1] = This
->clipplane
[i
][1];
814 clip
[2] = This
->clipplane
[i
][2];
815 clip
[3] = This
->clipplane
[i
][3];
816 IWineD3DDevice_SetClipPlane(pDevice
, i
, clip
);
820 } else if(This
->blockType
== WINED3DSBT_VERTEXSTATE
) {
821 IWineD3DDevice_SetVertexShader(pDevice
, This
->vertexShader
);
822 for (i
= 0; i
< GL_LIMITS(vshader_constantsF
); i
++) {
823 IWineD3DDevice_SetVertexShaderConstantF(pDevice
, i
,
824 This
->vertexShaderConstantF
+ i
* 4, 1);
826 for (i
= 0; i
< MAX_CONST_I
; i
++) {
827 IWineD3DDevice_SetVertexShaderConstantI(pDevice
, i
,
828 This
->vertexShaderConstantI
+ i
* 4, 1);
830 for (i
= 0; i
< MAX_CONST_B
; i
++) {
831 IWineD3DDevice_SetVertexShaderConstantB(pDevice
, i
,
832 This
->vertexShaderConstantB
+ i
, 1);
835 apply_lights(pDevice
, This
);
837 for(i
= 0; i
< NUM_SAVEDVERTEXSTATES_R
; i
++) {
838 IWineD3DDevice_SetRenderState(pDevice
, SavedVertexStates_R
[i
], This
->renderState
[SavedVertexStates_R
[i
]]);
840 for(j
= 0; j
< MAX_TEXTURES
; j
++) {
841 for(i
= 0; i
< NUM_SAVEDVERTEXSTATES_T
; i
++) {
842 IWineD3DDevice_SetTextureStageState(pDevice
, j
, SavedVertexStates_T
[i
],
843 This
->textureState
[j
][SavedVertexStates_T
[i
]]);
847 for(j
= 0; j
< MAX_FRAGMENT_SAMPLERS
; j
++) {
848 for(i
= 0; i
< NUM_SAVEDVERTEXSTATES_S
; i
++) {
849 IWineD3DDevice_SetSamplerState(pDevice
, j
, SavedVertexStates_S
[i
],
850 This
->samplerState
[j
][SavedVertexStates_S
[i
]]);
853 for(j
= MAX_FRAGMENT_SAMPLERS
; j
< MAX_COMBINED_SAMPLERS
; j
++) {
854 for(i
= 0; i
< NUM_SAVEDVERTEXSTATES_S
; i
++) {
855 IWineD3DDevice_SetSamplerState(pDevice
,
856 WINED3DVERTEXTEXTURESAMPLER0
+ j
- MAX_FRAGMENT_SAMPLERS
,
857 SavedVertexStates_S
[i
],
858 This
->samplerState
[j
][SavedVertexStates_S
[i
]]);
861 } else if(This
->blockType
== WINED3DSBT_PIXELSTATE
) {
862 IWineD3DDevice_SetPixelShader(pDevice
, This
->pixelShader
);
863 for (i
= 0; i
< GL_LIMITS(pshader_constantsF
); i
++) {
864 IWineD3DDevice_SetPixelShaderConstantF(pDevice
, i
,
865 This
->pixelShaderConstantF
+ i
* 4, 1);
867 for (i
= 0; i
< MAX_CONST_I
; i
++) {
868 IWineD3DDevice_SetPixelShaderConstantI(pDevice
, i
,
869 This
->pixelShaderConstantI
+ i
* 4, 1);
871 for (i
= 0; i
< MAX_CONST_B
; i
++) {
872 IWineD3DDevice_SetPixelShaderConstantB(pDevice
, i
,
873 This
->pixelShaderConstantB
+ i
, 1);
876 for(i
= 0; i
< NUM_SAVEDPIXELSTATES_R
; i
++) {
877 IWineD3DDevice_SetRenderState(pDevice
, SavedPixelStates_R
[i
], This
->renderState
[SavedPixelStates_R
[i
]]);
879 for(j
= 0; j
< MAX_TEXTURES
; j
++) {
880 for(i
= 0; i
< NUM_SAVEDPIXELSTATES_T
; i
++) {
881 IWineD3DDevice_SetTextureStageState(pDevice
, j
, SavedPixelStates_T
[i
],
882 This
->textureState
[j
][SavedPixelStates_T
[i
]]);
886 for(j
= 0; j
< MAX_FRAGMENT_SAMPLERS
; j
++) {
887 for(i
= 0; i
< NUM_SAVEDPIXELSTATES_S
; i
++) {
888 IWineD3DDevice_SetSamplerState(pDevice
, j
, SavedPixelStates_S
[i
],
889 This
->samplerState
[j
][SavedPixelStates_S
[i
]]);
892 for(j
= MAX_FRAGMENT_SAMPLERS
; j
< MAX_COMBINED_SAMPLERS
; j
++) {
893 for(i
= 0; i
< NUM_SAVEDPIXELSTATES_S
; i
++) {
894 IWineD3DDevice_SetSamplerState(pDevice
,
895 WINED3DVERTEXTEXTURESAMPLER0
+ j
- MAX_FRAGMENT_SAMPLERS
,
896 SavedPixelStates_S
[i
],
897 This
->samplerState
[j
][SavedPixelStates_S
[i
]]);
900 } else if(This
->blockType
== WINED3DSBT_ALL
) {
901 IWineD3DDevice_SetVertexShader(pDevice
, This
->vertexShader
);
902 for (i
= 0; i
< GL_LIMITS(vshader_constantsF
); i
++) {
903 IWineD3DDevice_SetVertexShaderConstantF(pDevice
, i
,
904 This
->vertexShaderConstantF
+ i
* 4, 1);
906 for (i
= 0; i
< MAX_CONST_I
; i
++) {
907 IWineD3DDevice_SetVertexShaderConstantI(pDevice
, i
,
908 This
->vertexShaderConstantI
+ i
* 4, 1);
910 for (i
= 0; i
< MAX_CONST_B
; i
++) {
911 IWineD3DDevice_SetVertexShaderConstantB(pDevice
, i
,
912 This
->vertexShaderConstantB
+ i
, 1);
915 IWineD3DDevice_SetPixelShader(pDevice
, This
->pixelShader
);
916 for (i
= 0; i
< GL_LIMITS(pshader_constantsF
); i
++) {
917 IWineD3DDevice_SetPixelShaderConstantF(pDevice
, i
,
918 This
->pixelShaderConstantF
+ i
* 4, 1);
920 for (i
= 0; i
< MAX_CONST_I
; i
++) {
921 IWineD3DDevice_SetPixelShaderConstantI(pDevice
, i
,
922 This
->pixelShaderConstantI
+ i
* 4, 1);
924 for (i
= 0; i
< MAX_CONST_B
; i
++) {
925 IWineD3DDevice_SetPixelShaderConstantB(pDevice
, i
,
926 This
->pixelShaderConstantB
+ i
, 1);
929 apply_lights(pDevice
, This
);
931 for(i
= 1; i
<= WINEHIGHEST_RENDER_STATE
; i
++) {
932 IWineD3DDevice_SetRenderState(pDevice
, i
, This
->renderState
[i
]);
934 for(j
= 0; j
< MAX_TEXTURES
; j
++) {
935 for(i
= 1; i
<= WINED3D_HIGHEST_TEXTURE_STATE
; i
++) {
936 IWineD3DDevice_SetTextureStageState(pDevice
, j
, i
, This
->textureState
[j
][i
]);
940 /* Skip unused values between TEXTURE8 and WORLD0 ? */
941 for(i
= 1; i
<= HIGHEST_TRANSFORMSTATE
; i
++) {
942 IWineD3DDevice_SetTransform(pDevice
, i
, &This
->transforms
[i
]);
944 IWineD3DDevice_SetIndices(pDevice
, This
->pIndexData
);
945 IWineD3DDevice_SetBaseVertexIndex(pDevice
, This
->baseVertexIndex
);
946 IWineD3DDevice_SetFVF(pDevice
, This
->fvf
);
947 IWineD3DDevice_SetVertexDeclaration(pDevice
, This
->vertexDecl
);
948 IWineD3DDevice_SetMaterial(pDevice
, &This
->material
);
949 IWineD3DDevice_SetViewport(pDevice
, &This
->viewport
);
950 IWineD3DDevice_SetScissorRect(pDevice
, &This
->scissorRect
);
952 /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
953 for (i
=0; i
<MAX_STREAMS
; i
++) {
954 IWineD3DDevice_SetStreamSource(pDevice
, i
, This
->streamSource
[i
], 0, This
->streamStride
[i
]);
955 IWineD3DDevice_SetStreamSourceFreq(pDevice
, i
, This
->streamFreq
[i
] | This
->streamFlags
[i
]);
957 for (j
= 0 ; j
< MAX_COMBINED_SAMPLERS
; j
++){
958 UINT sampler
= j
< MAX_FRAGMENT_SAMPLERS
? j
: WINED3DVERTEXTEXTURESAMPLER0
+ j
- MAX_FRAGMENT_SAMPLERS
;
960 IWineD3DDevice_SetTexture(pDevice
, sampler
, This
->textures
[j
]);
961 for(i
= 1; i
< WINED3D_HIGHEST_SAMPLER_STATE
; i
++) {
962 IWineD3DDevice_SetSamplerState(pDevice
, sampler
, i
, This
->samplerState
[j
][i
]);
965 for (i
= 0; i
< GL_LIMITS(clipplanes
); i
++) {
968 clip
[0] = This
->clipplane
[i
][0];
969 clip
[1] = This
->clipplane
[i
][1];
970 clip
[2] = This
->clipplane
[i
][2];
971 clip
[3] = This
->clipplane
[i
][3];
972 IWineD3DDevice_SetClipPlane(pDevice
, i
, clip
);
976 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->lowest_disabled_stage
= MAX_TEXTURES
- 1;
977 for(j
= 0; j
< MAX_TEXTURES
- 1; j
++) {
978 if(((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->textureState
[j
][WINED3DTSS_COLOROP
] == WINED3DTOP_DISABLE
) {
979 ((IWineD3DDeviceImpl
*)pDevice
)->stateBlock
->lowest_disabled_stage
= j
;
983 TRACE("(%p) : Applied state block %p ------------------^\n", This
, pDevice
);
988 static HRESULT WINAPI
IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock
* iface
) {
989 IWineD3DStateBlockImpl
*This
= (IWineD3DStateBlockImpl
*)iface
;
990 IWineD3DDevice
*device
= (IWineD3DDevice
*)This
->wineD3DDevice
;
991 IWineD3DDeviceImpl
*ThisDevice
= (IWineD3DDeviceImpl
*)device
;
993 WINED3DLINEPATTERN lp
;
1002 /* Note this may have a large overhead but it should only be executed
1003 once, in order to initialize the complete state of the device and
1004 all opengl equivalents */
1005 TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This
, This
->wineD3DDevice
);
1006 /* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
1007 This
->blockType
= WINED3DSBT_INIT
;
1009 /* Set some of the defaults for lights, transforms etc */
1010 memcpy(&This
->transforms
[WINED3DTS_PROJECTION
], &identity
, sizeof(identity
));
1011 memcpy(&This
->transforms
[WINED3DTS_VIEW
], &identity
, sizeof(identity
));
1012 for (i
= 0; i
< 256; ++i
) {
1013 memcpy(&This
->transforms
[WINED3DTS_WORLDMATRIX(i
)], &identity
, sizeof(identity
));
1016 TRACE("Render states\n");
1017 /* Render states: */
1018 if (ThisDevice
->depthStencilBuffer
!= NULL
) {
1019 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZENABLE
, WINED3DZB_TRUE
);
1021 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZENABLE
, WINED3DZB_FALSE
);
1023 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FILLMODE
, WINED3DFILL_SOLID
);
1024 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SHADEMODE
, WINED3DSHADE_GOURAUD
);
1025 lp
.lp
.wRepeatFactor
= 0;
1026 lp
.lp
.wLinePattern
= 0;
1027 IWineD3DDevice_SetRenderState(device
, WINED3DRS_LINEPATTERN
, lp
.d
);
1028 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZWRITEENABLE
, TRUE
);
1029 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ALPHATESTENABLE
, FALSE
);
1030 IWineD3DDevice_SetRenderState(device
, WINED3DRS_LASTPIXEL
, TRUE
);
1031 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SRCBLEND
, WINED3DBLEND_ONE
);
1032 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DESTBLEND
, WINED3DBLEND_ZERO
);
1033 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CULLMODE
, WINED3DCULL_CCW
);
1034 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZFUNC
, WINED3DCMP_LESSEQUAL
);
1035 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ALPHAFUNC
, WINED3DCMP_ALWAYS
);
1036 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ALPHAREF
, 0);
1037 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DITHERENABLE
, FALSE
);
1038 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ALPHABLENDENABLE
, FALSE
);
1039 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGENABLE
, FALSE
);
1040 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SPECULARENABLE
, FALSE
);
1041 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZVISIBLE
, 0);
1042 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGCOLOR
, 0);
1043 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGTABLEMODE
, WINED3DFOG_NONE
);
1045 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGSTART
, tmpfloat
.d
);
1047 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGEND
, tmpfloat
.d
);
1049 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGDENSITY
, tmpfloat
.d
);
1050 IWineD3DDevice_SetRenderState(device
, WINED3DRS_EDGEANTIALIAS
, FALSE
);
1051 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ZBIAS
, 0);
1052 IWineD3DDevice_SetRenderState(device
, WINED3DRS_RANGEFOGENABLE
, FALSE
);
1053 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILENABLE
, FALSE
);
1054 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILFAIL
, WINED3DSTENCILOP_KEEP
);
1055 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILZFAIL
, WINED3DSTENCILOP_KEEP
);
1056 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILPASS
, WINED3DSTENCILOP_KEEP
);
1057 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILREF
, 0);
1058 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILMASK
, 0xFFFFFFFF);
1059 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILFUNC
, WINED3DCMP_ALWAYS
);
1060 IWineD3DDevice_SetRenderState(device
, WINED3DRS_STENCILWRITEMASK
, 0xFFFFFFFF);
1061 IWineD3DDevice_SetRenderState(device
, WINED3DRS_TEXTUREFACTOR
, 0xFFFFFFFF);
1062 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP0
, 0);
1063 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP1
, 0);
1064 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP2
, 0);
1065 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP3
, 0);
1066 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP4
, 0);
1067 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP5
, 0);
1068 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP6
, 0);
1069 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP7
, 0);
1070 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CLIPPING
, TRUE
);
1071 IWineD3DDevice_SetRenderState(device
, WINED3DRS_LIGHTING
, TRUE
);
1072 IWineD3DDevice_SetRenderState(device
, WINED3DRS_AMBIENT
, 0);
1073 IWineD3DDevice_SetRenderState(device
, WINED3DRS_FOGVERTEXMODE
, WINED3DFOG_NONE
);
1074 IWineD3DDevice_SetRenderState(device
, WINED3DRS_COLORVERTEX
, TRUE
);
1075 IWineD3DDevice_SetRenderState(device
, WINED3DRS_LOCALVIEWER
, TRUE
);
1076 IWineD3DDevice_SetRenderState(device
, WINED3DRS_NORMALIZENORMALS
, FALSE
);
1077 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DIFFUSEMATERIALSOURCE
, WINED3DMCS_COLOR1
);
1078 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SPECULARMATERIALSOURCE
, WINED3DMCS_COLOR2
);
1079 IWineD3DDevice_SetRenderState(device
, WINED3DRS_AMBIENTMATERIALSOURCE
, WINED3DMCS_MATERIAL
);
1080 IWineD3DDevice_SetRenderState(device
, WINED3DRS_EMISSIVEMATERIALSOURCE
, WINED3DMCS_MATERIAL
);
1081 IWineD3DDevice_SetRenderState(device
, WINED3DRS_VERTEXBLEND
, WINED3DVBF_DISABLE
);
1082 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CLIPPLANEENABLE
, 0);
1083 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SOFTWAREVERTEXPROCESSING
, FALSE
);
1085 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSIZE
, tmpfloat
.d
);
1087 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSIZE_MIN
, tmpfloat
.d
);
1088 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSPRITEENABLE
, FALSE
);
1089 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSCALEENABLE
, FALSE
);
1091 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSCALE_A
, tmpfloat
.d
);
1093 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSCALE_B
, tmpfloat
.d
);
1095 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSCALE_C
, tmpfloat
.d
);
1096 IWineD3DDevice_SetRenderState(device
, WINED3DRS_MULTISAMPLEANTIALIAS
, TRUE
);
1097 IWineD3DDevice_SetRenderState(device
, WINED3DRS_MULTISAMPLEMASK
, 0xFFFFFFFF);
1098 IWineD3DDevice_SetRenderState(device
, WINED3DRS_PATCHEDGESTYLE
, WINED3DPATCHEDGE_DISCRETE
);
1100 IWineD3DDevice_SetRenderState(device
, WINED3DRS_PATCHSEGMENTS
, tmpfloat
.d
);
1101 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DEBUGMONITORTOKEN
, 0xbaadcafe);
1103 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POINTSIZE_MAX
, tmpfloat
.d
);
1104 IWineD3DDevice_SetRenderState(device
, WINED3DRS_INDEXEDVERTEXBLENDENABLE
, FALSE
);
1105 IWineD3DDevice_SetRenderState(device
, WINED3DRS_COLORWRITEENABLE
, 0x0000000F);
1107 IWineD3DDevice_SetRenderState(device
, WINED3DRS_TWEENFACTOR
, tmpfloat
.d
);
1108 IWineD3DDevice_SetRenderState(device
, WINED3DRS_BLENDOP
, WINED3DBLENDOP_ADD
);
1109 IWineD3DDevice_SetRenderState(device
, WINED3DRS_POSITIONDEGREE
, WINED3DDEGREE_CUBIC
);
1110 IWineD3DDevice_SetRenderState(device
, WINED3DRS_NORMALDEGREE
, WINED3DDEGREE_LINEAR
);
1111 /* states new in d3d9 */
1112 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SCISSORTESTENABLE
, FALSE
);
1113 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SLOPESCALEDEPTHBIAS
, 0);
1115 IWineD3DDevice_SetRenderState(device
, WINED3DRS_MINTESSELLATIONLEVEL
, tmpfloat
.d
);
1116 IWineD3DDevice_SetRenderState(device
, WINED3DRS_MAXTESSELLATIONLEVEL
, tmpfloat
.d
);
1117 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ANTIALIASEDLINEENABLE
, FALSE
);
1119 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ADAPTIVETESS_X
, tmpfloat
.d
);
1120 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ADAPTIVETESS_Y
, tmpfloat
.d
);
1122 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ADAPTIVETESS_Z
, tmpfloat
.d
);
1124 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ADAPTIVETESS_W
, tmpfloat
.d
);
1125 IWineD3DDevice_SetRenderState(device
, WINED3DRS_ENABLEADAPTIVETESSELLATION
, FALSE
);
1126 IWineD3DDevice_SetRenderState(device
, WINED3DRS_TWOSIDEDSTENCILMODE
, FALSE
);
1127 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CCW_STENCILFAIL
, WINED3DSTENCILOP_KEEP
);
1128 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CCW_STENCILZFAIL
, WINED3DSTENCILOP_KEEP
);
1129 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CCW_STENCILPASS
, WINED3DSTENCILOP_KEEP
);
1130 IWineD3DDevice_SetRenderState(device
, WINED3DRS_CCW_STENCILFUNC
, WINED3DCMP_ALWAYS
);
1131 IWineD3DDevice_SetRenderState(device
, WINED3DRS_COLORWRITEENABLE1
, 0x0000000F);
1132 IWineD3DDevice_SetRenderState(device
, WINED3DRS_COLORWRITEENABLE2
, 0x0000000F);
1133 IWineD3DDevice_SetRenderState(device
, WINED3DRS_COLORWRITEENABLE3
, 0x0000000F);
1134 IWineD3DDevice_SetRenderState(device
, WINED3DRS_BLENDFACTOR
, 0xFFFFFFFF);
1135 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SRGBWRITEENABLE
, 0);
1136 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DEPTHBIAS
, 0);
1137 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP8
, 0);
1138 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP9
, 0);
1139 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP10
, 0);
1140 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP11
, 0);
1141 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP12
, 0);
1142 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP13
, 0);
1143 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP14
, 0);
1144 IWineD3DDevice_SetRenderState(device
, WINED3DRS_WRAP15
, 0);
1145 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SEPARATEALPHABLENDENABLE
, FALSE
);
1146 IWineD3DDevice_SetRenderState(device
, WINED3DRS_SRCBLENDALPHA
, WINED3DBLEND_ONE
);
1147 IWineD3DDevice_SetRenderState(device
, WINED3DRS_DESTBLENDALPHA
, WINED3DBLEND_ZERO
);
1148 IWineD3DDevice_SetRenderState(device
, WINED3DRS_BLENDOPALPHA
, WINED3DBLENDOP_ADD
);
1150 /* clipping status */
1151 This
->clip_status
.ClipUnion
= 0;
1152 This
->clip_status
.ClipIntersection
= 0xFFFFFFFF;
1154 /* Texture Stage States - Put directly into state block, we will call function below */
1155 for (i
= 0; i
< MAX_TEXTURES
; i
++) {
1156 TRACE("Setting up default texture states for texture Stage %d\n", i
);
1157 memcpy(&This
->transforms
[WINED3DTS_TEXTURE0
+ i
], &identity
, sizeof(identity
));
1158 This
->textureState
[i
][WINED3DTSS_COLOROP
] = (i
==0)? WINED3DTOP_MODULATE
: WINED3DTOP_DISABLE
;
1159 This
->textureState
[i
][WINED3DTSS_COLORARG1
] = WINED3DTA_TEXTURE
;
1160 This
->textureState
[i
][WINED3DTSS_COLORARG2
] = WINED3DTA_CURRENT
;
1161 This
->textureState
[i
][WINED3DTSS_ALPHAOP
] = (i
==0)? WINED3DTOP_SELECTARG1
: WINED3DTOP_DISABLE
;
1162 This
->textureState
[i
][WINED3DTSS_ALPHAARG1
] = WINED3DTA_TEXTURE
;
1163 This
->textureState
[i
][WINED3DTSS_ALPHAARG2
] = WINED3DTA_CURRENT
;
1164 This
->textureState
[i
][WINED3DTSS_BUMPENVMAT00
] = (DWORD
) 0.0;
1165 This
->textureState
[i
][WINED3DTSS_BUMPENVMAT01
] = (DWORD
) 0.0;
1166 This
->textureState
[i
][WINED3DTSS_BUMPENVMAT10
] = (DWORD
) 0.0;
1167 This
->textureState
[i
][WINED3DTSS_BUMPENVMAT11
] = (DWORD
) 0.0;
1168 This
->textureState
[i
][WINED3DTSS_TEXCOORDINDEX
] = i
;
1169 This
->textureState
[i
][WINED3DTSS_BUMPENVLSCALE
] = (DWORD
) 0.0;
1170 This
->textureState
[i
][WINED3DTSS_BUMPENVLOFFSET
] = (DWORD
) 0.0;
1171 This
->textureState
[i
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] = WINED3DTTFF_DISABLE
;
1172 This
->textureState
[i
][WINED3DTSS_ADDRESSW
] = WINED3DTADDRESS_WRAP
;
1173 This
->textureState
[i
][WINED3DTSS_COLORARG0
] = WINED3DTA_CURRENT
;
1174 This
->textureState
[i
][WINED3DTSS_ALPHAARG0
] = WINED3DTA_CURRENT
;
1175 This
->textureState
[i
][WINED3DTSS_RESULTARG
] = WINED3DTA_CURRENT
;
1177 This
->lowest_disabled_stage
= 1;
1180 for (i
= 0 ; i
< MAX_COMBINED_SAMPLERS
; i
++) {
1181 TRACE("Setting up default samplers states for sampler %d\n", i
);
1182 This
->samplerState
[i
][WINED3DSAMP_ADDRESSU
] = WINED3DTADDRESS_WRAP
;
1183 This
->samplerState
[i
][WINED3DSAMP_ADDRESSV
] = WINED3DTADDRESS_WRAP
;
1184 This
->samplerState
[i
][WINED3DSAMP_ADDRESSW
] = WINED3DTADDRESS_WRAP
;
1185 This
->samplerState
[i
][WINED3DSAMP_BORDERCOLOR
] = 0x00;
1186 This
->samplerState
[i
][WINED3DSAMP_MAGFILTER
] = WINED3DTEXF_POINT
;
1187 This
->samplerState
[i
][WINED3DSAMP_MINFILTER
] = WINED3DTEXF_POINT
;
1188 This
->samplerState
[i
][WINED3DSAMP_MIPFILTER
] = WINED3DTEXF_NONE
;
1189 This
->samplerState
[i
][WINED3DSAMP_MIPMAPLODBIAS
] = 0;
1190 This
->samplerState
[i
][WINED3DSAMP_MAXMIPLEVEL
] = 0;
1191 This
->samplerState
[i
][WINED3DSAMP_MAXANISOTROPY
] = 1;
1192 This
->samplerState
[i
][WINED3DSAMP_SRGBTEXTURE
] = 0;
1193 This
->samplerState
[i
][WINED3DSAMP_ELEMENTINDEX
] = 0; /* TODO: Indicates which element of a multielement texture to use */
1194 This
->samplerState
[i
][WINED3DSAMP_DMAPOFFSET
] = 0; /* TODO: Vertex offset in the presampled displacement map */
1197 /* Under DirectX you can have texture stage operations even if no texture is
1198 bound, whereas opengl will only do texture operations when a valid texture is
1199 bound. We emulate this by creating dummy textures and binding them to each
1200 texture stage, but disable all stages by default. Hence if a stage is enabled
1201 then the default texture will kick in until replaced by a SetTexture call */
1204 if(GL_SUPPORT(APPLE_CLIENT_STORAGE
)) {
1205 /* The dummy texture does not have client storage backing */
1206 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE
, GL_FALSE
);
1207 checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
1209 for (i
= 0; i
< GL_LIMITS(textures
); i
++) {
1210 GLubyte white
= 255;
1212 /* Note this avoids calling settexture, so pretend it has been called */
1213 This
->changed
.textures
[i
] = TRUE
;
1214 This
->textures
[i
] = NULL
;
1216 /* Make appropriate texture active */
1217 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
1218 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB
+ i
));
1219 checkGLcall("glActiveTextureARB");
1221 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1224 /* Generate an opengl texture name */
1225 glGenTextures(1, &ThisDevice
->dummyTextureName
[i
]);
1226 checkGLcall("glGenTextures");
1227 TRACE("Dummy Texture %d given name %d\n", i
, ThisDevice
->dummyTextureName
[i
]);
1229 /* Generate a dummy 2d texture (not using 1d because they cause many
1230 * DRI drivers fall back to sw) */
1231 This
->textureDimensions
[i
] = GL_TEXTURE_2D
;
1232 glBindTexture(GL_TEXTURE_2D
, ThisDevice
->dummyTextureName
[i
]);
1233 checkGLcall("glBindTexture");
1235 glTexImage2D(GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 1, 1, 0, GL_LUMINANCE
, GL_UNSIGNED_BYTE
, &white
);
1236 checkGLcall("glTexImage2D");
1238 if(GL_SUPPORT(APPLE_CLIENT_STORAGE
)) {
1239 /* Reenable because if supported it is enabled by default */
1240 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE
, GL_TRUE
);
1241 checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
1247 /* Defaulting palettes - Note these are device wide but reinitialized here for convenience*/
1248 for (i
= 0; i
< MAX_PALETTES
; ++i
) {
1250 for (j
= 0; j
< 256; ++j
) {
1251 This
->wineD3DDevice
->palettes
[i
][j
].peRed
= 0xFF;
1252 This
->wineD3DDevice
->palettes
[i
][j
].peGreen
= 0xFF;
1253 This
->wineD3DDevice
->palettes
[i
][j
].peBlue
= 0xFF;
1254 This
->wineD3DDevice
->palettes
[i
][j
].peFlags
= 0xFF;
1257 This
->wineD3DDevice
->currentPalette
= 0;
1259 /* Set default GLSL program to NULL. We won't actually create one
1260 * until the app sets a vertex or pixel shader */
1261 This
->glsl_program
= NULL
;
1263 TRACE("-----------------------> Device defaults now set up...\n");
1267 /**********************************************************
1268 * IWineD3DStateBlock VTbl follows
1269 **********************************************************/
1271 const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl
=
1274 IWineD3DStateBlockImpl_QueryInterface
,
1275 IWineD3DStateBlockImpl_AddRef
,
1276 IWineD3DStateBlockImpl_Release
,
1277 /* IWineD3DStateBlock */
1278 IWineD3DStateBlockImpl_GetParent
,
1279 IWineD3DStateBlockImpl_GetDevice
,
1280 IWineD3DStateBlockImpl_Capture
,
1281 IWineD3DStateBlockImpl_Apply
,
1282 IWineD3DStateBlockImpl_InitStartupStateBlock