aboutsummaryrefslogtreecommitdiff
path: root/render/gles2
diff options
context:
space:
mode:
authorAlexander Orzechowski <alex@ozal.ski>2023-11-30 20:01:12 -0500
committerAlexander Orzechowski <alex@ozal.ski>2023-11-30 20:01:12 -0500
commitc5a3c5ca4cc4ee664bb4b4edad77dba8c36b0a21 (patch)
treef693358d1a1502fbab143eeb06eb3944f693812a /render/gles2
parent57b18d26d09f5219fe0458dcdd06fd2c817c294e (diff)
render: Implement texture_preferred_read_format
Diffstat (limited to 'render/gles2')
-rw-r--r--render/gles2/texture.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index b2421d07..1cfd7bab 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -195,6 +195,8 @@ static bool gles2_texture_read_pixels(struct wlr_texture *wlr_texture,
}
push_gles2_debug(texture->renderer);
+ struct wlr_egl_context prev_ctx;
+ wlr_egl_save_context(&prev_ctx);
if (!wlr_egl_make_current(texture->renderer->egl)) {
return false;
@@ -228,15 +230,58 @@ static bool gles2_texture_read_pixels(struct wlr_texture *wlr_texture,
}
}
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ wlr_egl_restore_context(&prev_ctx);
pop_gles2_debug(texture->renderer);
return glGetError() == GL_NO_ERROR;
}
+static uint32_t gles2_texture_preferred_read_format(struct wlr_texture *wlr_texture) {
+ struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
+
+ push_gles2_debug(texture->renderer);
+ struct wlr_egl_context prev_ctx;
+ wlr_egl_save_context(&prev_ctx);
+
+ uint32_t fmt = DRM_FORMAT_INVALID;
+
+ if (!wlr_egl_make_current(texture->renderer->egl)) {
+ goto out;
+ }
+
+ if (!gles2_texture_bind(texture)) {
+ goto out;
+ }
+
+ GLint gl_format = -1, gl_type = -1, alpha_size = -1;
+ glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_format);
+ glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_type);
+ glGetIntegerv(GL_ALPHA_BITS, &alpha_size);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ pop_gles2_debug(texture->renderer);
+
+ const struct wlr_gles2_pixel_format *pix_fmt =
+ get_gles2_format_from_gl(gl_format, gl_type, alpha_size > 0);
+ if (pix_fmt != NULL) {
+ fmt = pix_fmt->drm_format;
+ goto out;
+ }
+
+ if (texture->renderer->exts.EXT_read_format_bgra) {
+ fmt = DRM_FORMAT_XRGB8888;
+ goto out;
+ }
+
+out:
+ wlr_egl_restore_context(&prev_ctx);
+ return fmt;
+}
+
static const struct wlr_texture_impl texture_impl = {
.update_from_buffer = gles2_texture_update_from_buffer,
.read_pixels = gles2_texture_read_pixels,
+ .preferred_read_format = gles2_texture_preferred_read_format,
.destroy = handle_gles2_texture_destroy,
};