Mesa (mesa_7_4_branch): i965: fix polygon face orientation when rendering to FBO

Ian Romanick idr at kemper.freedesktop.org
Wed Mar 18 21:48:19 UTC 2009


Module: Mesa
Branch: mesa_7_4_branch
Commit: 918e5221efa4d4d0cd60c6446dc0df2b84e44851
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=918e5221efa4d4d0cd60c6446dc0df2b84e44851

Author: Robert Ellison <papillo at vmware.com>
Date:   Wed Mar 11 16:27:38 2009 -0600

i965: fix polygon face orientation when rendering to FBO

In the i965, the FBO coordinate system is inverted from the standard
OpenGL/Mesa coordinate system; that means that the viewport and the
polygon face orientation have to be inverted if rendering to a FBO.

The viewport was already being handled correctly; but polygon face
was not.  This caused a conform failure when rendering to texture with
two-sided lighting enabled.

This fixes the problem in the i965 driver, and adds to the comment about
the gl_framebuffer "Name" field so that this isn't a surprise to other
driver writers.
(cherry picked from commit 6dceeb2eb804d708639d68a13a924d65f366458a)

---

 src/mesa/drivers/dri/i965/brw_sf.c |   10 ++++++++--
 src/mesa/main/mtypes.h             |   12 ++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
index 8c17115..c3c8597 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -167,8 +167,14 @@ static void upload_sf_prog(struct brw_context *brw)
    key.do_twoside_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
 
    /* _NEW_POLYGON */
-   if (key.do_twoside_color)
-      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW);
+   if (key.do_twoside_color) {
+      /* If we're rendering to a FBO, we have to invert the polygon
+       * face orientation, just as we invert the viewport in
+       * sf_unit_create_from_key().  ctx->DrawBuffer->Name will be
+       * nonzero if we're rendering to such an FBO.
+       */
+      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW) ^ (ctx->DrawBuffer->Name != 0);
+   }
 
    dri_bo_unreference(brw->sf.prog_bo);
    brw->sf.prog_bo = brw_search_cache(&brw->cache, BRW_SF_PROG,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 61177ae..5a2603f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2376,8 +2376,16 @@ struct gl_renderbuffer_attachment
  */
 struct gl_framebuffer
 {
-   _glthread_Mutex Mutex;		   /**< for thread safety */
-   GLuint Name;      /* if zero, this is a window system framebuffer */
+   _glthread_Mutex Mutex;  /**< for thread safety */
+   /**
+    * If zero, this is a window system framebuffer.  If non-zero, this
+    * is a FBO framebuffer; note that for some devices (i.e. those with
+    * a natural pixel coordinate system for FBOs that differs from the 
+    * OpenGL/Mesa coordinate system), this means that both the viewport
+    * and polygon face orientation will have to be inverted.
+    */
+   GLuint Name;
+
    GLint RefCount;
    GLboolean DeletePending;
 




More information about the mesa-commit mailing list