Rework overlays as a video driver interface.

This commit is contained in:
Themaister 2012-12-20 11:16:22 +01:00
parent c981cb77f8
commit b4cd58afe7
3 changed files with 55 additions and 21 deletions

View File

@ -205,6 +205,14 @@ typedef struct input_driver
struct rarch_viewport;
typedef struct video_overlay_interface
{
void (*enable)(void *data, bool state);
bool (*load)(void *data, const char *path);
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);
} video_overlay_interface_t;
typedef struct video_driver
{
void *(*init)(const video_info_t *video, const input_driver_t **input, void **input_data);
@ -232,6 +240,8 @@ typedef struct video_driver
// Reads out in BGR byte order (24bpp).
bool (*read_viewport)(void *data, uint8_t *buffer);
void (*overlay_interface)(void *data, const video_overlay_interface_t **iface);
} video_driver_t;
enum rarch_display_type

View File

@ -77,6 +77,12 @@ static const GLfloat tex_coords[] = {
1, 1
};
static void gl_render_overlay(gl_t *gl);
static void gl_overlay_vertex_geom(void *data,
float x, float y, float w, float h);
static void gl_overlay_tex_geom(void *data,
float x, float y, float w, float h);
static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt)
{
coords[2] = xamt;
@ -1185,7 +1191,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
if (gl->ctx_driver->post_render)
context_post_render_func(gl);
//gl_render_overlay(gl);
else if (gl->overlay_enable)
gl_render_overlay(gl);
#if !defined(RARCH_CONSOLE)
context_update_window_title_func(false);
@ -1555,9 +1562,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl_init_pbo_readback(gl);
//gl_load_overlay(gl, "/mnt/extsd/basic_quickmenu.tga");
//gl_set_overlay_vertex_coord(gl, 0, 0, 1.0, 1.0);
if (!gl_check_error())
{
context_destroy_func();
@ -1788,8 +1792,10 @@ static void gl_set_aspect_ratio(void *data, unsigned aspectratio_index)
}
#endif
bool gl_load_overlay(gl_t *gl, const char *path)
static bool gl_overlay_load(void *data, const char *path)
{
gl_t *gl = (gl_t*)data;
if (!gl->tex_overlay)
glGenTextures(1, &gl->tex_overlay);
@ -1812,25 +1818,29 @@ bool gl_load_overlay(gl_t *gl, const char *path)
RARCH_GL_FORMAT32, img.pixels);
free(img.pixels);
gl_set_overlay_tex_coord(gl, 0, 0, 1, 1); // Default. Stretch to whole screen.
gl_set_overlay_vertex_coord(gl, 0, 0, 1, 1);
gl_overlay_tex_geom(gl, 0, 0, 1, 1); // Default. Stretch to whole screen.
gl_overlay_vertex_geom(gl, 0, 0, 1, 1);
return true;
}
void gl_set_overlay_tex_coord(gl_t *gl,
static void gl_overlay_tex_geom(void *data,
GLfloat x, GLfloat y,
GLfloat w, GLfloat h)
{
gl_t *gl = (gl_t*)data;
gl->overlay_tex_coord[0] = x; gl->overlay_tex_coord[1] = y;
gl->overlay_tex_coord[2] = x + w; gl->overlay_tex_coord[3] = y;
gl->overlay_tex_coord[4] = x; gl->overlay_tex_coord[5] = y + h;
gl->overlay_tex_coord[6] = x + w; gl->overlay_tex_coord[7] = y + h;
}
void gl_set_overlay_vertex_coord(gl_t *gl,
GLfloat x, GLfloat y,
GLfloat w, GLfloat h)
static void gl_overlay_vertex_geom(void *data,
float x, float y,
float w, float h)
{
gl_t *gl = (gl_t*)data;
// Flipped, so we preserve top-down semantics.
y = 1.0f - y;
h = -h;
@ -1841,7 +1851,13 @@ void gl_set_overlay_vertex_coord(gl_t *gl,
gl->overlay_vertex_coord[6] = x + w; gl->overlay_vertex_coord[7] = y + h;
}
void gl_render_overlay(gl_t *gl)
static void gl_overlay_enable(void *data, bool state)
{
gl_t *gl = (gl_t*)data;
gl->overlay_enable = state;
}
static void gl_render_overlay(gl_t *gl)
{
glBindTexture(GL_TEXTURE_2D, gl->tex_overlay);
@ -1858,6 +1874,19 @@ void gl_render_overlay(gl_t *gl)
gl->coords.tex_coord = gl->tex_coords;
}
static const video_overlay_interface_t gl_overlay_interface = {
gl_overlay_enable,
gl_overlay_load,
gl_overlay_tex_geom,
gl_overlay_vertex_geom,
};
static void gl_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
{
(void)data;
*iface = &gl_overlay_interface;
}
const video_driver_t video_gl = {
gl_init,
gl_frame,
@ -1891,5 +1920,8 @@ const video_driver_t video_gl = {
NULL,
NULL,
#endif
gl_get_overlay_interface,
};

View File

@ -281,6 +281,7 @@ typedef struct gl
bool egl_images;
// Overlay rendering
bool overlay_enable;
GLuint tex_overlay;
GLfloat overlay_tex_coord[8];
GLfloat overlay_vertex_coord[8];
@ -366,14 +367,5 @@ void gl_shader_set_coords(gl_t *gl, const struct gl_coords *coords, const math_m
void gl_init_fbo(gl_t *gl, unsigned width, unsigned height);
void gl_deinit_fbo(gl_t *gl);
bool gl_load_overlay(gl_t *gl, const char *path);
void gl_set_overlay_tex_coord(gl_t *gl,
GLfloat x, GLfloat y, // Relative coordinates [0, 1] range for screen.
GLfloat w, GLfloat h);
void gl_set_overlay_vertex_coord(gl_t *gl,
GLfloat x, GLfloat y, // Relative coordinates [0, 1] range for screen.
GLfloat w, GLfloat h);
void gl_render_overlay(gl_t *gl);
#endif