mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 00:28:20 +00:00
[client] renderers: remove alert handling
This commit is contained in:
parent
be44249c05
commit
dd0edc1394
@ -35,7 +35,6 @@
|
||||
(x)->on_resize && \
|
||||
(x)->on_mouse_shape && \
|
||||
(x)->on_mouse_event && \
|
||||
(x)->on_alert && \
|
||||
(x)->render_startup && \
|
||||
(x)->render)
|
||||
|
||||
@ -112,7 +111,6 @@ typedef bool (* LG_RendererOnMouseShape )(void * opaque, const LG_Render
|
||||
typedef bool (* LG_RendererOnMouseEvent )(void * opaque, const bool visible , const int x, const int y);
|
||||
typedef bool (* LG_RendererOnFrameFormat)(void * opaque, const LG_RendererFormat format, bool useDMA);
|
||||
typedef bool (* LG_RendererOnFrame )(void * opaque, const FrameBuffer * frame, int dmaFD, const FrameDamageRect * damage, int damageCount);
|
||||
typedef void (* LG_RendererOnAlert )(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag);
|
||||
typedef bool (* LG_RendererRenderStartup)(void * opaque);
|
||||
typedef bool (* LG_RendererRender )(void * opaque, LG_RendererRotate rotate, const bool newFrame);
|
||||
|
||||
@ -131,7 +129,6 @@ typedef struct LG_Renderer
|
||||
LG_RendererOnMouseEvent on_mouse_event;
|
||||
LG_RendererOnFrameFormat on_frame_format;
|
||||
LG_RendererOnFrame on_frame;
|
||||
LG_RendererOnAlert on_alert;
|
||||
LG_RendererRenderStartup render_startup;
|
||||
LG_RendererRender render;
|
||||
}
|
||||
|
@ -21,9 +21,6 @@ make_object(
|
||||
shader/cursor_mono.frag
|
||||
shader/damage.vert
|
||||
shader/damage.frag
|
||||
shader/alert.vert
|
||||
shader/alert.frag
|
||||
shader/alert_bg.frag
|
||||
shader/splash_bg.vert
|
||||
shader/splash_bg.frag
|
||||
shader/splash_logo.vert
|
||||
@ -45,7 +42,6 @@ add_library(renderer_EGL STATIC
|
||||
cursor.c
|
||||
draw.c
|
||||
splash.c
|
||||
alert.c
|
||||
damage.c
|
||||
${EGL_SHADER_OBJS}
|
||||
"${EGL_SHADER_INCS}/desktop_rgb.def.h"
|
||||
|
@ -1,227 +0,0 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright (C) 2017-2021 The Looking Glass Authors
|
||||
* 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 "alert.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/locking.h"
|
||||
|
||||
#include "texture.h"
|
||||
#include "shader.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// these headers are auto generated by cmake
|
||||
#include "alert.vert.h"
|
||||
#include "alert.frag.h"
|
||||
#include "alert_bg.frag.h"
|
||||
|
||||
struct EGL_Alert
|
||||
{
|
||||
const LG_Font * font;
|
||||
LG_FontObj fontObj;
|
||||
|
||||
EGL_Texture * texture;
|
||||
EGL_Shader * shader;
|
||||
EGL_Shader * shaderBG;
|
||||
EGL_Model * model;
|
||||
|
||||
LG_Lock lock;
|
||||
bool update;
|
||||
LG_FontBitmap * bmp;
|
||||
|
||||
bool ready;
|
||||
float width , height ;
|
||||
float bgWidth, bgHeight;
|
||||
float r, g, b, a;
|
||||
|
||||
// uniforms
|
||||
GLint uScreen , uSize;
|
||||
GLint uScreenBG, uSizeBG, uColorBG;
|
||||
};
|
||||
|
||||
bool egl_alert_init(EGL_Alert ** alert, const LG_Font * font, LG_FontObj fontObj)
|
||||
{
|
||||
*alert = (EGL_Alert *)malloc(sizeof(EGL_Alert));
|
||||
if (!*alert)
|
||||
{
|
||||
DEBUG_ERROR("Failed to malloc EGL_Alert");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(*alert, 0, sizeof(EGL_Alert));
|
||||
|
||||
(*alert)->font = font;
|
||||
(*alert)->fontObj = fontObj;
|
||||
LG_LOCK_INIT((*alert)->lock);
|
||||
|
||||
if (!egl_texture_init(&(*alert)->texture, NULL))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the alert texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_shader_init(&(*alert)->shader))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the alert shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_shader_init(&(*alert)->shaderBG))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the alert bg shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!egl_shader_compile((*alert)->shader,
|
||||
b_shader_alert_vert, b_shader_alert_vert_size,
|
||||
b_shader_alert_frag, b_shader_alert_frag_size))
|
||||
{
|
||||
DEBUG_ERROR("Failed to compile the alert shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_shader_compile((*alert)->shaderBG,
|
||||
b_shader_alert_vert , b_shader_alert_vert_size,
|
||||
b_shader_alert_bg_frag, b_shader_alert_bg_frag_size))
|
||||
{
|
||||
DEBUG_ERROR("Failed to compile the alert shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
(*alert)->uSize = egl_shader_get_uniform_location((*alert)->shader , "size" );
|
||||
(*alert)->uScreen = egl_shader_get_uniform_location((*alert)->shader , "screen");
|
||||
(*alert)->uSizeBG = egl_shader_get_uniform_location((*alert)->shaderBG, "size" );
|
||||
(*alert)->uScreenBG = egl_shader_get_uniform_location((*alert)->shaderBG, "screen");
|
||||
(*alert)->uColorBG = egl_shader_get_uniform_location((*alert)->shaderBG, "color" );
|
||||
|
||||
if (!egl_model_init(&(*alert)->model))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the alert model");
|
||||
return false;
|
||||
}
|
||||
|
||||
egl_model_set_default((*alert)->model);
|
||||
egl_model_set_texture((*alert)->model, (*alert)->texture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void egl_alert_free(EGL_Alert ** alert)
|
||||
{
|
||||
if (!*alert)
|
||||
return;
|
||||
|
||||
egl_texture_free(&(*alert)->texture );
|
||||
egl_shader_free (&(*alert)->shader );
|
||||
egl_shader_free (&(*alert)->shaderBG);
|
||||
egl_model_free (&(*alert)->model );
|
||||
|
||||
free(*alert);
|
||||
*alert = NULL;
|
||||
}
|
||||
|
||||
void egl_alert_set_color(EGL_Alert * alert, const uint32_t color)
|
||||
{
|
||||
alert->r = (1.0f / 0xff) * ((color >> 24) & 0xFF);
|
||||
alert->g = (1.0f / 0xff) * ((color >> 16) & 0xFF);
|
||||
alert->b = (1.0f / 0xff) * ((color >> 8) & 0xFF);
|
||||
alert->a = (1.0f / 0xff) * ((color >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
void egl_alert_set_text (EGL_Alert * alert, const char * str)
|
||||
{
|
||||
LG_LOCK(alert->lock);
|
||||
alert->bmp = alert->font->render(alert->fontObj, 0xffffff00, str);
|
||||
if (!alert->bmp)
|
||||
{
|
||||
alert->update = false;
|
||||
LG_UNLOCK(alert->lock);
|
||||
DEBUG_ERROR("Failed to render alert text");
|
||||
return;
|
||||
}
|
||||
|
||||
alert->update = true;
|
||||
LG_UNLOCK(alert->lock);
|
||||
}
|
||||
|
||||
void egl_alert_set_font(EGL_Alert * alert, LG_Font * fontObj)
|
||||
{
|
||||
LG_LOCK(alert->lock);
|
||||
alert->fontObj = fontObj;
|
||||
LG_UNLOCK(alert->lock);
|
||||
}
|
||||
|
||||
void egl_alert_render(EGL_Alert * alert, const float scaleX, const float scaleY)
|
||||
{
|
||||
if (alert->update)
|
||||
{
|
||||
LG_LOCK(alert->lock);
|
||||
egl_texture_setup(
|
||||
alert->texture,
|
||||
EGL_PF_BGRA,
|
||||
alert->bmp->width ,
|
||||
alert->bmp->height,
|
||||
alert->bmp->width * alert->bmp->bpp,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
egl_texture_update(alert->texture, alert->bmp->pixels);
|
||||
|
||||
alert->width = alert->bgWidth = alert->bmp->width;
|
||||
alert->height = alert->bgHeight = alert->bmp->height;
|
||||
|
||||
if (alert->bgWidth < 200)
|
||||
alert->bgWidth = 200;
|
||||
alert->bgHeight += 4;
|
||||
|
||||
alert->ready = true;
|
||||
|
||||
alert->font->release(alert->fontObj, alert->bmp);
|
||||
alert->update = false;
|
||||
alert->bmp = NULL;
|
||||
LG_UNLOCK(alert->lock);
|
||||
}
|
||||
|
||||
if (!alert->ready)
|
||||
return;
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// render the background first
|
||||
egl_shader_use(alert->shaderBG);
|
||||
glUniform2f(alert->uScreenBG, scaleX , scaleY );
|
||||
glUniform2i(alert->uSizeBG , alert->bgWidth, alert->bgHeight);
|
||||
glUniform4f(alert->uColorBG , alert->r, alert->g, alert->b, alert->a);
|
||||
egl_model_render(alert->model);
|
||||
|
||||
// render the texture over the background
|
||||
egl_shader_use(alert->shader);
|
||||
glUniform2f(alert->uScreen, scaleX , scaleY );
|
||||
glUniform2i(alert->uSize , alert->width, alert->height);
|
||||
egl_model_render(alert->model);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright (C) 2017-2021 The Looking Glass Authors
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "interface/font.h"
|
||||
|
||||
typedef struct EGL_Alert EGL_Alert;
|
||||
|
||||
bool egl_alert_init(EGL_Alert ** alert, const LG_Font * font, LG_FontObj fontObj);
|
||||
void egl_alert_free(EGL_Alert ** alert);
|
||||
|
||||
void egl_alert_set_color(EGL_Alert * alert, const uint32_t color);
|
||||
void egl_alert_set_text (EGL_Alert * alert, const char * str);
|
||||
void egl_alert_set_font (EGL_Alert * alert, LG_Font * fontObj);
|
||||
void egl_alert_render (EGL_Alert * alert, const float scaleX, const float scaleY);
|
@ -48,10 +48,8 @@
|
||||
#include "desktop.h"
|
||||
#include "cursor.h"
|
||||
#include "splash.h"
|
||||
#include "alert.h"
|
||||
|
||||
#define SPLASH_FADE_TIME 1000000
|
||||
#define ALERT_TIMEOUT 2000000
|
||||
|
||||
struct Options
|
||||
{
|
||||
@ -74,7 +72,6 @@ struct Inst
|
||||
EGL_Desktop * desktop; // the desktop
|
||||
EGL_Cursor * cursor; // the mouse cursor
|
||||
EGL_Splash * splash; // the splash screen
|
||||
EGL_Alert * alert; // the alert display
|
||||
EGL_Damage * damage; // the damage display
|
||||
bool imgui; // if imgui was initialized
|
||||
|
||||
@ -84,12 +81,6 @@ struct Inst
|
||||
uint64_t waitFadeTime;
|
||||
bool waitDone;
|
||||
|
||||
bool showAlert;
|
||||
uint64_t alertTimeout;
|
||||
bool useCloseFlag;
|
||||
bool closeFlag;
|
||||
bool showDamage;
|
||||
|
||||
int width, height;
|
||||
float uiScale;
|
||||
LG_RendererRect destRect;
|
||||
@ -103,10 +94,11 @@ struct Inst
|
||||
int viewportWidth, viewportHeight;
|
||||
enum EGL_DesktopScaleType scaleType;
|
||||
|
||||
bool cursorVisible;
|
||||
int cursorX , cursorY;
|
||||
float mouseWidth , mouseHeight;
|
||||
float mouseScaleX, mouseScaleY;
|
||||
bool cursorVisible;
|
||||
int cursorX , cursorY;
|
||||
float mouseWidth , mouseHeight;
|
||||
float mouseScaleX, mouseScaleY;
|
||||
bool showDamage;
|
||||
|
||||
const LG_Font * font;
|
||||
LG_FontObj fontObj;
|
||||
@ -205,9 +197,6 @@ static bool egl_update_font(struct Inst * this)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->alert)
|
||||
egl_alert_set_font(this->alert, fontObj);
|
||||
|
||||
if (this->fontObj)
|
||||
this->font->destroy(this->fontObj);
|
||||
this->fontObj = fontObj;
|
||||
@ -277,7 +266,6 @@ void egl_deinitialize(void * opaque)
|
||||
egl_desktop_free(&this->desktop);
|
||||
egl_cursor_free (&this->cursor);
|
||||
egl_splash_free (&this->splash);
|
||||
egl_alert_free (&this->alert );
|
||||
egl_damage_free (&this->damage);
|
||||
|
||||
LG_LOCK_FREE(this->lock);
|
||||
@ -564,41 +552,6 @@ bool egl_on_frame(void * opaque, const FrameBuffer * frame, int dmaFd,
|
||||
return true;
|
||||
}
|
||||
|
||||
void egl_on_alert(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
|
||||
static const uint32_t colors[] =
|
||||
{
|
||||
0x0000CCCC, // LG_ALERT_INFO
|
||||
0x00CC00CC, // LG_ALERT_SUCCESS
|
||||
0xCC7F00CC, // LG_ALERT_WARNING
|
||||
0xFF0000CC // LG_ALERT_ERROR
|
||||
};
|
||||
|
||||
if (alert > LG_ALERT_ERROR || alert < 0)
|
||||
{
|
||||
DEBUG_ERROR("Invalid alert value");
|
||||
return;
|
||||
}
|
||||
|
||||
egl_alert_set_color(this->alert, colors[alert]);
|
||||
egl_alert_set_text (this->alert, message );
|
||||
|
||||
if (closeFlag)
|
||||
{
|
||||
this->useCloseFlag = true;
|
||||
*closeFlag = &this->closeFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->useCloseFlag = false;
|
||||
this->alertTimeout = microtime() + ALERT_TIMEOUT;
|
||||
}
|
||||
|
||||
this->showAlert = true;
|
||||
}
|
||||
|
||||
static void debugCallback(GLenum source, GLenum type, GLuint id,
|
||||
GLenum severity, GLsizei length, const GLchar * message,
|
||||
const void * userParam)
|
||||
@ -858,12 +811,6 @@ bool egl_render_startup(void * opaque)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_alert_init(&this->alert, this->font, this->fontObj))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the alert display");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_damage_init(&this->damage))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the damage display");
|
||||
@ -944,23 +891,6 @@ bool egl_render(void * opaque, LG_RendererRotate rotate, const bool newFrame)
|
||||
hasOverlay = true;
|
||||
}
|
||||
|
||||
if (this->showAlert)
|
||||
{
|
||||
bool close = false;
|
||||
if (this->useCloseFlag)
|
||||
close = this->closeFlag;
|
||||
else if (this->alertTimeout < microtime())
|
||||
close = true;
|
||||
|
||||
if (close)
|
||||
this->showAlert = false;
|
||||
else
|
||||
{
|
||||
egl_alert_render(this->alert, this->screenScaleX, this->screenScaleY);
|
||||
hasOverlay = true;
|
||||
}
|
||||
}
|
||||
|
||||
hasOverlay |= egl_damage_render(this->damage, newFrame ? desktopDamage : NULL);
|
||||
|
||||
struct Rect damage[KVMFR_MAX_DAMAGE_RECTS + MAX_OVERLAY_RECTS + 2];
|
||||
@ -1040,7 +970,6 @@ struct LG_Renderer LGR_EGL =
|
||||
.on_mouse_event = egl_on_mouse_event,
|
||||
.on_frame_format = egl_on_frame_format,
|
||||
.on_frame = egl_on_frame,
|
||||
.on_alert = egl_on_alert,
|
||||
.render_startup = egl_render_startup,
|
||||
.render = egl_render
|
||||
};
|
||||
|
@ -1,12 +0,0 @@
|
||||
#version 300 es
|
||||
|
||||
in highp vec2 uv;
|
||||
in highp vec2 sz;
|
||||
out highp vec4 color;
|
||||
|
||||
uniform sampler2D sampler1;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = texelFetch(sampler1, ivec2(uv * sz), 0);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#version 300 es
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
|
||||
uniform vec2 screen;
|
||||
uniform ivec2 size;
|
||||
uniform vec4 color;
|
||||
|
||||
out highp vec2 uv;
|
||||
out highp vec2 sz;
|
||||
out highp vec4 c;
|
||||
|
||||
void main()
|
||||
{
|
||||
sz = vec2(size) + 0.5;
|
||||
|
||||
gl_Position.xyz = vertexPosition_modelspace;
|
||||
gl_Position.w = 1.0;
|
||||
gl_Position.xy *= screen.xy * sz;
|
||||
|
||||
uv = vertexUV;
|
||||
c = color;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#version 300 es
|
||||
|
||||
in highp vec4 c;
|
||||
out highp vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = c;
|
||||
}
|
@ -42,10 +42,7 @@
|
||||
|
||||
#define FPS_TEXTURE 0
|
||||
#define MOUSE_TEXTURE 1
|
||||
#define ALERT_TEXTURE 2
|
||||
#define TEXTURE_COUNT 3
|
||||
|
||||
#define ALERT_TIMEOUT_FLAG ((uint64_t)-1)
|
||||
#define TEXTURE_COUNT 2
|
||||
|
||||
#define FADE_TIME 1000000
|
||||
|
||||
@ -104,17 +101,6 @@ struct OpenGL_Options
|
||||
bool amdPinnedMem;
|
||||
};
|
||||
|
||||
struct Alert
|
||||
{
|
||||
bool ready;
|
||||
bool useCloseFlag;
|
||||
|
||||
LG_FontBitmap *text;
|
||||
float r, g, b, a;
|
||||
uint64_t timeout;
|
||||
bool closeFlag;
|
||||
};
|
||||
|
||||
struct Inst
|
||||
{
|
||||
LG_RendererParams params;
|
||||
@ -131,7 +117,7 @@ struct Inst
|
||||
_Atomic(bool) frameUpdate;
|
||||
|
||||
const LG_Font * font;
|
||||
LG_FontObj fontObj, alertFontObj;
|
||||
LG_FontObj fontObj;
|
||||
|
||||
LG_Lock formatLock;
|
||||
LG_RendererFormat format;
|
||||
@ -157,8 +143,6 @@ struct Inst
|
||||
GLuint frames[BUFFER_COUNT];
|
||||
GLsync fences[BUFFER_COUNT];
|
||||
GLuint textures[TEXTURE_COUNT];
|
||||
struct ll * alerts;
|
||||
int alertList;
|
||||
|
||||
bool waiting;
|
||||
uint64_t waitFadeTime;
|
||||
@ -238,14 +222,6 @@ bool opengl_create(void ** opaque, const LG_RendererParams params,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->font->create(&this->alertFontObj, NULL, 18))
|
||||
{
|
||||
DEBUG_ERROR("Unable to create the font renderer");
|
||||
return false;
|
||||
}
|
||||
|
||||
this->alerts = ll_new();
|
||||
|
||||
*needsOpenGL = true;
|
||||
return true;
|
||||
}
|
||||
@ -273,7 +249,6 @@ void opengl_deinitialize(void * opaque)
|
||||
|
||||
glDeleteLists(this->texList , BUFFER_COUNT);
|
||||
glDeleteLists(this->mouseList, 1);
|
||||
glDeleteLists(this->alertList, 1);
|
||||
}
|
||||
|
||||
deconfigure(this);
|
||||
@ -297,15 +272,6 @@ void opengl_deinitialize(void * opaque)
|
||||
LG_LOCK_FREE(this->frameLock );
|
||||
LG_LOCK_FREE(this->mouseLock );
|
||||
|
||||
struct Alert * alert;
|
||||
while(ll_shift(this->alerts, (void **)&alert))
|
||||
{
|
||||
if (alert->text)
|
||||
this->font->release(this->alertFontObj, alert->text);
|
||||
free(alert);
|
||||
}
|
||||
ll_free(this->alerts);
|
||||
|
||||
if (this->font && this->fontObj)
|
||||
this->font->destroy(this->fontObj);
|
||||
|
||||
@ -441,59 +407,6 @@ bool opengl_on_frame(void * opaque, const FrameBuffer * frame, int dmaFd,
|
||||
return true;
|
||||
}
|
||||
|
||||
void opengl_on_alert(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
struct Alert * a = malloc(sizeof(struct Alert));
|
||||
memset(a, 0, sizeof(struct Alert));
|
||||
|
||||
switch(alert)
|
||||
{
|
||||
case LG_ALERT_INFO:
|
||||
a->r = 0.0f;
|
||||
a->g = 0.0f;
|
||||
a->b = 0.8f;
|
||||
a->a = 0.8f;
|
||||
break;
|
||||
|
||||
case LG_ALERT_SUCCESS:
|
||||
a->r = 0.0f;
|
||||
a->g = 0.8f;
|
||||
a->b = 0.0f;
|
||||
a->a = 0.8f;
|
||||
break;
|
||||
|
||||
case LG_ALERT_WARNING:
|
||||
a->r = 0.8f;
|
||||
a->g = 0.5f;
|
||||
a->b = 0.0f;
|
||||
a->a = 0.8f;
|
||||
break;
|
||||
|
||||
case LG_ALERT_ERROR:
|
||||
a->r = 1.0f;
|
||||
a->g = 0.0f;
|
||||
a->b = 0.0f;
|
||||
a->a = 0.8f;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(a->text = this->font->render(this->alertFontObj, 0xffffff00, message)))
|
||||
{
|
||||
DEBUG_ERROR("Failed to render alert text");
|
||||
free(a);
|
||||
return;
|
||||
}
|
||||
|
||||
if (closeFlag)
|
||||
{
|
||||
a->useCloseFlag = true;
|
||||
*closeFlag = &a->closeFlag;
|
||||
}
|
||||
|
||||
ll_push(this->alerts, a);
|
||||
}
|
||||
|
||||
void bitmap_to_texture(LG_FontBitmap * bitmap, GLuint texture)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D , texture );
|
||||
@ -560,7 +473,6 @@ bool opengl_render_startup(void * opaque)
|
||||
// generate lists for drawing
|
||||
this->texList = glGenLists(BUFFER_COUNT);
|
||||
this->mouseList = glGenLists(1);
|
||||
this->alertList = glGenLists(1);
|
||||
|
||||
// create the overlay textures
|
||||
glGenTextures(TEXTURE_COUNT, this->textures);
|
||||
@ -617,74 +529,6 @@ bool opengl_render(void * opaque, LG_RendererRotate rotate, const bool newFrame)
|
||||
render_wait(this);
|
||||
}
|
||||
|
||||
struct Alert * alert;
|
||||
while(ll_peek_head(this->alerts, (void **)&alert))
|
||||
{
|
||||
if (!alert->ready)
|
||||
{
|
||||
bitmap_to_texture(alert->text, this->textures[ALERT_TEXTURE]);
|
||||
|
||||
glNewList(this->alertList, GL_COMPILE);
|
||||
const int p = 4;
|
||||
const int w = alert->text->width + p * 2;
|
||||
const int h = alert->text->height + p * 2;
|
||||
glTranslatef(-(w / 2), -(h / 2), 0.0f);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4f(alert->r, alert->g, alert->b, alert->a);
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glVertex2i(0, 0);
|
||||
glVertex2i(w, 0);
|
||||
glVertex2i(0, h);
|
||||
glVertex2i(w, h);
|
||||
glEnd();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, this->textures[ALERT_TEXTURE]);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glTranslatef(p, p, 0.0f);
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex2i(0 , 0 );
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex2i(alert->text->width, 0 );
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex2i(0 , alert->text->height);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex2i(alert->text->width, alert->text->height);
|
||||
glEnd();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_BLEND);
|
||||
glEndList();
|
||||
|
||||
if (!alert->useCloseFlag)
|
||||
alert->timeout = microtime() + 2*1000000;
|
||||
alert->ready = true;
|
||||
|
||||
this->font->release(this->fontObj, alert->text);
|
||||
alert->text = NULL;
|
||||
alert->ready = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool close = false;
|
||||
if (alert->useCloseFlag)
|
||||
close = alert->closeFlag;
|
||||
else if (alert->timeout < microtime())
|
||||
close = true;
|
||||
|
||||
if (close)
|
||||
{
|
||||
free(alert);
|
||||
ll_shift(this->alerts, NULL);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef(this->window.x / 2, this->window.y / 2, 0.0f);
|
||||
glScalef(this->uiScale, this->uiScale, 1.0f);
|
||||
glCallList(this->alertList);
|
||||
glPopMatrix();
|
||||
break;
|
||||
}
|
||||
|
||||
if (app_renderOverlay(NULL, 0) != 0)
|
||||
{
|
||||
ImGui_ImplOpenGL2_NewFrame();
|
||||
@ -811,7 +655,6 @@ const LG_Renderer LGR_OpenGL =
|
||||
.on_mouse_event = opengl_on_mouse_event,
|
||||
.on_frame_format = opengl_on_frame_format,
|
||||
.on_frame = opengl_on_frame,
|
||||
.on_alert = opengl_on_alert,
|
||||
.render_startup = opengl_render_startup,
|
||||
.render = opengl_render
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user