Remove calls to new when modifying shader constants.
There were some unnecessary temporary copies we can remove, and the rest have a maximum size so we can allocate them on the stack.
BUG=276
TEST=
Review URL: https://codereview.appspot.com/5540071
git-svn-id: https://angleproject.googlecode.com/svn/trunk@961 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Program.cpp b/src/libGLESv2/Program.cpp
index 986593f..bcab6f7 100644
--- a/src/libGLESv2/Program.cpp
+++ b/src/libGLESv2/Program.cpp
@@ -333,7 +333,7 @@
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);
- GLboolean *boolParams = new GLboolean[count];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i)
{
@@ -346,11 +346,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean),
- boolParams, sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -400,7 +395,7 @@
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
- GLboolean *boolParams = new GLboolean[count * 2];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
for (int i = 0; i < count * 2; ++i)
{
@@ -413,11 +408,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 2,
- boolParams, 2 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -466,7 +456,7 @@
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);
- GLboolean *boolParams = new GLboolean[count * 3];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i)
{
@@ -479,11 +469,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 3,
- boolParams, 3 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -523,7 +508,7 @@
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);
- GLboolean *boolParams = new GLboolean[count * 4];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i)
{
@@ -536,11 +521,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 4,
- boolParams, 4 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -713,7 +693,7 @@
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);
- GLboolean *boolParams = new GLboolean[count];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i)
{
@@ -726,11 +706,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean),
- boolParams, sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -770,7 +745,7 @@
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);
- GLboolean *boolParams = new GLboolean[count * 2];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
for (int i = 0; i < count * 2; ++i)
{
@@ -783,11 +758,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 2,
- boolParams, 2 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -827,7 +797,7 @@
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);
- GLboolean *boolParams = new GLboolean[count * 3];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i)
{
@@ -840,11 +810,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 3,
- boolParams, 3 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -884,7 +849,7 @@
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);
- GLboolean *boolParams = new GLboolean[count * 4];
+ GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i)
{
@@ -897,11 +862,6 @@
boolParams[i] = GL_TRUE;
}
}
-
- memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 4,
- boolParams, 4 * sizeof(GLboolean) * count);
-
- delete [] boolParams;
}
else
{
@@ -2085,14 +2045,13 @@
void Program::applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v)
{
- float *vector = NULL;
- BOOL *boolVector = NULL;
+ float vector[D3D9_MAX_FLOAT_CONSTANTS * 4];
+ BOOL boolVector[D3D9_MAX_BOOL_CONSTANTS];
if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_FLOAT4 ||
targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_FLOAT4)
{
- vector = new float[4 * count];
-
+ ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 4; j++)
@@ -2112,8 +2071,11 @@
if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_BOOL ||
targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_BOOL)
{
- boolVector = new BOOL[count * width];
- for (int i = 0; i < count * width; i++)
+ int psCount = targetUniform->ps.registerSet == D3DXRS_BOOL ? targetUniform->ps.registerCount : 0;
+ int vsCount = targetUniform->vs.registerSet == D3DXRS_BOOL ? targetUniform->vs.registerCount : 0;
+ int copyCount = std::min(count * width, std::max(psCount, vsCount));
+ ASSERT(copyCount <= D3D9_MAX_BOOL_CONSTANTS);
+ for (int i = 0; i < copyCount; i++)
{
boolVector[i] = v[i] != GL_FALSE;
}
@@ -2144,9 +2106,6 @@
}
else UNREACHABLE();
}
-
- delete [] vector;
- delete [] boolVector;
}
bool Program::applyUniformnfv(Uniform *targetUniform, const GLfloat *v)
@@ -2166,7 +2125,8 @@
bool Program::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
- D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
+ ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
+ D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
@@ -2221,14 +2181,13 @@
}
}
- delete [] vector;
-
return true;
}
bool Program::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
- D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
+ ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
+ D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
@@ -2239,14 +2198,13 @@
applyUniformniv(targetUniform, count, vector);
- delete[] vector;
-
return true;
}
bool Program::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
- D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
+ ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
+ D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
@@ -2257,14 +2215,13 @@
applyUniformniv(targetUniform, count, vector);
- delete[] vector;
-
return true;
}
bool Program::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
- D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
+ ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
+ D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
@@ -2275,8 +2232,6 @@
applyUniformniv(targetUniform, count, vector);
- delete [] vector;
-
return true;
}