From 9a889f6b0b1393609eba09383ef7d88afa83afbc Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 2 Jan 2009 16:19:12 +0100 Subject: [PATCH] wined3d: Convert textures to a bitmap in struct SAVEDSTATES. --- dlls/wined3d/device.c | 2 +- dlls/wined3d/stateblock.c | 35 ++++++++++++++++++---------------- dlls/wined3d/wined3d_private.h | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index a0b6d1ffc6e..1ce2287a871 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4541,7 +4541,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetTexture(IWineD3DDevice *iface, DWORD TRACE("GL_LIMITS %d\n",GL_LIMITS(sampler_stages)); TRACE("(%p) : oldtexture(%p)\n", This,oldTexture); - This->updateStateBlock->changed.textures[Stage] = TRUE; + This->updateStateBlock->changed.textures |= 1 << Stage; TRACE("(%p) : setting new texture to %p\n", This, pTexture); This->updateStateBlock->textures[Stage] = pTexture; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 2923d501fa0..1ffdabe1933 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -88,7 +88,7 @@ static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES * /* Fixed size arrays */ dest->streamSource = source->streamSource; dest->streamFreq = source->streamFreq; - memcpy(dest->textures, source->textures, bsize * MAX_COMBINED_SAMPLERS); + dest->textures = source->textures; memcpy(dest->transform, source->transform, bsize * (HIGHEST_TRANSFORMSTATE + 1)); memcpy(dest->renderState, source->renderState, bsize * (WINEHIGHEST_RENDER_STATE + 1)); memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)); @@ -125,7 +125,7 @@ void stateblock_savedstates_set( /* Fixed size arrays */ states->streamSource = value ? 0xffff : 0; states->streamFreq = value ? 0xffff : 0; - memset(states->textures, value, bsize * MAX_COMBINED_SAMPLERS); + states->textures = value ? 0xfffff : 0; memset(states->transform, value, bsize * (HIGHEST_TRANSFORMSTATE + 1)); memset(states->renderState, value, bsize * (WINEHIGHEST_RENDER_STATE + 1)); memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)); @@ -574,11 +574,13 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface) /* Samplers */ /* TODO: move over to using memcpy */ - for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) { - if (This->changed.textures[j]) { - TRACE("Updating texture %u to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]); - This->textures[j] = targetStateBlock->textures[j]; - } + map = This->changed.textures; + for (i = 0; map; map >>= 1, ++i) + { + if (!(map & 1)) continue; + + TRACE("Updating texture %u to %p (was %p)\n", i, targetStateBlock->textures[i], This->textures[i]); + This->textures[i] = targetStateBlock->textures[i]; } for (j = 0; j < This->num_contained_sampler_states; j++) { @@ -832,14 +834,15 @@ should really perform a delta so that only the changes get updated*/ { if (map & 1) IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]); } - for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){ - if (This->changed.textures[j]) { - if (j < MAX_FRAGMENT_SAMPLERS) { - IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]); - } else { - IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]); - } - } + + map = This->changed.textures; + for (i = 0; map; map >>= 1, ++i) + { + if (!(map & 1)) continue; + + if (i < MAX_FRAGMENT_SAMPLERS) IWineD3DDevice_SetTexture(pDevice, i, This->textures[i]); + else IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + i - MAX_FRAGMENT_SAMPLERS, + This->textures[i]); } map = This->changed.clipplane; @@ -1239,7 +1242,7 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStat for(i = 0; i < GL_LIMITS(textures); i++) { /* Note: This avoids calling SetTexture, so pretend it has been called */ - This->changed.textures[i] = TRUE; + This->changed.textures |= 1 << i; This->textures[i] = NULL; } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 010f0974c2c..90f8ee147a5 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1760,7 +1760,7 @@ extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl; typedef struct SAVEDSTATES { WORD streamSource; /* MAX_STREAMS, 16 */ WORD streamFreq; /* MAX_STREAMS, 16 */ - BOOL textures[MAX_COMBINED_SAMPLERS]; + DWORD textures; /* MAX_COMBINED_SAMPLERS, 20 */ BOOL transform[HIGHEST_TRANSFORMSTATE + 1]; BOOL renderState[WINEHIGHEST_RENDER_STATE + 1]; BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];