Implemented support for DX11 uniform arrays.

TRAC #22239 Signed-off-by: Daniel Koch Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1629 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 873f28aa
...@@ -237,12 +237,12 @@ bool ProgramBinary::setUniform1fv(GLint location, GLsizei count, const GLfloat* ...@@ -237,12 +237,12 @@ bool ProgramBinary::setUniform1fv(GLint location, GLsizei count, const GLfloat*
if (targetUniform->type == GL_FLOAT) if (targetUniform->type == GL_FLOAT)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
...@@ -258,12 +258,12 @@ bool ProgramBinary::setUniform1fv(GLint location, GLsizei count, const GLfloat* ...@@ -258,12 +258,12 @@ bool ProgramBinary::setUniform1fv(GLint location, GLsizei count, const GLfloat*
} }
else if (targetUniform->type == GL_BOOL) else if (targetUniform->type == GL_BOOL)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
...@@ -298,12 +298,12 @@ bool ProgramBinary::setUniform2fv(GLint location, GLsizei count, const GLfloat * ...@@ -298,12 +298,12 @@ bool ProgramBinary::setUniform2fv(GLint location, GLsizei count, const GLfloat *
if (targetUniform->type == GL_FLOAT_VEC2) if (targetUniform->type == GL_FLOAT_VEC2)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
...@@ -319,12 +319,12 @@ bool ProgramBinary::setUniform2fv(GLint location, GLsizei count, const GLfloat * ...@@ -319,12 +319,12 @@ bool ProgramBinary::setUniform2fv(GLint location, GLsizei count, const GLfloat *
} }
else if (targetUniform->type == GL_BOOL_VEC2) else if (targetUniform->type == GL_BOOL_VEC2)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
...@@ -360,12 +360,12 @@ bool ProgramBinary::setUniform3fv(GLint location, GLsizei count, const GLfloat * ...@@ -360,12 +360,12 @@ bool ProgramBinary::setUniform3fv(GLint location, GLsizei count, const GLfloat *
if (targetUniform->type == GL_FLOAT_VEC3) if (targetUniform->type == GL_FLOAT_VEC3)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
...@@ -381,12 +381,12 @@ bool ProgramBinary::setUniform3fv(GLint location, GLsizei count, const GLfloat * ...@@ -381,12 +381,12 @@ bool ProgramBinary::setUniform3fv(GLint location, GLsizei count, const GLfloat *
} }
else if (targetUniform->type == GL_BOOL_VEC3) else if (targetUniform->type == GL_BOOL_VEC3)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i) for (int i = 0; i < count * 3; ++i)
...@@ -421,24 +421,24 @@ bool ProgramBinary::setUniform4fv(GLint location, GLsizei count, const GLfloat * ...@@ -421,24 +421,24 @@ bool ProgramBinary::setUniform4fv(GLint location, GLsizei count, const GLfloat *
if (targetUniform->type == GL_FLOAT_VEC4) if (targetUniform->type == GL_FLOAT_VEC4)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 4, memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 4,
v, 4 * sizeof(GLfloat) * count); v, 4 * sizeof(GLfloat) * count);
} }
else if (targetUniform->type == GL_BOOL_VEC4) else if (targetUniform->type == GL_BOOL_VEC4)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i) for (int i = 0; i < count * 4; ++i)
...@@ -507,12 +507,12 @@ bool ProgramBinary::setUniformMatrix2fv(GLint location, GLsizei count, const GLf ...@@ -507,12 +507,12 @@ bool ProgramBinary::setUniformMatrix2fv(GLint location, GLsizei count, const GLf
return false; return false;
} }
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 8; GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 8;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
...@@ -540,12 +540,12 @@ bool ProgramBinary::setUniformMatrix3fv(GLint location, GLsizei count, const GLf ...@@ -540,12 +540,12 @@ bool ProgramBinary::setUniformMatrix3fv(GLint location, GLsizei count, const GLf
return false; return false;
} }
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 12; GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 12;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
...@@ -574,12 +574,12 @@ bool ProgramBinary::setUniformMatrix4fv(GLint location, GLsizei count, const GLf ...@@ -574,12 +574,12 @@ bool ProgramBinary::setUniformMatrix4fv(GLint location, GLsizei count, const GLf
return false; return false;
} }
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 16); GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 16);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
...@@ -606,24 +606,24 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v) ...@@ -606,24 +606,24 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v)
targetUniform->type == GL_SAMPLER_2D || targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE) targetUniform->type == GL_SAMPLER_CUBE)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint), memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint),
v, sizeof(GLint) * count); v, sizeof(GLint) * count);
} }
else if (targetUniform->type == GL_BOOL) else if (targetUniform->type == GL_BOOL)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
...@@ -658,24 +658,24 @@ bool ProgramBinary::setUniform2iv(GLint location, GLsizei count, const GLint *v) ...@@ -658,24 +658,24 @@ bool ProgramBinary::setUniform2iv(GLint location, GLsizei count, const GLint *v)
if (targetUniform->type == GL_INT_VEC2) if (targetUniform->type == GL_INT_VEC2)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 2, memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 2,
v, 2 * sizeof(GLint) * count); v, 2 * sizeof(GLint) * count);
} }
else if (targetUniform->type == GL_BOOL_VEC2) else if (targetUniform->type == GL_BOOL_VEC2)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
for (int i = 0; i < count * 2; ++i) for (int i = 0; i < count * 2; ++i)
...@@ -710,24 +710,24 @@ bool ProgramBinary::setUniform3iv(GLint location, GLsizei count, const GLint *v) ...@@ -710,24 +710,24 @@ bool ProgramBinary::setUniform3iv(GLint location, GLsizei count, const GLint *v)
if (targetUniform->type == GL_INT_VEC3) if (targetUniform->type == GL_INT_VEC3)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 3, memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 3,
v, 3 * sizeof(GLint) * count); v, 3 * sizeof(GLint) * count);
} }
else if (targetUniform->type == GL_BOOL_VEC3) else if (targetUniform->type == GL_BOOL_VEC3)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i) for (int i = 0; i < count * 3; ++i)
...@@ -762,24 +762,24 @@ bool ProgramBinary::setUniform4iv(GLint location, GLsizei count, const GLint *v) ...@@ -762,24 +762,24 @@ bool ProgramBinary::setUniform4iv(GLint location, GLsizei count, const GLint *v)
if (targetUniform->type == GL_INT_VEC4) if (targetUniform->type == GL_INT_VEC4)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 4, memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLint) * 4,
v, 4 * sizeof(GLint) * count); v, 4 * sizeof(GLint) * count);
} }
else if (targetUniform->type == GL_BOOL_VEC4) else if (targetUniform->type == GL_BOOL_VEC4)
{ {
int arraySize = targetUniform->arraySize; int elementCount = targetUniform->elementCount();
if (arraySize == 1 && count > 1) if (elementCount == 1 && count > 1)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count); count = std::min(elementCount - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4; GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i) for (int i = 0; i < count * 4; ++i)
...@@ -968,7 +968,7 @@ void ProgramBinary::applyUniforms() ...@@ -968,7 +968,7 @@ void ProgramBinary::applyUniforms()
if (targetUniform->type == GL_SAMPLER_2D || if (targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE) targetUniform->type == GL_SAMPLER_CUBE)
{ {
int count = targetUniform->arraySize; int count = targetUniform->elementCount();
GLint *v = (GLint*)targetUniform->data; GLint *v = (GLint*)targetUniform->data;
if (targetUniform->ps.registerCount) if (targetUniform->ps.registerCount)
...@@ -2112,45 +2112,49 @@ bool ProgramBinary::defineUniform(GLenum shader, const rx::D3DConstant *constant ...@@ -2112,45 +2112,49 @@ bool ProgramBinary::defineUniform(GLenum shader, const rx::D3DConstant *constant
bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant) bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant)
{ {
ASSERT(constant.arraySize <= 1); // FIXME: UNIMPLEMENTED Uniform *uniform = NULL;
Uniform *uniform = new Uniform(constant.type, constant.name, 1 /*constant.arraySize*/); GLint location = getUniformLocation(constant.name);
if (!uniform) if (location >= 0) // Previously defined, types must match
{
uniform = mUniforms[mUniformIndex[location].index];
if (uniform->type != constant.type)
{ {
return false; return false;
} }
}
else
{
uniform = new Uniform(constant.type, constant.name, constant.arraySize);
}
// Check if already defined if (!uniform)
GLint location = getUniformLocation(uniform->name);
GLenum type = uniform->type;
if (location >= 0)
{ {
delete uniform; return false;
uniform = mUniforms[mUniformIndex[location].index];
} }
if (shader == GL_FRAGMENT_SHADER) if (shader == GL_FRAGMENT_SHADER)
{ {
uniform->ps.registerIndex = constant.registerIndex; uniform->ps.registerIndex = constant.registerIndex;
uniform->ps.registerCount = 1 /*constant.arraySize*/; uniform->ps.registerCount = uniform->registerCount();
} }
else if (shader == GL_VERTEX_SHADER) else if (shader == GL_VERTEX_SHADER)
{ {
uniform->vs.registerIndex = constant.registerIndex; uniform->vs.registerIndex = constant.registerIndex;
uniform->vs.registerCount = 1 /*constant.arraySize*/; uniform->vs.registerCount = uniform->registerCount();
} }
else UNREACHABLE(); else UNREACHABLE();
if (location >= 0) if (location >= 0)
{ {
return uniform->type == type; return uniform->type == constant.type;
} }
mUniforms.push_back(uniform); mUniforms.push_back(uniform);
unsigned int uniformIndex = mUniforms.size() - 1; unsigned int uniformIndex = mUniforms.size() - 1;
for (unsigned int i = 0; i < uniform->arraySize; i++) for (unsigned int i = 0; i < uniform->elementCount(); i++)
{ {
mUniformIndex.push_back(UniformLocation(constant.name, i, uniformIndex)); mUniformIndex.push_back(UniformLocation(constant.name, i, uniformIndex));
} }
...@@ -2339,7 +2343,7 @@ void ProgramBinary::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *len ...@@ -2339,7 +2343,7 @@ void ProgramBinary::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *len
} }
} }
*size = mUniforms[index]->arraySize; *size = mUniforms[index]->elementCount();
*type = mUniforms[index]->type; *type = mUniforms[index]->type;
} }
......
...@@ -14,7 +14,7 @@ namespace gl ...@@ -14,7 +14,7 @@ namespace gl
Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize) Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize)
: type(type), _name(_name), name(undecorate(_name)), arraySize(arraySize) : type(type), _name(_name), name(undecorate(_name)), arraySize(arraySize)
{ {
int bytes = gl::UniformInternalSize(type) * arraySize; int bytes = gl::UniformInternalSize(type) * elementCount();
data = new unsigned char[bytes]; data = new unsigned char[bytes];
memset(data, 0, bytes); memset(data, 0, bytes);
dirty = true; dirty = true;
...@@ -25,12 +25,29 @@ Uniform::~Uniform() ...@@ -25,12 +25,29 @@ Uniform::~Uniform()
delete[] data; delete[] data;
} }
bool Uniform::isArray() bool Uniform::isArray() const
{ {
if (name != _name) // D3D9_REPLACE
{
size_t dot = _name.find_last_of('.'); size_t dot = _name.find_last_of('.');
if (dot == std::string::npos) dot = -1; if (dot == std::string::npos) dot = -1;
return _name.compare(dot + 1, dot + 4, "ar_") == 0; return _name.compare(dot + 1, dot + 4, "ar_") == 0;
}
else
{
return arraySize > 0;
}
}
unsigned int Uniform::elementCount() const
{
return arraySize > 0 ? arraySize : 1;
}
unsigned int Uniform::registerCount() const
{
return VariableRowCount(type) * elementCount();
} }
std::string Uniform::undecorate(const std::string &_name) std::string Uniform::undecorate(const std::string &_name)
......
...@@ -25,7 +25,9 @@ struct Uniform ...@@ -25,7 +25,9 @@ struct Uniform
~Uniform(); ~Uniform();
bool isArray(); bool isArray() const;
unsigned int elementCount() const;
unsigned int registerCount() const;
static std::string Uniform::undecorate(const std::string &_name); static std::string Uniform::undecorate(const std::string &_name);
const GLenum type; const GLenum type;
...@@ -45,7 +47,7 @@ struct Uniform ...@@ -45,7 +47,7 @@ struct Uniform
} }
int registerIndex; int registerIndex;
int registerCount; unsigned int registerCount;
}; };
RegisterInfo ps; RegisterInfo ps;
......
...@@ -837,7 +837,7 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -837,7 +837,7 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
case GL_FLOAT_MAT4: case GL_FLOAT_MAT4:
if (uniform->vs.registerCount) if (uniform->vs.registerCount)
{ {
for (int i = 0; i < uniform->vs.registerCount; i++) for (unsigned int i = 0; i < uniform->vs.registerCount; i++)
{ {
cVS[uniform->vs.registerIndex + i][0] = f[i][0]; cVS[uniform->vs.registerIndex + i][0] = f[i][0];
cVS[uniform->vs.registerIndex + i][1] = f[i][1]; cVS[uniform->vs.registerIndex + i][1] = f[i][1];
...@@ -847,7 +847,7 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -847,7 +847,7 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
} }
if (uniform->ps.registerCount) if (uniform->ps.registerCount)
{ {
for (int i = 0; i < uniform->ps.registerCount; i++) for (unsigned int i = 0; i < uniform->ps.registerCount; i++)
{ {
cPS[uniform->ps.registerIndex + i][0] = f[i][0]; cPS[uniform->ps.registerIndex + i][0] = f[i][0];
cPS[uniform->ps.registerIndex + i][1] = f[i][1]; cPS[uniform->ps.registerIndex + i][1] = f[i][1];
......
...@@ -1471,7 +1471,7 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -1471,7 +1471,7 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
if (targetUniform->dirty) if (targetUniform->dirty)
{ {
int arraySize = targetUniform->arraySize; int count = targetUniform->elementCount();
GLfloat *f = (GLfloat*)targetUniform->data; GLfloat *f = (GLfloat*)targetUniform->data;
GLint *i = (GLint*)targetUniform->data; GLint *i = (GLint*)targetUniform->data;
GLboolean *b = (GLboolean*)targetUniform->data; GLboolean *b = (GLboolean*)targetUniform->data;
...@@ -1481,10 +1481,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -1481,10 +1481,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
break; break;
case GL_BOOL: applyUniformnbv(targetUniform, arraySize, 1, b); break; case GL_BOOL: applyUniformnbv(targetUniform, count, 1, b); break;
case GL_BOOL_VEC2: applyUniformnbv(targetUniform, arraySize, 2, b); break; case GL_BOOL_VEC2: applyUniformnbv(targetUniform, count, 2, b); break;
case GL_BOOL_VEC3: applyUniformnbv(targetUniform, arraySize, 3, b); break; case GL_BOOL_VEC3: applyUniformnbv(targetUniform, count, 3, b); break;
case GL_BOOL_VEC4: applyUniformnbv(targetUniform, arraySize, 4, b); break; case GL_BOOL_VEC4: applyUniformnbv(targetUniform, count, 4, b); break;
case GL_FLOAT: case GL_FLOAT:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
case GL_FLOAT_VEC3: case GL_FLOAT_VEC3:
...@@ -1492,10 +1492,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -1492,10 +1492,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
case GL_FLOAT_MAT3: case GL_FLOAT_MAT3:
case GL_FLOAT_MAT4: applyUniformnfv(targetUniform, f); break; case GL_FLOAT_MAT4: applyUniformnfv(targetUniform, f); break;
case GL_INT: applyUniform1iv(targetUniform, arraySize, i); break; case GL_INT: applyUniform1iv(targetUniform, count, i); break;
case GL_INT_VEC2: applyUniform2iv(targetUniform, arraySize, i); break; case GL_INT_VEC2: applyUniform2iv(targetUniform, count, i); break;
case GL_INT_VEC3: applyUniform3iv(targetUniform, arraySize, i); break; case GL_INT_VEC3: applyUniform3iv(targetUniform, count, i); break;
case GL_INT_VEC4: applyUniform4iv(targetUniform, arraySize, i); break; case GL_INT_VEC4: applyUniform4iv(targetUniform, count, i); break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
......
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