Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrShaderVar.h
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrShaderVar_DEFINED
9 #define GrShaderVar_DEFINED
10 
11 #include "GrTypesPriv.h"
12 #include "SkString.h"
13 
14 class GrShaderVar {
15 public:
25  enum TypeModifier {
26  kNone_TypeModifier,
27  kOut_TypeModifier,
28  kIn_TypeModifier,
29  kInOut_TypeModifier,
30  kUniform_TypeModifier,
31  // GL Specific types below
32  kAttribute_TypeModifier,
33  kVaryingIn_TypeModifier,
34  kVaryingOut_TypeModifier
35  };
36 
41  : fType(kFloat_GrSLType)
42  , fTypeModifier(kNone_TypeModifier)
43  , fCount(kNonArray)
44  , fPrecision(kDefault_GrSLPrecision) {
45  }
46 
47  GrShaderVar(const SkString& name, GrSLType type, int arrayCount = kNonArray,
48  GrSLPrecision precision = kDefault_GrSLPrecision)
49  : fType(type)
50  , fTypeModifier(kNone_TypeModifier)
51  , fName(name)
52  , fCount(arrayCount)
53  , fPrecision(precision) {
54  SkASSERT(kVoid_GrSLType != type);
55  }
56 
57  GrShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray,
58  GrSLPrecision precision = kDefault_GrSLPrecision)
59  : fType(type)
60  , fTypeModifier(kNone_TypeModifier)
61  , fName(name)
62  , fCount(arrayCount)
63  , fPrecision(precision) {
64  SkASSERT(kVoid_GrSLType != type);
65  }
66 
67  GrShaderVar(const char* name, GrSLType type, TypeModifier typeModifier,
68  int arrayCount = kNonArray, GrSLPrecision precision = kDefault_GrSLPrecision)
69  : fType(type)
70  , fTypeModifier(typeModifier)
71  , fName(name)
72  , fCount(arrayCount)
73  , fPrecision(precision) {
74  SkASSERT(kVoid_GrSLType != type);
75  }
76 
80  enum {
81  kNonArray = 0, // not an array
82  kUnsizedArray = -1, // an unsized array (declared with [])
83  };
84 
85  void set(GrSLType type,
86  const SkString& name,
87  TypeModifier typeModifier = kNone_TypeModifier,
88  GrSLPrecision precision = kDefault_GrSLPrecision,
89  int count = kNonArray) {
90  SkASSERT(kVoid_GrSLType != type);
91  fType = type;
92  fTypeModifier = typeModifier;
93  fName = name;
94  fCount = count;
95  fPrecision = precision;
96  }
97 
98  void set(GrSLType type,
99  const char* name,
100  TypeModifier typeModifier = kNone_TypeModifier,
101  GrSLPrecision precision = kDefault_GrSLPrecision,
102  int count = kNonArray) {
103  SkASSERT(kVoid_GrSLType != type);
104  fType = type;
105  fTypeModifier = typeModifier;
106  fName = name;
107  fCount = count;
108  fPrecision = precision;
109  }
110 
114  bool isArray() const { return kNonArray != fCount; }
118  bool isUnsizedArray() const { return kUnsizedArray == fCount; }
122  int getArrayCount() const { return fCount; }
126  void setArrayCount(int count) { fCount = count; }
130  void setNonArray() { fCount = kNonArray; }
134  void setUnsizedArray() { fCount = kUnsizedArray; }
135 
139  SkString* accessName() { return &fName; }
143  void setName(const SkString& n) { fName = n; }
144  void setName(const char* n) { fName = n; }
145 
149  const SkString& getName() const { return fName; }
150 
154  const char* c_str() const { return this->getName().c_str(); }
155 
159  GrSLType getType() const { return fType; }
163  void setType(GrSLType type) { fType = type; }
164 
165  TypeModifier getTypeModifier() const { return fTypeModifier; }
166  void setTypeModifier(TypeModifier type) { fTypeModifier = type; }
167 
171  GrSLPrecision getPrecision() const { return fPrecision; }
172 
176  void setPrecision(GrSLPrecision p) { fPrecision = p; }
177 
178 protected:
179  GrSLType fType;
180  TypeModifier fTypeModifier;
181  SkString fName;
182  int fCount;
183  GrSLPrecision fPrecision;
184 };
185 
186 #endif
GrSLType getType() const
Get the type of the var.
Definition: GrShaderVar.h:159
int getArrayCount() const
Get the array length of the var.
Definition: GrShaderVar.h:122
const char * c_str() const
Shortcut for this->getName().c_str();.
Definition: GrShaderVar.h:154
Definition: GrShaderVar.h:14
void setName(const SkString &n)
Set the var name.
Definition: GrShaderVar.h:143
bool isArray() const
Is the var an array.
Definition: GrShaderVar.h:114
void setNonArray()
Set to be a non-array.
Definition: GrShaderVar.h:130
bool isUnsizedArray() const
Is this an unsized array, (i.e.
Definition: GrShaderVar.h:118
GrSLPrecision getPrecision() const
Get the precision of the var.
Definition: GrShaderVar.h:171
SkString * accessName()
Access the var name as a writable string.
Definition: GrShaderVar.h:139
TypeModifier
Early versions of GLSL have Varying and Attribute; those are later deprecated, but we still need to k...
Definition: GrShaderVar.h:25
void setUnsizedArray()
Set to be an unsized array.
Definition: GrShaderVar.h:134
void setPrecision(GrSLPrecision p)
Set the precision of the var.
Definition: GrShaderVar.h:176
void setType(GrSLType type)
Set the type of the var.
Definition: GrShaderVar.h:163
GrShaderVar()
Defaults to a float with no precision specifier.
Definition: GrShaderVar.h:40
const SkString & getName() const
Get the var name.
Definition: GrShaderVar.h:149
void setArrayCount(int count)
Set the array length of the var.
Definition: GrShaderVar.h:126
Light weight class for managing strings.
Definition: SkString.h:121