1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/TranslatorGLSL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,44 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#include "compiler/TranslatorGLSL.h" 1.11 + 1.12 +#include "compiler/OutputGLSL.h" 1.13 +#include "compiler/VersionGLSL.h" 1.14 + 1.15 +static void writeVersion(ShShaderType type, TIntermNode* root, 1.16 + TInfoSinkBase& sink) { 1.17 + TVersionGLSL versionGLSL(type); 1.18 + root->traverse(&versionGLSL); 1.19 + int version = versionGLSL.getVersion(); 1.20 + // We need to write version directive only if it is greater than 110. 1.21 + // If there is no version directive in the shader, 110 is implied. 1.22 + if (version > 110) { 1.23 + sink << "#version " << version << "\n"; 1.24 + } 1.25 +} 1.26 + 1.27 +TranslatorGLSL::TranslatorGLSL(ShShaderType type, ShShaderSpec spec) 1.28 + : TCompiler(type, spec) { 1.29 +} 1.30 + 1.31 +void TranslatorGLSL::translate(TIntermNode* root) { 1.32 + TInfoSinkBase& sink = getInfoSink().obj; 1.33 + 1.34 + // Write GLSL version. 1.35 + writeVersion(getShaderType(), root, sink); 1.36 + 1.37 + // Write emulated built-in functions if needed. 1.38 + getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition( 1.39 + sink, false); 1.40 + 1.41 + // Write array bounds clamping emulation if needed. 1.42 + getArrayBoundsClamper().OutputClampingFunctionDefinition(sink); 1.43 + 1.44 + // Write translated shader. 1.45 + TOutputGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(), getSymbolTable()); 1.46 + root->traverse(&outputGLSL); 1.47 +}