state.depth.range alpha value should be 1, not 0 (bug #14733)
[mesa.git] / src / mesa / shader / shader_api.c
index 4e039cba426b9bd321c0d70d1a110a2a84296fda..e9c35fce71562ae090964aac8c83c5bfc5cb3208 100644 (file)
@@ -178,7 +178,7 @@ _mesa_reference_shader_program(GLcontext *ctx,
       deleteFlag = (old->RefCount == 0);
 
       if (deleteFlag) {
-         _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name);
+         _mesa_HashRemove(ctx->Shared->ShaderProgramObjects, old->Name);
          _mesa_free_shader_program(ctx, old);
       }
 
@@ -204,7 +204,7 @@ _mesa_lookup_shader_program(GLcontext *ctx, GLuint name)
    struct gl_shader_program *shProg;
    if (name) {
       shProg = (struct gl_shader_program *)
-         _mesa_HashLookup(ctx->Shared->ShaderObjects, name);
+         _mesa_HashLookup(ctx->Shared->ShaderProgramObjects, name);
       /* Note that both gl_shader and gl_shader_program objects are kept
        * in the same hash table.  Check the object's type to be sure it's
        * what we're expecting.
@@ -536,10 +536,10 @@ _mesa_create_program(GLcontext *ctx)
    GLuint name;
    struct gl_shader_program *shProg;
 
-   name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
+   name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderProgramObjects, 1);
    shProg = _mesa_new_shader_program(ctx, name);
 
-   _mesa_HashInsert(ctx->Shared->ShaderObjects, name, shProg);
+   _mesa_HashInsert(ctx->Shared->ShaderProgramObjects, name, shProg);
 
    assert(shProg->RefCount == 1);
 
@@ -1152,18 +1152,21 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
    if (location == -1)
       return;   /* The standard specifies this as a no-op */
 
+   /* The spec says this is GL_INVALID_OPERATION, although it seems like it
+    * ought to be GL_INVALID_VALUE
+    */
    if (location < 0 || location >= (GLint) shProg->Uniforms->NumParameters) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glUniform(location)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(location)");
       return;
    }
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
-   uType = shProg->Uniforms->Parameters[location].Type;
+   uType = shProg->Uniforms->Parameters[location].DataType;
    /*
     * If we're setting a sampler, we must use glUniformi1()!
     */
-   if (uType == PROGRAM_SAMPLER) {
+   if (shProg->Uniforms->Parameters[location].Type == PROGRAM_SAMPLER) {
       GLint unit;
       if (type != GL_INT || count != 1) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -1216,14 +1219,15 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
       case GL_BOOL_VEC2:
       case GL_BOOL_VEC3:
       case GL_BOOL_VEC4:
-         if (elems != sizeof_glsl_type(shProg->Uniforms->Parameters[location].DataType)) {
+         if (elems != sizeof_glsl_type(uType)) {
             _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(count mismatch)");
          }
          break;
       case PROGRAM_SAMPLER:
          break;
       default:
-         if (uType != type) {
+         if (shProg->Uniforms->Parameters[location].Type != PROGRAM_SAMPLER 
+             && uType != type) {
             _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(type mismatch)");
          }
          break;
@@ -1254,6 +1258,13 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
             uniformVal[i] = fValues[i];
          }
       }
+      if (uType == GL_BOOL ||
+          uType == GL_BOOL_VEC2 ||
+          uType == GL_BOOL_VEC3 ||
+          uType == GL_BOOL_VEC4) {
+          for (i = 0; i < elems; i++)
+              uniformVal[i] = uniformVal[i] ? 1.0f : 0.0f;
+      }
    }
 
    if (shProg->Uniforms->Parameters[location].Type == PROGRAM_SAMPLER) {
@@ -1274,20 +1285,30 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
                      GLenum matrixType, GLint location, GLsizei count,
                      GLboolean transpose, const GLfloat *values)
 {
+   GLsizei maxCount, i;
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
    if (!shProg || !shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
          "glUniformMatrix(program not linked)");
       return;
    }
-   if (location < 0 || location >= shProg->Uniforms->NumParameters) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glUniformMatrix(location)");
+   if (location == -1)
+      return;   /* The standard specifies this as a no-op */
+   /* The spec says this is GL_INVALID_OPERATION, although it seems like it
+    * ought to be GL_INVALID_VALUE
+    */
+   if (location < 0 || location >= (GLint) shProg->Uniforms->NumParameters) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glUniformMatrix(location)");
       return;
    }
    if (values == NULL) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glUniformMatrix");
       return;
    }
+   if (count < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glUniformMatrix(count < 0)");
+      return;
+   }
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
@@ -1296,23 +1317,30 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
     * the rows.
     */
    /* XXXX need to test 3x3 and 2x2 matrices... */
-   if (transpose) {
-      GLuint row, col;
-      for (col = 0; col < cols; col++) {
-         GLfloat *v = shProg->Uniforms->ParameterValues[location + col];
-         for (row = 0; row < rows; row++) {
-            v[row] = values[row * cols + col];
+   maxCount = shProg->Uniforms->Parameters[location].Size / (4 * cols);
+   if (count > maxCount)
+      count = maxCount;
+   for (i = 0; i < count; i++) {
+      if (transpose) {
+         GLuint row, col;
+         for (col = 0; col < cols; col++) {
+            GLfloat *v = shProg->Uniforms->ParameterValues[location + col];
+            for (row = 0; row < rows; row++) {
+               v[row] = values[row * cols + col];
+            }
          }
       }
-   }
-   else {
-      GLuint row, col;
-      for (col = 0; col < cols; col++) {
-         GLfloat *v = shProg->Uniforms->ParameterValues[location + col];
-         for (row = 0; row < rows; row++) {
-            v[row] = values[col * rows + row];
+      else {
+         GLuint row, col;
+         for (col = 0; col < cols; col++) {
+            GLfloat *v = shProg->Uniforms->ParameterValues[location + col];
+            for (row = 0; row < rows; row++) {
+               v[row] = values[col * rows + row];
+            }
          }
       }
+      location += cols;
+      values += rows * cols;
    }
 }