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
...@@ -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
{ {
size_t dot = _name.find_last_of('.'); if (name != _name) // D3D9_REPLACE
if (dot == std::string::npos) dot = -1; {
size_t dot = _name.find_last_of('.');
if (dot == std::string::npos) dot = -1;
return _name.compare(dot + 1, dot + 4, "ar_") == 0;
}
else
{
return arraySize > 0;
}
}
return _name.compare(dot + 1, dot + 4, "ar_") == 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,21 +1481,21 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -1481,21 +1481,21 @@ 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:
case GL_FLOAT_VEC4: case GL_FLOAT_VEC4:
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