2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #include "compiler/translator/TranslatorESSL.h"
9 #include "compiler/translator/OutputESSL.h"
12 TranslatorESSL::TranslatorESSL(sh::GLenum type, ShShaderSpec spec)
13 : TCompiler(type, spec, SH_ESSL_OUTPUT) {
16 void TranslatorESSL::translate(TIntermNode* root) {
17 TInfoSinkBase& sink = getInfoSink().obj;
19 // Write built-in extension behaviors.
20 writeExtensionBehavior();
22 // Write emulated built-in functions if needed.
23 getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition(
24 sink, getShaderType() == GL_FRAGMENT_SHADER);
26 // Write array bounds clamping emulation if needed.
27 getArrayBoundsClamper().OutputClampingFunctionDefinition(sink);
29 // Write translated shader.
30 TOutputESSL outputESSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(), getSymbolTable(), getShaderVersion());
31 root->traverse(&outputESSL);
34 void TranslatorESSL::writeExtensionBehavior() {
35 TInfoSinkBase& sink = getInfoSink().obj;
36 const TExtensionBehavior& extensionBehavior = getExtensionBehavior();
37 for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin();
38 iter != extensionBehavior.end(); ++iter) {
39 if (iter->second != EBhUndefined) {
40 sink << "#extension " << iter->first << " : "
41 << getBehaviorString(iter->second) << "\n";