mirror of
https://github.com/libretro/RetroArch
synced 2025-01-18 04:12:07 +00:00
a0900ec433
Menu TODOs: * understand why ribbon does not look the same as GL * add clear support to `MenuDisplay` for glui
73 lines
1.7 KiB
Objective-C
73 lines
1.7 KiB
Objective-C
//
|
|
// RendererCommon.m
|
|
// MetalRenderer
|
|
//
|
|
// Created by Stuart Carnie on 6/3/18.
|
|
// Copyright © 2018 Stuart Carnie. All rights reserved.
|
|
//
|
|
|
|
#import "RendererCommon.h"
|
|
#import <Metal/Metal.h>
|
|
|
|
NSUInteger RPixelFormatToBPP(RPixelFormat format)
|
|
{
|
|
switch (format) {
|
|
case RPixelFormatBGRA8Unorm:
|
|
case RPixelFormatBGRX8Unorm:
|
|
return 4;
|
|
|
|
case RPixelFormatB5G6R5Unorm:
|
|
case RPixelFormatBGRA4Unorm:
|
|
return 2;
|
|
|
|
default:
|
|
RARCH_ERR("[Metal]: unknown RPixel format: %d\n", format);
|
|
return 4;
|
|
}
|
|
}
|
|
|
|
static NSString *RPixelStrings[RPixelFormatCount];
|
|
|
|
NSString *NSStringFromRPixelFormat(RPixelFormat format)
|
|
{
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
#define STRING(literal) RPixelStrings[literal] = @#literal
|
|
STRING(RPixelFormatInvalid);
|
|
STRING(RPixelFormatB5G6R5Unorm);
|
|
STRING(RPixelFormatBGRA4Unorm);
|
|
STRING(RPixelFormatBGRA8Unorm);
|
|
STRING(RPixelFormatBGRX8Unorm);
|
|
#undef STRING
|
|
|
|
});
|
|
|
|
if (format >= RPixelFormatCount) {
|
|
format = RPixelFormatInvalid;
|
|
}
|
|
|
|
return RPixelStrings[format];
|
|
}
|
|
|
|
matrix_float4x4 matrix_proj_ortho(float left, float right, float top, float bottom)
|
|
{
|
|
float near = 0;
|
|
float far = 1;
|
|
|
|
float sx = 2 / (right - left);
|
|
float sy = 2 / (top - bottom);
|
|
float sz = 1 / (far - near);
|
|
float tx = (right + left) / (left - right);
|
|
float ty = (top + bottom) / (bottom - top);
|
|
float tz = near / (far - near);
|
|
|
|
simd_float4 P = simd_make_float4(sx, 0, 0, 0);
|
|
simd_float4 Q = simd_make_float4(0, sy, 0, 0);
|
|
simd_float4 R = simd_make_float4(0, 0, sz, 0);
|
|
simd_float4 S = simd_make_float4(tx, ty, tz, 1);
|
|
|
|
matrix_float4x4 mat = {P, Q, R, S};
|
|
return mat;
|
|
}
|