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
|
2009-09-28 10:04:59 +02:00
|
|
|
* Copyright 2009 Henri Verbeet 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);
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD pixel_states_render[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
|
|
|
WINED3DRS_ALPHABLENDENABLE,
|
|
|
|
WINED3DRS_ALPHAFUNC,
|
|
|
|
WINED3DRS_ALPHAREF,
|
|
|
|
WINED3DRS_ALPHATESTENABLE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_ANTIALIASEDLINEENABLE,
|
|
|
|
WINED3DRS_BLENDFACTOR,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_BLENDOP,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_BLENDOPALPHA,
|
|
|
|
WINED3DRS_CCW_STENCILFAIL,
|
|
|
|
WINED3DRS_CCW_STENCILPASS,
|
|
|
|
WINED3DRS_CCW_STENCILZFAIL,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_COLORWRITEENABLE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_COLORWRITEENABLE1,
|
|
|
|
WINED3DRS_COLORWRITEENABLE2,
|
|
|
|
WINED3DRS_COLORWRITEENABLE3,
|
|
|
|
WINED3DRS_DEPTHBIAS,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_DESTBLEND,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_DESTBLENDALPHA,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_DITHERENABLE,
|
|
|
|
WINED3DRS_FILLMODE,
|
|
|
|
WINED3DRS_FOGDENSITY,
|
|
|
|
WINED3DRS_FOGEND,
|
|
|
|
WINED3DRS_FOGSTART,
|
|
|
|
WINED3DRS_LASTPIXEL,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_SCISSORTESTENABLE,
|
|
|
|
WINED3DRS_SEPARATEALPHABLENDENABLE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_SHADEMODE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_SLOPESCALEDEPTHBIAS,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_SRCBLEND,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_SRCBLENDALPHA,
|
|
|
|
WINED3DRS_SRGBWRITEENABLE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_STENCILENABLE,
|
|
|
|
WINED3DRS_STENCILFAIL,
|
|
|
|
WINED3DRS_STENCILFUNC,
|
|
|
|
WINED3DRS_STENCILMASK,
|
|
|
|
WINED3DRS_STENCILPASS,
|
|
|
|
WINED3DRS_STENCILREF,
|
|
|
|
WINED3DRS_STENCILWRITEMASK,
|
|
|
|
WINED3DRS_STENCILZFAIL,
|
|
|
|
WINED3DRS_TEXTUREFACTOR,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_TWOSIDEDSTENCILMODE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_WRAP0,
|
|
|
|
WINED3DRS_WRAP1,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_WRAP10,
|
|
|
|
WINED3DRS_WRAP11,
|
|
|
|
WINED3DRS_WRAP12,
|
|
|
|
WINED3DRS_WRAP13,
|
|
|
|
WINED3DRS_WRAP14,
|
|
|
|
WINED3DRS_WRAP15,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_WRAP2,
|
|
|
|
WINED3DRS_WRAP3,
|
|
|
|
WINED3DRS_WRAP4,
|
|
|
|
WINED3DRS_WRAP5,
|
|
|
|
WINED3DRS_WRAP6,
|
|
|
|
WINED3DRS_WRAP7,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_WRAP8,
|
|
|
|
WINED3DRS_WRAP9,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_ZENABLE,
|
|
|
|
WINED3DRS_ZFUNC,
|
|
|
|
WINED3DRS_ZWRITEENABLE,
|
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD pixel_states_texture[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
|
|
|
WINED3DTSS_ALPHAARG0,
|
|
|
|
WINED3DTSS_ALPHAARG1,
|
|
|
|
WINED3DTSS_ALPHAARG2,
|
|
|
|
WINED3DTSS_ALPHAOP,
|
|
|
|
WINED3DTSS_BUMPENVLOFFSET,
|
|
|
|
WINED3DTSS_BUMPENVLSCALE,
|
|
|
|
WINED3DTSS_BUMPENVMAT00,
|
|
|
|
WINED3DTSS_BUMPENVMAT01,
|
|
|
|
WINED3DTSS_BUMPENVMAT10,
|
|
|
|
WINED3DTSS_BUMPENVMAT11,
|
|
|
|
WINED3DTSS_COLORARG0,
|
|
|
|
WINED3DTSS_COLORARG1,
|
|
|
|
WINED3DTSS_COLORARG2,
|
|
|
|
WINED3DTSS_COLOROP,
|
|
|
|
WINED3DTSS_RESULTARG,
|
|
|
|
WINED3DTSS_TEXCOORDINDEX,
|
|
|
|
WINED3DTSS_TEXTURETRANSFORMFLAGS,
|
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD pixel_states_sampler[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
|
|
|
WINED3DSAMP_ADDRESSU,
|
|
|
|
WINED3DSAMP_ADDRESSV,
|
|
|
|
WINED3DSAMP_ADDRESSW,
|
|
|
|
WINED3DSAMP_BORDERCOLOR,
|
|
|
|
WINED3DSAMP_MAGFILTER,
|
|
|
|
WINED3DSAMP_MINFILTER,
|
|
|
|
WINED3DSAMP_MIPFILTER,
|
|
|
|
WINED3DSAMP_MIPMAPLODBIAS,
|
|
|
|
WINED3DSAMP_MAXMIPLEVEL,
|
|
|
|
WINED3DSAMP_MAXANISOTROPY,
|
|
|
|
WINED3DSAMP_SRGBTEXTURE,
|
|
|
|
WINED3DSAMP_ELEMENTINDEX,
|
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_render[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_ADAPTIVETESS_W,
|
|
|
|
WINED3DRS_ADAPTIVETESS_X,
|
|
|
|
WINED3DRS_ADAPTIVETESS_Y,
|
|
|
|
WINED3DRS_ADAPTIVETESS_Z,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_AMBIENT,
|
|
|
|
WINED3DRS_AMBIENTMATERIALSOURCE,
|
|
|
|
WINED3DRS_CLIPPING,
|
|
|
|
WINED3DRS_CLIPPLANEENABLE,
|
|
|
|
WINED3DRS_COLORVERTEX,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_CULLMODE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_DIFFUSEMATERIALSOURCE,
|
|
|
|
WINED3DRS_EMISSIVEMATERIALSOURCE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_ENABLEADAPTIVETESSELLATION,
|
|
|
|
WINED3DRS_FOGCOLOR,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_FOGDENSITY,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_FOGENABLE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_FOGEND,
|
|
|
|
WINED3DRS_FOGSTART,
|
|
|
|
WINED3DRS_FOGTABLEMODE,
|
|
|
|
WINED3DRS_FOGVERTEXMODE,
|
|
|
|
WINED3DRS_INDEXEDVERTEXBLENDENABLE,
|
|
|
|
WINED3DRS_LIGHTING,
|
|
|
|
WINED3DRS_LOCALVIEWER,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_MAXTESSELLATIONLEVEL,
|
|
|
|
WINED3DRS_MINTESSELLATIONLEVEL,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_MULTISAMPLEANTIALIAS,
|
|
|
|
WINED3DRS_MULTISAMPLEMASK,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_NORMALDEGREE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_NORMALIZENORMALS,
|
|
|
|
WINED3DRS_PATCHEDGESTYLE,
|
|
|
|
WINED3DRS_POINTSCALE_A,
|
|
|
|
WINED3DRS_POINTSCALE_B,
|
|
|
|
WINED3DRS_POINTSCALE_C,
|
|
|
|
WINED3DRS_POINTSCALEENABLE,
|
|
|
|
WINED3DRS_POINTSIZE,
|
|
|
|
WINED3DRS_POINTSIZE_MAX,
|
|
|
|
WINED3DRS_POINTSIZE_MIN,
|
|
|
|
WINED3DRS_POINTSPRITEENABLE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_POSITIONDEGREE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_RANGEFOGENABLE,
|
2009-10-09 09:58:47 +02:00
|
|
|
WINED3DRS_SHADEMODE,
|
|
|
|
WINED3DRS_SPECULARENABLE,
|
2009-10-02 11:16:12 +02:00
|
|
|
WINED3DRS_SPECULARMATERIALSOURCE,
|
|
|
|
WINED3DRS_TWEENFACTOR,
|
|
|
|
WINED3DRS_VERTEXBLEND,
|
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_texture[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
|
|
|
WINED3DTSS_TEXCOORDINDEX,
|
|
|
|
WINED3DTSS_TEXTURETRANSFORMFLAGS,
|
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_sampler[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
|
|
|
WINED3DSAMP_DMAPOFFSET,
|
|
|
|
};
|
2006-07-19 06:06:07 +02:00
|
|
|
|
2009-08-27 10:04:56 +02:00
|
|
|
/* Allocates the correct amount of space for pixel and vertex shader constants,
|
2006-07-19 06:06:07 +02:00
|
|
|
* along with their set/changed flags on the given stateblock object
|
|
|
|
*/
|
2009-09-29 11:09:04 +02:00
|
|
|
static HRESULT stateblock_allocate_shader_constants(IWineD3DStateBlockImpl *object)
|
2009-08-27 10:04:56 +02:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = object->device;
|
2006-07-19 06:06:07 +02:00
|
|
|
|
|
|
|
/* Allocate space for floating point constants */
|
2010-09-20 12:04:30 +02:00
|
|
|
object->state.ps_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(float) * device->d3d_pshader_constantF * 4);
|
2010-09-20 12:04:30 +02:00
|
|
|
if (!object->state.ps_consts_f) goto fail;
|
2008-12-12 09:33:52 +01:00
|
|
|
|
2009-10-22 10:09:54 +02:00
|
|
|
object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(BOOL) * device->d3d_pshader_constantF);
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->changed.pixelShaderConstantsF) goto fail;
|
|
|
|
|
2010-09-20 12:04:28 +02:00
|
|
|
object->state.vs_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(float) * device->d3d_vshader_constantF * 4);
|
2010-09-20 12:04:28 +02:00
|
|
|
if (!object->state.vs_consts_f) goto fail;
|
2008-12-12 09:33:52 +01:00
|
|
|
|
2009-10-22 10:09:54 +02:00
|
|
|
object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(BOOL) * device->d3d_vshader_constantF);
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->changed.vertexShaderConstantsF) goto fail;
|
|
|
|
|
2009-10-22 10:09:54 +02:00
|
|
|
object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(DWORD) * device->d3d_vshader_constantF);
|
2008-12-12 09:33:52 +01:00
|
|
|
if (!object->contained_vs_consts_f) goto fail;
|
|
|
|
|
2009-10-22 10:09:54 +02:00
|
|
|
object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0,
|
2009-10-25 01:23:34 +02:00
|
|
|
sizeof(DWORD) * device->d3d_pshader_constantF);
|
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");
|
2010-09-20 12:04:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object->state.ps_consts_f);
|
2008-12-12 09:33:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
|
2010-09-20 12:04:28 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object->state.vs_consts_f);
|
2008-12-12 09:33:52 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-01-05 10:10:16 +01:00
|
|
|
static inline void stateblock_set_bits(DWORD *map, UINT map_size)
|
|
|
|
{
|
|
|
|
DWORD mask = (1 << (map_size & 0x1f)) - 1;
|
|
|
|
memset(map, 0xff, (map_size >> 5) * sizeof(*map));
|
|
|
|
if (mask) map[map_size >> 5] = mask;
|
|
|
|
}
|
|
|
|
|
2009-09-30 10:49:09 +02:00
|
|
|
/* Set all members of a stateblock savedstate to the given value */
|
2009-10-25 01:23:34 +02:00
|
|
|
static void stateblock_savedstates_set_all(SAVEDSTATES *states, DWORD vs_consts, DWORD ps_consts)
|
2009-08-27 10:04:56 +02:00
|
|
|
{
|
2009-10-01 11:36:07 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2006-07-23 21:08:27 +02:00
|
|
|
/* Single values */
|
2009-10-01 11:36:07 +02:00
|
|
|
states->primitive_type = 1;
|
|
|
|
states->indices = 1;
|
|
|
|
states->material = 1;
|
|
|
|
states->viewport = 1;
|
|
|
|
states->vertexDecl = 1;
|
|
|
|
states->pixelShader = 1;
|
|
|
|
states->vertexShader = 1;
|
|
|
|
states->scissorRect = 1;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Fixed size arrays */
|
2009-10-01 11:36:07 +02:00
|
|
|
states->streamSource = 0xffff;
|
|
|
|
states->streamFreq = 0xffff;
|
|
|
|
states->textures = 0xfffff;
|
|
|
|
stateblock_set_bits(states->transform, HIGHEST_TRANSFORMSTATE + 1);
|
|
|
|
stateblock_set_bits(states->renderState, WINEHIGHEST_RENDER_STATE + 1);
|
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = 0x3ffff;
|
2010-06-02 11:24:54 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = 0x3ffe;
|
2009-10-01 11:36:07 +02:00
|
|
|
states->clipplane = 0xffffffff;
|
|
|
|
states->pixelShaderConstantsB = 0xffff;
|
|
|
|
states->pixelShaderConstantsI = 0xffff;
|
|
|
|
states->vertexShaderConstantsB = 0xffff;
|
|
|
|
states->vertexShaderConstantsI = 0xffff;
|
2006-07-23 21:08:27 +02:00
|
|
|
|
|
|
|
/* Dynamically sized arrays */
|
2009-10-25 01:23:34 +02:00
|
|
|
memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * ps_consts);
|
|
|
|
memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * vs_consts);
|
2006-07-23 21:08:27 +02:00
|
|
|
}
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
static void stateblock_savedstates_set_pixel(SAVEDSTATES *states, const DWORD num_constants)
|
2009-10-01 11:36:09 +02:00
|
|
|
{
|
|
|
|
DWORD texture_mask = 0;
|
|
|
|
WORD sampler_mask = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
states->pixelShader = 1;
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(pixel_states_render) / sizeof(*pixel_states_render); ++i)
|
2009-10-01 11:36:09 +02:00
|
|
|
{
|
2009-10-02 11:16:12 +02:00
|
|
|
DWORD rs = pixel_states_render[i];
|
2009-10-01 11:36:09 +02:00
|
|
|
states->renderState[rs >> 5] |= 1 << (rs & 0x1f);
|
|
|
|
}
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(pixel_states_texture) / sizeof(*pixel_states_texture); ++i)
|
|
|
|
texture_mask |= 1 << pixel_states_texture[i];
|
2009-10-01 11:36:09 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask;
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(pixel_states_sampler) / sizeof(*pixel_states_sampler); ++i)
|
|
|
|
sampler_mask |= 1 << pixel_states_sampler[i];
|
2009-10-01 11:36:09 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask;
|
|
|
|
states->pixelShaderConstantsB = 0xffff;
|
|
|
|
states->pixelShaderConstantsI = 0xffff;
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
|
2009-10-01 11:36:09 +02:00
|
|
|
}
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
static void stateblock_savedstates_set_vertex(SAVEDSTATES *states, const DWORD num_constants)
|
2009-10-02 11:16:09 +02:00
|
|
|
{
|
|
|
|
DWORD texture_mask = 0;
|
|
|
|
WORD sampler_mask = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
2009-10-13 10:38:00 +02:00
|
|
|
states->vertexDecl = 1;
|
2009-10-02 11:16:09 +02:00
|
|
|
states->vertexShader = 1;
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(vertex_states_render) / sizeof(*vertex_states_render); ++i)
|
2009-10-02 11:16:09 +02:00
|
|
|
{
|
2009-10-02 11:16:12 +02:00
|
|
|
DWORD rs = vertex_states_render[i];
|
2009-10-02 11:16:09 +02:00
|
|
|
states->renderState[rs >> 5] |= 1 << (rs & 0x1f);
|
|
|
|
}
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(vertex_states_texture) / sizeof(*vertex_states_texture); ++i)
|
|
|
|
texture_mask |= 1 << vertex_states_texture[i];
|
2009-10-02 11:16:09 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask;
|
2009-10-02 11:16:13 +02:00
|
|
|
for (i = 0; i < sizeof(vertex_states_sampler) / sizeof(*vertex_states_sampler); ++i)
|
|
|
|
sampler_mask |= 1 << vertex_states_sampler[i];
|
2009-10-02 11:16:09 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask;
|
|
|
|
states->vertexShaderConstantsB = 0xffff;
|
|
|
|
states->vertexShaderConstantsI = 0xffff;
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
|
2009-10-02 11:16:09 +02:00
|
|
|
}
|
|
|
|
|
2009-09-30 10:49:13 +02:00
|
|
|
void stateblock_init_contained_states(IWineD3DStateBlockImpl *stateblock)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = stateblock->device;
|
2009-09-30 10:49:13 +02:00
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i <= WINEHIGHEST_RENDER_STATE >> 5; ++i)
|
|
|
|
{
|
|
|
|
DWORD map = stateblock->changed.renderState[i];
|
|
|
|
for (j = 0; map; map >>= 1, ++j)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
|
|
|
stateblock->contained_render_states[stateblock->num_contained_render_states] = (i << 5) | j;
|
|
|
|
++stateblock->num_contained_render_states;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= HIGHEST_TRANSFORMSTATE >> 5; ++i)
|
|
|
|
{
|
|
|
|
DWORD map = stateblock->changed.transform[i];
|
|
|
|
for (j = 0; map; map >>= 1, ++j)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
|
|
|
stateblock->contained_transform_states[stateblock->num_contained_transform_states] = (i << 5) | j;
|
|
|
|
++stateblock->num_contained_transform_states;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
for (i = 0; i < device->d3d_vshader_constantF; ++i)
|
2009-09-30 10:49:13 +02:00
|
|
|
{
|
|
|
|
if (stateblock->changed.vertexShaderConstantsF[i])
|
|
|
|
{
|
|
|
|
stateblock->contained_vs_consts_f[stateblock->num_contained_vs_consts_f] = i;
|
|
|
|
++stateblock->num_contained_vs_consts_f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CONST_I; ++i)
|
|
|
|
{
|
|
|
|
if (stateblock->changed.vertexShaderConstantsI & (1 << i))
|
|
|
|
{
|
|
|
|
stateblock->contained_vs_consts_i[stateblock->num_contained_vs_consts_i] = i;
|
|
|
|
++stateblock->num_contained_vs_consts_i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CONST_B; ++i)
|
|
|
|
{
|
|
|
|
if (stateblock->changed.vertexShaderConstantsB & (1 << i))
|
|
|
|
{
|
|
|
|
stateblock->contained_vs_consts_b[stateblock->num_contained_vs_consts_b] = i;
|
|
|
|
++stateblock->num_contained_vs_consts_b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 01:23:34 +02:00
|
|
|
for (i = 0; i < device->d3d_pshader_constantF; ++i)
|
2009-09-30 10:49:13 +02:00
|
|
|
{
|
|
|
|
if (stateblock->changed.pixelShaderConstantsF[i])
|
|
|
|
{
|
|
|
|
stateblock->contained_ps_consts_f[stateblock->num_contained_ps_consts_f] = i;
|
|
|
|
++stateblock->num_contained_ps_consts_f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CONST_I; ++i)
|
|
|
|
{
|
|
|
|
if (stateblock->changed.pixelShaderConstantsI & (1 << i))
|
|
|
|
{
|
|
|
|
stateblock->contained_ps_consts_i[stateblock->num_contained_ps_consts_i] = i;
|
|
|
|
++stateblock->num_contained_ps_consts_i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CONST_B; ++i)
|
|
|
|
{
|
|
|
|
if (stateblock->changed.pixelShaderConstantsB & (1 << i))
|
|
|
|
{
|
|
|
|
stateblock->contained_ps_consts_b[stateblock->num_contained_ps_consts_b] = i;
|
|
|
|
++stateblock->num_contained_ps_consts_b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i)
|
|
|
|
{
|
|
|
|
DWORD map = stateblock->changed.textureState[i];
|
|
|
|
|
|
|
|
for(j = 0; map; map >>= 1, ++j)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
|
|
|
stateblock->contained_tss_states[stateblock->num_contained_tss_states].stage = i;
|
|
|
|
stateblock->contained_tss_states[stateblock->num_contained_tss_states].state = j;
|
|
|
|
++stateblock->num_contained_tss_states;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
|
|
|
DWORD map = stateblock->changed.samplerState[i];
|
|
|
|
|
|
|
|
for (j = 0; map; map >>= 1, ++j)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
|
|
|
stateblock->contained_sampler_states[stateblock->num_contained_sampler_states].stage = i;
|
|
|
|
stateblock->contained_sampler_states[stateblock->num_contained_sampler_states].state = j;
|
|
|
|
++stateblock->num_contained_sampler_states;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
static void stateblock_init_lights(IWineD3DStateBlockImpl *stateblock, struct list *light_map)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < LIGHTMAP_SIZE; ++i)
|
|
|
|
{
|
2009-10-14 10:55:16 +02:00
|
|
|
const struct wined3d_light_info *src_light;
|
2009-10-14 10:55:15 +02:00
|
|
|
|
2009-10-14 10:55:16 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(src_light, &light_map[i], struct wined3d_light_info, entry)
|
2009-10-14 10:55:15 +02:00
|
|
|
{
|
2009-10-14 10:55:16 +02:00
|
|
|
struct wined3d_light_info *dst_light = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_light));
|
2009-10-14 10:55:15 +02:00
|
|
|
|
|
|
|
*dst_light = *src_light;
|
2010-09-21 21:20:54 +02:00
|
|
|
list_add_tail(&stateblock->state.light_map[i], &dst_light->entry);
|
2009-10-14 10:55:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2009-12-17 19:14:36 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DStateBlock))
|
|
|
|
{
|
2005-03-02 14:44:58 +01:00
|
|
|
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
|
|
|
|
2010-09-17 11:59:41 +02:00
|
|
|
if (This->state.vertex_declaration)
|
|
|
|
IWineD3DVertexDeclaration_Release((IWineD3DVertexDeclaration *)This->state.vertex_declaration);
|
2009-09-28 10:05:00 +02:00
|
|
|
|
2009-09-28 10:04:59 +02:00
|
|
|
for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++)
|
|
|
|
{
|
2010-09-17 11:59:40 +02:00
|
|
|
if (This->state.textures[counter])
|
|
|
|
IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)This->state.textures[counter]);
|
2007-08-19 20:40:44 +02:00
|
|
|
}
|
2005-07-26 20:49:30 +02:00
|
|
|
|
2010-09-14 13:38:41 +02:00
|
|
|
for (counter = 0; counter < MAX_STREAMS; ++counter)
|
|
|
|
{
|
2010-09-20 19:41:22 +02:00
|
|
|
struct wined3d_buffer *buffer = This->state.streams[counter].buffer;
|
2010-09-14 13:38:41 +02:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
if (IWineD3DBuffer_Release((IWineD3DBuffer *)buffer))
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
WARN("Buffer %p still referenced by stateblock, stream %u.\n", buffer, counter);
|
2007-08-19 20:40:44 +02:00
|
|
|
}
|
|
|
|
}
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2010-09-20 19:41:23 +02:00
|
|
|
if (This->state.index_buffer) IWineD3DBuffer_Release((IWineD3DBuffer *)This->state.index_buffer);
|
2010-09-20 12:04:27 +02:00
|
|
|
if (This->state.vertex_shader) IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader);
|
2010-09-20 12:04:29 +02:00
|
|
|
if (This->state.pixel_shader) IWineD3DPixelShader_Release((IWineD3DPixelShader *)This->state.pixel_shader);
|
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;
|
2010-09-21 21:20:54 +02:00
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &This->state.light_map[counter])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
|
|
|
struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry);
|
2007-02-14 17:46:54 +01:00
|
|
|
list_remove(&light->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-20 12:04:28 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->state.vs_consts_f);
|
2006-08-19 17:23:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
|
2010-09-20 12:04:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->state.ps_consts_f);
|
2006-08-19 17:23:02 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-10-01 12:25:49 +02:00
|
|
|
static void wined3d_state_record_lights(struct wined3d_state *dst_state, const struct wined3d_state *src_state)
|
2009-09-30 10:49:10 +02:00
|
|
|
{
|
2007-08-04 14:44:33 +02:00
|
|
|
UINT i;
|
|
|
|
|
2010-10-01 12:25:49 +02:00
|
|
|
/* 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. */
|
2010-09-27 12:07:53 +02:00
|
|
|
for (i = 0; i < LIGHTMAP_SIZE; ++i)
|
|
|
|
{
|
2007-08-04 14:44:33 +02:00
|
|
|
struct list *e, *f;
|
2010-10-01 12:25:49 +02:00
|
|
|
LIST_FOR_EACH(e, &dst_state->light_map[i])
|
2010-09-21 21:20:54 +02:00
|
|
|
{
|
2007-08-04 14:44:33 +02:00
|
|
|
BOOL updated = FALSE;
|
2009-10-14 10:55:16 +02:00
|
|
|
struct wined3d_light_info *src = LIST_ENTRY(e, struct wined3d_light_info, entry), *realLight;
|
2007-08-04 14:44:33 +02:00
|
|
|
|
|
|
|
/* Look up the light in the destination */
|
2010-10-01 12:25:49 +02:00
|
|
|
LIST_FOR_EACH(f, &src_state->light_map[i])
|
2010-09-21 21:20:54 +02:00
|
|
|
{
|
2009-10-14 10:55:16 +02:00
|
|
|
realLight = LIST_ENTRY(f, struct wined3d_light_info, entry);
|
2009-10-14 10:55:17 +02:00
|
|
|
if (realLight->OriginalIndex == src->OriginalIndex)
|
|
|
|
{
|
|
|
|
src->OriginalParms = realLight->OriginalParms;
|
|
|
|
|
|
|
|
if (realLight->glIndex == -1 && src->glIndex != -1)
|
|
|
|
{
|
|
|
|
/* Light disabled */
|
2010-10-01 12:25:49 +02:00
|
|
|
dst_state->lights[src->glIndex] = NULL;
|
2007-08-04 14:44:33 +02:00
|
|
|
}
|
2009-10-14 10:55:17 +02:00
|
|
|
else if (realLight->glIndex != -1 && src->glIndex == -1)
|
|
|
|
{
|
|
|
|
/* Light enabled */
|
2010-10-01 12:25:49 +02:00
|
|
|
dst_state->lights[realLight->glIndex] = src;
|
2007-08-04 14:44:33 +02:00
|
|
|
}
|
2009-10-14 10:55:17 +02:00
|
|
|
src->glIndex = realLight->glIndex;
|
2007-08-04 14:44:33 +02:00
|
|
|
updated = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:55:17 +02:00
|
|
|
if (!updated)
|
|
|
|
{
|
2010-01-04 21:33:11 +01:00
|
|
|
/* This can happen if the light was originally created as a
|
|
|
|
* default light for SetLightEnable() while recording. */
|
2010-10-01 12:25:49 +02:00
|
|
|
WARN("Light %u in dst_state %p does not exist in src_state %p.\n",
|
|
|
|
src->OriginalIndex, dst_state, src_state);
|
2010-01-04 21:33:11 +01:00
|
|
|
|
|
|
|
src->OriginalParms = WINED3D_default_light;
|
|
|
|
if (src->glIndex != -1)
|
|
|
|
{
|
2010-10-01 12:25:49 +02:00
|
|
|
dst_state->lights[src->glIndex] = NULL;
|
2010-01-04 21:33:11 +01:00
|
|
|
src->glIndex = -1;
|
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
|
|
|
|
{
|
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
2010-09-27 12:07:55 +02:00
|
|
|
const struct wined3d_state *src_state = &This->device->stateBlock->state;
|
2009-10-14 10:55:18 +02:00
|
|
|
unsigned int i;
|
2008-12-31 16:57:11 +01:00
|
|
|
DWORD map;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Capturing state %p.\n", src_state);
|
|
|
|
|
|
|
|
if (This->changed.vertexShader && This->state.vertex_shader != src_state->vertex_shader)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2010-09-20 12:04:27 +02:00
|
|
|
TRACE("Updating vertex shader from %p to %p\n",
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vertex_shader, src_state->vertex_shader);
|
2006-02-06 11:32:13 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->vertex_shader)
|
|
|
|
IWineD3DVertexShader_AddRef((IWineD3DVertexShader *)src_state->vertex_shader);
|
2010-09-20 12:04:27 +02:00
|
|
|
if (This->state.vertex_shader)
|
|
|
|
IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vertex_shader = src_state->vertex_shader;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Vertex Shader Float Constants */
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_f; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_vs_consts_f[i];
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting vs_consts_f[%u] to {%.8e, %.8e, %.8e, %.8e}.\n", idx,
|
|
|
|
src_state->vs_consts_f[idx * 4 + 0],
|
|
|
|
src_state->vs_consts_f[idx * 4 + 1],
|
|
|
|
src_state->vs_consts_f[idx * 4 + 2],
|
|
|
|
src_state->vs_consts_f[idx * 4 + 3]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vs_consts_f[idx * 4 + 0] = src_state->vs_consts_f[idx * 4 + 0];
|
|
|
|
This->state.vs_consts_f[idx * 4 + 1] = src_state->vs_consts_f[idx * 4 + 1];
|
|
|
|
This->state.vs_consts_f[idx * 4 + 2] = src_state->vs_consts_f[idx * 4 + 2];
|
|
|
|
This->state.vs_consts_f[idx * 4 + 3] = src_state->vs_consts_f[idx * 4 + 3];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-04 14:44:33 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Vertex Shader Integer Constants */
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_i; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_vs_consts_i[i];
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting vs_consts[%u] to {%d, %d, %d, %d}.\n", idx,
|
|
|
|
src_state->vs_consts_i[idx * 4 + 0],
|
|
|
|
src_state->vs_consts_i[idx * 4 + 1],
|
|
|
|
src_state->vs_consts_i[idx * 4 + 2],
|
|
|
|
src_state->vs_consts_i[idx * 4 + 3]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vs_consts_i[idx * 4 + 0] = src_state->vs_consts_i[idx * 4 + 0];
|
|
|
|
This->state.vs_consts_i[idx * 4 + 1] = src_state->vs_consts_i[idx * 4 + 1];
|
|
|
|
This->state.vs_consts_i[idx * 4 + 2] = src_state->vs_consts_i[idx * 4 + 2];
|
|
|
|
This->state.vs_consts_i[idx * 4 + 3] = src_state->vs_consts_i[idx * 4 + 3];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-03 20:07:30 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Vertex Shader Boolean Constants */
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_b; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_vs_consts_b[i];
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting vs_consts_b[%u] to %s.\n",
|
|
|
|
idx, src_state->vs_consts_b[idx] ? "TRUE" : "FALSE");
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vs_consts_b[idx] = src_state->vs_consts_b[idx];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Pixel Shader Float Constants */
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_f; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_ps_consts_f[i];
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting ps_consts_f[%u] to {%.8e, %.8e, %.8e, %.8e}.\n", idx,
|
|
|
|
src_state->ps_consts_f[idx * 4 + 0],
|
|
|
|
src_state->ps_consts_f[idx * 4 + 1],
|
|
|
|
src_state->ps_consts_f[idx * 4 + 2],
|
|
|
|
src_state->ps_consts_f[idx * 4 + 3]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.ps_consts_f[idx * 4 + 0] = src_state->ps_consts_f[idx * 4 + 0];
|
|
|
|
This->state.ps_consts_f[idx * 4 + 1] = src_state->ps_consts_f[idx * 4 + 1];
|
|
|
|
This->state.ps_consts_f[idx * 4 + 2] = src_state->ps_consts_f[idx * 4 + 2];
|
|
|
|
This->state.ps_consts_f[idx * 4 + 3] = src_state->ps_consts_f[idx * 4 + 3];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-03 20:12:54 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Pixel Shader Integer Constants */
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_i; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_ps_consts_i[i];
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting ps_consts_i[%u] to {%d, %d, %d, %d}.\n", idx,
|
|
|
|
src_state->ps_consts_i[idx * 4 + 0],
|
|
|
|
src_state->ps_consts_i[idx * 4 + 1],
|
|
|
|
src_state->ps_consts_i[idx * 4 + 2],
|
|
|
|
src_state->ps_consts_i[idx * 4 + 3]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.ps_consts_i[idx * 4 + 0] = src_state->ps_consts_i[idx * 4 + 0];
|
|
|
|
This->state.ps_consts_i[idx * 4 + 1] = src_state->ps_consts_i[idx * 4 + 1];
|
|
|
|
This->state.ps_consts_i[idx * 4 + 2] = src_state->ps_consts_i[idx * 4 + 2];
|
|
|
|
This->state.ps_consts_i[idx * 4 + 3] = src_state->ps_consts_i[idx * 4 + 3];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Pixel Shader Boolean Constants */
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_b; ++i)
|
|
|
|
{
|
|
|
|
unsigned int idx = This->contained_ps_consts_b[i];
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Setting ps_consts_b[%u] to %s.\n",
|
|
|
|
idx, src_state->ps_consts_b[idx] ? "TRUE" : "FALSE");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.ps_consts_b[idx] = src_state->ps_consts_b[idx];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Others + Render & Texture */
|
|
|
|
for (i = 0; i < This->num_contained_transform_states; ++i)
|
|
|
|
{
|
|
|
|
WINED3DTRANSFORMSTATETYPE transform = This->contained_transform_states[i];
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
TRACE("Updating transform %#x.\n", transform);
|
2006-02-06 11:32:13 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.transforms[transform] = src_state->transforms[transform];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.primitive_type)
|
|
|
|
This->state.gl_primitive_type = src_state->gl_primitive_type;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
if (This->changed.indices
|
2010-09-27 12:07:55 +02:00
|
|
|
&& ((This->state.index_buffer != src_state->index_buffer)
|
|
|
|
|| (This->state.base_vertex_index != src_state->base_vertex_index)
|
|
|
|
|| (This->state.index_format != src_state->index_format)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Updating index buffer to %p, base vertex index to %d.\n",
|
|
|
|
src_state->index_buffer, src_state->base_vertex_index);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->index_buffer)
|
|
|
|
IWineD3DBuffer_AddRef((IWineD3DBuffer *)src_state->index_buffer);
|
2010-09-20 19:41:23 +02:00
|
|
|
if (This->state.index_buffer)
|
|
|
|
IWineD3DBuffer_Release((IWineD3DBuffer *)This->state.index_buffer);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.index_buffer = src_state->index_buffer;
|
|
|
|
This->state.base_vertex_index = src_state->base_vertex_index;
|
|
|
|
This->state.index_format = src_state->index_format;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.vertexDecl && This->state.vertex_declaration != src_state->vertex_declaration)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2010-09-17 11:59:41 +02:00
|
|
|
TRACE("Updating vertex declaration from %p to %p.\n",
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vertex_declaration, src_state->vertex_declaration);
|
2010-09-17 11:59:41 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->vertex_declaration)
|
|
|
|
IWineD3DVertexDeclaration_AddRef((IWineD3DVertexDeclaration *)src_state->vertex_declaration);
|
2010-09-17 11:59:41 +02:00
|
|
|
if (This->state.vertex_declaration)
|
|
|
|
IWineD3DVertexDeclaration_Release((IWineD3DVertexDeclaration *)This->state.vertex_declaration);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.vertex_declaration = src_state->vertex_declaration;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.material && memcmp(&src_state->material, &This->state.material, sizeof(This->state.material)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating material.\n");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.material = src_state->material;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.viewport && memcmp(&src_state->viewport, &This->state.viewport, sizeof(This->state.viewport)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating viewport.\n");
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.viewport = src_state->viewport;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.scissorRect && memcmp(&src_state->scissor_rect,
|
2010-09-15 12:00:05 +02:00
|
|
|
&This->state.scissor_rect, sizeof(This->state.scissor_rect)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating scissor rect.\n");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.scissor_rect = src_state->scissor_rect;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-09 17:45:29 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
map = This->changed.streamSource;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->state.streams[i].stride != src_state->streams[i].stride
|
|
|
|
|| This->state.streams[i].buffer != src_state->streams[i].buffer)
|
2009-01-02 16:19:12 +01:00
|
|
|
{
|
2009-10-14 10:55:18 +02:00
|
|
|
TRACE("Updating stream source %u to %p, stride to %u.\n",
|
2010-09-27 12:07:55 +02:00
|
|
|
i, src_state->streams[i].buffer,
|
|
|
|
src_state->streams[i].stride);
|
2010-09-20 19:41:22 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.streams[i].stride = src_state->streams[i].stride;
|
|
|
|
if (src_state->streams[i].buffer)
|
|
|
|
IWineD3DBuffer_AddRef((IWineD3DBuffer *)src_state->streams[i].buffer);
|
2010-09-20 19:41:22 +02:00
|
|
|
if (This->state.streams[i].buffer)
|
|
|
|
IWineD3DBuffer_Release((IWineD3DBuffer *)This->state.streams[i].buffer);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.streams[i].buffer = src_state->streams[i].buffer;
|
2007-08-03 20:23:52 +02:00
|
|
|
}
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-03 20:23:52 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
map = This->changed.streamFreq;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
2007-08-04 14:44:33 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->state.streams[i].frequency != src_state->streams[i].frequency
|
|
|
|
|| This->state.streams[i].flags != src_state->streams[i].flags)
|
2009-09-28 10:05:00 +02:00
|
|
|
{
|
2009-10-14 10:55:18 +02:00
|
|
|
TRACE("Updating stream frequency %u to %u flags to %#x.\n",
|
2010-09-27 12:07:55 +02:00
|
|
|
i, src_state->streams[i].frequency, src_state->streams[i].flags);
|
2009-09-28 10:05:00 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.streams[i].frequency = src_state->streams[i].frequency;
|
|
|
|
This->state.streams[i].flags = src_state->streams[i].flags;
|
2009-09-28 10:04:59 +02:00
|
|
|
}
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
map = This->changed.clipplane;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (memcmp(src_state->clip_planes[i], This->state.clip_planes[i], sizeof(*This->state.clip_planes)))
|
2009-10-02 11:16:13 +02:00
|
|
|
{
|
2009-10-14 10:55:18 +02:00
|
|
|
TRACE("Updating clipplane %u.\n", i);
|
2010-09-27 12:07:55 +02:00
|
|
|
memcpy(This->state.clip_planes[i], src_state->clip_planes[i], sizeof(*This->state.clip_planes));
|
2007-08-20 18:56:10 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:55:18 +02:00
|
|
|
/* Render */
|
|
|
|
for (i = 0; i < This->num_contained_render_states; ++i)
|
|
|
|
{
|
|
|
|
WINED3DRENDERSTATETYPE rs = This->contained_render_states[i];
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Updating render state %#x to %u.\n", rs, src_state->render_states[rs]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.render_states[rs] = src_state->render_states[rs];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-09-16 11:19:57 +02:00
|
|
|
TRACE("Updating texturestage state %u, %u to %#x (was %#x).\n", stage, state,
|
2010-09-27 12:07:55 +02:00
|
|
|
src_state->texture_states[stage][state], This->state.texture_states[stage][state]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.texture_states[stage][state] = src_state->texture_states[stage][state];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Samplers */
|
|
|
|
map = This->changed.textures;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
2010-09-17 11:59:40 +02:00
|
|
|
TRACE("Updating texture %u to %p (was %p).\n",
|
2010-09-27 12:07:55 +02:00
|
|
|
i, src_state->textures[i], This->state.textures[i]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->textures[i])
|
|
|
|
IWineD3DBaseTexture_AddRef((IWineD3DBaseTexture *)src_state->textures[i]);
|
2010-09-17 11:59:40 +02:00
|
|
|
if (This->state.textures[i])
|
|
|
|
IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)This->state.textures[i]);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.textures[i] = src_state->textures[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-09-16 11:19:58 +02:00
|
|
|
TRACE("Updating sampler state %u, %u to %#x (was %#x).\n", stage, state,
|
2010-09-27 12:07:55 +02:00
|
|
|
src_state->sampler_states[stage][state], This->state.sampler_states[stage][state]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.sampler_states[stage][state] = src_state->sampler_states[stage][state];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (This->changed.pixelShader && This->state.pixel_shader != src_state->pixel_shader)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->pixel_shader)
|
|
|
|
IWineD3DPixelShader_AddRef((IWineD3DPixelShader *)src_state->pixel_shader);
|
2010-09-20 12:04:29 +02:00
|
|
|
if (This->state.pixel_shader)
|
|
|
|
IWineD3DPixelShader_Release((IWineD3DPixelShader *)This->state.pixel_shader);
|
2010-09-27 12:07:55 +02:00
|
|
|
This->state.pixel_shader = src_state->pixel_shader;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 12:25:49 +02:00
|
|
|
wined3d_state_record_lights(&This->state, src_state);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Captue done.\n");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2010-09-27 12:07:54 +02:00
|
|
|
static void apply_lights(IWineD3DDevice *device, const struct wined3d_state *state)
|
2009-09-30 10:49:10 +02:00
|
|
|
{
|
2007-08-04 00:46:37 +02:00
|
|
|
UINT i;
|
2010-09-27 12:07:54 +02:00
|
|
|
|
|
|
|
for (i = 0; i < LIGHTMAP_SIZE; ++i)
|
|
|
|
{
|
2007-08-04 00:46:37 +02:00
|
|
|
struct list *e;
|
|
|
|
|
2010-09-27 12:07:54 +02:00
|
|
|
LIST_FOR_EACH(e, &state->light_map[i])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_light_info *light = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetLight(device, light->OriginalIndex, &light->OriginalParms);
|
|
|
|
IWineD3DDevice_SetLightEnable(device, light->OriginalIndex, light->glIndex != -1);
|
2007-08-04 00:46:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
|
|
|
|
{
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice *device = (IWineD3DDevice *)This->device;
|
2009-10-15 10:36:42 +02:00
|
|
|
unsigned int i;
|
2008-12-31 16:57:11 +01:00
|
|
|
DWORD map;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-04-20 22:38:39 +02:00
|
|
|
TRACE("(%p) : Applying state block %p ------------------v\n", This, device);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2007-08-09 17:45:29 +02:00
|
|
|
TRACE("Blocktype: %d\n", This->blockType);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-20 12:04:27 +02:00
|
|
|
if (This->changed.vertexShader)
|
|
|
|
IWineD3DDevice_SetVertexShader(device, (IWineD3DVertexShader *)This->state.vertex_shader);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
/* Vertex Shader Constants */
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_f; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetVertexShaderConstantF(device, This->contained_vs_consts_f[i],
|
2010-09-20 12:04:28 +02:00
|
|
|
This->state.vs_consts_f + This->contained_vs_consts_f[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_i; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetVertexShaderConstantI(device, This->contained_vs_consts_i[i],
|
2010-09-20 12:04:28 +02:00
|
|
|
This->state.vs_consts_i + This->contained_vs_consts_i[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < This->num_contained_vs_consts_b; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetVertexShaderConstantB(device, This->contained_vs_consts_b[i],
|
2010-09-20 12:04:28 +02:00
|
|
|
This->state.vs_consts_b + This->contained_vs_consts_b[i], 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2010-09-27 12:07:54 +02:00
|
|
|
apply_lights(device, &This->state);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-20 12:04:29 +02:00
|
|
|
if (This->changed.pixelShader)
|
|
|
|
IWineD3DDevice_SetPixelShader(device, (IWineD3DPixelShader *)This->state.pixel_shader);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
/* Pixel Shader Constants */
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_f; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetPixelShaderConstantF(device, This->contained_ps_consts_f[i],
|
2010-09-20 12:04:30 +02:00
|
|
|
This->state.ps_consts_f + This->contained_ps_consts_f[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_i; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetPixelShaderConstantI(device, This->contained_ps_consts_i[i],
|
2010-09-20 12:04:30 +02:00
|
|
|
This->state.ps_consts_i + This->contained_ps_consts_i[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < This->num_contained_ps_consts_b; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetPixelShaderConstantB(device, This->contained_ps_consts_b[i],
|
2010-09-20 12:04:30 +02:00
|
|
|
This->state.ps_consts_b + This->contained_ps_consts_b[i], 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
/* Render */
|
|
|
|
for (i = 0; i < This->num_contained_render_states; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetRenderState(device, This->contained_render_states[i],
|
2010-09-15 12:00:04 +02:00
|
|
|
This->state.render_states[This->contained_render_states[i]]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
/* 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;
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2010-09-16 11:19:57 +02:00
|
|
|
IWineD3DDevice_SetTextureStageState(device, stage, state, This->state.texture_states[stage][state]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
/* 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;
|
2010-09-16 11:19:58 +02:00
|
|
|
DWORD value = This->state.sampler_states[stage][state];
|
2009-01-02 16:19:12 +01:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (stage >= MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS;
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetSamplerState(device, stage, state, value);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2009-01-02 16:19:12 +01:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
for (i = 0; i < This->num_contained_transform_states; ++i)
|
|
|
|
{
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetTransform(device, This->contained_transform_states[i],
|
2010-09-16 11:19:56 +02:00
|
|
|
&This->state.transforms[This->contained_transform_states[i]]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (This->changed.primitive_type)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
This->device->updateStateBlock->changed.primitive_type = TRUE;
|
2010-09-21 21:20:53 +02:00
|
|
|
This->device->updateStateBlock->state.gl_primitive_type = This->state.gl_primitive_type;
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (This->changed.indices)
|
|
|
|
{
|
2010-09-20 19:41:23 +02:00
|
|
|
IWineD3DDevice_SetIndexBuffer(device, (IWineD3DBuffer *)This->state.index_buffer, This->state.index_format);
|
2010-09-20 19:41:24 +02:00
|
|
|
IWineD3DDevice_SetBaseVertexIndex(device, This->state.base_vertex_index);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-17 11:59:41 +02:00
|
|
|
if (This->changed.vertexDecl && This->state.vertex_declaration)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2010-09-17 11:59:41 +02:00
|
|
|
IWineD3DDevice_SetVertexDeclaration(device, (IWineD3DVertexDeclaration *)This->state.vertex_declaration);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (This->changed.material)
|
|
|
|
{
|
2010-09-16 11:19:55 +02:00
|
|
|
IWineD3DDevice_SetMaterial(device, &This->state.material);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (This->changed.viewport)
|
|
|
|
{
|
2010-09-15 12:00:06 +02:00
|
|
|
IWineD3DDevice_SetViewport(device, &This->state.viewport);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (This->changed.scissorRect)
|
|
|
|
{
|
2010-09-15 12:00:05 +02:00
|
|
|
IWineD3DDevice_SetScissorRect(device, &This->state.scissor_rect);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
map = This->changed.streamSource;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
if (map & 1)
|
|
|
|
IWineD3DDevice_SetStreamSource(device, i,
|
2010-09-20 19:41:22 +02:00
|
|
|
(IWineD3DBuffer *)This->state.streams[i].buffer,
|
|
|
|
0, This->state.streams[i].stride);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
map = This->changed.streamFreq;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
if (map & 1)
|
2010-09-20 19:41:22 +02:00
|
|
|
IWineD3DDevice_SetStreamSourceFreq(device, i,
|
|
|
|
This->state.streams[i].frequency | This->state.streams[i].flags);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
map = This->changed.textures;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
DWORD stage;
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (!(map & 1)) continue;
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
stage = i < MAX_FRAGMENT_SAMPLERS ? i : WINED3DVERTEXTEXTURESAMPLER0 + i - MAX_FRAGMENT_SAMPLERS;
|
2010-09-17 11:59:40 +02:00
|
|
|
IWineD3DDevice_SetTexture(device, stage, (IWineD3DBaseTexture *)This->state.textures[i]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
map = This->changed.clipplane;
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
float clip[4];
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2009-10-15 10:36:42 +02:00
|
|
|
if (!(map & 1)) continue;
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2010-09-21 21:20:55 +02:00
|
|
|
clip[0] = This->state.clip_planes[i][0];
|
|
|
|
clip[1] = This->state.clip_planes[i][1];
|
|
|
|
clip[2] = This->state.clip_planes[i][2];
|
|
|
|
clip[3] = This->state.clip_planes[i][3];
|
2010-04-20 22:38:39 +02:00
|
|
|
IWineD3DDevice_SetClipPlane(device, i, clip);
|
2007-08-03 20:23:52 +02:00
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2010-09-16 11:19:57 +02:00
|
|
|
This->device->stateBlock->state.lowest_disabled_stage = MAX_TEXTURES - 1;
|
2009-10-15 10:36:42 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES - 1; ++i)
|
|
|
|
{
|
2010-09-16 11:19:57 +02:00
|
|
|
if (This->device->stateBlock->state.texture_states[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2010-09-16 11:19:57 +02:00
|
|
|
This->device->stateBlock->state.lowest_disabled_stage = i;
|
2006-12-19 23:00:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-20 22:38:39 +02:00
|
|
|
TRACE("(%p) : Applied state block %p ------------------^\n", This, device);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2010-09-28 12:00:21 +02:00
|
|
|
void stateblock_init_default_state(IWineD3DStateBlockImpl *stateblock)
|
2010-09-27 12:07:56 +02:00
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *device = stateblock->device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
struct wined3d_state *state = &stateblock->state;
|
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;
|
|
|
|
HRESULT hr;
|
2004-10-21 22:59:12 +02:00
|
|
|
|
2010-09-28 12:00:21 +02:00
|
|
|
TRACE("stateblock %p.\n", stateblock);
|
2010-09-27 12:07:56 +02:00
|
|
|
|
|
|
|
stateblock->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 */
|
2010-09-27 12:07:56 +02:00
|
|
|
memcpy(&state->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
|
|
|
|
memcpy(&state->transforms[WINED3DTS_VIEW], identity, sizeof(identity));
|
2010-09-16 11:19:56 +02:00
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
2010-09-27 12:07:56 +02:00
|
|
|
memcpy(&state->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: */
|
2010-09-27 12:07:56 +02:00
|
|
|
if (device->auto_depth_stencil)
|
|
|
|
state->render_states[WINED3DRS_ZENABLE] = WINED3DZB_TRUE;
|
2010-04-19 20:47:00 +02:00
|
|
|
else
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_ZENABLE] = WINED3DZB_FALSE;
|
|
|
|
state->render_states[WINED3DRS_FILLMODE] = WINED3DFILL_SOLID;
|
|
|
|
state->render_states[WINED3DRS_SHADEMODE] = WINED3DSHADE_GOURAUD;
|
2005-07-05 16:05:18 +02:00
|
|
|
lp.lp.wRepeatFactor = 0;
|
2010-09-27 12:07:56 +02:00
|
|
|
lp.lp.wLinePattern = 0;
|
|
|
|
state->render_states[WINED3DRS_LINEPATTERN] = lp.d;
|
|
|
|
state->render_states[WINED3DRS_ZWRITEENABLE] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_ALPHATESTENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_LASTPIXEL] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_SRCBLEND] = WINED3DBLEND_ONE;
|
|
|
|
state->render_states[WINED3DRS_DESTBLEND] = WINED3DBLEND_ZERO;
|
|
|
|
state->render_states[WINED3DRS_CULLMODE] = WINED3DCULL_CCW;
|
|
|
|
state->render_states[WINED3DRS_ZFUNC] = WINED3DCMP_LESSEQUAL;
|
|
|
|
state->render_states[WINED3DRS_ALPHAFUNC] = WINED3DCMP_ALWAYS;
|
|
|
|
state->render_states[WINED3DRS_ALPHAREF] = 0;
|
|
|
|
state->render_states[WINED3DRS_DITHERENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_ALPHABLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_FOGENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_SPECULARENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_ZVISIBLE] = 0;
|
|
|
|
state->render_states[WINED3DRS_FOGCOLOR] = 0;
|
|
|
|
state->render_states[WINED3DRS_FOGTABLEMODE] = WINED3DFOG_NONE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_FOGSTART] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_FOGEND] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_FOGDENSITY] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_EDGEANTIALIAS] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_ZBIAS] = 0;
|
|
|
|
state->render_states[WINED3DRS_RANGEFOGENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_STENCILENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_STENCILFAIL] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_STENCILZFAIL] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_STENCILPASS] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_STENCILREF] = 0;
|
|
|
|
state->render_states[WINED3DRS_STENCILMASK] = 0xffffffff;
|
|
|
|
state->render_states[WINED3DRS_STENCILFUNC] = WINED3DCMP_ALWAYS;
|
|
|
|
state->render_states[WINED3DRS_STENCILWRITEMASK] = 0xffffffff;
|
|
|
|
state->render_states[WINED3DRS_TEXTUREFACTOR] = 0xffffffff;
|
|
|
|
state->render_states[WINED3DRS_WRAP0] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP1] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP2] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP3] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP4] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP5] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP6] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP7] = 0;
|
|
|
|
state->render_states[WINED3DRS_CLIPPING] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_LIGHTING] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_AMBIENT] = 0;
|
|
|
|
state->render_states[WINED3DRS_FOGVERTEXMODE] = WINED3DFOG_NONE;
|
|
|
|
state->render_states[WINED3DRS_COLORVERTEX] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_LOCALVIEWER] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_NORMALIZENORMALS] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE] = WINED3DMCS_COLOR1;
|
|
|
|
state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] = WINED3DMCS_COLOR2;
|
|
|
|
state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] = WINED3DMCS_MATERIAL;
|
|
|
|
state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] = WINED3DMCS_MATERIAL;
|
|
|
|
state->render_states[WINED3DRS_VERTEXBLEND] = WINED3DVBF_DISABLE;
|
|
|
|
state->render_states[WINED3DRS_CLIPPLANEENABLE] = 0;
|
|
|
|
state->render_states[WINED3DRS_SOFTWAREVERTEXPROCESSING] = FALSE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSIZE] = tmpfloat.d;
|
2009-10-20 10:26:06 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSIZE_MIN] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_POINTSPRITEENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_POINTSCALEENABLE] = FALSE;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSCALE_A] = tmpfloat.d;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSCALE_B] = tmpfloat.d;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSCALE_C] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_MULTISAMPLEANTIALIAS] = TRUE;
|
|
|
|
state->render_states[WINED3DRS_MULTISAMPLEMASK] = 0xffffffff;
|
|
|
|
state->render_states[WINED3DRS_PATCHEDGESTYLE] = WINED3DPATCHEDGE_DISCRETE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_PATCHSEGMENTS] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_DEBUGMONITORTOKEN] = 0xbaadcafe;
|
2009-10-29 10:37:10 +01:00
|
|
|
tmpfloat.f = gl_info->limits.pointsize_max;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_POINTSIZE_MAX] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_INDEXEDVERTEXBLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_COLORWRITEENABLE] = 0x0000000f;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_TWEENFACTOR] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_BLENDOP] = WINED3DBLENDOP_ADD;
|
|
|
|
state->render_states[WINED3DRS_POSITIONDEGREE] = WINED3DDEGREE_CUBIC;
|
|
|
|
state->render_states[WINED3DRS_NORMALDEGREE] = WINED3DDEGREE_LINEAR;
|
2005-07-05 16:05:18 +02:00
|
|
|
/* states new in d3d9 */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_SCISSORTESTENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_SLOPESCALEDEPTHBIAS] = 0;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_MINTESSELLATIONLEVEL] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_MAXTESSELLATIONLEVEL] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_ANTIALIASEDLINEENABLE] = FALSE;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_ADAPTIVETESS_X] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_ADAPTIVETESS_Y] = tmpfloat.d;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_ADAPTIVETESS_Z] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2010-09-27 12:07:56 +02:00
|
|
|
state->render_states[WINED3DRS_ADAPTIVETESS_W] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_TWOSIDEDSTENCILMODE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_CCW_STENCILFAIL] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_CCW_STENCILZFAIL] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_CCW_STENCILPASS] = WINED3DSTENCILOP_KEEP;
|
|
|
|
state->render_states[WINED3DRS_CCW_STENCILFUNC] = WINED3DCMP_ALWAYS;
|
|
|
|
state->render_states[WINED3DRS_COLORWRITEENABLE1] = 0x0000000f;
|
|
|
|
state->render_states[WINED3DRS_COLORWRITEENABLE2] = 0x0000000f;
|
|
|
|
state->render_states[WINED3DRS_COLORWRITEENABLE3] = 0x0000000f;
|
|
|
|
state->render_states[WINED3DRS_BLENDFACTOR] = 0xFFFFFFFF;
|
|
|
|
state->render_states[WINED3DRS_SRGBWRITEENABLE] = 0;
|
|
|
|
state->render_states[WINED3DRS_DEPTHBIAS] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP8] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP9] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP10] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP11] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP12] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP13] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP14] = 0;
|
|
|
|
state->render_states[WINED3DRS_WRAP15] = 0;
|
|
|
|
state->render_states[WINED3DRS_SEPARATEALPHABLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3DRS_SRCBLENDALPHA] = WINED3DBLEND_ONE;
|
|
|
|
state->render_states[WINED3DRS_DESTBLENDALPHA] = WINED3DBLEND_ZERO;
|
|
|
|
state->render_states[WINED3DRS_BLENDOPALPHA] = WINED3DBLENDOP_ADD;
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
/* clipping status */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->clip_status.ClipUnion = 0;
|
|
|
|
state->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 */
|
2010-09-16 11:19:56 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i)
|
|
|
|
{
|
2010-09-16 11:19:57 +02:00
|
|
|
TRACE("Setting up default texture states for texture Stage %u.\n", i);
|
2010-09-27 12:07:56 +02:00
|
|
|
memcpy(&state->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
|
|
|
|
state->texture_states[i][WINED3DTSS_COLOROP] = i ? WINED3DTOP_DISABLE : WINED3DTOP_MODULATE;
|
|
|
|
state->texture_states[i][WINED3DTSS_COLORARG1] = WINED3DTA_TEXTURE;
|
|
|
|
state->texture_states[i][WINED3DTSS_COLORARG2] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3DTSS_ALPHAOP] = i ? WINED3DTOP_DISABLE : WINED3DTOP_SELECTARG1;
|
|
|
|
state->texture_states[i][WINED3DTSS_ALPHAARG1] = WINED3DTA_TEXTURE;
|
|
|
|
state->texture_states[i][WINED3DTSS_ALPHAARG2] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVMAT00] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVMAT01] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVMAT10] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVMAT11] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_TEXCOORDINDEX] = i;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVLSCALE] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_BUMPENVLOFFSET] = 0;
|
|
|
|
state->texture_states[i][WINED3DTSS_TEXTURETRANSFORMFLAGS] = WINED3DTTFF_DISABLE;
|
|
|
|
state->texture_states[i][WINED3DTSS_COLORARG0] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3DTSS_ALPHAARG0] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3DTSS_RESULTARG] = WINED3DTA_CURRENT;
|
|
|
|
}
|
|
|
|
state->lowest_disabled_stage = 1;
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2005-07-05 16:05:18 +02:00
|
|
|
/* Sampler states*/
|
2010-09-16 11:19:58 +02:00
|
|
|
for (i = 0 ; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
|
|
|
TRACE("Setting up default samplers states for sampler %u.\n", i);
|
2010-09-27 12:07:56 +02:00
|
|
|
state->sampler_states[i][WINED3DSAMP_ADDRESSU] = WINED3DTADDRESS_WRAP;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_ADDRESSV] = WINED3DTADDRESS_WRAP;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_ADDRESSW] = WINED3DTADDRESS_WRAP;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_BORDERCOLOR] = 0;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MAGFILTER] = WINED3DTEXF_POINT;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MINFILTER] = WINED3DTEXF_POINT;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MIPFILTER] = WINED3DTEXF_NONE;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MIPMAPLODBIAS] = 0;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MAXMIPLEVEL] = 0;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_MAXANISOTROPY] = 1;
|
|
|
|
state->sampler_states[i][WINED3DSAMP_SRGBTEXTURE] = 0;
|
2010-09-16 11:19:58 +02:00
|
|
|
/* TODO: Indicates which element of a multielement texture to use. */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->sampler_states[i][WINED3DSAMP_ELEMENTINDEX] = 0;
|
2010-09-16 11:19:58 +02:00
|
|
|
/* TODO: Vertex offset in the presampled displacement map. */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->sampler_states[i][WINED3DSAMP_DMAPOFFSET] = 0;
|
2005-07-05 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.textures; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2010-09-27 12:07:56 +02:00
|
|
|
state->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
|
|
|
/* check the return values, because the GetBackBuffer call isn't valid for ddraw */
|
2010-09-27 12:07:56 +02:00
|
|
|
hr = IWineD3DDevice_GetSwapChain((IWineD3DDevice *)device, 0, &swapchain);
|
2010-09-14 13:38:39 +02:00
|
|
|
if (SUCCEEDED(hr) && swapchain)
|
|
|
|
{
|
2008-08-31 12:20:28 +02:00
|
|
|
hr = IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
|
2009-06-15 09:06:50 +02:00
|
|
|
if (SUCCEEDED(hr) && backbuffer)
|
|
|
|
{
|
|
|
|
WINED3DSURFACE_DESC desc;
|
|
|
|
|
2008-08-31 12:20:28 +02:00
|
|
|
IWineD3DSurface_GetDesc(backbuffer, &desc);
|
|
|
|
IWineD3DSurface_Release(backbuffer);
|
|
|
|
|
2009-06-15 09:06:50 +02:00
|
|
|
/* Set the default scissor rect values */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->scissor_rect.left = 0;
|
|
|
|
state->scissor_rect.right = desc.width;
|
|
|
|
state->scissor_rect.top = 0;
|
|
|
|
state->scissor_rect.bottom = desc.height;
|
2008-08-31 12:20:28 +02:00
|
|
|
}
|
2008-12-19 19:21:55 +01:00
|
|
|
|
|
|
|
/* Set the default viewport */
|
2010-09-27 12:07:56 +02:00
|
|
|
state->viewport.X = 0;
|
|
|
|
state->viewport.Y = 0;
|
|
|
|
state->viewport.Width = ((IWineD3DSwapChainImpl *)swapchain)->presentParms.BackBufferWidth;
|
|
|
|
state->viewport.Height = ((IWineD3DSwapChainImpl *)swapchain)->presentParms.BackBufferHeight;
|
|
|
|
state->viewport.MinZ = 0.0f;
|
|
|
|
state->viewport.MaxZ = 1.0f;
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2008-08-31 12:20:28 +02:00
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
|
|
|
}
|
|
|
|
|
2010-09-27 12:07:56 +02:00
|
|
|
TRACE("Done.\n");
|
2004-10-21 22:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
* IWineD3DStateBlock VTbl follows
|
|
|
|
**********************************************************/
|
|
|
|
|
2009-09-29 11:09:04 +02:00
|
|
|
static 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 */
|
2005-07-05 16:05:18 +02:00
|
|
|
IWineD3DStateBlockImpl_Capture,
|
|
|
|
IWineD3DStateBlockImpl_Apply,
|
2004-10-21 22:59:12 +02:00
|
|
|
};
|
2009-09-29 11:09:04 +02:00
|
|
|
|
2009-12-04 11:50:48 +01:00
|
|
|
HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl *device, WINED3DSTATEBLOCKTYPE type)
|
2009-09-29 11:09:04 +02:00
|
|
|
{
|
2009-10-02 11:16:10 +02:00
|
|
|
unsigned int i;
|
2009-09-29 11:09:04 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
stateblock->lpVtbl = &IWineD3DStateBlock_Vtbl;
|
|
|
|
stateblock->ref = 1;
|
2009-12-09 20:32:08 +01:00
|
|
|
stateblock->device = device;
|
2009-09-29 11:09:04 +02:00
|
|
|
stateblock->blockType = type;
|
|
|
|
|
|
|
|
for (i = 0; i < LIGHTMAP_SIZE; i++)
|
|
|
|
{
|
2010-09-21 21:20:54 +02:00
|
|
|
list_init(&stateblock->state.light_map[i]);
|
2009-09-29 11:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = stateblock_allocate_shader_constants(stateblock);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
/* The WINED3DSBT_INIT stateblock type is used during initialization to
|
|
|
|
* produce a placeholder stateblock so other functions called can update a
|
|
|
|
* state block. */
|
|
|
|
if (type == WINED3DSBT_INIT || type == WINED3DSBT_RECORDED) return WINED3D_OK;
|
|
|
|
|
|
|
|
TRACE("Updating changed flags appropriate for type %#x.\n", type);
|
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
switch (type)
|
2009-09-29 11:09:04 +02:00
|
|
|
{
|
2009-10-14 10:55:15 +02:00
|
|
|
case WINED3DSBT_ALL:
|
2010-09-21 21:20:54 +02:00
|
|
|
stateblock_init_lights(stateblock, device->stateBlock->state.light_map);
|
2009-10-25 01:23:34 +02:00
|
|
|
stateblock_savedstates_set_all(&stateblock->changed, device->d3d_vshader_constantF,
|
|
|
|
device->d3d_pshader_constantF);
|
2009-10-14 10:55:15 +02:00
|
|
|
break;
|
2009-09-29 11:09:04 +02:00
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
case WINED3DSBT_PIXELSTATE:
|
2009-10-25 01:23:34 +02:00
|
|
|
stateblock_savedstates_set_pixel(&stateblock->changed, device->d3d_pshader_constantF);
|
2009-10-14 10:55:15 +02:00
|
|
|
break;
|
2009-10-09 09:58:46 +02:00
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
case WINED3DSBT_VERTEXSTATE:
|
2010-09-21 21:20:54 +02:00
|
|
|
stateblock_init_lights(stateblock, device->stateBlock->state.light_map);
|
2009-10-25 01:23:34 +02:00
|
|
|
stateblock_savedstates_set_vertex(&stateblock->changed, device->d3d_vshader_constantF);
|
2009-10-14 10:55:15 +02:00
|
|
|
break;
|
2009-10-09 09:58:46 +02:00
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unrecognized state block type %#x.\n", type);
|
|
|
|
break;
|
2009-09-29 11:09:04 +02:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:55:15 +02:00
|
|
|
stateblock_init_contained_states(stateblock);
|
|
|
|
IWineD3DStateBlockImpl_Capture((IWineD3DStateBlock *)stateblock);
|
2009-09-29 11:09:04 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|