mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
render/gles: add support for some 16-bpc unsigned shm formats
These formats require EXT_texture_norm16, which in turn needs OpenGL ES 3.1. The EXT_texture_norm16 extension does not support passing gl_internalformat = GL_RGBA to glTexImage2D, as can be done for formats available in OpenGL ES 2.0, so this commit adds a field to wlr_gles2_pixel_format to provide a more specific internalformat parameter to glTexImage2D.
This commit is contained in:
parent
cb012c5cb5
commit
7ad67e0f1d
5 changed files with 42 additions and 1 deletions
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
struct wlr_gles2_pixel_format {
|
struct wlr_gles2_pixel_format {
|
||||||
uint32_t drm_format;
|
uint32_t drm_format;
|
||||||
|
// optional field, if empty then internalformat = format
|
||||||
|
GLint gl_internalformat;
|
||||||
GLint gl_format, gl_type;
|
GLint gl_format, gl_type;
|
||||||
bool has_alpha;
|
bool has_alpha;
|
||||||
};
|
};
|
||||||
|
@ -45,6 +47,7 @@ struct wlr_gles2_renderer {
|
||||||
bool OES_egl_image;
|
bool OES_egl_image;
|
||||||
bool EXT_texture_type_2_10_10_10_REV;
|
bool EXT_texture_type_2_10_10_10_REV;
|
||||||
bool OES_texture_half_float_linear;
|
bool OES_texture_half_float_linear;
|
||||||
|
bool EXT_texture_norm16;
|
||||||
} exts;
|
} exts;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -93,6 +93,20 @@ static const struct wlr_gles2_pixel_format formats[] = {
|
||||||
.gl_type = GL_HALF_FLOAT_OES,
|
.gl_type = GL_HALF_FLOAT_OES,
|
||||||
.has_alpha = true,
|
.has_alpha = true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.drm_format = DRM_FORMAT_XBGR16161616,
|
||||||
|
.gl_internalformat = GL_RGBA16_EXT,
|
||||||
|
.gl_format = GL_RGBA,
|
||||||
|
.gl_type = GL_UNSIGNED_SHORT,
|
||||||
|
.has_alpha = false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.drm_format = DRM_FORMAT_ABGR16161616,
|
||||||
|
.gl_internalformat = GL_RGBA16_EXT,
|
||||||
|
.gl_format = GL_RGBA,
|
||||||
|
.gl_type = GL_UNSIGNED_SHORT,
|
||||||
|
.has_alpha = true,
|
||||||
|
},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,6 +126,10 @@ bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
|
||||||
&& !renderer->exts.OES_texture_half_float_linear) {
|
&& !renderer->exts.OES_texture_half_float_linear) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (format->gl_type == GL_UNSIGNED_SHORT
|
||||||
|
&& !renderer->exts.EXT_texture_norm16) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Note that we don't need to check for GL_EXT_texture_format_BGRA8888
|
* Note that we don't need to check for GL_EXT_texture_format_BGRA8888
|
||||||
* here, since we've already checked if we have it at renderer creation
|
* here, since we've already checked if we have it at renderer creation
|
||||||
|
|
|
@ -765,6 +765,9 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
||||||
renderer->exts.OES_texture_half_float_linear =
|
renderer->exts.OES_texture_half_float_linear =
|
||||||
check_gl_ext(exts_str, "GL_OES_texture_half_float_linear");
|
check_gl_ext(exts_str, "GL_OES_texture_half_float_linear");
|
||||||
|
|
||||||
|
renderer->exts.EXT_texture_norm16 =
|
||||||
|
check_gl_ext(exts_str, "GL_EXT_texture_norm16");
|
||||||
|
|
||||||
if (check_gl_ext(exts_str, "GL_KHR_debug")) {
|
if (check_gl_ext(exts_str, "GL_KHR_debug")) {
|
||||||
renderer->exts.KHR_debug = true;
|
renderer->exts.KHR_debug = true;
|
||||||
load_gl_proc(&renderer->procs.glDebugMessageCallbackKHR,
|
load_gl_proc(&renderer->procs.glDebugMessageCallbackKHR,
|
||||||
|
|
|
@ -210,6 +210,11 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
||||||
texture->has_alpha = fmt->has_alpha;
|
texture->has_alpha = fmt->has_alpha;
|
||||||
texture->drm_format = fmt->drm_format;
|
texture->drm_format = fmt->drm_format;
|
||||||
|
|
||||||
|
GLint internal_format = fmt->gl_internalformat;
|
||||||
|
if (!internal_format) {
|
||||||
|
internal_format = fmt->gl_format;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_save_context(&prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
wlr_egl_make_current(renderer->egl);
|
||||||
|
@ -222,7 +227,7 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (drm_fmt->bpp / 8));
|
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (drm_fmt->bpp / 8));
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0,
|
||||||
fmt->gl_format, fmt->gl_type, data);
|
fmt->gl_format, fmt->gl_type, data);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,18 @@ static const struct wlr_pixel_format_info pixel_format_info[] = {
|
||||||
.bpp = 64,
|
.bpp = 64,
|
||||||
.has_alpha = true,
|
.has_alpha = true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.drm_format = DRM_FORMAT_XBGR16161616,
|
||||||
|
.opaque_substitute = DRM_FORMAT_INVALID,
|
||||||
|
.bpp = 64,
|
||||||
|
.has_alpha = false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.drm_format = DRM_FORMAT_ABGR16161616,
|
||||||
|
.opaque_substitute = DRM_FORMAT_XBGR16161616,
|
||||||
|
.bpp = 64,
|
||||||
|
.has_alpha = true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const size_t pixel_format_info_size =
|
static const size_t pixel_format_info_size =
|
||||||
|
|
Loading…
Reference in a new issue