[Mesa-dev] [PATCH 2/3] mesa/get: Add TYPE_UINT for casting through a GLuint.

Kenneth Graunke kenneth at whitecape.org
Sun Dec 18 05:02:10 UTC 2016


The "State Tables" section of the OpenGL specification lists many values
as belonging to Z+ (non-negative integers), not Z (all integers).

For ordinary glGetInteger queries, this doesn't matter.  However, when
accessing Z+ values via glGetFloat or glGetInteger64, we need to treat
the source value as an unsigned value.  Otherwise, we'll produce a
negative number when bit 31 is set.

This commit merely adds the plumbing.  It doesn't convert any values.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/main/get.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 25444e7..00d0d7f 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -95,6 +95,10 @@ enum value_type {
    TYPE_INT_3,
    TYPE_INT_4,
    TYPE_INT_N,
+   TYPE_UINT,
+   TYPE_UINT_2,
+   TYPE_UINT_3,
+   TYPE_UINT_4,
    TYPE_INT64,
    TYPE_ENUM,
    TYPE_ENUM_2,
@@ -205,6 +209,7 @@ union value {
 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
+#define CONTEXT_UINT(field) CONTEXT_FIELD(field, TYPE_UINT)
 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
@@ -1458,13 +1463,17 @@ _mesa_GetBooleanv(GLenum pname, GLboolean *params)
       break;
 
    case TYPE_INT_4:
+   case TYPE_UINT_4:
       params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
    case TYPE_INT_3:
+   case TYPE_UINT_3:
       params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
    case TYPE_INT_2:
+   case TYPE_UINT_2:
    case TYPE_ENUM_2:
       params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
    case TYPE_INT:
+   case TYPE_UINT:
    case TYPE_ENUM:
       params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
       break;
@@ -1567,6 +1576,16 @@ _mesa_GetFloatv(GLenum pname, GLfloat *params)
 	 params[i] = (GLfloat) v.value_int_n.ints[i];
       break;
 
+   case TYPE_UINT_4:
+      params[3] = (GLfloat) (((GLuint *) p)[3]);
+   case TYPE_UINT_3:
+      params[2] = (GLfloat) (((GLuint *) p)[2]);
+   case TYPE_UINT_2:
+      params[1] = (GLfloat) (((GLuint *) p)[1]);
+   case TYPE_UINT:
+      params[0] = (GLfloat) (((GLuint *) p)[0]);
+      break;
+
    case TYPE_INT64:
       params[0] = (GLfloat) (((GLint64 *) p)[0]);
       break;
@@ -1650,13 +1669,17 @@ _mesa_GetIntegerv(GLenum pname, GLint *params)
       break;
 
    case TYPE_INT_4:
+   case TYPE_UINT_4:
       params[3] = ((GLint *) p)[3];
    case TYPE_INT_3:
+   case TYPE_UINT_3:
       params[2] = ((GLint *) p)[2];
    case TYPE_INT_2:
+   case TYPE_UINT_2:
    case TYPE_ENUM_2:
       params[1] = ((GLint *) p)[1];
    case TYPE_INT:
+   case TYPE_UINT:
    case TYPE_ENUM:
       params[0] = ((GLint *) p)[0];
       break;
@@ -1765,6 +1788,16 @@ _mesa_GetInteger64v(GLenum pname, GLint64 *params)
 	 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
       break;
 
+   case TYPE_UINT_4:
+      params[3] = ((GLuint *) p)[3];
+   case TYPE_UINT_3:
+      params[2] = ((GLuint *) p)[2];
+   case TYPE_UINT_2:
+      params[1] = ((GLuint *) p)[1];
+   case TYPE_UINT:
+      params[0] = ((GLuint *) p)[0];
+      break;
+
    case TYPE_INT64:
       params[0] = ((GLint64 *) p)[0];
       break;
@@ -1858,6 +1891,16 @@ _mesa_GetDoublev(GLenum pname, GLdouble *params)
 	 params[i] = v.value_int_n.ints[i];
       break;
 
+   case TYPE_UINT_4:
+      params[3] = ((GLuint *) p)[3];
+   case TYPE_UINT_3:
+      params[2] = ((GLuint *) p)[2];
+   case TYPE_UINT_2:
+      params[1] = ((GLuint *) p)[1];
+   case TYPE_UINT:
+      params[0] = ((GLuint *) p)[0];
+      break;
+
    case TYPE_INT64:
       params[0] = (GLdouble) (((GLint64 *) p)[0]);
       break;
-- 
2.10.2



More information about the mesa-dev mailing list