void HlslLinker::emitGlobals(const GlslFunction* globalFunction, const std::vector<GlslSymbol*>& constants)
{
	// write global scope declarations (represented as a fake function)
	assert(globalFunction);
	shader << globalFunction->getCode();
	globalFunction->addNeededExtensions (m_Extensions, m_Target);
	
	// write mutable uniform declarations
	const unsigned n_constants = constants.size();
	for (unsigned i = 0; i != n_constants; ++i) {
		GlslSymbol* s = constants[i];
		if (s->getIsMutable()) {
			s->writeDecl(shader, GlslSymbol::kWriteDeclMutableDecl);
			shader << ";\n";	
		}
	}	
}
void HlslLinker::emitMainStart(const HlslCrossCompiler* compiler, const EGlslSymbolType retType, GlslFunction* funcMain, unsigned options, bool usePrecision, std::stringstream& preamble, const std::vector<GlslSymbol*>& constants)
{
	preamble << "void main() {\n";
	
	// initialize mutable uniforms with the original uniform values
	const unsigned n_constants = constants.size();
	for (unsigned i = 0; i != n_constants; ++i) {
		GlslSymbol* s = constants[i];
		if (s->getIsMutable()) {
			s->writeDecl(preamble, GlslSymbol::kWriteDeclMutableInit);
			preamble << ";\n";
		}
	}
	
	std::string arrayInit = compiler->m_DeferredArrayInit.str();
	if (!arrayInit.empty())
	{
		const bool emit_120_arrays = (m_Target >= ETargetGLSL_120);
		const bool emit_old_arrays = !emit_120_arrays || (options & ETranslateOpEmitGLSL120ArrayInitWorkaround);
		const bool emit_both = emit_120_arrays && emit_old_arrays;
		
		if (emit_both)
			preamble << "#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)" << std::endl;
		preamble << arrayInit;
		if (emit_both)
			preamble << "\n#endif" << std::endl;
	}
	std::string matrixInit = compiler->m_DeferredMatrixInit.str();
	if (!matrixInit.empty())
	{
		preamble << matrixInit;
	}
	
	if (retType == EgstStruct)
	{
		GlslStruct* retStruct = funcMain->getStruct();
		assert(retStruct);
		preamble << "    " << retStruct->getName() << " xl_retval;\n";
	}
	else if (retType != EgstVoid)
	{
		preamble << "    ";
		writeType (preamble, retType, NULL, usePrecision?funcMain->getPrecision():EbpUndefined);
		preamble << " xl_retval;\n";
	}
}