fix(Metal): fix XRGBA rendering; no nil texture; undefined stuff bad

This commit is contained in:
Stuart Carnie 2018-07-04 08:50:46 -07:00
parent c0dba89d43
commit 844e5e15d0
4 changed files with 33 additions and 29 deletions

View File

@ -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. */

View File

@ -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

View File

@ -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;

View File

@ -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
{