mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +01:00
render/gles2: save/restore context when creating/submitting a render pass
This is useful for e.g. lazily blitting a texture for readback purposes while rendering.
This commit is contained in:
parent
1208ba6c28
commit
e8b187cc92
4 changed files with 15 additions and 3 deletions
|
@ -15,6 +15,8 @@
|
|||
#include <wlr/util/addon.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#include "render/egl.h"
|
||||
|
||||
// mesa ships old GL headers that don't include this type, so for distros that use headers from
|
||||
// mesa we need to def it ourselves until they update.
|
||||
// https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23144
|
||||
|
@ -132,6 +134,7 @@ struct wlr_gles2_render_pass {
|
|||
struct wlr_render_pass base;
|
||||
struct wlr_gles2_buffer *buffer;
|
||||
float projection_matrix[9];
|
||||
struct wlr_egl_context prev_ctx;
|
||||
struct wlr_gles2_render_timer *timer;
|
||||
};
|
||||
|
||||
|
@ -164,6 +167,6 @@ void push_gles2_debug_(struct wlr_gles2_renderer *renderer,
|
|||
void pop_gles2_debug(struct wlr_gles2_renderer *renderer);
|
||||
|
||||
struct wlr_gles2_render_pass *begin_gles2_buffer_pass(struct wlr_gles2_buffer *buffer,
|
||||
struct wlr_gles2_render_timer *timer);
|
||||
struct wlr_egl_context *prev_ctx, struct wlr_gles2_render_timer *timer);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,10 @@ struct wlr_egl;
|
|||
* the current EGL is global state. The GLES2 renderer operations will save
|
||||
* and restore any previous EGL context when called. A render pass is seen as
|
||||
* a single operation.
|
||||
*
|
||||
* The GLES2 renderer doesn't support arbitrarily nested render passes. It
|
||||
* supports a subset only: after a nested render pass is created, any parent
|
||||
* render pass can't be used before the nested render pass is submitted.
|
||||
*/
|
||||
|
||||
struct wlr_renderer *wlr_gles2_renderer_create_with_drm_fd(int drm_fd);
|
||||
|
|
|
@ -41,6 +41,7 @@ static bool render_pass_submit(struct wlr_render_pass *wlr_pass) {
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
pop_gles2_debug(renderer);
|
||||
wlr_egl_restore_context(&pass->prev_ctx);
|
||||
|
||||
wlr_buffer_unlock(pass->buffer->buffer);
|
||||
free(pass);
|
||||
|
@ -247,7 +248,7 @@ static const char *reset_status_str(GLenum status) {
|
|||
}
|
||||
|
||||
struct wlr_gles2_render_pass *begin_gles2_buffer_pass(struct wlr_gles2_buffer *buffer,
|
||||
struct wlr_gles2_render_timer *timer) {
|
||||
struct wlr_egl_context *prev_ctx, struct wlr_gles2_render_timer *timer) {
|
||||
struct wlr_gles2_renderer *renderer = buffer->renderer;
|
||||
struct wlr_buffer *wlr_buffer = buffer->buffer;
|
||||
|
||||
|
@ -274,6 +275,7 @@ struct wlr_gles2_render_pass *begin_gles2_buffer_pass(struct wlr_gles2_buffer *b
|
|||
wlr_buffer_lock(wlr_buffer);
|
||||
pass->buffer = buffer;
|
||||
pass->timer = timer;
|
||||
pass->prev_ctx = *prev_ctx;
|
||||
|
||||
matrix_projection(pass->projection_matrix, wlr_buffer->width, wlr_buffer->height,
|
||||
WL_OUTPUT_TRANSFORM_FLIPPED_180);
|
||||
|
|
|
@ -433,6 +433,9 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
|
|||
static struct wlr_render_pass *gles2_begin_buffer_pass(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_buffer *wlr_buffer, const struct wlr_buffer_pass_options *options) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
struct wlr_egl_context prev_ctx = {0};
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
if (!wlr_egl_make_current(renderer->egl)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -448,7 +451,7 @@ static struct wlr_render_pass *gles2_begin_buffer_pass(struct wlr_renderer *wlr_
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_gles2_render_pass *pass = begin_gles2_buffer_pass(buffer, timer);
|
||||
struct wlr_gles2_render_pass *pass = begin_gles2_buffer_pass(buffer, &prev_ctx, timer);
|
||||
if (!pass) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue