[Mesa-dev] [PATCH 13/19] mesa: Implement glGetUnsignedByte{v|i_v}

Andres Rodriguez andresx7 at gmail.com
Fri Jun 30 23:03:06 UTC 2017


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

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
---
 src/mesa/main/get.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 177 insertions(+)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index b5c0723..9f26ad1 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1419,6 +1419,73 @@ static const int transpose[] = {
    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;
+      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)
 {
@@ -1937,7 +2004,70 @@ _mesa_GetDoublev(GLenum pname, GLdouble *params)
 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_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)",
+                  func, _mesa_enum_to_string(pname));
+   }
+
+   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 */
+   }
 }
 
 /**
@@ -2648,7 +2778,54 @@ _mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
 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_error(ctx, GL_INVALID_ENUM, "%s(target=%s)",
+                  func, _mesa_enum_to_string(target));
+   }
+
+   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
-- 
2.9.3



More information about the mesa-dev mailing list