[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can link your program with `lib3delight' (see section 8.1 Linking with 3Delight to query informations about shaders. Include the file `slo.h' to get the prototypes of the following functions and the type definitions they use.
Slo_SetShader
.
SLO_TYPE
.
SLO_VISSYMDEF
.
SLO_VISSYMDEF
.
Slo_GetArgById()
or Slo_GetArgByName
), each of its element should be accessed using this function.
Next is the complete source code of the shaderinfo
utility, it is compilable on all supported platforms, see section 8.1 Linking with 3Delight. Note that string parameters are represented using a const char * const *
and not a const char *
like in some implementations.
/******************************************************************************/ /* */ /* Copyright (c)The 3Delight Team. */ /* All Rights Reserved. */ /* */ /******************************************************************************/ // =========================================================================== // = VERSION // $Revision: 1.49 $ // = AUTHOR // Aghiles Kheffache // = DATE RELEASED // $Date: 2003/07/30 20:21:54 $ // = RCSID // $Id: 3delight.texinfo,v 1.49 2003/07/30 20:21:54 olivier Exp $ // =========================================================================== #include "slo.h" #include <string.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> int main( int argc, char ** argv ) { unsigned i, j, k, kk; int exitCode = 0; bool RIBDeclare = false; int start = 1; /* DlDebug::InitErrorSignalsHandling(); */ if( argc<=1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ) { printf( "Usage: shaderinfo file1 [file2 ... fileN]\n" ); printf( " -d : output declarations in RIB format\n" ); printf( " -v : show version to console\n" ); printf( " -h : show this help\n\n" ); return 0; } if( argc==2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) ) { printf( "shaderinfo version 2.0.\n" ); printf( "Copyright (c) 1999-2003 The 3Delight Team.\n" ); return 0; } if( (argc == 1) || !strcmp(argv[1], "-d") ) { RIBDeclare = true; start++; } const char* path = getenv( "DL_SHADERS_PATH" ); Slo_SetPath( path ? path : "." ); for( i = start; i < argc; i++ ) { int err = Slo_SetShader( argv[i] ); if( err != 0 ) { fprintf( stderr, "shaderinfo: unable to open shader \"%s\" (error %d).\n", argv[i], err ); exitCode = 1; continue; } printf( "\n%s \"%s\"\n", Slo_TypetoStr(Slo_GetType()), Slo_GetName() ); for( j = 0; j < Slo_GetNArgs(); j++ ) { SLO_VISSYMDEF *parameter = Slo_GetArgById( j+1 ); if( !parameter || !parameter->svd_valisvalid ) { fprintf( stderr, "shaderinfor: parameter %d is invalid\n", j ); continue; } const char *name = parameter->svd_name; const char *detail = Slo_DetailtoStr( parameter->svd_detail ); const char *type = Slo_TypetoStr( parameter->svd_type ); unsigned arraylen = parameter->svd_arraylen; if( RIBDeclare ) { /* Output a string suitable for RIB syntax */ if( arraylen == 1 ) printf( "Declare \"%s\" \"%s %s\"\n", name, detail, type ); else printf( "Declare \"%s\" \"%s %s[%d]\"\n", name, detail, type, arraylen ); continue; } if( parameter->svd_storage == SLO_STOR_OUTPUTPARAMETER ) printf( " \"%s\" \"output %s %s", name, detail, type ); else printf( " \"%s\" \"%s %s", name, detail, type ); if( arraylen > 1 ) printf( "[%d]", arraylen ); printf( "\"\n" ); printf( "\t\tDefault value: " ); switch( parameter->svd_type ) { case SLO_TYPE_COLOR: case SLO_TYPE_POINT: case SLO_TYPE_VECTOR: case SLO_TYPE_NORMAL: case SLO_TYPE_MATRIX: if( parameter->svd_spacename[0] != (char)0 ) printf( "\"%s\" ", parameter->svd_spacename ); break; default: break; } if( arraylen > 1 ) printf( "{" ); for( k=0; k<arraylen; k++ ) { SLO_VISSYMDEF *elem = Slo_GetArrayArgElement( parameter, k+1 ); if( !elem ) { printf( "<error>" ); continue; } switch( parameter->svd_type ) { case SLO_TYPE_SCALAR: printf( "%g", *elem->svd_default.scalarval ); break; case SLO_TYPE_POINT: case SLO_TYPE_VECTOR: case SLO_TYPE_NORMAL: case SLO_TYPE_COLOR: printf( "[%g %g %g]", elem->svd_default.pointval->xval, elem->svd_default.pointval->yval, elem->svd_default.pointval->zval ); break; case SLO_TYPE_MATRIX: printf( "[%g ", elem->svd_default.matrixval[0] ); for( kk = 1; kk < 15; kk++ ) printf( "%g ", elem->svd_default.matrixval[kk] ); printf( "%g]", elem->svd_default.matrixval[15] ); break; case SLO_TYPE_STRING: printf( "\"%s\"", *elem->svd_default.stringval ); break; default: break; } if( k != (arraylen-1) ) { printf( ", " ); } } if( arraylen > 1 ) printf( "}" ); printf( "\n" ); } Slo_EndShader(); printf( "\n" ); } return exitCode; } |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |