blob: f718f1ef8646154c7b24f41fe864815a4b1bdbc1 [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
2// Copyright (c) 2002-2011 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.
5//
6
7#include "compiler/TranslatorESSL.h"
8
9#include "compiler/OutputESSL.h"
10
11TranslatorESSL::TranslatorESSL(ShShaderType type, ShShaderSpec spec)
12 : TCompiler(type, spec) {
13}
14
15void TranslatorESSL::translate(TIntermNode* root) {
16 TInfoSinkBase& sink = getInfoSink().obj;
17
18 // Write built-in extension behaviors.
19 writeExtensionBehavior();
20
zmo@google.com32e97312011-08-24 01:03:11 +000021 // Write emulated built-in functions if needed.
22 getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition(
23 sink, getShaderType() == SH_FRAGMENT_SHADER);
24
zmo@google.com5601ea02011-06-10 18:23:25 +000025 // Write translated shader.
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000026 TOutputESSL outputESSL(sink, getHashFunction(), getNameMap(), getSymbolTable());
zmo@google.com5601ea02011-06-10 18:23:25 +000027 root->traverse(&outputESSL);
28}
29
30void TranslatorESSL::writeExtensionBehavior() {
31 TInfoSinkBase& sink = getInfoSink().obj;
32 const TExtensionBehavior& extensionBehavior = getExtensionBehavior();
33 for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin();
34 iter != extensionBehavior.end(); ++iter) {
zmo@google.com09c323a2011-08-12 18:22:25 +000035 if (iter->second != EBhUndefined) {
36 sink << "#extension " << iter->first << " : "
37 << getBehaviorString(iter->second) << "\n";
38 }
zmo@google.com5601ea02011-06-10 18:23:25 +000039 }
40}