Add a state to for valid/invalid shaders. Added some shader debug code.

This commit is contained in:
aignacio_sf 2006-02-10 21:10:43 +00:00
parent 2da70352f4
commit b58a54df1d
3 changed files with 98 additions and 46 deletions

View File

@ -28,7 +28,7 @@
INLINE bool CLP(ShaderContext)::
valid() {
#ifdef HAVE_CGGL
if (_cg_context) return true;
if (_state && _cg_context) return true;
#endif
return false;
}

View File

@ -16,6 +16,8 @@
//
////////////////////////////////////////////////////////////////////
#define DEBUG_GL_SHADER 0
TypeHandle CLP(ShaderContext)::_type_handle;
////////////////////////////////////////////////////////////////////
@ -29,6 +31,8 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
s->parse_init();
s->parse_line(header, true, true);
_state = false;
#ifdef HAVE_CGGL
_cg_context = (CGcontext)0;
_cg_profile[SHADER_type_vert] = CG_PROFILE_UNKNOWN;
@ -176,6 +180,16 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
return false;
}
#if DEBUG_GL_SHADER
// DEBUG: output the generated program
{
const char *program;
program = cgGetProgramString (_cg_program[1], CG_COMPILED_PROGRAM);
glgsg_cat.debug ( ) << program << "\n";
}
#endif
// The following code is present to work around a bug in the Cg compiler.
// It does not generate correct code for shadow map lookups when using arbfp1.
// This is a particularly onerous limitation, given that arbfp1 is the only
@ -268,6 +282,9 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
_cg_errors = s->get_name() + ": compiled to "
+ cgGetProfileString(_cg_profile[SHADER_type_vert]) + " "
+ cgGetProfileString(_cg_profile[SHADER_type_frag]) + "\n";
_state = true;
return true;
}
#endif
@ -371,6 +388,25 @@ issue_cg_auto_bind(const ShaderAutoBind &bind, GSG *gsg)
case SIC_inv_modelproj:
case SIC_tps_modelproj:
case SIC_itp_modelproj:
/*
float data [16];
glGetFloatv (GL_MODELVIEW_MATRIX, data);
glgsg_cat.debug ( ) << "MODELVIEW MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
glGetFloatv (GL_PROJECTION_MATRIX, data);
glgsg_cat.debug ( ) << "PROJECTION MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
*/
cgGLSetStateMatrixParameter(p, (CGGLenum)((bind.value >> 2)+4), (CGGLenum)(bind.value & 3));
return;
case SIC_sys_windowsize:
@ -420,6 +456,20 @@ issue_parameters(GSG *gsg)
InternalName *id = _cg_fbind[i].name;
const ShaderInput *input = gsg->_target._shader->get_shader_input(id);
cgGLSetParameter4fv(_cg_fbind[i].parameter, input->get_vector().get_data());
#if DEBUG_GL_SHADER
// DEBUG
{
const float *data;
char string [256];
data = input->get_vector().get_data();
sprintf (string, "%f %f %f %f \n", data [0], data [1], data [2], data [3]);
glgsg_cat.debug ( ) << "SHADER: issue_parameters, _cg_fbind " << id -> get_name ( ) << "\n";
glgsg_cat.debug ( ) << string;
}
#endif
}
// Pass in k-float4x4 parameters.

View File

@ -49,6 +49,8 @@ public:
void disable_shader_texture_bindings(GSG *gsg);
void update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg);
bool _state;
private:
#ifdef HAVE_CGGL