2015-11-08 00:30:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch 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 Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch 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 RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
|
|
|
#include "../../config.def.h"
|
|
|
|
#include "../../gfx/font_renderer_driver.h"
|
|
|
|
#include "../../gfx/video_context_driver.h"
|
|
|
|
#include "../../gfx/video_thread_wrapper.h"
|
|
|
|
#include "../../gfx/video_texture.h"
|
2015-11-17 07:01:33 +00:00
|
|
|
#include "../../gfx/common/gl_common.h"
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
#include "../menu_display.h"
|
|
|
|
|
|
|
|
static const GLfloat gl_vertexes[] = {
|
|
|
|
0, 0,
|
|
|
|
1, 0,
|
|
|
|
0, 1,
|
|
|
|
1, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GLfloat gl_tex_coords[] = {
|
|
|
|
0, 1,
|
|
|
|
1, 1,
|
|
|
|
0, 0,
|
|
|
|
1, 0
|
|
|
|
};
|
|
|
|
|
2015-11-20 16:46:42 +00:00
|
|
|
static gl_t *gl_get_ptr(void)
|
2015-11-08 00:30:07 +00:00
|
|
|
{
|
2015-11-23 15:06:09 +00:00
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(false);
|
2015-11-20 16:46:42 +00:00
|
|
|
if (!gl)
|
|
|
|
return NULL;
|
|
|
|
return gl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *menu_display_gl_get_default_mvp(void)
|
|
|
|
{
|
|
|
|
gl_t *gl = gl_get_ptr();
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return NULL;
|
|
|
|
|
2015-11-08 20:03:12 +00:00
|
|
|
return &gl->mvp_no_rot;
|
2015-11-08 00:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum menu_display_prim_to_gl_enum(enum menu_display_prim_type prim_type)
|
|
|
|
{
|
|
|
|
switch (prim_type)
|
|
|
|
{
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLES:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
case MENU_DISPLAY_PRIM_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_blend_begin(void)
|
|
|
|
{
|
2015-11-20 16:46:42 +00:00
|
|
|
gl_t *gl = gl_get_ptr();
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2015-12-05 06:33:21 +00:00
|
|
|
video_shader_driver_use(gl->shader, NULL, GL_SHADER_STOCK_BLEND);
|
2015-11-08 00:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_blend_end(void)
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_draw(
|
2015-12-03 08:34:17 +00:00
|
|
|
float x, float y,
|
2015-11-08 00:30:07 +00:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
struct gfx_coords *coords,
|
|
|
|
void *matrix_data,
|
|
|
|
uintptr_t texture,
|
|
|
|
enum menu_display_prim_type prim_type
|
|
|
|
)
|
|
|
|
{
|
2015-11-20 16:46:42 +00:00
|
|
|
gl_t *gl = gl_get_ptr();
|
2015-11-08 00:30:07 +00:00
|
|
|
math_matrix_4x4 *mat = (math_matrix_4x4*)matrix_data;
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* TODO - edge case */
|
|
|
|
if (height <= 0)
|
|
|
|
height = 1;
|
|
|
|
|
|
|
|
if (!mat)
|
2015-11-08 22:14:33 +00:00
|
|
|
mat = (math_matrix_4x4*)menu_display_gl_get_default_mvp();
|
2015-11-08 00:30:07 +00:00
|
|
|
if (!coords->vertex)
|
|
|
|
coords->vertex = &gl_vertexes[0];
|
|
|
|
if (!coords->tex_coord)
|
|
|
|
coords->tex_coord = &gl_tex_coords[0];
|
|
|
|
if (!coords->lut_tex_coord)
|
|
|
|
coords->lut_tex_coord = &gl_tex_coords[0];
|
|
|
|
|
|
|
|
glViewport(x, y, width, height);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, (GLuint)texture);
|
|
|
|
|
2015-12-05 06:33:21 +00:00
|
|
|
video_shader_driver_set_coords(gl->shader, gl, coords);
|
|
|
|
video_shader_driver_set_mvp(gl->shader, video_driver_get_ptr(false), mat);
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
glDrawArrays(menu_display_prim_to_gl_enum(prim_type), 0, coords->vertices);
|
|
|
|
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_draw_bg(
|
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
|
|
|
uintptr_t texture,
|
|
|
|
float handle_alpha,
|
|
|
|
bool force_transparency,
|
|
|
|
GLfloat *coord_color,
|
|
|
|
GLfloat *coord_color2,
|
|
|
|
const float *vertex,
|
|
|
|
const float *tex_coord,
|
|
|
|
size_t vertex_count,
|
|
|
|
enum menu_display_prim_type prim_type)
|
|
|
|
{
|
|
|
|
struct gfx_coords coords;
|
|
|
|
const GLfloat *new_vertex = NULL;
|
|
|
|
const GLfloat *new_tex_coord = NULL;
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-11-20 16:46:42 +00:00
|
|
|
gl_t *gl = gl_get_ptr();
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new_vertex = vertex;
|
|
|
|
new_tex_coord = tex_coord;
|
|
|
|
|
|
|
|
if (!new_vertex)
|
|
|
|
new_vertex = &gl_vertexes[0];
|
|
|
|
if (!new_tex_coord)
|
|
|
|
new_tex_coord = &gl_tex_coords[0];
|
|
|
|
|
|
|
|
coords.vertices = vertex_count;
|
|
|
|
coords.vertex = new_vertex;
|
|
|
|
coords.tex_coord = new_tex_coord;
|
|
|
|
coords.lut_tex_coord = new_tex_coord;
|
|
|
|
coords.color = (const float*)coord_color;
|
|
|
|
|
|
|
|
menu_display_gl_blend_begin();
|
|
|
|
|
|
|
|
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
|
|
|
|
|
|
|
|
if ((settings->menu.pause_libretro
|
|
|
|
|| !global->inited.main || (global->inited.core.type == CORE_TYPE_DUMMY))
|
|
|
|
&& !force_transparency
|
|
|
|
&& texture)
|
|
|
|
coords.color = (const float*)coord_color2;
|
|
|
|
|
|
|
|
menu_display_gl_draw(0, 0, width, height,
|
2015-11-08 22:14:33 +00:00
|
|
|
&coords, (math_matrix_4x4*)menu_display_gl_get_default_mvp(),
|
2015-11-08 00:30:07 +00:00
|
|
|
(GLuint)texture, prim_type);
|
|
|
|
|
|
|
|
menu_display_gl_blend_end();
|
|
|
|
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_restore_clear_color(void)
|
|
|
|
{
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.00f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_clear_color(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
glClearColor(r, g, b, a);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned menu_display_gl_texture_load(void *data, enum texture_filter_type type)
|
|
|
|
{
|
|
|
|
return video_texture_load(data, TEXTURE_BACKEND_OPENGL, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_texture_unload(uintptr_t *id)
|
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
return;
|
2015-11-08 23:38:02 +00:00
|
|
|
video_texture_unload(TEXTURE_BACKEND_OPENGL, id);
|
2015-11-08 00:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const float *menu_display_gl_get_tex_coords(void)
|
|
|
|
{
|
|
|
|
return &gl_tex_coords[0];
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:12:32 +00:00
|
|
|
static bool menu_display_gl_font_init_first(const void **font_driver,
|
|
|
|
void **font_handle, void *video_data, const char *font_path,
|
|
|
|
float font_size)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
const struct retro_hw_render_callback *hw_render =
|
|
|
|
(const struct retro_hw_render_callback*)video_driver_callback();
|
|
|
|
|
|
|
|
if (settings->video.threaded && !hw_render->context_type)
|
|
|
|
{
|
|
|
|
thread_packet_t pkt;
|
2015-11-23 17:50:49 +00:00
|
|
|
thread_video_t *thr = (thread_video_t*)video_driver_get_ptr(true);
|
2015-11-09 21:12:32 +00:00
|
|
|
|
|
|
|
if (!thr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pkt.type = CMD_FONT_INIT;
|
|
|
|
pkt.data.font_init.method = font_init_first;
|
|
|
|
pkt.data.font_init.font_driver = (const void**)font_driver;
|
|
|
|
pkt.data.font_init.font_handle = font_handle;
|
|
|
|
pkt.data.font_init.video_data = video_data;
|
|
|
|
pkt.data.font_init.font_path = font_path;
|
|
|
|
pkt.data.font_init.font_size = font_size;
|
|
|
|
pkt.data.font_init.api = FONT_DRIVER_RENDER_OPENGL_API;
|
|
|
|
|
|
|
|
thr->send_and_wait(thr, &pkt);
|
|
|
|
|
|
|
|
return pkt.data.font_init.return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return font_init_first(font_driver, font_handle, video_data,
|
|
|
|
font_path, font_size, FONT_DRIVER_RENDER_OPENGL_API);
|
|
|
|
}
|
|
|
|
|
2015-11-08 00:30:07 +00:00
|
|
|
menu_display_ctx_driver_t menu_display_ctx_gl = {
|
|
|
|
menu_display_gl_draw,
|
|
|
|
menu_display_gl_draw_bg,
|
|
|
|
menu_display_gl_blend_begin,
|
|
|
|
menu_display_gl_blend_end,
|
|
|
|
menu_display_gl_restore_clear_color,
|
|
|
|
menu_display_gl_clear_color,
|
2015-11-08 20:03:12 +00:00
|
|
|
menu_display_gl_get_default_mvp,
|
2015-11-08 00:30:07 +00:00
|
|
|
menu_display_gl_get_tex_coords,
|
|
|
|
menu_display_gl_texture_load,
|
|
|
|
menu_display_gl_texture_unload,
|
2015-11-09 21:12:32 +00:00
|
|
|
menu_display_gl_font_init_first,
|
2015-11-08 00:30:07 +00:00
|
|
|
MENU_VIDEO_DRIVER_OPENGL,
|
|
|
|
"menu_display_gl",
|
|
|
|
};
|