Commit 76648fe2 by Jamie Madill Committed by Commit Bot

Constexpr-fy the ES3 effective format map.

This removes the global std::vector constructor here. BUG=angleproject:1459 Change-Id: I407a7bda1f8f8a2dd8d5b0e847573f8594eccf39 Reviewed-on: https://chromium-review.googlesource.com/394235 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 22416868
...@@ -343,102 +343,110 @@ bool ValidateES3TexImage3DParameters(Context *context, ...@@ -343,102 +343,110 @@ bool ValidateES3TexImage3DParameters(Context *context,
struct EffectiveInternalFormatInfo struct EffectiveInternalFormatInfo
{ {
GLenum mEffectiveFormat; GLenum effectiveFormat;
GLenum mDestFormat; GLenum destFormat;
GLuint mMinRedBits; GLuint minRedBits;
GLuint mMaxRedBits; GLuint maxRedBits;
GLuint mMinGreenBits; GLuint minGreenBits;
GLuint mMaxGreenBits; GLuint maxGreenBits;
GLuint mMinBlueBits; GLuint minBlueBits;
GLuint mMaxBlueBits; GLuint maxBlueBits;
GLuint mMinAlphaBits; GLuint minAlphaBits;
GLuint mMaxAlphaBits; GLuint maxAlphaBits;
EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits,
GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits,
GLuint minAlphaBits, GLuint maxAlphaBits)
: mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits),
mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits),
mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits),
mMaxAlphaBits(maxAlphaBits) {};
}; };
typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; static bool QueryEffectiveFormatList(const InternalFormat &srcFormat,
GLenum targetFormat,
static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() const EffectiveInternalFormatInfo *list,
{ size_t size,
EffectiveInternalFormatList list; GLenum *outEffectiveFormat)
{
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and for (size_t curFormat = 0; curFormat < size; ++curFormat)
// linear source buffer component sizes. {
// | Source channel min/max sizes | const EffectiveInternalFormatInfo &formatInfo = list[curFormat];
// Effective Internal Format | N/A | R | G | B | A | if ((formatInfo.destFormat == targetFormat) &&
list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); (formatInfo.minRedBits <= srcFormat.redBits &&
list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); formatInfo.maxRedBits >= srcFormat.redBits) &&
list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); (formatInfo.minGreenBits <= srcFormat.greenBits &&
list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); formatInfo.maxGreenBits >= srcFormat.greenBits) &&
list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); (formatInfo.minBlueBits <= srcFormat.blueBits &&
list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); formatInfo.maxBlueBits >= srcFormat.blueBits) &&
list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); (formatInfo.minAlphaBits <= srcFormat.alphaBits &&
list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); formatInfo.maxAlphaBits >= srcFormat.alphaBits))
list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); {
*outEffectiveFormat = formatInfo.effectiveFormat;
return true;
}
}
return list; *outEffectiveFormat = GL_NONE;
return false;
} }
static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat,
{ GLenum *outEffectiveFormat)
EffectiveInternalFormatList list; {
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141:
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and // Effective internal format coresponding to destination internal format and linear source
// linear source buffer component sizes. // buffer component sizes.
// | Source channel min/max sizes | // | Source channel min/max sizes |
// Effective Internal Format | Dest Format | R | G | B | A | // Effective Internal Format | N/A | R | G | B | A |
list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); // clang-format off
list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); constexpr EffectiveInternalFormatInfo list[] = {
list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 },
list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 },
list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 },
list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 },
list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 },
list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 },
{ GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 },
{ GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 },
{ GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 },
};
// clang-format on
return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat);
}
return list; bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat,
const InternalFormat &destFormat,
GLenum *outEffectiveFormat)
{
constexpr GLuint umax = UINT_MAX;
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141:
// Effective internal format coresponding to destination internal format andlinear source buffer
// component sizes.
// | Source channel min/max sizes |
// Effective Internal Format | Dest Format | R | G | B | A |
// clang-format off
constexpr EffectiveInternalFormatInfo list[] = {
{ GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 },
{ GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax },
{ GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 },
{ GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax },
{ GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax },
{ GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 },
{ GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 },
{ GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 },
};
// clang-format on
return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list),
outEffectiveFormat);
} }
static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat, static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat,
GLenum *outEffectiveFormat) GLenum *outEffectiveFormat)
{ {
const EffectiveInternalFormatList *list = NULL;
GLenum targetFormat = GL_NONE;
if (destFormat.pixelBytes > 0) if (destFormat.pixelBytes > 0)
{ {
static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat);
list = &sizedList;
} }
else else
{ {
static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat);
list = &unsizedList;
targetFormat = destFormat.format;
}
for (size_t curFormat = 0; curFormat < list->size(); ++curFormat)
{
const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat);
if ((formatInfo.mDestFormat == targetFormat) &&
(formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) &&
(formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) &&
(formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) &&
(formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits))
{
*outEffectiveFormat = formatInfo.mEffectiveFormat;
return true;
}
} }
return false;
} }
struct CopyConversion struct CopyConversion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment