alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_ |
| 8 | #define COMPILER_TRANSLATOR_VERSIONGLSL_H_ |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 9 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 10 | #include "compiler/translator/IntermNode.h" |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 11 | |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 12 | #include "compiler/translator/Pragma.h" |
| 13 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 14 | namespace sh |
| 15 | { |
| 16 | |
Geoff Lang | 7b9b284 | 2015-06-15 11:02:49 -0700 | [diff] [blame] | 17 | static const int GLSL_VERSION_110 = 110; |
| 18 | static const int GLSL_VERSION_120 = 120; |
| 19 | static const int GLSL_VERSION_130 = 130; |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 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; |
Geoff Lang | 7b9b284 | 2015-06-15 11:02:49 -0700 | [diff] [blame] | 24 | static const int GLSL_VERSION_410 = 410; |
| 25 | static const int GLSL_VERSION_420 = 420; |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 26 | static const int GLSL_VERSION_430 = 430; |
| 27 | static const int GLSL_VERSION_440 = 440; |
| 28 | static const int GLSL_VERSION_450 = 450; |
Geoff Lang | 7b9b284 | 2015-06-15 11:02:49 -0700 | [diff] [blame] | 29 | |
| 30 | int ShaderOutputTypeToGLSLVersion(ShShaderOutput output); |
| 31 | |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 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. |
kbr@chromium.org | e26cb5e | 2011-01-18 21:27:02 +0000 | [diff] [blame] | 43 | // - matrix constructors taking matrix as argument. |
alokp@chromium.org | 8d47c11 | 2012-09-06 16:03:23 +0000 | [diff] [blame] | 44 | // - array as "out" function parameters |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 45 | // |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 46 | // TODO: ES3 equivalent versions of GLSL |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 47 | class TVersionGLSL : public TIntermTraverser |
| 48 | { |
| 49 | public: |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 50 | TVersionGLSL(sh::GLenum type, const TPragma &pragma, ShShaderOutput output); |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 51 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 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. |
Geoff Lang | 7b9b284 | 2015-06-15 11:02:49 -0700 | [diff] [blame] | 60 | int getVersion() const { return mVersion; } |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 61 | |
Olli Etuaho | bf4e1b7 | 2016-12-09 11:30:15 +0000 | [diff] [blame] | 62 | void visitSymbol(TIntermSymbol *node) override; |
| 63 | bool visitAggregate(Visit, TIntermAggregate *node) override; |
| 64 | bool visitInvariantDeclaration(Visit, TIntermInvariantDeclaration *node) override; |
Olli Etuaho | 8ad9e75 | 2017-01-16 19:55:20 +0000 | [diff] [blame] | 65 | bool visitFunctionPrototype(Visit, TIntermFunctionPrototype *node) override; |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 66 | bool visitDeclaration(Visit, TIntermDeclaration *node) override; |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 67 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 68 | private: |
Geoff Lang | 7b9b284 | 2015-06-15 11:02:49 -0700 | [diff] [blame] | 69 | void ensureVersionIsAtLeast(int version); |
| 70 | |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 71 | int mVersion; |
| 72 | }; |
| 73 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 74 | } // namespace sh |
| 75 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 76 | #endif // COMPILER_TRANSLATOR_VERSIONGLSL_H_ |