st/mesa: use SINT/UINT formats for VertexAttribIPointer
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Tue, 3 Jan 2012 22:00:31 +0000 (23:00 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Tue, 3 Jan 2012 22:00:31 +0000 (23:00 +0100)
Reviewed-by: Dave Airlie <airlied@redhat.com>
v2: added assertion that packed formats are not pure integer

src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_draw.h
src/mesa/state_tracker/st_draw_feedback.c

index 954f15a3437569948497cb21dc6058690bd8968f..a21160c956d6cca70d9345b69fb1021fe2eb4236 100644 (file)
@@ -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 ||
@@ -199,6 +241,7 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
    if (type == GL_INT_2_10_10_10_REV ||
        type == GL_UNSIGNED_INT_2_10_10_10_REV) {
       assert(size == 4);
+      assert(!integer);
 
       if (format == GL_BGRA) {
          if (type == GL_INT_2_10_10_10_REV) {
@@ -234,7 +277,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 +461,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 +619,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);
    }
 
index 2623cdbb1ff26854d508ffc6dbefcf1acaab4bf9..47bdb11f81cdda4746ac343a1fe6b744eeab2835 100644 (file)
@@ -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);
 
 
 /**
index a99eb2bf7d5c32f79985366f756d626530edfb01..fbf0349b41bde69538613041df15f866656000d9 100644 (file)
@@ -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 */