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"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2004-10-21 22:59:12 +02:00
|
|
|
#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
|
|
|
{
|
2011-12-19 21:00:09 +01:00
|
|
|
WINED3D_RS_ALPHABLENDENABLE,
|
|
|
|
WINED3D_RS_ALPHAFUNC,
|
|
|
|
WINED3D_RS_ALPHAREF,
|
|
|
|
WINED3D_RS_ALPHATESTENABLE,
|
|
|
|
WINED3D_RS_ANTIALIASEDLINEENABLE,
|
|
|
|
WINED3D_RS_BLENDFACTOR,
|
|
|
|
WINED3D_RS_BLENDOP,
|
|
|
|
WINED3D_RS_BLENDOPALPHA,
|
|
|
|
WINED3D_RS_CCW_STENCILFAIL,
|
|
|
|
WINED3D_RS_CCW_STENCILPASS,
|
|
|
|
WINED3D_RS_CCW_STENCILZFAIL,
|
|
|
|
WINED3D_RS_COLORWRITEENABLE,
|
|
|
|
WINED3D_RS_COLORWRITEENABLE1,
|
|
|
|
WINED3D_RS_COLORWRITEENABLE2,
|
|
|
|
WINED3D_RS_COLORWRITEENABLE3,
|
|
|
|
WINED3D_RS_DEPTHBIAS,
|
|
|
|
WINED3D_RS_DESTBLEND,
|
|
|
|
WINED3D_RS_DESTBLENDALPHA,
|
|
|
|
WINED3D_RS_DITHERENABLE,
|
|
|
|
WINED3D_RS_FILLMODE,
|
|
|
|
WINED3D_RS_FOGDENSITY,
|
|
|
|
WINED3D_RS_FOGEND,
|
|
|
|
WINED3D_RS_FOGSTART,
|
|
|
|
WINED3D_RS_LASTPIXEL,
|
|
|
|
WINED3D_RS_SCISSORTESTENABLE,
|
|
|
|
WINED3D_RS_SEPARATEALPHABLENDENABLE,
|
|
|
|
WINED3D_RS_SHADEMODE,
|
|
|
|
WINED3D_RS_SLOPESCALEDEPTHBIAS,
|
|
|
|
WINED3D_RS_SRCBLEND,
|
|
|
|
WINED3D_RS_SRCBLENDALPHA,
|
|
|
|
WINED3D_RS_SRGBWRITEENABLE,
|
|
|
|
WINED3D_RS_STENCILENABLE,
|
|
|
|
WINED3D_RS_STENCILFAIL,
|
|
|
|
WINED3D_RS_STENCILFUNC,
|
|
|
|
WINED3D_RS_STENCILMASK,
|
|
|
|
WINED3D_RS_STENCILPASS,
|
|
|
|
WINED3D_RS_STENCILREF,
|
|
|
|
WINED3D_RS_STENCILWRITEMASK,
|
|
|
|
WINED3D_RS_STENCILZFAIL,
|
|
|
|
WINED3D_RS_TEXTUREFACTOR,
|
|
|
|
WINED3D_RS_TWOSIDEDSTENCILMODE,
|
|
|
|
WINED3D_RS_WRAP0,
|
|
|
|
WINED3D_RS_WRAP1,
|
|
|
|
WINED3D_RS_WRAP10,
|
|
|
|
WINED3D_RS_WRAP11,
|
|
|
|
WINED3D_RS_WRAP12,
|
|
|
|
WINED3D_RS_WRAP13,
|
|
|
|
WINED3D_RS_WRAP14,
|
|
|
|
WINED3D_RS_WRAP15,
|
|
|
|
WINED3D_RS_WRAP2,
|
|
|
|
WINED3D_RS_WRAP3,
|
|
|
|
WINED3D_RS_WRAP4,
|
|
|
|
WINED3D_RS_WRAP5,
|
|
|
|
WINED3D_RS_WRAP6,
|
|
|
|
WINED3D_RS_WRAP7,
|
|
|
|
WINED3D_RS_WRAP8,
|
|
|
|
WINED3D_RS_WRAP9,
|
|
|
|
WINED3D_RS_ZENABLE,
|
|
|
|
WINED3D_RS_ZFUNC,
|
|
|
|
WINED3D_RS_ZWRITEENABLE,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD pixel_states_texture[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2012-01-09 22:16:51 +01:00
|
|
|
WINED3D_TSS_ALPHA_ARG0,
|
|
|
|
WINED3D_TSS_ALPHA_ARG1,
|
|
|
|
WINED3D_TSS_ALPHA_ARG2,
|
|
|
|
WINED3D_TSS_ALPHA_OP,
|
|
|
|
WINED3D_TSS_BUMPENV_LOFFSET,
|
|
|
|
WINED3D_TSS_BUMPENV_LSCALE,
|
|
|
|
WINED3D_TSS_BUMPENV_MAT00,
|
|
|
|
WINED3D_TSS_BUMPENV_MAT01,
|
|
|
|
WINED3D_TSS_BUMPENV_MAT10,
|
|
|
|
WINED3D_TSS_BUMPENV_MAT11,
|
|
|
|
WINED3D_TSS_COLOR_ARG0,
|
|
|
|
WINED3D_TSS_COLOR_ARG1,
|
|
|
|
WINED3D_TSS_COLOR_ARG2,
|
|
|
|
WINED3D_TSS_COLOR_OP,
|
|
|
|
WINED3D_TSS_RESULT_ARG,
|
|
|
|
WINED3D_TSS_TEXCOORD_INDEX,
|
|
|
|
WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD pixel_states_sampler[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
WINED3D_SAMP_ADDRESS_U,
|
|
|
|
WINED3D_SAMP_ADDRESS_V,
|
|
|
|
WINED3D_SAMP_ADDRESS_W,
|
|
|
|
WINED3D_SAMP_BORDER_COLOR,
|
|
|
|
WINED3D_SAMP_MAG_FILTER,
|
|
|
|
WINED3D_SAMP_MIN_FILTER,
|
|
|
|
WINED3D_SAMP_MIP_FILTER,
|
|
|
|
WINED3D_SAMP_MIPMAP_LOD_BIAS,
|
|
|
|
WINED3D_SAMP_MAX_MIP_LEVEL,
|
|
|
|
WINED3D_SAMP_MAX_ANISOTROPY,
|
|
|
|
WINED3D_SAMP_SRGB_TEXTURE,
|
|
|
|
WINED3D_SAMP_ELEMENT_INDEX,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_render[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2011-12-19 21:00:09 +01:00
|
|
|
WINED3D_RS_ADAPTIVETESS_W,
|
|
|
|
WINED3D_RS_ADAPTIVETESS_X,
|
|
|
|
WINED3D_RS_ADAPTIVETESS_Y,
|
|
|
|
WINED3D_RS_ADAPTIVETESS_Z,
|
|
|
|
WINED3D_RS_AMBIENT,
|
|
|
|
WINED3D_RS_AMBIENTMATERIALSOURCE,
|
|
|
|
WINED3D_RS_CLIPPING,
|
|
|
|
WINED3D_RS_CLIPPLANEENABLE,
|
|
|
|
WINED3D_RS_COLORVERTEX,
|
|
|
|
WINED3D_RS_CULLMODE,
|
|
|
|
WINED3D_RS_DIFFUSEMATERIALSOURCE,
|
|
|
|
WINED3D_RS_EMISSIVEMATERIALSOURCE,
|
|
|
|
WINED3D_RS_ENABLEADAPTIVETESSELLATION,
|
|
|
|
WINED3D_RS_FOGCOLOR,
|
|
|
|
WINED3D_RS_FOGDENSITY,
|
|
|
|
WINED3D_RS_FOGENABLE,
|
|
|
|
WINED3D_RS_FOGEND,
|
|
|
|
WINED3D_RS_FOGSTART,
|
|
|
|
WINED3D_RS_FOGTABLEMODE,
|
|
|
|
WINED3D_RS_FOGVERTEXMODE,
|
|
|
|
WINED3D_RS_INDEXEDVERTEXBLENDENABLE,
|
|
|
|
WINED3D_RS_LIGHTING,
|
|
|
|
WINED3D_RS_LOCALVIEWER,
|
|
|
|
WINED3D_RS_MAXTESSELLATIONLEVEL,
|
|
|
|
WINED3D_RS_MINTESSELLATIONLEVEL,
|
|
|
|
WINED3D_RS_MULTISAMPLEANTIALIAS,
|
|
|
|
WINED3D_RS_MULTISAMPLEMASK,
|
|
|
|
WINED3D_RS_NORMALDEGREE,
|
|
|
|
WINED3D_RS_NORMALIZENORMALS,
|
|
|
|
WINED3D_RS_PATCHEDGESTYLE,
|
|
|
|
WINED3D_RS_POINTSCALE_A,
|
|
|
|
WINED3D_RS_POINTSCALE_B,
|
|
|
|
WINED3D_RS_POINTSCALE_C,
|
|
|
|
WINED3D_RS_POINTSCALEENABLE,
|
|
|
|
WINED3D_RS_POINTSIZE,
|
|
|
|
WINED3D_RS_POINTSIZE_MAX,
|
|
|
|
WINED3D_RS_POINTSIZE_MIN,
|
|
|
|
WINED3D_RS_POINTSPRITEENABLE,
|
|
|
|
WINED3D_RS_POSITIONDEGREE,
|
|
|
|
WINED3D_RS_RANGEFOGENABLE,
|
|
|
|
WINED3D_RS_SHADEMODE,
|
|
|
|
WINED3D_RS_SPECULARENABLE,
|
|
|
|
WINED3D_RS_SPECULARMATERIALSOURCE,
|
|
|
|
WINED3D_RS_TWEENFACTOR,
|
|
|
|
WINED3D_RS_VERTEXBLEND,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_texture[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2012-01-09 22:16:51 +01:00
|
|
|
WINED3D_TSS_TEXCOORD_INDEX,
|
|
|
|
WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
|
|
|
|
2009-10-02 11:16:13 +02:00
|
|
|
static const DWORD vertex_states_sampler[] =
|
2009-10-02 11:16:12 +02:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
WINED3D_SAMP_DMAP_OFFSET,
|
2009-10-02 11:16:12 +02:00
|
|
|
};
|
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
|
|
|
|
*/
|
2011-01-28 20:05:43 +01:00
|
|
|
static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *object)
|
2009-08-27 10:04:56 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *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 */
|
2011-11-07 21:20:01 +01:00
|
|
|
static void stateblock_savedstates_set_all(struct wined3d_saved_states *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
|
|
|
}
|
|
|
|
|
2011-11-07 21:20:01 +01:00
|
|
|
static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *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
|
|
|
}
|
|
|
|
|
2011-11-07 21:20:01 +01:00
|
|
|
static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *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
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:43 +01:00
|
|
|
void stateblock_init_contained_states(struct wined3d_stateblock *stateblock)
|
2009-09-30 10:49:13 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:43 +01:00
|
|
|
static void stateblock_init_lights(struct wined3d_stateblock *stateblock, struct list *light_map)
|
2009-10-14 10:55:15 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
ULONG CDECL wined3d_stateblock_incref(struct wined3d_stateblock *stateblock)
|
2005-03-02 14:44:58 +01:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&stateblock->ref);
|
2005-03-02 14:44:58 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", stateblock, refcount);
|
2005-03-02 14:44:58 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
return refcount;
|
2005-03-02 14:44:58 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
void stateblock_unbind_resources(struct wined3d_stateblock *stateblock)
|
2011-01-28 20:05:41 +01:00
|
|
|
{
|
2011-12-06 22:57:44 +01:00
|
|
|
struct wined3d_state *state = &stateblock->state;
|
|
|
|
struct wined3d_vertex_declaration *decl;
|
|
|
|
struct wined3d_texture *texture;
|
|
|
|
struct wined3d_buffer *buffer;
|
|
|
|
struct wined3d_shader *shader;
|
|
|
|
unsigned int i;
|
2005-03-02 14:44:58 +01:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
if ((decl = state->vertex_declaration))
|
2011-01-28 20:05:41 +01:00
|
|
|
{
|
2011-12-06 22:57:44 +01:00
|
|
|
state->vertex_declaration = NULL;
|
|
|
|
wined3d_vertex_declaration_decref(decl);
|
|
|
|
}
|
2005-07-26 20:49:30 +02:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
|
|
|
if ((texture = state->textures[i]))
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-12-06 22:57:44 +01:00
|
|
|
state->textures[i] = NULL;
|
|
|
|
wined3d_texture_decref(texture);
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2011-12-06 22:57:44 +01:00
|
|
|
}
|
2011-04-19 00:07:57 +02:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
for (i = 0; i < MAX_STREAMS; ++i)
|
|
|
|
{
|
|
|
|
if ((buffer = state->streams[i].buffer))
|
2011-04-19 00:07:57 +02:00
|
|
|
{
|
2011-12-06 22:57:44 +01:00
|
|
|
state->streams[i].buffer = NULL;
|
2011-04-19 00:07:57 +02:00
|
|
|
wined3d_buffer_decref(buffer);
|
|
|
|
}
|
2011-12-06 22:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((buffer = state->index_buffer))
|
|
|
|
{
|
|
|
|
state->index_buffer = NULL;
|
|
|
|
wined3d_buffer_decref(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((shader = state->vertex_shader))
|
|
|
|
{
|
|
|
|
state->vertex_shader = NULL;
|
|
|
|
wined3d_shader_decref(shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((shader = state->pixel_shader))
|
|
|
|
{
|
|
|
|
state->pixel_shader = NULL;
|
|
|
|
wined3d_shader_decref(shader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&stateblock->ref);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u\n", stateblock, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
int counter;
|
2011-04-19 00:07:57 +02:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
stateblock_unbind_resources(stateblock);
|
2011-01-28 20:05:41 +01:00
|
|
|
|
|
|
|
for (counter = 0; counter < LIGHTMAP_SIZE; ++counter)
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e1, *e2;
|
2011-01-28 20:05:41 +01:00
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &stateblock->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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->state.vs_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->changed.vertexShaderConstantsF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->state.ps_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->changed.pixelShaderConstantsF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->contained_vs_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock->contained_ps_consts_f);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stateblock);
|
2005-03-02 14:44:58 +01:00
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
|
|
|
|
return refcount;
|
2005-03-02 14:44:58 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
HRESULT CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
const struct wined3d_state *src_state = &stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
TRACE("stateblock %p.\n", stateblock);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
TRACE("Capturing state %p.\n", src_state);
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.vertexShader && stateblock->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",
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(src_state->vertex_shader);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.vertex_shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(stateblock->state.vertex_shader);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vertex_shader = src_state->vertex_shader;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Vertex shader float constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_f; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->contained_vs_consts_f[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
|
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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vs_consts_f[idx * 4 + 0] = src_state->vs_consts_f[idx * 4 + 0];
|
|
|
|
stateblock->state.vs_consts_f[idx * 4 + 1] = src_state->vs_consts_f[idx * 4 + 1];
|
|
|
|
stateblock->state.vs_consts_f[idx * 4 + 2] = src_state->vs_consts_f[idx * 4 + 2];
|
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Vertex shader integer constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_i; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->contained_vs_consts_i[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
|
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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vs_consts_i[idx * 4 + 0] = src_state->vs_consts_i[idx * 4 + 0];
|
|
|
|
stateblock->state.vs_consts_i[idx * 4 + 1] = src_state->vs_consts_i[idx * 4 + 1];
|
|
|
|
stateblock->state.vs_consts_i[idx * 4 + 2] = src_state->vs_consts_i[idx * 4 + 2];
|
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Vertex shader boolean constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_b; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Pixel shader float constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_f; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->contained_ps_consts_f[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
|
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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.ps_consts_f[idx * 4 + 0] = src_state->ps_consts_f[idx * 4 + 0];
|
|
|
|
stateblock->state.ps_consts_f[idx * 4 + 1] = src_state->ps_consts_f[idx * 4 + 1];
|
|
|
|
stateblock->state.ps_consts_f[idx * 4 + 2] = src_state->ps_consts_f[idx * 4 + 2];
|
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Pixel shader integer constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_i; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.ps_consts_i[idx * 4 + 0] = src_state->ps_consts_i[idx * 4 + 0];
|
|
|
|
stateblock->state.ps_consts_i[idx * 4 + 1] = src_state->ps_consts_i[idx * 4 + 1];
|
|
|
|
stateblock->state.ps_consts_i[idx * 4 + 2] = src_state->ps_consts_i[idx * 4 + 2];
|
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Pixel shader boolean constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_b; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
unsigned int idx = stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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 */
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_transform_states; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2012-01-11 21:27:32 +01:00
|
|
|
enum wined3d_transform_state transform = stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.transforms[transform] = src_state->transforms[transform];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.primitive_type)
|
|
|
|
stateblock->state.gl_primitive_type = src_state->gl_primitive_type;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.indices
|
|
|
|
&& ((stateblock->state.index_buffer != src_state->index_buffer)
|
|
|
|
|| (stateblock->state.base_vertex_index != src_state->base_vertex_index)
|
|
|
|
|| (stateblock->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)
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_incref(src_state->index_buffer);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.index_buffer)
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_decref(stateblock->state.index_buffer);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.index_buffer = src_state->index_buffer;
|
|
|
|
stateblock->state.base_vertex_index = src_state->base_vertex_index;
|
|
|
|
stateblock->state.index_format = src_state->index_format;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.vertexDecl && stateblock->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",
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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)
|
2011-02-02 20:22:50 +01:00
|
|
|
wined3d_vertex_declaration_incref(src_state->vertex_declaration);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.vertex_declaration)
|
2011-02-02 20:22:50 +01:00
|
|
|
wined3d_vertex_declaration_decref(stateblock->state.vertex_declaration);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vertex_declaration = src_state->vertex_declaration;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.material
|
|
|
|
&& memcmp(&src_state->material, &stateblock->state.material, sizeof(stateblock->state.material)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating material.\n");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.material = src_state->material;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.viewport
|
|
|
|
&& memcmp(&src_state->viewport, &stateblock->state.viewport, sizeof(stateblock->state.viewport)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating viewport.\n");
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.viewport = src_state->viewport;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.scissorRect && memcmp(&src_state->scissor_rect,
|
|
|
|
&stateblock->state.scissor_rect, sizeof(stateblock->state.scissor_rect)))
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Updating scissor rect.\n");
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.scissor_rect = src_state->scissor_rect;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
2007-08-09 17:45:29 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.streamSource;
|
2009-10-14 10:55:18 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.streams[i].stride != src_state->streams[i].stride
|
|
|
|
|| stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.streams[i].stride = src_state->streams[i].stride;
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->streams[i].buffer)
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_incref(src_state->streams[i].buffer);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.streams[i].buffer)
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_decref(stateblock->state.streams[i].buffer);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.streamFreq;
|
2009-10-14 10:55:18 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
2007-08-04 14:44:33 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.streams[i].frequency != src_state->streams[i].frequency
|
|
|
|
|| stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.streams[i].frequency = src_state->streams[i].frequency;
|
|
|
|
stateblock->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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.clipplane;
|
2009-10-14 10:55:18 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
if (memcmp(&stateblock->state.clip_planes[i], &src_state->clip_planes[i], sizeof(src_state->clip_planes[i])))
|
2009-10-02 11:16:13 +02:00
|
|
|
{
|
2009-10-14 10:55:18 +02:00
|
|
|
TRACE("Updating clipplane %u.\n", i);
|
2012-05-22 18:01:06 +02:00
|
|
|
stateblock->state.clip_planes[i] = src_state->clip_planes[i];
|
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 */
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_render_states; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-12-19 21:00:09 +01:00
|
|
|
enum wined3d_render_state rs = stateblock->contained_render_states[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
|
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
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.render_states[rs] = src_state->render_states[rs];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Texture states */
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_tss_states; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
DWORD stage = stateblock->contained_tss_states[i].stage;
|
|
|
|
DWORD state = stateblock->contained_tss_states[i].state;
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-16 11:19:57 +02:00
|
|
|
TRACE("Updating texturestage state %u, %u to %#x (was %#x).\n", stage, state,
|
2011-01-28 20:05:41 +01:00
|
|
|
src_state->texture_states[stage][state], stateblock->state.texture_states[stage][state]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.texture_states[stage][state] = src_state->texture_states[stage][state];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Samplers */
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.textures;
|
2009-10-14 10:55:18 +02:00
|
|
|
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",
|
2011-01-28 20:05:41 +01:00
|
|
|
i, src_state->textures[i], stateblock->state.textures[i]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-27 12:07:55 +02:00
|
|
|
if (src_state->textures[i])
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_incref(src_state->textures[i]);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.textures[i])
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_decref(stateblock->state.textures[i]);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.textures[i] = src_state->textures[i];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_sampler_states; ++i)
|
2009-10-14 10:55:18 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
DWORD stage = stateblock->contained_sampler_states[i].stage;
|
|
|
|
DWORD state = stateblock->contained_sampler_states[i].state;
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2010-09-16 11:19:58 +02:00
|
|
|
TRACE("Updating sampler state %u, %u to %#x (was %#x).\n", stage, state,
|
2011-01-28 20:05:41 +01:00
|
|
|
src_state->sampler_states[stage][state], stateblock->state.sampler_states[stage][state]);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.sampler_states[stage][state] = src_state->sampler_states[stage][state];
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.pixelShader && stateblock->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)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(src_state->pixel_shader);
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->state.pixel_shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(stateblock->state.pixel_shader);
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.pixel_shader = src_state->pixel_shader;
|
2009-10-14 10:55:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
wined3d_state_record_lights(&stateblock->state, src_state);
|
2009-10-14 10:55:18 +02:00
|
|
|
|
2011-09-21 08:10:05 +02:00
|
|
|
TRACE("Capture 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
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void apply_lights(struct wined3d_device *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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms);
|
|
|
|
wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1);
|
2007-08-04 00:46:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
HRESULT CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = stateblock->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
|
|
|
|
2012-01-18 21:46:18 +01:00
|
|
|
TRACE("Applying stateblock %p to device %p.\n", stateblock, device);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.vertexShader)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_vertex_shader(device, stateblock->state.vertex_shader);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Vertex Shader Constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_f; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_vs_consts_f(device, stateblock->contained_vs_consts_f[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vs_consts_f + stateblock->contained_vs_consts_f[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_i; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_vs_consts_i(device, stateblock->contained_vs_consts_i[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vs_consts_i + stateblock->contained_vs_consts_i[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_vs_consts_b; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_vs_consts_b(device, stateblock->contained_vs_consts_b[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.vs_consts_b + stateblock->contained_vs_consts_b[i], 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
apply_lights(device, &stateblock->state);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.pixelShader)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_pixel_shader(device, stateblock->state.pixel_shader);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Pixel Shader Constants. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_f; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_ps_consts_f(device, stateblock->contained_ps_consts_f[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.ps_consts_f + stateblock->contained_ps_consts_f[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_i; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_ps_consts_i(device, stateblock->contained_ps_consts_i[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.ps_consts_i + stateblock->contained_ps_consts_i[i] * 4, 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
for (i = 0; i < stateblock->num_contained_ps_consts_b; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_ps_consts_b(device, stateblock->contained_ps_consts_b[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.ps_consts_b + stateblock->contained_ps_consts_b[i], 1);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Render states. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_render_states; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_render_state(device, stateblock->contained_render_states[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.render_states[stateblock->contained_render_states[i]]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Texture states. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_tss_states; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
DWORD stage = stateblock->contained_tss_states[i].stage;
|
|
|
|
DWORD state = stateblock->contained_tss_states[i].state;
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_texture_stage_state(device, stage, state, stateblock->state.texture_states[stage][state]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Sampler states. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_sampler_states; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
DWORD stage = stateblock->contained_sampler_states[i].stage;
|
|
|
|
DWORD state = stateblock->contained_sampler_states[i].state;
|
|
|
|
DWORD value = stateblock->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;
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_sampler_state(device, stage, state, value);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2009-01-02 16:19:12 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
/* Transform states. */
|
|
|
|
for (i = 0; i < stateblock->num_contained_transform_states; ++i)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_transform(device, stateblock->contained_transform_states[i],
|
2011-01-28 20:05:41 +01:00
|
|
|
&stateblock->state.transforms[stateblock->contained_transform_states[i]]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.primitive_type)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->device->updateStateBlock->changed.primitive_type = TRUE;
|
|
|
|
stateblock->device->updateStateBlock->state.gl_primitive_type = stateblock->state.gl_primitive_type;
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2008-12-31 16:57:11 +01:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.indices)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_index_buffer(device, stateblock->state.index_buffer, stateblock->state.index_format);
|
|
|
|
wined3d_device_set_base_vertex_index(device, stateblock->state.base_vertex_index);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_vertex_declaration(device, stateblock->state.vertex_declaration);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.material)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_material(device, &stateblock->state.material);
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_viewport(device, &stateblock->state.viewport);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
if (stateblock->changed.scissorRect)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_scissor_rect(device, &stateblock->state.scissor_rect);
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.streamSource;
|
2009-10-15 10:36:42 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
if (map & 1)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_stream_source(device, i,
|
2011-03-03 21:49:10 +01:00
|
|
|
stateblock->state.streams[i].buffer,
|
2011-01-28 20:05:41 +01:00
|
|
|
0, stateblock->state.streams[i].stride);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.streamFreq;
|
2009-10-15 10:36:42 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
if (map & 1)
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_stream_source_freq(device, i,
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->state.streams[i].frequency | stateblock->state.streams[i].flags);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.textures;
|
2009-10-15 10:36:42 +02:00
|
|
|
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;
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_device_set_texture(device, stage, stateblock->state.textures[i]);
|
2009-10-15 10:36:42 +02:00
|
|
|
}
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
map = stateblock->changed.clipplane;
|
2009-10-15 10:36:42 +02:00
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1)) continue;
|
2007-08-04 00:46:37 +02:00
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
wined3d_device_set_clip_plane(device, i, &stateblock->state.clip_planes[i]);
|
2007-08-03 20:23:52 +02:00
|
|
|
}
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->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)
|
|
|
|
{
|
2012-01-10 20:37:01 +01:00
|
|
|
if (stateblock->device->stateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
|
2009-10-15 10:36:42 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->device->stateBlock->state.lowest_disabled_stage = i;
|
2006-12-19 23:00:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-28 20:05:41 +01:00
|
|
|
|
|
|
|
TRACE("Applied stateblock %p.\n", stateblock);
|
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
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:43 +01:00
|
|
|
void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
|
2010-09-27 12:07:56 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = stateblock->device;
|
2010-09-27 12:07:56 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
struct wined3d_state *state = &stateblock->state;
|
2011-11-23 08:51:44 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct wined3d_line_pattern lp;
|
2004-12-13 14:35:38 +01:00
|
|
|
DWORD d;
|
|
|
|
} lp;
|
|
|
|
union {
|
|
|
|
float f;
|
|
|
|
DWORD d;
|
|
|
|
} tmpfloat;
|
|
|
|
unsigned int i;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *backbuffer;
|
2008-08-31 12:20:28 +02:00
|
|
|
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
|
|
|
|
2012-01-17 21:13:31 +01:00
|
|
|
memset(stateblock->changed.pixelShaderConstantsF, 0, device->d3d_pshader_constantF * sizeof(BOOL));
|
|
|
|
memset(stateblock->changed.vertexShaderConstantsF, 0, device->d3d_vshader_constantF * sizeof(BOOL));
|
|
|
|
|
2005-07-26 20:49:30 +02:00
|
|
|
/* Set some of the defaults for lights, transforms etc */
|
2012-05-03 21:49:38 +02:00
|
|
|
memcpy(&state->transforms[WINED3D_TS_PROJECTION], &identity, sizeof(identity));
|
|
|
|
memcpy(&state->transforms[WINED3D_TS_VIEW], &identity, sizeof(identity));
|
2010-09-16 11:19:56 +02:00
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
2012-05-03 21:49:38 +02:00
|
|
|
memcpy(&state->transforms[WINED3D_TS_WORLD_MATRIX(i)], &identity, sizeof(identity));
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
2005-07-05 16:05:18 +02:00
|
|
|
|
2011-07-14 01:02:44 +02:00
|
|
|
state->fb = &device->fb;
|
|
|
|
|
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)
|
2011-12-21 21:34:59 +01:00
|
|
|
state->render_states[WINED3D_RS_ZENABLE] = WINED3D_ZB_TRUE;
|
2010-04-19 20:47:00 +02:00
|
|
|
else
|
2011-12-21 21:34:59 +01:00
|
|
|
state->render_states[WINED3D_RS_ZENABLE] = WINED3D_ZB_FALSE;
|
2012-01-02 21:45:30 +01:00
|
|
|
state->render_states[WINED3D_RS_FILLMODE] = WINED3D_FILL_SOLID;
|
2012-01-02 21:45:29 +01:00
|
|
|
state->render_states[WINED3D_RS_SHADEMODE] = WINED3D_SHADE_GOURAUD;
|
2011-11-23 08:51:44 +01:00
|
|
|
lp.lp.repeat_factor = 0;
|
|
|
|
lp.lp.line_pattern = 0;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_LINEPATTERN] = lp.d;
|
|
|
|
state->render_states[WINED3D_RS_ZWRITEENABLE] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_ALPHATESTENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_LASTPIXEL] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_SRCBLEND] = WINED3D_BLEND_ONE;
|
|
|
|
state->render_states[WINED3D_RS_DESTBLEND] = WINED3D_BLEND_ZERO;
|
2012-01-03 23:06:54 +01:00
|
|
|
state->render_states[WINED3D_RS_CULLMODE] = WINED3D_CULL_CCW;
|
2011-12-20 21:42:14 +01:00
|
|
|
state->render_states[WINED3D_RS_ZFUNC] = WINED3D_CMP_LESSEQUAL;
|
|
|
|
state->render_states[WINED3D_RS_ALPHAFUNC] = WINED3D_CMP_ALWAYS;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_ALPHAREF] = 0;
|
|
|
|
state->render_states[WINED3D_RS_DITHERENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_ALPHABLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_FOGENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_SPECULARENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_ZVISIBLE] = 0;
|
|
|
|
state->render_states[WINED3D_RS_FOGCOLOR] = 0;
|
2011-12-21 21:35:00 +01:00
|
|
|
state->render_states[WINED3D_RS_FOGTABLEMODE] = WINED3D_FOG_NONE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_FOGSTART] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_FOGEND] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_FOGDENSITY] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_EDGEANTIALIAS] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_RANGEFOGENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_STENCILENABLE] = FALSE;
|
2012-01-03 23:06:55 +01:00
|
|
|
state->render_states[WINED3D_RS_STENCILFAIL] = WINED3D_STENCIL_OP_KEEP;
|
|
|
|
state->render_states[WINED3D_RS_STENCILZFAIL] = WINED3D_STENCIL_OP_KEEP;
|
|
|
|
state->render_states[WINED3D_RS_STENCILPASS] = WINED3D_STENCIL_OP_KEEP;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_STENCILREF] = 0;
|
|
|
|
state->render_states[WINED3D_RS_STENCILMASK] = 0xffffffff;
|
2011-12-20 21:42:14 +01:00
|
|
|
state->render_states[WINED3D_RS_STENCILFUNC] = WINED3D_CMP_ALWAYS;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_STENCILWRITEMASK] = 0xffffffff;
|
|
|
|
state->render_states[WINED3D_RS_TEXTUREFACTOR] = 0xffffffff;
|
|
|
|
state->render_states[WINED3D_RS_WRAP0] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP1] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP2] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP3] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP4] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP5] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP6] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP7] = 0;
|
|
|
|
state->render_states[WINED3D_RS_CLIPPING] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_LIGHTING] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_AMBIENT] = 0;
|
2011-12-21 21:35:00 +01:00
|
|
|
state->render_states[WINED3D_RS_FOGVERTEXMODE] = WINED3D_FOG_NONE;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_COLORVERTEX] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_LOCALVIEWER] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_NORMALIZENORMALS] = FALSE;
|
2012-01-04 23:34:55 +01:00
|
|
|
state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] = WINED3D_MCS_COLOR1;
|
|
|
|
state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] = WINED3D_MCS_COLOR2;
|
|
|
|
state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] = WINED3D_MCS_MATERIAL;
|
|
|
|
state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] = WINED3D_MCS_MATERIAL;
|
2011-12-20 21:42:13 +01:00
|
|
|
state->render_states[WINED3D_RS_VERTEXBLEND] = WINED3D_VBF_DISABLE;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_CLIPPLANEENABLE] = 0;
|
|
|
|
state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING] = FALSE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSIZE] = tmpfloat.d;
|
2009-10-20 10:26:06 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSIZE_MIN] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_POINTSPRITEENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_POINTSCALEENABLE] = FALSE;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSCALE_A] = tmpfloat.d;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSCALE_B] = tmpfloat.d;
|
2006-07-21 05:05:22 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSCALE_C] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS] = TRUE;
|
|
|
|
state->render_states[WINED3D_RS_MULTISAMPLEMASK] = 0xffffffff;
|
2012-01-04 23:34:56 +01:00
|
|
|
state->render_states[WINED3D_RS_PATCHEDGESTYLE] = WINED3D_PATCH_EDGE_DISCRETE;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_PATCHSEGMENTS] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_DEBUGMONITORTOKEN] = 0xbaadcafe;
|
2009-10-29 10:37:10 +01:00
|
|
|
tmpfloat.f = gl_info->limits.pointsize_max;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_POINTSIZE_MAX] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_INDEXEDVERTEXBLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_COLORWRITEENABLE] = 0x0000000f;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_TWEENFACTOR] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_BLENDOP] = WINED3D_BLEND_OP_ADD;
|
|
|
|
state->render_states[WINED3D_RS_POSITIONDEGREE] = WINED3D_DEGREE_CUBIC;
|
|
|
|
state->render_states[WINED3D_RS_NORMALDEGREE] = WINED3D_DEGREE_LINEAR;
|
2005-07-05 16:05:18 +02:00
|
|
|
/* states new in d3d9 */
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_SCISSORTESTENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS] = 0;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_MINTESSELLATIONLEVEL] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_MAXTESSELLATIONLEVEL] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE] = FALSE;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_ADAPTIVETESS_X] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_ADAPTIVETESS_Y] = tmpfloat.d;
|
2005-07-05 16:05:18 +02:00
|
|
|
tmpfloat.f = 1.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_ADAPTIVETESS_Z] = tmpfloat.d;
|
2004-12-13 14:35:38 +01:00
|
|
|
tmpfloat.f = 0.0f;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_ADAPTIVETESS_W] = tmpfloat.d;
|
|
|
|
state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE] = FALSE;
|
2012-01-03 23:06:55 +01:00
|
|
|
state->render_states[WINED3D_RS_CCW_STENCILFAIL] = WINED3D_STENCIL_OP_KEEP;
|
|
|
|
state->render_states[WINED3D_RS_CCW_STENCILZFAIL] = WINED3D_STENCIL_OP_KEEP;
|
|
|
|
state->render_states[WINED3D_RS_CCW_STENCILPASS] = WINED3D_STENCIL_OP_KEEP;
|
2011-12-20 21:42:14 +01:00
|
|
|
state->render_states[WINED3D_RS_CCW_STENCILFUNC] = WINED3D_CMP_ALWAYS;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_COLORWRITEENABLE1] = 0x0000000f;
|
|
|
|
state->render_states[WINED3D_RS_COLORWRITEENABLE2] = 0x0000000f;
|
|
|
|
state->render_states[WINED3D_RS_COLORWRITEENABLE3] = 0x0000000f;
|
2012-07-20 00:24:27 +02:00
|
|
|
state->render_states[WINED3D_RS_BLENDFACTOR] = 0xffffffff;
|
2011-12-19 21:00:09 +01:00
|
|
|
state->render_states[WINED3D_RS_SRGBWRITEENABLE] = 0;
|
|
|
|
state->render_states[WINED3D_RS_DEPTHBIAS] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP8] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP9] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP10] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP11] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP12] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP13] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP14] = 0;
|
|
|
|
state->render_states[WINED3D_RS_WRAP15] = 0;
|
|
|
|
state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE] = FALSE;
|
|
|
|
state->render_states[WINED3D_RS_SRCBLENDALPHA] = WINED3D_BLEND_ONE;
|
|
|
|
state->render_states[WINED3D_RS_DESTBLENDALPHA] = WINED3D_BLEND_ZERO;
|
|
|
|
state->render_states[WINED3D_RS_BLENDOPALPHA] = WINED3D_BLEND_OP_ADD;
|
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);
|
2012-05-03 21:49:38 +02:00
|
|
|
memcpy(&state->transforms[WINED3D_TS_TEXTURE0 + i], &identity, sizeof(identity));
|
2012-01-10 20:37:01 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_COLOR_OP] = i ? WINED3D_TOP_DISABLE : WINED3D_TOP_MODULATE;
|
2012-01-09 22:16:51 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_COLOR_ARG1] = WINED3DTA_TEXTURE;
|
|
|
|
state->texture_states[i][WINED3D_TSS_COLOR_ARG2] = WINED3DTA_CURRENT;
|
2012-01-10 20:37:01 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_ALPHA_OP] = i ? WINED3D_TOP_DISABLE : WINED3D_TOP_SELECT_ARG1;
|
2012-01-09 22:16:51 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] = WINED3DTA_TEXTURE;
|
|
|
|
state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_MAT00] = 0;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_MAT01] = 0;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_MAT10] = 0;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_MAT11] = 0;
|
|
|
|
state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] = i;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_LSCALE] = 0;
|
|
|
|
state->texture_states[i][WINED3D_TSS_BUMPENV_LOFFSET] = 0;
|
2012-01-09 22:16:52 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS] = WINED3D_TTFF_DISABLE;
|
2012-01-09 22:16:51 +01:00
|
|
|
state->texture_states[i][WINED3D_TSS_COLOR_ARG0] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] = WINED3DTA_CURRENT;
|
|
|
|
state->texture_states[i][WINED3D_TSS_RESULT_ARG] = WINED3DTA_CURRENT;
|
2010-09-27 12:07:56 +02:00
|
|
|
}
|
|
|
|
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);
|
2012-01-10 20:37:02 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_ADDRESS_U] = WINED3D_TADDRESS_WRAP;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_ADDRESS_V] = WINED3D_TADDRESS_WRAP;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_ADDRESS_W] = WINED3D_TADDRESS_WRAP;
|
2012-01-08 21:14:59 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_BORDER_COLOR] = 0;
|
2012-01-12 21:43:12 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] = WINED3D_TEXF_POINT;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] = WINED3D_TEXF_POINT;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] = WINED3D_TEXF_NONE;
|
2012-01-08 21:14:59 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_MIPMAP_LOD_BIAS] = 0;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_MAX_MIP_LEVEL] = 0;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_MAX_ANISOTROPY] = 1;
|
|
|
|
state->sampler_states[i][WINED3D_SAMP_SRGB_TEXTURE] = 0;
|
2010-09-16 11:19:58 +02:00
|
|
|
/* TODO: Indicates which element of a multielement texture to use. */
|
2012-01-08 21:14:59 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_ELEMENT_INDEX] = 0;
|
2010-09-16 11:19:58 +02:00
|
|
|
/* TODO: Vertex offset in the presampled displacement map. */
|
2012-01-08 21:14:59 +01:00
|
|
|
state->sampler_states[i][WINED3D_SAMP_DMAP_OFFSET] = 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 */
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, 0, &swapchain);
|
2010-09-14 13:38:39 +02:00
|
|
|
if (SUCCEEDED(hr) && swapchain)
|
|
|
|
{
|
2012-01-06 11:20:06 +01:00
|
|
|
hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer);
|
2009-06-15 09:06:50 +02:00
|
|
|
if (SUCCEEDED(hr) && backbuffer)
|
|
|
|
{
|
2011-03-08 19:41:05 +01:00
|
|
|
struct wined3d_resource_desc desc;
|
2009-06-15 09:06:50 +02:00
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_resource_get_desc(&backbuffer->resource, &desc);
|
|
|
|
wined3d_surface_decref(backbuffer);
|
2008-08-31 12:20:28 +02:00
|
|
|
|
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 */
|
2011-11-21 18:48:40 +01:00
|
|
|
state->viewport.x = 0;
|
|
|
|
state->viewport.y = 0;
|
2011-12-02 08:15:52 +01:00
|
|
|
state->viewport.width = swapchain->desc.backbuffer_width;
|
|
|
|
state->viewport.height = swapchain->desc.backbuffer_height;
|
2011-11-21 18:48:40 +01:00
|
|
|
state->viewport.min_z = 0.0f;
|
|
|
|
state->viewport.max_z = 1.0f;
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2008-08-31 12:20:28 +02:00
|
|
|
}
|
|
|
|
|
2010-09-27 12:07:56 +02:00
|
|
|
TRACE("Done.\n");
|
2004-10-21 22:59:12 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 21:18:47 +02:00
|
|
|
static HRESULT stateblock_init(struct wined3d_stateblock *stateblock,
|
2012-01-17 21:13:39 +01:00
|
|
|
struct wined3d_device *device, enum wined3d_stateblock_type 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->ref = 1;
|
2009-12-09 20:32:08 +01:00
|
|
|
stateblock->device = device;
|
2009-09-29 11:09:04 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-01-17 21:13:39 +01:00
|
|
|
/* The WINED3D_SBT_INIT stateblock type is used during initialization to
|
2009-09-29 11:09:04 +02:00
|
|
|
* produce a placeholder stateblock so other functions called can update a
|
|
|
|
* state block. */
|
2012-01-17 21:13:39 +01:00
|
|
|
if (type == WINED3D_SBT_INIT || type == WINED3D_SBT_RECORDED) return WINED3D_OK;
|
2009-09-29 11:09:04 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-01-17 21:13:39 +01:00
|
|
|
case WINED3D_SBT_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
|
|
|
|
2012-01-17 21:13:39 +01:00
|
|
|
case WINED3D_SBT_PIXEL_STATE:
|
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
|
|
|
|
2012-01-17 21:13:39 +01:00
|
|
|
case WINED3D_SBT_VERTEX_STATE:
|
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);
|
2011-01-28 20:05:41 +01:00
|
|
|
wined3d_stateblock_capture(stateblock);
|
2009-09-29 11:09:04 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_stateblock_create(struct wined3d_device *device,
|
2012-01-17 21:13:39 +01:00
|
|
|
enum wined3d_stateblock_type type, struct wined3d_stateblock **stateblock)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_stateblock *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("device %p, type %#x, stateblock %p.\n",
|
|
|
|
device, type, stateblock);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate stateblock memory.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = stateblock_init(object, device, type);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize stateblock, hr %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created stateblock %p.\n", object);
|
|
|
|
*stateblock = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|