Select texture type based on program usage.

TRAC #11410

Add Program::getSamplerType() and internal machinery to track the reported sampler uniforms.
Make State::samplerTexture into a 2D array with a dimension for sampler type.
Context::applyTextures queries the sampler type and asks for the right texture.

Author:    Andrew Lewycky
Signed-off-by: Shannon Woods
Signed-off-by: Daniel Koch

git-svn-id: https://angleproject.googlecode.com/svn/trunk@25 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/libGLESv2/Context.cpp b/libGLESv2/Context.cpp
index 52817ce..37db9a7 100644
--- a/libGLESv2/Context.cpp
+++ b/libGLESv2/Context.cpp
@@ -115,9 +115,12 @@
     bindFramebuffer(0);
     bindRenderbuffer(0);
 
-    for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)
+    for (int type = 0; type < SAMPLER_TYPE_COUNT; type++)
     {
-        samplerTexture[sampler] = 0;
+        for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)
+        {
+            samplerTexture[type][sampler] = 0;
+        }
     }
 
     currentProgram = 0;
@@ -458,7 +461,7 @@
 
     texture2D = texture;
 
-    samplerTexture[activeSampler] = texture;
+    samplerTexture[SAMPLER_2D][activeSampler] = texture;
 }
 
 void Context::bindTextureCubeMap(GLuint texture)
@@ -477,7 +480,7 @@
 
     textureCubeMap = texture;
 
-    samplerTexture[activeSampler] = texture;
+    samplerTexture[SAMPLER_CUBE][activeSampler] = texture;
 }
 
 void Context::bindFramebuffer(GLuint framebuffer)
@@ -718,9 +721,9 @@
     return (TextureCubeMap*)getTexture(textureCubeMap);
 }
 
-Texture *Context::getSamplerTexture(unsigned int sampler)
+Texture *Context::getSamplerTexture(unsigned int sampler, SamplerType type)
 {
-    return getTexture(samplerTexture[sampler]);
+    return getTexture(samplerTexture[type][sampler]);
 }
 
 Framebuffer *Context::getFramebuffer()
@@ -1051,11 +1054,13 @@
 
     for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)
     {
-        unsigned int textureUnit = programObject->getSamplerMapping(sampler);
-        Texture *texture = getSamplerTexture(textureUnit);
-
-        if (texture && texture->isComplete())
+        int textureUnit = programObject->getSamplerMapping(sampler);
+        if (textureUnit != -1)
         {
+            SamplerType textureType = programObject->getSamplerType(sampler);
+
+            Texture *texture = getSamplerTexture(textureUnit, textureType);
+
             GLenum wrapS = texture->getWrapS();
             GLenum wrapT = texture->getWrapT();
             GLenum minFilter = texture->getMinFilter();
@@ -1072,6 +1077,10 @@
 
             device->SetTexture(sampler, texture->getTexture());
         }
+        else
+        {
+            device->SetTexture(sampler, NULL);
+        }
     }
 }
 
@@ -1637,11 +1646,14 @@
     // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
     // rebound to texture object zero
 
-    for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)
+    for (int type = 0; type < SAMPLER_TYPE_COUNT; type++)
     {
-        if (samplerTexture[sampler] == texture)
+        for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)
         {
-            samplerTexture[sampler] = 0;
+            if (samplerTexture[type][sampler] == texture)
+            {
+                samplerTexture[type][sampler] = 0;
+            }
         }
     }