Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / Uniform.cpp
1 #include "precompiled.h"
2 //
3 // Copyright (c) 2010-2013 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
6 //
7
8 #include "libGLESv2/Uniform.h"
9
10 #include "common/utilities.h"
11
12 namespace gl
13 {
14
15 LinkedUniform::LinkedUniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize,
16                              const int blockIndex, const sh::BlockMemberInfo &blockInfo)
17     : type(type),
18       precision(precision),
19       name(name),
20       arraySize(arraySize),
21       blockIndex(blockIndex),
22       blockInfo(blockInfo),
23       data(NULL),
24       dirty(true),
25       psRegisterIndex(GL_INVALID_INDEX),
26       vsRegisterIndex(GL_INVALID_INDEX),
27       registerCount(0),
28       registerElement(0)
29 {
30     // We use data storage for default block uniforms to cache values that are sent to D3D during rendering
31     // Uniform blocks/buffers are treated separately by the Renderer (ES3 path only)
32     if (isInDefaultBlock())
33     {
34         size_t bytes = dataSize();
35         data = new unsigned char[bytes];
36         memset(data, 0, bytes);
37         registerCount = VariableRowCount(type) * elementCount();
38     }
39 }
40
41 LinkedUniform::~LinkedUniform()
42 {
43     delete[] data;
44 }
45
46 bool LinkedUniform::isArray() const
47 {
48     return arraySize > 0;
49 }
50
51 unsigned int LinkedUniform::elementCount() const
52 {
53     return arraySize > 0 ? arraySize : 1;
54 }
55
56 bool LinkedUniform::isReferencedByVertexShader() const
57 {
58     return vsRegisterIndex != GL_INVALID_INDEX;
59 }
60
61 bool LinkedUniform::isReferencedByFragmentShader() const
62 {
63     return psRegisterIndex != GL_INVALID_INDEX;
64 }
65
66 bool LinkedUniform::isInDefaultBlock() const
67 {
68     return blockIndex == -1;
69 }
70
71 size_t LinkedUniform::dataSize() const
72 {
73     ASSERT(type != GL_STRUCT_ANGLEX);
74     return VariableInternalSize(type) * elementCount();
75 }
76
77 bool LinkedUniform::isSampler() const
78 {
79     return IsSampler(type);
80 }
81
82 UniformBlock::UniformBlock(const std::string &name, unsigned int elementIndex, unsigned int dataSize)
83     : name(name),
84       elementIndex(elementIndex),
85       dataSize(dataSize),
86       psRegisterIndex(GL_INVALID_INDEX),
87       vsRegisterIndex(GL_INVALID_INDEX)
88 {
89 }
90
91 bool UniformBlock::isArrayElement() const
92 {
93     return elementIndex != GL_INVALID_INDEX;
94 }
95
96 bool UniformBlock::isReferencedByVertexShader() const
97 {
98     return vsRegisterIndex != GL_INVALID_INDEX;
99 }
100
101 bool UniformBlock::isReferencedByFragmentShader() const
102 {
103     return psRegisterIndex != GL_INVALID_INDEX;
104 }
105
106 }