feat(metal): Add scissor rect support

This is required for correct rendering of the ozone menu
This commit is contained in:
Stuart Carnie 2018-11-06 07:51:40 -07:00
parent 0485d741a2
commit 8569ee79bc
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
5 changed files with 58 additions and 3 deletions

View File

@ -61,6 +61,9 @@ typedef struct
/*! @brief resets the viewport for the main render encoder to the drawable size */
- (void)resetRenderViewport;
/*! @brief resets the scissor rect for the main render encoder to the drawable size */
- (void)resetScissorRect;
/*! @brief draws a quad at the specified position (normalized coordinates) using the main render encoder */
- (void)drawQuadX:(float)x y:(float)y w:(float)w h:(float)h
r:(float)r g:(float)g b:(float)b a:(float)a;

View File

@ -565,6 +565,17 @@
[self.rce setViewport:vp];
}
- (void)resetScissorRect
{
MTLScissorRect sr = {
.x = 0,
.y = 0,
.width = _viewport.full_width,
.height = _viewport.full_height,
};
[self.rce setScissorRect:sr];
}
- (void)drawQuadX:(float)x y:(float)y w:(float)w h:(float)h
r:(float)r g:(float)g b:(float)b a:(float)a
{

View File

@ -14,6 +14,8 @@
- (instancetype)initWithContext:(Context *)context;
- (void)drawPipeline:(menu_display_ctx_draw_t *)draw video:(video_frame_info_t *)video;
- (void)draw:(menu_display_ctx_draw_t *)draw video:(video_frame_info_t *)video;
- (void)setScissorRect:(MTLScissorRect)rect;
- (void)clearScissorRect;
#pragma mark - static methods

View File

@ -14,8 +14,10 @@
{
Context *_context;
MTLClearColor _clearColor;
bool _clearNextRender;
MTLScissorRect _scissorRect;
BOOL _useScissorRect;
Uniforms _uniforms;
bool _clearNextRender;
}
- (instancetype)initWithContext:(Context *)context
@ -25,6 +27,7 @@
_context = context;
_clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0);
_uniforms.projectionMatrix = matrix_proj_ortho(0, 1, 0, 1);
_useScissorRect = NO;
}
return self;
}
@ -73,6 +76,19 @@
return _clearColor;
}
- (void)setScissorRect:(MTLScissorRect)rect
{
_scissorRect = rect;
_useScissorRect = YES;
}
- (void)clearScissorRect
{
_useScissorRect = NO;
[_context resetScissorRect];
}
- (MTLPrimitiveType)_toPrimitiveType:(enum menu_display_prim_type)prim
{
switch (prim)
@ -181,6 +197,10 @@
};
[rce setViewport:vp];
if (_useScissorRect) {
[rce setScissorRect:_scissorRect];
}
switch (draw->pipeline.id)
{
#if HAVE_SHADERPIPELINE

View File

@ -88,6 +88,25 @@ static void menu_display_metal_viewport(menu_display_ctx_draw_t *draw,
{
}
static void menu_display_metal_scissor_begin(video_frame_info_t *video_info, int x, int y, unsigned width, unsigned height)
{
MetalDriver *md = GET_DRIVER(video_info);
if (!md)
return;
MTLScissorRect r = {.x = (NSUInteger)x, .y = (NSUInteger)y, .width = width, .height = height};
[md.display setScissorRect:r];
}
static void menu_display_metal_scissor_end(video_frame_info_t *video_info)
{
MetalDriver *md = GET_DRIVER(video_info);
if (!md)
return;
[md.display clearScissorRect];
}
static void menu_display_metal_restore_clear_color(void)
{
// nothing to do
@ -135,7 +154,7 @@ menu_display_ctx_driver_t menu_display_ctx_metal = {
.type = MENU_VIDEO_DRIVER_METAL,
.ident = "menu_display_metal",
.handles_transform = NO,
.scissor_begin = NULL,
.scissor_end = NULL
.scissor_begin = menu_display_metal_scissor_begin,
.scissor_end = menu_display_metal_scissor_end
};