mesa: Refactor per-stage link check to its own function

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
Ian Romanick 2014-02-07 21:13:02 -08:00
parent 68bc1e2025
commit 79146065f9
1 changed files with 34 additions and 68 deletions

View File

@ -1766,6 +1766,32 @@ _mesa_check_blend_func_error(struct gl_context *ctx)
return GL_TRUE;
}
static bool
shader_linked_or_absent(struct gl_context *ctx,
const struct gl_shader_program *shProg,
bool *shader_present, const char *where)
{
if (shProg) {
*shader_present = true;
if (!shProg->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(shader not linked)", where);
return false;
}
#if 0 /* not normally enabled */
{
char errMsg[100];
if (!_mesa_validate_shader_program(ctx, shProg, errMsg)) {
_mesa_warning(ctx, "Shader program %u is invalid: %s",
shProg->Name, errMsg);
}
}
#endif
}
return true;
}
/**
* Prior to drawing anything with glBegin, glDrawArrays, etc. this function
* is called to see if it's valid to render. This involves checking that
@ -1776,83 +1802,23 @@ _mesa_check_blend_func_error(struct gl_context *ctx)
GLboolean
_mesa_valid_to_render(struct gl_context *ctx, const char *where)
{
bool vert_from_glsl_shader = false;
bool geom_from_glsl_shader = false;
bool frag_from_glsl_shader = false;
bool from_glsl_shader[MESA_SHADER_COMPUTE] = { false };
unsigned i;
/* This depends on having up to date derived state (shaders) */
if (ctx->NewState)
_mesa_update_state(ctx);
if (ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]) {
vert_from_glsl_shader = true;
if (!ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(shader not linked)", where);
for (i = 0; i < MESA_SHADER_COMPUTE; i++) {
if (!shader_linked_or_absent(ctx, ctx->Shader.CurrentProgram[i],
&from_glsl_shader[i], where))
return GL_FALSE;
}
#if 0 /* not normally enabled */
{
char errMsg[100];
if (!_mesa_validate_shader_program(ctx,
ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX],
errMsg)) {
_mesa_warning(ctx, "Shader program %u is invalid: %s",
ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]->Name, errMsg);
}
}
#endif
}
if (ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]) {
geom_from_glsl_shader = true;
if (!ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(shader not linked)", where);
return GL_FALSE;
}
#if 0 /* not normally enabled */
{
char errMsg[100];
if (!_mesa_validate_shader_program(ctx,
ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY],
errMsg)) {
_mesa_warning(ctx, "Shader program %u is invalid: %s",
ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]->Name,
errMsg);
}
}
#endif
}
if (ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]) {
frag_from_glsl_shader = true;
if (!ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(shader not linked)", where);
return GL_FALSE;
}
#if 0 /* not normally enabled */
{
char errMsg[100];
if (!_mesa_validate_shader_program(ctx,
ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT],
errMsg)) {
_mesa_warning(ctx, "Shader program %u is invalid: %s",
ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]->Name,
errMsg);
}
}
#endif
}
/* Any shader stages that are not supplied by the GLSL shader and have
* assembly shaders enabled must now be validated.
*/
if (!vert_from_glsl_shader
if (!from_glsl_shader[MESA_SHADER_VERTEX]
&& ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(vertex program not valid)", where);
@ -1862,9 +1828,9 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
/* FINISHME: If GL_NV_geometry_program4 is ever supported, the current
* FINISHME: geometry program should validated here.
*/
(void) geom_from_glsl_shader;
(void) from_glsl_shader[MESA_SHADER_GEOMETRY];
if (!frag_from_glsl_shader) {
if (!from_glsl_shader[MESA_SHADER_FRAGMENT]) {
if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(fragment program not valid)", where);