[PATCH] WineD3D: NP2 coordinate adjustment is a vertex operation=0A=

Stefan Doesinger stefan at codeweavers.com
Thu Jul 3 13:26:06 CDT 2008


=0A=
When a sampler is changed and unconditional NP2 textures are=0A=
not supported, the texture matrix may need adjustion. The=0A=
sampler state function checks for that, and calls the texture=0A=
transform setting function in that case. However, samplers are=0A=
a misc state, and the texture transform flags a vertex state.=0A=
Thus split up the code and move the matrix changes to the=0A=
vertex side=0A=
---=0A=
 dlls/wined3d/state.c |   66 =
+++++++++++++++++++++++++++++++-------------------=0A=
 1 files changed, 41 insertions(+), 25 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c=0A=
index 3e45942..b96f80f 100644=0A=
--- a/dlls/wined3d/state.c=0A=
+++ b/dlls/wined3d/state.c=0A=
@@ -2344,6 +2344,38 @@ static void tex_bumpenvloffset(DWORD state, =
IWineD3DStateBlockImpl *stateblock,=0A=
     }=0A=
 }=0A=
 =0A=
+static void sampler_texmatrix(DWORD state, IWineD3DStateBlockImpl =
*stateblock, WineD3DContext *context) {=0A=
+    BOOL texIsPow2 =3D FALSE;=0A=
+    DWORD sampler =3D state - STATE_SAMPLER(0);=0A=
+=0A=
+    if(!stateblock->textures[sampler]) return;=0A=
+    /* The fixed function np2 texture emulation uses the texture matrix =
to fix up the coordinates=0A=
+     * IWineD3DBaseTexture::ApplyStateChanges multiplies the set matrix =
with a fixup matrix. Before the=0A=
+     * scaling is reapplied or removed, the texture matrix has to be =
reapplied=0A=
+     *=0A=
+     * The mapped stage is alrady active because the sampler() function =
below, which is part of the=0A=
+     * misc pipeline=0A=
+     */=0A=
+    if(!GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) && sampler < =
MAX_TEXTURES) {=0A=
+        if(stateblock->textureDimensions[sampler] =3D=3D GL_TEXTURE_2D =
||=0A=
+           stateblock->textureDimensions[sampler] =3D=3D =
GL_TEXTURE_RECTANGLE_ARB) {=0A=
+            if(((IWineD3DTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[0] !=3D 1.0 ||=0A=
+               ((IWineD3DTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[5] !=3D 1.0 ) {=0A=
+                texIsPow2 =3D TRUE;=0A=
+            }=0A=
+        } else if(stateblock->textureDimensions[sampler] =3D=3D =
GL_TEXTURE_CUBE_MAP_ARB) {=0A=
+            if(((IWineD3DCubeTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[0] !=3D 1.0) {=0A=
+                texIsPow2 =3D TRUE;=0A=
+            }=0A=
+        }=0A=
+=0A=
+        if(texIsPow2 || context->lastWasPow2Texture[sampler]) {=0A=
+            context->lastWasPow2Texture[sampler] =3D texIsPow2;=0A=
+            transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + =
stateblock->wineD3DDevice->texUnitMap[sampler]), stateblock, context);=0A=
+        }=0A=
+    }=0A=
+}=0A=
+=0A=
 static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, =
WineD3DContext *context) {=0A=
     DWORD sampler =3D state - STATE_SAMPLER(0);=0A=
     DWORD mapped_stage =3D =
stateblock->wineD3DDevice->texUnitMap[sampler];=0A=
@@ -2375,31 +2407,6 @@ static void sampler(DWORD state, =
IWineD3DStateBlockImpl *stateblock, WineD3DCont=0A=
     }=0A=
 =0A=
     if(stateblock->textures[sampler]) {=0A=
-        BOOL texIsPow2 =3D FALSE;=0A=
-=0A=
-        /* The fixed function np2 texture emulation uses the texture =
matrix to fix up the coordinates=0A=
-         * IWineD3DBaseTexture::ApplyStateChanges multiplies the set =
matrix with a fixup matrix. Before the=0A=
-         * scaling is reapplied or removed, the texture matrix has to =
be reapplied=0A=
-         */=0A=
-        if(!GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) && sampler < =
MAX_TEXTURES) {=0A=
-            if(stateblock->textureDimensions[sampler] =3D=3D =
GL_TEXTURE_2D ||=0A=
-               stateblock->textureDimensions[sampler] =3D=3D =
GL_TEXTURE_RECTANGLE_ARB) {=0A=
-                if(((IWineD3DTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[0] !=3D 1.0 ||=0A=
-                   ((IWineD3DTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[5] !=3D 1.0 ) {=0A=
-                    texIsPow2 =3D TRUE;=0A=
-                }=0A=
-            } else if(stateblock->textureDimensions[sampler] =3D=3D =
GL_TEXTURE_CUBE_MAP_ARB) {=0A=
-                if(((IWineD3DCubeTextureImpl *) =
stateblock->textures[sampler])->baseTexture.pow2Matrix[0] !=3D 1.0) {=0A=
-                    texIsPow2 =3D TRUE;=0A=
-                }=0A=
-            }=0A=
-=0A=
-            if(texIsPow2 || context->lastWasPow2Texture[sampler]) {=0A=
-                context->lastWasPow2Texture[sampler] =3D texIsPow2;=0A=
-                transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + =
stateblock->wineD3DDevice->texUnitMap[sampler]), stateblock, context);=0A=
-            }=0A=
-        }=0A=
-=0A=
         IWineD3DBaseTexture_PreLoad(stateblock->textures[sampler]);=0A=
         =
IWineD3DBaseTexture_ApplyStateChanges(stateblock->textures[sampler], =
stateblock->textureState[sampler], stateblock->samplerState[sampler]);=0A=
 =0A=
@@ -4300,6 +4307,15 @@ const struct StateEntryTemplate =
ffp_vertexstate_template[] =3D {=0A=
     { STATE_RENDER(WINED3DRS_POINTSCALE_B),               { =
STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        =
}},=0A=
     { STATE_RENDER(WINED3DRS_POINTSCALE_C),               { =
STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        =
}},=0A=
     { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { =
STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax      =
}},=0A=
+    /* Samplers for NP2 texture matrix adjustions */=0A=
+    { STATE_SAMPLER(0),                                   { =
STATE_SAMPLER(0),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(1),                                   { =
STATE_SAMPLER(1),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(2),                                   { =
STATE_SAMPLER(2),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(3),                                   { =
STATE_SAMPLER(3),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(4),                                   { =
STATE_SAMPLER(4),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(5),                                   { =
STATE_SAMPLER(5),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(6),                                   { =
STATE_SAMPLER(6),                                   sampler_texmatrix   =
}},=0A=
+    { STATE_SAMPLER(7),                                   { =
STATE_SAMPLER(7),                                   sampler_texmatrix   =
}},=0A=
     {0 /* Terminate */,                                   { 0,          =
                                        0                   }},=0A=
 };=0A=
 =0A=
-- =0A=
1.5.4.5=0A=
=0A=

------=_NextPart_000_002D_01C8E33C.8CE06C00--




More information about the wine-patches mailing list