summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/shader_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader/shader_api.c')
-rw-r--r--src/mesa/shader/shader_api.c81
1 files changed, 50 insertions, 31 deletions
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index d8b210be539..854f8bfdaa6 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 7.1
+ * Version: 7.2
*
* Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
*
@@ -39,11 +39,11 @@
#include "main/context.h"
#include "main/hash.h"
#include "main/macros.h"
-#include "program.h"
-#include "prog_parameter.h"
-#include "prog_print.h"
-#include "prog_statevars.h"
-#include "prog_uniform.h"
+#include "shader/program.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_print.h"
+#include "shader/prog_statevars.h"
+#include "shader/prog_uniform.h"
#include "shader/shader_api.h"
#include "shader/slang/slang_compile.h"
#include "shader/slang/slang_link.h"
@@ -497,10 +497,14 @@ _mesa_get_attrib_location(GLcontext *ctx, GLuint program,
if (!name)
return -1;
- if (shProg->Attributes) {
- GLint i = _mesa_lookup_parameter_index(shProg->Attributes, -1, name);
- if (i >= 0) {
- return shProg->Attributes->Parameters[i].StateIndexes[0];
+ if (shProg->VertexProgram) {
+ const struct gl_program_parameter_list *attribs =
+ shProg->VertexProgram->Base.Attributes;
+ if (attribs) {
+ GLint i = _mesa_lookup_parameter_index(attribs, -1, name);
+ if (i >= 0) {
+ return attribs->Parameters[i].StateIndexes[0];
+ }
}
}
return -1;
@@ -551,12 +555,10 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
return;
}
- if (shProg->VertexProgram && oldIndex >= 0 && oldIndex != index) {
- /* If the index changed, need to search/replace references to that attribute
- * in the vertex program.
- */
- _slang_remap_attribute(&shProg->VertexProgram->Base, oldIndex, index);
- }
+ /*
+ * Note that this attribute binding won't go into effect until
+ * glLinkProgram is called again.
+ */
}
@@ -798,24 +800,29 @@ _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index,
GLsizei maxLength, GLsizei *length, GLint *size,
GLenum *type, GLchar *nameOut)
{
+ const struct gl_program_parameter_list *attribs = NULL;
struct gl_shader_program *shProg;
shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveAttrib");
if (!shProg)
return;
- if (!shProg->Attributes || index >= shProg->Attributes->NumParameters) {
+ if (shProg->VertexProgram)
+ attribs = shProg->VertexProgram->Base.Attributes;
+
+ if (!attribs || index >= attribs->NumParameters) {
_mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
return;
}
- copy_string(nameOut, maxLength, length,
- shProg->Attributes->Parameters[index].Name);
+ copy_string(nameOut, maxLength, length, attribs->Parameters[index].Name);
+
if (size)
- *size = shProg->Attributes->Parameters[index].Size
- / sizeof_glsl_type(shProg->Attributes->Parameters[index].DataType);
+ *size = attribs->Parameters[index].Size
+ / sizeof_glsl_type(attribs->Parameters[index].DataType);
+
if (type)
- *type = shProg->Attributes->Parameters[index].DataType;
+ *type = attribs->Parameters[index].DataType;
}
@@ -937,6 +944,7 @@ static void
_mesa_get_programiv(GLcontext *ctx, GLuint program,
GLenum pname, GLint *params)
{
+ const struct gl_program_parameter_list *attribs;
struct gl_shader_program *shProg
= _mesa_lookup_shader_program(ctx, program);
@@ -945,6 +953,11 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program,
return;
}
+ if (shProg->VertexProgram)
+ attribs = shProg->VertexProgram->Base.Attributes;
+ else
+ attribs = NULL;
+
switch (pname) {
case GL_DELETE_STATUS:
*params = shProg->DeletePending;
@@ -962,11 +975,10 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program,
*params = shProg->NumShaders;
break;
case GL_ACTIVE_ATTRIBUTES:
- *params = shProg->Attributes ? shProg->Attributes->NumParameters : 0;
+ *params = attribs ? attribs->NumParameters : 0;
break;
case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
- *params = _mesa_longest_parameter_name(shProg->Attributes,
- PROGRAM_INPUT) + 1;
+ *params = _mesa_longest_parameter_name(attribs, PROGRAM_INPUT) + 1;
break;
case GL_ACTIVE_UNIFORMS:
*params = shProg->Uniforms ? shProg->Uniforms->NumUniforms : 0;
@@ -1108,7 +1120,8 @@ get_matrix_dims(GLenum type, GLint *rows, GLint *cols)
/**
* Determine the number of rows and columns occupied by a uniform
- * according to its datatype.
+ * according to its datatype. For non-matrix types (such as GL_FLOAT_VEC4),
+ * the number of rows = 1 and cols = number of elements in the vector.
*/
static void
get_uniform_rows_cols(const struct gl_program_parameter *p,
@@ -1117,11 +1130,17 @@ get_uniform_rows_cols(const struct gl_program_parameter *p,
get_matrix_dims(p->DataType, rows, cols);
if (*rows == 0 && *cols == 0) {
/* not a matrix type, probably a float or vector */
- *rows = p->Size / 4 + 1;
- if (p->Size % 4 == 0)
- *cols = 4;
- else
- *cols = p->Size % 4;
+ if (p->Size <= 4) {
+ *rows = 1;
+ *cols = p->Size;
+ }
+ else {
+ *rows = p->Size / 4 + 1;
+ if (p->Size % 4 == 0)
+ *cols = 4;
+ else
+ *cols = p->Size % 4;
+ }
}
}