1//
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.
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
14namespace sh
15{
16
17static const int GLSL_VERSION_110 = 110;
18static const int GLSL_VERSION_120 = 120;
19static const int GLSL_VERSION_130 = 130;
20static const int GLSL_VERSION_140 = 140;
21static const int GLSL_VERSION_150 = 150;
22static const int GLSL_VERSION_330 = 330;
23static const int GLSL_VERSION_400 = 400;
24static const int GLSL_VERSION_410 = 410;
25static const int GLSL_VERSION_420 = 420;
26static const int GLSL_VERSION_430 = 430;
27static const int GLSL_VERSION_440 = 440;
28static const int GLSL_VERSION_450 = 450;
29
30int 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
47class 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.
60 int getVersion() const { return mVersion; }
61
62 void visitSymbol(TIntermSymbol *node) override;
63 bool visitAggregate(Visit, TIntermAggregate *node) override;
64 bool visitInvariantDeclaration(Visit, TIntermInvariantDeclaration *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