mesa/main: Add conversion from double to uint64/int64 in GetUniform*i64v()
authorIago Toral Quiroga <itoral@igalia.com>
Thu, 18 May 2017 09:43:55 +0000 (11:43 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Thu, 1 Jun 2017 06:44:34 +0000 (08:44 +0200)
v2:
  - need unsigned rounding for double->uint64 conversion (Nicolai)
  - use round() instead of IROUND() macros (Iago)

Reviewed-by: Matt Turner <mattst88@gmail.com>
src/mesa/main/uniform_query.cpp

index aca54163bff643582a1ead743d6b8d5cc560c181..b53f60bc4567e002c325f499764b842c2cc4c877 100644 (file)
@@ -580,6 +580,13 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                   memcpy(&dst[didx].u, &tmp, sizeof(tmp));
                   break;
                }
+               case GLSL_TYPE_DOUBLE: {
+                  double d;
+                  memcpy(&d, &src[sidx].f, sizeof(d));
+                  int64_t tmp = (int64_t) round(d);
+                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
+                  break;
+               }
                default:
                   assert(!"Should not get here.");
                   break;
@@ -618,6 +625,13 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                   memcpy(&dst[didx].u, &tmp, sizeof(tmp));
                   break;
                }
+               case GLSL_TYPE_DOUBLE: {
+                  double d;
+                  memcpy(&d, &src[sidx].f, sizeof(d));
+                  uint64_t tmp = (d < 0.0) ? 0ull : (uint64_t) round(d);
+                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
+                  break;
+               }
                default:
                   assert(!"Should not get here.");
                   break;