Fixed a problem with the searching for embedding local and embedded shaders

This commit is contained in:
Robert Beckebans 2014-05-10 16:00:18 +02:00
parent 12fd563fce
commit 96e879361d
5 changed files with 39 additions and 34 deletions

View file

@ -1092,38 +1092,38 @@ int idParser::ReadLine( idToken* token )
idParser::Directive_include
================
*/
int idParser::Directive_include()
// RB: added token as parameter
int idParser::Directive_include( idToken* token )
{
idLexer* script;
idToken token;
idStr path;
if( !idParser::ReadSourceToken( &token ) )
if( !idParser::ReadSourceToken( token ) )
{
idParser::Error( "#include without file name" );
return false;
}
if( token.linesCrossed > 0 )
if( token->linesCrossed > 0 )
{
idParser::Error( "#include without file name" );
return false;
}
if( token.type == TT_STRING )
if( token->type == TT_STRING )
{
script = new( TAG_IDLIB_PARSER ) idLexer;
// try relative to the current file
path = scriptstack->GetFileName();
path.StripFilename();
path += "/";
path += token;
path += *token;
if( !script->LoadFile( path, OSPath ) )
{
// try absolute path
path = token;
path = *token;
if( !script->LoadFile( path, OSPath ) )
{
// try from the include path
path = includepath + token;
path = includepath + *token;
if( !script->LoadFile( path, OSPath ) )
{
delete script;
@ -1132,23 +1132,23 @@ int idParser::Directive_include()
}
}
}
else if( token.type == TT_PUNCTUATION && token == "<" )
else if( token->type == TT_PUNCTUATION && *token == "<" )
{
path = idParser::includepath;
while( idParser::ReadSourceToken( &token ) )
while( idParser::ReadSourceToken( token ) )
{
if( token.linesCrossed > 0 )
if( token->linesCrossed > 0 )
{
idParser::UnreadSourceToken( &token );
idParser::UnreadSourceToken( token );
break;
}
if( token.type == TT_PUNCTUATION && token == ">" )
if( token->type == TT_PUNCTUATION && *token == ">" )
{
break;
}
path += token;
path += *token;
}
if( token != ">" )
if( *token != ">" )
{
idParser::Warning( "#include missing trailing >" );
}
@ -1183,6 +1183,7 @@ int idParser::Directive_include()
idParser::PushScript( script );
return true;
}
// RB end
/*
================
@ -2599,7 +2600,8 @@ int idParser::ReadDirective()
if( token == "include" )
{
// RB lets override for embedded shaders
return Directive_include();
idToken filename;
return Directive_include( &filename );
// RB end
}
else if( token == "define" )

View file

@ -228,7 +228,7 @@ protected:
static define_t* DefineFromString( const char* string );
define_t* CopyFirstDefine();
// RB: allow override
virtual int Directive_include();
virtual int Directive_include( idToken* token );
// RB end
int Directive_undef();
int Directive_if_def( int type );

View file

@ -382,7 +382,7 @@ void idRenderLog::OpenBlock( const char* label )
//if( logFile != NULL )
if( r_logFile.GetInteger() != 0 )
{
LogOpenBlock( RENDER_LOG_INDENT_MAIN_BLOCK, "%s", label );
LogOpenBlock( RENDER_LOG_INDENT_MAIN_BLOCK, "%s", label );
}
}

View file

@ -125,7 +125,7 @@ public:
logStats_t logStats[MAX_LOG_LEVELS];
int logLevel;
void LogOpenBlock( renderLogIndentLabel_t label, const char* fmt, ... );
void LogOpenBlock( renderLogIndentLabel_t label, const char* fmt, ... );
void LogCloseBlock( renderLogIndentLabel_t label );
};

View file

@ -392,31 +392,34 @@ public:
}
private:
int Directive_include()
int Directive_include( idToken* token )
{
if( idParser::Directive_include() )
if( idParser::Directive_include( token ) )
{
// RB: try local shaders in base/renderprogs/ first
return true;
}
idLexer* script;
idToken token;
idStr path;
/*
token was already parsed
if( !idParser::ReadSourceToken( &token ) )
{
idParser::Error( "#include without file name" );
return false;
}
*/
if( token.linesCrossed > 0 )
if( token->linesCrossed > 0 )
{
idParser::Error( "#include without file name" );
return false;
}
if( token.type == TT_STRING )
if( token->type == TT_STRING )
{
script = new idLexer;
@ -424,19 +427,19 @@ private:
path = scriptstack->GetFileName();
path.StripFilename();
path += "/";
path += token;
path += *token;
//if( !script->LoadFile( path, OSPath ) )
const char* embeddedSource = FindEmbeddedSourceShader( path );
if( embeddedSource == NULL )
{
// try absolute path
path = token;
path = *token;
embeddedSource = FindEmbeddedSourceShader( path );
if( embeddedSource == NULL )
{
// try from the include path
path = includepath + token;
path = includepath + *token;
embeddedSource = FindEmbeddedSourceShader( path );
}
}
@ -447,23 +450,23 @@ private:
script = NULL;
}
}
else if( token.type == TT_PUNCTUATION && token == "<" )
else if( token->type == TT_PUNCTUATION && *token == "<" )
{
path = idParser::includepath;
while( idParser::ReadSourceToken( &token ) )
while( idParser::ReadSourceToken( token ) )
{
if( token.linesCrossed > 0 )
if( token->linesCrossed > 0 )
{
idParser::UnreadSourceToken( &token );
idParser::UnreadSourceToken( token );
break;
}
if( token.type == TT_PUNCTUATION && token == ">" )
if( token->type == TT_PUNCTUATION && *token == ">" )
{
break;
}
path += token;
path += *token;
}
if( token != ">" )
if( *token != ">" )
{
idParser::Warning( "#include missing trailing >" );
}