2018-08-16 10:18:00 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2018 - Stuart Carnie
|
|
|
|
*
|
|
|
|
* 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-06-20 21:29:53 -07:00
|
|
|
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
#include "../gfx_display.h"
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2020-02-16 15:26:58 +01:00
|
|
|
#include "../font_driver.h"
|
2019-06-17 15:10:22 +02:00
|
|
|
#include "../../retroarch.h"
|
2020-02-16 15:26:58 +01:00
|
|
|
#import "../common/metal_common.h"
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static const float *gfx_display_metal_get_default_vertices(void)
|
2018-06-29 22:57:48 -07:00
|
|
|
{
|
|
|
|
return [MenuDisplay defaultVertices];
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static const float *gfx_display_metal_get_default_tex_coords(void)
|
2018-06-29 22:57:48 -07:00
|
|
|
{
|
|
|
|
return [MenuDisplay defaultTexCoords];
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:59:03 +01:00
|
|
|
static void *gfx_display_metal_get_default_mvp(void *data)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 19:59:03 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-29 22:57:48 -07:00
|
|
|
if (!md)
|
|
|
|
return NULL;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-07-12 21:33:18 -07:00
|
|
|
return (void *)&md.viewportMVP->projectionMatrix;
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-03-08 21:02:03 +01:00
|
|
|
static void gfx_display_metal_blend_begin(void *data)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 21:02:03 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-29 22:57:48 -07:00
|
|
|
if (!md)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-06-29 22:57:48 -07:00
|
|
|
md.display.blend = YES;
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-03-08 21:02:03 +01:00
|
|
|
static void gfx_display_metal_blend_end(void *data)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 21:02:03 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-29 22:57:48 -07:00
|
|
|
if (!md)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-06-29 22:57:48 -07:00
|
|
|
md.display.blend = NO;
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static void gfx_display_metal_draw(gfx_display_ctx_draw_t *draw,
|
2020-03-08 22:05:51 +01:00
|
|
|
void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 22:05:51 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-29 22:57:48 -07:00
|
|
|
if (!md || !draw)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2020-03-08 22:05:51 +01:00
|
|
|
[md.display draw:draw];
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-03-08 22:05:51 +01:00
|
|
|
static void gfx_display_metal_draw_pipeline(
|
|
|
|
gfx_display_ctx_draw_t *draw,
|
|
|
|
void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 22:05:51 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-30 10:30:43 -07:00
|
|
|
if (!md || !draw)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2020-03-08 22:05:51 +01:00
|
|
|
[md.display drawPipeline:draw];
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static void gfx_display_metal_viewport(gfx_display_ctx_draw_t *draw,
|
2020-03-09 01:18:01 +01:00
|
|
|
void *data) { }
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2020-03-08 21:46:52 +01:00
|
|
|
static void gfx_display_metal_scissor_begin(
|
|
|
|
void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height,
|
|
|
|
int x, int y, unsigned width, unsigned height)
|
2018-11-06 07:51:40 -07:00
|
|
|
{
|
2020-03-08 21:46:52 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-11-06 07:51:40 -07:00
|
|
|
if (!md)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-11-06 07:51:40 -07:00
|
|
|
MTLScissorRect r = {.x = (NSUInteger)x, .y = (NSUInteger)y, .width = width, .height = height};
|
|
|
|
[md.display setScissorRect:r];
|
|
|
|
}
|
|
|
|
|
2020-03-08 21:46:52 +01:00
|
|
|
static void gfx_display_metal_scissor_end(void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height)
|
2018-11-06 07:51:40 -07:00
|
|
|
{
|
2020-03-08 21:46:52 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-11-06 07:51:40 -07:00
|
|
|
if (!md)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-11-06 07:51:40 -07:00
|
|
|
[md.display clearScissorRect];
|
|
|
|
}
|
|
|
|
|
2020-03-08 21:46:52 +01:00
|
|
|
/* Nothing to do */
|
|
|
|
static void gfx_display_metal_restore_clear_color(void) { }
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2020-03-08 21:46:52 +01:00
|
|
|
static void gfx_display_metal_clear_color(
|
|
|
|
gfx_display_ctx_clearcolor_t *clearcolor,
|
2020-03-08 22:05:51 +01:00
|
|
|
void *data)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2020-03-08 22:05:51 +01:00
|
|
|
MetalDriver *md = (__bridge MetalDriver *)data;
|
2018-06-29 22:57:48 -07:00
|
|
|
if (!md)
|
|
|
|
return;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-06-29 22:57:48 -07:00
|
|
|
md.display.clearColor = MTLClearColorMake(clearcolor->r, clearcolor->g, clearcolor->b, clearcolor->a);
|
2018-06-20 21:29:53 -07:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static bool gfx_display_metal_font_init_first(
|
2018-06-29 22:57:48 -07:00
|
|
|
void **font_handle, void *video_data,
|
|
|
|
const char *font_path, float font_size,
|
|
|
|
bool is_threaded)
|
2018-06-20 21:29:53 -07:00
|
|
|
{
|
2018-06-29 22:57:48 -07:00
|
|
|
font_data_t **handle = (font_data_t **)font_handle;
|
2018-06-20 21:29:53 -07:00
|
|
|
*handle = font_driver_init_first(video_data,
|
2020-03-08 21:46:52 +01:00
|
|
|
font_path, font_size, true,
|
|
|
|
is_threaded,
|
|
|
|
FONT_DRIVER_RENDER_METAL_API);
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-06-20 21:29:53 -07:00
|
|
|
if (*handle)
|
|
|
|
return true;
|
2019-02-03 15:49:35 -08:00
|
|
|
|
2018-06-20 21:29:53 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
gfx_display_ctx_driver_t gfx_display_ctx_metal = {
|
|
|
|
.draw = gfx_display_metal_draw,
|
|
|
|
.draw_pipeline = gfx_display_metal_draw_pipeline,
|
|
|
|
.viewport = gfx_display_metal_viewport,
|
|
|
|
.blend_begin = gfx_display_metal_blend_begin,
|
|
|
|
.blend_end = gfx_display_metal_blend_end,
|
|
|
|
.restore_clear_color = gfx_display_metal_restore_clear_color,
|
|
|
|
.clear_color = gfx_display_metal_clear_color,
|
|
|
|
.get_default_mvp = gfx_display_metal_get_default_mvp,
|
|
|
|
.get_default_vertices = gfx_display_metal_get_default_vertices,
|
|
|
|
.get_default_tex_coords = gfx_display_metal_get_default_tex_coords,
|
|
|
|
.font_init_first = gfx_display_metal_font_init_first,
|
|
|
|
.type = GFX_VIDEO_DRIVER_METAL,
|
|
|
|
.ident = "gfx_display_metal",
|
2018-06-29 22:57:48 -07:00
|
|
|
.handles_transform = NO,
|
2020-02-16 15:10:07 +01:00
|
|
|
.scissor_begin = gfx_display_metal_scissor_begin,
|
|
|
|
.scissor_end = gfx_display_metal_scissor_end
|
2018-06-20 21:29:53 -07:00
|
|
|
};
|