Matteo Bruni : wined3d: Introduce a get_texture_matrix() function.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Mar 23 10:03:19 CDT 2015


Module: wine
Branch: master
Commit: 74cda79ac3d813aa8d9364e4d619d4c4605a09c9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=74cda79ac3d813aa8d9364e4d619d4c4605a09c9

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Fri Mar 20 13:50:55 2015 +0100

wined3d: Introduce a get_texture_matrix() function.

---

 dlls/wined3d/state.c           | 40 +++++++++--------------------------
 dlls/wined3d/utils.c           | 47 +++++++++++++++++++++++++++++++++---------
 dlls/wined3d/wined3d_private.h |  5 ++---
 3 files changed, 49 insertions(+), 43 deletions(-)

diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 9a40876..bfef4b0 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3278,12 +3278,10 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
 
 void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 {
-    DWORD texUnit = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    const struct wined3d_device *device = context->swapchain->device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
-    DWORD mapped_stage = context->tex_unit_map[texUnit];
-    BOOL generated;
-    int coordIdx;
+    unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
+    unsigned int mapped_stage = context->tex_unit_map[tex];
+    struct wined3d_matrix mat;
 
     /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
     if (use_vs(state) || isStateDirty(context, STATE_VDECL))
@@ -3296,31 +3294,13 @@ void transform_texture(struct wined3d_context *context, const struct wined3d_sta
     if (mapped_stage >= gl_info->limits.textures) return;
 
     context_active_texture(context, gl_info, mapped_stage);
-    generated = (state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU;
-    coordIdx = min(state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff], MAX_TEXTURES - 1);
-
-    set_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + texUnit],
-            state->texture_states[texUnit][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
-            generated, context->last_was_rhw,
-            context->stream_info.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
-            ? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id
-            : WINED3DFMT_UNKNOWN,
-            device->shader_backend->shader_has_ffp_proj_control(device->shader_priv));
-
-    /* The sampler applying function calls us if this changes */
-    if ((context->lastWasPow2Texture & (1 << texUnit)) && state->textures[texUnit])
-    {
-        if(generated) {
-            FIXME("Non-power2 texture being used with generated texture coords\n");
-        }
-        /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
-           fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
-        if (!use_ps(state))
-        {
-            TRACE("Non power two matrix multiply fixup\n");
-            gl_info->gl_ops.gl.p_glMultMatrixf(state->textures[texUnit]->pow2_matrix);
-        }
-    }
+    gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
+    checkGLcall("glMatrixMode(GL_TEXTURE)");
+
+    get_texture_matrix(context, state, mapped_stage, &mat);
+
+    gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
+    checkGLcall("glLoadMatrixf");
 }
 
 static void unload_tex_coords(const struct wined3d_gl_info *gl_info)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 4452f7c..b28142c 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3203,19 +3203,15 @@ void get_projection_matrix(const struct wined3d_context *context, const struct w
 }
 
 /* Setup this textures matrix according to the texture flags. */
-/* Context activation is done by the caller (state handler). */
-void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix, DWORD flags,
-        BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id, BOOL ffp_proj_control)
+static void compute_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix,
+        DWORD flags, BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id,
+        BOOL ffp_proj_control, struct wined3d_matrix *out_matrix)
 {
     struct wined3d_matrix mat;
 
-    gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
-    checkGLcall("glMatrixMode(GL_TEXTURE)");
-
     if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed)
     {
-        gl_info->gl_ops.gl.p_glLoadIdentity();
-        checkGLcall("glLoadIdentity()");
+        get_identity_matrix(out_matrix);
         return;
     }
 
@@ -3314,8 +3310,39 @@ void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wine
         }
     }
 
-    gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
-    checkGLcall("glLoadMatrixf(mat)");
+    *out_matrix = mat;
+}
+
+void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
+        unsigned int tex, struct wined3d_matrix *mat)
+{
+    const struct wined3d_device *device = context->swapchain->device;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    BOOL generated = (state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
+            != WINED3DTSS_TCI_PASSTHRU;
+    unsigned int coord_idx = min(state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff],
+            MAX_TEXTURES - 1);
+
+    compute_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + tex],
+            state->texture_states[tex][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
+            generated, context->last_was_rhw,
+            context->stream_info.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coord_idx))
+            ? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->id
+            : WINED3DFMT_UNKNOWN,
+            device->shader_backend->shader_has_ffp_proj_control(device->shader_priv), mat);
+
+    if ((context->lastWasPow2Texture & (1 << tex)) && state->textures[tex])
+    {
+        if (generated)
+            FIXME("Non-power-of-two texture being used with generated texture coords.\n");
+        /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
+         * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
+        if (!use_ps(state))
+        {
+            TRACE("Non-power-of-two texture matrix multiply fixup.\n");
+            multiply_matrix(mat, mat, (struct wined3d_matrix *)state->textures[tex]->pow2_matrix);
+        }
+    }
 }
 
 /* This small helper function is used to convert a bitmask into the number of masked bits */
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index bd4f2e2..4e36969 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2782,9 +2782,6 @@ BOOL is_invalid_op(const struct wined3d_state *state, int stage,
 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
         BOOL is_alpha, int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3,
         INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
-void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix,
-        DWORD flags, BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id,
-        BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
 void texture_activate_dimensions(const struct wined3d_texture *texture,
         const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
 void sampler_texdim(struct wined3d_context *context,
@@ -3039,6 +3036,8 @@ void get_modelview_matrix(const struct wined3d_context *context, const struct wi
         struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
         struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
+void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
+        unsigned int tex, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
 
 /* Using additional shader constants (uniforms in GLSL / program environment
  * or local parameters in ARB) is costly:




More information about the wine-cvs mailing list