Added origin_lower_left field to pipe_rasterizer_state
authorBrian <brian.paul@tungstengraphics.com>
Fri, 14 Dec 2007 19:25:25 +0000 (12:25 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 14 Dec 2007 19:25:25 +0000 (12:25 -0700)
This controls whether the window origin is considered to be the lower-left
or upper-left corner.
This effects computation of gl_FragCoord and the application of polygon stipple.

src/mesa/pipe/p_state.h
src/mesa/pipe/softpipe/sp_prim_setup.c
src/mesa/pipe/softpipe/sp_quad_stipple.c
src/mesa/state_tracker/st_atom_rasterizer.c

index 43b710ff3b6154edfc9e4bab0b9928a50836c014..af65d365bf0b6a79dc4fc6a324f6765aae4d12b9 100644 (file)
@@ -94,6 +94,7 @@ struct pipe_rasterizer_state
    unsigned line_stipple_factor:8;  /**< [1..256] actually */
    unsigned line_stipple_pattern:16;
    unsigned bypass_clipping:1;
+   unsigned origin_lower_left:1;  /**< Is (0,0) the lower-left corner? */
 
    float line_width;
    float point_size;           /**< used when no per-vertex size */
index 8d8dceadc5cd8b8068deca7fb54c5af18d4bfd00..2ccf5e2624ac4a56754b7a48318ace2569fff5c4 100644 (file)
@@ -480,15 +480,23 @@ static void tri_persp_coeff( struct setup_stage *setup,
 static void
 setup_fragcoord_coeff(struct setup_stage *setup)
 {
-   const int winHeight = setup->softpipe->framebuffer.cbufs[0]->height;
    /*X*/
    setup->coef[0].a0[0] = 0;
    setup->coef[0].dadx[0] = 1.0;
    setup->coef[0].dady[0] = 0.0;
    /*Y*/
-   setup->coef[0].a0[1] = winHeight - 1;
+   if (setup->softpipe->rasterizer->origin_lower_left) {
+      /* y=0=bottom */
+      const int winHeight = setup->softpipe->framebuffer.cbufs[0]->height;
+      setup->coef[0].a0[1] = winHeight - 1;
+      setup->coef[0].dady[1] = -1.0;
+   }
+   else {
+      /* y=0=top */
+      setup->coef[0].a0[1] = 0.0;
+      setup->coef[0].dady[1] = 1.0;
+   }
    setup->coef[0].dadx[1] = 0.0;
-   setup->coef[0].dady[1] = -1.0;
    /*Z*/
    setup->coef[0].a0[2] = setup->posCoef.a0[2];
    setup->coef[0].dadx[2] = setup->posCoef.dadx[2];
index 04d95989c40381116c34f48cda30a500d8b153cb..0c42963dfe36bee64df91c718259d8b8e794ea38 100644 (file)
@@ -22,10 +22,18 @@ stipple_quad(struct quad_stage *qs, struct quad_header *quad)
    if (quad->prim == PRIM_TRI) {
       struct softpipe_context *softpipe = qs->softpipe;
       /* need to invert Y to index into OpenGL's stipple pattern */
-      const int y0 = softpipe->framebuffer.cbufs[0]->height - 1 - quad->y0;
-      const int y1 = y0 - 1;
-      const unsigned stipple0 = softpipe->poly_stipple.stipple[y0 % 32];
-      const unsigned stipple1 = softpipe->poly_stipple.stipple[y1 % 32];
+      int y0, y1;
+      uint stipple0, stipple1;
+      if (softpipe->rasterizer->origin_lower_left) {
+         y0 = softpipe->framebuffer.cbufs[0]->height - 1 - quad->y0;
+         y1 = y0 - 1;
+      }
+      else {
+         y0 = quad->y0;
+         y1 = y0 + 1;
+      }
+      stipple0 = softpipe->poly_stipple.stipple[y0 % 32];
+      stipple1 = softpipe->poly_stipple.stipple[y1 % 32];
 
 #if 1
       const int col0 = quad->x0 % 32;
index 2a7128dd27cf90b1a550e87e703168866d62cddd..5c6b89d78c45b715106d97112ad7c8b4b20bb1bb 100644 (file)
@@ -77,6 +77,8 @@ static void update_raster_state( struct st_context *st )
    uint i;
 
    memset(&raster, 0, sizeof(raster));
+
+   raster.origin_lower_left = 1; /* Always true for OpenGL */
    
    /* _NEW_POLYGON, _NEW_BUFFERS
     */