From d6d3999ccb2cb72d55820770260172eccbbb68d7 Mon Sep 17 00:00:00 2001 From: marha Date: Mon, 16 Apr 2012 09:17:34 +0200 Subject: libX11 xserver pixman mesa git update 16 Apr 2012 --- mesalib/src/mesa/main/shader_query.cpp | 85 +++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-) (limited to 'mesalib/src/mesa/main/shader_query.cpp') diff --git a/mesalib/src/mesa/main/shader_query.cpp b/mesalib/src/mesa/main/shader_query.cpp index 8ab18126c..02a48ba60 100644 --- a/mesalib/src/mesa/main/shader_query.cpp +++ b/mesalib/src/mesa/main/shader_query.cpp @@ -238,11 +238,18 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg) void GLAPIENTRY _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber, const GLchar *name) +{ + _mesa_BindFragDataLocationIndexed(program, colorNumber, 0, name); +} + +void GLAPIENTRY +_mesa_BindFragDataLocationIndexed(GLuint program, GLuint colorNumber, + GLuint index, const GLchar *name) { GET_CURRENT_CONTEXT(ctx); struct gl_shader_program *const shProg = - _mesa_lookup_shader_program_err(ctx, program, "glBindFragDataLocation"); + _mesa_lookup_shader_program_err(ctx, program, "glBindFragDataLocationIndexed"); if (!shProg) return; @@ -250,13 +257,22 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber, return; if (strncmp(name, "gl_", 3) == 0) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glBindFragDataLocation(illegal name)"); + _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFragDataLocationIndexed(illegal name)"); + return; + } + + if (index > 1) { + _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(index)"); return; } - if (colorNumber >= ctx->Const.MaxDrawBuffers) { - _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocation(index)"); + if (index == 0 && colorNumber >= ctx->Const.MaxDrawBuffers) { + _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)"); + return; + } + + if (index == 1 && colorNumber >= ctx->Const.MaxDualSourceDrawBuffers) { + _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)"); return; } @@ -265,11 +281,68 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber, * between built-in attributes and user-defined attributes. */ shProg->FragDataBindings->put(colorNumber + FRAG_RESULT_DATA0, name); - + shProg->FragDataIndexBindings->put(index, name); /* * Note that this binding won't go into effect until * glLinkProgram is called again. */ + +} + +GLint GLAPIENTRY +_mesa_GetFragDataIndex(GLuint program, const GLchar *name) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_shader_program *const shProg = + _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataIndex"); + + if (!shProg) { + return -1; + } + + if (!shProg->LinkStatus) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetFragDataIndex(program not linked)"); + return -1; + } + + if (!name) + return -1; + + if (strncmp(name, "gl_", 3) == 0) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetFragDataIndex(illegal name)"); + return -1; + } + + /* Not having a fragment shader is not an error. + */ + if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) + return -1; + + exec_list *ir = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir; + foreach_list(node, ir) { + const ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + /* The extra check against FRAG_RESULT_DATA0 is because + * glGetFragDataLocation cannot be used on "conventional" attributes. + * + * From page 95 of the OpenGL 3.0 spec: + * + * "If name is not an active attribute, if name is a conventional + * attribute, or if an error occurs, -1 will be returned." + */ + if (var == NULL + || var->mode != ir_var_out + || var->location == -1 + || var->location < FRAG_RESULT_DATA0) + continue; + + if (strcmp(var->name, name) == 0) + return var->index; + } + + return -1; } GLint GLAPIENTRY -- cgit v1.2.3