Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "ScreenshotCreator.h"

#include "GlesHelper.h"
#include "UnityMetalSupport.h"
#include "DisplayManager.h"

static ScreenshotCreator* _Creator = nil;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Graphics/AsyncScreenshot/Assets/TestScreenshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void OnGUI()
savingScreenshot = true;
CaptureScreenshot(ScreenshotCompleteCallback, "test.png");
#else
Application.CaptureScreenshot("test.png");
ScreenCapture.CaptureScreenshot("test.png");
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion Graphics/AsyncScreenshot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions Graphics/ExternalTexture/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
11 changes: 11 additions & 0 deletions Graphics/ExternalTexture/Assets/Editor/PostprocessBuild.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 3 additions & 39 deletions Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <UIKit/UIKit.h>

#include "UnityMetalSupport.h"

#include <stdlib.h>
Expand Down Expand Up @@ -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 =
Expand All @@ -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<MTLTexture> mtltex = (__bridge_transfer id<MTLTexture>)(void*) tex;
mtltex = nil;
#endif
}

extern "C" intptr_t CreateNativeTexture(const char* filename)
Expand All @@ -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;
Expand All @@ -111,6 +77,4 @@ static void DestroyMetalTexture(uintptr_t tex)
{
if (UnitySelectedRenderingAPI() == apiMetal)
DestroyMetalTexture(tex);
else
DestroyGlesTexture(tex);
}
14 changes: 10 additions & 4 deletions Graphics/ExternalTexture/Assets/TestNativeTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Graphics/ExternalTexture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a sample of usage of **Texture2D.CreateExternalTexture** and **Texture2D

##Prerequisites

Unity: 4.2
Unity: 2020

iOS: any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MTLRenderPipelineState> CreateCommonRenderPipeline(id<MTLFunction> fs, MTLPixelFormat format, int sampleCount) {
static id<MTLRenderPipelineState> CreateCommonRenderPipeline(id<MTLFunction> fs, MTLPixelFormat colorFormat, MTLPixelFormat depthFormat, MTLPixelFormat stencilFormat, int sampleCount) {
id<MTLDevice> 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;
Expand All @@ -115,12 +118,18 @@ static void CreatePluginAssets() {

static void DoExtraDrawCall() {
// get current render pass setup
id<MTLTexture> rt = g_MetalGraphics->CurrentRenderPassDescriptor().colorAttachments[0].texture;
MTLRenderPassDescriptor* curDesc = g_MetalGraphics->CurrentRenderPassDescriptor();

id<MTLTexture> rtColor = curDesc.colorAttachments[0].texture;
id<MTLTexture> rtDepth = curDesc.depthAttachment.texture;
id<MTLTexture> 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
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions NativeIntegration/Misc/UpdateXcodeProject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "ScreenshotCreator.h"

#include "GlesHelper.h"
#include "UnityMetalSupport.h"
#include "DisplayManager.h"

static ScreenshotCreator* _Creator = nil;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion NativeIntegration/UI/ResizedView/Assets/Screenshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void OnGUI()
savingScreenshot = true;
CaptureScreenshot(ScreenshotCompleteCallback, "test.png");
#else
Application.CaptureScreenshot("test.png");
ScreenCapture.CaptureScreenshot("test.png");
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion NativeIntegration/WWW/CustomConnection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down