• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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 #include "libANGLE/Uniform.h"
8 
9 #include <cstring>
10 
11 namespace gl
12 {
13 
ActiveVariable()14 ActiveVariable::ActiveVariable() {}
15 
~ActiveVariable()16 ActiveVariable::~ActiveVariable() {}
17 
18 ActiveVariable::ActiveVariable(const ActiveVariable &rhs) = default;
19 ActiveVariable &ActiveVariable::operator=(const ActiveVariable &rhs) = default;
20 
setActive(ShaderType shaderType,bool used)21 void ActiveVariable::setActive(ShaderType shaderType, bool used)
22 {
23     ASSERT(shaderType != ShaderType::InvalidEnum);
24     mActiveUseBits.set(shaderType, used);
25 }
26 
unionReferencesWith(const ActiveVariable & other)27 void ActiveVariable::unionReferencesWith(const ActiveVariable &other)
28 {
29     mActiveUseBits |= other.mActiveUseBits;
30 }
31 
getFirstShaderTypeWhereActive() const32 ShaderType ActiveVariable::getFirstShaderTypeWhereActive() const
33 {
34     return static_cast<ShaderType>(ScanForward(mActiveUseBits.bits()));
35 }
36 
activeShaderCount() const37 GLuint ActiveVariable::activeShaderCount() const
38 {
39     return static_cast<GLuint>(mActiveUseBits.count());
40 }
41 
LinkedUniform()42 LinkedUniform::LinkedUniform()
43     : typeInfo(nullptr),
44       bufferIndex(-1),
45       blockInfo(sh::kDefaultBlockMemberInfo),
46       outerArrayOffset(0)
47 {}
48 
LinkedUniform(GLenum typeIn,GLenum precisionIn,const std::string & nameIn,const std::vector<unsigned int> & arraySizesIn,const int bindingIn,const int offsetIn,const int locationIn,const int bufferIndexIn,const sh::BlockMemberInfo & blockInfoIn)49 LinkedUniform::LinkedUniform(GLenum typeIn,
50                              GLenum precisionIn,
51                              const std::string &nameIn,
52                              const std::vector<unsigned int> &arraySizesIn,
53                              const int bindingIn,
54                              const int offsetIn,
55                              const int locationIn,
56                              const int bufferIndexIn,
57                              const sh::BlockMemberInfo &blockInfoIn)
58     : typeInfo(&GetUniformTypeInfo(typeIn)),
59       bufferIndex(bufferIndexIn),
60       blockInfo(blockInfoIn),
61       outerArrayOffset(0)
62 {
63     type       = typeIn;
64     precision  = precisionIn;
65     name       = nameIn;
66     arraySizes = arraySizesIn;
67     binding    = bindingIn;
68     offset     = offsetIn;
69     location   = locationIn;
70     ASSERT(!isArrayOfArrays());
71     ASSERT(!isArray() || !isStruct());
72 }
73 
LinkedUniform(const sh::ShaderVariable & uniform)74 LinkedUniform::LinkedUniform(const sh::ShaderVariable &uniform)
75     : sh::ShaderVariable(uniform),
76       typeInfo(&GetUniformTypeInfo(type)),
77       bufferIndex(-1),
78       blockInfo(sh::kDefaultBlockMemberInfo)
79 {
80     ASSERT(!isArrayOfArrays());
81     ASSERT(!isArray() || !isStruct());
82 }
83 
LinkedUniform(const LinkedUniform & uniform)84 LinkedUniform::LinkedUniform(const LinkedUniform &uniform)
85     : sh::ShaderVariable(uniform),
86       ActiveVariable(uniform),
87       typeInfo(uniform.typeInfo),
88       bufferIndex(uniform.bufferIndex),
89       blockInfo(uniform.blockInfo),
90       outerArraySizes(uniform.outerArraySizes),
91       outerArrayOffset(uniform.outerArrayOffset)
92 {}
93 
operator =(const LinkedUniform & uniform)94 LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform)
95 {
96     sh::ShaderVariable::operator=(uniform);
97     ActiveVariable::operator    =(uniform);
98     typeInfo                    = uniform.typeInfo;
99     bufferIndex                 = uniform.bufferIndex;
100     blockInfo                   = uniform.blockInfo;
101     outerArraySizes             = uniform.outerArraySizes;
102     outerArrayOffset            = uniform.outerArrayOffset;
103     return *this;
104 }
105 
~LinkedUniform()106 LinkedUniform::~LinkedUniform() {}
107 
BufferVariable()108 BufferVariable::BufferVariable()
109     : bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo), topLevelArraySize(-1)
110 {}
111 
BufferVariable(GLenum typeIn,GLenum precisionIn,const std::string & nameIn,const std::vector<unsigned int> & arraySizesIn,const int bufferIndexIn,const sh::BlockMemberInfo & blockInfoIn)112 BufferVariable::BufferVariable(GLenum typeIn,
113                                GLenum precisionIn,
114                                const std::string &nameIn,
115                                const std::vector<unsigned int> &arraySizesIn,
116                                const int bufferIndexIn,
117                                const sh::BlockMemberInfo &blockInfoIn)
118     : bufferIndex(bufferIndexIn), blockInfo(blockInfoIn), topLevelArraySize(-1)
119 {
120     type       = typeIn;
121     precision  = precisionIn;
122     name       = nameIn;
123     arraySizes = arraySizesIn;
124 }
125 
~BufferVariable()126 BufferVariable::~BufferVariable() {}
127 
ShaderVariableBuffer()128 ShaderVariableBuffer::ShaderVariableBuffer() : binding(0), dataSize(0) {}
129 
130 ShaderVariableBuffer::ShaderVariableBuffer(const ShaderVariableBuffer &other) = default;
131 
~ShaderVariableBuffer()132 ShaderVariableBuffer::~ShaderVariableBuffer() {}
133 
numActiveVariables() const134 int ShaderVariableBuffer::numActiveVariables() const
135 {
136     return static_cast<int>(memberIndexes.size());
137 }
138 
InterfaceBlock()139 InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0) {}
140 
InterfaceBlock(const std::string & nameIn,const std::string & mappedNameIn,bool isArrayIn,unsigned int arrayElementIn,unsigned int firstFieldArraySizeIn,int bindingIn)141 InterfaceBlock::InterfaceBlock(const std::string &nameIn,
142                                const std::string &mappedNameIn,
143                                bool isArrayIn,
144                                unsigned int arrayElementIn,
145                                unsigned int firstFieldArraySizeIn,
146                                int bindingIn)
147     : name(nameIn),
148       mappedName(mappedNameIn),
149       isArray(isArrayIn),
150       arrayElement(arrayElementIn),
151       firstFieldArraySize(firstFieldArraySizeIn)
152 {
153     binding = bindingIn;
154 }
155 
nameWithArrayIndex() const156 std::string InterfaceBlock::nameWithArrayIndex() const
157 {
158     std::stringstream fullNameStr;
159     fullNameStr << name;
160     if (isArray)
161     {
162         fullNameStr << "[" << arrayElement << "]";
163     }
164 
165     return fullNameStr.str();
166 }
167 
mappedNameWithArrayIndex() const168 std::string InterfaceBlock::mappedNameWithArrayIndex() const
169 {
170     std::stringstream fullNameStr;
171     fullNameStr << mappedName;
172     if (isArray)
173     {
174         fullNameStr << "[" << arrayElement << "]";
175     }
176 
177     return fullNameStr.str();
178 }
179 }  // namespace gl
180