Mesa (gallium-mesa-7.4): glsl: asst improvements, clean-ups in set_program_uniform()
Alan Hourihane
alanh at kemper.freedesktop.org
Thu Feb 19 10:49:59 UTC 2009
Module: Mesa
Branch: gallium-mesa-7.4
Commit: 04f90f83b484476709abcd44e2b47012a06487f6
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=04f90f83b484476709abcd44e2b47012a06487f6
Author: Brian Paul <brianp at vmware.com>
Date: Wed Feb 18 17:53:08 2009 -0700
glsl: asst improvements, clean-ups in set_program_uniform()
Move the is_boolean/integer_type() calls out of the loops.
Move the is_sampler_type() function near the bool/int functions.
Add a bunch of comments.
(cherry picked from master, commit c4ffbf009e76289fec53c82ce12da8de89d8b7af)
---
src/mesa/shader/shader_api.c | 63 ++++++++++++++++++++++++------------------
1 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index c64d4ba..81d31e6 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -1,8 +1,9 @@
/*
* Mesa 3-D graphics library
- * Version: 7.2
+ * Version: 7.5
*
* Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -801,6 +802,27 @@ is_integer_type(GLenum type)
}
+static GLboolean
+is_sampler_type(GLenum type)
+{
+ switch (type) {
+ case GL_SAMPLER_1D:
+ case GL_SAMPLER_2D:
+ case GL_SAMPLER_3D:
+ case GL_SAMPLER_CUBE:
+ case GL_SAMPLER_1D_SHADOW:
+ case GL_SAMPLER_2D_SHADOW:
+ case GL_SAMPLER_2D_RECT_ARB:
+ case GL_SAMPLER_2D_RECT_SHADOW_ARB:
+ case GL_SAMPLER_1D_ARRAY_EXT:
+ case GL_SAMPLER_2D_ARRAY_EXT:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
static void
_mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index,
GLsizei maxLength, GLsizei *length, GLint *size,
@@ -1487,27 +1509,6 @@ _mesa_update_shader_textures_used(struct gl_program *prog)
}
-static GLboolean
-is_sampler_type(GLenum type)
-{
- switch (type) {
- case GL_SAMPLER_1D:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_3D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_1D_SHADOW:
- case GL_SAMPLER_2D_SHADOW:
- case GL_SAMPLER_2D_RECT_ARB:
- case GL_SAMPLER_2D_RECT_SHADOW_ARB:
- case GL_SAMPLER_1D_ARRAY_EXT:
- case GL_SAMPLER_2D_ARRAY_EXT:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
/**
* Check if the type given by userType is allowed to set a uniform of the
* target type. Generally, equivalence is required, but setting Boolean
@@ -1546,10 +1547,10 @@ compatible_types(GLenum userType, GLenum targetType)
* \param program the program whose uniform to update
* \param index the index of the program parameter for the uniform
* \param offset additional parameter slot offset (for arrays)
- * \param type the datatype of the uniform
+ * \param type the incoming datatype of 'values'
* \param count the number of uniforms to set
- * \param elems number of elements per uniform
- * \param values the new values
+ * \param elems number of elements per uniform (1, 2, 3 or 4)
+ * \param values the new values, of datatype 'type'
*/
static void
set_program_uniform(GLcontext *ctx, struct gl_program *program,
@@ -1559,8 +1560,12 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
{
struct gl_program_parameter *param =
&program->Parameters->Parameters[index];
+ const GLboolean isUniformBool = is_boolean_type(param->DataType);
+ const GLboolean areIntValues = is_integer_type(type);
assert(offset >= 0);
+ assert(elems >= 1);
+ assert(elems <= 4);
if (!compatible_types(type, param->DataType)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(type mismatch)");
@@ -1628,6 +1633,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
}
}
+ /* loop over number of array elements */
for (k = 0; k < count; k++) {
GLfloat *uniformVal;
@@ -1636,8 +1642,11 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
break;
}
+ /* uniformVal (the destination) is always float[4] */
uniformVal = program->Parameters->ParameterValues[index + offset + k];
- if (is_integer_type(type)) {
+
+ if (areIntValues) {
+ /* convert user's ints to floats */
const GLint *iValues = ((const GLint *) values) + k * elems;
for (i = 0; i < elems; i++) {
uniformVal[i] = (GLfloat) iValues[i];
@@ -1651,7 +1660,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
}
/* if the uniform is bool-valued, convert to 1.0 or 0.0 */
- if (is_boolean_type(param->DataType)) {
+ if (isUniformBool) {
for (i = 0; i < elems; i++) {
uniformVal[i] = uniformVal[i] ? 1.0f : 0.0f;
}
More information about the mesa-commit
mailing list