st/mesa: put fragment wpos code into separate function
authorBrian Paul <brianp@vmware.com>
Tue, 6 Apr 2010 03:59:05 +0000 (21:59 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 6 Apr 2010 04:19:11 +0000 (22:19 -0600)
src/mesa/state_tracker/st_mesa_to_tgsi.c

index 807d21a7197e7cc2df8d18c87d91daee531390c4..bb52d2d10f432121bd902e1964ad56db903f0537 100644 (file)
@@ -738,6 +738,65 @@ emit_inverted_wpos( struct st_translate *t,
 }
 
 
+/**
+ * Emit fragment position/ooordinate code.
+ */
+static void
+emit_wpos(struct st_context *st,
+          struct st_translate *t,
+          const struct gl_program *program,
+          struct ureg_program *ureg)
+{
+   const struct gl_fragment_program *fp =
+      (const struct gl_fragment_program *) program;
+   struct pipe_screen *pscreen = st->pipe->screen;
+   boolean invert = FALSE;
+
+   if (fp->OriginUpperLeft) {
+      if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) {
+      }
+      else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) {
+         ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
+         invert = TRUE;
+      }
+      else
+         assert(0);
+   }
+   else {
+      if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT))
+         ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
+      else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT))
+         invert = TRUE;
+      else
+         assert(0);
+   }
+   
+   if (fp->PixelCenterInteger) {
+      if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER))
+         ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
+      else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER))
+         emit_adjusted_wpos(t, program, invert ? 0.5f : -0.5f);
+      else
+         assert(0);
+   }
+   else {
+      if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) {
+      }
+      else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) {
+         ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
+         emit_adjusted_wpos(t, program, invert ? -0.5f : 0.5f);
+      }
+      else
+         assert(0);
+   }
+
+   /* we invert after adjustment so that we avoid the MOV to temporary,
+    * and reuse the adjustment ADD instead */
+   if (invert)
+      emit_inverted_wpos(t, program);
+}
+
+
 /**
  * OpenGL's fragment gl_FrontFace input is 1 for front-facing, 0 for back.
  * TGSI uses +1 for front, -1 for back.
@@ -831,7 +890,6 @@ st_translate_mesa_program(
     * Declare input attributes.
     */
    if (procType == TGSI_PROCESSOR_FRAGMENT) {
-      struct gl_fragment_program* fp = (struct gl_fragment_program*)program;
       for (i = 0; i < numInputs; i++) {
          if (program->InputFlags[0] & PROG_PARAM_BIT_CYL_WRAP) {
             t->inputs[i] = ureg_DECL_fs_input_cyl(ureg,
@@ -852,51 +910,7 @@ st_translate_mesa_program(
          /* Must do this after setting up t->inputs, and before
           * emitting constant references, below:
           */
-         struct pipe_screen* pscreen = st_context(ctx)->pipe->screen;
-         boolean invert = FALSE;
-
-         if (fp->OriginUpperLeft) {
-            if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) {
-            }
-            else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) {
-               ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
-               invert = TRUE;
-            }
-            else
-               assert(0);
-         }
-         else {
-            if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT))
-               ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
-            else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT))
-               invert = TRUE;
-            else
-               assert(0);
-         }
-
-         if (fp->PixelCenterInteger) {
-            if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER))
-               ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
-            else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER))
-               emit_adjusted_wpos(t, program, invert ? 0.5f : -0.5f);
-            else
-               assert(0);
-         }
-         else {
-            if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) {
-            }
-            else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) {
-               ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
-               emit_adjusted_wpos(t, program, invert ? -0.5f : 0.5f);
-            }
-            else
-               assert(0);
-         }
-
-         /* we invert after adjustment so that we avoid the MOV to temporary,
-          * and reuse the adjustment ADD instead */
-         if (invert)
-            emit_inverted_wpos(t, program);
+         emit_wpos(st_context(ctx), t, program, ureg);
       }
 
       if (program->InputsRead & FRAG_BIT_FACE) {