1 //
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.
5 //
6
7 #include "libGLESv2/Uniform.h"
8
9 #include "common/utilities.h"
10
11 namespace gl
12 {
13
LinkedUniform(GLenum type,GLenum precision,const std::string & name,unsigned int arraySize,const int blockIndex,const sh::BlockMemberInfo & blockInfo)14 LinkedUniform::LinkedUniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize,
15 const int blockIndex, const sh::BlockMemberInfo &blockInfo)
16 : type(type),
17 precision(precision),
18 name(name),
19 arraySize(arraySize),
20 blockIndex(blockIndex),
21 blockInfo(blockInfo),
22 data(NULL),
23 dirty(true),
24 psRegisterIndex(GL_INVALID_INDEX),
25 vsRegisterIndex(GL_INVALID_INDEX),
26 registerCount(0),
27 registerElement(0)
28 {
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())
32 {
33 size_t bytes = dataSize();
34 data = new unsigned char[bytes];
35 memset(data, 0, bytes);
36 registerCount = VariableRowCount(type) * elementCount();
37 }
38 }
39
~LinkedUniform()40 LinkedUniform::~LinkedUniform()
41 {
42 delete[] data;
43 }
44
isArray() const45 bool LinkedUniform::isArray() const
46 {
47 return arraySize > 0;
48 }
49
elementCount() const50 unsigned int LinkedUniform::elementCount() const
51 {
52 return arraySize > 0 ? arraySize : 1;
53 }
54
isReferencedByVertexShader() const55 bool LinkedUniform::isReferencedByVertexShader() const
56 {
57 return vsRegisterIndex != GL_INVALID_INDEX;
58 }
59
isReferencedByFragmentShader() const60 bool LinkedUniform::isReferencedByFragmentShader() const
61 {
62 return psRegisterIndex != GL_INVALID_INDEX;
63 }
64
isInDefaultBlock() const65 bool LinkedUniform::isInDefaultBlock() const
66 {
67 return blockIndex == -1;
68 }
69
dataSize() const70 size_t LinkedUniform::dataSize() const
71 {
72 ASSERT(type != GL_STRUCT_ANGLEX);
73 return VariableInternalSize(type) * elementCount();
74 }
75
isSampler() const76 bool LinkedUniform::isSampler() const
77 {
78 return IsSampler(type);
79 }
80
UniformBlock(const std::string & name,unsigned int elementIndex,unsigned int dataSize)81 UniformBlock::UniformBlock(const std::string &name, unsigned int elementIndex, unsigned int dataSize)
82 : name(name),
83 elementIndex(elementIndex),
84 dataSize(dataSize),
85 psRegisterIndex(GL_INVALID_INDEX),
86 vsRegisterIndex(GL_INVALID_INDEX)
87 {
88 }
89
isArrayElement() const90 bool UniformBlock::isArrayElement() const
91 {
92 return elementIndex != GL_INVALID_INDEX;
93 }
94
isReferencedByVertexShader() const95 bool UniformBlock::isReferencedByVertexShader() const
96 {
97 return vsRegisterIndex != GL_INVALID_INDEX;
98 }
99
isReferencedByFragmentShader() const100 bool UniformBlock::isReferencedByFragmentShader() const
101 {
102 return psRegisterIndex != GL_INVALID_INDEX;
103 }
104
105 }
106