mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-03-06 08:40:49 +00:00
[client] egl: corrected fps alpha blending
This commit is contained in:
parent
abfe3a9b4d
commit
42fa0e1d1f
1 changed files with 53 additions and 18 deletions
|
@ -35,13 +35,15 @@ struct EGL_FPS
|
||||||
|
|
||||||
EGL_Texture * texture;
|
EGL_Texture * texture;
|
||||||
EGL_Shader * shader;
|
EGL_Shader * shader;
|
||||||
|
EGL_Shader * shaderBG;
|
||||||
EGL_Model * model;
|
EGL_Model * model;
|
||||||
|
|
||||||
bool ready;
|
bool ready;
|
||||||
float width, height;
|
float width, height;
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
GLint uScreen, uSize;
|
GLint uScreen , uSize;
|
||||||
|
GLint uScreenBG, uSizeBG;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char vertex_shader[] = "\
|
static const char vertex_shader[] = "\
|
||||||
|
@ -81,20 +83,25 @@ uniform sampler2D sampler1;\
|
||||||
\
|
\
|
||||||
void main()\
|
void main()\
|
||||||
{\
|
{\
|
||||||
highp vec4 tmp = texture(sampler1, uv);\
|
color = texture(sampler1, uv);\
|
||||||
color.r = tmp.b; \
|
|
||||||
color.g = tmp.g; \
|
|
||||||
color.b = tmp.r; \
|
|
||||||
color.a = tmp.a; \
|
|
||||||
if (color.a == 0.0) \
|
|
||||||
{\
|
|
||||||
color.a = 0.5; \
|
|
||||||
color.r = 0.0; \
|
|
||||||
color.g = 0.0; \
|
|
||||||
}\
|
|
||||||
}\
|
}\
|
||||||
";
|
";
|
||||||
|
|
||||||
|
static const char frag_shaderBG[] = "\
|
||||||
|
#version 300 es\n\
|
||||||
|
\
|
||||||
|
in highp vec2 uv;\
|
||||||
|
out highp vec4 color;\
|
||||||
|
\
|
||||||
|
uniform sampler2D sampler1;\
|
||||||
|
\
|
||||||
|
void main()\
|
||||||
|
{\
|
||||||
|
color = vec4(0.0, 0.0, 1.0, 0.5);\
|
||||||
|
}\
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj)
|
bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj)
|
||||||
{
|
{
|
||||||
*fps = (EGL_FPS *)malloc(sizeof(EGL_FPS));
|
*fps = (EGL_FPS *)malloc(sizeof(EGL_FPS));
|
||||||
|
@ -121,16 +128,34 @@ bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!egl_shader_init(&(*fps)->shaderBG))
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to initialize the fps bg shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!egl_shader_compile((*fps)->shader,
|
if (!egl_shader_compile((*fps)->shader,
|
||||||
vertex_shader, sizeof(vertex_shader),
|
vertex_shader, sizeof(vertex_shader),
|
||||||
frag_shader, sizeof(frag_shader)))
|
frag_shader , sizeof(frag_shader )))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to compile the fps shader");
|
DEBUG_ERROR("Failed to compile the fps shader");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*fps)->uSize = egl_shader_get_uniform_location((*fps)->shader, "size" );
|
if (!egl_shader_compile((*fps)->shaderBG,
|
||||||
(*fps)->uScreen = egl_shader_get_uniform_location((*fps)->shader, "screen");
|
vertex_shader, sizeof(vertex_shader),
|
||||||
|
frag_shaderBG, sizeof(frag_shaderBG)))
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to compile the fps shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(*fps)->uSize = egl_shader_get_uniform_location((*fps)->shader , "size" );
|
||||||
|
(*fps)->uScreen = egl_shader_get_uniform_location((*fps)->shader , "screen");
|
||||||
|
(*fps)->uSizeBG = egl_shader_get_uniform_location((*fps)->shaderBG, "size" );
|
||||||
|
(*fps)->uScreenBG = egl_shader_get_uniform_location((*fps)->shaderBG, "screen");
|
||||||
|
|
||||||
if (!egl_model_init(&(*fps)->model))
|
if (!egl_model_init(&(*fps)->model))
|
||||||
{
|
{
|
||||||
|
@ -149,8 +174,9 @@ void egl_fps_free(EGL_FPS ** fps)
|
||||||
if (!*fps)
|
if (!*fps)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
egl_texture_free(&(*fps)->texture);
|
egl_texture_free(&(*fps)->texture );
|
||||||
egl_shader_free (&(*fps)->shader );
|
egl_shader_free (&(*fps)->shader );
|
||||||
|
egl_shader_free (&(*fps)->shaderBG);
|
||||||
egl_model_free (&(*fps)->model );
|
egl_model_free (&(*fps)->model );
|
||||||
|
|
||||||
free(*fps);
|
free(*fps);
|
||||||
|
@ -198,9 +224,18 @@ void egl_fps_render(EGL_FPS * fps, float screenWidth, float screenHeight)
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
// render the background first
|
||||||
|
egl_shader_use(fps->shaderBG);
|
||||||
|
glUniform2f(fps->uScreenBG, screenWidth, screenHeight);
|
||||||
|
glUniform2f(fps->uSizeBG , fps->width , fps->height );
|
||||||
|
egl_model_render(fps->model);
|
||||||
|
|
||||||
|
// render the texture over the background
|
||||||
egl_shader_use(fps->shader);
|
egl_shader_use(fps->shader);
|
||||||
glUniform2f(fps->uScreen, screenWidth, screenHeight);
|
glUniform2f(fps->uScreen, screenWidth, screenHeight);
|
||||||
glUniform2f(fps->uSize , fps->width , fps->height );
|
glUniform2f(fps->uSize , fps->width , fps->height );
|
||||||
egl_model_render(fps->model);
|
egl_model_render(fps->model);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue