blob: 376fcb84861ae5213df7a5497c5ba2700c29d7c4 [file] [log] [blame]
alokp@chromium.org9ecf3952010-10-13 19:28:25 +00001//
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#ifndef COMPILER_VERSIONGLSL_H_
8#define COMPILER_VERSIONGLSL_H_
9
10#include "GLSLANG/ShaderLang.h"
11#include "compiler/intermediate.h"
12
13// Traverses the intermediate tree to return the minimum GLSL version
14// required to legally access all built-in features used in the shader.
15// GLSL 1.1 which is mandated by OpenGL 2.0 provides:
16// - #version and #extension to declare version and extensions.
17// - built-in functions refract, exp, and log.
18// - updated step() to compare x < edge instead of x <= edge.
19// GLSL 1.2 which is mandated by OpenGL 2.1 provides:
20// - many changes to reduce differences when compared to the ES specification.
21// - invariant keyword and its support.
22// - c++ style name hiding rules.
23// - built-in variable gl_PointCoord for fragment shaders.
kbr@chromium.orge26cb5e2011-01-18 21:27:02 +000024// - matrix constructors taking matrix as argument.
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000025//
26class TVersionGLSL : public TIntermTraverser {
27public:
28 TVersionGLSL(ShShaderType type);
29
kbr@chromium.orge26cb5e2011-01-18 21:27:02 +000030 // Returns 120 if "invariant" keyword, "gl_PointCoord", or
31 // matrix/matrix constructors are used in the shader. Else 110 is
32 // returned.
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000033 int getVersion() { return mVersion; }
34
35 virtual void visitSymbol(TIntermSymbol*);
36 virtual void visitConstantUnion(TIntermConstantUnion*);
37 virtual bool visitBinary(Visit, TIntermBinary*);
38 virtual bool visitUnary(Visit, TIntermUnary*);
39 virtual bool visitSelection(Visit, TIntermSelection*);
40 virtual bool visitAggregate(Visit, TIntermAggregate*);
41 virtual bool visitLoop(Visit, TIntermLoop*);
42 virtual bool visitBranch(Visit, TIntermBranch*);
43
44protected:
45 void updateVersion(int version);
46
47private:
48 ShShaderType mShaderType;
49 int mVersion;
50};
51
52#endif // COMPILER_VERSIONGLSL_H_