2021-07-15 10:04:25 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2021-08-04 09:48:32 +00:00
|
|
|
* Copyright © 2017-2021 The Looking Glass Authors
|
2021-07-15 10:04:25 +00:00
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "damage.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/KVMFR.h"
|
|
|
|
#include "common/locking.h"
|
|
|
|
|
|
|
|
#include "app.h"
|
2021-08-02 22:40:19 +00:00
|
|
|
#include "desktop_rects.h"
|
2021-07-15 10:04:25 +00:00
|
|
|
#include "shader.h"
|
2021-08-04 14:55:51 +00:00
|
|
|
#include "cimgui.h"
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
// these headers are auto generated by cmake
|
|
|
|
#include "damage.vert.h"
|
|
|
|
#include "damage.frag.h"
|
|
|
|
|
|
|
|
struct EGL_Damage
|
|
|
|
{
|
2021-08-02 22:40:19 +00:00
|
|
|
EGL_Shader * shader;
|
|
|
|
EGL_DesktopRects * mesh;
|
|
|
|
GLfloat transform[6];
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
bool show;
|
|
|
|
|
|
|
|
int width , height;
|
|
|
|
float translateX, translateY;
|
|
|
|
float scaleX , scaleY;
|
2021-08-02 22:40:19 +00:00
|
|
|
LG_RendererRotate rotate;
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
// uniforms
|
|
|
|
GLint uTransform;
|
|
|
|
};
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_damageConfigUI(EGL_Damage * damage)
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
2021-08-04 14:55:51 +00:00
|
|
|
igCheckbox("Show damage overlay", &damage->show);
|
2021-07-15 10:04:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_damageInit(EGL_Damage ** damage)
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
2021-08-15 22:55:19 +00:00
|
|
|
*damage = malloc(sizeof(**damage));
|
2021-07-15 10:04:25 +00:00
|
|
|
if (!*damage)
|
|
|
|
{
|
2021-08-02 22:40:19 +00:00
|
|
|
DEBUG_ERROR("Failed to malloc EGL_Damage");
|
2021-07-15 10:04:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(*damage, 0, sizeof(EGL_Damage));
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_shaderInit(&(*damage)->shader))
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the damage shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_shaderCompile((*damage)->shader,
|
2021-07-15 10:04:25 +00:00
|
|
|
b_shader_damage_vert, b_shader_damage_vert_size,
|
|
|
|
b_shader_damage_frag, b_shader_damage_frag_size))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to compile the damage shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:40:19 +00:00
|
|
|
if (!egl_desktopRectsInit(&(*damage)->mesh, KVMFR_MAX_DAMAGE_RECTS))
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
2021-08-02 22:40:19 +00:00
|
|
|
DEBUG_ERROR("Failed to initialize the mesh");
|
|
|
|
return false;
|
2021-07-15 10:04:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
(*damage)->uTransform = egl_shaderGetUniform((*damage)->shader, "transform");
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_damageFree(EGL_Damage ** damage)
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
|
|
|
if (!*damage)
|
|
|
|
return;
|
|
|
|
|
2021-08-02 22:40:19 +00:00
|
|
|
egl_desktopRectsFree(&(*damage)->mesh);
|
2021-08-08 07:16:10 +00:00
|
|
|
egl_shaderFree(&(*damage)->shader);
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
free(*damage);
|
|
|
|
*damage = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_matrix(EGL_Damage * damage)
|
|
|
|
{
|
2021-08-02 22:40:19 +00:00
|
|
|
egl_desktopRectsMatrix(damage->transform, damage->width, damage->height,
|
|
|
|
damage->translateX, damage->translateY, damage->scaleX, damage->scaleY, damage->rotate);
|
2021-07-15 10:04:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_damageSetup(EGL_Damage * damage, int width, int height)
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
|
|
|
damage->width = width;
|
|
|
|
damage->height = height;
|
|
|
|
update_matrix(damage);
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_damageResize(EGL_Damage * damage, float translateX, float translateY,
|
2021-07-15 10:04:25 +00:00
|
|
|
float scaleX, float scaleY)
|
|
|
|
{
|
|
|
|
damage->translateX = translateX;
|
|
|
|
damage->translateY = translateY;
|
|
|
|
damage->scaleX = scaleX;
|
|
|
|
damage->scaleY = scaleY;
|
|
|
|
update_matrix(damage);
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_damageRender(EGL_Damage * damage, LG_RendererRotate rotate, const struct DesktopDamage * data)
|
2021-07-15 10:04:25 +00:00
|
|
|
{
|
2021-08-02 22:40:19 +00:00
|
|
|
if (!damage->show)
|
2021-07-15 10:04:25 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-25 06:35:28 +00:00
|
|
|
if (rotate != damage->rotate)
|
|
|
|
{
|
|
|
|
damage->rotate = rotate;
|
|
|
|
update_matrix(damage);
|
|
|
|
}
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
egl_shaderUse(damage->shader);
|
2021-07-15 10:04:25 +00:00
|
|
|
glUniformMatrix3x2fv(damage->uTransform, 1, GL_FALSE, damage->transform);
|
|
|
|
|
2021-08-02 01:01:24 +00:00
|
|
|
if (data && data->count != 0)
|
2021-08-02 22:40:19 +00:00
|
|
|
egl_desktopRectsUpdate(damage->mesh, (const struct DamageRects *) data,
|
|
|
|
damage->width, damage->height);
|
2021-07-18 04:06:32 +00:00
|
|
|
|
2021-08-02 22:40:19 +00:00
|
|
|
egl_desktopRectsRender(damage->mesh);
|
2021-07-15 10:04:25 +00:00
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
return true;
|
|
|
|
}
|