//-----------------------------------------------------------------------
void CGProgramWriter::writeFunctionDeclaration(std::ostream& os, Function* function, bool & needToTranslateHlsl4Color, ParameterPtr & colorParameter)
{
	const ShaderParameterList& inParams  = function->getInputParameters();
	const ShaderParameterList& outParams = function->getOutputParameters();


	os << "void";
	os << " ";

	os << function->getName();
	os << std::endl << "\t(" << std::endl;

	ShaderParameterConstIterator it;
	size_t paramsCount = inParams.size() + outParams.size();
	size_t curParamIndex = 0;

	// for shader model 4 - we need to get the color as unsigned int
	bool isVs4 = GpuProgramManager::getSingleton().isSyntaxSupported("vs_4_0");

	// Write input parameters.
	for (it=inParams.begin(); it != inParams.end(); ++it)
	{					
		os << "\t in ";

		if (isVs4 &&
			function->getFunctionType() == Function::FFT_VS_MAIN &&
			(*it)->getSemantic() == Parameter::SPS_COLOR 
			)
		{
			os << "unsigned int iHlsl4Color_0 : COLOR";
			needToTranslateHlsl4Color = true;
			colorParameter = *it;
		}
		else
		{
			writeFunctionParameter(os, *it);
		}

		if (curParamIndex + 1 != paramsCount)		
			os << ", " << std::endl;

		curParamIndex++;
	}


	// Write output parameters.
	for (it=outParams.begin(); it != outParams.end(); ++it)
	{
		os << "\t out ";
		writeFunctionParameter(os, *it);

		if (curParamIndex + 1 != paramsCount)				
			os << ", " << std::endl;

		curParamIndex++;
	}	

	os << std::endl << "\t)" << std::endl;
}
//-----------------------------------------------------------------------
void HLSLProgramWriter::writeFunctionDeclaration(std::ostream& os, Function* function)
{
	const ShaderParameterList& inParams  = function->getInputParameters();
	const ShaderParameterList& outParams = function->getOutputParameters();


	os << "void";
	os << " ";

	os << function->getName();
	os << std::endl << "\t(" << std::endl;

	ShaderParameterConstIterator it;
	size_t paramsCount = inParams.size() + outParams.size();
	size_t curParamIndex = 0;

	bool isVs4 = GpuProgramManager::getSingleton().isSyntaxSupported("vs_4_0_level_9_1");

	// Write input parameters.
	for (it=inParams.begin(); it != inParams.end(); ++it)
	{					
		os << "\t in ";

		const char* forcedSemantic = 
			(isVs4 && function->getFunctionType() == Function::FFT_PS_MAIN && (*it)->getSemantic() == Parameter::SPS_POSITION) ? "SV_Position" : NULL;

		writeFunctionParameter(os, *it, forcedSemantic);

		if (curParamIndex + 1 != paramsCount)		
			os << ", " << std::endl;

		curParamIndex++;
	}

	// Write output parameters.
	for (it=outParams.begin(); it != outParams.end(); ++it)
	{
		os << "\t out ";

		const char* forcedSemantic = 
			(isVs4 && function->getFunctionType() == Function::FFT_PS_MAIN) ? "SV_Target" :
			(isVs4 && function->getFunctionType() == Function::FFT_VS_MAIN && (*it)->getSemantic() == Parameter::SPS_POSITION) ? "SV_Position" : NULL;

		writeFunctionParameter(os, *it, forcedSemantic);

		if (curParamIndex + 1 != paramsCount)				
			os << ", " << std::endl;

		curParamIndex++;
	}	
	
	os << std::endl << "\t)" << std::endl;
}
Пример #3
0
//-----------------------------------------------------------------------
void CGProgramWriter::writeFunctionDeclaration(std::ostream& os, Function* function)
{
	const ShaderParameterList& inParams  = function->getInputParameters();
	const ShaderParameterList& outParams = function->getOutputParameters();


	os << "void";
	os << " ";

	os << function->getName();
	os << std::endl << "\t(" << std::endl;

	ShaderParameterConstIterator it;
	size_t paramsCount = inParams.size() + outParams.size();
	size_t curParamIndex = 0;

	// Write input parameters.
	for (it=inParams.begin(); it != inParams.end(); ++it)
	{					
		os << "\t in ";

		writeFunctionParameter(os, *it);

		if (curParamIndex + 1 != paramsCount)		
			os << ", " << std::endl;

		curParamIndex++;
	}


	// Write output parameters.
	for (it=outParams.begin(); it != outParams.end(); ++it)
	{
		os << "\t out ";
		writeFunctionParameter(os, *it);

		if (curParamIndex + 1 != paramsCount)				
			os << ", " << std::endl;

		curParamIndex++;
	}	

	os << std::endl << "\t)" << std::endl;
}