Moved duplicate code.

TRAC #22428
Signed-off-by: Geoff Lang
Signed-off-by: Jamie Madill
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1899 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 5f557c8..d17fd0d 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -252,14 +252,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_FLOAT)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -274,12 +275,6 @@
     }
     else if (targetUniform->type == GL_BOOL)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -310,14 +305,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_FLOAT_VEC2)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -332,12 +328,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC2)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -368,14 +358,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_FLOAT_VEC3)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -390,12 +381,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC3)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -426,14 +411,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_FLOAT_VEC4)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -448,12 +434,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC4)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -615,16 +595,17 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_INT ||
         targetUniform->type == GL_SAMPLER_2D ||
         targetUniform->type == GL_SAMPLER_CUBE)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *target = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -639,12 +620,6 @@
     }
     else if (targetUniform->type == GL_BOOL)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -675,14 +650,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_INT_VEC2)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *target = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -697,12 +673,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC2)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -733,14 +703,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_INT_VEC3)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *target = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -755,12 +726,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC3)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -791,14 +756,15 @@
     Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
     targetUniform->dirty = true;
 
+    int elementCount = targetUniform->elementCount();
+
+    if (elementCount == 1 && count > 1)
+        return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
+
+    count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
     if (targetUniform->type == GL_INT_VEC4)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *target = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)
@@ -813,12 +779,6 @@
     }
     else if (targetUniform->type == GL_BOOL_VEC4)
     {
-        int elementCount = targetUniform->elementCount();
-
-        if (elementCount == 1 && count > 1)
-            return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
-
-        count = std::min(elementCount - (int)mUniformIndex[location].element, count);
         GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
 
         for (int i = 0; i < count; i++)