blob: 3ee7769e0064e0fcb269e47d3694dd26a381c97e [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
shannonwoods@chromium.org7e0904d2013-05-30 00:06:45 +00002//
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
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000010#include "common/utilities.h"
shannonwoods@chromium.org7e0904d2013-05-30 00:06:45 +000011
12namespace gl
13{
14
shannonwoods@chromium.orgd7784172013-05-30 00:07:03 +000015Uniform::Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize, 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)
shannonwoods@chromium.org7e0904d2013-05-30 00:06:45 +000027{
shannonwoods@chromium.orgd7784172013-05-30 00:07:03 +000028 // We use data storage for default block uniforms to cache values that are sent to D3D during rendering
29 // Uniform blocks/buffers are treated separately by the Renderer (ES3 path only)
30 if (isInDefaultBlock())
31 {
32 size_t bytes = UniformInternalSize(type) * elementCount();
33 data = new unsigned char[bytes];
34 memset(data, 0, bytes);
35 registerCount = VariableRowCount(type) * elementCount();
36 }
shannonwoods@chromium.org7e0904d2013-05-30 00:06:45 +000037}
38
39Uniform::~Uniform()
40{
41 delete[] data;
42}
43
44bool Uniform::isArray() const
45{
46 return arraySize > 0;
47}
48
49unsigned int Uniform::elementCount() const
50{
51 return arraySize > 0 ? arraySize : 1;
52}
53
shannonwoods@chromium.org38676dc2013-05-30 00:06:52 +000054bool Uniform::isReferencedByVertexShader() const
55{
56 return vsRegisterIndex != GL_INVALID_INDEX;
57}
58
59bool Uniform::isReferencedByFragmentShader() const
60{
61 return psRegisterIndex != GL_INVALID_INDEX;
62}
63
shannonwoods@chromium.orgd7784172013-05-30 00:07:03 +000064bool Uniform::isInDefaultBlock() const
65{
66 return blockIndex == -1;
67}
68
69UniformBlock::UniformBlock(const std::string &name, unsigned int elementIndex, unsigned int dataSize)
70 : name(name),
71 elementIndex(elementIndex),
72 dataSize(dataSize),
73 psRegisterIndex(GL_INVALID_INDEX),
74 vsRegisterIndex(GL_INVALID_INDEX)
75{
76}
77
78bool UniformBlock::isArrayElement() const
79{
80 return elementIndex != GL_INVALID_INDEX;
81}
82
83bool UniformBlock::isReferencedByVertexShader() const
84{
85 return vsRegisterIndex != GL_INVALID_INDEX;
86}
87
88bool UniformBlock::isReferencedByFragmentShader() const
89{
90 return psRegisterIndex != GL_INVALID_INDEX;
91}
92
shannonwoods@chromium.org7e0904d2013-05-30 00:06:45 +000093}