blob: b7f2e62027ffe7d0d3c25b15a0b88d15b386a2d9 [file] [log] [blame]
daniel@transgaming.com15186aa2012-12-20 21:08:23 +00001//
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
11namespace gl
12{
13
14Uniform::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
23Uniform::~Uniform()
24{
25 delete[] data;
26}
27
28bool 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
36std::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}