Add a helper routine to parse out uniform array indices.

TRAC #22858 Signed-off-by: Geoff Lang Signed-off-by: Nicolas Capens Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2303 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f2d76f80
...@@ -35,6 +35,27 @@ std::string str(int i) ...@@ -35,6 +35,27 @@ std::string str(int i)
return buffer; return buffer;
} }
namespace
{
unsigned int parseAndStripArrayIndex(std::string* name)
{
unsigned int subscript = GL_INVALID_INDEX;
// Strip any trailing array operator and retrieve the subscript
size_t open = name->find_last_of('[');
size_t close = name->find_last_of(']');
if (open != std::string::npos && close == name->length() - 1)
{
subscript = atoi(name->substr(open + 1).c_str());
name->erase(open);
}
return subscript;
}
}
UniformLocation::UniformLocation(const std::string &name, unsigned int element, unsigned int index) UniformLocation::UniformLocation(const std::string &name, unsigned int element, unsigned int index)
: name(name), element(element), index(index) : name(name), element(element), index(index)
{ {
...@@ -223,16 +244,7 @@ TextureType ProgramBinary::getSamplerTextureType(SamplerType type, unsigned int ...@@ -223,16 +244,7 @@ TextureType ProgramBinary::getSamplerTextureType(SamplerType type, unsigned int
GLint ProgramBinary::getUniformLocation(std::string name) GLint ProgramBinary::getUniformLocation(std::string name)
{ {
unsigned int subscript = GL_INVALID_INDEX; unsigned int subscript = parseAndStripArrayIndex(&name);
// Strip any trailing array operator and retrieve the subscript
size_t open = name.find_last_of('[');
size_t close = name.find_last_of(']');
if (open != std::string::npos && close == name.length() - 1)
{
subscript = atoi(name.substr(open + 1).c_str());
name.erase(open);
}
unsigned int numUniforms = mUniformIndex.size(); unsigned int numUniforms = mUniformIndex.size();
for (unsigned int location = 0; location < numUniforms; location++) for (unsigned int location = 0; location < numUniforms; location++)
...@@ -255,16 +267,7 @@ GLint ProgramBinary::getUniformLocation(std::string name) ...@@ -255,16 +267,7 @@ GLint ProgramBinary::getUniformLocation(std::string name)
GLuint ProgramBinary::getUniformIndex(std::string name) GLuint ProgramBinary::getUniformIndex(std::string name)
{ {
unsigned int subscript = GL_INVALID_INDEX; unsigned int subscript = parseAndStripArrayIndex(&name);
// Strip any trailing array operator and retrieve the subscript
size_t open = name.find_last_of('[');
size_t close = name.find_last_of(']');
if (open != std::string::npos && close == name.length() - 1)
{
subscript = atoi(name.substr(open + 1).c_str());
name.erase(open);
}
// The app is not allowed to specify array indices other than 0 for arrays of basic types // The app is not allowed to specify array indices other than 0 for arrays of basic types
if (subscript != 0 && subscript != GL_INVALID_INDEX) if (subscript != 0 && subscript != GL_INVALID_INDEX)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment