Implements glGetUniform

TRAC #11647 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@123 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 9a95e2bb
...@@ -692,6 +692,117 @@ bool Program::setUniform4iv(GLint location, GLsizei count, const GLint *v) ...@@ -692,6 +692,117 @@ bool Program::setUniform4iv(GLint location, GLsizei count, const GLint *v)
return true; return true;
} }
bool Program::getUniformfv(GLint location, GLfloat *params)
{
if (location < 0 || location >= (int)mUniforms.size())
{
return false;
}
unsigned int count = 0;
switch (mUniforms[location]->type)
{
case GL_FLOAT:
case GL_BOOL:
count = 1;
break;
case GL_FLOAT_VEC2:
case GL_BOOL_VEC2:
count = 2;
break;
case GL_FLOAT_VEC3:
case GL_BOOL_VEC3:
count = 3;
break;
case GL_FLOAT_VEC4:
case GL_BOOL_VEC4:
case GL_FLOAT_MAT2:
count = 4;
break;
case GL_FLOAT_MAT3:
count = 9;
break;
case GL_FLOAT_MAT4:
count = 16;
break;
default:
return false;
}
if (mUniforms[location]->type == GL_BOOL || mUniforms[location]->type == GL_BOOL_VEC2 ||
mUniforms[location]->type == GL_BOOL_VEC3 || mUniforms[location]->type == GL_BOOL_VEC4)
{
GLboolean *boolParams = mUniforms[location]->data;
for (unsigned int i = 0; i < count; ++i)
{
if (boolParams[i] == GL_FALSE)
params[i] = 0.0f;
else
params[i] = 1.0f;
}
}
else
{
memcpy(params, mUniforms[location]->data, count * sizeof(GLfloat));
}
return true;
}
bool Program::getUniformiv(GLint location, GLint *params)
{
if (location < 0 || location >= (int)mUniforms.size())
{
return false;
}
unsigned int count = 0;
switch (mUniforms[location]->type)
{
case GL_INT:
case GL_BOOL:
count = 1;
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
count = 2;
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
count = 3;
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
count = 4;
break;
default:
return false;
}
if (mUniforms[location]->type == GL_BOOL || mUniforms[location]->type == GL_BOOL_VEC2 ||
mUniforms[location]->type == GL_BOOL_VEC3 || mUniforms[location]->type == GL_BOOL_VEC4)
{
GLboolean *boolParams = mUniforms[location]->data;
for (unsigned int i = 0; i < count; ++i)
{
if (boolParams[i] == GL_FALSE)
params[i] = 0;
else
params[i] = 1;
}
}
else
{
memcpy(params, mUniforms[location]->data, count * sizeof(GLint));
}
return true;
}
// Applies all the uniforms set for this program object to the Direct3D 9 device // Applies all the uniforms set for this program object to the Direct3D 9 device
void Program::applyUniforms() void Program::applyUniforms()
{ {
......
...@@ -69,6 +69,9 @@ class Program ...@@ -69,6 +69,9 @@ class Program
bool setUniform3iv(GLint location, GLsizei count, const GLint *v); bool setUniform3iv(GLint location, GLsizei count, const GLint *v);
bool setUniform4iv(GLint location, GLsizei count, const GLint *v); bool setUniform4iv(GLint location, GLsizei count, const GLint *v);
bool getUniformfv(GLint location, GLfloat *params);
bool getUniformiv(GLint location, GLint *params);
void applyUniforms(); void applyUniforms();
void link(); void link();
......
...@@ -2286,7 +2286,27 @@ void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params) ...@@ -2286,7 +2286,27 @@ void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
try try
{ {
UNIMPLEMENTED(); // FIXME gl::Context *context = gl::getContext();
if (context)
{
if (program == 0)
{
return error(GL_INVALID_VALUE);
}
gl::Program *programObject = context->getProgram(program);
if (!programObject || !programObject->isLinked())
{
return error(GL_INVALID_OPERATION);
}
if (!programObject->getUniformfv(location, params))
{
return error(GL_INVALID_OPERATION);
}
}
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
{ {
...@@ -2300,7 +2320,32 @@ void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params) ...@@ -2300,7 +2320,32 @@ void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
try try
{ {
UNIMPLEMENTED(); // FIXME gl::Context *context = gl::getContext();
if (context)
{
if (program == 0)
{
return error(GL_INVALID_VALUE);
}
gl::Program *programObject = context->getProgram(program);
if (!programObject || !programObject->isLinked())
{
return error(GL_INVALID_OPERATION);
}
if (!programObject)
{
return error(GL_INVALID_OPERATION);
}
if (!programObject->getUniformiv(location, params))
{
return error(GL_INVALID_OPERATION);
}
}
} }
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