From 56c4226fcc54158eb7fe54eeb13539a979ec155c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 14 Aug 2009 10:45:17 -0600 Subject: mesa: new _mesa_valid_to_render() function Tests if the current shader/program is valid and that the framebuffer is complete. To be called by glBegin, glDrawArrays, etc. --- src/mesa/main/context.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 415e339cb8..3547d0a220 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1576,4 +1576,46 @@ _mesa_set_mvp_with_dp4( GLcontext *ctx, } + +/** + * Prior to drawing anything with glBegin, glDrawArrays, etc. this function + * is called to see if it's valid to render. This involves checking that + * the current shader is valid and the framebuffer is complete. + * If an error is detected it'll be recorded here. + * \return GL_TRUE if OK to render, GL_FALSE if not + */ +GLboolean +_mesa_valid_to_render(GLcontext *ctx, const char *where) +{ + if (ctx->Shader.CurrentProgram) { + /* using shaders */ + if (!ctx->Shader.CurrentProgram->LinkStatus) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(shader not linked), where"); + return GL_FALSE; + } + } + else { + if (ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(vertex program not valid)", where); + return GL_FALSE; + } + if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(fragment program not valid)", where); + return GL_FALSE; + } + } + + if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { + _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, + "%s(incomplete framebuffer)", where); + return GL_FALSE; + } + + return GL_TRUE; +} + + /*@}*/ -- cgit v1.2.3 From 71b1610941f9bfefa01d827fd19cc2368e6cdae3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 14 Aug 2009 12:58:21 -0600 Subject: mesa: append uniform values to the log file the first time we use a shader This info is essential to using/debugging a shader outside of its normal application. --- src/mesa/main/context.c | 27 +++++++++++++++++++++++++++ src/mesa/main/mtypes.h | 1 + 2 files changed, 28 insertions(+) (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 3547d0a220..38ec418809 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -150,6 +150,7 @@ #include "glapi/glapioffsets.h" #include "glapi/glapitable.h" #include "shader/program.h" +#include "shader/prog_print.h" #include "shader/shader_api.h" #if FEATURE_ATI_fragment_shader #include "shader/atifragshader.h" @@ -1614,6 +1615,32 @@ _mesa_valid_to_render(GLcontext *ctx, const char *where) return GL_FALSE; } +#ifdef DEBUG + if (ctx->Shader.Flags & GLSL_LOG) { + struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; + if (shProg) { + if (!shProg->_Used) { + /* This is the first time this shader is being used. + * Append shader's constants/uniforms to log file. + */ + GLuint i; + for (i = 0; i < shProg->NumShaders; i++) { + struct gl_shader *sh = shProg->Shaders[i]; + if (sh->Type == GL_VERTEX_SHADER) { + _mesa_append_uniforms_to_file(sh, + &shProg->VertexProgram->Base); + } + else if (sh->Type == GL_FRAGMENT_SHADER) { + _mesa_append_uniforms_to_file(sh, + &shProg->FragmentProgram->Base); + } + } + shProg->_Used = GL_TRUE; + } + } + } +#endif + return GL_TRUE; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 6a60ad1cee..41172788ef 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2037,6 +2037,7 @@ struct gl_shader_program struct gl_program_parameter_list *Varying; GLboolean LinkStatus; /**< GL_LINK_STATUS */ GLboolean Validated; + GLboolean _Used; /**< Ever used for drawing? */ GLchar *InfoLog; }; -- cgit v1.2.3