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 11namespace gl 12{ 13 14LinkedUniform::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 40LinkedUniform::~LinkedUniform() 41{ 42 delete[] data; 43} 44 45bool LinkedUniform::isArray() const 46{ 47 return arraySize > 0; 48} 49 50unsigned int LinkedUniform::elementCount() const 51{ 52 return arraySize > 0 ? arraySize : 1; 53} 54 55bool LinkedUniform::isReferencedByVertexShader() const 56{ 57 return vsRegisterIndex != GL_INVALID_INDEX; 58} 59 60bool LinkedUniform::isReferencedByFragmentShader() const 61{ 62 return psRegisterIndex != GL_INVALID_INDEX; 63} 64 65bool LinkedUniform::isInDefaultBlock() const 66{ 67 return blockIndex == -1; 68} 69 70size_t LinkedUniform::dataSize() const 71{ 72 ASSERT(type != GL_STRUCT_ANGLEX); 73 return VariableInternalSize(type) * elementCount(); 74} 75 76bool LinkedUniform::isSampler() const 77{ 78 return IsSampler(type); 79} 80 81UniformBlock::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 90bool UniformBlock::isArrayElement() const 91{ 92 return elementIndex != GL_INVALID_INDEX; 93} 94 95bool UniformBlock::isReferencedByVertexShader() const 96{ 97 return vsRegisterIndex != GL_INVALID_INDEX; 98} 99 100bool UniformBlock::isReferencedByFragmentShader() const 101{ 102 return psRegisterIndex != GL_INVALID_INDEX; 103} 104 105} 106