Skip to content

Commit 4c19e00

Browse files
committed
vo_gpu: opengl: use R8/RG8 formats on GLES 2.0 and GL 2.1
GLES 2.0 contexts with GL_EXT_texture_rg never used single- and two-component R/RG textures, because the format table only listed them for GL 3.0/ES 3.0, or for GL 2.1 with texture_rg + texture_float + FBOs all present (F_GL2F). Video planes were uploaded as LUMINANCE/ LUMINANCE_ALPHA instead, which needs a swizzle hack and mismatches the .rg layout produced by dmabuf imports of DRM_FORMAT_R8/GR88 (NV12 via drm-prime), and forced dumb mode due to the have_texrg check. Add format classes for ES2 with GL_EXT_texture_rg (unsized internal formats, as ES2 requires) and for GL 2.1 with ARB/EXT_texture_rg alone, without the float/FBO requirements of F_GL2F. The entries are placed before the legacy LUMINANCE ones so format lookups prefer them; F_GL2RG is suppressed when F_GL2F is active to avoid duplicate entries.
1 parent 04830ca commit 4c19e00

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

video/out/opengl/formats.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ const struct gl_format gl_formats[] = {
2424
// Specifically not color-renderable.
2525
{"rgb16", GL_RGB16, GL_RGB, T_U16, F_TF | F_EXT16},
2626

27+
// GL 2.1 with GL_ARB/EXT_texture_rg, but without requiring FBOs or float
28+
// textures (unlike F_GL2F). Upload/filtering only.
29+
{"r8", GL_R8, GL_RED, T_U8, F_TF | F_GL2RG},
30+
{"rg8", GL_RG8, GL_RG, T_U8, F_TF | F_GL2RG},
31+
32+
// ES2 with GL_EXT_texture_rg. ES2 requires unsized internal formats.
33+
{"r", GL_RED, GL_RED, T_U8, F_TF | F_ES2RG},
34+
{"rg", GL_RG, GL_RG, T_U8, F_TF | F_ES2RG},
35+
2736
// GL2 legacy. Ignores possibly present FBO extensions (no CF flag set).
2837
{"l8", GL_LUMINANCE8, GL_LUMINANCE, T_U8, F_TF | F_GL2},
2938
{"la8", GL_LUMINANCE8_ALPHA8, GL_LUMINANCE_ALPHA, T_U8, F_TF | F_GL2},
@@ -104,7 +113,7 @@ const struct gl_format gl_formats[] = {
104113
// Return an or-ed combination of all F_ flags that apply.
105114
int gl_format_feature_flags(GL *gl)
106115
{
107-
return (gl->version == 210 ? F_GL2 : 0)
116+
int flags = (gl->version == 210 ? F_GL2 : 0)
108117
| (gl->version >= 300 ? F_GL3 : 0)
109118
| (gl->es == 200 ? F_ES2 : 0)
110119
| (gl->es >= 300 ? F_ES3 : 0)
@@ -116,7 +125,15 @@ int gl_format_feature_flags(GL *gl)
116125
(gl->mpgl_caps & MPGL_CAP_ARB_FLOAT) &&
117126
(gl->mpgl_caps & MPGL_CAP_TEX_RG) &&
118127
(gl->mpgl_caps & MPGL_CAP_FB)) ? F_GL2F : 0)
128+
| ((gl->version == 210 &&
129+
(gl->mpgl_caps & MPGL_CAP_TEX_RG)) ? F_GL2RG : 0)
130+
| ((gl->es == 200 &&
131+
(gl->mpgl_caps & MPGL_CAP_TEX_RG)) ? F_ES2RG : 0)
119132
| (gl->mpgl_caps & MPGL_CAP_APPLE_RGB_422 ? F_APPL : 0);
133+
// F_GL2RG is a subset of F_GL2F; avoid duplicate format entries.
134+
if (flags & F_GL2F)
135+
flags &= ~F_GL2RG;
136+
return flags;
120137
}
121138

122139
int gl_format_type(const struct gl_format *format)

video/out/opengl/formats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ enum {
2525
F_EXTF16 = 1 << 6, // GL_EXT_color_buffer_half_float
2626
F_GL2F = 1 << 7, // GL2.1-only with texture_rg + texture_float + FBOs
2727
F_APPL = 1 << 8, // GL_APPLE_rgb_422
28+
F_GL2RG = 1 << 9, // GL2.1-only with texture_rg (no float/FBO requirement)
29+
F_ES2RG = 1 << 10, // ES2-only with GL_EXT_texture_rg
2830

2931
// Feature flags. They are additional and signal presence of features.
3032
F_CR = 1 << 16, // color-renderable

0 commit comments

Comments
 (0)