• 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), bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo)
44 {}
45 
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)46 LinkedUniform::LinkedUniform(GLenum typeIn,
47                              GLenum precisionIn,
48                              const std::string &nameIn,
49                              const std::vector<unsigned int> &arraySizesIn,
50                              const int bindingIn,
51                              const int offsetIn,
52                              const int locationIn,
53                              const int bufferIndexIn,
54                              const sh::BlockMemberInfo &blockInfoIn)
55     : typeInfo(&GetUniformTypeInfo(typeIn)), bufferIndex(bufferIndexIn), blockInfo(blockInfoIn)
56 {
57     type       = typeIn;
58     precision  = precisionIn;
59     name       = nameIn;
60     arraySizes = arraySizesIn;
61     binding    = bindingIn;
62     offset     = offsetIn;
63     location   = locationIn;
64     ASSERT(!isArrayOfArrays());
65     ASSERT(!isArray() || !isStruct());
66 }
67 
LinkedUniform(const sh::ShaderVariable & uniform)68 LinkedUniform::LinkedUniform(const sh::ShaderVariable &uniform)
69     : sh::ShaderVariable(uniform),
70       typeInfo(&GetUniformTypeInfo(type)),
71       bufferIndex(-1),
72       blockInfo(sh::kDefaultBlockMemberInfo)
73 {
74     ASSERT(!isArrayOfArrays());
75     ASSERT(!isArray() || !isStruct());
76 }
77 
LinkedUniform(const LinkedUniform & uniform)78 LinkedUniform::LinkedUniform(const LinkedUniform &uniform)
79     : sh::ShaderVariable(uniform),
80       ActiveVariable(uniform),
81       typeInfo(uniform.typeInfo),
82       bufferIndex(uniform.bufferIndex),
83       blockInfo(uniform.blockInfo),
84       outerArraySizes(uniform.outerArraySizes)
85 {}
86 
operator =(const LinkedUniform & uniform)87 LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform)
88 {
89     sh::ShaderVariable::operator=(uniform);
90     ActiveVariable::operator    =(uniform);
91     typeInfo                    = uniform.typeInfo;
92     bufferIndex                 = uniform.bufferIndex;
93     blockInfo                   = uniform.blockInfo;
94     outerArraySizes             = uniform.outerArraySizes;
95     return *this;
96 }
97 
~LinkedUniform()98 LinkedUniform::~LinkedUniform() {}
99 
BufferVariable()100 BufferVariable::BufferVariable()
101     : bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo), topLevelArraySize(-1)
102 {}
103 
BufferVariable(GLenum typeIn,GLenum precisionIn,const std::string & nameIn,const std::vector<unsigned int> & arraySizesIn,const int bufferIndexIn,const sh::BlockMemberInfo & blockInfoIn)104 BufferVariable::BufferVariable(GLenum typeIn,
105                                GLenum precisionIn,
106                                const std::string &nameIn,
107                                const std::vector<unsigned int> &arraySizesIn,
108                                const int bufferIndexIn,
109                                const sh::BlockMemberInfo &blockInfoIn)
110     : bufferIndex(bufferIndexIn), blockInfo(blockInfoIn), topLevelArraySize(-1)
111 {
112     type       = typeIn;
113     precision  = precisionIn;
114     name       = nameIn;
115     arraySizes = arraySizesIn;
116 }
117 
~BufferVariable()118 BufferVariable::~BufferVariable() {}
119 
ShaderVariableBuffer()120 ShaderVariableBuffer::ShaderVariableBuffer() : binding(0), dataSize(0) {}
121 
122 ShaderVariableBuffer::ShaderVariableBuffer(const ShaderVariableBuffer &other) = default;
123 
~ShaderVariableBuffer()124 ShaderVariableBuffer::~ShaderVariableBuffer() {}
125 
numActiveVariables() const126 int ShaderVariableBuffer::numActiveVariables() const
127 {
128     return static_cast<int>(memberIndexes.size());
129 }
130 
InterfaceBlock()131 InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0) {}
132 
InterfaceBlock(const std::string & nameIn,const std::string & mappedNameIn,bool isArrayIn,unsigned int arrayElementIn,unsigned int firstFieldArraySizeIn,int bindingIn)133 InterfaceBlock::InterfaceBlock(const std::string &nameIn,
134                                const std::string &mappedNameIn,
135                                bool isArrayIn,
136                                unsigned int arrayElementIn,
137                                unsigned int firstFieldArraySizeIn,
138                                int bindingIn)
139     : name(nameIn),
140       mappedName(mappedNameIn),
141       isArray(isArrayIn),
142       arrayElement(arrayElementIn),
143       firstFieldArraySize(firstFieldArraySizeIn)
144 {
145     binding = bindingIn;
146 }
147 
nameWithArrayIndex() const148 std::string InterfaceBlock::nameWithArrayIndex() const
149 {
150     std::stringstream fullNameStr;
151     fullNameStr << name;
152     if (isArray)
153     {
154         fullNameStr << "[" << arrayElement << "]";
155     }
156 
157     return fullNameStr.str();
158 }
159 
mappedNameWithArrayIndex() const160 std::string InterfaceBlock::mappedNameWithArrayIndex() const
161 {
162     std::stringstream fullNameStr;
163     fullNameStr << mappedName;
164     if (isArray)
165     {
166         fullNameStr << "[" << arrayElement << "]";
167     }
168 
169     return fullNameStr.str();
170 }
171 }  // namespace gl
172