michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "compiler/TranslatorGLSL.h" michael@0: michael@0: #include "compiler/OutputGLSL.h" michael@0: #include "compiler/VersionGLSL.h" michael@0: michael@0: static void writeVersion(ShShaderType type, TIntermNode* root, michael@0: TInfoSinkBase& sink) { michael@0: TVersionGLSL versionGLSL(type); michael@0: root->traverse(&versionGLSL); michael@0: int version = versionGLSL.getVersion(); michael@0: // We need to write version directive only if it is greater than 110. michael@0: // If there is no version directive in the shader, 110 is implied. michael@0: if (version > 110) { michael@0: sink << "#version " << version << "\n"; michael@0: } michael@0: } michael@0: michael@0: TranslatorGLSL::TranslatorGLSL(ShShaderType type, ShShaderSpec spec) michael@0: : TCompiler(type, spec) { michael@0: } michael@0: michael@0: void TranslatorGLSL::translate(TIntermNode* root) { michael@0: TInfoSinkBase& sink = getInfoSink().obj; michael@0: michael@0: // Write GLSL version. michael@0: writeVersion(getShaderType(), root, sink); michael@0: michael@0: // Write emulated built-in functions if needed. michael@0: getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition( michael@0: sink, false); michael@0: michael@0: // Write array bounds clamping emulation if needed. michael@0: getArrayBoundsClamper().OutputClampingFunctionDefinition(sink); michael@0: michael@0: // Write translated shader. michael@0: TOutputGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(), getSymbolTable()); michael@0: root->traverse(&outputGLSL); michael@0: }