mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-15 14:59:37 +00:00
fix(Metal): fix XRGBA rendering; no nil texture; undefined stuff bad
This commit is contained in:
parent
c0dba89d43
commit
844e5e15d0
@ -134,6 +134,8 @@
|
||||
|
||||
- (Texture *)newTexture:(struct texture_image)image filter:(enum texture_filter_type)filter
|
||||
{
|
||||
assert(filter >= TEXTURE_FILTER_LINEAR && filter <= TEXTURE_FILTER_MIPMAP_NEAREST);
|
||||
|
||||
if (!image.pixels && !image.width && !image.height)
|
||||
{
|
||||
/* Create a dummy texture instead. */
|
||||
|
@ -131,7 +131,6 @@
|
||||
|
||||
- (void)draw:(menu_display_ctx_draw_t *)draw video:(video_frame_info_t *)video
|
||||
{
|
||||
Texture *tex = (__bridge Texture *)(void *)draw->texture;
|
||||
const float *vertex = draw->coords->vertex ?: MenuDisplay.defaultVertices;
|
||||
const float *tex_coord = draw->coords->tex_coord ?: MenuDisplay.defaultTexCoords;
|
||||
const float *color = draw->coords->color ?: MenuDisplay.defaultColor;
|
||||
@ -178,37 +177,37 @@
|
||||
case VIDEO_SHADER_MENU_4:
|
||||
case VIDEO_SHADER_MENU_5:
|
||||
case VIDEO_SHADER_MENU_6:
|
||||
{
|
||||
[rce setRenderPipelineState:[_driver getStockShader:draw->pipeline.id blend:_blend]];
|
||||
[rce setVertexBytes:draw->pipeline.backend_data length:draw->pipeline.backend_data_size atIndex:BufferIndexUniforms];
|
||||
[rce setVertexBuffer:range.buffer offset:range.offset atIndex:BufferIndexPositions];
|
||||
[rce setFragmentBytes:draw->pipeline.backend_data length:draw->pipeline.backend_data_size atIndex:BufferIndexUniforms];
|
||||
[rce drawPrimitives:[self _toPrimitiveType:draw->prim_type] vertexStart:0 vertexCount:vertexCount];
|
||||
break;
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
if (_clearNextRender)
|
||||
{
|
||||
// TODO(sgc): draw quad to clear
|
||||
_clearNextRender = NO;
|
||||
}
|
||||
|
||||
[rce setRenderPipelineState:[_driver getStockShader:VIDEO_SHADER_STOCK_BLEND blend:_blend]];
|
||||
|
||||
Uniforms uniforms = {
|
||||
.projectionMatrix = draw->matrix_data ? make_matrix_float4x4((const float *)draw->matrix_data)
|
||||
: _uniforms.projectionMatrix
|
||||
};
|
||||
[rce setVertexBytes:&uniforms length:sizeof(uniforms) atIndex:BufferIndexUniforms];
|
||||
[rce setVertexBuffer:range.buffer offset:range.offset atIndex:BufferIndexPositions];
|
||||
[rce setFragmentTexture:tex.texture atIndex:TextureIndexColor];
|
||||
[rce setFragmentSamplerState:tex.sampler atIndex:SamplerIndexDraw];
|
||||
[rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:vertexCount];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Texture *tex = (__bridge Texture *)(void *)draw->texture;
|
||||
if (tex == nil)
|
||||
return;
|
||||
|
||||
if (_clearNextRender)
|
||||
{
|
||||
// TODO(sgc): draw quad to clear
|
||||
_clearNextRender = NO;
|
||||
}
|
||||
|
||||
[rce setRenderPipelineState:[_driver getStockShader:VIDEO_SHADER_STOCK_BLEND blend:_blend]];
|
||||
|
||||
Uniforms uniforms = {
|
||||
.projectionMatrix = draw->matrix_data ? make_matrix_float4x4((const float *)draw->matrix_data)
|
||||
: _uniforms.projectionMatrix
|
||||
};
|
||||
[rce setVertexBytes:&uniforms length:sizeof(uniforms) atIndex:BufferIndexUniforms];
|
||||
[rce setVertexBuffer:range.buffer offset:range.offset atIndex:BufferIndexPositions];
|
||||
[rce setFragmentTexture:tex.texture atIndex:TextureIndexColor];
|
||||
[rce setFragmentSamplerState:tex.sampler atIndex:SamplerIndexDraw];
|
||||
[rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:vertexCount];
|
||||
}
|
||||
@end
|
||||
|
@ -54,10 +54,13 @@ NSString *NSStringFromRPixelFormat(RPixelFormat format)
|
||||
|
||||
matrix_float4x4 make_matrix_float4x4(const float *v)
|
||||
{
|
||||
simd_float4 P = simd_make_float4(*v++, *v++, *v++, *v++);
|
||||
simd_float4 Q = simd_make_float4(*v++, *v++, *v++, *v++);
|
||||
simd_float4 R = simd_make_float4(*v++, *v++, *v++, *v++);
|
||||
simd_float4 S = simd_make_float4(*v++, *v++, *v++, *v++);
|
||||
simd_float4 P = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
v+=4;
|
||||
simd_float4 Q = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
v+=4;
|
||||
simd_float4 R = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
v+=4;
|
||||
simd_float4 S = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
|
||||
matrix_float4x4 mat = {P, Q, R, S};
|
||||
return mat;
|
||||
|
@ -901,7 +901,7 @@ typedef struct MTLALIGN(16)
|
||||
id<MTLTexture> tex = _engine.frame.texture[0].view;
|
||||
[tex replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)_size.width, (NSUInteger)_size.height)
|
||||
mipmapLevel:0 withBytes:src
|
||||
bytesPerRow:(NSUInteger)(4 * pitch)];
|
||||
bytesPerRow:pitch];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user