2004-10-21 22:59:12 +02:00
|
|
|
/*
|
|
|
|
* state block implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002 Raphael Junqueira
|
2005-03-02 14:44:58 +01:00
|
|
|
* Copyright 2004 Jason Edmeades
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007 Stefan Dösinger for CodeWeavers
|
2004-10-21 22:59:12 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-10-21 22:59:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2007-06-09 14:27:41 +02:00
|
|
|
#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
|
2004-10-21 22:59:12 +02:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/***************************************
|
|
|
|
* Stateblock helper functions follow
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
/** Allocates the correct amount of space for pixel and vertex shader constants,
|
|
|
|
* along with their set/changed flags on the given stateblock object
|
|
|
|
*/
|
|
|
|
HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
|
|
|
|
|
|
|
|
IWineD3DStateBlockImpl *This = object;
|
|
|
|
|
|
|
|
/* Allocate space for floating point constants */
|
|
|
|
object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->pixelShaderConstantF) goto fail;
|
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->changed.pixelShaderConstantsF) goto fail;
|
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->vertexShaderConstantF) goto fail;
|
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->changed.vertexShaderConstantsF) goto fail;
|
|
|
|
|
2007-08-03 20:26:29 +02:00
|
|
|
object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->contained_vs_consts_f) goto fail;
|
|
|
|
|
2007-08-03 20:26:29 +02:00
|
|
|
object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->contained_ps_consts_f) goto fail;
|
2006-07-19 06:06:07 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2008-12-12 09:33:52 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
ERR("Failed to allocate memory\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->pixelShaderConstantF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->vertexShaderConstantF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
|
|
|
|
return E_OUTOFMEMORY;
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
|
|
|
|
2006-07-23 21:08:27 +02:00
|
|
|
/** Copy all members of one stateblock to another */
|
2008-12-02 18:41:33 +01:00
|
|
|
static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *dest, const SAVEDSTATES *source)
|
2008-12-01 15:32:15 +01:00
|
|
|
{
|
2006-07-23 21:08:27 +02:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
unsigned bsize = sizeof(BOOL);
|
|
|
|
|
|
|
|
/* Single values */
|
|
|
|
dest->indices = source->indices;
|
|
|
|
dest->material = source->material;
|
|
|
|
dest->viewport = source->viewport;
|
|
|
|
dest->vertexDecl = source->vertexDecl;
|
|
|
|
dest->pixelShader = source->pixelShader;
|
|
|
|
dest->vertexShader = source->vertexShader;
|
2007-01-10 11:28:42 +01:00
|
|
|
dest->scissorRect = dest->scissorRect;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Fixed size arrays */
|
|
|
|
memcpy(dest->streamSource, source->streamSource, bsize * MAX_STREAMS);
|
|
|
|
memcpy(dest->streamFreq, source->streamFreq, bsize * MAX_STREAMS);
|
2007-06-25 22:45:40 +02:00
|
|
|
memcpy(dest->textures, source->textures, bsize * MAX_COMBINED_SAMPLERS);
|
2006-07-23 21:08:27 +02:00
|
|
|
memcpy(dest->transform, source->transform, bsize * (HIGHEST_TRANSFORMSTATE + 1));
|
|
|
|
memcpy(dest->renderState, source->renderState, bsize * (WINEHIGHEST_RENDER_STATE + 1));
|
|
|
|
memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
|
2007-06-25 22:45:40 +02:00
|
|
|
memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
|
2006-07-23 21:08:27 +02:00
|
|
|
memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
|
2008-12-02 18:41:33 +01:00
|
|
|
dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
|
|
|
|
dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
|
|
|
|
dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
|
|
|
|
dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Dynamically sized arrays */
|
|
|
|
memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
|
|
|
|
memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set all members of a stateblock savedstate to the given value */
|
|
|
|
void stateblock_savedstates_set(
|
|
|
|
IWineD3DStateBlock* iface,
|
|
|
|
SAVEDSTATES* states,
|
|
|
|
BOOL value) {
|
|
|
|
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
unsigned bsize = sizeof(BOOL);
|
|
|
|
|
|
|
|
/* Single values */
|
|
|
|
states->indices = value;
|
|
|
|
states->material = value;
|
|
|
|
states->viewport = value;
|
|
|
|
states->vertexDecl = value;
|
|
|
|
states->pixelShader = value;
|
|
|
|
states->vertexShader = value;
|
2007-01-10 11:28:42 +01:00
|
|
|
states->scissorRect = value;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Fixed size arrays */
|
|
|
|
memset(states->streamSource, value, bsize * MAX_STREAMS);
|
|
|
|
memset(states->streamFreq, value, bsize * MAX_STREAMS);
|
2007-06-25 22:45:40 +02:00
|
|
|
memset(states->textures, value, bsize * MAX_COMBINED_SAMPLERS);
|
2006-07-23 21:08:27 +02:00
|
|
|
memset(states->transform, value, bsize * (HIGHEST_TRANSFORMSTATE + 1));
|
|
|
|
memset(states->renderState, value, bsize * (WINEHIGHEST_RENDER_STATE + 1));
|
|
|
|
memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
|
2007-06-25 22:45:40 +02:00
|
|
|
memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
|
2006-07-23 21:08:27 +02:00
|
|
|
memset(states->clipplane, value, bsize * MAX_CLIPPLANES);
|
2008-12-02 18:41:33 +01:00
|
|
|
states->pixelShaderConstantsB = value ? 0xffff : 0;
|
|
|
|
states->pixelShaderConstantsI = value ? 0xffff : 0;
|
|
|
|
states->vertexShaderConstantsB = value ? 0xffff : 0;
|
|
|
|
states->vertexShaderConstantsI = value ? 0xffff : 0;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Dynamically sized arrays */
|
|
|
|
memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
|
|
|
|
memset(states->vertexShaderConstantsF, value, bsize * GL_LIMITS(vshader_constantsF));
|
|
|
|
}
|
|
|
|
|
|
|
|
void stateblock_copy(
|
|
|
|
IWineD3DStateBlock* destination,
|
|
|
|
IWineD3DStateBlock* source) {
|
2007-02-14 17:46:54 +01:00
|
|
|
int l;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)source;
|
|
|
|
IWineD3DStateBlockImpl *Dest = (IWineD3DStateBlockImpl *)destination;
|
|
|
|
|
|
|
|
/* IUnknown fields */
|
|
|
|
Dest->lpVtbl = This->lpVtbl;
|
|
|
|
Dest->ref = This->ref;
|
|
|
|
|
|
|
|
/* IWineD3DStateBlock information */
|
|
|
|
Dest->parent = This->parent;
|
|
|
|
Dest->wineD3DDevice = This->wineD3DDevice;
|
|
|
|
Dest->blockType = This->blockType;
|
|
|
|
|
|
|
|
/* Saved states */
|
|
|
|
stateblock_savedstates_copy(source, &Dest->changed, &This->changed);
|
|
|
|
|
|
|
|
/* Single items */
|
|
|
|
Dest->vertexDecl = This->vertexDecl;
|
|
|
|
Dest->vertexShader = This->vertexShader;
|
|
|
|
Dest->streamIsUP = This->streamIsUP;
|
|
|
|
Dest->pIndexData = This->pIndexData;
|
|
|
|
Dest->baseVertexIndex = This->baseVertexIndex;
|
2007-02-14 17:46:54 +01:00
|
|
|
/* Dest->lights = This->lights; */
|
2006-07-23 21:08:27 +02:00
|
|
|
Dest->clip_status = This->clip_status;
|
|
|
|
Dest->viewport = This->viewport;
|
|
|
|
Dest->material = This->material;
|
|
|
|
Dest->pixelShader = This->pixelShader;
|
2008-03-20 23:25:13 +01:00
|
|
|
Dest->scissorRect = This->scissorRect;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
2007-02-14 17:46:54 +01:00
|
|
|
/* Lights */
|
|
|
|
memset(This->activeLights, 0, sizeof(This->activeLights));
|
|
|
|
for(l = 0; l < LIGHTMAP_SIZE; l++) {
|
|
|
|
struct list *e1, *e2;
|
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &Dest->lightMap[l]) {
|
|
|
|
PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
|
|
|
|
list_remove(&light->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, light);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH(e1, &This->lightMap[l]) {
|
|
|
|
PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry), *light2;
|
|
|
|
light2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*light));
|
2008-03-20 23:25:13 +01:00
|
|
|
*light2 = *light;
|
2007-08-16 13:30:42 +02:00
|
|
|
list_add_tail(&Dest->lightMap[l], &light2->entry);
|
|
|
|
if(light2->glIndex != -1) Dest->activeLights[light2->glIndex] = light2;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-23 21:08:27 +02:00
|
|
|
/* Fixed size arrays */
|
|
|
|
memcpy(Dest->vertexShaderConstantB, This->vertexShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
|
|
|
|
memcpy(Dest->vertexShaderConstantI, This->vertexShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
|
|
|
|
memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
|
|
|
|
memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
|
|
|
|
|
|
|
|
memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
|
|
|
|
memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
|
|
|
|
memcpy(Dest->streamSource, This->streamSource, sizeof(IWineD3DVertexBuffer*) * MAX_STREAMS);
|
|
|
|
memcpy(Dest->streamFreq, This->streamFreq, sizeof(UINT) * MAX_STREAMS);
|
|
|
|
memcpy(Dest->streamFlags, This->streamFlags, sizeof(UINT) * MAX_STREAMS);
|
2006-10-12 08:21:39 +02:00
|
|
|
memcpy(Dest->transforms, This->transforms, sizeof(WINED3DMATRIX) * (HIGHEST_TRANSFORMSTATE + 1));
|
2006-07-23 21:08:27 +02:00
|
|
|
memcpy(Dest->clipplane, This->clipplane, sizeof(double) * MAX_CLIPPLANES * 4);
|
|
|
|
memcpy(Dest->renderState, This->renderState, sizeof(DWORD) * (WINEHIGHEST_RENDER_STATE + 1));
|
2007-06-25 22:45:40 +02:00
|
|
|
memcpy(Dest->textures, This->textures, sizeof(IWineD3DBaseTexture*) * MAX_COMBINED_SAMPLERS);
|
2006-07-23 21:08:27 +02:00
|
|
|
memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
|
2007-06-25 22:45:40 +02:00
|
|
|
memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Dynamically sized arrays */
|
|
|
|
memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
|
|
|
|
memcpy(Dest->pixelShaderConstantF, This->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
|
|
|
|
}
|
|
|
|
|
2005-03-02 14:44:58 +01:00
|
|
|
/**********************************************************
|
|
|
|
* IWineD3DStateBlockImpl IUnknown parts follows
|
|
|
|
**********************************************************/
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,REFIID riid,LPVOID *ppobj)
|
2005-03-02 14:44:58 +01:00
|
|
|
{
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2006-02-06 11:32:41 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
2005-03-02 14:44:58 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DStateBlock)){
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*ppobj = This;
|
2006-04-25 23:59:12 +02:00
|
|
|
return S_OK;
|
2005-03-02 14:44:58 +01:00
|
|
|
}
|
2006-04-25 23:59:12 +02:00
|
|
|
*ppobj = NULL;
|
2005-03-02 14:44:58 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DStateBlockImpl_AddRef(IWineD3DStateBlock *iface) {
|
2005-03-02 14:44:58 +01:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
|
2005-03-02 14:44:58 +01:00
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
|
2005-03-02 14:44:58 +01:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : Releasing from %d\n", This, refCount + 1);
|
2005-03-02 14:44:58 +01:00
|
|
|
|
|
|
|
if (!refCount) {
|
2007-02-14 17:46:54 +01:00
|
|
|
int counter;
|
2006-08-19 17:24:02 +02:00
|
|
|
|
2005-07-26 20:49:30 +02:00
|
|
|
/* type 0 represents the primary stateblock, so free all the resources */
|
|
|
|
if (This->blockType == WINED3DSBT_INIT) {
|
2006-06-23 18:18:02 +02:00
|
|
|
/* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
|
2007-06-25 22:45:40 +02:00
|
|
|
for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) {
|
2005-07-26 20:49:30 +02:00
|
|
|
if (This->textures[counter]) {
|
|
|
|
/* release our 'internal' hold on the texture */
|
2005-12-15 10:25:47 +01:00
|
|
|
if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
|
2006-01-03 12:10:37 +01:00
|
|
|
TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-19 20:40:44 +02:00
|
|
|
}
|
2005-07-26 20:49:30 +02:00
|
|
|
|
2007-08-19 20:40:44 +02:00
|
|
|
for (counter = 0; counter < MAX_STREAMS; counter++) {
|
|
|
|
if(This->streamSource[counter]) {
|
|
|
|
if(0 != IWineD3DVertexBuffer_Release(This->streamSource[counter])) {
|
|
|
|
TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter, This->streamSource[counter]);
|
|
|
|
}
|
|
|
|
}
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2007-08-19 20:42:29 +02:00
|
|
|
if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
|
2007-08-20 18:56:10 +02:00
|
|
|
if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
|
|
|
|
if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
|
2006-08-19 17:23:02 +02:00
|
|
|
|
2007-02-14 17:46:54 +01:00
|
|
|
for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
|
|
|
|
struct list *e1, *e2;
|
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) {
|
|
|
|
PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
|
|
|
|
list_remove(&light->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 17:23:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->vertexShaderConstantF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pixelShaderConstantF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->changed.pixelShaderConstantsF);
|
2007-08-03 20:26:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->contained_vs_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->contained_ps_consts_f);
|
2005-03-02 14:44:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
* IWineD3DStateBlockImpl parts follows
|
|
|
|
**********************************************************/
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
|
2004-11-23 14:52:46 +01:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
IUnknown_AddRef(This->parent);
|
|
|
|
*pParent = This->parent;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-23 14:52:46 +01:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
|
|
|
|
*ppDevice = (IWineD3DDevice*)This->wineD3DDevice;
|
|
|
|
IWineD3DDevice_AddRef(*ppDevice);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-04 14:44:33 +02:00
|
|
|
static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
/* Lights... For a recorded state block, we just had a chain of actions to perform,
|
|
|
|
* so we need to walk that chain and update any actions which differ
|
|
|
|
*/
|
|
|
|
for(i = 0; i < LIGHTMAP_SIZE; i++) {
|
|
|
|
struct list *e, *f;
|
|
|
|
LIST_FOR_EACH(e, &This->lightMap[i]) {
|
|
|
|
BOOL updated = FALSE;
|
|
|
|
PLIGHTINFOEL *src = LIST_ENTRY(e, PLIGHTINFOEL, entry), *realLight;
|
|
|
|
if(!src->changed || !src->enabledChanged) continue;
|
|
|
|
|
|
|
|
/* Look up the light in the destination */
|
|
|
|
LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) {
|
|
|
|
realLight = LIST_ENTRY(f, PLIGHTINFOEL, entry);
|
|
|
|
if(realLight->OriginalIndex == src->OriginalIndex) {
|
|
|
|
if(src->changed) {
|
2008-03-20 23:25:13 +01:00
|
|
|
src->OriginalParms = realLight->OriginalParms;
|
2007-08-04 14:44:33 +02:00
|
|
|
}
|
|
|
|
if(src->enabledChanged) {
|
|
|
|
/* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
|
|
|
|
* or disabled -> enabled -> disabled changes
|
|
|
|
*/
|
|
|
|
if(realLight->glIndex == -1 && src->glIndex != -1) {
|
|
|
|
/* Light disabled */
|
|
|
|
This->activeLights[src->glIndex] = NULL;
|
|
|
|
} else if(realLight->glIndex != -1 && src->glIndex == -1){
|
|
|
|
/* Light enabled */
|
|
|
|
This->activeLights[realLight->glIndex] = src;
|
|
|
|
}
|
|
|
|
src->glIndex = realLight->glIndex;
|
|
|
|
}
|
|
|
|
updated = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(updated) {
|
|
|
|
/* Found a light, all done, proceed with next hash entry */
|
|
|
|
continue;
|
|
|
|
} else if(src->changed) {
|
|
|
|
/* Otherwise assign defaul params */
|
2008-03-20 23:25:13 +01:00
|
|
|
src->OriginalParms = WINED3D_default_light;
|
2007-08-04 14:44:33 +02:00
|
|
|
} else {
|
|
|
|
/* Not enabled by default */
|
|
|
|
src->glIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
IWineD3DStateBlockImpl *targetStateBlock = This->wineD3DDevice->stateBlock;
|
2007-08-04 14:44:33 +02:00
|
|
|
unsigned int i, j;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
/* If not recorded, then update can just recapture */
|
2007-08-04 14:44:33 +02:00
|
|
|
if (This->blockType == WINED3DSBT_RECORDED) {
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
/* Recorded => Only update 'changed' values */
|
2007-08-20 18:56:10 +02:00
|
|
|
if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader) {
|
2006-02-06 11:32:13 +01:00
|
|
|
TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
|
|
|
|
|
2007-08-20 18:56:10 +02:00
|
|
|
if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
|
|
|
|
if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
|
2005-07-05 16:05:18 +02:00
|
|
|
This->vertexShader = targetStateBlock->vertexShader;
|
|
|
|
}
|
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Vertex Shader Float Constants */
|
2007-08-03 20:26:29 +02:00
|
|
|
for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
|
|
|
|
i = This->contained_vs_consts_f[j];
|
|
|
|
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->vertexShaderConstantF[i * 4],
|
|
|
|
targetStateBlock->vertexShaderConstantF[i * 4 + 1],
|
|
|
|
targetStateBlock->vertexShaderConstantF[i * 4 + 2],
|
|
|
|
targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
|
|
|
|
|
|
|
|
This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
|
|
|
|
This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
|
|
|
|
This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
|
|
|
|
This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Vertex Shader Integer Constants */
|
2007-08-03 20:07:30 +02:00
|
|
|
for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
|
|
|
|
i = This->contained_vs_consts_i[j];
|
|
|
|
TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->vertexShaderConstantI[i * 4],
|
|
|
|
targetStateBlock->vertexShaderConstantI[i * 4 + 1],
|
|
|
|
targetStateBlock->vertexShaderConstantI[i * 4 + 2],
|
|
|
|
targetStateBlock->vertexShaderConstantI[i * 4 + 3]);
|
|
|
|
|
|
|
|
This->vertexShaderConstantI[i * 4] = targetStateBlock->vertexShaderConstantI[i * 4];
|
|
|
|
This->vertexShaderConstantI[i * 4 + 1] = targetStateBlock->vertexShaderConstantI[i * 4 + 1];
|
|
|
|
This->vertexShaderConstantI[i * 4 + 2] = targetStateBlock->vertexShaderConstantI[i * 4 + 2];
|
|
|
|
This->vertexShaderConstantI[i * 4 + 3] = targetStateBlock->vertexShaderConstantI[i * 4 + 3];
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:07:30 +02:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Vertex Shader Boolean Constants */
|
2007-08-03 20:07:30 +02:00
|
|
|
for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
|
|
|
|
i = This->contained_vs_consts_b[j];
|
|
|
|
TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->vertexShaderConstantB[i]? "TRUE":"FALSE");
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2007-08-03 20:07:30 +02:00
|
|
|
This->vertexShaderConstantB[i] = targetStateBlock->vertexShaderConstantB[i];
|
2005-09-21 12:19:29 +02:00
|
|
|
}
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Pixel Shader Float Constants */
|
2007-08-03 20:26:29 +02:00
|
|
|
for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
|
|
|
|
i = This->contained_ps_consts_f[j];
|
|
|
|
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->pixelShaderConstantF[i * 4],
|
|
|
|
targetStateBlock->pixelShaderConstantF[i * 4 + 1],
|
|
|
|
targetStateBlock->pixelShaderConstantF[i * 4 + 2],
|
|
|
|
targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
|
|
|
|
|
|
|
|
This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
|
|
|
|
This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
|
|
|
|
This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
|
|
|
|
This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Pixel Shader Integer Constants */
|
2007-08-03 20:12:54 +02:00
|
|
|
for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
|
|
|
|
i = This->contained_ps_consts_i[j];
|
|
|
|
TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->pixelShaderConstantI[i * 4],
|
|
|
|
targetStateBlock->pixelShaderConstantI[i * 4 + 1],
|
|
|
|
targetStateBlock->pixelShaderConstantI[i * 4 + 2],
|
|
|
|
targetStateBlock->pixelShaderConstantI[i * 4 + 3]);
|
|
|
|
|
|
|
|
This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4];
|
|
|
|
This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
|
|
|
|
This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
|
|
|
|
This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
|
2006-07-19 06:06:07 +02:00
|
|
|
/* Pixel Shader Boolean Constants */
|
2007-08-03 20:12:54 +02:00
|
|
|
for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
|
|
|
|
i = This->contained_ps_consts_b[j];
|
|
|
|
TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i,
|
|
|
|
targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE");
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2007-08-03 20:12:54 +02:00
|
|
|
This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i];
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Others + Render & Texture */
|
2007-07-31 15:44:13 +02:00
|
|
|
for (i = 0; i < This->num_contained_transform_states; i++) {
|
|
|
|
TRACE("Updating transform %d\n", i);
|
2008-03-20 23:25:13 +01:00
|
|
|
This->transforms[This->contained_transform_states[i]] =
|
|
|
|
targetStateBlock->transforms[This->contained_transform_states[i]];
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.indices && ((This->pIndexData != targetStateBlock->pIndexData)
|
2005-07-05 16:05:18 +02:00
|
|
|
|| (This->baseVertexIndex != targetStateBlock->baseVertexIndex))) {
|
|
|
|
TRACE("Updating pindexData to %p, baseVertexIndex to %d\n",
|
2007-08-19 20:42:29 +02:00
|
|
|
targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
|
|
|
|
if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
|
|
|
|
if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
|
2005-07-05 16:05:18 +02:00
|
|
|
This->pIndexData = targetStateBlock->pIndexData;
|
|
|
|
This->baseVertexIndex = targetStateBlock->baseVertexIndex;
|
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
|
2006-02-06 11:32:13 +01:00
|
|
|
TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
|
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
This->vertexDecl = targetStateBlock->vertexDecl;
|
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.material && memcmp(&targetStateBlock->material,
|
2005-07-05 16:05:18 +02:00
|
|
|
&This->material,
|
2006-10-11 03:56:41 +02:00
|
|
|
sizeof(WINED3DMATERIAL)) != 0) {
|
2005-07-05 16:05:18 +02:00
|
|
|
TRACE("Updating material\n");
|
2008-03-20 23:25:13 +01:00
|
|
|
This->material = targetStateBlock->material;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.viewport && memcmp(&targetStateBlock->viewport,
|
2005-07-05 16:05:18 +02:00
|
|
|
&This->viewport,
|
2006-10-11 03:57:25 +02:00
|
|
|
sizeof(WINED3DVIEWPORT)) != 0) {
|
2005-07-05 16:05:18 +02:00
|
|
|
TRACE("Updating viewport\n");
|
2008-03-20 23:25:13 +01:00
|
|
|
This->viewport = targetStateBlock->viewport;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if(This->changed.scissorRect && memcmp(&targetStateBlock->scissorRect,
|
2007-01-10 11:28:42 +01:00
|
|
|
&This->scissorRect,
|
|
|
|
sizeof(targetStateBlock->scissorRect)))
|
|
|
|
{
|
|
|
|
TRACE("Updating scissor rect\n");
|
2008-03-20 23:25:13 +01:00
|
|
|
targetStateBlock->scissorRect = This->scissorRect;
|
2007-01-10 11:28:42 +01:00
|
|
|
}
|
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
for (i = 0; i < MAX_STREAMS; i++) {
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.streamSource[i] &&
|
2005-07-05 16:05:18 +02:00
|
|
|
((This->streamStride[i] != targetStateBlock->streamStride[i]) ||
|
|
|
|
(This->streamSource[i] != targetStateBlock->streamSource[i]))) {
|
|
|
|
TRACE("Updating stream source %d to %p, stride to %d\n", i, targetStateBlock->streamSource[i],
|
|
|
|
targetStateBlock->streamStride[i]);
|
|
|
|
This->streamStride[i] = targetStateBlock->streamStride[i];
|
2007-08-19 20:40:44 +02:00
|
|
|
if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
|
|
|
|
if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
|
2005-07-05 16:05:18 +02:00
|
|
|
This->streamSource[i] = targetStateBlock->streamSource[i];
|
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.streamFreq[i] &&
|
2005-07-05 16:05:18 +02:00
|
|
|
(This->streamFreq[i] != targetStateBlock->streamFreq[i]
|
|
|
|
|| This->streamFlags[i] != targetStateBlock->streamFlags[i])){
|
|
|
|
TRACE("Updating stream frequency %d to %d flags to %d\n", i , targetStateBlock->streamFreq[i] ,
|
|
|
|
targetStateBlock->streamFlags[i]);
|
|
|
|
This->streamFreq[i] = targetStateBlock->streamFreq[i];
|
|
|
|
This->streamFlags[i] = targetStateBlock->streamFlags[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < GL_LIMITS(clipplanes); i++) {
|
2008-12-10 10:04:40 +01:00
|
|
|
if (This->changed.clipplane[i]
|
|
|
|
&& memcmp(targetStateBlock->clipplane[i], This->clipplane[i], sizeof(*This->clipplane)))
|
|
|
|
{
|
2005-07-05 16:05:18 +02:00
|
|
|
TRACE("Updating clipplane %d\n", i);
|
2008-12-10 10:04:40 +01:00
|
|
|
memcpy(This->clipplane[i], targetStateBlock->clipplane[i], sizeof(*This->clipplane));
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Render */
|
2007-08-04 14:44:33 +02:00
|
|
|
for (i = 0; i < This->num_contained_render_states; i++) {
|
2007-07-31 15:04:56 +02:00
|
|
|
TRACE("Updating renderState %d to %d\n",
|
|
|
|
This->contained_render_states[i], targetStateBlock->renderState[This->contained_render_states[i]]);
|
|
|
|
This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2006-06-27 23:40:42 +02:00
|
|
|
/* Texture states */
|
2007-08-09 17:45:29 +02:00
|
|
|
for (j = 0; j < This->num_contained_tss_states; j++) {
|
|
|
|
DWORD stage = This->contained_tss_states[j].stage;
|
|
|
|
DWORD state = This->contained_tss_states[j].state;
|
|
|
|
|
|
|
|
TRACE("Updating texturestagestate %d,%d to %d (was %d)\n", stage,state,
|
|
|
|
targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
|
|
|
|
This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
|
2006-06-27 23:40:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2006-06-27 23:40:42 +02:00
|
|
|
/* Samplers */
|
|
|
|
/* TODO: move over to using memcpy */
|
2007-06-25 22:45:40 +02:00
|
|
|
for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.textures[j]) {
|
2005-07-05 16:05:18 +02:00
|
|
|
TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]);
|
|
|
|
This->textures[j] = targetStateBlock->textures[j];
|
|
|
|
}
|
2007-08-03 20:23:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < This->num_contained_sampler_states; j++) {
|
|
|
|
DWORD stage = This->contained_sampler_states[j].stage;
|
|
|
|
DWORD state = This->contained_sampler_states[j].state;
|
|
|
|
TRACE("Updating sampler state %d,%d to %d (was %d)\n",
|
|
|
|
stage, state, targetStateBlock->samplerState[stage][state],
|
|
|
|
This->samplerState[stage][state]);
|
|
|
|
This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
2007-08-20 18:56:10 +02:00
|
|
|
if(This->changed.pixelShader && This->pixelShader != targetStateBlock->pixelShader) {
|
|
|
|
if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
|
|
|
|
if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
|
|
|
|
This->pixelShader = targetStateBlock->pixelShader;
|
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
|
|
|
|
record_lights(This, targetStateBlock);
|
|
|
|
} else if(This->blockType == WINED3DSBT_ALL) {
|
|
|
|
This->vertexDecl = targetStateBlock->vertexDecl;
|
|
|
|
memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
|
|
|
|
memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
|
|
|
|
memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
|
|
|
|
memcpy(This->streamStride, targetStateBlock->streamStride, sizeof(This->streamStride));
|
|
|
|
memcpy(This->streamOffset, targetStateBlock->streamOffset, sizeof(This->streamOffset));
|
|
|
|
memcpy(This->streamFreq, targetStateBlock->streamFreq, sizeof(This->streamFreq));
|
|
|
|
memcpy(This->streamFlags, targetStateBlock->streamFlags, sizeof(This->streamFlags));
|
|
|
|
This->baseVertexIndex = targetStateBlock->baseVertexIndex;
|
|
|
|
memcpy(This->transforms, targetStateBlock->transforms, sizeof(This->transforms));
|
|
|
|
record_lights(This, targetStateBlock);
|
|
|
|
memcpy(This->clipplane, targetStateBlock->clipplane, sizeof(This->clipplane));
|
|
|
|
This->clip_status = targetStateBlock->clip_status;
|
|
|
|
This->viewport = targetStateBlock->viewport;
|
|
|
|
This->material = targetStateBlock->material;
|
|
|
|
memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
|
|
|
|
memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
|
|
|
|
memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
|
|
|
|
memcpy(This->renderState, targetStateBlock->renderState, sizeof(This->renderState));
|
|
|
|
memcpy(This->textures, targetStateBlock->textures, sizeof(This->textures));
|
|
|
|
memcpy(This->textureState, targetStateBlock->textureState, sizeof(This->textureState));
|
|
|
|
memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
|
|
|
|
This->scissorRect = targetStateBlock->scissorRect;
|
2007-08-19 20:40:44 +02:00
|
|
|
|
2007-08-19 20:42:29 +02:00
|
|
|
if(targetStateBlock->pIndexData != This->pIndexData) {
|
|
|
|
if(targetStateBlock->pIndexData) IWineD3DIndexBuffer_AddRef(targetStateBlock->pIndexData);
|
|
|
|
if(This->pIndexData) IWineD3DIndexBuffer_Release(This->pIndexData);
|
|
|
|
This->pIndexData = targetStateBlock->pIndexData;
|
|
|
|
}
|
2007-08-19 20:40:44 +02:00
|
|
|
for(i = 0; i < MAX_STREAMS; i++) {
|
|
|
|
if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
|
|
|
|
if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
|
|
|
|
if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
|
|
|
|
This->streamSource[i] = targetStateBlock->streamSource[i];
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 18:56:10 +02:00
|
|
|
if(This->vertexShader != targetStateBlock->vertexShader) {
|
|
|
|
if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
|
|
|
|
if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
|
|
|
|
This->vertexShader = targetStateBlock->vertexShader;
|
|
|
|
}
|
|
|
|
if(This->pixelShader != targetStateBlock->pixelShader) {
|
|
|
|
if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
|
|
|
|
if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
|
|
|
|
This->pixelShader = targetStateBlock->pixelShader;
|
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
} else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
|
|
|
|
memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
|
|
|
|
memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
|
|
|
|
memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
|
|
|
|
record_lights(This, targetStateBlock);
|
|
|
|
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
|
|
|
|
This->renderState[SavedVertexStates_R[i]] = targetStateBlock->renderState[SavedVertexStates_R[i]];
|
|
|
|
}
|
|
|
|
for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
|
|
|
|
for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
|
|
|
|
This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j = 0; j < MAX_TEXTURES; j++) {
|
|
|
|
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
|
|
|
|
This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
|
|
|
|
}
|
|
|
|
}
|
2007-08-19 20:40:44 +02:00
|
|
|
for(i = 0; i < MAX_STREAMS; i++) {
|
|
|
|
if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
|
|
|
|
if(targetStateBlock->streamSource[i]) IWineD3DVertexBuffer_AddRef(targetStateBlock->streamSource[i]);
|
|
|
|
if(This->streamSource[i]) IWineD3DVertexBuffer_Release(This->streamSource[i]);
|
|
|
|
This->streamSource[i] = targetStateBlock->streamSource[i];
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 18:56:10 +02:00
|
|
|
if(This->vertexShader != targetStateBlock->vertexShader) {
|
|
|
|
if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
|
|
|
|
if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
|
|
|
|
This->vertexShader = targetStateBlock->vertexShader;
|
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
} else if(This->blockType == WINED3DSBT_PIXELSTATE) {
|
|
|
|
memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
|
|
|
|
memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
|
|
|
|
memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
|
|
|
|
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
|
|
|
|
This->renderState[SavedPixelStates_R[i]] = targetStateBlock->renderState[SavedPixelStates_R[i]];
|
|
|
|
}
|
|
|
|
for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
|
|
|
|
for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
|
|
|
|
This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j = 0; j < MAX_TEXTURES; j++) {
|
|
|
|
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
|
|
|
|
This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 18:56:10 +02:00
|
|
|
if(This->pixelShader != targetStateBlock->pixelShader) {
|
|
|
|
if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
|
|
|
|
if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
|
|
|
|
This->pixelShader = targetStateBlock->pixelShader;
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock, This);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
static inline void apply_lights(IWineD3DDevice *pDevice, IWineD3DStateBlockImpl *This) {
|
|
|
|
UINT i;
|
|
|
|
for(i = 0; i < LIGHTMAP_SIZE; i++) {
|
|
|
|
struct list *e;
|
|
|
|
|
|
|
|
LIST_FOR_EACH(e, &This->lightMap[i]) {
|
2008-12-01 15:32:15 +01:00
|
|
|
const PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
|
|
|
if(light->changed) {
|
|
|
|
IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
|
|
|
|
}
|
|
|
|
if(light->enabledChanged) {
|
|
|
|
IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface){
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
|
|
|
IWineD3DDevice* pDevice = (IWineD3DDevice*)This->wineD3DDevice;
|
|
|
|
|
|
|
|
/*Copy thing over to updateBlock is isRecording otherwise StateBlock,
|
|
|
|
should really perform a delta so that only the changes get updated*/
|
|
|
|
|
|
|
|
UINT i;
|
|
|
|
UINT j;
|
|
|
|
|
|
|
|
TRACE("(%p) : Applying state block %p ------------------v\n", This, pDevice);
|
|
|
|
|
2007-08-09 17:45:29 +02:00
|
|
|
TRACE("Blocktype: %d\n", This->blockType);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
if(This->blockType == WINED3DSBT_RECORDED) {
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.vertexShader) {
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
|
2005-09-21 12:19:29 +02:00
|
|
|
}
|
|
|
|
/* Vertex Shader Constants */
|
2007-08-03 20:26:29 +02:00
|
|
|
for (i = 0; i < This->num_contained_vs_consts_f; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
|
|
|
|
This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:07:30 +02:00
|
|
|
for (i = 0; i < This->num_contained_vs_consts_i; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
|
|
|
|
This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:07:30 +02:00
|
|
|
for (i = 0; i < This->num_contained_vs_consts_b; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
|
|
|
|
This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
|
2006-06-06 08:46:59 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
apply_lights(pDevice, This);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.pixelShader) {
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
|
2005-09-28 12:13:00 +02:00
|
|
|
}
|
|
|
|
/* Pixel Shader Constants */
|
2007-08-03 20:26:29 +02:00
|
|
|
for (i = 0; i < This->num_contained_ps_consts_f; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
|
|
|
|
This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
for (i = 0; i < This->num_contained_ps_consts_i; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
|
|
|
|
This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
|
2006-07-19 06:06:07 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
for (i = 0; i < This->num_contained_ps_consts_b; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
|
|
|
|
This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
|
2005-09-28 12:13:00 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
/* Render */
|
|
|
|
for (i = 0; i <= This->num_contained_render_states; i++) {
|
|
|
|
IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
|
|
|
|
This->renderState[This->contained_render_states[i]]);
|
|
|
|
}
|
|
|
|
/* Texture states */
|
|
|
|
for (i = 0; i < This->num_contained_tss_states; i++) {
|
|
|
|
DWORD stage = This->contained_tss_states[i].stage;
|
|
|
|
DWORD state = This->contained_tss_states[i].state;
|
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state] = This->textureState[stage][state];
|
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.textureState[stage][state] = TRUE;
|
|
|
|
/* TODO: Record a display list to apply all gl states. For now apply by brute force */
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state));
|
|
|
|
}
|
|
|
|
/* Sampler states */
|
|
|
|
for (i = 0; i < This->num_contained_sampler_states; i++) {
|
|
|
|
DWORD stage = This->contained_sampler_states[i].stage;
|
|
|
|
DWORD state = This->contained_sampler_states[i].state;
|
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state];
|
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage][state] = TRUE;
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage));
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-07-31 15:44:13 +02:00
|
|
|
for (i = 0; i < This->num_contained_transform_states; i++) {
|
|
|
|
IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
|
|
|
|
&This->transforms[This->contained_transform_states[i]]);
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.indices) {
|
2007-06-05 18:52:21 +02:00
|
|
|
IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
|
|
|
|
IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
if (This->changed.vertexDecl) {
|
|
|
|
IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->changed.material ) {
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetMaterial(pDevice, &This->material);
|
2007-08-04 00:46:37 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
if (This->changed.viewport) {
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetViewport(pDevice, &This->viewport);
|
2007-08-04 00:46:37 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
if (This->changed.scissorRect) {
|
2007-01-10 11:28:42 +01:00
|
|
|
IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
|
2007-08-04 00:46:37 +02:00
|
|
|
}
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
/* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
|
|
|
|
for (i=0; i<MAX_STREAMS; i++) {
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.streamSource[i])
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
|
|
|
|
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.streamFreq[i])
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
|
|
|
|
}
|
2007-08-04 00:46:37 +02:00
|
|
|
for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
|
|
|
|
if (This->changed.textures[j]) {
|
|
|
|
if (j < MAX_FRAGMENT_SAMPLERS) {
|
|
|
|
IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
|
|
|
|
} else {
|
|
|
|
IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
for (i = 0; i < GL_LIMITS(clipplanes); i++) {
|
2007-07-30 19:28:33 +02:00
|
|
|
if (This->changed.clipplane[i]) {
|
2005-07-05 16:05:18 +02:00
|
|
|
float clip[4];
|
|
|
|
|
|
|
|
clip[0] = This->clipplane[i][0];
|
|
|
|
clip[1] = This->clipplane[i][1];
|
|
|
|
clip[2] = This->clipplane[i][2];
|
|
|
|
clip[3] = This->clipplane[i][3];
|
|
|
|
IWineD3DDevice_SetClipPlane(pDevice, i, clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
} else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
|
|
|
|
IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
|
|
|
|
for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
|
|
|
|
This->vertexShaderConstantF + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_I; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
|
|
|
|
This->vertexShaderConstantI + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_B; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
|
|
|
|
This->vertexShaderConstantB + i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_lights(pDevice, This);
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
|
|
|
|
IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
|
|
|
|
}
|
|
|
|
for(j = 0; j < MAX_TEXTURES; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
|
|
|
|
IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
|
|
|
|
This->textureState[j][SavedVertexStates_T[i]]);
|
2006-06-27 23:40:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
|
|
|
|
IWineD3DDevice_SetSamplerState(pDevice, j, SavedVertexStates_S[i],
|
|
|
|
This->samplerState[j][SavedVertexStates_S[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
|
|
|
|
IWineD3DDevice_SetSamplerState(pDevice,
|
|
|
|
WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
|
|
|
|
SavedVertexStates_S[i],
|
|
|
|
This->samplerState[j][SavedVertexStates_S[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(This->blockType == WINED3DSBT_PIXELSTATE) {
|
|
|
|
IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
|
|
|
|
for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
|
|
|
|
This->pixelShaderConstantF + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_I; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
|
|
|
|
This->pixelShaderConstantI + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_B; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
|
|
|
|
This->pixelShaderConstantB + i, 1);
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
|
|
|
|
IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
|
|
|
|
}
|
|
|
|
for(j = 0; j < MAX_TEXTURES; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
|
|
|
|
IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
|
|
|
|
This->textureState[j][SavedPixelStates_T[i]]);
|
|
|
|
}
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
|
|
|
|
IWineD3DDevice_SetSamplerState(pDevice, j, SavedPixelStates_S[i],
|
|
|
|
This->samplerState[j][SavedPixelStates_S[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
|
|
|
|
for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
|
|
|
|
IWineD3DDevice_SetSamplerState(pDevice,
|
|
|
|
WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
|
|
|
|
SavedPixelStates_S[i],
|
|
|
|
This->samplerState[j][SavedPixelStates_S[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(This->blockType == WINED3DSBT_ALL) {
|
|
|
|
IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
|
|
|
|
for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
|
|
|
|
This->vertexShaderConstantF + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_I; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
|
|
|
|
This->vertexShaderConstantI + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_B; i++) {
|
|
|
|
IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
|
|
|
|
This->vertexShaderConstantB + i, 1);
|
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2007-08-04 00:46:37 +02:00
|
|
|
IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
|
|
|
|
for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
|
|
|
|
This->pixelShaderConstantF + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_I; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
|
|
|
|
This->pixelShaderConstantI + i * 4, 1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_CONST_B; i++) {
|
|
|
|
IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
|
|
|
|
This->pixelShaderConstantB + i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_lights(pDevice, This);
|
|
|
|
|
|
|
|
for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
|
|
|
|
IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
|
|
|
|
}
|
|
|
|
for(j = 0; j < MAX_TEXTURES; j++) {
|
|
|
|
for(i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE; i++) {
|
|
|
|
IWineD3DDevice_SetTextureStageState(pDevice, j, i, This->textureState[j][i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip unused values between TEXTURE8 and WORLD0 ? */
|
|
|
|
for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
|
|
|
|
IWineD3DDevice_SetTransform(pDevice, i, &This->transforms[i]);
|
|
|
|
}
|
|
|
|
IWineD3DDevice_SetIndices(pDevice, This->pIndexData);
|
|
|
|
IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
|
|
|
|
IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
|
|
|
|
IWineD3DDevice_SetMaterial(pDevice, &This->material);
|
|
|
|
IWineD3DDevice_SetViewport(pDevice, &This->viewport);
|
|
|
|
IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
|
|
|
|
|
|
|
|
/* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
|
|
|
|
for (i=0; i<MAX_STREAMS; i++) {
|
|
|
|
IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
|
|
|
|
IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
|
|
|
|
}
|
|
|
|
for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
|
|
|
|
UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
|
|
|
|
|
|
|
|
IWineD3DDevice_SetTexture(pDevice, sampler, This->textures[j]);
|
|
|
|
for(i = 1; i < WINED3D_HIGHEST_SAMPLER_STATE; i++) {
|
|
|
|
IWineD3DDevice_SetSamplerState(pDevice, sampler, i, This->samplerState[j][i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < GL_LIMITS(clipplanes); i++) {
|
|
|
|
float clip[4];
|
|
|
|
|
|
|
|
clip[0] = This->clipplane[i][0];
|
|
|
|
clip[1] = This->clipplane[i][1];
|
|
|
|
clip[2] = This->clipplane[i][2];
|
|
|
|
clip[3] = This->clipplane[i][3];
|
|
|
|
IWineD3DDevice_SetClipPlane(pDevice, i, clip);
|
|
|
|
}
|
2007-08-03 20:23:52 +02:00
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2006-12-19 23:00:58 +01:00
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
|
|
|
|
for(j = 0; j < MAX_TEXTURES - 1; j++) {
|
2007-02-15 13:32:19 +01:00
|
|
|
if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
|
2006-12-19 23:00:58 +01:00
|
|
|
((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
TRACE("(%p) : Applied state block %p ------------------^\n", This, pDevice);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock* iface) {
|
2004-10-21 22:59:12 +02:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice *device = (IWineD3DDevice *)This->wineD3DDevice;
|
|
|
|
IWineD3DDeviceImpl *ThisDevice = (IWineD3DDeviceImpl *)device;
|
2004-12-13 14:35:38 +01:00
|
|
|
union {
|
2006-10-31 09:21:15 +01:00
|
|
|
WINED3DLINEPATTERN lp;
|
2004-12-13 14:35:38 +01:00
|
|
|
DWORD d;
|
|
|
|
} lp;
|
|
|
|
union {
|
|
|
|
float f;
|
|
|
|
DWORD d;
|
|
|
|
} tmpfloat;
|
|
|
|
unsigned int i;
|
2008-08-31 12:20:28 +02:00
|
|
|
IWineD3DSwapChain *swapchain;
|
|
|
|
IWineD3DSurface *backbuffer;
|
|
|
|
WINED3DSURFACE_DESC desc = {0};
|
|
|
|
UINT width, height;
|
|
|
|
RECT scissorrect;
|
|
|
|
HRESULT hr;
|
2004-10-21 22:59:12 +02:00
|
|
|
|
|
|
|
/* Note this may have a large overhead but it should only be executed
|
2005-07-13 16:15:54 +02:00
|
|
|
once, in order to initialize the complete state of the device and
|
2004-10-21 22:59:12 +02:00
|
|
|
all opengl equivalents */
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
|
2005-07-26 20:49:30 +02:00
|
|
|
/* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
|
|
|
|
This->blockType = WINED3DSBT_INIT;
|
2004-10-21 22:59:12 +02:00
|
|
|
|
2005-07-26 20:49:30 +02:00
|
|
|
/* Set some of the defaults for lights, transforms etc */
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(&This->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
|
|
|
|
memcpy(&This->transforms[WINED3DTS_VIEW], identity, sizeof(identity));
|
2004-12-13 14:35:38 +01:00
|
|
|
for (i = 0; i < 256; ++i) {
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(&This->transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity));
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
|
|
|
TRACE("Render states\n");
|
2004-12-13 14:35:38 +01:00
|
|
|
/* Render states: */
|
2007-11-10 00:19:19 +01:00
|
|
|
if (ThisDevice->auto_depth_stencil_buffer != NULL) {
|
2006-10-24 12:06:19 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_TRUE);
|
2004-12-13 14:35:38 +01:00
|
|
|
} else {
|
2006-10-24 12:06:19 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZENABLE, WINED3DZB_FALSE);
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
2006-10-30 03:43:51 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FILLMODE, WINED3DFILL_SOLID);
|
2006-10-30 03:42:47 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SHADEMODE, WINED3DSHADE_GOURAUD);
|
2005-07-05 16:05:18 +02:00
|
|
|
lp.lp.wRepeatFactor = 0;
|
|
|
|
lp.lp.wLinePattern = 0;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_LINEPATTERN, lp.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZWRITEENABLE, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHATESTENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_LASTPIXEL, TRUE);
|
2006-10-24 12:05:39 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLEND, WINED3DBLEND_ONE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLEND, WINED3DBLEND_ZERO);
|
2006-10-30 03:43:18 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CULLMODE, WINED3DCULL_CCW);
|
2006-10-30 03:44:58 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZFUNC, WINED3DCMP_LESSEQUAL);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAFUNC, WINED3DCMP_ALWAYS);
|
2006-07-21 05:05:22 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHAREF, 0);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DITHERENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ALPHABLENDENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZVISIBLE, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGCOLOR, 0);
|
2006-10-30 03:41:42 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGTABLEMODE, WINED3DFOG_NONE);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGSTART, tmpfloat.d);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGEND, tmpfloat.d);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGDENSITY, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_EDGEANTIALIAS, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ZBIAS, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_RANGEFOGENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILENABLE, FALSE);
|
2006-10-30 03:44:22 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFAIL, WINED3DSTENCILOP_KEEP);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILPASS, WINED3DSTENCILOP_KEEP);
|
2007-07-30 18:46:20 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILREF, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILMASK, 0xFFFFFFFF);
|
2006-10-30 03:44:58 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILFUNC, WINED3DCMP_ALWAYS);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP0, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP1, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP2, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP3, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP4, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP5, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP6, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP7, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPING, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_LIGHTING, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENT, 0);
|
2006-10-30 03:41:42 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_FOGVERTEXMODE, WINED3DFOG_NONE);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORVERTEX, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_LOCALVIEWER, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALIZENORMALS, FALSE);
|
2006-10-30 03:45:23 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DIFFUSEMATERIALSOURCE, WINED3DMCS_COLOR1);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SPECULARMATERIALSOURCE, WINED3DMCS_COLOR2);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_AMBIENTMATERIALSOURCE, WINED3DMCS_MATERIAL);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_EMISSIVEMATERIALSOURCE, WINED3DMCS_MATERIAL);
|
2006-10-13 05:33:44 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_VERTEXBLEND, WINED3DVBF_DISABLE);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CLIPPLANEENABLE, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE, tmpfloat.d);
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALEENABLE, FALSE);
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_A, tmpfloat.d);
|
|
|
|
tmpfloat.f = 0.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_B, tmpfloat.d);
|
|
|
|
tmpfloat.f = 0.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALE_C, tmpfloat.d);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEANTIALIAS, TRUE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
|
2006-10-31 09:20:48 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHEDGESTYLE, WINED3DPATCHEDGE_DISCRETE);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHSEGMENTS, tmpfloat.d);
|
2006-07-21 05:05:22 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DEBUGMONITORTOKEN, 0xbaadcafe);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 64.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MAX, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE, 0x0000000F);
|
|
|
|
tmpfloat.f = 0.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_TWEENFACTOR, tmpfloat.d);
|
2006-10-30 03:42:14 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOP, WINED3DBLENDOP_ADD);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_POSITIONDEGREE, WINED3DDEGREE_CUBIC);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_NORMALDEGREE, WINED3DDEGREE_LINEAR);
|
|
|
|
/* states new in d3d9 */
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SCISSORTESTENABLE, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SLOPESCALEDEPTHBIAS, 0);
|
|
|
|
tmpfloat.f = 1.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_MINTESSELLATIONLEVEL, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_MAXTESSELLATIONLEVEL, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ANTIALIASEDLINEENABLE, FALSE);
|
|
|
|
tmpfloat.f = 0.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_X, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Y, tmpfloat.d);
|
|
|
|
tmpfloat.f = 1.0f;
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_Z, tmpfloat.d);
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ADAPTIVETESS_W, tmpfloat.d);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_ENABLEADAPTIVETESSELLATION, FALSE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_TWOSIDEDSTENCILMODE, FALSE);
|
2006-10-30 03:44:22 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFAIL, WINED3DSTENCILOP_KEEP);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILZFAIL, WINED3DSTENCILOP_KEEP);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILPASS, WINED3DSTENCILOP_KEEP);
|
2006-10-30 03:44:58 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_CCW_STENCILFUNC, WINED3DCMP_ALWAYS);
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE1, 0x0000000F);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE2, 0x0000000F);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_COLORWRITEENABLE3, 0x0000000F);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDFACTOR, 0xFFFFFFFF);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SRGBWRITEENABLE, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DEPTHBIAS, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP8, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP9, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP10, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP11, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP12, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP13, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP14, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_WRAP15, 0);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SEPARATEALPHABLENDENABLE, FALSE);
|
2006-10-24 12:05:39 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_SRCBLENDALPHA, WINED3DBLEND_ONE);
|
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_DESTBLENDALPHA, WINED3DBLEND_ZERO);
|
2006-10-30 03:42:14 +01:00
|
|
|
IWineD3DDevice_SetRenderState(device, WINED3DRS_BLENDOPALPHA, WINED3DBLENDOP_ADD);
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
/* clipping status */
|
2004-12-13 14:35:38 +01:00
|
|
|
This->clip_status.ClipUnion = 0;
|
|
|
|
This->clip_status.ClipIntersection = 0xFFFFFFFF;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2004-12-13 14:35:38 +01:00
|
|
|
/* Texture Stage States - Put directly into state block, we will call function below */
|
2007-06-22 00:02:12 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES; i++) {
|
2004-12-13 14:35:38 +01:00
|
|
|
TRACE("Setting up default texture states for texture Stage %d\n", i);
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(&This->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
|
2006-10-13 05:33:03 +02:00
|
|
|
This->textureState[i][WINED3DTSS_COLOROP ] = (i==0)? WINED3DTOP_MODULATE : WINED3DTOP_DISABLE;
|
2006-10-24 12:05:00 +02:00
|
|
|
This->textureState[i][WINED3DTSS_COLORARG1 ] = WINED3DTA_TEXTURE;
|
|
|
|
This->textureState[i][WINED3DTSS_COLORARG2 ] = WINED3DTA_CURRENT;
|
2006-10-13 05:33:03 +02:00
|
|
|
This->textureState[i][WINED3DTSS_ALPHAOP ] = (i==0)? WINED3DTOP_SELECTARG1 : WINED3DTOP_DISABLE;
|
2006-10-24 12:05:00 +02:00
|
|
|
This->textureState[i][WINED3DTSS_ALPHAARG1 ] = WINED3DTA_TEXTURE;
|
|
|
|
This->textureState[i][WINED3DTSS_ALPHAARG2 ] = WINED3DTA_CURRENT;
|
2008-11-03 22:34:44 +01:00
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVMAT00 ] = 0;
|
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVMAT01 ] = 0;
|
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVMAT10 ] = 0;
|
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVMAT11 ] = 0;
|
2006-10-11 03:52:50 +02:00
|
|
|
This->textureState[i][WINED3DTSS_TEXCOORDINDEX ] = i;
|
2008-11-03 22:34:44 +01:00
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVLSCALE ] = 0;
|
|
|
|
This->textureState[i][WINED3DTSS_BUMPENVLOFFSET ] = 0;
|
2006-10-13 05:36:09 +02:00
|
|
|
This->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS ] = WINED3DTTFF_DISABLE;
|
2006-10-24 12:03:18 +02:00
|
|
|
This->textureState[i][WINED3DTSS_ADDRESSW ] = WINED3DTADDRESS_WRAP;
|
2006-10-24 12:05:00 +02:00
|
|
|
This->textureState[i][WINED3DTSS_COLORARG0 ] = WINED3DTA_CURRENT;
|
|
|
|
This->textureState[i][WINED3DTSS_ALPHAARG0 ] = WINED3DTA_CURRENT;
|
|
|
|
This->textureState[i][WINED3DTSS_RESULTARG ] = WINED3DTA_CURRENT;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
2006-12-19 23:00:58 +01:00
|
|
|
This->lowest_disabled_stage = 1;
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
/* Sampler states*/
|
2007-06-25 22:45:40 +02:00
|
|
|
for (i = 0 ; i < MAX_COMBINED_SAMPLERS; i++) {
|
2005-07-13 16:15:54 +02:00
|
|
|
TRACE("Setting up default samplers states for sampler %d\n", i);
|
2006-10-24 12:03:18 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_ADDRESSU ] = WINED3DTADDRESS_WRAP;
|
|
|
|
This->samplerState[i][WINED3DSAMP_ADDRESSV ] = WINED3DTADDRESS_WRAP;
|
|
|
|
This->samplerState[i][WINED3DSAMP_ADDRESSW ] = WINED3DTADDRESS_WRAP;
|
2005-07-05 16:05:18 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_BORDERCOLOR ] = 0x00;
|
2006-04-06 19:02:16 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_MAGFILTER ] = WINED3DTEXF_POINT;
|
|
|
|
This->samplerState[i][WINED3DSAMP_MINFILTER ] = WINED3DTEXF_POINT;
|
|
|
|
This->samplerState[i][WINED3DSAMP_MIPFILTER ] = WINED3DTEXF_NONE;
|
2005-07-05 16:05:18 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_MIPMAPLODBIAS ] = 0;
|
|
|
|
This->samplerState[i][WINED3DSAMP_MAXMIPLEVEL ] = 0;
|
|
|
|
This->samplerState[i][WINED3DSAMP_MAXANISOTROPY ] = 1;
|
2007-06-07 01:13:16 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_SRGBTEXTURE ] = 0;
|
2005-07-05 16:05:18 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_ELEMENTINDEX ] = 0; /* TODO: Indicates which element of a multielement texture to use */
|
2006-10-29 01:55:03 +02:00
|
|
|
This->samplerState[i][WINED3DSAMP_DMAPOFFSET ] = 0; /* TODO: Vertex offset in the presampled displacement map */
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2008-02-15 15:54:37 +01:00
|
|
|
for(i = 0; i < GL_LIMITS(textures); i++) {
|
2008-04-22 08:18:14 +02:00
|
|
|
/* Note: This avoids calling SetTexture, so pretend it has been called */
|
2006-12-19 22:37:37 +01:00
|
|
|
This->changed.textures[i] = TRUE;
|
|
|
|
This->textures[i] = NULL;
|
2007-05-25 14:15:45 +02:00
|
|
|
}
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2008-08-31 12:20:28 +02:00
|
|
|
/* Set the default scissor rect values */
|
|
|
|
desc.Width = &width;
|
|
|
|
desc.Height = &height;
|
|
|
|
|
|
|
|
/* check the return values, because the GetBackBuffer call isn't valid for ddraw */
|
|
|
|
hr = IWineD3DDevice_GetSwapChain(device, 0, &swapchain);
|
|
|
|
if( hr == WINED3D_OK && swapchain != NULL) {
|
2008-12-19 19:21:55 +01:00
|
|
|
WINED3DVIEWPORT vp;
|
|
|
|
|
2008-08-31 12:20:28 +02:00
|
|
|
hr = IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
|
|
|
|
if( hr == WINED3D_OK && backbuffer != NULL) {
|
|
|
|
IWineD3DSurface_GetDesc(backbuffer, &desc);
|
|
|
|
IWineD3DSurface_Release(backbuffer);
|
|
|
|
|
|
|
|
scissorrect.left = 0;
|
|
|
|
scissorrect.right = width;
|
|
|
|
scissorrect.top = 0;
|
|
|
|
scissorrect.bottom = height;
|
|
|
|
hr = IWineD3DDevice_SetScissorRect(device, &scissorrect);
|
|
|
|
if( hr != WINED3D_OK ) {
|
|
|
|
ERR("This should never happen, expect rendering issues!\n");
|
|
|
|
}
|
|
|
|
}
|
2008-12-19 19:21:55 +01:00
|
|
|
|
|
|
|
/* Set the default viewport */
|
|
|
|
vp.X = 0;
|
|
|
|
vp.Y = 0;
|
|
|
|
vp.Width = ((IWineD3DSwapChainImpl *)swapchain)->presentParms.BackBufferWidth;
|
|
|
|
vp.Height = ((IWineD3DSwapChainImpl *)swapchain)->presentParms.BackBufferHeight;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 1.0f;
|
|
|
|
IWineD3DDevice_SetViewport(device, &vp);
|
|
|
|
|
2008-08-31 12:20:28 +02:00
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
|
|
|
}
|
|
|
|
|
2004-10-21 22:59:12 +02:00
|
|
|
TRACE("-----------------------> Device defaults now set up...\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-10-21 22:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
* IWineD3DStateBlock VTbl follows
|
|
|
|
**********************************************************/
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
|
2004-10-21 22:59:12 +02:00
|
|
|
{
|
2005-07-13 16:15:54 +02:00
|
|
|
/* IUnknown */
|
2004-10-21 22:59:12 +02:00
|
|
|
IWineD3DStateBlockImpl_QueryInterface,
|
|
|
|
IWineD3DStateBlockImpl_AddRef,
|
|
|
|
IWineD3DStateBlockImpl_Release,
|
2005-07-13 16:15:54 +02:00
|
|
|
/* IWineD3DStateBlock */
|
2004-11-23 14:52:46 +01:00
|
|
|
IWineD3DStateBlockImpl_GetParent,
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DStateBlockImpl_GetDevice,
|
|
|
|
IWineD3DStateBlockImpl_Capture,
|
|
|
|
IWineD3DStateBlockImpl_Apply,
|
2004-10-21 22:59:12 +02:00
|
|
|
IWineD3DStateBlockImpl_InitStartupStateBlock
|
|
|
|
};
|