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/Program.cpp b/libGLESv2/Program.cpp
index 1d6e36d..7f18731 100644
--- a/libGLESv2/Program.cpp
+++ b/libGLESv2/Program.cpp
@@ -164,12 +164,22 @@
 // index referenced in the compiled HLSL shader
 GLint Program::getSamplerMapping(unsigned int samplerIndex)
 {
-    if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
+    assert(samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]));
+
+    if (mSamplers[samplerIndex].active)
     {
-        return mSamplerMapping[samplerIndex];
+        return mSamplers[samplerIndex].logicalTextureUnit;
     }
 
-    return 0;
+    return -1;
+}
+
+SamplerType Program::getSamplerType(unsigned int samplerIndex)
+{
+    assert(samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]));
+    assert(mSamplers[samplerIndex].active);
+
+    return mSamplers[samplerIndex].type;
 }
 
 GLint Program::getUniformLocation(const char *name)
@@ -434,6 +444,11 @@
                 return;
             }
 
+            for (int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
+            {
+                mSamplers[i].active = false;
+            }
+
             if (!linkUniforms(mConstantTablePS))
             {
                 return;
@@ -515,6 +530,17 @@
 // Returns true if succesful (uniform not already defined)
 bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name)
 {
+    if (constantDescription.RegisterSet == D3DXRS_SAMPLER)
+    {
+        unsigned int samplerIndex = constantDescription.RegisterIndex;
+
+        assert(samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]));
+
+        mSamplers[samplerIndex].active = true;
+        mSamplers[samplerIndex].type = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? SAMPLER_CUBE : SAMPLER_2D;
+        mSamplers[samplerIndex].logicalTextureUnit = 0;
+    }
+
     switch(constantDescription.Class)
     {
       case D3DXPC_STRUCT:
@@ -858,7 +884,8 @@
                 {
                     if (samplerIndex >= 0 && samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
                     {
-                        mSamplerMapping[samplerIndex] = mappedSampler;
+                        ASSERT(mSamplers[samplerIndex].active);
+                        mSamplers[samplerIndex].logicalTextureUnit = mappedSampler;
                     }
                 }
             }
@@ -935,7 +962,7 @@
 
     for (int index = 0; index < MAX_TEXTURE_IMAGE_UNITS; index++)
     {
-        mSamplerMapping[index] = 0;
+        mSamplers[index].active = false;
     }
 
     while (!mUniforms.empty())