• 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::Uniform & uniform)68 LinkedUniform::LinkedUniform(const sh::Uniform &uniform)
69     : sh::Uniform(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::Uniform(uniform),
80       ActiveVariable(uniform),
81       typeInfo(uniform.typeInfo),
82       bufferIndex(uniform.bufferIndex),
83       blockInfo(uniform.blockInfo)
84 {}
85 
operator =(const LinkedUniform & uniform)86 LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform)
87 {
88     sh::Uniform::operator   =(uniform);
89     ActiveVariable::operator=(uniform);
90     typeInfo                = uniform.typeInfo;
91     bufferIndex             = uniform.bufferIndex;
92     blockInfo               = uniform.blockInfo;
93     return *this;
94 }
95 
~LinkedUniform()96 LinkedUniform::~LinkedUniform() {}
97 
BufferVariable()98 BufferVariable::BufferVariable()
99     : bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo), topLevelArraySize(-1)
100 {}
101 
BufferVariable(GLenum typeIn,GLenum precisionIn,const std::string & nameIn,const std::vector<unsigned int> & arraySizesIn,const int bufferIndexIn,const sh::BlockMemberInfo & blockInfoIn)102 BufferVariable::BufferVariable(GLenum typeIn,
103                                GLenum precisionIn,
104                                const std::string &nameIn,
105                                const std::vector<unsigned int> &arraySizesIn,
106                                const int bufferIndexIn,
107                                const sh::BlockMemberInfo &blockInfoIn)
108     : bufferIndex(bufferIndexIn), blockInfo(blockInfoIn), topLevelArraySize(-1)
109 {
110     type       = typeIn;
111     precision  = precisionIn;
112     name       = nameIn;
113     arraySizes = arraySizesIn;
114 }
115 
~BufferVariable()116 BufferVariable::~BufferVariable() {}
117 
ShaderVariableBuffer()118 ShaderVariableBuffer::ShaderVariableBuffer() : binding(0), dataSize(0) {}
119 
120 ShaderVariableBuffer::ShaderVariableBuffer(const ShaderVariableBuffer &other) = default;
121 
~ShaderVariableBuffer()122 ShaderVariableBuffer::~ShaderVariableBuffer() {}
123 
numActiveVariables() const124 int ShaderVariableBuffer::numActiveVariables() const
125 {
126     return static_cast<int>(memberIndexes.size());
127 }
128 
InterfaceBlock()129 InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0) {}
130 
InterfaceBlock(const std::string & nameIn,const std::string & mappedNameIn,bool isArrayIn,unsigned int arrayElementIn,int bindingIn)131 InterfaceBlock::InterfaceBlock(const std::string &nameIn,
132                                const std::string &mappedNameIn,
133                                bool isArrayIn,
134                                unsigned int arrayElementIn,
135                                int bindingIn)
136     : name(nameIn), mappedName(mappedNameIn), isArray(isArrayIn), arrayElement(arrayElementIn)
137 {
138     binding = bindingIn;
139 }
140 
nameWithArrayIndex() const141 std::string InterfaceBlock::nameWithArrayIndex() const
142 {
143     std::stringstream fullNameStr;
144     fullNameStr << name;
145     if (isArray)
146     {
147         fullNameStr << "[" << arrayElement << "]";
148     }
149 
150     return fullNameStr.str();
151 }
152 
mappedNameWithArrayIndex() const153 std::string InterfaceBlock::mappedNameWithArrayIndex() const
154 {
155     std::stringstream fullNameStr;
156     fullNameStr << mappedName;
157     if (isArray)
158     {
159         fullNameStr << "[" << arrayElement << "]";
160     }
161 
162     return fullNameStr.str();
163 }
164 }  // namespace gl
165