From 08293c872173d0f596dfaa57aad449944c60c1d7 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 21 Jul 2021 17:29:46 +1000 Subject: [PATCH] [egl] damage: only update the damage vbo if there was a new frame --- client/renderers/EGL/damage.c | 44 ++++++++++++++++++++--------------- client/renderers/EGL/egl.c | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/client/renderers/EGL/damage.c b/client/renderers/EGL/damage.c index 9684f414..e63bc3fb 100644 --- a/client/renderers/EGL/damage.c +++ b/client/renderers/EGL/damage.c @@ -40,6 +40,7 @@ struct EGL_Damage GLfloat transform[6]; GLuint buffers[2]; GLuint vao; + int count; bool show; KeybindHandle toggleHandle; @@ -109,6 +110,7 @@ bool egl_damage_init(EGL_Damage ** damage) glBindVertexArray(0); + (*damage)->count = -1; (*damage)->uTransform = egl_shader_get_uniform_location((*damage)->shader, "transform"); (*damage)->toggleHandle = app_registerKeybind(KEY_A, egl_damage_show_toggle, *damage, "Toggle damage display"); @@ -170,10 +172,9 @@ inline static void rectToVertices(GLfloat * vertex, const FrameDamageRect * rect bool egl_damage_render(EGL_Damage * damage, const struct DesktopDamage * data) { - if (!damage->show || !data) + if (!damage->show || (!data && damage->count == -1)) return false; - int count = data->count; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -181,27 +182,32 @@ bool egl_damage_render(EGL_Damage * damage, const struct DesktopDamage * data) egl_shader_use(damage->shader); glUniformMatrix3x2fv(damage->uTransform, 1, GL_FALSE, damage->transform); - GLfloat vertices[KVMFR_MAX_DAMAGE_RECTS * 8]; - if (count == 0) + if (data) { - FrameDamageRect full = { - .x = 0, .y = 0, .width = damage->width, .height = damage->height, - }; - count = 1; - rectToVertices(vertices, &full); - } - else - { - for (int i = 0; i < count; ++i) - rectToVertices(vertices + i * 8, data->rects + i); - } + damage->count = data->count; + GLfloat vertices[KVMFR_MAX_DAMAGE_RECTS * 8]; + if (damage->count == 0) + { + FrameDamageRect full = { + .x = 0, .y = 0, .width = damage->width, .height = damage->height, + }; + damage->count = 1; + rectToVertices(vertices, &full); + } + else + { + for (int i = 0; i < damage->count; ++i) + rectToVertices(vertices + i * 8, data->rects + i); + } - glBindBuffer(GL_ARRAY_BUFFER, damage->buffers[0]); - glBufferSubData(GL_ARRAY_BUFFER, 0, count * 8 * sizeof(GLfloat), vertices); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, damage->buffers[0]); + glBufferSubData(GL_ARRAY_BUFFER, 0, damage->count * 8 * sizeof(GLfloat), + vertices); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } glBindVertexArray(damage->vao); - glDrawElements(GL_TRIANGLES, 6 * count, GL_UNSIGNED_SHORT, NULL); + glDrawElements(GL_TRIANGLES, 6 * damage->count, GL_UNSIGNED_SHORT, NULL); glBindVertexArray(0); glDisable(GL_BLEND); diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index bba045d1..77273689 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -1005,7 +1005,7 @@ bool egl_render(void * opaque, LG_RendererRotate rotate, const bool newFrame) } hasOverlay |= egl_help_render(this->help, this->screenScaleX, this->screenScaleY); - hasOverlay |= egl_damage_render(this->damage, desktopDamage); + hasOverlay |= egl_damage_render(this->damage, newFrame ? desktopDamage : NULL); if (app_renderImGui()) {