daniel@transgaming.com | 15186aa | 2012-12-20 21:08:23 +0000 | [diff] [blame] | 1 | //
|
| 2 | // Copyright (c) 2010-2012 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 "libGLESv2/utilities.h"
|
| 10 |
|
| 11 | namespace gl
|
| 12 | {
|
| 13 |
|
| 14 | Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize)
|
| 15 | : type(type), _name(_name), name(undecorate(_name)), arraySize(arraySize)
|
| 16 | {
|
| 17 | int bytes = gl::UniformInternalSize(type) * arraySize;
|
| 18 | data = new unsigned char[bytes];
|
| 19 | memset(data, 0, bytes);
|
| 20 | dirty = true;
|
| 21 | }
|
| 22 |
|
| 23 | Uniform::~Uniform()
|
| 24 | {
|
| 25 | delete[] data;
|
| 26 | }
|
| 27 |
|
| 28 | bool Uniform::isArray()
|
| 29 | {
|
| 30 | size_t dot = _name.find_last_of('.');
|
| 31 | if (dot == std::string::npos) dot = -1;
|
| 32 |
|
| 33 | return _name.compare(dot + 1, dot + 4, "ar_") == 0;
|
| 34 | }
|
| 35 |
|
| 36 | std::string Uniform::undecorate(const std::string &_name)
|
| 37 | {
|
| 38 | std::string name = _name;
|
| 39 |
|
| 40 | // Remove any structure field decoration
|
| 41 | size_t pos = 0;
|
| 42 | while ((pos = name.find("._", pos)) != std::string::npos)
|
| 43 | {
|
| 44 | name.replace(pos, 2, ".");
|
| 45 | }
|
| 46 |
|
| 47 | // Remove the leading decoration
|
| 48 | if (name[0] == '_')
|
| 49 | {
|
| 50 | return name.substr(1);
|
| 51 | }
|
| 52 | else if (name.compare(0, 3, "ar_") == 0)
|
| 53 | {
|
| 54 | return name.substr(3);
|
| 55 | }
|
| 56 |
|
| 57 | return name;
|
| 58 | }
|
| 59 |
|
| 60 | }
|