2015-11-08 00:30:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-11-08 00:30:07 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2016-01-19 22:26:47 +00:00
|
|
|
#include "../../retroarch.h"
|
2015-12-05 11:07:22 +00:00
|
|
|
#include "../../gfx/font_driver.h"
|
2015-11-08 00:30:07 +00:00
|
|
|
#include "../../gfx/video_context_driver.h"
|
2015-12-08 08:30:44 +00:00
|
|
|
#include "../../gfx/video_shader_driver.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
|
|
|
|
};
|
|
|
|
|
2016-04-15 01:24:21 +00:00
|
|
|
static const float *menu_display_gl_get_default_vertices(void)
|
|
|
|
{
|
|
|
|
return &gl_vertexes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const float *menu_display_gl_get_default_tex_coords(void)
|
|
|
|
{
|
|
|
|
return &gl_tex_coords[0];
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:46:42 +00:00
|
|
|
static void *menu_display_gl_get_default_mvp(void)
|
|
|
|
{
|
2016-04-15 02:17:31 +00:00
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(false);
|
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
|
|
|
}
|
|
|
|
|
2016-02-04 20:42:42 +00:00
|
|
|
static GLenum menu_display_prim_to_gl_enum(
|
2016-02-25 18:52:40 +00:00
|
|
|
enum menu_display_prim_type type)
|
2015-11-08 00:30:07 +00:00
|
|
|
{
|
2016-02-25 18:52:40 +00:00
|
|
|
switch (type)
|
2015-11-08 00:30:07 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2016-02-14 19:01:39 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
|
|
|
|
2015-11-08 00:30:07 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2016-02-14 19:01:39 +00:00
|
|
|
shader_info.data = NULL;
|
2016-04-15 23:50:20 +00:00
|
|
|
shader_info.idx = VIDEO_SHADER_STOCK_BLEND;
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.set_active = true;
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_use(&shader_info);
|
2015-11-08 00:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_display_gl_blend_end(void)
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2016-04-19 06:50:35 +00:00
|
|
|
static void menu_display_gl_viewport(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(false);
|
|
|
|
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
|
|
|
|
|
|
|
if (!gl || !draw)
|
|
|
|
return;
|
|
|
|
glViewport(draw->x, draw->y, draw->width, draw->height);
|
|
|
|
}
|
|
|
|
|
2016-04-19 06:53:48 +00:00
|
|
|
static void menu_display_gl_bind_texture(void *data)
|
|
|
|
{
|
|
|
|
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
|
|
|
|
|
|
|
if (!draw)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, (GLuint)draw->texture);
|
|
|
|
}
|
|
|
|
|
2016-02-09 15:11:37 +00:00
|
|
|
static void menu_display_gl_draw(void *data)
|
2015-11-08 00:30:07 +00:00
|
|
|
{
|
2016-02-14 18:43:47 +00:00
|
|
|
video_shader_ctx_mvp_t mvp;
|
2016-02-14 17:59:42 +00:00
|
|
|
video_shader_ctx_coords_t coords;
|
2016-04-19 06:50:35 +00:00
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(false);
|
2016-02-09 15:11:37 +00:00
|
|
|
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
2016-02-09 14:55:31 +00:00
|
|
|
|
|
|
|
if (!gl || !draw)
|
2015-11-08 00:30:07 +00:00
|
|
|
return;
|
|
|
|
|
2016-02-09 14:55:31 +00:00
|
|
|
if (!draw->coords->vertex)
|
2016-04-15 01:24:21 +00:00
|
|
|
draw->coords->vertex = menu_display_gl_get_default_vertices();
|
2016-02-09 14:55:31 +00:00
|
|
|
if (!draw->coords->tex_coord)
|
2016-04-15 01:24:21 +00:00
|
|
|
draw->coords->tex_coord = menu_display_gl_get_default_tex_coords();
|
2016-02-09 14:55:31 +00:00
|
|
|
if (!draw->coords->lut_tex_coord)
|
2016-04-15 01:24:21 +00:00
|
|
|
draw->coords->lut_tex_coord = menu_display_gl_get_default_tex_coords();
|
2015-11-08 00:30:07 +00:00
|
|
|
|
2016-04-19 06:50:35 +00:00
|
|
|
menu_display_gl_viewport(draw);
|
2016-04-19 06:53:48 +00:00
|
|
|
menu_display_gl_bind_texture(draw);
|
2015-11-08 00:30:07 +00:00
|
|
|
|
2016-02-14 17:59:42 +00:00
|
|
|
coords.handle_data = gl;
|
|
|
|
coords.data = draw->coords;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_set_coords(&coords);
|
2016-02-14 18:43:47 +00:00
|
|
|
|
|
|
|
mvp.data = gl;
|
2016-04-19 15:40:03 +00:00
|
|
|
mvp.matrix = draw->matrix_data ? (math_matrix_4x4*)draw->matrix_data
|
|
|
|
: (math_matrix_4x4*)menu_display_gl_get_default_mvp();
|
2016-02-14 18:43:47 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_set_mvp(&mvp);
|
2015-11-08 00:30:07 +00:00
|
|
|
|
2016-02-09 14:55:31 +00:00
|
|
|
glDrawArrays(menu_display_prim_to_gl_enum(
|
|
|
|
draw->prim_type), 0, draw->coords->vertices);
|
2015-11-08 00:30:07 +00:00
|
|
|
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
|
|
|
|
2016-04-25 11:56:12 +00:00
|
|
|
static void menu_display_gl_draw_pipeline(void *data)
|
|
|
|
{
|
2016-06-06 22:00:28 +00:00
|
|
|
#ifdef HAVE_SHADERPIPELINE
|
2016-04-25 11:56:12 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
|
|
|
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
|
|
|
struct uniform_info uniform_param = {0};
|
|
|
|
static float t = 0;
|
2016-05-10 00:32:49 +00:00
|
|
|
video_coord_array_t *ca = NULL;
|
2016-04-25 11:56:12 +00:00
|
|
|
|
2016-05-08 10:33:28 +00:00
|
|
|
ca = menu_display_get_coords_array();
|
2016-04-25 11:56:12 +00:00
|
|
|
|
|
|
|
draw->x = 0;
|
|
|
|
draw->y = 0;
|
2016-05-10 00:32:49 +00:00
|
|
|
draw->coords = (struct video_coords*)(&ca->coords);
|
2016-04-25 11:56:12 +00:00
|
|
|
draw->matrix_data = NULL;
|
|
|
|
|
|
|
|
switch (draw->pipeline.id)
|
|
|
|
{
|
|
|
|
case VIDEO_SHADER_MENU:
|
|
|
|
case VIDEO_SHADER_MENU_SEC:
|
|
|
|
shader_info.data = NULL;
|
|
|
|
shader_info.idx = draw->pipeline.id;
|
|
|
|
shader_info.set_active = true;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_use(&shader_info);
|
2016-04-25 11:56:12 +00:00
|
|
|
|
|
|
|
t += 0.01;
|
|
|
|
|
|
|
|
uniform_param.enabled = true;
|
|
|
|
uniform_param.lookup.enable = true;
|
|
|
|
uniform_param.lookup.add_prefix = true;
|
2016-04-26 10:46:16 +00:00
|
|
|
uniform_param.lookup.idx = draw->pipeline.id;
|
2016-04-25 11:56:12 +00:00
|
|
|
uniform_param.lookup.type = SHADER_PROGRAM_VERTEX;
|
|
|
|
uniform_param.type = UNIFORM_1F;
|
|
|
|
uniform_param.lookup.ident = "time";
|
|
|
|
uniform_param.result.f.v0 = t;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_set_parameter(&uniform_param);
|
2016-04-25 11:56:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-11-08 00:30:07 +00:00
|
|
|
static void menu_display_gl_restore_clear_color(void)
|
|
|
|
{
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.00f);
|
|
|
|
}
|
|
|
|
|
2016-04-15 02:20:57 +00:00
|
|
|
static void menu_display_gl_clear_color(menu_display_ctx_clearcolor_t *clearcolor)
|
2015-11-08 00:30:07 +00:00
|
|
|
{
|
2016-02-09 15:11:37 +00:00
|
|
|
if (!clearcolor)
|
|
|
|
return;
|
|
|
|
|
2016-02-09 15:13:00 +00:00
|
|
|
glClearColor(clearcolor->r,
|
|
|
|
clearcolor->g, clearcolor->b, clearcolor->a);
|
2015-11-08 00:30:07 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2015-12-05 10:29:06 +00:00
|
|
|
static bool menu_display_gl_font_init_first(
|
2016-02-09 15:13:00 +00:00
|
|
|
void **font_handle, void *video_data,
|
|
|
|
const char *font_path, float font_size)
|
2015-11-09 21:12:32 +00:00
|
|
|
{
|
2015-12-05 10:29:06 +00:00
|
|
|
return font_driver_init_first(NULL, font_handle, video_data,
|
|
|
|
font_path, font_size, true, FONT_DRIVER_RENDER_OPENGL_API);
|
2015-11-09 21:12:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 00:30:07 +00:00
|
|
|
menu_display_ctx_driver_t menu_display_ctx_gl = {
|
|
|
|
menu_display_gl_draw,
|
2016-04-25 11:56:12 +00:00
|
|
|
menu_display_gl_draw_pipeline,
|
2016-04-19 06:50:35 +00:00
|
|
|
menu_display_gl_viewport,
|
2015-11-08 00:30:07 +00:00
|
|
|
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,
|
2016-04-15 01:31:59 +00:00
|
|
|
menu_display_gl_get_default_vertices,
|
|
|
|
menu_display_gl_get_default_tex_coords,
|
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",
|
|
|
|
};
|