2018-01-21 07:57:25 +01:00
|
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-11-08 21:26:19 +01: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 14:27:39 +02:00
|
|
|
|
#define CINTERFACE
|
|
|
|
|
|
2015-11-08 21:26:19 +01:00
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
|
2005-04-23 20:22:55 +02:00
|
|
|
|
#include <gfx/math/matrix_4x4.h>
|
|
|
|
|
|
2016-09-08 06:02:41 +02:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "../../config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
#include "../gfx_display.h"
|
2016-09-08 06:02:41 +02:00
|
|
|
|
|
2019-06-17 15:10:22 +02:00
|
|
|
|
#include "../../retroarch.h"
|
2020-02-16 15:26:58 +01:00
|
|
|
|
#include "../common/d3d_common.h"
|
|
|
|
|
#include "../common/d3d8_common.h"
|
2016-12-02 01:46:16 +01:00
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
|
static const float d3d8_vertexes[] = {
|
2015-11-08 21:26:19 +01:00
|
|
|
|
0, 0,
|
|
|
|
|
1, 0,
|
|
|
|
|
0, 1,
|
|
|
|
|
1, 1
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
|
static const float d3d8_tex_coords[] = {
|
2015-11-08 21:26:19 +01:00
|
|
|
|
0, 1,
|
|
|
|
|
1, 1,
|
|
|
|
|
0, 0,
|
|
|
|
|
1, 0
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
static const float *gfx_display_d3d8_get_default_vertices(void)
|
2016-04-15 03:24:21 +02:00
|
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
|
return &d3d8_vertexes[0];
|
2016-04-15 03:24:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
static const float *gfx_display_d3d8_get_default_tex_coords(void)
|
2016-04-15 03:24:21 +02:00
|
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
|
return &d3d8_tex_coords[0];
|
2016-04-15 03:24:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 19:59:03 +01:00
|
|
|
|
static void *gfx_display_d3d8_get_default_mvp(void *data)
|
2015-11-20 17:45:10 +01:00
|
|
|
|
{
|
2022-04-16 22:33:18 +02:00
|
|
|
|
static float id[] = { 1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f
|
|
|
|
|
};
|
2020-09-11 14:16:12 +02:00
|
|
|
|
return &id;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
static INT32 gfx_display_prim_to_d3d8_enum(
|
|
|
|
|
enum gfx_display_prim_type prim_type)
|
2015-11-08 21:26:19 +01:00
|
|
|
|
{
|
|
|
|
|
switch (prim_type)
|
|
|
|
|
{
|
2020-02-16 15:10:07 +01:00
|
|
|
|
case GFX_DISPLAY_PRIM_TRIANGLES:
|
|
|
|
|
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
|
2018-01-26 03:53:37 +01:00
|
|
|
|
return D3DPT_COMM_TRIANGLESTRIP;
|
2020-02-16 15:10:07 +01:00
|
|
|
|
case GFX_DISPLAY_PRIM_NONE:
|
2015-11-08 21:26:19 +01:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-26 23:31:12 +02:00
|
|
|
|
/* TODO/FIXME - hack */
|
2018-01-26 03:53:37 +01:00
|
|
|
|
return 0;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 21:02:03 +01:00
|
|
|
|
static void gfx_display_d3d8_blend_begin(void *data)
|
2015-11-08 21:26:19 +01:00
|
|
|
|
{
|
2020-03-08 21:02:03 +01:00
|
|
|
|
d3d8_video_t *d3d = (d3d8_video_t*)data;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-04-20 17:26:03 +02:00
|
|
|
|
IDirect3DDevice8_SetRenderState(d3d->dev, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
|
|
|
IDirect3DDevice8_SetRenderState(d3d->dev, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
|
|
|
IDirect3DDevice8_SetRenderState(d3d->dev, D3DRS_ALPHABLENDENABLE, true);
|
2015-11-08 21:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 21:02:03 +01:00
|
|
|
|
static void gfx_display_d3d8_blend_end(void *data)
|
2015-11-08 21:26:19 +01:00
|
|
|
|
{
|
2020-03-08 21:02:03 +01:00
|
|
|
|
d3d8_video_t *d3d = (d3d8_video_t*)data;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-04-20 17:26:03 +02:00
|
|
|
|
IDirect3DDevice8_SetRenderState(d3d->dev, D3DRS_ALPHABLENDENABLE, false);
|
2015-11-08 21:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
static void gfx_display_d3d8_draw(gfx_display_ctx_draw_t *draw,
|
2020-03-08 22:05:51 +01:00
|
|
|
|
void *data,
|
|
|
|
|
unsigned video_width,
|
|
|
|
|
unsigned video_height)
|
2016-04-19 08:50:35 +02:00
|
|
|
|
{
|
2022-04-22 15:05:28 +02:00
|
|
|
|
static float default_mvp[] ={ 1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f
|
|
|
|
|
};
|
2018-01-14 02:21:48 +01:00
|
|
|
|
unsigned i;
|
2018-01-15 03:45:37 +01:00
|
|
|
|
math_matrix_4x4 mop, m1, m2;
|
2022-04-22 15:05:28 +02:00
|
|
|
|
LPDIRECT3DDEVICE8 dev;
|
|
|
|
|
D3DPRIMITIVETYPE type;
|
|
|
|
|
unsigned start = 0;
|
|
|
|
|
unsigned count = 0;
|
2020-03-08 22:05:51 +01:00
|
|
|
|
d3d8_video_t *d3d = (d3d8_video_t*)data;
|
2018-01-19 02:24:10 +01:00
|
|
|
|
Vertex * pv = NULL;
|
2018-01-14 02:21:48 +01:00
|
|
|
|
const float *vertex = NULL;
|
|
|
|
|
const float *tex_coord = NULL;
|
|
|
|
|
const float *color = NULL;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
|
2020-08-14 15:58:43 +02:00
|
|
|
|
if (!d3d || !draw || draw->pipeline_id)
|
2015-11-08 21:26:19 +01:00
|
|
|
|
return;
|
2020-02-10 13:18:27 +01:00
|
|
|
|
if ((d3d->menu_display.offset + draw->coords->vertices )
|
2018-01-21 07:57:25 +01:00
|
|
|
|
> (unsigned)d3d->menu_display.size)
|
2018-01-15 03:45:37 +01:00
|
|
|
|
return;
|
2022-04-22 15:05:28 +02:00
|
|
|
|
dev = d3d->dev;
|
|
|
|
|
pv = (Vertex*)
|
2018-03-03 15:28:58 +01:00
|
|
|
|
d3d8_vertex_buffer_lock(d3d->menu_display.buffer);
|
2018-01-19 03:40:34 +01:00
|
|
|
|
|
|
|
|
|
if (!pv)
|
2018-01-14 02:21:48 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2018-01-19 03:40:34 +01:00
|
|
|
|
pv += d3d->menu_display.offset;
|
|
|
|
|
vertex = draw->coords->vertex;
|
|
|
|
|
tex_coord = draw->coords->tex_coord;
|
|
|
|
|
color = draw->coords->color;
|
2017-11-15 16:51:29 +01:00
|
|
|
|
|
2018-01-15 03:45:37 +01:00
|
|
|
|
if (!vertex)
|
2020-09-11 13:46:35 +02:00
|
|
|
|
vertex = &d3d8_vertexes[0];
|
2018-01-15 03:45:37 +01:00
|
|
|
|
if (!tex_coord)
|
2020-09-11 13:46:35 +02:00
|
|
|
|
tex_coord = &d3d8_tex_coords[0];
|
2018-01-15 03:45:37 +01:00
|
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
|
for (i = 0; i < draw->coords->vertices; i++)
|
|
|
|
|
{
|
2018-01-19 02:24:10 +01:00
|
|
|
|
int colors[4];
|
|
|
|
|
|
2018-01-19 03:40:34 +01: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 15:28:58 +01:00
|
|
|
|
|
|
|
|
|
#if 1
|
2018-02-17 19:19:16 +01:00
|
|
|
|
if ((void*)draw->texture)
|
2018-01-20 07:00:03 +01:00
|
|
|
|
{
|
2018-04-22 14:55:15 +02:00
|
|
|
|
D3DSURFACE_DESC desc;
|
2018-03-03 15:28:58 +01:00
|
|
|
|
if (d3d8_texture_get_level_desc((void*)draw->texture, 0, &desc))
|
2018-01-20 07:00:03 +01:00
|
|
|
|
{
|
|
|
|
|
pv[i].u *= desc.Width;
|
|
|
|
|
pv[i].v *= desc.Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-01-19 02:24:10 +01:00
|
|
|
|
|
|
|
|
|
pv[i].color =
|
|
|
|
|
D3DCOLOR_ARGB(
|
|
|
|
|
colors[3], /* A */
|
|
|
|
|
colors[0], /* R */
|
|
|
|
|
colors[1], /* G */
|
|
|
|
|
colors[2] /* B */
|
|
|
|
|
);
|
2018-01-14 02:21:48 +01:00
|
|
|
|
}
|
2018-03-03 15:28:58 +01:00
|
|
|
|
d3d8_vertex_buffer_unlock(d3d->menu_display.buffer);
|
2017-11-15 16:51:29 +01:00
|
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
|
if (!draw->matrix_data)
|
2022-04-22 15:05:28 +02:00
|
|
|
|
draw->matrix_data = &default_mvp;
|
2018-01-15 03:45:37 +01:00
|
|
|
|
|
|
|
|
|
/* ugh */
|
2018-01-19 03:40:34 +01:00
|
|
|
|
matrix_4x4_scale(m1, 2.0, 2.0, 0);
|
2018-01-15 03:45:37 +01:00
|
|
|
|
matrix_4x4_translate(mop, -1.0, -1.0, 0);
|
|
|
|
|
matrix_4x4_multiply(m2, mop, m1);
|
2018-01-19 03:40:34 +01:00
|
|
|
|
matrix_4x4_multiply(m1,
|
|
|
|
|
*((math_matrix_4x4*)draw->matrix_data), m2);
|
|
|
|
|
matrix_4x4_scale(mop,
|
2020-03-07 21:18:12 +01:00
|
|
|
|
(draw->width / 2.0) / video_width,
|
|
|
|
|
(draw->height / 2.0) / video_height, 0);
|
2018-01-15 03:45:37 +01:00
|
|
|
|
matrix_4x4_multiply(m2, mop, m1);
|
2018-01-19 03:40:34 +01:00
|
|
|
|
matrix_4x4_translate(mop,
|
2020-03-07 21:18:12 +01:00
|
|
|
|
(draw->x + (draw->width / 2.0)) / video_width,
|
|
|
|
|
(draw->y + (draw->height / 2.0)) / video_height,
|
2018-01-19 03:40:34 +01:00
|
|
|
|
0);
|
2018-01-15 03:45:37 +01:00
|
|
|
|
matrix_4x4_multiply(m1, mop, m2);
|
|
|
|
|
matrix_4x4_multiply(m2, d3d->mvp_transposed, m1);
|
|
|
|
|
d3d_matrix_transpose(&m1, &m2);
|
|
|
|
|
|
2022-04-22 15:05:28 +02:00
|
|
|
|
d3d8_set_mvp(dev, &m1);
|
2019-03-18 15:19:11 +01:00
|
|
|
|
|
2022-04-22 15:05:28 +02:00
|
|
|
|
if (draw->texture)
|
|
|
|
|
{
|
|
|
|
|
IDirect3DDevice8_SetTexture(dev, 0,
|
|
|
|
|
(IDirect3DBaseTexture8*)draw->texture);
|
|
|
|
|
IDirect3DDevice8_SetTextureStageState(dev, 0,
|
|
|
|
|
(D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, D3DTADDRESS_COMM_CLAMP);
|
|
|
|
|
IDirect3DDevice8_SetTextureStageState(dev, 0,
|
|
|
|
|
(D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, D3DTADDRESS_COMM_CLAMP);
|
|
|
|
|
IDirect3DDevice8_SetTextureStageState(dev, 0,
|
|
|
|
|
(D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, D3DTEXF_COMM_LINEAR);
|
|
|
|
|
IDirect3DDevice8_SetTextureStageState(dev, 0,
|
|
|
|
|
(D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, D3DTEXF_COMM_LINEAR);
|
|
|
|
|
}
|
2018-05-13 14:43:40 +02:00
|
|
|
|
|
2022-04-22 15:05:28 +02:00
|
|
|
|
type = gfx_display_prim_to_d3d8_enum(draw->prim_type);
|
|
|
|
|
start = d3d->menu_display.offset;
|
|
|
|
|
count = draw->coords->vertices -
|
2020-02-16 15:10:07 +01:00
|
|
|
|
((draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
|
2022-04-22 15:05:28 +02:00
|
|
|
|
? 2 : 0);
|
|
|
|
|
|
|
|
|
|
IDirect3DDevice8_BeginScene(dev);
|
|
|
|
|
IDirect3DDevice8_DrawPrimitive(dev, type, start, count);
|
|
|
|
|
IDirect3DDevice8_EndScene(dev);
|
2015-11-08 21:26:19 +01:00
|
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
|
d3d->menu_display.offset += draw->coords->vertices;
|
2015-11-08 21:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
static bool gfx_display_d3d8_font_init_first(
|
2016-02-09 16:11:37 +01:00
|
|
|
|
void **font_handle, void *video_data,
|
2017-04-29 16:52:52 +02:00
|
|
|
|
const char *font_path, float font_size,
|
|
|
|
|
bool is_threaded)
|
2015-11-09 22:12:32 +01:00
|
|
|
|
{
|
2016-10-18 20:07:00 -03:00
|
|
|
|
font_data_t **handle = (font_data_t**)font_handle;
|
2017-10-03 00:56:18 +02:00
|
|
|
|
if (!(*handle = font_driver_init_first(video_data,
|
2017-04-29 16:52:52 +02:00
|
|
|
|
font_path, font_size, true,
|
|
|
|
|
is_threaded,
|
2018-03-03 15:28:58 +01:00
|
|
|
|
FONT_DRIVER_RENDER_D3D8_API)))
|
2017-10-03 00:56:18 +02:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2015-11-09 22:12:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
|
gfx_display_ctx_driver_t gfx_display_ctx_d3d8 = {
|
|
|
|
|
gfx_display_d3d8_draw,
|
2020-09-26 23:31:12 +02:00
|
|
|
|
NULL, /* draw_pipeline */
|
2020-02-16 15:10:07 +01:00
|
|
|
|
gfx_display_d3d8_blend_begin,
|
|
|
|
|
gfx_display_d3d8_blend_end,
|
|
|
|
|
gfx_display_d3d8_get_default_mvp,
|
|
|
|
|
gfx_display_d3d8_get_default_vertices,
|
|
|
|
|
gfx_display_d3d8_get_default_tex_coords,
|
|
|
|
|
gfx_display_d3d8_font_init_first,
|
|
|
|
|
GFX_VIDEO_DRIVER_DIRECT3D8,
|
2018-10-09 01:05:46 +02:00
|
|
|
|
"d3d8",
|
2018-09-20 14:48:07 +02:00
|
|
|
|
false,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
2015-11-08 21:26:19 +01:00
|
|
|
|
};
|