[Mesa-dev] [PATCH 15/23] mesa: implement glGetUnsignedByte{v|i_v}

Timothy Arceri tarceri at itsqueeze.com
Fri Aug 4 01:54:18 UTC 2017


From: Andres Rodriguez <andresx7 at gmail.com>

These are used by EXT_external_objects to present UUIDs for the device
and the driver.

v2 (Timothy Arceri):
 - remove extra break
 - use _mesa_problem() rather the _mesa_error() for unimplemented
   support for value types

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/mesa/main/get.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 174 insertions(+)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 982f64a08a..75d77c80b0 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1424,20 +1424,86 @@ find_value(const char *func, GLenum pname, void **p, union value *v)
    return &error_value;
 }
 
 static const int transpose[] = {
    0, 4,  8, 12,
    1, 5,  9, 13,
    2, 6, 10, 14,
    3, 7, 11, 15
 };
 
+static GLsizei
+get_value_size(enum value_type type, const union value *v)
+{
+   switch (type) {
+   case TYPE_INVALID:
+      return 0;
+   case TYPE_CONST:
+   case TYPE_UINT:
+   case TYPE_INT:
+      return sizeof(GLint);
+   case TYPE_INT_2:
+   case TYPE_UINT_2:
+      return sizeof(GLint) * 2;
+   case TYPE_INT_3:
+   case TYPE_UINT_3:
+      return sizeof(GLint) * 3;
+   case TYPE_INT_4:
+   case TYPE_UINT_4:
+      return sizeof(GLint) * 4;
+   case TYPE_INT_N:
+      return sizeof(GLint) * v->value_int_n.n;
+   case TYPE_INT64:
+      return sizeof(GLint64);
+      break;
+   case TYPE_ENUM:
+      return sizeof(GLenum);
+   case TYPE_ENUM_2:
+      return sizeof(GLenum) * 2;
+   case TYPE_BOOLEAN:
+      return sizeof(GLboolean);
+   case TYPE_BIT_0:
+   case TYPE_BIT_1:
+   case TYPE_BIT_2:
+   case TYPE_BIT_3:
+   case TYPE_BIT_4:
+   case TYPE_BIT_5:
+   case TYPE_BIT_6:
+   case TYPE_BIT_7:
+      return 1;
+   case TYPE_FLOAT:
+   case TYPE_FLOATN:
+      return sizeof(GLfloat);
+   case TYPE_FLOAT_2:
+   case TYPE_FLOATN_2:
+      return sizeof(GLfloat) * 2;
+   case TYPE_FLOAT_3:
+   case TYPE_FLOATN_3:
+      return sizeof(GLfloat) * 3;
+   case TYPE_FLOAT_4:
+   case TYPE_FLOATN_4:
+      return sizeof(GLfloat) * 4;
+   case TYPE_FLOAT_8:
+      return sizeof(GLfloat) * 8;
+   case TYPE_DOUBLEN:
+      return sizeof(GLdouble);
+   case TYPE_DOUBLEN_2:
+      return sizeof(GLdouble) * 2;
+   case TYPE_MATRIX:
+      return sizeof (GLfloat) * 16;
+   case TYPE_MATRIX_T:
+      return sizeof (GLfloat) * 16;
+   default:
+      return -1;
+   }
+}
+
 void GLAPIENTRY
 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
 {
    const struct value_desc *d;
    union value v;
    GLmatrix *m;
    int shift, i;
    void *p;
 
    d = find_value("glGetBooleanv", pname, &p, &v);
@@ -1942,21 +2008,83 @@ _mesa_GetDoublev(GLenum pname, GLdouble *params)
    case TYPE_BIT_7:
       shift = d->type - TYPE_BIT_0;
       params[0] = (*(GLbitfield *) p >> shift) & 1;
       break;
    }
 }
 
 void GLAPIENTRY
 _mesa_GetUnsignedBytevEXT(GLenum pname, GLubyte *data)
 {
+   const struct value_desc *d;
+   union value v;
+   int shift;
+   void *p;
+   GLsizei size;
+   const char *func = "glGetUnsignedBytevEXT";
+
+   GET_CURRENT_CONTEXT(ctx);
 
+   d = find_value(func, pname, &p, &v);
+   size = get_value_size(d->type, &v);
+   if (size >= 0) {
+      _mesa_problem(ctx, "invalid value type in GetUnsignedBytevEXT()");
+   }
+
+   switch (d->type) {
+   case TYPE_BIT_0:
+   case TYPE_BIT_1:
+   case TYPE_BIT_2:
+   case TYPE_BIT_3:
+   case TYPE_BIT_4:
+   case TYPE_BIT_5:
+   case TYPE_BIT_6:
+   case TYPE_BIT_7:
+      shift = d->type - TYPE_BIT_0;
+      data[0] = (*(GLbitfield *) p >> shift) & 1;
+      break;
+   case TYPE_CONST:
+      memcpy(data, &d->offset, size);
+      break;
+   case TYPE_INT_N:
+      memcpy(data, &v.value_int_n.ints, size);
+      break;
+   case TYPE_UINT:
+   case TYPE_INT:
+   case TYPE_INT_2:
+   case TYPE_UINT_2:
+   case TYPE_INT_3:
+   case TYPE_UINT_3:
+   case TYPE_INT_4:
+   case TYPE_UINT_4:
+   case TYPE_INT64:
+   case TYPE_ENUM:
+   case TYPE_ENUM_2:
+   case TYPE_BOOLEAN:
+   case TYPE_FLOAT:
+   case TYPE_FLOATN:
+   case TYPE_FLOAT_2:
+   case TYPE_FLOATN_2:
+   case TYPE_FLOAT_3:
+   case TYPE_FLOATN_3:
+   case TYPE_FLOAT_4:
+   case TYPE_FLOATN_4:
+   case TYPE_FLOAT_8:
+   case TYPE_DOUBLEN:
+   case TYPE_DOUBLEN_2:
+   case TYPE_MATRIX:
+   case TYPE_MATRIX_T:
+      memcpy(data, p, size);
+      break;
+   default:
+      break; /* nothing - GL error was recorded */
+   }
 }
 
 /**
  * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
  * into the corresponding Mesa texture target index.
  * \return TEXTURE_x_INDEX or -1 if binding is invalid
  */
 static int
 tex_binding_to_index(const struct gl_context *ctx, GLenum binding)
 {
@@ -2653,21 +2781,67 @@ _mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
       break;
 
    default:
       ;
    }
 }
 
 void GLAPIENTRY
 _mesa_GetUnsignedBytei_vEXT(GLenum target, GLuint index, GLubyte *data)
 {
+   GLsizei size;
+   union value v;
+   enum value_type type;
+   const char *func = "glGetUnsignedBytei_vEXT";
+
+   GET_CURRENT_CONTEXT(ctx);
 
+   type = find_value_indexed(func, target, index, &v);
+   size = get_value_size(type, &v);
+   if (size <= 0) {
+      _mesa_problem(ctx, "invalid value type in GetUnsignedBytei_vEXT()");
+   }
+
+   switch (type) {
+   case TYPE_UINT:
+   case TYPE_INT:
+   case TYPE_INT_2:
+   case TYPE_UINT_2:
+   case TYPE_INT_3:
+   case TYPE_UINT_3:
+   case TYPE_INT_4:
+   case TYPE_UINT_4:
+   case TYPE_INT64:
+   case TYPE_ENUM:
+   case TYPE_ENUM_2:
+   case TYPE_BOOLEAN:
+   case TYPE_FLOAT:
+   case TYPE_FLOATN:
+   case TYPE_FLOAT_2:
+   case TYPE_FLOATN_2:
+   case TYPE_FLOAT_3:
+   case TYPE_FLOATN_3:
+   case TYPE_FLOAT_4:
+   case TYPE_FLOATN_4:
+   case TYPE_FLOAT_8:
+   case TYPE_DOUBLEN:
+   case TYPE_DOUBLEN_2:
+   case TYPE_MATRIX:
+   case TYPE_MATRIX_T:
+      memcpy(data, &v.value_int, size);
+      break;
+   case TYPE_INT_N:
+      memcpy(data, &v.value_int_n.ints, size);
+      break;
+   default:
+      break; /* nothing - GL error was recorded */
+   }
 }
 
 void GLAPIENTRY
 _mesa_GetFixedv(GLenum pname, GLfixed *params)
 {
    const struct value_desc *d;
    union value v;
    GLmatrix *m;
    int shift, i;
    void *p;
-- 
2.13.3



More information about the mesa-dev mailing list