[Mesa-dev] [PATCH 06/14] mesa/varray: create get_array_format() helper

Timothy Arceri tarceri at itsqueeze.com
Tue Apr 18 00:09:45 UTC 2017


This will help us split array validation from array update.

V2: add const to ctx param
---
 src/mesa/main/varray.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 65734df..f00a64b 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -251,20 +251,38 @@ get_legal_types_mask(const struct gl_context *ctx)
          legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
                              INT_2_10_10_10_REV_BIT);
 
       if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
          legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
    }
 
    return legalTypesMask;
 }
 
+static GLenum
+get_array_format(const struct gl_context *ctx, GLint sizeMax, GLint *size)
+{
+   GLenum format = GL_RGBA;
+
+   /* Do size parameter checking.
+    * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
+    * must be handled specially.
+    */
+   if (ctx->Extensions.EXT_vertex_array_bgra && sizeMax == BGRA_OR_4 &&
+       *size == GL_BGRA) {
+      format = GL_BGRA;
+      *size = 4;
+   }
+
+   return format;
+}
+
 
 /**
  * \param attrib         The index of the attribute array
  * \param size           Components per element (1, 2, 3 or 4)
  * \param type           Datatype of each component (GL_FLOAT, GL_INT, etc)
  * \param format         Either GL_RGBA or GL_BGRA.
  * \param normalized     Whether integer types are converted to floats in [-1, 1]
  * \param integer        Integer-valued values (will not be normalized to [-1, 1])
  * \param doubles        Double values not reduced to floats
  * \param relativeOffset Offset of the first element relative to the binding
@@ -322,21 +340,21 @@ static bool
 update_array_format(struct gl_context *ctx,
                     const char *func,
                     struct gl_vertex_array_object *vao,
                     GLuint attrib, GLbitfield legalTypesMask,
                     GLint sizeMin, GLint sizeMax,
                     GLint size, GLenum type,
                     GLboolean normalized, GLboolean integer, GLboolean doubles,
                     GLuint relativeOffset)
 {
    GLbitfield typeBit;
-   GLenum format = GL_RGBA;
+   GLenum format = get_array_format(ctx, sizeMax, &size);
 
    /* at most, one of these bools can be true */
    assert((int) normalized + (int) integer + (int) doubles <= 1);
 
    if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
       /* Compute the LegalTypesMask only once, unless the context API has
        * changed, in which case we want to compute it again.  We can't do this
        * in _mesa_init_varrays() below because extensions are not yet enabled
        * at that point.
        */
@@ -352,27 +370,21 @@ update_array_format(struct gl_context *ctx,
       sizeMax = 4;
    }
 
    typeBit = type_to_bit(ctx, type);
    if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
       _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
                   func, _mesa_enum_to_string(type));
       return false;
    }
 
-   /* Do size parameter checking.
-    * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
-    * must be handled specially.
-    */
-   if (ctx->Extensions.EXT_vertex_array_bgra &&
-       sizeMax == BGRA_OR_4 &&
-       size == GL_BGRA) {
+   if (format == GL_BGRA) {
       /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
        *
        * "An INVALID_OPERATION error is generated under any of the following
        *  conditions:
        *    ...
        *    • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
        *      or UNSIGNED_INT_2_10_10_10_REV;
        *    ...
        *    • size is BGRA and normalized is FALSE;"
        */
@@ -390,23 +402,20 @@ update_array_format(struct gl_context *ctx,
          _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
                      func, _mesa_enum_to_string(type));
          return false;
       }
 
       if (!normalized) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
          return false;
       }
-
-      format = GL_BGRA;
-      size = 4;
    }
    else if (size < sizeMin || size > sizeMax || size > 4) {
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
       return false;
    }
 
    if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
        (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
         type == GL_INT_2_10_10_10_REV) && size != 4) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
-- 
2.9.3



More information about the mesa-dev mailing list