From 96e879361d435bda0ad1a68e2ddf7c10203c2446 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 10 May 2014 16:00:18 +0200 Subject: [PATCH] Fixed a problem with the searching for embedding local and embedded shaders --- neo/idlib/Parser.cpp | 34 ++++++++++++++++--------------- neo/idlib/Parser.h | 2 +- neo/renderer/RenderLog.cpp | 2 +- neo/renderer/RenderLog.h | 2 +- neo/renderer/RenderProgs_GLSL.cpp | 33 ++++++++++++++++-------------- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/neo/idlib/Parser.cpp b/neo/idlib/Parser.cpp index 81a1fcde..749e6695 100644 --- a/neo/idlib/Parser.cpp +++ b/neo/idlib/Parser.cpp @@ -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" ) diff --git a/neo/idlib/Parser.h b/neo/idlib/Parser.h index f3d7df1a..b5ff5990 100644 --- a/neo/idlib/Parser.h +++ b/neo/idlib/Parser.h @@ -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 ); diff --git a/neo/renderer/RenderLog.cpp b/neo/renderer/RenderLog.cpp index 9446822e..70d60b18 100644 --- a/neo/renderer/RenderLog.cpp +++ b/neo/renderer/RenderLog.cpp @@ -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 ); } } diff --git a/neo/renderer/RenderLog.h b/neo/renderer/RenderLog.h index d17edeb3..e57b2ffa 100644 --- a/neo/renderer/RenderLog.h +++ b/neo/renderer/RenderLog.h @@ -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 ); }; diff --git a/neo/renderer/RenderProgs_GLSL.cpp b/neo/renderer/RenderProgs_GLSL.cpp index 1f95ca2e..fd9bde9d 100644 --- a/neo/renderer/RenderProgs_GLSL.cpp +++ b/neo/renderer/RenderProgs_GLSL.cpp @@ -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 >" ); }