Exemple #1
0
	OGL4ShaderPtr OGL4ShaderCompiler::CreateShaderFromFile(SHADER_TYPE type, const boost::filesystem::path& path, const std::string& entry)
	{
	
		std::string source = LoadShaderSource(path.string());
		
		
		if(source == "")
		{
			return OGL4ShaderPtr();
		}
		


		std::vector<IncludeInfo> inc_list;
		IncludeInfo inc;
		inc.file = path;
		inc.lines = GetSourceLines(source);

		inc_list.push_back(inc);
		source = ProcessInclude(path.parent_path(), source, inc_list);
		
		inc_list.push_back(inc);
		inc_list.erase(inc_list.begin());


		source = ClearVersionComment(source);

		return CreateShaderFromSource(type, source, inc_list, entry);


	}
Exemple #2
0
        void ProcessLine(QString line, int level, const Location &location, bool &inComment)
        {
            if (m_debug) Out(QString("Line (level %1): %2").arg(level).arg(line));

            // remove comments, etc.
            line = SimplifyLine(line, inComment); 
            if (line.isEmpty()) return;

            // process includes
            if (line.startsWith(CInclude)) 
            {
                ProcessInclude(line, level + 1, location);
                return;
            }

            // process defines
            line = m_defs.ProcessLine(line);
            
            if (line.isEmpty()) return;

            // save
            int cmdNum = m_result.size() + 1;
            m_result.push_back(DRIFileLoad::RawCommand(line, cmdNum, 
                                                       location.File, location.Line));
        }
Exemple #3
0
void ModelManager :: AddModelFromFile( const string & fname, ModelMode mm ) {
	ALib::XMLTreeParser parser;
	std::auto_ptr <ALib::XMLElement> e ( parser.ParseFile( fname ) );
	if ( e.get() == 0 ) {
		throw Exception( "XML parser error: " + parser.ErrorMsg()
							+ " at line " + ALib::Str( parser.ErrorLine()) );
	}

	if ( e.get()->Name() != DMKROOT_TAG ) {
		throw Exception( "Expected tag " + ALib::SQuote( DMKROOT_TAG )
							+ " but found "
							+ ALib::SQuote( e.get()->Name()));
	}

	int incs = 0;
	while( ProcessInclude( e.get() ) ) {
		if ( ++incs > MAX_INC ) {
			throw Exception( "Too many includes" );
		}
	}

	ModelBuilder builder;
	std::auto_ptr <Model> m( builder.Build( e.get() ) );

	AddModel( m.get(), mm );
	m.release();
}
Exemple #4
0
bool ModelManager :: ProcessInclude( ALib::XMLElement * e ) {
	if ( e->Name() == INCLUDE_TAG ) {
		if ( e->ChildCount() != 0 ) {
			XMLERR( e, "include cannot have content" );
		}
		string incfile = e->AttrValue( FILE_ATTR, "" );
		if ( incfile == ""  ) {
			XMLERR( e, "No include file specified" );
		}
		ReplaceFromFile( e, incfile );
		return true;
	}
	for ( unsigned int i = 0; i < e->ChildCount(); i++ ) {
		ALib::XMLElement * ce = const_cast <ALib::XMLElement *>(e->ChildElement(i) );
		if ( ce  && ProcessInclude( ce ) ) {
			return true;
		}
	}
	return false;
}
Exemple #5
0
	std::string OGL4ShaderCompiler::ProcessInclude(const boost::filesystem::path& basePath, const std::string& source, std::vector<IncludeInfo>& inc_list)
	{
		std::vector<IncludeInfo> include_list = ExtractIncludeList(source);

		if(include_list.size() == 0)
		{
			return source;
		}

		std::string ret = "";
		for(size_t i = 0; i < include_list.size(); ++i)
		{
			bool included = false;
			for(auto v : inc_list)
			{
				if((basePath / v.file) == (basePath / include_list[i].file))
				{
					included = true;
					break;
				}
			}

			if(included)
			{
				continue;
			}
			
			std::string inc_source = LoadShaderSource(basePath / include_list[i].file);
			
			include_list[i].lines = GetSourceLines(inc_source);
			
			ret += ProcessInclude(basePath, inc_source, inc_list) + "\n";
			
			inc_list.push_back(include_list[i]);
		}

		ret += source;

		return ret;
	}
Exemple #6
0
void csWrappedDocumentNode::ProcessSingleWrappedNode (
  NodeProcessingState* state, iDocumentNode* node)
{
  CS_ASSERT(globalState);

  if (ProcessTemplate (node, state)) return;
  if (ProcessStaticIf (state, node))
  {
    // Template invokation has precedence over dropping nodes...
    TempString<> tokenStr, args; 
    if (SplitNodeValue (node->GetValue(), tokenStr, args))
    {
      Template::Params params;
      if (!args.IsEmpty())
      {
        ParseTemplateArguments (args, params, false);
      }
      InvokeTemplate (tokenStr, node, state, params);
    }
    return;
  }

  csRefArray<iDocumentNode>& currentWrapper = state->currentWrapper;
  bool handled = false;
  if (node->GetType() == CS_NODE_UNKNOWN)
  {
    TempString<> replaceScratch;
    const char* nodeValue = ReplaceEntities (node->GetValue(),
      replaceScratch);
    if ((nodeValue != 0) && (*nodeValue == '?') && 
      (*(nodeValue + strlen (nodeValue) - 1) == '?'))
    {
      const char* valStart = nodeValue + 1;
      if ((*valStart == '!') || (*valStart == '#'))
      {
	/* Discard PIs beginning with ! and #. This allows comments, e.g.
	 * <?! some comment ?>
	 * The difference to XML comments is that the PI comments do not
	 * appear in the final document after processing, hence are useful
	 * if some PIs themselves are to be commented, but it is undesireable
	 * to have an XML comment in the result. */
	return;
      }

      while (*valStart == ' ') valStart++;
      CS_ASSERT (*valStart != 0);
      size_t valLen = strlen (valStart) - 1;
      if (valLen == 0)
      {
	Report (syntaxErrorSeverity, node,
	  "Empty processing instruction");
      }
      else
      {
	while (*(valStart + valLen - 1) == ' ') valLen--;
	const char* space = strchr (valStart, ' ');
	/* The rightmost spaces were skipped and don't interest us
	    any more. */
	if (space >= valStart + valLen) space = 0;
	size_t cmdLen;
	if (space != 0)
	{
	  cmdLen = space - valStart;
	}
	else
	{
	  cmdLen = valLen;
	}

	TempString<> tokenStr; tokenStr.Replace (valStart, cmdLen);
	csStringID tokenID = shared->pitokens.Request (tokenStr);
	switch (tokenID)
	{
	  case csWrappedDocumentNodeFactory::PITOKEN_INCLUDE:
            if (shared->plugin->do_verbose)
            {
              Report (CS_REPORTER_SEVERITY_WARNING, node,
                "Deprecated syntax, please use %s",
		CS::Quote::Single ("Include"));
            }
            // Fall through
	  case csWrappedDocumentNodeFactory::PITOKEN_INCLUDE_NEW:
	    {
	      bool okay = true;
	      TempString<> filename;
	      const char* space = strchr (valStart, ' ');
	      /* The rightmost spaces were skipped and don't interest us
	       * any more. */
	      if (space != 0)
	      {
		filename.Replace (space + 1, valLen - cmdLen - 1);
		filename.Trim ();
	      }
	      if ((space == 0) || (filename.IsEmpty ()))
	      {
		Report (syntaxErrorSeverity, node,
		  "%s without filename", CS::Quote::Single ("Include"));
		okay = false;
	      }
	      if (okay)
	      {
		ProcessInclude (filename, state, node);
	      }
	      handled = true;
	    }
	    break;
	  case csWrappedDocumentNodeFactory::PITOKEN_TEMPLATE:
            if (shared->plugin->do_verbose)
            {
              Report (CS_REPORTER_SEVERITY_WARNING, node,
                "Deprecated syntax, please use %s",
		CS::Quote::Single ("Template"));
            }
            // Fall through
          case csWrappedDocumentNodeFactory::PITOKEN_TEMPLATE_NEW:
	  case csWrappedDocumentNodeFactory::PITOKEN_TEMPLATEWEAK:
            {
              TempString<> args (valStart + cmdLen, valLen - cmdLen);
              args.LTrim();
              ProcessInstrTemplate (state, node, args, 
                tokenID == csWrappedDocumentNodeFactory::PITOKEN_TEMPLATEWEAK);
	      handled = true;
            }
	    break;
	  case csWrappedDocumentNodeFactory::PITOKEN_ENDTEMPLATE:
            if (shared->plugin->do_verbose)
            {
              Report (CS_REPORTER_SEVERITY_WARNING, node,
                "Deprecated syntax, please use %s",
		CS::Quote::Single ("Endtemplate"));
	      handled = true;
            }
            // Fall through
	  case csWrappedDocumentNodeFactory::PITOKEN_ENDTEMPLATE_NEW:
	    {
	      Report (syntaxErrorSeverity, node,
		"%s without %s",
		CS::Quote::Single ("Endtemplate"),
		CS::Quote::Single ("Template"));
              // ProcessTemplate() would've handled it otherwise
	      handled = true;
	    }
	    break;
          case csWrappedDocumentNodeFactory::PITOKEN_GENERATE:
            {
	      bool okay = true;
              Template::Params args;
	      if (space != 0)
	      {
		TempString<> pStr (space + 1, valLen - cmdLen - 1);
		ParseTemplateArguments (pStr, args, false);
	      }
              if ((args.GetSize() < 3) || (args.GetSize() > 4))
              {
                okay = false;
	        Report (syntaxErrorSeverity, node,
		  "%s expects 3 or 4 arguments, got %zu",
		  CS::Quote::Single ("Generate"), args.GetSize());
              }
              if (okay)
              {
                state->generateVar = args[0];

                int start, end, step;
                char dummy;
                if (sscanf (args[1], "%d%c", &start, &dummy) != 1)
                {
	          Report (syntaxErrorSeverity, node,
		    "Argument %s is not an integer", CS::Quote::Single (args[1].GetData()));
                  okay = false;
                }
                if (okay && sscanf (args[2], "%d%c", &end, &dummy) != 1)
                {
	          Report (syntaxErrorSeverity, node,
		    "Argument %s is not an integer", CS::Quote::Single (args[2].GetData()));
                  okay = false;
                }
                if (okay)
                {
                  if (args.GetSize() == 4)
                  {
                    if (sscanf (args[3], "%d%c", &step, &dummy) != 1)
                    {
	              Report (syntaxErrorSeverity, node,
		        "Argument %s is not an integer", CS::Quote::Single (args[3].GetData()));
                      okay = false;
                    }
                  }
                  else
                  {
                    step = (end < start) ? -1 : 1;
                  }
                }
                if (okay)
                {
                  state->generateActive = true;
		              state->generateNestLevel = 1;
                  if (((start > end) && (step >= 0))
                    || ((end >= start) && (step <= 0)))
                  {
	                  Report (syntaxErrorSeverity, node,
		                  "Can't reach end value %d starting from %d with step %d", 
                      end, start, step);
                    state->generateValid = false;
                  }
                  else
                  {
                    state->generateValid = true;
                    state->generateStart = start;
                    state->generateEnd = end;
                    state->generateStep = step;
                    state->templ = Template();
                  }
                }
              }
	      handled = true;
            }
            break;
	  case csWrappedDocumentNodeFactory::PITOKEN_ENDGENERATE:
	    {
	      Report (syntaxErrorSeverity, node,
		"%s without %s",
		CS::Quote::Single ("Endgenerate"),
		CS::Quote::Single ("Generate"));
              // ProcessTemplate() would've handled it otherwise
	    }
	    break;
	  case csWrappedDocumentNodeFactory::PITOKEN_DEFINE:
            {
              TempString<> args (valStart + cmdLen, valLen - cmdLen);
              args.LTrim();
              ProcessDefine (state, node, args);
	      handled = true;
            }
	    break;
	  case csWrappedDocumentNodeFactory::PITOKEN_UNDEF:
            {
              TempString<> args (valStart + cmdLen, valLen - cmdLen);
              args.LTrim();
              ProcessUndef (state, node, args);
	      handled = true;
            }
	    break;
	  case csWrappedDocumentNodeFactory::PITOKEN_STATIC_IFDEF:
	  case csWrappedDocumentNodeFactory::PITOKEN_STATIC_IFNDEF:
            {
              TempString<> args (valStart + cmdLen, valLen - cmdLen);
              args.LTrim();
              ProcessStaticIfDef (state, node, args,
                tokenID == csWrappedDocumentNodeFactory::PITOKEN_STATIC_IFNDEF);
	      handled = true;
            }
            break;
          case csWrappedDocumentNodeFactory::PITOKEN_STATIC_ELSIFDEF:
          case csWrappedDocumentNodeFactory::PITOKEN_STATIC_ELSIFNDEF:
          case csWrappedDocumentNodeFactory::PITOKEN_STATIC_ELSE:
          case csWrappedDocumentNodeFactory::PITOKEN_STATIC_ENDIF:
            {
	      Report (syntaxErrorSeverity, node,
		"%s without %s",
		CS::Quote::Single (shared->pitokens.Request (tokenID)),
		CS::Quote::Single ("SIfDef"));
              // ProcessStaticIf() would've handled it otherwise
	      handled = true;
            }
            break;
	  default:
	    {
	      Template::Params params;
	      if (space != 0)
	      {
		TempString<> pStr (space + 1, valLen - cmdLen - 1);
		ParseTemplateArguments (pStr, params, false);
	      }
	      if (InvokeTemplate (tokenStr, node, state, params))
	      {
            handled = true;
	      }
	      // If it's neither a template nor a recognized command, pass through
	    }
	}
      }
    }
  }
  if (!handled)
  {
    csRef<iDocumentNode> newWrapper;
    newWrapper.AttachNew (new csWrappedDocumentNode (this,
      node, shared, globalState));
    currentWrapper.Push (newWrapper);
  }
}