Implement GetUniformIndices, for retrieving active uniform indices from their names.

TRAC #22865 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2293 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 0329988b
...@@ -247,6 +247,40 @@ GLint ProgramBinary::getUniformLocation(std::string name) ...@@ -247,6 +247,40 @@ GLint ProgramBinary::getUniformLocation(std::string name)
return -1; return -1;
} }
GLuint ProgramBinary::getUniformIndex(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);
}
// The app is not allowed to specify array indices other than 0 for arrays of basic types
if (subscript != 0 && subscript != GL_INVALID_INDEX)
{
return GL_INVALID_INDEX;
}
unsigned int numUniforms = mUniforms.size();
for (unsigned int index = 0; index < numUniforms; index++)
{
if (mUniforms[index]->name == name)
{
if (mUniforms[index]->isArray() || subscript == GL_INVALID_INDEX)
{
return index;
}
}
}
return GL_INVALID_INDEX;
}
template <typename T> template <typename T>
bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType) bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType)
{ {
......
...@@ -77,6 +77,7 @@ class ProgramBinary : public RefCountObject ...@@ -77,6 +77,7 @@ class ProgramBinary : public RefCountObject
bool usesGeometryShader() const; bool usesGeometryShader() const;
GLint getUniformLocation(std::string name); GLint getUniformLocation(std::string name);
GLuint getUniformIndex(std::string name);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
......
...@@ -9532,9 +9532,42 @@ void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const G ...@@ -9532,9 +9532,42 @@ void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const G
{ {
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
}
UNIMPLEMENTED(); if (uniformCount < 0)
{
return gl::error(GL_INVALID_VALUE);
}
gl::Program *programObject = context->getProgram(program);
if (!programObject)
{
if (context->getShader(program))
{
return gl::error(GL_INVALID_OPERATION);
}
else
{
return gl::error(GL_INVALID_VALUE);
}
}
gl::ProgramBinary *programBinary = programObject->getProgramBinary();
if (!programObject->isLinked() || !programBinary)
{
for (int uniformId = 0; uniformId < uniformCount; uniformId++)
{
uniformIndices[uniformId] = GL_INVALID_INDEX;
}
}
else
{
for (int uniformId = 0; uniformId < uniformCount; uniformId++)
{
uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
}
}
}
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
{ {
......
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