2018-01-21 06:57:25 +00:00
|
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-11-08 20:26:19 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-04-22 12:27:39 +00:00
|
|
|
|
#define CINTERFACE
|
|
|
|
|
|
2015-11-08 20:26:19 +00:00
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
|
2005-04-23 18:22:55 +00:00
|
|
|
|
#include <gfx/math/matrix_4x4.h>
|
|
|
|
|
|
2016-09-08 04:02:41 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "../../config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-05-19 13:25:14 +00:00
|
|
|
|
#include "../menu_driver.h"
|
2016-09-08 04:02:41 +00:00
|
|
|
|
|
2017-05-08 23:25:59 +00:00
|
|
|
|
#include "../../gfx/video_driver.h"
|
2015-11-18 12:00:13 +00:00
|
|
|
|
#include "../../gfx/common/d3d_common.h"
|
2018-03-03 14:28:58 +00:00
|
|
|
|
#include "../../gfx/common/d3d8_common.h"
|
2016-12-02 00:46:16 +00:00
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static const float d3d8_vertexes[] = {
|
2015-11-08 20:26:19 +00:00
|
|
|
|
0, 0,
|
|
|
|
|
1, 0,
|
|
|
|
|
0, 1,
|
|
|
|
|
1, 1
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static const float d3d8_tex_coords[] = {
|
2015-11-08 20:26:19 +00:00
|
|
|
|
0, 1,
|
|
|
|
|
1, 1,
|
|
|
|
|
0, 0,
|
|
|
|
|
1, 0
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static const float *menu_display_d3d8_get_default_vertices(void)
|
2016-04-15 01:24:21 +00:00
|
|
|
|
{
|
2018-03-03 14:28:58 +00:00
|
|
|
|
return &d3d8_vertexes[0];
|
2016-04-15 01:24:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static const float *menu_display_d3d8_get_default_tex_coords(void)
|
2016-04-15 01:24:21 +00:00
|
|
|
|
{
|
2018-03-03 14:28:58 +00:00
|
|
|
|
return &d3d8_tex_coords[0];
|
2016-04-15 01:24:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static void *menu_display_d3d8_get_default_mvp(video_frame_info_t *video_info)
|
2015-11-20 16:45:10 +00:00
|
|
|
|
{
|
2018-01-15 02:45:37 +00:00
|
|
|
|
static math_matrix_4x4 id;
|
|
|
|
|
matrix_4x4_identity(id);
|
2016-01-08 07:12:59 +00:00
|
|
|
|
|
2018-01-15 02:45:37 +00:00
|
|
|
|
return &id;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static INT32 menu_display_prim_to_d3d8_enum(
|
2016-02-09 15:11:37 +00:00
|
|
|
|
enum menu_display_prim_type prim_type)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
|
|
|
|
switch (prim_type)
|
|
|
|
|
{
|
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLES:
|
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
|
2018-01-26 02:53:37 +00:00
|
|
|
|
return D3DPT_COMM_TRIANGLESTRIP;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
case MENU_DISPLAY_PRIM_NONE:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 20:44:34 +00:00
|
|
|
|
/* TOD/FIXME - hack */
|
2018-01-26 02:53:37 +00:00
|
|
|
|
return 0;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static void menu_display_d3d8_blend_begin(video_frame_info_t *video_info)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
2018-05-03 20:03:12 +00:00
|
|
|
|
d3d8_video_t *d3d = video_info ?
|
|
|
|
|
(d3d8_video_t*)video_info->userdata : NULL;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_enable_blend_func(d3d->dev);
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static void menu_display_d3d8_blend_end(video_frame_info_t *video_info)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
2018-05-03 20:03:12 +00:00
|
|
|
|
d3d8_video_t *d3d = video_info ?
|
|
|
|
|
(d3d8_video_t*)video_info->userdata : NULL;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_disable_blend_func(d3d->dev);
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 12:15:04 +00:00
|
|
|
|
static void menu_display_d3d8_viewport(menu_display_ctx_draw_t *draw,
|
|
|
|
|
video_frame_info_t *video_info)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
2016-04-19 06:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 12:43:40 +00:00
|
|
|
|
static void menu_display_d3d8_bind_texture(menu_display_ctx_draw_t *draw,
|
|
|
|
|
d3d8_video_t *d3d)
|
2016-04-19 06:53:48 +00:00
|
|
|
|
{
|
2018-05-13 12:43:40 +00:00
|
|
|
|
LPDIRECT3DDEVICE8 dev = d3d->dev;
|
2016-04-19 06:53:48 +00:00
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_set_texture(d3d->dev, 0, (void*)draw->texture);
|
|
|
|
|
d3d8_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_COMM_CLAMP);
|
|
|
|
|
d3d8_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_COMM_CLAMP);
|
|
|
|
|
d3d8_set_sampler_minfilter(d3d->dev, 0, D3DTEXF_COMM_LINEAR);
|
|
|
|
|
d3d8_set_sampler_magfilter(d3d->dev, 0, D3DTEXF_COMM_LINEAR);
|
2016-04-19 06:53:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 12:15:04 +00:00
|
|
|
|
static void menu_display_d3d8_draw(menu_display_ctx_draw_t *draw,
|
|
|
|
|
video_frame_info_t *video_info)
|
2016-04-19 06:50:35 +00:00
|
|
|
|
{
|
2018-01-14 01:21:48 +00:00
|
|
|
|
unsigned i;
|
2018-01-15 02:45:37 +00:00
|
|
|
|
video_shader_ctx_mvp_t mvp;
|
|
|
|
|
math_matrix_4x4 mop, m1, m2;
|
|
|
|
|
unsigned width, height;
|
2018-05-13 12:15:04 +00:00
|
|
|
|
d3d8_video_t *d3d = video_info ?
|
|
|
|
|
(d3d8_video_t*)video_info->userdata : NULL;
|
2018-01-19 01:24:10 +00:00
|
|
|
|
Vertex * pv = NULL;
|
2018-01-14 01:21:48 +00:00
|
|
|
|
const float *vertex = NULL;
|
|
|
|
|
const float *tex_coord = NULL;
|
|
|
|
|
const float *color = NULL;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
|
2018-01-19 02:40:34 +00:00
|
|
|
|
if (!d3d || !draw || draw->pipeline.id)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
return;
|
2018-01-19 02:40:34 +00:00
|
|
|
|
if((d3d->menu_display.offset + draw->coords->vertices )
|
2018-01-21 06:57:25 +00:00
|
|
|
|
> (unsigned)d3d->menu_display.size)
|
2018-01-15 02:45:37 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-01-19 02:40:34 +00:00
|
|
|
|
pv = (Vertex*)
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_vertex_buffer_lock(d3d->menu_display.buffer);
|
2018-01-19 02:40:34 +00:00
|
|
|
|
|
|
|
|
|
if (!pv)
|
2018-01-14 01:21:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-01-19 02:40:34 +00:00
|
|
|
|
pv += d3d->menu_display.offset;
|
|
|
|
|
vertex = draw->coords->vertex;
|
|
|
|
|
tex_coord = draw->coords->tex_coord;
|
|
|
|
|
color = draw->coords->color;
|
2017-11-15 15:51:29 +00:00
|
|
|
|
|
2018-01-15 02:45:37 +00:00
|
|
|
|
if (!vertex)
|
2018-03-03 14:28:58 +00:00
|
|
|
|
vertex = menu_display_d3d8_get_default_vertices();
|
2018-01-15 02:45:37 +00:00
|
|
|
|
if (!tex_coord)
|
2018-03-03 14:28:58 +00:00
|
|
|
|
tex_coord = menu_display_d3d8_get_default_tex_coords();
|
2018-01-15 02:45:37 +00:00
|
|
|
|
|
2018-01-14 01:21:48 +00:00
|
|
|
|
for (i = 0; i < draw->coords->vertices; i++)
|
|
|
|
|
{
|
2018-01-19 01:24:10 +00:00
|
|
|
|
int colors[4];
|
|
|
|
|
|
2018-01-19 02:40:34 +00:00
|
|
|
|
colors[0] = *color++ * 0xFF;
|
|
|
|
|
colors[1] = *color++ * 0xFF;
|
|
|
|
|
colors[2] = *color++ * 0xFF;
|
|
|
|
|
colors[3] = *color++ * 0xFF;
|
|
|
|
|
|
|
|
|
|
pv[i].x = *vertex++;
|
|
|
|
|
pv[i].y = *vertex++;
|
|
|
|
|
pv[i].z = 0.5f;
|
|
|
|
|
pv[i].u = *tex_coord++;
|
|
|
|
|
pv[i].v = *tex_coord++;
|
2018-03-03 14:28:58 +00:00
|
|
|
|
|
|
|
|
|
#if 1
|
2018-02-17 18:19:16 +00:00
|
|
|
|
if ((void*)draw->texture)
|
2018-01-20 06:00:03 +00:00
|
|
|
|
{
|
2018-04-22 12:55:15 +00:00
|
|
|
|
D3DSURFACE_DESC desc;
|
2018-03-03 14:28:58 +00:00
|
|
|
|
if (d3d8_texture_get_level_desc((void*)draw->texture, 0, &desc))
|
2018-01-20 06:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
pv[i].u *= desc.Width;
|
|
|
|
|
pv[i].v *= desc.Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-01-19 01:24:10 +00:00
|
|
|
|
|
|
|
|
|
pv[i].color =
|
|
|
|
|
D3DCOLOR_ARGB(
|
|
|
|
|
colors[3], /* A */
|
|
|
|
|
colors[0], /* R */
|
|
|
|
|
colors[1], /* G */
|
|
|
|
|
colors[2] /* B */
|
|
|
|
|
);
|
2018-01-14 01:21:48 +00:00
|
|
|
|
}
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_vertex_buffer_unlock(d3d->menu_display.buffer);
|
2017-11-15 15:51:29 +00:00
|
|
|
|
|
2018-01-15 02:45:37 +00:00
|
|
|
|
if(!draw->matrix_data)
|
2018-03-03 14:28:58 +00:00
|
|
|
|
draw->matrix_data = menu_display_d3d8_get_default_mvp(video_info);
|
2018-01-15 02:45:37 +00:00
|
|
|
|
|
|
|
|
|
/* ugh */
|
|
|
|
|
video_driver_get_size(&width, &height);
|
2018-01-19 02:40:34 +00:00
|
|
|
|
matrix_4x4_scale(m1, 2.0, 2.0, 0);
|
2018-01-15 02:45:37 +00:00
|
|
|
|
matrix_4x4_translate(mop, -1.0, -1.0, 0);
|
|
|
|
|
matrix_4x4_multiply(m2, mop, m1);
|
2018-01-19 02:40:34 +00:00
|
|
|
|
matrix_4x4_multiply(m1,
|
|
|
|
|
*((math_matrix_4x4*)draw->matrix_data), m2);
|
|
|
|
|
matrix_4x4_scale(mop,
|
|
|
|
|
(draw->width / 2.0) / width,
|
|
|
|
|
(draw->height / 2.0) / height, 0);
|
2018-01-15 02:45:37 +00:00
|
|
|
|
matrix_4x4_multiply(m2, mop, m1);
|
2018-01-19 02:40:34 +00:00
|
|
|
|
matrix_4x4_translate(mop,
|
|
|
|
|
(draw->x + (draw->width / 2.0)) / width,
|
|
|
|
|
(draw->y + (draw->height / 2.0)) / height,
|
|
|
|
|
0);
|
2018-01-15 02:45:37 +00:00
|
|
|
|
matrix_4x4_multiply(m1, mop, m2);
|
|
|
|
|
matrix_4x4_multiply(m2, d3d->mvp_transposed, m1);
|
|
|
|
|
d3d_matrix_transpose(&m1, &m2);
|
|
|
|
|
|
2018-01-19 02:40:34 +00:00
|
|
|
|
mvp.data = d3d;
|
2018-01-15 02:45:37 +00:00
|
|
|
|
mvp.matrix = &m1;
|
|
|
|
|
video_driver_set_mvp(&mvp);
|
2018-05-13 12:43:40 +00:00
|
|
|
|
if (draw && draw->texture)
|
|
|
|
|
menu_display_d3d8_bind_texture(draw, d3d);
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_draw_primitive(d3d->dev,
|
|
|
|
|
menu_display_prim_to_d3d8_enum(draw->prim_type),
|
2018-01-19 02:40:34 +00:00
|
|
|
|
d3d->menu_display.offset,
|
|
|
|
|
draw->coords->vertices -
|
|
|
|
|
((draw->prim_type == MENU_DISPLAY_PRIM_TRIANGLESTRIP)
|
|
|
|
|
? 2 : 0));
|
2015-11-08 20:26:19 +00:00
|
|
|
|
|
2018-01-14 01:21:48 +00:00
|
|
|
|
d3d->menu_display.offset += draw->coords->vertices;
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 12:15:04 +00:00
|
|
|
|
static void menu_display_d3d8_draw_pipeline(menu_display_ctx_draw_t *draw,
|
2018-02-16 18:08:16 +00:00
|
|
|
|
video_frame_info_t *video_info)
|
2016-04-25 11:56:12 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static void menu_display_d3d8_restore_clear_color(void)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
2018-01-14 01:21:48 +00:00
|
|
|
|
/* not needed */
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static void menu_display_d3d8_clear_color(
|
2018-02-16 18:25:19 +00:00
|
|
|
|
menu_display_ctx_clearcolor_t *clearcolor, video_frame_info_t *video_info)
|
2015-11-08 20:26:19 +00:00
|
|
|
|
{
|
2018-01-19 02:40:34 +00:00
|
|
|
|
DWORD clear_color = 0;
|
2018-05-03 20:03:12 +00:00
|
|
|
|
d3d8_video_t *d3d = video_info ?
|
|
|
|
|
(d3d8_video_t*)video_info->userdata : NULL;
|
2016-02-09 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
if (!d3d || !clearcolor)
|
|
|
|
|
return;
|
2017-12-12 07:55:31 +00:00
|
|
|
|
|
2016-02-09 15:11:37 +00:00
|
|
|
|
clear_color = D3DCOLOR_ARGB(
|
|
|
|
|
BYTE_CLAMP(clearcolor->a * 255.0f), /* A */
|
|
|
|
|
BYTE_CLAMP(clearcolor->r * 255.0f), /* R */
|
|
|
|
|
BYTE_CLAMP(clearcolor->g * 255.0f), /* G */
|
|
|
|
|
BYTE_CLAMP(clearcolor->b * 255.0f) /* B */
|
|
|
|
|
);
|
2015-11-08 22:32:46 +00:00
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
d3d8_clear(d3d->dev, 0, NULL, D3D_COMM_CLEAR_TARGET, clear_color, 0, 0);
|
2015-11-08 20:26:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
static bool menu_display_d3d8_font_init_first(
|
2016-02-09 15:11:37 +00:00
|
|
|
|
void **font_handle, void *video_data,
|
2017-04-29 14:52:52 +00:00
|
|
|
|
const char *font_path, float font_size,
|
|
|
|
|
bool is_threaded)
|
2015-11-09 21:12:32 +00:00
|
|
|
|
{
|
2016-10-18 23:07:00 +00:00
|
|
|
|
font_data_t **handle = (font_data_t**)font_handle;
|
2017-10-02 22:56:18 +00:00
|
|
|
|
if (!(*handle = font_driver_init_first(video_data,
|
2017-04-29 14:52:52 +00:00
|
|
|
|
font_path, font_size, true,
|
|
|
|
|
is_threaded,
|
2018-03-03 14:28:58 +00:00
|
|
|
|
FONT_DRIVER_RENDER_D3D8_API)))
|
2017-10-02 22:56:18 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2015-11-09 21:12:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 14:28:58 +00:00
|
|
|
|
menu_display_ctx_driver_t menu_display_ctx_d3d8 = {
|
|
|
|
|
menu_display_d3d8_draw,
|
|
|
|
|
menu_display_d3d8_draw_pipeline,
|
|
|
|
|
menu_display_d3d8_viewport,
|
|
|
|
|
menu_display_d3d8_blend_begin,
|
|
|
|
|
menu_display_d3d8_blend_end,
|
|
|
|
|
menu_display_d3d8_restore_clear_color,
|
|
|
|
|
menu_display_d3d8_clear_color,
|
|
|
|
|
menu_display_d3d8_get_default_mvp,
|
|
|
|
|
menu_display_d3d8_get_default_vertices,
|
|
|
|
|
menu_display_d3d8_get_default_tex_coords,
|
|
|
|
|
menu_display_d3d8_font_init_first,
|
|
|
|
|
MENU_VIDEO_DRIVER_DIRECT3D8,
|
2018-10-08 23:05:46 +00:00
|
|
|
|
"d3d8",
|
2018-09-20 12:48:07 +00:00
|
|
|
|
false,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
2015-11-08 20:26:19 +00:00
|
|
|
|
};
|