diff --git a/Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.mm b/Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.mm index da9889b..3eb044e 100644 --- a/Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.mm +++ b/Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.mm @@ -1,6 +1,6 @@ #import "ScreenshotCreator.h" -#include "GlesHelper.h" +#include "UnityMetalSupport.h" #include "DisplayManager.h" static ScreenshotCreator* _Creator = nil; @@ -56,7 +56,8 @@ - (void)onFrameResolved bufferW = CVPixelBufferGetWidth(pixelBuf); bufferH = CVPixelBufferGetHeight(pixelBuf); bufferRowLen = CVPixelBufferGetBytesPerRow(pixelBuf); - bufferFlipped = CVOpenGLESTextureIsFlipped((CVOpenGLESTextureRef)mainDisplaySurface->cvTextureCacheTexture); + // note that for metal rows ordering is opposite to gl + bufferFlipped = !CVMetalTextureIsFlipped((CVMetalTextureRef)mainDisplaySurface->cvTextureCacheTexture); imageW = mainDisplaySurface->targetW; imageH = mainDisplaySurface->targetH; @@ -98,7 +99,7 @@ - (void)saveImage char* srcRow = imageBuffer; char* dstRow = finalImageData; - if (bufferFlipped) srcRow = imageBuffer + (bufferH - 1) * srcRowSize; + if (bufferFlipped) srcRow = imageBuffer + (bufferH - 1) * srcRowSize; else srcRow = imageBuffer; for (int i = 0; i < imageH; ++i, srcRow += srcRowNext, dstRow += dstRowSize) @@ -119,7 +120,7 @@ - (void)saveImage CGImageRef cgImage = CGImageCreate(imageW, imageH, 8, 32, 4 * imageW, cgColorSpace, kCGBitmapByteOrderDefault, cgProvider, 0, NO, kCGRenderingIntentDefault - ); + ); CGDataProviderRelease(cgProvider); CGColorSpaceRelease(cgColorSpace); diff --git a/Graphics/AsyncScreenshot/Assets/TestScreenshot.cs b/Graphics/AsyncScreenshot/Assets/TestScreenshot.cs index c048310..72ebd38 100644 --- a/Graphics/AsyncScreenshot/Assets/TestScreenshot.cs +++ b/Graphics/AsyncScreenshot/Assets/TestScreenshot.cs @@ -29,7 +29,7 @@ void OnGUI() savingScreenshot = true; CaptureScreenshot(ScreenshotCompleteCallback, "test.png"); #else - Application.CaptureScreenshot("test.png"); + ScreenCapture.CaptureScreenshot("test.png"); #endif } } diff --git a/Graphics/AsyncScreenshot/README.md b/Graphics/AsyncScreenshot/README.md index 30133c6..680f90a 100644 --- a/Graphics/AsyncScreenshot/README.md +++ b/Graphics/AsyncScreenshot/README.md @@ -8,7 +8,7 @@ This is a sample of usage of native **RenderPluginDelegate**. It will make scree ##Prerequisites -Unity: 4.3 +Unity: 2020 iOS: any diff --git a/Graphics/ExternalTexture/Assets/Editor.meta b/Graphics/ExternalTexture/Assets/Editor.meta new file mode 100644 index 0000000..ad68059 --- /dev/null +++ b/Graphics/ExternalTexture/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bfa945941802e41b4b167df6c034196d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs b/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs new file mode 100644 index 0000000..5a32501 --- /dev/null +++ b/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs @@ -0,0 +1,29 @@ +using System.IO; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Callbacks; +using UnityEditor.iOS.Xcode; + +public class PostprocessBuild +{ + [PostProcessBuild] + public static void OnPostprocessBuild(BuildTarget buildTarget, string path) + { + if (buildTarget == BuildTarget.iOS) + { + string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; + + PBXProject proj = new PBXProject(); + proj.ReadFromString(File.ReadAllText(projPath)); + + string target = proj.GetUnityMainTargetGuid(); + string resSection = proj.GetResourcesBuildPhaseByTarget(target); + + proj.AddFileToBuildSection(target, resSection, proj.AddFile("Libraries/Soft.png","Libraries/Soft.png", PBXSourceTree.Source)); + proj.AddFileToBuildSection(target, resSection, proj.AddFile("Libraries/Test_Icon.png","Libraries/Test_Icon.png", PBXSourceTree.Source)); + proj.AddFileToBuildSection(target, resSection, proj.AddFile("Libraries/Test_UnityLogoLarge.png","Libraries/Test_UnityLogoLarge.png", PBXSourceTree.Source)); + + File.WriteAllText(projPath, proj.WriteToString()); + } + } +} diff --git a/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs.meta b/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs.meta new file mode 100644 index 0000000..748b7f7 --- /dev/null +++ b/Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d1fe8f1d04a8f4a42a9f52a49ef2383d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm b/Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm index 0530d49..ab61754 100644 --- a/Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm +++ b/Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm @@ -1,7 +1,4 @@ -#import -#import #import - #include "UnityMetalSupport.h" #include @@ -36,40 +33,9 @@ return textureData; } -static uintptr_t CreateGlesTexture(void* data, unsigned w, unsigned h) -{ - GLuint texture = 0; - glGenTextures(1, &texture); - - GLint curGLTex = 0; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &curGLTex); - - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - - glBindTexture(GL_TEXTURE_2D, curGLTex); - - return texture; -} - -static void DestroyGlesTexture(uintptr_t tex) -{ - GLint curGLTex = 0; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &curGLTex); - - GLuint glTex = tex; - glDeleteTextures(1, &glTex); - - glBindTexture(GL_TEXTURE_2D, curGLTex); -} - static uintptr_t CreateMetalTexture(void* data, unsigned w, unsigned h) { -#if defined(__IPHONE_8_0) && !TARGET_IPHONE_SIMULATOR +#if UNITY_CAN_USE_METAL Class MTLTextureDescriptorClass = [UnityGetMetalBundle() classNamed: @"MTLTextureDescriptor"]; MTLTextureDescriptor* texDesc = @@ -88,8 +54,10 @@ static uintptr_t CreateMetalTexture(void* data, unsigned w, unsigned h) static void DestroyMetalTexture(uintptr_t tex) { +#if UNITY_CAN_USE_METAL id mtltex = (__bridge_transfer id)(void*) tex; mtltex = nil; +#endif } extern "C" intptr_t CreateNativeTexture(const char* filename) @@ -100,8 +68,6 @@ static void DestroyMetalTexture(uintptr_t tex) uintptr_t ret = 0; if (UnitySelectedRenderingAPI() == apiMetal) ret = CreateMetalTexture(textureData, image.size.width, image.size.height); - else - ret = CreateGlesTexture(textureData, image.size.width, image.size.height); ::free(textureData); return ret; @@ -111,6 +77,4 @@ static void DestroyMetalTexture(uintptr_t tex) { if (UnitySelectedRenderingAPI() == apiMetal) DestroyMetalTexture(tex); - else - DestroyGlesTexture(tex); } diff --git a/Graphics/ExternalTexture/Assets/TestNativeTexture.cs b/Graphics/ExternalTexture/Assets/TestNativeTexture.cs index 12e2777..6674e47 100644 --- a/Graphics/ExternalTexture/Assets/TestNativeTexture.cs +++ b/Graphics/ExternalTexture/Assets/TestNativeTexture.cs @@ -38,16 +38,22 @@ void LoadTexture() curTexIndex = (curTexIndex + 1) % externalTexture.Length; curTex = CreateNativeTexture(externalTexture[curTexIndex]); - testTex.UpdateExternalTexture(curTex); + if(testTex == null) + { + testTex = Texture2D.CreateExternalTexture(128, 128, TextureFormat.ARGB32, false, false, curTex); + target.material.mainTexture = testTex; + } + else + { + testTex.UpdateExternalTexture(curTex); + } + if (texToDestroy != System.IntPtr.Zero) DestroyNativeTexture(texToDestroy); } void Start() { - testTex = Texture2D.CreateExternalTexture(128, 128, TextureFormat.ARGB32, false, false, System.IntPtr.Zero); - target.material.mainTexture = testTex; - curTexIndex = -1; curTex = System.IntPtr.Zero; LoadTexture(); diff --git a/Graphics/ExternalTexture/README.md b/Graphics/ExternalTexture/README.md index 1e122f0..9816188 100644 --- a/Graphics/ExternalTexture/README.md +++ b/Graphics/ExternalTexture/README.md @@ -8,7 +8,7 @@ This is a sample of usage of **Texture2D.CreateExternalTexture** and **Texture2D ##Prerequisites -Unity: 4.2 +Unity: 2020 iOS: any diff --git a/Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS/MetalPlugin.m b/Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS/MetalPlugin.m index c287701..39e2483 100644 --- a/Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS/MetalPlugin.m +++ b/Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS/MetalPlugin.m @@ -90,15 +90,18 @@ static void CreatePluginAssets() { // to simplify our lives: we will use similar setup for both "color rect" and "texture" draw calls // the only reason we cannot pre-alloc them is that we want to handle changing RT transparently -static id CreateCommonRenderPipeline(id fs, MTLPixelFormat format, int sampleCount) { +static id CreateCommonRenderPipeline(id fs, MTLPixelFormat colorFormat, MTLPixelFormat depthFormat, MTLPixelFormat stencilFormat, int sampleCount) { id device = g_MetalGraphics->MetalDevice(); NSBundle* mtlBundle = g_MetalGraphics->MetalBundle(); MTLRenderPipelineDescriptor* pipeDesc = [[mtlBundle classNamed:@"MTLRenderPipelineDescriptor"] new]; MTLRenderPipelineColorAttachmentDescriptor* colorDesc = [[mtlBundle classNamed:@"MTLRenderPipelineColorAttachmentDescriptor"] new]; - colorDesc.pixelFormat = format; + colorDesc.pixelFormat = colorFormat; pipeDesc.colorAttachments[0] = colorDesc; + pipeDesc.depthAttachmentPixelFormat = depthFormat; + pipeDesc.stencilAttachmentPixelFormat = stencilFormat; + pipeDesc.fragmentFunction = fs; pipeDesc.vertexFunction = g_VProg; pipeDesc.vertexDescriptor = g_VertexDesc; @@ -115,12 +118,18 @@ static void CreatePluginAssets() { static void DoExtraDrawCall() { // get current render pass setup - id rt = g_MetalGraphics->CurrentRenderPassDescriptor().colorAttachments[0].texture; + MTLRenderPassDescriptor* curDesc = g_MetalGraphics->CurrentRenderPassDescriptor(); + + id rtColor = curDesc.colorAttachments[0].texture; + id rtDepth = curDesc.depthAttachment.texture; + id rtStencil = curDesc.stencilAttachment.texture; - if(rt.pixelFormat != g_ExtraDrawCallPixelFormat || rt.sampleCount != g_ExtraDrawCallSampleCount) { + if(rtColor.pixelFormat != g_ExtraDrawCallPixelFormat || rtColor.sampleCount != g_ExtraDrawCallSampleCount) { // RT format changed - recreate render pipeline - g_ExtraDrawCallPixelFormat = rt.pixelFormat, g_ExtraDrawCallSampleCount = (int)rt.sampleCount; - g_ExtraDrawCallPipe = CreateCommonRenderPipeline(g_FShaderColor, g_ExtraDrawCallPixelFormat, g_ExtraDrawCallSampleCount); + // we silently assume that depth/stencil format does not change + // even though we dont need it we need to set it up as otherwise validation will whine + g_ExtraDrawCallPixelFormat = rtColor.pixelFormat, g_ExtraDrawCallSampleCount = (int)rtColor.sampleCount; + g_ExtraDrawCallPipe = CreateCommonRenderPipeline(g_FShaderColor, g_ExtraDrawCallPixelFormat, rtDepth.pixelFormat, rtStencil.pixelFormat, g_ExtraDrawCallSampleCount); } // get current command encoder, update render setup and do extra draw call @@ -193,7 +202,7 @@ static void DoCaptureRT() { if(dst.pixelFormat != g_RTCopyPixelFormat || dst.sampleCount != g_RTCopySampleCount) { // RT format changed - recreate render pipeline g_RTCopyPixelFormat = dst.pixelFormat, g_RTCopySampleCount = (int)dst.sampleCount; - g_RTCopyPipe = CreateCommonRenderPipeline(g_FShaderTexture, g_RTCopyPixelFormat, g_RTCopySampleCount); + g_RTCopyPipe = CreateCommonRenderPipeline(g_FShaderTexture, g_RTCopyPixelFormat, MTLPixelFormatInvalid, MTLPixelFormatInvalid, g_RTCopySampleCount); } // render diff --git a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll b/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll deleted file mode 100755 index 3e2c169..0000000 Binary files a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll and /dev/null differ diff --git a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll.meta b/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll.meta deleted file mode 100644 index d19f66f..0000000 --- a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 4b9607f4d1ede4513baef82b894f6ab0 -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs b/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs index ce58c2b..0f398a5 100644 --- a/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs +++ b/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs @@ -26,14 +26,14 @@ internal static void CopyAndReplaceDirectory(string srcPath, string dstPath) [PostProcessBuild] public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { - if (buildTarget == BuildTarget.iPhone) + if (buildTarget == BuildTarget.iOS) { string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); - string target = proj.TargetGuidByName("Unity-iPhone"); + string target = proj.GetUnityFrameworkTargetGuid(); // Add user packages to project. Most other source or resource files and packages // can be added the same way. diff --git a/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib b/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib index 4ec7dc6..b82b680 100644 Binary files a/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib and b/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib differ diff --git a/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.pbxproj b/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.pbxproj index f980bfe..254f1e2 100644 --- a/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.pbxproj +++ b/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.pbxproj @@ -360,6 +360,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = arm64; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -387,7 +388,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -397,6 +398,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = arm64; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -418,7 +420,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -503,7 +505,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_NAME = TestLib; - SDKROOT = iphoneos7.1; + SDKROOT = iphoneos; WRAPPER_EXTENSION = bundle; }; name = Debug; @@ -520,7 +522,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_NAME = TestLib; - SDKROOT = iphoneos7.1; + SDKROOT = iphoneos; WRAPPER_EXTENSION = bundle; }; name = Release; diff --git a/NativeIntegration/Misc/UpdateXcodeProject/README.md b/NativeIntegration/Misc/UpdateXcodeProject/README.md index 0acbac3..677b2eb 100644 --- a/NativeIntegration/Misc/UpdateXcodeProject/README.md +++ b/NativeIntegration/Misc/UpdateXcodeProject/README.md @@ -3,12 +3,12 @@ ## Description -This sample shows how to modify generated Xcode projects in order to support +This sample shows how to modify generated Xcode projects in order to support various types of native plugins. ##Prerequisites -Unity: 4.5 +Unity: 2020 iOS: any diff --git a/NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.mm b/NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.mm index d405b8a..c93ad1b 100644 --- a/NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.mm +++ b/NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.mm @@ -1,6 +1,6 @@ #import "ScreenshotCreator.h" -#include "GlesHelper.h" +#include "UnityMetalSupport.h" #include "DisplayManager.h" static ScreenshotCreator* _Creator = nil; @@ -56,7 +56,8 @@ - (void)onFrameResolved bufferW = CVPixelBufferGetWidth(pixelBuf); bufferH = CVPixelBufferGetHeight(pixelBuf); bufferRowLen = CVPixelBufferGetBytesPerRow(pixelBuf); - bufferFlipped = CVOpenGLESTextureIsFlipped((CVOpenGLESTextureRef)mainDisplaySurface->cvTextureCacheTexture); + // note that for metal rows ordering is opposite to gl + bufferFlipped = !CVMetalTextureIsFlipped((CVMetalTextureRef)mainDisplaySurface->cvTextureCacheTexture); imageW = mainDisplaySurface->targetW; imageH = mainDisplaySurface->targetH; diff --git a/NativeIntegration/UI/ResizedView/Assets/Screenshot.cs b/NativeIntegration/UI/ResizedView/Assets/Screenshot.cs index b20e21d..eba46ea 100644 --- a/NativeIntegration/UI/ResizedView/Assets/Screenshot.cs +++ b/NativeIntegration/UI/ResizedView/Assets/Screenshot.cs @@ -45,7 +45,7 @@ void OnGUI() savingScreenshot = true; CaptureScreenshot(ScreenshotCompleteCallback, "test.png"); #else - Application.CaptureScreenshot("test.png"); + ScreenCapture.CaptureScreenshot("test.png"); #endif } } diff --git a/NativeIntegration/WWW/CustomConnection/README.md b/NativeIntegration/WWW/CustomConnection/README.md index 7b9e96a..1fa094e 100644 --- a/NativeIntegration/WWW/CustomConnection/README.md +++ b/NativeIntegration/WWW/CustomConnection/README.md @@ -8,7 +8,7 @@ This sample shows how to tweak WWW connection to better suit your needs. ##Prerequisites -Unity: 4.3.1 +Unity: 4.3.1 - 2019.1 iOS: any