Use packed enums for the texture types and targets, part 1

In OpenGL there are two enum "sets" used by the API that are very
similar: texture types (or bind point) and texture targets. They only
differ in that texture types have GL_TEXTURE_CUBEMAP and target have
GL_TEXTURE_CUBEMAP_[POSITIVE|NEGATIVE]_[X|Y|Z].

This is a problem because in ANGLE we use GLenum to pass around both
types of data, making it difficult to know which of type and target a
variable is.

In addition these enums are placed somewhat randomly in the space of
OpenGL enums, making it slow to have a mapping from texture types to
some data. Such a mapping is in hot-code with gl::State::mTextures.

This commit stack makes the texture types and target enums be
translated to internal packed enums right at the OpenGL entry point
and used throughout ANGLE to have type safety and performance gains.

This is the first of two commit which does the refactor for all of the
validation and stops inside gl::Context. This was the best place to
split patches without having many conversions from packed enums to GL
enums.

BUG=angleproject:2169

Change-Id: Ib43da7e71c253bd9fe210fb0ec0de61bc286e6d3
Reviewed-on: https://chromium-review.googlesource.com/758835
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index 2b29002..b1757e4 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -519,7 +519,7 @@
 }
 
 // SamplerBindings implementation.
-SamplerBinding::SamplerBinding(GLenum textureTypeIn, size_t elementCount, bool unreferenced)
+SamplerBinding::SamplerBinding(TextureType textureTypeIn, size_t elementCount, bool unreferenced)
     : textureType(textureTypeIn), boundTextureUnits(elementCount, 0), unreferenced(unreferenced)
 {
 }
@@ -1837,11 +1837,12 @@
 
     if (mTextureUnitTypesCache.empty())
     {
-        mTextureUnitTypesCache.resize(caps.maxCombinedTextureImageUnits, GL_NONE);
+        mTextureUnitTypesCache.resize(caps.maxCombinedTextureImageUnits, TextureType::InvalidEnum);
     }
     else
     {
-        std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(), GL_NONE);
+        std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(),
+                  TextureType::InvalidEnum);
     }
 
     // if any two active samplers in a program are of different types, but refer to the same
@@ -1852,7 +1853,7 @@
         if (samplerBinding.unreferenced)
             continue;
 
-        GLenum textureType = samplerBinding.textureType;
+        TextureType textureType = samplerBinding.textureType;
 
         for (GLuint textureUnit : samplerBinding.boundTextureUnits)
         {
@@ -1869,7 +1870,7 @@
                 return false;
             }
 
-            if (mTextureUnitTypesCache[textureUnit] != GL_NONE)
+            if (mTextureUnitTypesCache[textureUnit] != TextureType::InvalidEnum)
             {
                 if (textureType != mTextureUnitTypesCache[textureUnit])
                 {
@@ -2425,7 +2426,7 @@
     for (unsigned int samplerIndex : mState.mSamplerUniformRange)
     {
         const auto &samplerUniform = mState.mUniforms[samplerIndex];
-        GLenum textureType         = SamplerTypeToTextureType(samplerUniform.type);
+        TextureType textureType    = SamplerTypeToTextureType(samplerUniform.type);
         mState.mSamplerBindings.emplace_back(
             SamplerBinding(textureType, samplerUniform.getBasicTypeElementCount(), false));
     }
@@ -3442,7 +3443,7 @@
 
     for (const auto &binding : mState.mSamplerBindings)
     {
-        GLenum textureType = binding.textureType;
+        TextureType textureType = binding.textureType;
         for (const auto &unit : binding.boundTextureUnits)
         {
             GLenum programTextureID = state.getSamplerTextureId(unit, textureType);