blob: 62b645f5152411fbfd0bfda64724a691d1340151 [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
21 // FIXME(zmo): no need to emit default precision if all variables emit
22 // their own precision.
23 // http://code.google.com/p/angleproject/issues/detail?id=168
24 if (this->getShaderType() == SH_FRAGMENT_SHADER) {
25 // Write default float precision.
26 sink << "#if defined(GL_FRAGMENT_PRECISION_HIGH)\n"
27 << "precision highp float;\n"
28 << "#else\n"
29 << "precision mediump float;\n"
30 << "#endif\n";
31 }
32
33 // Write translated shader.
34 TOutputESSL outputESSL(sink);
35 root->traverse(&outputESSL);
36}
37
38void TranslatorESSL::writeExtensionBehavior() {
39 TInfoSinkBase& sink = getInfoSink().obj;
40 const TExtensionBehavior& extensionBehavior = getExtensionBehavior();
41 for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin();
42 iter != extensionBehavior.end(); ++iter) {
43 sink << "#extension " << iter->first << " : "
44 << getBehaviorString(iter->second) << "\n";
45 }
46}