1
0
Fork 0

cogl/gles: Use unsized internal formats for RGB8, RGBA8 in GLES 2.0

GLES 2.0 does not have RGB8 and RGBA8 as sized internal formats. There
is OES_rgb8_rgba8 which adds RGB8 and RGBA8 but only for
RenderbufferStorageOES and not for TexImage2D which I wrongly assumed.
It seems like there is currently no GLES2 extension which adds RGB8 and
RGBA8 to TexImage2D so we have no choice but to fall back to unsized
internal formats in those cases as long as we don't want to drop GLES2
support.

This should be fine in practice and we should get our 8bpc textures.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3680
Fixes: 7f943613a8 ("cogl: Use sized internal renderable formats")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4036>
This commit is contained in:
Sebastian Wick 2024-09-18 12:57:48 +02:00 committed by Marge Bot
parent 846fc458d3
commit 2ce64ac0c3
2 changed files with 20 additions and 15 deletions

View file

@ -46,6 +46,7 @@ typedef enum
COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL, COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL,
COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL, COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL,
COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888,
COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_SIZED_RGBA,
COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE, COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE,
COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS, COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS,
COGL_PRIVATE_FEATURE_READ_PIXELS_ANY_STRIDE, COGL_PRIVATE_FEATURE_READ_PIXELS_ANY_STRIDE,

View file

@ -134,10 +134,7 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
* Sized formats from table 4.5: * Sized formats from table 4.5:
* RGBA4, RGB5_A1, RGB565 * RGBA4, RGB5_A1, RGB565
* *
* More color-renderable formats from extensions: * More color-renderable formats for glTexImage2D from extensions:
*
* OES_rgb8_rgba8
* adds RGB8, RGBA8 as color-renderable internal formats
* *
* EXT_texture_format_BGRA8888 * EXT_texture_format_BGRA8888
* adds BGRA_EXT as internal and external color-renderable format * adds BGRA_EXT as internal and external color-renderable format
@ -146,8 +143,9 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
* adds R16F, RG16F (required EXT_texture_rg) and RGB16F, RGBA16F * adds R16F, RG16F (required EXT_texture_rg) and RGB16F, RGBA16F
* as internal color-renderable formats * as internal color-renderable formats
* *
* => We require GLES 2 + OES_rgb8_rgba8 or GLES 3 which gives us at least: * This means we have no way to get sized internal formats for RGB8 and RGBA8
* RGB8, RGBA8, RGBA4, RGB5_A1, RGB565 * in GLES 2.0 and we have to fall back to non-sized internal formats but in
* practice this should be fine.
*/ */
/* For GLES 2 (not GLES 3) the glintformat and glformat have to match: /* For GLES 2 (not GLES 3) the glintformat and glformat have to match:
@ -204,7 +202,12 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
break; break;
case COGL_PIXEL_FORMAT_RGB_888: case COGL_PIXEL_FORMAT_RGB_888:
glintformat = GL_RGB8; if (_cogl_has_private_feature
(context, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_SIZED_RGBA))
glintformat = GL_RGB8;
else
glintformat = GL_RGB;
glformat = GL_RGB; glformat = GL_RGB;
gltype = GL_UNSIGNED_BYTE; gltype = GL_UNSIGNED_BYTE;
break; break;
@ -315,7 +318,11 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
case COGL_PIXEL_FORMAT_RGBA_8888: case COGL_PIXEL_FORMAT_RGBA_8888:
case COGL_PIXEL_FORMAT_RGBA_8888_PRE: case COGL_PIXEL_FORMAT_RGBA_8888_PRE:
glintformat = GL_RGBA8; if (_cogl_has_private_feature
(context, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_SIZED_RGBA))
glintformat = GL_RGBA8;
else
glintformat = GL_RGBA;
glformat = GL_RGBA; glformat = GL_RGBA;
gltype = GL_UNSIGNED_BYTE; gltype = GL_UNSIGNED_BYTE;
break; break;
@ -727,14 +734,11 @@ _cogl_driver_update_features (CoglContext *context,
gl_minor, gl_minor,
gl_extensions); gl_extensions);
if (!_cogl_check_extension ("GL_OES_rgb8_rgba8", gl_extensions) && if (COGL_CHECK_GL_VERSION (gl_major, gl_minor, 3, 0))
!COGL_CHECK_GL_VERSION (gl_major, gl_minor, 3, 0))
{ {
g_set_error (error, /* unfortunately there is no GLES 2 ext which adds the equivalent */
COGL_DRIVER_ERROR, COGL_FLAGS_SET (private_features,
COGL_DRIVER_ERROR_INVALID_VERSION, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_SIZED_RGBA, TRUE);
"GL_OES_rgb8_rgba8 is required for GLES 2");
return FALSE;
} }
if (_cogl_check_extension ("GL_ANGLE_pack_reverse_row_order", gl_extensions)) if (_cogl_check_extension ("GL_ANGLE_pack_reverse_row_order", gl_extensions))