コード例 #1
0
ファイル: glslOutput.cpp プロジェクト: jims/hlsl2glslfork
bool TGlslOutputTraverser::traverseLoop( bool preVisit, TIntermLoop *node, TIntermTraverser *it )
{
   TGlslOutputTraverser* goit = static_cast<TGlslOutputTraverser*>(it);
   GlslFunction *current = goit->current;
   std::stringstream& out = current->getActiveOutput();

   current->beginStatement();

   if ( node->getTerminal())
   {
      // Process for loop, initial statement was promoted outside the loop
      out << "for ( ; ";
      node->getTest()->traverse(goit);
      out << "; ";
      node->getTerminal()->traverse(goit);
      out << ") ";
      current->beginBlock();
      if (node->getBody())
         node->getBody()->traverse(goit);
      current->endBlock();
   }
   else
   {
      if ( node->testFirst())
      {
         // Process while loop
         out << "while ( ";
         node->getTest()->traverse(goit);
         out << " ) ";
         current->beginBlock();
         if (node->getBody())
            node->getBody()->traverse(goit);
         current->endBlock();
      }
      else
      {
         // Process do loop
         out << "do ";
         current->beginBlock();
         if (node->getBody())
            node->getBody()->traverse(goit);
         current->endBlock();
         current->indent();
         out << "while ( ";
         node->getTest()->traverse(goit);
         out << " )\n";
      }
   }
   return false;
}
コード例 #2
0
ファイル: glslOutput.cpp プロジェクト: jims/hlsl2glslfork
bool TGlslOutputTraverser::traverseSelection( bool preVisit, TIntermSelection *node, TIntermTraverser *it )
{
	TGlslOutputTraverser* goit = static_cast<TGlslOutputTraverser*>(it);
	GlslFunction *current = goit->current;
	std::stringstream& out = current->getActiveOutput();

	current->beginStatement();

	if (node->getBasicType() == EbtVoid)
	{
		// if/else selection
		out << "if (";
		node->getCondition()->traverse(goit);
		out << ')';
		current->beginBlock();
		node->getTrueBlock()->traverse(goit);
		current->endBlock();
		if (node->getFalseBlock())
		{
			current->indent();
			out << "else";
			current->beginBlock();
			node->getFalseBlock()->traverse(goit);
			current->endBlock();
		}
	}
	else if (node->isVector() && node->getCondition()->getAsTyped()->isVector())
	{
		// ?: selection on vectors, e.g. bvec4 ? vec4 : vec4
		// emulate HLSL's component-wise selection here
		current->addLibFunction(EOpVecTernarySel);
		out << "xll_vecTSel (";
		node->getCondition()->traverse(goit);
		out << ", ";
		node->getTrueBlock()->traverse(goit);
		out << ", ";
		if (node->getFalseBlock())
		{
			node->getFalseBlock()->traverse(goit);
		}
		else
			assert(0);
		out << ")";
	}
	else
	{
		// simple ?: selection
		out << "(( ";
		node->getCondition()->traverse(goit);
		out << " ) ? ( ";
		node->getTrueBlock()->traverse(goit);
		out << " ) : ( ";
		if (node->getFalseBlock())
		{
			node->getFalseBlock()->traverse(goit);
		}
		else
			assert(0);
		out << " ))";
	}

	return false;
}