Move the computation of the viewport matrix into a new update_viewport_matrix()
[mesa.git] / src / mesa / main / state.c
index 994aaff7b00ba82811f3345fca30a87a3f40718a..7e452bdfd7ff4c7869a422ada149c8b0e65f0edf 100644 (file)
@@ -945,6 +945,26 @@ update_program(GLcontext *ctx)
 }
 
 
+static void
+update_viewport_matrix(GLcontext *ctx)
+{
+   const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
+
+   ASSERT(depthMax > 0);
+
+   /* Compute scale and bias values. This is really driver-specific
+    * and should be maintained elsewhere if at all.
+    * NOTE: RasterPos uses this.
+    */
+   _math_matrix_viewport(&ctx->Viewport._WindowMap,
+                         ctx->Viewport.X, ctx->Viewport.Y,
+                         ctx->Viewport.Width, ctx->Viewport.Height,
+                         ctx->Viewport.Near, ctx->Viewport.Far,
+                         depthMax);
+}
+
+
+
 /**
  * If __GLcontextRec::NewState is non-zero then this function \b must be called
  * before rendering any primitive.  Basically, function pointers and
@@ -1002,6 +1022,9 @@ _mesa_update_state( GLcontext *ctx )
    if (new_state & (_NEW_ARRAY | _NEW_PROGRAM))
       update_arrays( ctx );
 
+   if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
+      update_viewport_matrix(ctx);
+
    if (ctx->_MaintainTexEnvProgram) {
       if (new_state & (_NEW_TEXTURE | _DD_NEW_SEPARATE_SPECULAR | _NEW_FOG))
         _mesa_UpdateTexEnvProgram(ctx);