Fixed MAXFIFO_S4. Removed WAIT_IDLE_EMPTY from savage_BCI_swap which resulted
[mesa.git] / src / mesa / tnl / t_vertex.c
index e932ee0ca7857017f6ca340d41250b628c72ac57..fc076190e464aa99ca9eb0f93091559867ceaab9 100644 (file)
 
 #define GET_VERTEX_STATE(ctx)  &(TNL_CONTEXT(ctx)->clipspace)
 
-static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
-                               const GLfloat *in )
+
+/*
+ * These functions take the NDC coordinates pointed to by 'in', apply the
+ * NDC->Viewport mapping and store the results at 'v'.
+ */
+
+static void
+insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+                      const GLfloat *in )
 {
    GLfloat *out = (GLfloat *)v;
    const GLfloat * const vp = a->vp;
@@ -147,6 +154,10 @@ static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v
 }
 
 
+/*
+ * These functions do the same as above, except for the viewport mapping.
+ */
+
 static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
 {
    GLfloat *out = (GLfloat *)(v);
@@ -409,7 +420,7 @@ static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
 {
    UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
    v[1] = 0;
-   v[0]= 0;
+   v[0] = 0;
 }
 
 
@@ -433,6 +444,9 @@ static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *ou
    const GLfloat *in = (const GLfloat *)v;
    const GLfloat * const vp = a->vp;
    
+   /* Although included for completeness, the position coordinate is
+    * usually handled differently during clipping.
+    */
    out[0] = (in[0] - vp[12]) / vp[0];
    out[1] = (in[1] - vp[13]) / vp[5];
    out[2] = (in[2] - vp[14]) / vp[10];
@@ -481,8 +495,8 @@ static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, co
    
    out[0] = in[0];
    out[1] = in[1];
-   out[2] = in[3];
-   out[3] = 1;
+   out[2] = 0;
+   out[3] = in[2];
 }
 
 
@@ -577,7 +591,7 @@ struct {
    const char *name;
    extract_func extract;
    insert_func insert[4];
-   GLuint attrsize;
+   const GLuint attrsize;
 } format_info[EMIT_MAX] = {
 
    { "1f",
@@ -681,7 +695,7 @@ static void generic_emit( GLcontext *ctx,
    struct tnl_clipspace_attr *a = vtx->attr;
    GLubyte *v = (GLubyte *)dest;
    GLuint i, j;
-   GLuint count = vtx->attr_count;
+   const GLuint count = vtx->attr_count;
    GLuint stride;
 
    for (j = 0; j < count; j++) {
@@ -712,12 +726,12 @@ static void generic_interp( GLcontext *ctx,
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
-   GLubyte *vin  = vtx->vertex_buf + ein  * vtx->vertex_size;
-   GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
+   const GLubyte *vin  = vtx->vertex_buf + ein  * vtx->vertex_size;
+   const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
    GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
    const struct tnl_clipspace_attr *a = vtx->attr;
-   int attr_count = vtx->attr_count;
-   int j;
+   const GLuint attr_count = vtx->attr_count;
+   GLuint j;
 
    if (tnl->NeedNdcCoords) {
       const GLfloat *dstclip = VB->ClipPtr->data[edst];
@@ -763,8 +777,8 @@ static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
    GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
    GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
    const struct tnl_clipspace_attr *a = vtx->attr;
-   int attr_count = vtx->attr_count;
-   int j;
+   const GLuint attr_count = vtx->attr_count;
+   GLuint j;
 
    for (j = 0; j < attr_count; j++) {
       if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
@@ -834,14 +848,12 @@ static void generic_copy_pv_extras( GLcontext *ctx,
       VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
    }
 
-   _tnl_copy_pv(ctx, dst, src);
+   generic_copy_pv(ctx, dst, src);
 }
 
 
 
 
-
-
 /***********************************************************************
  * Build codegen functions or return generic ones:
  */
@@ -924,8 +936,8 @@ void _tnl_get_attr( GLcontext *ctx, const void *vin,
 {
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
    const struct tnl_clipspace_attr *a = vtx->attr;
-   int attr_count = vtx->attr_count;
-   int j;
+   const GLuint attr_count = vtx->attr_count;
+   GLuint j;
 
    for (j = 0; j < attr_count; j++) {
       if (a[j].attrib == (int)attr) {
@@ -934,11 +946,31 @@ void _tnl_get_attr( GLcontext *ctx, const void *vin,
       }
    }
 
-   /* Else return the value from ctx->Current
+   /* Else return the value from ctx->Current -- dangerous???
     */
    _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
 }
 
+
+/* Complementary operation to the above.
+ */
+void _tnl_set_attr( GLcontext *ctx, void *vout,
+                   GLenum attr, const GLfloat *src )
+{
+   struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+   const struct tnl_clipspace_attr *a = vtx->attr;
+   const GLuint attr_count = vtx->attr_count;
+   GLuint j;
+
+   for (j = 0; j < attr_count; j++) {
+      if (a[j].attrib == (int)attr) {
+        a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src );
+        return;
+      }
+   }
+}
+
+
 void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
 {
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
@@ -962,7 +994,7 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
                           GLuint unpacked_size )
 {
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
-   int offset = 0;
+   GLuint offset = 0;
    GLuint i, j;
 
    assert(nr < _TNL_ATTRIB_MAX);
@@ -974,12 +1006,12 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
    vtx->new_inputs = ~0;
 
    for (j = 0, i = 0; i < nr; i++) {
-      GLuint format = map[i].format;
+      const GLuint format = map[i].format;
       if (format == EMIT_PAD) {
         offset += map[i].offset;
 
-/*         fprintf(stderr, "%d: pad %d, offset now %d\n", i,  */
-/*                 map[i].offset, offset);  */
+/*      fprintf(stderr, "%d: pad %d, offset now %d\n", i,   */
+/*              map[i].offset, offset);   */
 
       }
       else {
@@ -994,8 +1026,8 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
         else
            vtx->attr[j].vertoffset = offset;
         
-/*         fprintf(stderr, "%d: %s offset %d\n", i,  */
-/*                 format_info[format].name, vtx->attr[j].vertoffset);  */
+/*      fprintf(stderr, "%d: %s offset %d\n", i,  */
+/*              format_info[format].name, vtx->attr[j].vertoffset);   */
         
         offset += format_info[format].attrsize;
         j++;
@@ -1030,14 +1062,14 @@ void _tnl_build_vertices( GLcontext *ctx,
                          GLuint newinputs )
 {
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
-   GLuint stride = vtx->vertex_size;
-   GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride));
+   const GLuint stride = vtx->vertex_size;
+   GLubyte *vDest = ((GLubyte *)vtx->vertex_buf + (start*stride));
 
    newinputs |= vtx->new_inputs;
    vtx->new_inputs = 0;
 
    if (newinputs)
-      vtx->emit( ctx, start, end, v );
+      vtx->emit( ctx, start, end, vDest );
 }