shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
shannonwoods@chromium.org | 7e0904d | 2013-05-30 00:06:45 +0000 | [diff] [blame] | 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 | |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame^] | 10 | #include "common/utilities.h" |
shannonwoods@chromium.org | 7e0904d | 2013-05-30 00:06:45 +0000 | [diff] [blame] | 11 | |
| 12 | namespace gl |
| 13 | { |
| 14 | |
shannonwoods@chromium.org | d778417 | 2013-05-30 00:07:03 +0000 | [diff] [blame] | 15 | Uniform::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.org | 7e0904d | 2013-05-30 00:06:45 +0000 | [diff] [blame] | 27 | { |
shannonwoods@chromium.org | d778417 | 2013-05-30 00:07:03 +0000 | [diff] [blame] | 28 | // 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.org | 7e0904d | 2013-05-30 00:06:45 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | Uniform::~Uniform() |
| 40 | { |
| 41 | delete[] data; |
| 42 | } |
| 43 | |
| 44 | bool Uniform::isArray() const |
| 45 | { |
| 46 | return arraySize > 0; |
| 47 | } |
| 48 | |
| 49 | unsigned int Uniform::elementCount() const |
| 50 | { |
| 51 | return arraySize > 0 ? arraySize : 1; |
| 52 | } |
| 53 | |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 54 | bool Uniform::isReferencedByVertexShader() const |
| 55 | { |
| 56 | return vsRegisterIndex != GL_INVALID_INDEX; |
| 57 | } |
| 58 | |
| 59 | bool Uniform::isReferencedByFragmentShader() const |
| 60 | { |
| 61 | return psRegisterIndex != GL_INVALID_INDEX; |
| 62 | } |
| 63 | |
shannonwoods@chromium.org | d778417 | 2013-05-30 00:07:03 +0000 | [diff] [blame] | 64 | bool Uniform::isInDefaultBlock() const |
| 65 | { |
| 66 | return blockIndex == -1; |
| 67 | } |
| 68 | |
| 69 | UniformBlock::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 | |
| 78 | bool UniformBlock::isArrayElement() const |
| 79 | { |
| 80 | return elementIndex != GL_INVALID_INDEX; |
| 81 | } |
| 82 | |
| 83 | bool UniformBlock::isReferencedByVertexShader() const |
| 84 | { |
| 85 | return vsRegisterIndex != GL_INVALID_INDEX; |
| 86 | } |
| 87 | |
| 88 | bool UniformBlock::isReferencedByFragmentShader() const |
| 89 | { |
| 90 | return psRegisterIndex != GL_INVALID_INDEX; |
| 91 | } |
| 92 | |
shannonwoods@chromium.org | 7e0904d | 2013-05-30 00:06:45 +0000 | [diff] [blame] | 93 | } |