1 //
2 // Copyright 2002 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 #ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_
8 #define COMPILER_TRANSLATOR_VERSIONGLSL_H_
9 
10 #include "compiler/translator/tree_util/IntermTraverse.h"
11 
12 #include "compiler/translator/Pragma.h"
13 
14 namespace sh
15 {
16 
17 static const int GLSL_VERSION_110 = 110;
18 static const int GLSL_VERSION_120 = 120;
19 static const int GLSL_VERSION_130 = 130;
20 static const int GLSL_VERSION_140 = 140;
21 static const int GLSL_VERSION_150 = 150;
22 static const int GLSL_VERSION_330 = 330;
23 static const int GLSL_VERSION_400 = 400;
24 static const int GLSL_VERSION_410 = 410;
25 static const int GLSL_VERSION_420 = 420;
26 static const int GLSL_VERSION_430 = 430;
27 static const int GLSL_VERSION_440 = 440;
28 static const int GLSL_VERSION_450 = 450;
29 
30 int ShaderOutputTypeToGLSLVersion(ShShaderOutput output);
31 
32 // Traverses the intermediate tree to return the minimum GLSL version
33 // required to legally access all built-in features used in the shader.
34 // GLSL 1.1 which is mandated by OpenGL 2.0 provides:
35 //   - #version and #extension to declare version and extensions.
36 //   - built-in functions refract, exp, and log.
37 //   - updated step() to compare x < edge instead of x <= edge.
38 // GLSL 1.2 which is mandated by OpenGL 2.1 provides:
39 //   - many changes to reduce differences when compared to the ES specification.
40 //   - invariant keyword and its support.
41 //   - c++ style name hiding rules.
42 //   - built-in variable gl_PointCoord for fragment shaders.
43 //   - matrix constructors taking matrix as argument.
44 //   - array as "out" function parameters
45 //
46 // TODO: ES3 equivalent versions of GLSL
47 class TVersionGLSL : public TIntermTraverser
48 {
49   public:
50     TVersionGLSL(sh::GLenum type, const TPragma &pragma, ShShaderOutput output);
51 
52     // If output is core profile, returns 150.
53     // If output is legacy profile,
54     //   Returns 120 if the following is used the shader:
55     //   - "invariant",
56     //   - "gl_PointCoord",
57     //   - matrix/matrix constructors
58     //   - array "out" parameters
59     //   Else 110 is returned.
getVersion()60     int getVersion() const { return mVersion; }
61 
62     void visitSymbol(TIntermSymbol *node) override;
63     bool visitAggregate(Visit, TIntermAggregate *node) override;
64     bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *node) override;
65     void visitFunctionPrototype(TIntermFunctionPrototype *node) override;
66     bool visitDeclaration(Visit, TIntermDeclaration *node) override;
67 
68   private:
69     void ensureVersionIsAtLeast(int version);
70 
71     int mVersion;
72 };
73 
74 }  // namespace sh
75 
76 #endif  // COMPILER_TRANSLATOR_VERSIONGLSL_H_
77