Merge branch '7.8'
[mesa.git] / src / gallium / auxiliary / draw / draw_vertex.h
index a943607d7ede7ea69efea7d9bdae5f9714b08378..ca272371267a957aab5f23dbd11892ca03c1515a 100644 (file)
@@ -39,7 +39,9 @@
 #define DRAW_VERTEX_H
 
 
+#include "pipe/p_compiler.h"
 #include "pipe/p_state.h"
+#include "util/u_debug.h"
 
 
 /**
@@ -52,7 +54,8 @@ enum attrib_emit {
    EMIT_2F,
    EMIT_3F,
    EMIT_4F,
-   EMIT_4UB  /**< XXX may need variations for RGBA vs BGRA, etc */
+   EMIT_4UB, /**< is RGBA like the rest */
+   EMIT_4UB_BGRA
 };
 
 
@@ -81,24 +84,23 @@ struct vertex_info
     * memcmp() comparisons.
     */
    struct {
-      ubyte interp_mode:4;      /**< INTERP_x */
-      ubyte emit:4;             /**< EMIT_x */
-      ubyte src_index;          /**< map to post-xform attribs */
+      unsigned interp_mode:4;      /**< INTERP_x */
+      unsigned emit:4;             /**< EMIT_x */
+      unsigned src_index:8;          /**< map to post-xform attribs */
    } attrib[PIPE_MAX_SHADER_INPUTS];
 };
 
-static INLINE int
+static INLINE size_t
 draw_vinfo_size( const struct vertex_info *a )
 {
-   return ((const char *)&a->attrib[a->num_attribs] -
-           (const char *)a);
+   return offsetof(const struct vertex_info, attrib[a->num_attribs]);
 }
 
 static INLINE int
 draw_vinfo_compare( const struct vertex_info *a,
                     const struct vertex_info *b )
 {
-   unsigned sizea = draw_vinfo_size( a );
+   size_t sizea = draw_vinfo_size( a );
    return memcmp( a, b, sizea );
 }
 
@@ -106,7 +108,7 @@ static INLINE void
 draw_vinfo_copy( struct vertex_info *dst,
                  const struct vertex_info *src )
 {
-   unsigned size = draw_vinfo_size( src );
+   size_t size = draw_vinfo_size( src );
    memcpy( dst, src, size );
 }
 
@@ -140,9 +142,11 @@ void draw_dump_emitted_vertex(const struct vertex_info *vinfo,
                               const uint8_t *data);
 
 
-static INLINE unsigned draw_translate_vinfo_format(unsigned format )
+static INLINE unsigned draw_translate_vinfo_format(enum attrib_emit emit)
 {
-   switch (format) {
+   switch (emit) {
+   case EMIT_OMIT:
+      return PIPE_FORMAT_NONE;
    case EMIT_1F:
    case EMIT_1F_PSIZE:
       return PIPE_FORMAT_R32_FLOAT;
@@ -154,10 +158,36 @@ static INLINE unsigned draw_translate_vinfo_format(unsigned format )
       return PIPE_FORMAT_R32G32B32A32_FLOAT;
    case EMIT_4UB:
       return PIPE_FORMAT_R8G8B8A8_UNORM;
+   case EMIT_4UB_BGRA:
+      return PIPE_FORMAT_B8G8R8A8_UNORM;
    default:
+      assert(!"unexpected format");
       return PIPE_FORMAT_NONE;
    }
 }
 
+static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit)
+{
+   switch (emit) {
+   case EMIT_OMIT:
+      return 0;
+   case EMIT_1F:
+   case EMIT_1F_PSIZE:
+      return 1 * sizeof(float);
+   case EMIT_2F:
+      return 2 * sizeof(float);
+   case EMIT_3F:
+      return 3 * sizeof(float);
+   case EMIT_4F:
+      return 4 * sizeof(float);
+   case EMIT_4UB:
+      return 4 * sizeof(unsigned char);
+   case EMIT_4UB_BGRA:
+      return 4 * sizeof(unsigned char);
+   default:
+      assert(!"unexpected format");
+      return 0;
+   }
+}
 
 #endif /* DRAW_VERTEX_H */