wined3d: Texture limits fixes.

GL_LIMITS(textures) is currently used for both the number of texture
stages and the maximum number of simultaneous textures. In the current
code that's the same, but in a later patch that will be separated,
since a texture stage doesn't have to reference an actual
texture. Also, shaders can access a larger number of samplers than the
number of texture units the fixed function pipeline can access.
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 58f0470..0a17761 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -90,7 +90,7 @@
             }
 
             /* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
-            for (counter = 0; counter < GL_LIMITS(textures); counter++) {
+            for (counter = 0; counter < GL_LIMITS(sampler_stages); counter++) {
                 if (This->textures[counter]) {
                     /* release our 'internal' hold on the texture */
                     if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
@@ -374,9 +374,8 @@
             }
         }
 
-        /* FIXME: textures are up to MAX_SAMPLERS for d3d9? */
-        /* Texture */
-        for (j = 0; j < GL_LIMITS(textures); j++) {
+        /* Texture states */
+        for (j = 0; j < GL_LIMITS(texture_stages); j++) {
             /* TODO: move over to using memcpy */
             for (i = 1; i <= WINED3D_HIGHEST_TEXTURE_STATE ; i++) {
                 if (This->set.textureState[j][i]) {
@@ -385,17 +384,15 @@
                     This->textureState[j][i]         =  targetStateBlock->textureState[j][i];
                 }
             }
-
-            if (This->set.textures[j]) {
-                TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j],  This->textures[j]);
-                This->textures[j] = targetStateBlock->textures[j];
-            }
-
         }
 
         /* Samplers */
         /* TODO: move over to using memcpy */
-        for (j = 0 ; j < GL_LIMITS(samplers); j++){
+        for (j = 0; j < GL_LIMITS(sampler_stages); j++) {
+            if (This->set.textures[j]) {
+                TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j],  This->textures[j]);
+                This->textures[j] = targetStateBlock->textures[j];
+            }
             for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE ; i++){ /* States are 1 based */
                 if (This->set.samplerState[j][i]) {
                     TRACE("Updating sampler state %d,%d to %ld (was %ld)\n",
@@ -528,12 +525,8 @@
                 IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
         }
 
-        /* FIXME: Texture are set against samplers... not just TextureStages */
-        /* Texture */
-        for (j = 0; j < GL_LIMITS(textures); j++) { /* Set The texture first, just in case it resets the states? */
-            if (This->set.textures[j] && This->changed.textures[j]) {
-                IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
-            }
+        /* Texture states */
+        for (j = 0; j < GL_LIMITS(texture_stages); j++) { /* Set The texture first, just in case it resets the states? */
             /* 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]) { /* tb_dx9_10 failes without this test */
@@ -546,7 +539,10 @@
 
         /* Samplers */
         /* TODO: move over to memcpy */
-        for (j = 0 ; j < GL_LIMITS(samplers); j++){
+        for (j = 0 ; j < GL_LIMITS(sampler_stages); j++){
+            if (This->set.textures[j] && This->changed.textures[j]) {
+                IWineD3DDevice_SetTexture(pDevice, j, This->textures[j]);
+            }
             for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; i++){
                 if (This->set.samplerState[j][i] && This->changed.samplerState[j][i]) {
                     ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][i]         = This->samplerState[j][i];
@@ -565,13 +561,13 @@
 
         }
 
-        for (j = 0; j < GL_LIMITS(textures); j++) {
+        for (j = 0; j < GL_LIMITS(texture_stages); j++) {
             for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
                 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedPixelStates_T[i]] = This->textureState[j][SavedPixelStates_T[i]];
             }
         }
 
-        for (j = 0; j < GL_LIMITS(samplers); j++) {
+        for (j = 0; j < GL_LIMITS(sampler_stages); j++) {
             for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
                 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][SavedPixelStates_S[i]] = This->samplerState[j][SavedPixelStates_S[i]];
             }
@@ -584,13 +580,13 @@
                 IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
         }
 
-        for (j = 0; j < GL_LIMITS(textures); j++) {
+        for (j = 0; j < GL_LIMITS(texture_stages); j++) {
             for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
                 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedVertexStates_T[i]] = This->textureState[j][SavedVertexStates_T[i]];
             }
         }
 
-        for (j = 0; j < GL_LIMITS(textures); j++) {
+        for (j = 0; j < GL_LIMITS(sampler_stages); j++) {
             for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
                 ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][SavedVertexStates_S[i]] = This->samplerState[j][SavedVertexStates_S[i]];
             }
@@ -777,7 +773,7 @@
     This->clip_status.ClipIntersection = 0xFFFFFFFF;
 
     /* Texture Stage States - Put directly into state block, we will call function below */
-    for (i = 0; i < GL_LIMITS(textures); i++) {
+    for (i = 0; i < GL_LIMITS(texture_stages); i++) {
         TRACE("Setting up default texture states for texture Stage %d\n", i);
         memcpy(&This->transforms[D3DTS_TEXTURE0 + i], &identity, sizeof(identity));
         This->textureState[i][D3DTSS_COLOROP               ] = (i==0)? D3DTOP_MODULATE :  D3DTOP_DISABLE;
@@ -801,7 +797,7 @@
     }
 
         /* Sampler states*/
-    for (i = 0 ; i <  GL_LIMITS(samplers); i++) {
+    for (i = 0 ; i <  GL_LIMITS(sampler_stages); i++) {
         TRACE("Setting up default samplers states for sampler %d\n", i);
         This->samplerState[i][WINED3DSAMP_ADDRESSU         ] = D3DTADDRESS_WRAP;
         This->samplerState[i][WINED3DSAMP_ADDRESSV         ] = D3DTADDRESS_WRAP;
@@ -826,7 +822,7 @@
 
     ENTER_GL();
 
-    for (i = 0; i < GL_LIMITS(textures); i++) {
+    for (i = 0; i < GL_LIMITS(texture_stages); i++) {
         GLubyte white = 255;
 
         /* Note this avoids calling settexture, so pretend it has been called */