case GL_FLOAT:
return comps * sizeof(GLfloat);
case GL_HALF_FLOAT_ARB:
+ case GL_HALF_FLOAT_OES:
return comps * sizeof(GLhalfARB);
case GL_DOUBLE:
return comps * sizeof(GLdouble);
}
/**
- * Test if the given format is an ASTC format.
+ * Test if the given format is an ASTC 2D format.
*/
-GLboolean
-_mesa_is_astc_format(GLenum internalFormat)
+static bool
+is_astc_2d_format(GLenum internalFormat)
{
switch (internalFormat) {
case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
}
}
+/**
+ * Test if the given format is an ASTC 3D format.
+ */
+static bool
+is_astc_3d_format(GLenum internalFormat)
+{
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES:
+ case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES:
+ case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES:
+ case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES:
+ case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES:
+ case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES:
+ case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES:
+ case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES:
+ case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES:
+ case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/**
+ * Test if the given format is an ASTC format.
+ */
+GLboolean
+_mesa_is_astc_format(GLenum internalFormat)
+{
+ return is_astc_2d_format(internalFormat) ||
+ is_astc_3d_format(internalFormat);
+}
+
+/**
+ * Test if the given format is an ETC2 format.
+ */
+GLboolean
+_mesa_is_etc2_format(GLenum internalFormat)
+{
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB8_ETC2:
+ case GL_COMPRESSED_SRGB8_ETC2:
+ case GL_COMPRESSED_RGBA8_ETC2_EAC:
+ case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+ case GL_COMPRESSED_R11_EAC:
+ case GL_COMPRESSED_RG11_EAC:
+ case GL_COMPRESSED_SIGNED_R11_EAC:
+ case GL_COMPRESSED_SIGNED_RG11_EAC:
+ case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+ case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+ return true;
+ default:
+ return false;
+ }
+}
/**
* Test if the given format is an integer (non-normalized) format.
_mesa_base_format_component_count(GLenum base_format)
{
switch (base_format) {
+ case GL_LUMINANCE:
case GL_RED:
case GL_ALPHA:
case GL_INTENSITY:
return base_compressed;
}
- if (ctx->Extensions.KHR_texture_compression_astc_ldr &&
- _mesa_is_astc_format(internalFormat))
+ if ((ctx->Extensions.KHR_texture_compression_astc_ldr &&
+ is_astc_2d_format(internalFormat)) ||
+ (ctx->Extensions.OES_texture_compression_astc &&
+ is_astc_3d_format(internalFormat)))
return GL_RGBA;
if (ctx->Extensions.MESA_ycbcr_texture) {
case GL_RGBA8I_EXT:
case GL_RGBA16I_EXT:
case GL_RGBA32I_EXT:
- case GL_RGB10_A2UI:
return GL_RGBA;
case GL_RGB8UI_EXT:
case GL_RGB16UI_EXT:
}
}
+ if (ctx->Extensions.ARB_texture_rgb10_a2ui) {
+ switch (internalFormat) {
+ case GL_RGB10_A2UI:
+ return GL_RGBA;
+ }
+ }
+
if (ctx->Extensions.EXT_texture_integer) {
switch (internalFormat) {
case GL_ALPHA8UI_EXT:
return GL_RGBA8;
case GL_RGB:
return GL_RGB8;
+ case GL_RG:
+ return GL_RG8;
+ case GL_RED:
+ return GL_R8;
/* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
* (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
* internal formats, they do not correspond to GL constants, so the base
case GL_UNSIGNED_INT_10F_11F_11F_REV:
if (format == GL_RGB)
return MESA_FORMAT_R11G11B10_FLOAT;
+ break;
+ case GL_FLOAT:
+ if (format == GL_DEPTH_COMPONENT)
+ return MESA_FORMAT_Z_FLOAT32;
+ break;
+ case GL_UNSIGNED_INT:
+ if (format == GL_DEPTH_COMPONENT)
+ return MESA_FORMAT_Z_UNORM32;
+ break;
+ case GL_UNSIGNED_SHORT:
+ if (format == GL_DEPTH_COMPONENT)
+ return MESA_FORMAT_Z_UNORM16;
+ break;
+ case GL_UNSIGNED_INT_24_8:
+ if (format == GL_DEPTH_STENCIL)
+ return MESA_FORMAT_Z24_UNORM_S8_UINT;
+ break;
+ case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+ if (format == GL_DEPTH_STENCIL)
+ return MESA_FORMAT_Z32_FLOAT_S8X24_UINT;
+ break;
default:
break;
}
*/
unreachable("Unsupported format");
}
+
+uint32_t
+_mesa_tex_format_from_format_and_type(const struct gl_context *ctx,
+ GLenum gl_format, GLenum type)
+{
+ mesa_format format = _mesa_format_from_format_and_type(gl_format, type);
+
+ if (_mesa_format_is_mesa_array_format(format))
+ format = _mesa_format_from_array_format(format);
+
+ if (format == MESA_FORMAT_NONE || !ctx->TextureFormatSupported[format])
+ return MESA_FORMAT_NONE;
+
+ return format;
+}
+
+/**
+ * Returns true if \p internal_format is a sized internal format that
+ * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
+ */
+bool
+_mesa_is_es3_color_renderable(GLenum internal_format)
+{
+ switch (internal_format) {
+ case GL_R8:
+ case GL_RG8:
+ case GL_RGB8:
+ case GL_RGB565:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGB10_A2UI:
+ case GL_SRGB8_ALPHA8:
+ case GL_R16F:
+ case GL_RG16F:
+ case GL_RGBA16F:
+ case GL_R32F:
+ case GL_RG32F:
+ case GL_RGBA32F:
+ case GL_R11F_G11F_B10F:
+ case GL_R8I:
+ case GL_R8UI:
+ case GL_R16I:
+ case GL_R16UI:
+ case GL_R32I:
+ case GL_R32UI:
+ case GL_RG8I:
+ case GL_RG8UI:
+ case GL_RG16I:
+ case GL_RG16UI:
+ case GL_RG32I:
+ case GL_RG32UI:
+ case GL_RGBA8I:
+ case GL_RGBA8UI:
+ case GL_RGBA16I:
+ case GL_RGBA16UI:
+ case GL_RGBA32I:
+ case GL_RGBA32UI:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/**
+ * Returns true if \p internal_format is a sized internal format that
+ * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
+ */
+bool
+_mesa_is_es3_texture_filterable(const struct gl_context *ctx,
+ GLenum internal_format)
+{
+ switch (internal_format) {
+ case GL_R8:
+ case GL_R8_SNORM:
+ case GL_RG8:
+ case GL_RG8_SNORM:
+ case GL_RGB8:
+ case GL_RGB8_SNORM:
+ case GL_RGB565:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGBA8_SNORM:
+ case GL_RGB10_A2:
+ case GL_SRGB8:
+ case GL_SRGB8_ALPHA8:
+ case GL_R16F:
+ case GL_RG16F:
+ case GL_RGB16F:
+ case GL_RGBA16F:
+ case GL_R11F_G11F_B10F:
+ case GL_RGB9_E5:
+ return true;
+ case GL_R32F:
+ case GL_RG32F:
+ case GL_RGB32F:
+ case GL_RGBA32F:
+ /* The OES_texture_float_linear spec says:
+ *
+ * "When implemented against OpenGL ES 3.0 or later versions, sized
+ * 32-bit floating-point formats become texture-filterable. This
+ * should be noted by, for example, checking the ``TF'' column of
+ * table 8.13 in the ES 3.1 Specification (``Correspondence of sized
+ * internal formats to base internal formats ... and use cases ...'')
+ * for the R32F, RG32F, RGB32F, and RGBA32F formats."
+ */
+ return ctx->Extensions.OES_texture_float_linear;
+ default:
+ return false;
+ }
+}