arb_program_interface_query: set vs_input2[1][0] as valid name
[piglit.git] / tests / llvmpipe / glsl / variable.h
blob6622e6c4bf613f6006ad75d4fc0360e35ae5aa0f
1 /*
2 * Copyright © 2012-2021 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #pragma once
26 #include "value.h"
28 namespace glsl
30 class Variable
32 public:
33 enum Type {
34 BuiltIn,
35 Attribute,
36 Local,
37 Varying,
38 Uniform,
39 UniformSampler
42 public:
43 Variable()
44 : mType(BuiltIn), mLocation(0)
48 Variable(const std::string& name, Type type, const Value& value)
49 : mType(type), mName(name), mValue(value), mLocation(0)
53 const std::string& name() const
55 return mName;
58 std::string toGLSL() const
60 if (mType == UniformSampler) {
61 return std::string("uniform sampler2D ") + mName;
62 } else if (mType == Uniform) {
63 return std::string("uniform ") + mValue.toTypeString() + " " + mName;
64 } else if (mType == Varying) {
65 return std::string("varying ") + mValue.toTypeString() + " " + mName;
66 } else if (mType == Attribute) {
67 return std::string("attribute ") + mValue.toTypeString() + " " + mName;
68 } else {
69 return mValue.toTypeString() + " " + mName;
73 Type type() const
75 return mType;
78 unsigned int location()
80 return mLocation;
83 void setType(Type type)
85 mType = type;
88 void setLocation(unsigned int location)
90 mLocation = location;
93 bool declare() const
95 return isAttribute() || isVarying() || isUniform();
98 bool isAttribute() const
100 return mType == Attribute;
103 bool isUniform() const
105 return mType == Uniform || mType == UniformSampler;
108 bool isVarying() const
110 return mType == Varying;
113 Value value() const
115 return mValue;
118 template<typename T>
119 T* valuePtr() const
121 return mValue.valuePtr<T>();
124 template<typename T>
125 T& value() const
127 return mValue.value<T>();
130 Variable& operator=(const Value& rhs)
132 mValue = rhs;
133 return *this;
136 private:
137 Type mType;
138 std::string mName;
139 Value mValue;
140 unsigned int mLocation;