1 : //
2 : // Copyright (c) 2002-2010 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/TranslatorGLSL.h"
8 :
9 : #include "compiler/OutputGLSL.h"
10 : #include "compiler/VersionGLSL.h"
11 :
12 0 : static void writeVersion(ShShaderType type, TIntermNode* root,
13 : TInfoSinkBase& sink) {
14 0 : TVersionGLSL versionGLSL(type);
15 0 : root->traverse(&versionGLSL);
16 0 : int version = versionGLSL.getVersion();
17 : // We need to write version directive only if it is greater than 110.
18 : // If there is no version directive in the shader, 110 is implied.
19 0 : if (version > 110) {
20 0 : sink << "#version " << version << "\n";
21 : }
22 0 : }
23 :
24 0 : TranslatorGLSL::TranslatorGLSL(ShShaderType type, ShShaderSpec spec)
25 0 : : TCompiler(type, spec) {
26 0 : }
27 :
28 0 : void TranslatorGLSL::translate(TIntermNode* root) {
29 0 : TInfoSinkBase& sink = getInfoSink().obj;
30 :
31 : // Write GLSL version.
32 0 : writeVersion(getShaderType(), root, sink);
33 :
34 : // Write emulated built-in functions if needed.
35 0 : getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition(
36 0 : sink, false);
37 :
38 : // Write translated shader.
39 0 : TOutputGLSL outputGLSL(sink);
40 0 : root->traverse(&outputGLSL);
41 0 : }
|