Resolve conflict between default cube map and 2D textures in texture map.

TRAC #11625

Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch

Author:    Andrew Lewycky

git-svn-id: http://angleproject.googlecode.com/svn/trunk@106 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index 9515716..ab93ba7 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -499,16 +499,9 @@
 
 void Context::bindTexture2D(GLuint texture)
 {
-    if (!getTexture(texture) || texture == 0)
+    if (!getTexture(texture) && texture != 0)
     {
-        if (texture != 0)
-        {
-            mTextureMap[texture] = new Texture2D();
-        }
-        else   // Special case: 0 refers to different initial textures based on the target
-        {
-            mTextureMap[0] = mTexture2DZero;
-        }
+        mTextureMap[texture] = new Texture2D();
     }
 
     texture2D = texture;
@@ -518,16 +511,9 @@
 
 void Context::bindTextureCubeMap(GLuint texture)
 {
-    if (!getTexture(texture) || texture == 0)
+    if (!getTexture(texture) && texture != 0)
     {
-        if (texture != 0)
-        {
-            mTextureMap[texture] = new TextureCubeMap();
-        }
-        else   // Special case: 0 refers to different initial textures based on the target
-        {
-            mTextureMap[0] = mTextureCubeMapZero;
-        }
+        mTextureMap[texture] = new TextureCubeMap();
     }
 
     textureCubeMap = texture;
@@ -641,6 +627,8 @@
 
 Texture *Context::getTexture(unsigned int handle)
 {
+    if (handle == 0) return NULL;
+
     TextureMap::iterator texture = mTextureMap.find(handle);
 
     if (texture == mTextureMap.end())
@@ -775,7 +763,19 @@
 
 Texture *Context::getSamplerTexture(unsigned int sampler, SamplerType type)
 {
-    return getTexture(samplerTexture[type][sampler]);
+    GLuint texid = samplerTexture[type][sampler];
+
+    if (texid == 0)
+    {
+        switch (type)
+        {
+          default: UNREACHABLE();
+          case SAMPLER_2D: return mTexture2DZero;
+          case SAMPLER_CUBE: return mTextureCubeMapZero;
+        }
+    }
+
+    return getTexture(texid);
 }
 
 Framebuffer *Context::getFramebuffer()