[egl] damage: only update the damage vbo if there was a new frame

This commit is contained in:
Geoffrey McRae 2021-07-21 17:29:46 +10:00
parent 6389a06903
commit 08293c8721
2 changed files with 26 additions and 20 deletions

View File

@ -40,6 +40,7 @@ struct EGL_Damage
GLfloat transform[6]; GLfloat transform[6];
GLuint buffers[2]; GLuint buffers[2];
GLuint vao; GLuint vao;
int count;
bool show; bool show;
KeybindHandle toggleHandle; KeybindHandle toggleHandle;
@ -109,6 +110,7 @@ bool egl_damage_init(EGL_Damage ** damage)
glBindVertexArray(0); glBindVertexArray(0);
(*damage)->count = -1;
(*damage)->uTransform = egl_shader_get_uniform_location((*damage)->shader, "transform"); (*damage)->uTransform = egl_shader_get_uniform_location((*damage)->shader, "transform");
(*damage)->toggleHandle = app_registerKeybind(KEY_A, egl_damage_show_toggle, *damage, "Toggle damage display"); (*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) bool egl_damage_render(EGL_Damage * damage, const struct DesktopDamage * data)
{ {
if (!damage->show || !data) if (!damage->show || (!data && damage->count == -1))
return false; return false;
int count = data->count;
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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); egl_shader_use(damage->shader);
glUniformMatrix3x2fv(damage->uTransform, 1, GL_FALSE, damage->transform); glUniformMatrix3x2fv(damage->uTransform, 1, GL_FALSE, damage->transform);
if (data)
{
damage->count = data->count;
GLfloat vertices[KVMFR_MAX_DAMAGE_RECTS * 8]; GLfloat vertices[KVMFR_MAX_DAMAGE_RECTS * 8];
if (count == 0) if (damage->count == 0)
{ {
FrameDamageRect full = { FrameDamageRect full = {
.x = 0, .y = 0, .width = damage->width, .height = damage->height, .x = 0, .y = 0, .width = damage->width, .height = damage->height,
}; };
count = 1; damage->count = 1;
rectToVertices(vertices, &full); rectToVertices(vertices, &full);
} }
else else
{ {
for (int i = 0; i < count; ++i) for (int i = 0; i < damage->count; ++i)
rectToVertices(vertices + i * 8, data->rects + i); rectToVertices(vertices + i * 8, data->rects + i);
} }
glBindBuffer(GL_ARRAY_BUFFER, damage->buffers[0]); glBindBuffer(GL_ARRAY_BUFFER, damage->buffers[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * 8 * sizeof(GLfloat), vertices); glBufferSubData(GL_ARRAY_BUFFER, 0, damage->count * 8 * sizeof(GLfloat),
vertices);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
}
glBindVertexArray(damage->vao); glBindVertexArray(damage->vao);
glDrawElements(GL_TRIANGLES, 6 * count, GL_UNSIGNED_SHORT, NULL); glDrawElements(GL_TRIANGLES, 6 * damage->count, GL_UNSIGNED_SHORT, NULL);
glBindVertexArray(0); glBindVertexArray(0);
glDisable(GL_BLEND); glDisable(GL_BLEND);

View File

@ -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_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()) if (app_renderImGui())
{ {