Port viewport setting code from R200.
authorVladimir Dergachev <volodya@freedesktop.org>
Thu, 30 Dec 2004 06:06:54 +0000 (06:06 +0000)
committerVladimir Dergachev <volodya@freedesktop.org>
Thu, 30 Dec 2004 06:06:54 +0000 (06:06 +0000)
Take it outside R300ResetHwState.

src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_state.h

index be276592593cc7b9b599ea9b7e45addbbb986faa..5863ee52f2f253a2f8fda3fc9c13f19b18dd672e 100644 (file)
@@ -308,7 +308,13 @@ struct r300_cmdbuf {
 /**
  * State cache
  */
+struct r300_depthbuffer_state {
+       GLfloat scale;
+};
+
 struct r300_state {
+       struct r300_depthbuffer_state depth;
 };
 
 
@@ -321,6 +327,11 @@ struct r300_context {
        struct r300_hw_state hw;
        struct r300_cmdbuf cmdbuf;
        struct r300_state state;
+       
+       /* Vertex buffers */
+       int elt_count;  /* size of the buffer for vertices */
+       int attrib_count; /* size of the buffer for vertex attributes.. Somehow it can be different ? */
+       
 };
 
 #define R300_CONTEXT(ctx)              ((r300ContextPtr)(ctx->DriverCtx))
index 86b457bf82c3310a1257c0afcac797b354098af1..d080ae5bf719a9feb4f38464c760533146421cef 100644 (file)
@@ -225,6 +225,58 @@ static void r300ColorMask(GLcontext* ctx,
        }
 }
 
+/* =============================================================
+ * Window position and viewport transformation
+ */
+
+/*
+ * To correctly position primitives:
+ */
+#define SUBPIXEL_X 0.125
+#define SUBPIXEL_Y 0.125
+
+void r300UpdateWindow(GLcontext * ctx)
+{
+       r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       __DRIdrawablePrivate *dPriv = rmesa->radeon.dri.drawable;
+       GLfloat xoffset = dPriv ? (GLfloat) dPriv->x : 0;
+       GLfloat yoffset = dPriv ? (GLfloat) dPriv->y + dPriv->h : 0;
+       const GLfloat *v = ctx->Viewport._WindowMap.m;
+
+       GLfloat sx = v[MAT_SX];
+       GLfloat tx = v[MAT_TX] + xoffset + SUBPIXEL_X;
+       GLfloat sy = -v[MAT_SY];
+       GLfloat ty = (-v[MAT_TY]) + yoffset + SUBPIXEL_Y;
+       GLfloat sz = v[MAT_SZ] * rmesa->state.depth.scale;
+       GLfloat tz = v[MAT_TZ] * rmesa->state.depth.scale;
+
+       R300_FIREVERTICES(rmesa);
+       R300_STATECHANGE(rmesa, vpt);
+
+       rmesa->hw.vpt.cmd[R300_VPT_XSCALE]  = r300PackFloat32(sx);
+       rmesa->hw.vpt.cmd[R300_VPT_XOFFSET] = r300PackFloat32(tx);
+       rmesa->hw.vpt.cmd[R300_VPT_YSCALE]  = r300PackFloat32(sy);
+       rmesa->hw.vpt.cmd[R300_VPT_YOFFSET] = r300PackFloat32(ty);
+       rmesa->hw.vpt.cmd[R300_VPT_ZSCALE]  = r300PackFloat32(sz);
+       rmesa->hw.vpt.cmd[R300_VPT_ZOFFSET] = r300PackFloat32(tz);
+}
+
+static void r300Viewport(GLcontext * ctx, GLint x, GLint y,
+                        GLsizei width, GLsizei height)
+{
+       /* Don't pipeline viewport changes, conflict with window offset
+        * setting below.  Could apply deltas to rescue pipelined viewport
+        * values, or keep the originals hanging around.
+        */
+       R200_FIREVERTICES(R200_CONTEXT(ctx));
+       r300UpdateWindow(ctx);
+}
+
+static void r300DepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
+{
+       r300UpdateWindow(ctx);
+}
+
 
 /**
  * Called by Mesa after an internal state update.
@@ -255,26 +307,8 @@ void r300ResetHwState(r300ContextPtr r300)
        if (RADEON_DEBUG & DEBUG_STATE)
                fprintf(stderr, "%s\n", __FUNCTION__);
 
-       {
-               __DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable;
-               GLfloat xoffset = dPriv ? (GLfloat) dPriv->x : 0;
-               GLfloat yoffset = dPriv ? (GLfloat) dPriv->y + dPriv->h : 0;
-               const GLfloat *v = ctx->Viewport._WindowMap.m;
-
-               r300->hw.vpt.cmd[R300_VPT_XSCALE] =
-                       r300PackFloat32(v[MAT_SX]);
-               r300->hw.vpt.cmd[R300_VPT_XOFFSET] =
-                       r300PackFloat32(v[MAT_TX] + xoffset);
-               r300->hw.vpt.cmd[R300_VPT_YSCALE] =
-                       r300PackFloat32(-v[MAT_SY]);
-               r300->hw.vpt.cmd[R300_VPT_YOFFSET] =
-                       r300PackFloat32(-v[MAT_TY] + yoffset);
-               r300->hw.vpt.cmd[R300_VPT_ZSCALE] =
-                       r300PackFloat32(v[MAT_SZ]);
-               r300->hw.vpt.cmd[R300_VPT_ZOFFSET] =
-                       r300PackFloat32(v[MAT_TZ]);
-       }
-
+       r300UpdateWindow(ctx);
+       
        r300ColorMask(ctx,
                ctx->Color.ColorMask[RCOMP],
                ctx->Color.ColorMask[GCOMP],
@@ -504,11 +538,14 @@ void r300ResetHwState(r300ContextPtr r300)
 void r300InitState(r300ContextPtr r300)
 {
        radeonInitState(&r300->radeon);
+       
+       r300->state.depth.scale = 1.0 / (GLfloat) 0xffff;
 
        r300ResetHwState(r300);
 }
 
 
+
 /**
  * Initialize driver's state callback functions
  */
@@ -523,5 +560,9 @@ void r300InitStateFuncs(struct dd_function_table* functions)
        functions->DepthMask = r300DepthMask;
        functions->CullFace = r300CullFace;
        functions->FrontFace = r300FrontFace;
+
+       /* Viewport related */
+       functions->Viewport = r300Viewport;
+       functions->DepthRange = r300DepthRange;
 }
 
index 9c945c4cdd66d28097632099b6b7fac4462caed3..a04835c79d15ecac9917c703bc3481ae41373506 100644 (file)
@@ -43,6 +43,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                r300->hw.is_dirty = GL_TRUE;            \
        } while(0)
 
+/* Fire the buffered vertices no matter what.
+   TODO: This has not been implemented yet
+ */
+#define R300_FIREVERTICES( r300 )                      \
+do {                                                   \
+   /* \
+   if ( (r300)->store.cmd_used || (r300)->dma.flush ) {        \
+      radeonFlush( (r300)->radeon.glCtx );             \
+   }                                                   \
+   */ \
+} while (0)
+
+       
 extern void r300ResetHwState(r300ContextPtr r300);
 
 extern void r300InitState(r300ContextPtr r300);