Add alpha modulation to overlays.

This commit is contained in:
Themaister 2013-01-29 21:51:15 +01:00
parent 5f1e92ef4b
commit eb979732b4
5 changed files with 34 additions and 1 deletions

View File

@ -226,6 +226,7 @@ typedef struct video_overlay_interface
void (*tex_geom)(void *data, float x, float y, float w, float h);
void (*vertex_geom)(void *data, float x, float y, float w, float h);
void (*full_screen)(void *data, bool enable);
void (*set_alpha)(void *data, float mod);
} video_overlay_interface_t;
#endif

View File

@ -1995,6 +1995,11 @@ static bool gl_overlay_load(void *data, const uint32_t *image, unsigned width, u
gl_overlay_tex_geom(gl, 0, 0, 1, 1); // Default. Stretch to whole screen.
gl_overlay_vertex_geom(gl, 0, 0, 1, 1);
// Only override this value when we need to.
if (gl->overlay_alpha_mod <= 0.0f)
gl->overlay_alpha_mod = 1.0f;
return true;
}
@ -2038,16 +2043,31 @@ static void gl_overlay_full_screen(void *data, bool enable)
gl->overlay_full_screen = enable;
}
static void gl_overlay_set_alpha(void *data, float mod)
{
gl_t *gl = (gl_t*)data;
gl->overlay_alpha_mod = mod;
}
static void gl_render_overlay(void *data)
{
gl_t *gl = (gl_t*)data;
glBindTexture(GL_TEXTURE_2D, gl->tex_overlay);
const GLfloat white_color_mod[16] = {
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
};
gl_shader_use_func(gl, 0);
glEnable(GL_BLEND);
gl->coords.vertex = gl->overlay_vertex_coord;
gl->coords.tex_coord = gl->overlay_tex_coord;
gl->coords.color = white_color_mod;
gl_shader_set_coords_func(gl, &gl->coords, &gl->mvp_no_rot);
if (gl->overlay_full_screen)
@ -2063,6 +2083,7 @@ static void gl_render_overlay(void *data)
gl->coords.vertex = vertex_ptr;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
}
static const video_overlay_interface_t gl_overlay_interface = {
@ -2071,6 +2092,7 @@ static const video_overlay_interface_t gl_overlay_interface = {
gl_overlay_tex_geom,
gl_overlay_vertex_geom,
gl_overlay_full_screen,
gl_overlay_set_alpha,
};
static void gl_get_overlay_interface(void *data, const video_overlay_interface_t **iface)

View File

@ -289,7 +289,7 @@ typedef struct gl
GLuint tex_overlay;
GLfloat overlay_tex_coord[8];
GLfloat overlay_vertex_coord[8];
GLfloat overlay_alpha_mod; // TODO. Needs a specific shader.
GLfloat overlay_alpha_mod;
#endif
#if !defined(HAVE_OPENGLES) && defined(HAVE_FFMPEG)

View File

@ -373,3 +373,9 @@ void input_overlay_free(input_overlay_t *ol)
free(ol);
}
void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod)
{
ol->iface->set_alpha(ol->iface_data, mod);
}

View File

@ -37,6 +37,10 @@ bool input_overlay_full_screen(input_overlay_t *ol);
// Resulting state is a bitmask of (1 << key_bind_id).
uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y);
// Sets a modulating factor for alpha channel. Default is 1.0.
// The alpha factor is applied for all overlays.
void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod);
void input_overlay_next(input_overlay_t *ol);
#endif