Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / compiler / translator / VersionGLSL.cpp
1 //
2 // Copyright (c) 2002-2012 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 #include "compiler/translator/VersionGLSL.h"
8
9 static const int GLSL_VERSION_110 = 110;
10 static const int GLSL_VERSION_120 = 120;
11
12 // We need to scan for the following:
13 // 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
14 //    but only at the global scope.
15 // 2. "gl_PointCoord" built-in variable: This can only occur in fragment shader
16 //    but inside any scope.
17 // 3. Call to a matrix constructor with another matrix as argument.
18 //    (These constructors were reserved in GLSL version 1.10.)
19 // 4. Arrays as "out" function parameters.
20 //    GLSL spec section 6.1.1: "When calling a function, expressions that do
21 //    not evaluate to l-values cannot be passed to parameters declared as
22 //    out or inout."
23 //    GLSL 1.1 section 5.8: "Other binary or unary expressions,
24 //    non-dereferenced arrays, function names, swizzles with repeated fields,
25 //    and constants cannot be l-values."
26 //    GLSL 1.2 relaxed the restriction on arrays, section 5.8: "Variables that
27 //    are built-in types, entire structures or arrays... are all l-values."
28 //
29 TVersionGLSL::TVersionGLSL(sh::GLenum type, const TPragma &pragma)
30 {
31     if (pragma.stdgl.invariantAll)
32         mVersion = GLSL_VERSION_120;
33     else
34         mVersion = GLSL_VERSION_110;
35 }
36
37 void TVersionGLSL::visitSymbol(TIntermSymbol *node)
38 {
39     if (node->getSymbol() == "gl_PointCoord")
40         updateVersion(GLSL_VERSION_120);
41 }
42
43 bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
44 {
45     bool visitChildren = true;
46
47     switch (node->getOp())
48     {
49       case EOpSequence:
50         // We need to visit sequence children to get to global or inner scope.
51         visitChildren = true;
52         break;
53       case EOpDeclaration:
54         {
55             const TIntermSequence &sequence = *(node->getSequence());
56             TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
57             if ((qualifier == EvqInvariantVaryingIn) ||
58                 (qualifier == EvqInvariantVaryingOut))
59             {
60                 updateVersion(GLSL_VERSION_120);
61             }
62             break;
63         }
64       case EOpInvariantDeclaration:
65         updateVersion(GLSL_VERSION_120);
66         break;
67       case EOpParameters:
68         {
69             const TIntermSequence &params = *(node->getSequence());
70             for (TIntermSequence::const_iterator iter = params.begin();
71                  iter != params.end(); ++iter)
72             {
73                 const TIntermTyped *param = (*iter)->getAsTyped();
74                 if (param->isArray())
75                 {
76                     TQualifier qualifier = param->getQualifier();
77                     if ((qualifier == EvqOut) || (qualifier ==  EvqInOut))
78                     {
79                         updateVersion(GLSL_VERSION_120);
80                         break;
81                     }
82                 }
83             }
84             // Fully processed. No need to visit children.
85             visitChildren = false;
86             break;
87         }
88       case EOpConstructMat2:
89       case EOpConstructMat3:
90       case EOpConstructMat4:
91         {
92             const TIntermSequence &sequence = *(node->getSequence());
93             if (sequence.size() == 1)
94             {
95                 TIntermTyped *typed = sequence.front()->getAsTyped();
96                 if (typed && typed->isMatrix())
97                 {
98                     updateVersion(GLSL_VERSION_120);
99                 }
100             }
101             break;
102         }
103       default:
104         break;
105     }
106
107     return visitChildren;
108 }
109
110 void TVersionGLSL::updateVersion(int version)
111 {
112     mVersion = std::max(version, mVersion);
113 }
114