blob: 9cf727c1422305d41402d6e7ec68ce6c211b535b [file] [log] [blame]
alokp@chromium.org9ecf3952010-10-13 19:28:25 +00001//
Jamie Madill02f20dd2013-09-12 12:07:42 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org9ecf3952010-10-13 19:28:25 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Zhenyao Moe40d1e92014-07-16 17:40:36 -07007#ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_
8#define COMPILER_TRANSLATOR_VERSIONGLSL_H_
alokp@chromium.org9ecf3952010-10-13 19:28:25 +00009
Jamie Madillb1a85f42014-08-19 15:23:24 -040010#include "compiler/translator/IntermNode.h"
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000011
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070012#include "compiler/translator/Pragma.h"
13
Jamie Madill45bcc782016-11-07 13:58:48 -050014namespace sh
15{
16
Geoff Lang7b9b2842015-06-15 11:02:49 -070017static const int GLSL_VERSION_110 = 110;
18static const int GLSL_VERSION_120 = 120;
19static const int GLSL_VERSION_130 = 130;
Geoff Lang8273e002015-06-15 13:40:19 -070020static 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;
Geoff Lang7b9b2842015-06-15 11:02:49 -070024static const int GLSL_VERSION_410 = 410;
25static const int GLSL_VERSION_420 = 420;
Geoff Lang8273e002015-06-15 13:40:19 -070026static const int GLSL_VERSION_430 = 430;
27static const int GLSL_VERSION_440 = 440;
28static const int GLSL_VERSION_450 = 450;
Geoff Lang7b9b2842015-06-15 11:02:49 -070029
30int ShaderOutputTypeToGLSLVersion(ShShaderOutput output);
31
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000032// 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.orge26cb5e2011-01-18 21:27:02 +000043// - matrix constructors taking matrix as argument.
alokp@chromium.org8d47c112012-09-06 16:03:23 +000044// - array as "out" function parameters
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000045//
Jamie Madill02f20dd2013-09-12 12:07:42 -040046// TODO: ES3 equivalent versions of GLSL
Zhenyao Moe40d1e92014-07-16 17:40:36 -070047class TVersionGLSL : public TIntermTraverser
48{
49 public:
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080050 TVersionGLSL(sh::GLenum type, const TPragma &pragma, ShShaderOutput output);
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000051
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080052 // 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 Lang7b9b2842015-06-15 11:02:49 -070060 int getVersion() const { return mVersion; }
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000061
Olli Etuahobf4e1b72016-12-09 11:30:15 +000062 void visitSymbol(TIntermSymbol *node) override;
63 bool visitAggregate(Visit, TIntermAggregate *node) override;
64 bool visitInvariantDeclaration(Visit, TIntermInvariantDeclaration *node) override;
Olli Etuaho8ad9e752017-01-16 19:55:20 +000065 bool visitFunctionPrototype(Visit, TIntermFunctionPrototype *node) override;
Olli Etuaho13389b62016-10-16 11:48:18 +010066 bool visitDeclaration(Visit, TIntermDeclaration *node) override;
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000067
Zhenyao Moe40d1e92014-07-16 17:40:36 -070068 private:
Geoff Lang7b9b2842015-06-15 11:02:49 -070069 void ensureVersionIsAtLeast(int version);
70
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000071 int mVersion;
72};
73
Jamie Madill45bcc782016-11-07 13:58:48 -050074} // namespace sh
75
Zhenyao Moe40d1e92014-07-16 17:40:36 -070076#endif // COMPILER_TRANSLATOR_VERSIONGLSL_H_