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/renderer/d3d/ProgramD3D.cpp b/src/libANGLE/renderer/d3d/ProgramD3D.cpp
index be1660f..072012d 100644
--- a/src/libANGLE/renderer/d3d/ProgramD3D.cpp
+++ b/src/libANGLE/renderer/d3d/ProgramD3D.cpp
@@ -594,7 +594,8 @@
SafeDelete(mShaderExecutable);
}
-ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D)
+ProgramD3D::Sampler::Sampler()
+ : active(false), logicalTextureUnit(0), textureType(gl::TextureType::_2D)
{
}
@@ -707,7 +708,8 @@
// Returns the texture type for a given Direct3D 9 sampler type and
// index (0-15 for the pixel shader and 0-3 for the vertex shader).
-GLenum ProgramD3D::getSamplerTextureType(gl::ShaderType type, unsigned int samplerIndex) const
+gl::TextureType ProgramD3D::getSamplerTextureType(gl::ShaderType type,
+ unsigned int samplerIndex) const
{
switch (type)
{
@@ -725,9 +727,9 @@
return mSamplersCS[samplerIndex].textureType;
default:
UNREACHABLE();
+ return gl::TextureType::InvalidEnum;
}
- return GL_TEXTURE_2D;
}
GLuint ProgramD3D::getUsedSamplerRange(gl::ShaderType type) const
@@ -898,7 +900,7 @@
Sampler sampler;
stream->readBool(&sampler.active);
stream->readInt(&sampler.logicalTextureUnit);
- stream->readInt(&sampler.textureType);
+ stream->readEnum(&sampler.textureType);
mSamplersPS.push_back(sampler);
}
const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
@@ -907,7 +909,7 @@
Sampler sampler;
stream->readBool(&sampler.active);
stream->readInt(&sampler.logicalTextureUnit);
- stream->readInt(&sampler.textureType);
+ stream->readEnum(&sampler.textureType);
mSamplersVS.push_back(sampler);
}
@@ -917,7 +919,7 @@
Sampler sampler;
stream->readBool(&sampler.active);
stream->readInt(&sampler.logicalTextureUnit);
- stream->readInt(&sampler.textureType);
+ stream->readEnum(&sampler.textureType);
mSamplersCS.push_back(sampler);
}
@@ -1170,7 +1172,7 @@
{
stream->writeInt(mSamplersPS[i].active);
stream->writeInt(mSamplersPS[i].logicalTextureUnit);
- stream->writeInt(mSamplersPS[i].textureType);
+ stream->writeEnum(mSamplersPS[i].textureType);
}
stream->writeInt(mSamplersVS.size());
@@ -1178,7 +1180,7 @@
{
stream->writeInt(mSamplersVS[i].active);
stream->writeInt(mSamplersVS[i].logicalTextureUnit);
- stream->writeInt(mSamplersVS[i].textureType);
+ stream->writeEnum(mSamplersVS[i].textureType);
}
stream->writeInt(mSamplersCS.size());
@@ -1186,7 +1188,7 @@
{
stream->writeInt(mSamplersCS[i].active);
stream->writeInt(mSamplersCS[i].logicalTextureUnit);
- stream->writeInt(mSamplersCS[i].textureType);
+ stream->writeEnum(mSamplersCS[i].textureType);
}
stream->writeInt(mImagesCS.size());
@@ -2616,7 +2618,7 @@
ASSERT(samplerIndex < outSamplers.size());
Sampler *sampler = &outSamplers[samplerIndex];
sampler->active = true;
- sampler->textureType = typeInfo.textureType;
+ sampler->textureType = gl::FromGLenum<gl::TextureType>(typeInfo.textureType);
sampler->logicalTextureUnit = 0;
*outUsedRange = std::max(samplerIndex + 1, *outUsedRange);
samplerIndex++;