Preliminary attempt at Metal support

This commit is contained in:
Struma 2020-11-16 20:26:49 -05:00 committed by zzoro
parent fff60b21da
commit a9d7e0783a
7 changed files with 53 additions and 44 deletions

1
macos/lib/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
MetalANGLE.framework/*

Binary file not shown.

View file

@ -2,10 +2,22 @@
EXE=${MESON_INSTALL_PREFIX}/Contents/MacOS/$2 EXE=${MESON_INSTALL_PREFIX}/Contents/MacOS/$2
ANGLE="${MESON_SOURCE_ROOT}/macos/lib/MetalANGLE.framework"
FRAMEWORKS="${MESON_INSTALL_PREFIX}/Contents/Frameworks"
if [ -n "$(otool -L $EXE | grep ANGLE)" ] && [ -d $ANGLE ]; then
if [ ! -d $FRAMEWORKS ]; then
mkdir -p $FRAMEWORKS
fi
cp -a $ANGLE $FRAMEWORKS
fi
if [ -n "$1" ]; then if [ -n "$1" ]; then
echo "Setting up steam_api manually..." echo "Setting up steam_api manually..."
mkdir -p "${MESON_INSTALL_PREFIX}/Contents/Frameworks" if [ ! -d $FRAMEWORKS ]; then
cp "$1/libsteam_api.dylib" "${MESON_INSTALL_PREFIX}/Contents/Frameworks" mkdir -p $FRAMEWORKS
fi
cp "$1/libsteam_api.dylib" $FRAMEWORKS
install_name_tool -change "@loader_path/libsteam_api.dylib" "@executable_path/../Frameworks/libsteam_api.dylib" $EXE install_name_tool -change "@loader_path/libsteam_api.dylib" "@executable_path/../Frameworks/libsteam_api.dylib" $EXE
install_name_tool -add_rpath "@executable_path/../Frameworks" ${EXE}_rt install_name_tool -add_rpath "@executable_path/../Frameworks" ${EXE}_rt
macpack -d "../Frameworks" ${EXE}_rt macpack -d "../Frameworks" ${EXE}_rt

View file

@ -72,6 +72,36 @@ endif
# BOOST UNORDERED # BOOST UNORDERED
global_include_dirs += include_directories('boost-unordered') global_include_dirs += include_directories('boost-unordered')
# METAL/GLES
gfx_backend = get_option('gfx_backend')
if gfx_backend == 'metal'
# Verify that we can use metal in the first place,
# so 10.13 SDK or higher
message('Verifying that Metal is available...')
if not dependency('Metal', required: false).found()
error('Could not find Metal. Ensure that you are building against the macOS 10.13+ or higher SDK.')
endif
global_args += '-DGLES2_HEADER'
global_args += '-F' + meson.source_root() + '/macos/lib'
mangle = dependency('MetalANGLE', required: false)
if not mangle.found()
warning('There is a pre-built archive of MetalANGLE located in macos/lib.')
warning('Simply extract it to the same directory, or build it yourself.')
error('Could not locate the MetalANGLE framework.')
endif
global_args += '-I' + meson.source_root() + '/macos/lib/MetalANGLE.framework/Headers'
global_link_args += '-F' + meson.source_root() + '/macos/lib'
global_dependencies += mangle
elif gfx_backend == 'gles'
# Needs to be manually set up for now
global_args += '-DGLES2_HEADER'
elif gfx_backend == 'gl'
global_dependencies += dependency('gl')
# boop
endif
# ==================== # ====================
# Main source # Main source
# ==================== # ====================

View file

@ -21,5 +21,7 @@ option('appimage', type: 'boolean', value: false, description: 'Whether to insta
option('steamworks_path', type: 'string', value: '', description: 'Path to Steamshim') option('steamworks_path', type: 'string', value: '', description: 'Path to Steamshim')
option('steam_appid', type: 'string', value: '', description: 'Steam AppID. Set this to use SteamAPI_RestartAppIfNecessary') option('steam_appid', type: 'string', value: '', description: 'Steam AppID. Set this to use SteamAPI_RestartAppIfNecessary')
option('gfx_backend', type: 'combo', value: 'gl', choices: ['gl', 'gles', 'metal'], description: 'Graphics rendering API to use. Metal is achieved through MetalANGLE.')
option('codesign', type: 'boolean', value: false, description: 'Whether to codesign the Mac app bundle upon creation. If codesign_identity is not set, signs for local use.') option('codesign', type: 'boolean', value: false, description: 'Whether to codesign the Mac app bundle upon creation. If codesign_identity is not set, signs for local use.')
option('codesign_identity', type: 'string', value: '', description: 'A valid Apple Developer ID for signing Mac apps.') option('codesign_identity', type: 'string', value: '', description: 'A valid Apple Developer ID for signing Mac apps.')

View file

@ -857,47 +857,12 @@ void Graphics::playMovie(const char *filename) {
} }
void Graphics::screenshot(const char *filename) { void Graphics::screenshot(const char *filename) {
int w = p->scSize.x;
int h = p->scSize.y;
update(); update();
#ifdef __WIN32__ Bitmap *ss = snapToBitmap();
SDL_Surface *img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0); ss->saveToFile(filename);
if (!img) ss->dispose();
throw new Exception(Exception::SDLError, "%s", SDL_GetError()); delete ss;
glReadPixels(p->scOffset.x, p->scOffset.y, w, h, GL_BGRA, GL_UNSIGNED_BYTE,
img->pixels);
#else
SDL_Surface *tmp, *img;
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0);
img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0);
if (!tmp || !img) {
if (tmp)
SDL_FreeSurface(tmp);
if (img)
SDL_FreeSurface(img);
throw Exception(Exception::SDLError, "%s", SDL_GetError());
}
glReadPixels(p->scOffset.x, p->scOffset.y, w, h, GL_BGRA, GL_UNSIGNED_BYTE,
tmp->pixels);
for (int i = 0; i < h; i++) {
memcpy((char *)img->pixels + 4 * w * i,
(char *)tmp->pixels + 4 * w * (h - i - 1), 4 * w);
}
SDL_FreeSurface(tmp);
#endif
char *fn_normalized = shState->fileSystem().normalize(filename, 1, 1);
int rc = SDL_SaveBMP(img, fn_normalized);
SDL_FreeSurface(img);
delete fn_normalized;
if (rc)
throw new Exception(Exception::SDLError, "%s", SDL_GetError());
} }
DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness)

View file

@ -6,7 +6,6 @@ sdl2 = dependency('sdl2', static: build_static)
sdl2_ttf = dependency('SDL2_ttf', static: build_static) sdl2_ttf = dependency('SDL2_ttf', static: build_static)
sdl2_image = dependency('SDL2_image', static: build_static) sdl2_image = dependency('SDL2_image', static: build_static)
sdl_sound = dependency('SDL_sound', static: build_static) sdl_sound = dependency('SDL_sound', static: build_static)
opengl = dependency('GL')
openal = dependency('openal', static: build_static) openal = dependency('openal', static: build_static)
zlib = dependency('zlib', static: build_static) zlib = dependency('zlib', static: build_static)
@ -39,7 +38,7 @@ endif
global_args += '-DALCDEVICE_STRUCT=' + alcdev_struct global_args += '-DALCDEVICE_STRUCT=' + alcdev_struct
global_include_dirs += include_directories('.') global_include_dirs += include_directories('.')
global_dependencies += [sigcxx, openal, opengl, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] global_dependencies += [sigcxx, openal, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound]
if host_system == 'darwin' if host_system == 'darwin'
global_dependencies += compilers['cpp'].find_library('iconv') global_dependencies += compilers['cpp'].find_library('iconv')
global_dependencies += dependency('Foundation') global_dependencies += dependency('Foundation')