diff --git a/macos/lib/.gitignore b/macos/lib/.gitignore new file mode 100644 index 0000000..1da08e0 --- /dev/null +++ b/macos/lib/.gitignore @@ -0,0 +1 @@ +MetalANGLE.framework/* \ No newline at end of file diff --git a/macos/lib/MetalANGLE.framework.zip b/macos/lib/MetalANGLE.framework.zip new file mode 100644 index 0000000..1dd6b6f Binary files /dev/null and b/macos/lib/MetalANGLE.framework.zip differ diff --git a/macos/macpack.sh b/macos/macpack.sh index 30d617b..608ae7a 100755 --- a/macos/macpack.sh +++ b/macos/macpack.sh @@ -2,10 +2,22 @@ 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 echo "Setting up steam_api manually..." - mkdir -p "${MESON_INSTALL_PREFIX}/Contents/Frameworks" - cp "$1/libsteam_api.dylib" "${MESON_INSTALL_PREFIX}/Contents/Frameworks" + if [ ! -d $FRAMEWORKS ]; then + 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 -add_rpath "@executable_path/../Frameworks" ${EXE}_rt macpack -d "../Frameworks" ${EXE}_rt diff --git a/meson.build b/meson.build index 332be83..aa74581 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,36 @@ endif # 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 # ==================== diff --git a/meson_options.txt b/meson_options.txt index b108ce6..75bbe54 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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('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_identity', type: 'string', value: '', description: 'A valid Apple Developer ID for signing Mac apps.') \ No newline at end of file diff --git a/src/graphics.cpp b/src/graphics.cpp index 92cd511..1cf3298 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -857,47 +857,12 @@ void Graphics::playMovie(const char *filename) { } void Graphics::screenshot(const char *filename) { - int w = p->scSize.x; - int h = p->scSize.y; - update(); -#ifdef __WIN32__ - SDL_Surface *img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0); - if (!img) - throw new Exception(Exception::SDLError, "%s", SDL_GetError()); - - 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()); + Bitmap *ss = snapToBitmap(); + ss->saveToFile(filename); + ss->dispose(); + delete ss; } DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) diff --git a/src/meson.build b/src/meson.build index 633feae..c32c958 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,7 +6,6 @@ sdl2 = dependency('sdl2', static: build_static) sdl2_ttf = dependency('SDL2_ttf', static: build_static) sdl2_image = dependency('SDL2_image', static: build_static) sdl_sound = dependency('SDL_sound', static: build_static) -opengl = dependency('GL') openal = dependency('openal', static: build_static) zlib = dependency('zlib', static: build_static) @@ -39,13 +38,13 @@ endif global_args += '-DALCDEVICE_STRUCT=' + alcdev_struct 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' global_dependencies += compilers['cpp'].find_library('iconv') global_dependencies += dependency('Foundation') if openal.type_name() != 'pkgconfig' - add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') + add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') endif elif host_system == 'windows' global_dependencies += compilers['cpp'].find_library('wsock32')