zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VersionGLSL.cpp
Go to the documentation of this file.
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/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 // TODO(alokp): The following two cases of invariant decalaration get lost
30 // during parsing - they do not get carried over to the intermediate tree.
31 // Handle these cases:
32 // 1. When a pragma is used to force all output variables to be invariant:
33 // - #pragma STDGL invariant(all)
34 // 2. When a previously decalared or built-in variable is marked invariant:
35 // - invariant gl_Position;
36 // - varying vec3 color; invariant color;
37 //
39  : mShaderType(type),
40  mVersion(GLSL_VERSION_110)
41 {
42 }
43 
45 {
46  if (node->getSymbol() == "gl_PointCoord")
48 }
49 
51 {
52 }
53 
55 {
56  return true;
57 }
58 
60 {
61  return true;
62 }
63 
65 {
66  return true;
67 }
68 
70 {
71  bool visitChildren = true;
72 
73  switch (node->getOp()) {
74  case EOpSequence:
75  // We need to visit sequence children to get to global or inner scope.
76  visitChildren = true;
77  break;
78  case EOpDeclaration: {
79  const TIntermSequence& sequence = node->getSequence();
80  TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
81  if ((qualifier == EvqInvariantVaryingIn) ||
82  (qualifier == EvqInvariantVaryingOut)) {
84  }
85  break;
86  }
87  case EOpParameters: {
88  const TIntermSequence& params = node->getSequence();
89  for (TIntermSequence::const_iterator iter = params.begin();
90  iter != params.end(); ++iter)
91  {
92  const TIntermTyped* param = (*iter)->getAsTyped();
93  if (param->isArray())
94  {
95  TQualifier qualifier = param->getQualifier();
96  if ((qualifier == EvqOut) || (qualifier == EvqInOut))
97  {
99  break;
100  }
101  }
102  }
103  // Fully processed. No need to visit children.
104  visitChildren = false;
105  break;
106  }
107  case EOpConstructMat2:
108  case EOpConstructMat3:
109  case EOpConstructMat4: {
110  const TIntermSequence& sequence = node->getSequence();
111  if (sequence.size() == 1) {
112  TIntermTyped* typed = sequence.front()->getAsTyped();
113  if (typed && typed->isMatrix()) {
115  }
116  }
117  break;
118  }
119 
120  default: break;
121  }
122 
123  return visitChildren;
124 }
125 
127 {
128  return true;
129 }
130 
132 {
133  return true;
134 }
135 
137 {
138  mVersion = std::max(version, mVersion);
139 }
140 
TVersionGLSL(ShShaderType type)
Definition: VersionGLSL.cpp:38
Visit
Definition: intermediate.h:524
TOperator getOp() const
Definition: intermediate.h:389
TQualifier
Definition: BaseTypes.h:81
GLenum GLint param
Definition: gl2ext.h:1491
TIntermSequence & getSequence()
Definition: intermediate.h:469
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
virtual bool visitBinary(Visit, TIntermBinary *)
Definition: VersionGLSL.cpp:54
virtual bool visitUnary(Visit, TIntermUnary *)
Definition: VersionGLSL.cpp:59
virtual bool visitAggregate(Visit, TIntermAggregate *)
Definition: VersionGLSL.cpp:69
int const char * version
Definition: zlib.h:813
virtual bool visitSelection(Visit, TIntermSelection *)
Definition: VersionGLSL.cpp:64
TQualifier getQualifier() const
Definition: intermediate.h:255
bool isMatrix() const
Definition: intermediate.h:259
GLenum GLvoid ** params
Definition: gl2ext.h:806
virtual bool visitLoop(Visit, TIntermLoop *)
static const int GLSL_VERSION_110
Definition: VersionGLSL.cpp:9
virtual void visitSymbol(TIntermSymbol *)
Definition: VersionGLSL.cpp:44
virtual void visitConstantUnion(TIntermConstantUnion *)
Definition: VersionGLSL.cpp:50
static const int GLSL_VERSION_120
Definition: VersionGLSL.cpp:10
virtual bool visitBranch(Visit, TIntermBranch *)
bool isArray() const
Definition: intermediate.h:260
virtual TIntermTyped * getAsTyped()
Definition: intermediate.h:248
ShShaderType
Definition: ShaderLang.h:48
const TString & getSymbol() const
Definition: intermediate.h:349
#define max(x, y)
Definition: os.h:79
void updateVersion(int version)