[PATCH 3/5] wined3d: Don't use the builtin FFP uniform for the projection matrix.

Matteo Bruni mbruni at codeweavers.com
Fri Mar 20 07:50:54 CDT 2015


---
 dlls/wined3d/glsl_shader.c     | 30 ++++++++++++++++++------------
 dlls/wined3d/state.c           |  4 ++--
 dlls/wined3d/wined3d_private.h |  5 ++---
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 3e3f9c2..c0d551f 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -118,6 +118,7 @@ struct glsl_vs_program
     GLint pos_fixup_location;
 
     GLint modelview_matrix_location;
+    GLint projection_matrix_location;
 };
 
 struct glsl_gs_program
@@ -786,6 +787,15 @@ static void shader_glsl_load_constants(void *shader_priv, struct wined3d_context
         checkGLcall("glUniformMatrix4fv");
     }
 
+    if (update_mask & WINED3D_SHADER_CONST_FFP_PROJ)
+    {
+        struct wined3d_matrix projection;
+
+        get_projection_matrix(context, state, &projection);
+        GL_EXTCALL(glUniformMatrix4fv(prog->vs.projection_matrix_location, 1, FALSE, (GLfloat *)&projection));
+        checkGLcall("glUniformMatrix4fv");
+    }
+
     if (update_mask & WINED3D_SHADER_CONST_PS_F)
         shader_glsl_load_constantsF(pshader, gl_info, state->ps_consts_f,
                 prog->ps.uniform_f_locations, &priv->pconst_heap, priv->stack, constant_version);
@@ -4989,6 +4999,7 @@ static GLuint shader_glsl_generate_ffp_vertex_shader(struct wined3d_shader_buffe
     shader_addline(buffer, "\n");
 
     shader_addline(buffer, "uniform mat4 ffp_modelview_matrix;\n");
+    shader_addline(buffer, "uniform mat4 ffp_projection_matrix;\n");
 
     shader_addline(buffer, "\nvoid main()\n{\n");
     shader_addline(buffer, "float m;\n");
@@ -4997,13 +5008,13 @@ static GLuint shader_glsl_generate_ffp_vertex_shader(struct wined3d_shader_buffe
     if (settings->transformed)
     {
         shader_addline(buffer, "vec4 ec_pos = vec4(gl_Vertex.xyz, 1.0);\n");
-        shader_addline(buffer, "gl_Position = gl_ProjectionMatrix * ec_pos;\n");
+        shader_addline(buffer, "gl_Position = ffp_projection_matrix * ec_pos;\n");
         shader_addline(buffer, "if (gl_Vertex.w != 0.0) gl_Position /= gl_Vertex.w;\n");
     }
     else
     {
         shader_addline(buffer, "vec4 ec_pos = ffp_modelview_matrix * gl_Vertex;\n");
-        shader_addline(buffer, "gl_Position = gl_ProjectionMatrix * ec_pos;\n");
+        shader_addline(buffer, "gl_Position = ffp_projection_matrix * ec_pos;\n");
         if (settings->clipping)
             shader_addline(buffer, "gl_ClipVertex = ec_pos;\n");
         shader_addline(buffer, "ec_pos /= ec_pos.w;\n");
@@ -5771,6 +5782,7 @@ static void shader_glsl_init_vs_uniform_locations(const struct wined3d_gl_info *
     vs->pos_fixup_location = GL_EXTCALL(glGetUniformLocation(program_id, "posFixup"));
 
     vs->modelview_matrix_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_modelview_matrix"));
+    vs->projection_matrix_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_projection_matrix"));
 }
 
 static void shader_glsl_init_ps_uniform_locations(const struct wined3d_gl_info *gl_info,
@@ -6073,7 +6085,8 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const
     }
     else
     {
-        entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_MODELVIEW;
+        entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_MODELVIEW
+                | WINED3D_SHADER_CONST_FFP_PROJ;
     }
 
     if (gshader)
@@ -6990,11 +7003,7 @@ static void glsl_vertex_pipe_vdecl(struct wined3d_context *context,
         }
 
         if (transformed != wasrhw)
-        {
-            if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))
-                    && !isStateDirty(context, STATE_VIEWPORT))
-                transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
-        }
+            context->constant_update_mask |= WINED3D_SHADER_CONST_FFP_PROJ;
 
         for (i = 0; i < MAX_TEXTURES; ++i)
         {
@@ -7028,9 +7037,6 @@ static void glsl_vertex_pipe_vdecl(struct wined3d_context *context,
         }
     }
 
-    if (transformed != wasrhw && !isStateDirty(context, STATE_RENDER(WINED3D_RS_ZENABLE)))
-        context_apply_state(context, state, STATE_RENDER(WINED3D_RS_ZENABLE));
-
     context->last_was_vshader = use_vs(state);
 }
 
@@ -7089,7 +7095,7 @@ static void glsl_vertex_pipe_projection(struct wined3d_context *context,
     if (state->render_states[WINED3D_RS_FOGENABLE]
             && state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
         context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_VERTEX;
-    transform_projection(context, state, state_id);
+    context->constant_update_mask |= WINED3D_SHADER_CONST_FFP_PROJ;
 }
 
 static void glsl_vertex_pipe_viewport(struct wined3d_context *context,
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 9a40876..c651c17 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -132,7 +132,7 @@ static void state_zenable(struct wined3d_context *context, const struct wined3d_
     }
 
     if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
-        transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
+        context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
 }
 
 static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
@@ -4049,7 +4049,7 @@ static void transform_view(struct wined3d_context *context, const struct wined3d
     }
 }
 
-void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
+static void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
     struct wined3d_matrix projection;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index eca6bdb..6ccfad6 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -307,7 +307,8 @@ enum wined3d_shader_resource_type
 #define WINED3D_SHADER_CONST_PS_Y_CORR      0x00000100
 #define WINED3D_SHADER_CONST_PS_NP2_FIXUP   0x00000200
 #define WINED3D_SHADER_CONST_FFP_MODELVIEW  0x00000400
-#define WINED3D_SHADER_CONST_FFP_PS         0x00000800
+#define WINED3D_SHADER_CONST_FFP_PROJ       0x00000800
+#define WINED3D_SHADER_CONST_FFP_PS         0x00001000
 
 enum wined3d_shader_register_type
 {
@@ -2808,8 +2809,6 @@ void sampler_texmatrix(struct wined3d_context *context,
         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
 void state_specularenable(struct wined3d_context *context,
         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
-void transform_projection(struct wined3d_context *context,
-        const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
 void transform_texture(struct wined3d_context *context,
         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
 void state_ambient(struct wined3d_context *context,
-- 
2.0.5




More information about the wine-patches mailing list