mesa: glsl: more assignment type checking
[mesa.git] / src / mesa / shader / shader_api.c
index f390e3cef45e76b4f05796097ec48bb78f749570..5c18e55dacf9afd11edb0bcb0f73e9011d3b5453 100644 (file)
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/macros.h"
 #include "program.h"
 #include "prog_parameter.h"
 #include "prog_print.h"
@@ -262,15 +262,11 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type)
 void
 _mesa_free_shader(GLcontext *ctx, struct gl_shader *sh)
 {
-   GLuint i;
    if (sh->Source)
       _mesa_free((void *) sh->Source);
    if (sh->InfoLog)
       _mesa_free(sh->InfoLog);
-   for (i = 0; i < sh->NumPrograms; i++)
-      _mesa_reference_program(ctx, &sh->Programs[i], NULL);
-   if (sh->Programs)
-      _mesa_free(sh->Programs);
+   _mesa_reference_program(ctx, &sh->Program, NULL);
    _mesa_free(sh);
 }
 
@@ -513,7 +509,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
    struct gl_shader_program *shProg;
    const GLint size = -1; /* unknown size */
    GLint i, oldIndex;
-   GLenum datatype;
+   GLenum datatype = GL_FLOAT_VEC4;
 
    shProg = _mesa_lookup_shader_program_err(ctx, program,
                                             "glBindAttribLocation");
@@ -538,7 +534,6 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
    if (shProg->LinkStatus) {
       /* get current index/location for the attribute */
       oldIndex = _mesa_get_attrib_location(ctx, program, name);
-      assert(0);
    }
    else {
       oldIndex = -1;
@@ -548,6 +543,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
    i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index);
    if (i < 0) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
+      return;
    }
 
    if (shProg->VertexProgram && oldIndex >= 0 && oldIndex != index) {
@@ -1209,6 +1205,27 @@ update_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
@@ -1235,6 +1252,9 @@ compatible_types(GLenum userType, GLenum targetType)
                                       userType == GL_INT_VEC4))
       return GL_TRUE;
 
+   if (is_sampler_type(targetType) && userType == GL_INT)
+      return GL_TRUE;
+
    return GL_FALSE;
 }