[wined3d] texture state sepeartion part2 -02

Oliver Stieber oliver_stieber at yahoo.co.uk
Sun Jul 31 20:22:15 CDT 2005


This time the patch is incremental and requires part 1 to be applied first.

--- Oliver Stieber <oliver_stieber at yahoo.co.uk> wrote:

> Hi,
>    This patch sepeartes the setting of the DirectX texture and sampler states
> from the setting of OpenGL states (now in applyTextureStateState and
> applySamplerState)
> 
> Setting states relating to texture object will be move to basetexture and it's
> descendants in a future patch.
> 
> Also the clearing of the z matrix row in set_texture_matrix has been disabled
> as it was causing some problems.
> 
> 
> 
> 		
> ___________________________________________________________ 
> To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.
http://uk.security.yahoo.com> diff -Nru -X ignore clean/wine/dlls/wined3d/device.c
small-patches/wine/dlls/wined3d/device.c
> --- clean/wine/dlls/wined3d/device.c	2005-07-29 14:08:50.635665384 +0100
> +++ small-patches/wine/dlls/wined3d/device.c	2005-07-31 19:46:12.590784328 +0100
> @@ -62,6 +62,9 @@
>  /* static function declarations */
>  static void WINAPI IWineD3DDeviceImpl_AddResource(IWineD3DDevice *iface, IWineD3DResource
> *resource);
>  
> +static void WINAPI IWineD3DDeviceImpl_ApplyTextureStageState(IWineD3DDevice *iface, DWORD
> Stage, WINED3DTEXTURESTAGESTATETYPE Type);
> +
> +static void WINAPI IWineD3DDeviceImpl_ApplySamplerState(IWineD3DDevice *iface, DWORD Sampler,
> WINED3DSAMPLERSTATETYPE Type);
>  
>  /* helper macros */
>  #define D3DMEMCHECK(object, ppResult) if(NULL == object) { *ppResult = NULL; WARN("Out of
> memory\n"); return D3DERR_OUTOFVIDEOMEMORY;}
> @@ -224,7 +227,6 @@
>      IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
>      int i = 0;
>      float col[4];
> -    BOOL changeTexture = TRUE;
>  
>      TRACE("-----------------------> Updating the texture at stage %ld to have new texture state
> information\n", Stage);
>      for (i = 1; i < WINED3D_HIGHEST_TEXTURE_STATE; i++) {
> @@ -254,11 +256,11 @@
>               of these, which is what the Flags allows                                     */
>          case WINED3DTSS_COLOROP:
>          case WINED3DTSS_TEXCOORDINDEX:
> -            if (!(Flags == REAPPLY_ALL)) skip=TRUE;
> +            if (!(Flags == REAPPLY_ALL)) skip = TRUE;
>              break;
>  
>          case WINED3DTSS_ALPHAOP:
> -            if (!(Flags & REAPPLY_ALPHAOP)) skip=TRUE;
> +            if (!(Flags & REAPPLY_ALPHAOP)) skip = TRUE;
>              break;
>  
>          default:
> @@ -266,25 +268,14 @@
>          }
>  
>          if (skip == FALSE) {
> -           /* Performance: Only change to this texture if we have to */
> -           if (changeTexture) {
> -               /* Make appropriate texture active */
> -               if (GL_SUPPORT(ARB_MULTITEXTURE)) {
> -                   GLACTIVETEXTURE(Stage);
> -                } else if (Stage > 0) {
> -                    FIXME("Program using multiple concurrent textures which this opengl
> implementation doesn't support\n");
> -                }
> -                changeTexture = FALSE;
> -           }
> -
>             /* Now apply the change */
> -           IWineD3DDevice_SetTextureStageState(iface, Stage, i,
> This->stateBlock->textureState[Stage][i]);
> +           IWineD3DDeviceImpl_ApplyTextureStageState(iface, Stage, i);
>          }
>      }
>  
>      /* apply the sampler states to the texture */
> -    for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE;i++) {
> -      IWineD3DDevice_SetSamplerState(iface, Stage, i,
> This->stateBlock->samplerState[Stage][i]);
> +    for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; i++) {
> +        IWineD3DDeviceImpl_ApplySamplerState(iface, Stage, i);
>      }
>  
>      /* Note the D3DRS value applies to all textures, but GL has one
> @@ -432,7 +423,7 @@
>  
>      IWineD3DDeviceImpl     *This = (IWineD3DDeviceImpl *)iface;
>      IWineD3DStateBlockImpl *object;
> -    int i,j;
> +    int i;
>  
>      D3DCREATEOBJECTINSTANCE(object, StateBlock)
>      object->blockType     = Type;
> @@ -472,38 +463,15 @@
>          for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
>              object->changed.renderState[SavedPixelStates_R[i]] = TRUE;
>          }
> -        for (j = 0; j < GL_LIMITS(textures); i++) {
> -            for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
> -                object->changed.textureState[j][SavedPixelStates_T[i]] = TRUE;
> -            }
> -        }
> -        /* Setting sampler block changes states */
> -        for (j = 0 ; j < GL_LIMITS(samplers); j++) {
> -            for (i =0; i < NUM_SAVEDPIXELSTATES_S;i++) {
>  
> -                object->changed.samplerState[j][SavedPixelStates_S[i]] = TRUE;
> -            }
> -        }
>      } else if (Type == WINED3DSBT_VERTEXSTATE) {
>  
>          memset(&object->changed, FALSE, sizeof(This->stateBlock->changed));
> -
>          /* TODO: Vertex Shader Constants */
>          object->changed.vertexShader = TRUE;
>          for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
>              object->changed.renderState[SavedVertexStates_R[i]] = TRUE;
>          }
> -        for (j = 0; j < GL_LIMITS(textures); i++) {
> -            for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
> -                object->changed.textureState[j][SavedVertexStates_T[i]] = TRUE;
> -            }
> -        }
> -        /* Setting sampler block changes states */
> -        for (j = 0 ; j < GL_LIMITS(samplers); j++) {
> -            for (i =0; i < NUM_SAVEDVERTEXSTATES_S;i++) {
> -                object->changed.samplerState[j][SavedVertexStates_S[i]] = TRUE;
> -            }
> -        }
>  
>      /* Duplicate light chain */
>      {
> @@ -1637,13 +1605,7 @@
>      ENTER_GL();
>  
>      if (d3dts >= D3DTS_TEXTURE0 && d3dts <= D3DTS_TEXTURE7) { /* handle texture matrices */
> -        if (d3dts < GL_LIMITS(textures)) {
> -            int tex = d3dts - D3DTS_TEXTURE0;
> -            GLACTIVETEXTURE(tex);
> -            set_texture_matrix((float *)lpmatrix,
> -                              
> This->updateStateBlock->textureState[tex][WINED3DTSS_TEXTURETRANSFORMFLAGS],
> (This->stateBlock->textureState[tex][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) !=
> D3DTSS_TCI_PASSTHRU);
> -        }
> -
> +        /* This is now set with the texture unit states, it may be a good idea to flag the
> change though! */
>      } else if (d3dts == D3DTS_VIEW) { /* handle the VIEW matrice */
>          unsigned int k;
>  
> @@ -3294,8 +3256,15 @@
>      return D3D_OK;
>  }
>  
> -HRESULT WINAPI IWineD3DDeviceImpl_SetSamplerState(IWineD3DDevice *iface, DWORD Sampler,
> WINED3DSAMPLERSTATETYPE Type, DWORD Value) {
> +/*****
> + * Apply / Get / Set Sampler States
> + * TODO: Verify against dx9 definitions
> + *****/
> +
> +/* NOTE: It is expected that this function is called a number of times in a row for the same
> texture unit, so it is more efficient if the caller sets the active texture unit before calling
> this function. set the correct Texture unit active before calling ApplySamplerState */
> +static void WINAPI IWineD3DDeviceImpl_ApplySamplerState(IWineD3DDevice *iface, DWORD Sampler,
> WINED3DSAMPLERSTATETYPE Type) {
>      IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
> +    DWORD Value = This->stateBlock->samplerState[Sampler][Type];
>      /**
>      * SetSampler is designed to allow for more than the standard up to 8 textures
>      *  and Geforce has stopped supporting more than 6 standard textures in openGL.
> @@ -3318,33 +3287,16 @@
>      TRACE("(%p) Sampler(%ld), Type(%d) Value(%ld)\n",This, Sampler ,Type, Value);
>  
>      if(Sampler >  GL_LIMITS(samplers) || Sampler < 0 || Type > WINED3D_HIGHEST_SAMPLER_STATE ||
> Type < 0) {
> -        FIXME("out of range %d %d sampler %ld type %u\n", GL_LIMITS(samplers),
> WINED3D_HIGHEST_SAMPLER_STATE, Sampler, Type);
> -        return D3DERR_INVALIDCALL;
> +        return;
>      }
>  
> -    This->updateStateBlock->changed.samplerState[Sampler][Type] = TRUE;
> -    This->updateStateBlock->set.samplerState[Sampler][Type]     = TRUE;
>      TRACE("Setting sampler %ld %d to %ld \n", Sampler, Type, Value);
> -    This->updateStateBlock->samplerState[Sampler][Type]         = Value;
> -
> -    /* Handle recording of state blocks */
> -    if (This->isRecordingState) {
> -        TRACE("Recording... not performing anything\n");
> -        return D3D_OK;
> -    }
>  
>      /* In addition, IDirect3DDevice9::SetSamplerState will now be used for filtering, tiling,
>      clamping, MIPLOD, etc. This will work for up to 16 samplers.
>      is this just GL_TEXTURE_2D or is it GL_TEXTURE_1D and GL_TEXTURE_3D as well?
>      */
>      ENTER_GL();
> -    VTRACE(("Activating appropriate texture state %ld\n", Sampler));
> -    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
> -        GLACTIVETEXTURE(Sampler);
> -    } else if (Sampler > 0) {
> -        FIXME("Program using multiple concurrent textures which this opengl implementation
> doesn't support\n");
> -    }
> -
>  
>      switch (Type) {
>  
> @@ -3582,6 +3534,40 @@
>          TRACE("invalid sampler setting, Sampler=%ld, Type=%d, Value =%ld\n", Sampler, Type,
> Value);
>      };
>      LEAVE_GL();
> +    return;
> +}
> +
> +HRESULT WINAPI IWineD3DDeviceImpl_SetSamplerState(IWineD3DDevice *iface, DWORD Sampler,
> WINED3DSAMPLERSTATETYPE Type, DWORD Value) {
> +    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
> +    /**
> +    * SetSampler is designed to allow for more than the standard up to 8 textures
> +    *  and Geforce has stopped supporting more than 6 standard textures in openGL.
> +    * So I have to use ARB for Gforce. (maybe if the sampler > 4 then use ARB?)
> +    *
> +    * http://developer.nvidia.com/object/General_FAQ.html#t6
> +    *
> +    * There are two new settings for GForce
> +    * the sampler one:
> +    * GL_MAX_TEXTURE_IMAGE_UNITS_ARB
> +    * and the texture one:
> +    * GL_MAX_TEXTURE_COORDS_ARB.
> +    * Ok GForce say it's ok to use glTexParameter/glGetTexParameter(...).
> +     ******************/
> +    TRACE("(%p) Sampler(%ld), Type(%d) Value(%ld)\n",This, Sampler ,Type, Value);
> +
> +    if(Sampler >  GL_LIMITS(samplers) || Sampler < 0 || Type > WINED3D_HIGHEST_SAMPLER_STATE ||
> Type < 0) {
> +         FIXME("out of range %d %d sampler %ld type %u\n", GL_LIMITS(samplers),
> WINED3D_HIGHEST_SAMPLER_STATE, Sampler, Type);
> +        return D3DERR_INVALIDCALL;
> +    }
> +    TRACE("Setting sampler %ld %d to %ld \n", Sampler, Type, Value);
> +    This->updateStateBlock->samplerState[Sampler][Type]         = Value;
> +
> +    /* Handle recording of state blocks */
> +    if (This->isRecordingState) {
> +        TRACE("Recording... not performing anything\n");
> +        return D3D_OK;
> +    }
> +
>      return D3D_OK;
>  }
>  
> @@ -3590,8 +3576,8 @@
>      /** TODO: check that sampler is in  range **/
>      *Value = This->updateStateBlock->samplerState[Sampler][Type];
>      TRACE("(%p) : Sampler %ld Type %u Returning %ld\n", This, Sampler, Type, *Value);
> -    return D3D_OK;
>  
> +    return D3D_OK;
>  }
>  
>  HRESULT WINAPI IWineD3DDeviceImpl_SetScissorRect(IWineD3DDevice *iface, CONST RECT* pRect) {
> @@ -3602,6 +3588,7 @@
>      TRACE("(%p)Setting new Scissor Rect to %ld:%ld-%ld:%ld\n", This, pRect->left, pRect->top,
> pRect->right, pRect->bottom);
>      glScissor(pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top);
>      LEAVE_GL();
> +
>      return D3D_OK;
>  }
>  
> @@ -3796,42 +3783,26 @@
>  }
>  
>  /*****
> - * Get / Set Texture Stage States
> + * Apply / Get / Set Texture Stage States
>   * TODO: Verify against dx9 definitions
>   *****/
> -HRESULT WINAPI IWineD3DDeviceImpl_SetTextureStageState(IWineD3DDevice *iface, DWORD Stage,
> WINED3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
> -    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
>  
> +/* NOTE: It's expected that this function is going to be called lots of times with the same
> stage active, so make it the callers responsibility to GLACTIVETEXTURE(Stage) for better state
> management. Set the correct Texture unit active before callnig ApplyTextureStageState */
> +static void WINAPI IWineD3DDeviceImpl_ApplyTextureStageState(IWineD3DDevice *iface, DWORD
> Stage, WINED3DTEXTURESTAGESTATETYPE Type) {
> +    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
> +    DWORD Value = This->updateStateBlock->textureState[Stage][Type];
>      /* FIXME: Handle 3d textures? What if TSS value set before set texture? Need to reapply all
> values? */
>  
>      TRACE("(%p) : Stage=%ld, Type=%s(%d), Value=%ld\n", This, Stage,
> debug_d3dtexturestate(Type), Type, Value);
>  
> -    /* Reject invalid texture units */
> -    if (Stage >= GL_LIMITS(textures)) {
> +    /* Check that the stage is within limits  */
> +    if (Stage >= GL_LIMITS(textures) || Stage < 0) {
>          TRACE("Attempt to access invalid texture rejected\n");
> -        return D3DERR_INVALIDCALL;
> -    }
> -
> -    This->updateStateBlock->changed.textureState[Stage][Type] = TRUE;
> -    This->updateStateBlock->set.textureState[Stage][Type] = TRUE;
> -    This->updateStateBlock->textureState[Stage][Type] = Value;
> -
> -    /* Handle recording of state blocks */
> -    if (This->isRecordingState) {
> -        TRACE("Recording... not performing anything\n");
> -        return D3D_OK;
> +        return;
>      }
>  
>      ENTER_GL();
>  
> -    /* Make appropriate texture active */
> -    VTRACE(("Activating appropriate texture state %ld\n", Stage));
> -    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
> -        GLACTIVETEXTURE(Stage);
> -    } else if (Stage > 0) {
> -        FIXME("Program using multiple concurrent textures which this opengl implementation
> doesn't support\n");
> -    }
> -
>      switch (Type) {
>      case WINED3DTSS_ALPHAOP               :
>      case WINED3DTSS_COLOROP               :
> @@ -4137,6 +4108,24 @@
>  
>      LEAVE_GL();
>  
> +    return;
> +}
> +
> +HRESULT WINAPI IWineD3DDeviceImpl_SetTextureStageState(IWineD3DDevice *iface, DWORD Stage,
> WINED3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
> +    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
> +
> +    /* FIXME: Handle 3d textures? What if TSS value set before set texture? Need to reapply all
> values? */
> +
> +    TRACE("(%p) : Stage=%ld, Type=%s(%d), Value=%ld\n", This, Stage,
> debug_d3dtexturestate(Type), Type, Value);
> +
> +    /* Reject invalid texture units */
> +    if (Stage >= GL_LIMITS(textures)) {
> +        TRACE("Attempt to access invalid texture rejected\n");
> +        return D3DERR_INVALIDCALL;
> +    }
> +
> +    This->updateStateBlock->textureState[Stage][Type]         = Value;
> +
>      return D3D_OK;
>  }
>  
> @@ -4154,23 +4143,30 @@
>  
>      IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
>      IWineD3DBaseTexture   *oldTexture;
> -    BOOL                   reapplyStates = TRUE;
> -    DWORD                  reapplyFlags = 0;
> -    INT                    oldTextureDimensions = -1;
> -    D3DRESOURCETYPE        textureType;
>  
>      oldTexture = This->updateStateBlock->textures[Stage];
>      TRACE("(%p) : Stage(%ld), Texture (%p)\n", This, Stage, pTexture);
>  
> -    /* Reject invalid texture units */
> -    if (Stage >= GL_LIMITS(textures)) {
> -        TRACE("Attempt to access invalid texture rejected\n");
> +#if 0 /* TODO: check so vertex textures */
> +    if (Stage >= D3DVERTEXTEXTURESAMPLER && Stage <= D3DVERTEXTEXTURESAMPLER3){
> +        This->updateStateBlock->vertexTextures[Stage - D3DVERTEXTEXTURESAMPLER] = pTexture;
> +        return D3D_OK;
> +    }
> +#endif
> +
> +    if (Stage >= GL_LIMITS(textures) || Stage < 0) {
> +        WARN("Attempt to access invalid texture rejected\n");
>          return D3DERR_INVALIDCALL;
>      }
>  
> -    This->updateStateBlock->set.textures[Stage] = TRUE;
> +    oldTexture = This->updateStateBlock->textures[Stage];
> +    TRACE("GL_LIMITS %d\n",GL_LIMITS(textures));
> +    TRACE("(%p) : oldtexture(%p)\n", This,oldTexture);
> +
> +    This->updateStateBlock->set.textures[Stage]     = TRUE;
>      This->updateStateBlock->changed.textures[Stage] = TRUE;
> -    This->updateStateBlock->textures[Stage] = pTexture;
> +    TRACE("(%p) : setting new texture to %p\n", This, pTexture);
> +    This->updateStateBlock->textures[Stage]         = pTexture;
>  
>      /* Handle recording of state blocks */
>      if (This->isRecordingState) {
> @@ -4178,18 +4174,6 @@
>          return D3D_OK;
>      }
>  
> -    oldTextureDimensions = This->updateStateBlock->textureDimensions[Stage];
> -
> -    ENTER_GL();
> -
> -    /* Make appropriate texture active */
> -    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
> -        GLACTIVETEXTURE(Stage);
> -
> -    } else if (Stage>0) {
> -        FIXME("Program using multiple concurrent textures which this opengl implementation
> doesn't support\n");
> -    }
> -
>      /** NOTE: MSDN says that setTexture increases the reference count,
>      * and the the application nust set the texture back to null (or have a leaky application),
>      * This means we should pass the refcount upto the parent
> @@ -4197,7 +4181,7 @@
>      if (NULL != This->updateStateBlock->textures[Stage]) {
>          IUnknown *textureParent;
>          IWineD3DBaseTexture_GetParent(This->updateStateBlock->textures[Stage], (IUnknown
> **)&textureParent);
> -        /** NOTE: GetParent will increase the ref count for me, I won't clean up untill the
> texture is set to NULL **/
> +        /** NOTE: GetParent will increase the ref count for me, I won't clean up until the
> texture is set to NULL **/
>      }
>  
>      if (NULL != oldTexture) {
> @@ -4208,102 +4192,6 @@
>          oldTexture = NULL;
>      }
>  
> -
> -    if (NULL != pTexture) {
> -        /* Now setup the texture appropraitly */
> -        textureType = IWineD3DBaseTexture_GetType(pTexture);
> -
> -        if (textureType == D3DRTYPE_TEXTURE) {
> -
> -          if (oldTexture == pTexture && !IWineD3DBaseTexture_GetDirty(pTexture)) {
> -            TRACE("Skipping setting texture as old == new\n");
> -            reapplyStates = FALSE;
> -
> -          } else {
> -
> -            /* Standard 2D texture */
> -            TRACE("Standard 2d texture\n");
> -            This->updateStateBlock->textureDimensions[Stage] = GL_TEXTURE_2D;
> -
> -            /* Load up the texture now */
> -            IWineD3DTexture_PreLoad((IWineD3DTexture *) pTexture);
> -          }
> -
> -        } else if (textureType == D3DRTYPE_VOLUMETEXTURE) {
> -
> -          if (oldTexture == pTexture && !IWineD3DBaseTexture_GetDirty(pTexture)) {
> -              TRACE("Skipping setting texture as old == new\n");
> -              reapplyStates = FALSE;
> -
> -          } else {
> -
> -              /* Standard 3D (volume) texture */
> -              TRACE("Standard 3d texture\n");
> -              This->updateStateBlock->textureDimensions[Stage] = GL_TEXTURE_3D;
> -
> -              /* Load up the texture now */
> -              IWineD3DVolumeTexture_PreLoad((IWineD3DVolumeTexture *) pTexture);
> -          }
> -
> -        } else if (textureType == D3DRTYPE_CUBETEXTURE) {
> -
> -            if (oldTexture == pTexture && !IWineD3DBaseTexture_GetDirty(pTexture)) {
> -                TRACE("Skipping setting texture as old == new\n");
> -                reapplyStates = FALSE;
> -
> -            } else {
> -
> -                /* Standard Cube texture */
> -                TRACE("Standard Cube texture\n");
> -                This->updateStateBlock->textureDimensions[Stage] = GL_TEXTURE_CUBE_MAP_ARB;
> -
> -                /* Load up the texture now */
> -                IWineD3DCubeTexture_PreLoad((IWineD3DCubeTexture *) pTexture);
> -            }
> -
> -        } else {
> -            FIXME("(%p) : Incorrect type for a texture : (%d,%s)\n", This, textureType,
> debug_d3dresourcetype(textureType));
> -        }
> -
> -    } else {
> -
> -        TRACE("Setting to no texture (ie default texture)\n");
> -        This->updateStateBlock->textureDimensions[Stage] = GL_TEXTURE_1D;
> -        glBindTexture(GL_TEXTURE_1D, This->dummyTextureName[Stage]);
> -        checkGLcall("glBindTexture");
> -        TRACE("Bound dummy Texture to stage %ld (gl name %d)\n", Stage,
> This->dummyTextureName[Stage]);
> -    }
> -
> -    /* Disable the old texture binding and enable the new one (unless operations are disabled)
> */
> -    if (oldTextureDimensions != This->updateStateBlock->textureDimensions[Stage]) {
> -
> -       glDisable(oldTextureDimensions);
> -       checkGLcall("Disable oldTextureDimensions");
> -
> -       if (This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP] != D3DTOP_DISABLE) {
> -          glEnable(This->updateStateBlock->textureDimensions[Stage]);
> -          checkGLcall("glEnable new texture dimensions");
> -       }
> -
> -       /* If Alpha arg1 is texture then handle the special case when there changes between a
> -          texture and no texture - See comments in set_tex_op                                 
> */
> -       if ((This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAARG1] == D3DTA_TEXTURE) &&
> -           (((oldTexture == NULL) && (pTexture != NULL)) || ((pTexture == NULL) && (oldTexture
> != NULL))))
> -       {
> -           reapplyFlags |= REAPPLY_ALPHAOP;
> -       }
> -    }
> -
> -
> -    /* Even if the texture has been set to null, reapply the stages as a null texture to
> directx requires
> -       a dummy texture in opengl, and we always need to ensure the current view of the
> TextureStates apply */
> -    if (reapplyStates) {
> -       IWineD3DDeviceImpl_SetupTextureStates(iface, Stage, reapplyFlags);
> -    }
> -
> -    LEAVE_GL();
> -    TRACE("Texture now fully setup\n");
> -
>      return D3D_OK;
>  }
>  
> @@ -5569,7 +5457,7 @@
>              newContext->drawable  = glXCreatePbuffer(impSwapChain->display, cfgs[0], attribs);
>  
>              /** ****************************************
> -            *GLX1.3 isn't supported by XFree 'yet' untill that point ATI emulates pBuffers
> +            *GLX1.3 isn't supported by XFree 'yet' until that point ATI emulates pBuffers
>              *they note:
>              *   In future releases, we may provide the calls glXCreateNewContext,
>              *   glXQueryDrawable and glXMakeContextCurrent.
> diff -Nru -X ignore clean/wine/dlls/wined3d/drawprim.c
> small-patches/wine/dlls/wined3d/drawprim.c
> --- clean/wine/dlls/wined3d/drawprim.c	2005-07-25 16:58:09.066717112 +0100
> +++ small-patches/wine/dlls/wined3d/drawprim.c	2005-07-31 17:30:55.139747064 +0100
> @@ -1620,29 +1620,104 @@
>  
>  }
>  
> -/* loads any dirty textures and returns true if any of the textures are nonpower2 */
> +/**
> +* OK, here we clear down any old junk iect in the context
> +* enable the new texture and apply any state changes:
> +*
> +* Loop through all textures
> +* select texture unit
> +* if there is a texture bound to that unit then..
> +* disable all textures types on that unit
> +* enable and bind the texture that is bound to that unit.
> +* otherwise dissable all texture types on that unit.
> +**/
>  BOOL inline drawPrimitiveUploadDirtyTextures(IWineD3DDeviceImpl* This) {
>      BOOL nonPower2 = FALSE;
>      unsigned int i;
> -    register IWineD3DBaseTexture *texture;
> -    /* And re-upload any dirty textures */
> -    for (i = 0; i<GL_LIMITS(textures); ++i) {
> -        texture = This->stateBlock->textures[i];
> -        if (texture != NULL) {
> -            if(IWineD3DBaseTexture_GetDirty(texture)) {
> +    /* upload the textures */
> +    for (i = 0; i< GL_LIMITS(textures); ++i) {
> +        /* Bind the texture to the stage here */
> +        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
> +            GLACTIVETEXTURE(i);
> +        } else if (0 < i) {
> +            /* This isn't so much a warn as a message to the user about lack of hardware
> support */
> +            WARN("Program using multiple concurrent textures which this opengl implementation
> doesn't support\n");
> +        }
> +
> +        /* don't bother with textures that have a colorop of disable */
> +        if (This->stateBlock->textureState[i][WINED3DTSS_COLOROP] != D3DTOP_DISABLE) {
> +            if (This->stateBlock->textures[i] != NULL) {
> +                /* check to see if any of the texturs are non-power2 */
> +                if (IWineD3DResourceImpl_GetType((IWineD3DResource
> *)This->stateBlock->textures[i]) == D3DRTYPE_TEXTURE) {
> +                    IWineD3DSurface *surface;
> +                    IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture
> *)This->stateBlock->textures[i], 0, &surface);
> +                    if (((IWineD3DSurfaceImpl *)surface)->nonpow2) {
> +                        nonPower2 = TRUE;
> +                    }
> +                }
> +
> +                glDisable(GL_TEXTURE_1D);
> +                This->stateBlock->textureDimensions[i] =
> IWineD3DBaseTexture_GetTextureDimensions(This->stateBlock->textures[i]);
> +                /* disable all texture states that aren't the selected textures' dimension */
> +                switch(This->stateBlock->textureDimensions[i]) {
> +                case GL_TEXTURE_2D:
> +                    glDisable(GL_TEXTURE_3D);
> +                    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
> +                break;
> +                case GL_TEXTURE_3D:
> +                    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
> +                    glDisable(GL_TEXTURE_2D);
> +                break;
> +                case GLTEXTURECUBEMAP:
> +                    glDisable(GL_TEXTURE_2D);
> +                    glDisable(GL_TEXTURE_3D);
> +                break;
> +                }
> +                /* imply GL_SUPPORT(NV_TEXTURE_SHADER) when setting texture_shader_active */
> +                if (This->texture_shader_active && This->stateBlock->textureDimensions[i] ==
> GL_TEXTURE_2D) {
> +                    glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
> +                } else {
> +                    glEnable(This->stateBlock->textureDimensions[i]);
> +                }
>                  /* Load up the texture now */
> -                IWineD3DTexture_PreLoad((IWineD3DTexture *)texture);
> +                IWineD3DBaseTexture_PreLoad((IWineD3DBaseTexture *)
> This->stateBlock->textures[i]);
> +                IWineD3DDevice_SetupTextureStates((IWineD3DDevice *)This, i, REAPPLY_ALPHAOP);
> +                /* this is a stub function representing the state blocks being seperated here
> we are only updating the texture state changes, other objects and units get updated when they
> change (or need to be updated), e.g. states that relate to a context member line the texture
> unit are only updated when the context needs updating */
> +#if 0 /* TODO: move the setting of states over to base texture */
> +                IWineD3DBaseTexture_ApplyStateChanges(This->stateBlock->textures[i],
> This->stateBlock->textureState[i], This->stateBlock->samplerState[i]);
> +#endif
>              }
> -            if (IWineD3DResourceImpl_GetType((IWineD3DResource *)texture) == D3DRTYPE_TEXTURE)
> {
> -                /* TODO: Is this right, as its cast all texture types to texture8... checkme */
> -                IWineD3DSurface *surface;
> -                IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture *)texture, 0, &surface);
> -                if (((IWineD3DSurfaceImpl *)surface)->nonpow2) {
> -                    nonPower2 = TRUE;
> -                }
> +            /* Bind a default texture if no texture has been set, but colour-op is enabled */
> +            else {
> +                glDisable(GL_TEXTURE_2D);
> +                glDisable(GL_TEXTURE_3D);
> +                glDisable(GL_TEXTURE_CUBE_MAP_ARB);
> +                glEnable(GL_TEXTURE_1D);
> +                This->stateBlock->textureDimensions[i] = GL_TEXTURE_1D;
> +                glBindTexture(GL_TEXTURE_1D, This->dummyTextureName[i]);
>              }
> +/** these ops apply to the texture unit, so they are preseved between texture changes, but for
> now brute force and reapply all
> +        dx9_1pass_emboss_bump_mapping and dx9_2pass_emboss_bump_mapping are good texts to make
> sure the states are being applied when needed **/
> +            set_tex_op((IWineD3DDevice *)This, FALSE, i,
> This->stateBlock->textureState[i][WINED3DTSS_COLOROP],
> +                        This->stateBlock->textureState[i][WINED3DTSS_COLORARG1],
> +                        This->stateBlock->textureState[i][WINED3DTSS_COLORARG2],
> +                        This->stateBlock->textureState[i][WINED3DTSS_COLORARG0]);
> +            /* alphaop */
> +            set_tex_op((IWineD3DDevice *)This, TRUE, i,
> This->stateBlock->textureState[i][WINED3DTSS_ALPHAOP],
> +                        This->stateBlock->textureState[i][WINED3DTSS_ALPHAARG1],
> +                        This->stateBlock->textureState[i][WINED3DTSS_ALPHAARG2],
> +                        This->stateBlock->textureState[i][WINED3DTSS_ALPHAARG0]);
> +        } else {
> +
> +            /* no colorop so disable all the texture states */
> +            glDisable(GL_TEXTURE_1D);
> +            glDisable(GL_TEXTURE_2D);
> +            glDisable(GL_TEXTURE_3D);
> +            glDisable(GL_TEXTURE_CUBE_MAP_ARB);
>          }
> +
>      }
> +
>      return nonPower2;
>  }
>  
> diff -Nru -X ignore clean/wine/dlls/wined3d/stateblock.c
> small-patches/wine/dlls/wined3d/stateblock.c
> --- clean/wine/dlls/wined3d/stateblock.c	2005-07-27 15:26:54.113429152 +0100
> +++ small-patches/wine/dlls/wined3d/stateblock.c	2005-07-31 18:58:24.336825208 +0100
> @@ -284,16 +284,11 @@
>          /* FIXME: textures are upto MAX_SAMPLERS for d3d9? */
>          /* Texture */
>          for (j = 0; j < GL_LIMITS(textures); j++) {
> +            /* TODO: move over to using memcpy */
>              for (i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE ; i++) {
> -
> -                if (This->set.textureState[j][i] && (This->textureState[j][i] !=
> -                                                                   
> targetStateBlock->textureState[j][i])) {
> -                    TRACE("Updating texturestagestate %d,%d to %ld (was %ld)\n", j,i,
> targetStateBlock->textureState[j][i],
> -                    This->textureState[j][i]);
> -                    This->textureState[j][i] =  targetStateBlock->textureState[j][i];
> -                    This->renderState[i] = targetStateBlock->renderState[i];
> -                }
> -
> +                TRACE("Updating texturestagestate %d,%d to %ld (was %ld)\n", j,i,
> targetStateBlock->textureState[j][i],
> +                This->textureState[j][i]);
> +                This->textureState[j][i] =  targetStateBlock->textureState[j][i];
>              }
>  
>              if ((This->set.textures[j] && (This->textures[j] !=
> targetStateBlock->textures[j]))) {
> @@ -304,15 +299,13 @@
>          }
>  
>          /* Samplers */
> +        /* TODO: move over to using memcpy */
>          for (j = 0 ; j < GL_LIMITS(samplers); j++){
>              for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE ; i++){ /* States are 1 based */
> -                if (This->set.samplerState[j][i] && (This->samplerState[j][i] !=
> -                                                        targetStateBlock->samplerState[j][i]))
> {
> -                    TRACE("Updating sampler state %d,%d to %ld (was %ld)\n",
> -                    j, i, targetStateBlock->samplerState[j][i],
> -                    This->samplerState[j][i]);
> -                    This->samplerState[j][i] = targetStateBlock->samplerState[j][i];
> -                }
> +                TRACE("Updating sampler state %d,%d to %ld (was %ld)\n",
> +                j, i, targetStateBlock->samplerState[j][i],
> +                This->samplerState[j][i]);
> +                This->samplerState[j][i] = targetStateBlock->samplerState[j][i];
>              }
>          }
>      }
> @@ -423,19 +416,17 @@
>              if (This->set.textures[j] && This->changed.textures[j]) {
>                  IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
>              }
> +            /* TODO: move over to memcpy */
>              for (i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE; i++) {
> -                if (This->set.textureState[j][i] && This->changed.textureState[j][i]) {
> -                    IWineD3DDevice_SetTextureStageState(pDevice, j, i,
> This->textureState[j][i]);
> -                }
> +                ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][i] =
> This->textureState[j][i];
>              }
>          }
>  
>          /* Samplers */
> +        /* TODO: move over to memcpy */
>          for (j = 0 ; j < GL_LIMITS(samplers); j++){
>              for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; i++){
> -                 if (This->set.samplerState[j][i] && This->changed.samplerState[j][i] &&
> This->samplerState[j][i] != 0) {
> -                        IWineD3DDevice_SetSamplerState(pDevice, j, i,
> This->samplerState[j][i]);
> -                 }
> +                ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][i] =
> This->samplerState[j][i];
>              }
>  
>          }
> @@ -450,9 +441,13 @@
>  
>          for (j = 0; j < GL_LIMITS(textures); i++) {
>              for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
> -                if (This->set.textureState[j][SavedPixelStates_T[i]] &&
> -                    This->changed.textureState[j][SavedPixelStates_T[i]])
> -                    IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
> This->textureState[j][SavedPixelStates_T[i]]);
> +                ((IWineD3DDeviceImpl
> *)pDevice)->stateBlock->textureState[j][SavedPixelStates_T[i]] =
> This->textureState[j][SavedPixelStates_T[i]];
> +            }
> +        }
> +
> +        for (j = 0; j < GL_LIMITS(samplers); i++) {
> +            for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
> +                ((IWineD3DDeviceImpl
> *)pDevice)->stateBlock->samplerState[j][SavedPixelStates_S[i]] =
> This->samplerState[j][SavedPixelStates_S[i]];
>              }
>          }
>  
> @@ -465,9 +460,13 @@
>  
>          for (j = 0; j < GL_LIMITS(textures); i++) {
>              for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
> -                if ( This->set.textureState[j][SavedVertexStates_T[i]] &&
> -                    This->changed.textureState[j][SavedVertexStates_T[i]])
> -                    IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
> This->textureState[j][SavedVertexStates_T[i]]);
> +                ((IWineD3DDeviceImpl
> *)pDevice)->stateBlock->samplerState[j][SavedVertexStates_T[i]] =
> This->textureState[j][SavedVertexStates_T[i]];
> +            }
> +        }
> +
> +        for (j = 0; j < GL_LIMITS(textures); i++) {
> +            for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
> +                ((IWineD3DDeviceImpl
> *)pDevice)->stateBlock->samplerState[j][SavedVertexStates_S[i]] =
> This->textureState[j][SavedVertexStates_S[i]];
>              }
>          }
>  
> @@ -728,9 +727,10 @@
>  
>          glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
> &white);
>          checkGLcall("glTexImage1D");
> -
> +#if 1   /* TODO: move the setting texture states off to basetexture */
>          /* Reapply all the texture state information to this texture */
>          IWineD3DDevice_SetupTextureStates(device, i, REAPPLY_ALL);
> +#endif
>      }
>  
>      LEAVE_GL();
> diff -Nru -X ignore clean/wine/dlls/wined3d/utils.c small-patches/wine/dlls/wined3d/utils.c
> --- clean/wine/dlls/wined3d/utils.c	2005-07-27 15:26:54.197416384 +0100
> +++ small-patches/wine/dlls/wined3d/utils.c	2005-07-31 19:46:45.264817120 +0100
> @@ -1499,8 +1499,6 @@
>      } else if(!calculatedCoords) { /* under directx the R/Z coord can be used for translation,
> under opengl we use the Q coord instead */
>          mat[12] = mat[8];
>          mat[13] = mat[9];
> -        mat[8] = 0;
> -        mat[9] = 0;
>      }
>  
>      glLoadMatrixf(mat);
> diff -Nru -X ignore clean/wine/dlls/wined3d/wined3d_private.h
> small-patches/wine/dlls/wined3d/wined3d_private.h
> --- clean/wine/dlls/wined3d/wined3d_private.h	2005-07-28 13:22:10.768868088 +0100
> +++ small-patches/wine/dlls/wined3d/wined3d_private.h	2005-07-31 18:33:38.920642792 +0100
> @@ -776,9 +776,11 @@
>          BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
>          BOOL                      viewport;
>          BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
> +#if 0
>          BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE +
> 1];
> -        BOOL                      clipplane[MAX_CLIPPLANES];
>          BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE +
> 1];
> +#endif
> +        BOOL                      clipplane[MAX_CLIPPLANES];
>          BOOL                      vertexDecl;
>          BOOL                      pixelShader;
>          BOOL                      vertexShader;
> 


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wined3d-texture-state-sepeartion-part2-os-2.patch
Type: text/x-diff
Size: 21263 bytes
Desc: 2701173037-wined3d-texture-state-sepeartion-part2-os-2.patch
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20050801/b4679ed2/wined3d-texture-state-sepeartion-part2-os-2.bin


More information about the wine-patches mailing list