2 // Copyright (c) 2010-2013 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.
7 #include "libGLESv2/Uniform.h"
9 #include "common/utilities.h"
14 LinkedUniform::LinkedUniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize,
15 const int blockIndex, const sh::BlockMemberInfo &blockInfo)
20 blockIndex(blockIndex),
24 psRegisterIndex(GL_INVALID_INDEX),
25 vsRegisterIndex(GL_INVALID_INDEX),
29 // We use data storage for default block uniforms to cache values that are sent to D3D during rendering
30 // Uniform blocks/buffers are treated separately by the Renderer (ES3 path only)
31 if (isInDefaultBlock())
33 size_t bytes = dataSize();
34 data = new unsigned char[bytes];
35 memset(data, 0, bytes);
36 registerCount = VariableRowCount(type) * elementCount();
40 LinkedUniform::~LinkedUniform()
45 bool LinkedUniform::isArray() const
50 unsigned int LinkedUniform::elementCount() const
52 return arraySize > 0 ? arraySize : 1;
55 bool LinkedUniform::isReferencedByVertexShader() const
57 return vsRegisterIndex != GL_INVALID_INDEX;
60 bool LinkedUniform::isReferencedByFragmentShader() const
62 return psRegisterIndex != GL_INVALID_INDEX;
65 bool LinkedUniform::isInDefaultBlock() const
67 return blockIndex == -1;
70 size_t LinkedUniform::dataSize() const
72 ASSERT(type != GL_STRUCT_ANGLEX);
73 return VariableInternalSize(type) * elementCount();
76 bool LinkedUniform::isSampler() const
78 return IsSampler(type);
81 UniformBlock::UniformBlock(const std::string &name, unsigned int elementIndex, unsigned int dataSize)
83 elementIndex(elementIndex),
85 psRegisterIndex(GL_INVALID_INDEX),
86 vsRegisterIndex(GL_INVALID_INDEX)
90 bool UniformBlock::isArrayElement() const
92 return elementIndex != GL_INVALID_INDEX;
95 bool UniformBlock::isReferencedByVertexShader() const
97 return vsRegisterIndex != GL_INVALID_INDEX;
100 bool UniformBlock::isReferencedByFragmentShader() const
102 return psRegisterIndex != GL_INVALID_INDEX;