[Mesa-dev] [PATCH] st/mesa: use SINT/UINT formats for VertexAttribIPointer

Christoph Bumiller e0425955 at student.tuwien.ac.at
Mon Dec 19 07:45:02 PST 2011


---
 src/mesa/state_tracker/st_draw.c          |   63 +++++++++++++++++++++++++++--
 src/mesa/state_tracker/st_draw.h          |    2 +-
 src/mesa/state_tracker/st_draw_feedback.c |    3 +-
 3 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 87a9978..e8a7fe3 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -102,6 +102,13 @@ static GLuint uint_types_scale[4] = {
    PIPE_FORMAT_R32G32B32A32_USCALED
 };
 
+static GLuint uint_types_int[4] = {
+   PIPE_FORMAT_R32_UINT,
+   PIPE_FORMAT_R32G32_UINT,
+   PIPE_FORMAT_R32G32B32_UINT,
+   PIPE_FORMAT_R32G32B32A32_UINT
+};
+
 static GLuint int_types_norm[4] = {
    PIPE_FORMAT_R32_SNORM,
    PIPE_FORMAT_R32G32_SNORM,
@@ -116,6 +123,13 @@ static GLuint int_types_scale[4] = {
    PIPE_FORMAT_R32G32B32A32_SSCALED
 };
 
+static GLuint int_types_int[4] = {
+   PIPE_FORMAT_R32_SINT,
+   PIPE_FORMAT_R32G32_SINT,
+   PIPE_FORMAT_R32G32B32_SINT,
+   PIPE_FORMAT_R32G32B32A32_SINT
+};
+
 static GLuint ushort_types_norm[4] = {
    PIPE_FORMAT_R16_UNORM,
    PIPE_FORMAT_R16G16_UNORM,
@@ -130,6 +144,13 @@ static GLuint ushort_types_scale[4] = {
    PIPE_FORMAT_R16G16B16A16_USCALED
 };
 
+static GLuint ushort_types_int[4] = {
+   PIPE_FORMAT_R16_UINT,
+   PIPE_FORMAT_R16G16_UINT,
+   PIPE_FORMAT_R16G16B16_UINT,
+   PIPE_FORMAT_R16G16B16A16_UINT
+};
+
 static GLuint short_types_norm[4] = {
    PIPE_FORMAT_R16_SNORM,
    PIPE_FORMAT_R16G16_SNORM,
@@ -144,6 +165,13 @@ static GLuint short_types_scale[4] = {
    PIPE_FORMAT_R16G16B16A16_SSCALED
 };
 
+static GLuint short_types_int[4] = {
+   PIPE_FORMAT_R16_SINT,
+   PIPE_FORMAT_R16G16_SINT,
+   PIPE_FORMAT_R16G16B16_SINT,
+   PIPE_FORMAT_R16G16B16A16_SINT
+};
+
 static GLuint ubyte_types_norm[4] = {
    PIPE_FORMAT_R8_UNORM,
    PIPE_FORMAT_R8G8_UNORM,
@@ -158,6 +186,13 @@ static GLuint ubyte_types_scale[4] = {
    PIPE_FORMAT_R8G8B8A8_USCALED
 };
 
+static GLuint ubyte_types_int[4] = {
+   PIPE_FORMAT_R8_UINT,
+   PIPE_FORMAT_R8G8_UINT,
+   PIPE_FORMAT_R8G8B8_UINT,
+   PIPE_FORMAT_R8G8B8A8_UINT
+};
+
 static GLuint byte_types_norm[4] = {
    PIPE_FORMAT_R8_SNORM,
    PIPE_FORMAT_R8G8_SNORM,
@@ -172,6 +207,13 @@ static GLuint byte_types_scale[4] = {
    PIPE_FORMAT_R8G8B8A8_SSCALED
 };
 
+static GLuint byte_types_int[4] = {
+   PIPE_FORMAT_R8_SINT,
+   PIPE_FORMAT_R8G8_SINT,
+   PIPE_FORMAT_R8G8B8_SINT,
+   PIPE_FORMAT_R8G8B8A8_SINT
+};
+
 static GLuint fixed_types[4] = {
    PIPE_FORMAT_R32_FIXED,
    PIPE_FORMAT_R32G32_FIXED,
@@ -186,7 +228,7 @@ static GLuint fixed_types[4] = {
  */
 enum pipe_format
 st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
-                      GLboolean normalized)
+                      GLboolean normalized, GLboolean integer)
 {
    assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
           type == GL_FIXED || type == GL_HALF_FLOAT ||
@@ -234,7 +276,18 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
       return PIPE_FORMAT_B8G8R8A8_UNORM;
    }
 
-   if (normalized) {
+   if (integer) {
+      switch (type) {
+      case GL_INT: return int_types_int[size-1];
+      case GL_SHORT: return short_types_int[size-1];
+      case GL_BYTE: return byte_types_int[size-1];
+      case GL_UNSIGNED_INT: return uint_types_int[size-1];
+      case GL_UNSIGNED_SHORT: return ushort_types_int[size-1];
+      case GL_UNSIGNED_BYTE: return ubyte_types_int[size-1];
+      default: assert(0); return 0;
+      }
+   }
+   else if (normalized) {
       switch (type) {
       case GL_DOUBLE: return double_types[size-1];
       case GL_FLOAT: return float_types[size-1];
@@ -407,7 +460,8 @@ setup_interleaved_attribs(struct gl_context *ctx,
       velements[attr].src_format = st_pipe_vertex_format(array->Type,
                                                          array->Size,
                                                          array->Format,
-                                                         array->Normalized);
+                                                         array->Normalized,
+							 array->Integer);
       assert(velements[attr].src_format);
 
       if (!usingVBO) {
@@ -564,7 +618,8 @@ setup_non_interleaved_attribs(struct gl_context *ctx,
       velements[attr].src_format = st_pipe_vertex_format(array->Type,
                                                          array->Size,
                                                          array->Format,
-                                                         array->Normalized);
+                                                         array->Normalized,
+                                                         array->Integer);
       assert(velements[attr].src_format);
    }
 
diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h
index 2623cdb..47bdb11 100644
--- a/src/mesa/state_tracker/st_draw.h
+++ b/src/mesa/state_tracker/st_draw.h
@@ -73,7 +73,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
  */
 extern enum pipe_format
 st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
-                      GLboolean normalized);
+                      GLboolean normalized, GLboolean integer);
 
 
 /**
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 4c1e674..0c77e53 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -196,7 +196,8 @@ st_feedback_draw_vbo(struct gl_context *ctx,
          st_pipe_vertex_format(arrays[mesaAttr]->Type,
                                arrays[mesaAttr]->Size,
                                arrays[mesaAttr]->Format,
-                               arrays[mesaAttr]->Normalized);
+                               arrays[mesaAttr]->Normalized,
+                               arrays[mesaAttr]->Integer);
       assert(velements[attr].src_format);
 
       /* tell draw about this attribute */
-- 
1.7.3.4



More information about the mesa-dev mailing list