[PATCH 2/4] wined3d: Move transforms to wined3d_state.

Henri Verbeet hverbeet at codeweavers.com
Thu Sep 16 04:19:56 CDT 2010


---
 dlls/wined3d/device.c          |   31 +++++++++++++++++++++----------
 dlls/wined3d/state.c           |   26 ++++++++++++++------------
 dlls/wined3d/stateblock.c      |   18 ++++++++++--------
 dlls/wined3d/wined3d_private.h |    4 +---
 4 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index ab7e2ed..3d930f9 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2413,7 +2413,7 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_SetTransform(IWineD3DDevice *iface, W
     if (This->isRecordingState) {
         TRACE("Recording... not performing anything\n");
         This->updateStateBlock->changed.transform[d3dts >> 5] |= 1 << (d3dts & 0x1f);
-        This->updateStateBlock->transforms[d3dts] = *lpmatrix;
+        This->updateStateBlock->state.transforms[d3dts] = *lpmatrix;
         return WINED3D_OK;
     }
 
@@ -2425,11 +2425,14 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_SetTransform(IWineD3DDevice *iface, W
      *
      * From here on we assume that the new matrix is different, wherever it matters.
      */
-    if (!memcmp(&This->stateBlock->transforms[d3dts].u.m[0][0], lpmatrix, sizeof(WINED3DMATRIX))) {
+    if (!memcmp(&This->stateBlock->state.transforms[d3dts].u.m[0][0], lpmatrix, sizeof(*lpmatrix)))
+    {
         TRACE("The app is setting the same matrix over again\n");
         return WINED3D_OK;
-    } else {
-        conv_mat(lpmatrix, &This->stateBlock->transforms[d3dts].u.m[0][0]);
+    }
+    else
+    {
+        conv_mat(lpmatrix, &This->stateBlock->state.transforms[d3dts].u.m[0][0]);
     }
 
     /*
@@ -2452,10 +2455,16 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_SetTransform(IWineD3DDevice *iface, W
     return WINED3D_OK;
 
 }
-static HRESULT WINAPI IWineD3DDeviceImpl_GetTransform(IWineD3DDevice *iface, WINED3DTRANSFORMSTATETYPE State, WINED3DMATRIX* pMatrix) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    TRACE("(%p) : for Transform State %s\n", This, debug_d3dtstype(State));
-    *pMatrix = This->stateBlock->transforms[State];
+
+static HRESULT WINAPI IWineD3DDeviceImpl_GetTransform(IWineD3DDevice *iface,
+        WINED3DTRANSFORMSTATETYPE state, WINED3DMATRIX *matrix)
+{
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)iface;
+
+    TRACE("iface %p, state %s, matrix %p.\n", iface, debug_d3dtstype(state), matrix);
+
+    *matrix = device->stateBlock->state.transforms[state];
+
     return WINED3D_OK;
 }
 
@@ -2473,8 +2482,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_MultiplyTransform(IWineD3DDevice *iface
 
     if (State <= HIGHEST_TRANSFORMSTATE)
     {
-        mat = &This->updateStateBlock->transforms[State];
-    } else {
+        mat = &This->updateStateBlock->state.transforms[State];
+    }
+    else
+    {
         FIXME("Unhandled transform state!!\n");
     }
 
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index a37f8ee..e640b54 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3246,7 +3246,7 @@ static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, s
     generated = (stateblock->textureState[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) != WINED3DTSS_TCI_PASSTHRU;
     coordIdx = min(stateblock->textureState[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000FFFF], MAX_TEXTURES - 1);
 
-    set_texture_matrix(&stateblock->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
+    set_texture_matrix(&stateblock->state.transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
             stateblock->textureState[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], generated, context->last_was_rhw,
             stateblock->device->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
             ? stateblock->device->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id
@@ -3727,14 +3727,14 @@ static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock, str
         /* In the general case, the view matrix is the identity matrix */
         if (stateblock->device->view_ident)
         {
-            glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
+            glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
             checkGLcall("glLoadMatrixf");
         }
         else
         {
-            glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
+            glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
             checkGLcall("glLoadMatrixf");
-            glMultMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
+            glMultMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
             checkGLcall("glMultMatrixf");
         }
     }
@@ -3753,8 +3753,10 @@ static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wi
     if(!use_vs(stateblock)) {
         glMatrixMode(GL_MODELVIEW);
         glPushMatrix();
-        glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
-    } else {
+        glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
+    }
+    else
+    {
         /* with vertex shaders, clip planes are not transformed in direct3d,
          * in OpenGL they are still transformed by the model view.
          * Use this to swap the y coordinate if necessary
@@ -3808,14 +3810,14 @@ static void transform_worldex(DWORD state, IWineD3DStateBlockImpl *stateblock, s
      */
     if (stateblock->device->view_ident)
     {
-        glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
+        glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
         checkGLcall("glLoadMatrixf");
     }
     else
     {
-        glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
+        glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
         checkGLcall("glLoadMatrixf");
-        glMultMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
+        glMultMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
         checkGLcall("glMultMatrixf");
     }
 }
@@ -3889,7 +3891,7 @@ static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, stru
 
     glMatrixMode(GL_MODELVIEW);
     checkGLcall("glMatrixMode(GL_MODELVIEW)");
-    glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
+    glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
     checkGLcall("glLoadMatrixf(...)");
 
     /* Reset lights. TODO: Call light apply func */
@@ -4030,7 +4032,7 @@ static void transform_projection(DWORD state, IWineD3DStateBlockImpl *stateblock
         }
         checkGLcall("glScalef");
 
-        glMultMatrixf(&stateblock->transforms[WINED3DTS_PROJECTION].u.m[0][0]);
+        glMultMatrixf(&stateblock->state.transforms[WINED3DTS_PROJECTION].u.m[0][0]);
         checkGLcall("glLoadMatrixf");
     }
 }
@@ -4781,7 +4783,7 @@ static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3
         /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
         glMatrixMode(GL_MODELVIEW);
         glPushMatrix();
-        glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
+        glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
 
         /* Diffuse: */
         colRGBA[0] = lightInfo->OriginalParms.Diffuse.r;
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 13abfde..236c067 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -710,7 +710,7 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
 
         TRACE("Updating transform %#x.\n", transform);
 
-        This->transforms[transform] = targetStateBlock->transforms[transform];
+        This->state.transforms[transform] = targetStateBlock->state.transforms[transform];
     }
 
     if (This->changed.primitive_type) This->gl_primitive_type = targetStateBlock->gl_primitive_type;
@@ -968,7 +968,7 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
     for (i = 0; i < This->num_contained_transform_states; ++i)
     {
         IWineD3DDevice_SetTransform(device, This->contained_transform_states[i],
-                &This->transforms[This->contained_transform_states[i]]);
+                &This->state.transforms[This->contained_transform_states[i]]);
     }
 
     if (This->changed.primitive_type)
@@ -1084,10 +1084,11 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStat
     This->blockType = WINED3DSBT_INIT;
 
     /* Set some of the defaults for lights, transforms etc */
-    memcpy(&This->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
-    memcpy(&This->transforms[WINED3DTS_VIEW], identity, sizeof(identity));
-    for (i = 0; i < 256; ++i) {
-      memcpy(&This->transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity));
+    memcpy(&This->state.transforms[WINED3DTS_PROJECTION], identity, sizeof(identity));
+    memcpy(&This->state.transforms[WINED3DTS_VIEW], identity, sizeof(identity));
+    for (i = 0; i < 256; ++i)
+    {
+        memcpy(&This->state.transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity));
     }
 
     TRACE("Render states\n");
@@ -1228,9 +1229,10 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStat
     This->clip_status.ClipIntersection = 0xFFFFFFFF;
 
     /* Texture Stage States - Put directly into state block, we will call function below */
-    for (i = 0; i < MAX_TEXTURES; i++) {
+    for (i = 0; i < MAX_TEXTURES; ++i)
+    {
         TRACE("Setting up default texture states for texture Stage %d\n", i);
-        memcpy(&This->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
+        memcpy(&This->state.transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity));
         This->textureState[i][WINED3DTSS_COLOROP               ] = i ? WINED3DTOP_DISABLE : WINED3DTOP_MODULATE;
         This->textureState[i][WINED3DTSS_COLORARG1             ] = WINED3DTA_TEXTURE;
         This->textureState[i][WINED3DTSS_COLORARG2             ] = WINED3DTA_CURRENT;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index b3c2617..c11ed64 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2349,6 +2349,7 @@ struct wined3d_stream_state
 
 struct wined3d_state
 {
+    WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
     WINED3DMATERIAL material;
     WINED3DVIEWPORT viewport;
     RECT scissor_rect;
@@ -2393,9 +2394,6 @@ struct IWineD3DStateBlockImpl
     INT                       baseVertexIndex;
     INT                       loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
 
-    /* Transform */
-    WINED3DMATRIX             transforms[HIGHEST_TRANSFORMSTATE + 1];
-
     /* Light hashmap . Collisions are handled using standard wine double linked lists */
 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
-- 
1.7.1




More information about the wine-patches mailing list