summaryrefslogtreecommitdiffstats
path: root/unityplugin/UnityEmulator
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-01-27 05:19:49 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-01-27 05:19:49 +0000
commit1a528cdfc47aa142295876a780696cdf24bd09eb (patch)
treed8d645101a530792faf9e338ac3ec8c04a4d07d7 /unityplugin/UnityEmulator
parentUpdate README.md (diff)
downloadDiligentEngine-1a528cdfc47aa142295876a780696cdf24bd09eb.tar.gz
DiligentEngine-1a528cdfc47aa142295876a780696cdf24bd09eb.zip
Enabled MacOS support
Diffstat (limited to 'unityplugin/UnityEmulator')
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/OSX/Base.lproj/Main.storyboard161
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/Contents.json58
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/OSX/Info.plist32
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/LaunchScreen.xib42
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/Main.storyboard26
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/iOS/Images.xcassets/AppIcon.appiconset/Contents.json68
-rw-r--r--unityplugin/UnityEmulator/Apple/Data/iOS/info.plist47
-rw-r--r--unityplugin/UnityEmulator/Apple/LICENSE.txt42
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.h15
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.m29
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.h15
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.m52
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.h20
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.m262
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.h15
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.m154
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.h21
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.m88
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.h25
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.m135
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.h25
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.m134
-rw-r--r--unityplugin/UnityEmulator/Apple/Source/main.m25
-rw-r--r--unityplugin/UnityEmulator/CMakeLists.txt53
-rw-r--r--unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h4
-rw-r--r--unityplugin/UnityEmulator/src/MacOS/Renderer.cpp126
-rw-r--r--unityplugin/UnityEmulator/src/MacOS/Renderer.h49
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp27
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h17
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h2
30 files changed, 1762 insertions, 7 deletions
diff --git a/unityplugin/UnityEmulator/Apple/Data/OSX/Base.lproj/Main.storyboard b/unityplugin/UnityEmulator/Apple/Data/OSX/Base.lproj/Main.storyboard
new file mode 100644
index 0000000..5890ca3
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/OSX/Base.lproj/Main.storyboard
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+ </dependencies>
+ <scenes>
+ <!--Application-->
+ <scene sceneID="JPo-4y-FX3">
+ <objects>
+ <application id="hnw-xV-0zn" sceneMemberID="viewController">
+ <menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
+ <items>
+ <menuItem title="Application" id="1Xt-HY-uBw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Application" systemMenu="apple" id="uQy-DD-JDr">
+ <items>
+ <menuItem title="About" id="5kV-Vb-QxS" userLabel="About">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
+ <menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
+ <menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
+ <menuItem title="Services" id="NMo-om-nkz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
+ <menuItem title="Hide" keyEquivalent="h" id="Olw-nP-bQN" userLabel="Hide">
+ <connections>
+ <action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Show All" id="Kd2-mp-pUS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
+ <menuItem title="Quit" keyEquivalent="q" id="4sb-4s-VLi" userLabel="Quit">
+ <connections>
+ <action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="View" id="H8h-7b-M4v">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="View" id="HyV-fh-RgO">
+ <items>
+ <menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="toggleToolbarShown:" target="Ady-hI-5gd" id="BXY-wc-z0C"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="runToolbarCustomizationPalette:" target="Ady-hI-5gd" id="pQI-g3-MTW"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Window" id="aUF-d1-5bR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
+ <items>
+ <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
+ <connections>
+ <action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Zoom" id="R4o-n2-Eq4">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
+ <menuItem title="Bring All to Front" id="LE2-aR-0XJ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Help" id="wpr-3q-Mcd">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
+ <items>
+ <menuItem title="Help" keyEquivalent="?" id="FKE-Sm-Kum" userLabel="Sample Help">
+ <connections>
+ <action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ <connections>
+ <outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
+ </connections>
+ </application>
+ <customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
+ <customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="75" y="0.0"/>
+ </scene>
+ <!--Window Controller-->
+ <scene sceneID="R2V-B0-nI4">
+ <objects>
+ <windowController id="B8D-0N-5wS" customClass="WindowController" sceneMemberID="viewController">
+ <window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
+ <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
+ <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
+ <rect key="contentRect" x="196" y="240" width="480" height="270"/>
+ <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
+ <value key="minSize" type="size" width="10" height="20"/>
+ <connections>
+ <outlet property="delegate" destination="B8D-0N-5wS" id="owC-aB-m7U"/>
+ </connections>
+ </window>
+ <connections>
+ <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
+ </connections>
+ </windowController>
+ <customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="75" y="250"/>
+ </scene>
+ <!--View Controller-->
+ <scene sceneID="hIz-AP-VOD">
+ <objects>
+ <viewController id="XfG-lQ-9wD" sceneMemberID="viewController">
+ <view key="view" id="m2S-Jp-Qdl" userLabel="GL View" customClass="GLView">
+ <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </view>
+ </viewController>
+ <customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="75" y="655"/>
+ </scene>
+ </scenes>
+</document>
diff --git a/unityplugin/UnityEmulator/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/Contents.json b/unityplugin/UnityEmulator/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..2db2b1c
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/unityplugin/UnityEmulator/Apple/Data/OSX/Info.plist b/unityplugin/UnityEmulator/Apple/Data/OSX/Info.plist
new file mode 100644
index 0000000..53b1391
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/OSX/Info.plist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string></string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>2.3</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
+ <key>NSMainStoryboardFile</key>
+ <string>Main</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
diff --git a/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/LaunchScreen.xib b/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/LaunchScreen.xib
new file mode 100644
index 0000000..0d1a62b
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/LaunchScreen.xib
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
+ <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
+ </dependencies>
+ <objects>
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+ <view contentMode="scaleToFill" id="iN0-l3-epB">
+ <rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2015 Apple, Inc. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
+ <rect key="frame" x="20" y="439" width="441" height="21"/>
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
+ <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
+ <nil key="highlightedColor"/>
+ </label>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="GLEssentials" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
+ <rect key="frame" x="20" y="140" width="441" height="43"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
+ <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
+ <nil key="highlightedColor"/>
+ </label>
+ </subviews>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ <constraints>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
+ <constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
+ <constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
+ <constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
+ <constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
+ </constraints>
+ <nil key="simulatedStatusBarMetrics"/>
+ <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
+ <point key="canvasLocation" x="548" y="455"/>
+ </view>
+ </objects>
+</document>
diff --git a/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/Main.storyboard b/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/Main.storyboard
new file mode 100644
index 0000000..0dc87c1
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/iOS/Base.lproj/Main.storyboard
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
+ </dependencies>
+ <scenes>
+ <!--View Controller-->
+ <scene sceneID="tne-QT-ifu">
+ <objects>
+ <viewController id="BYZ-38-t0r" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
+ <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC" customClass="EAGLView">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
+ </objects>
+ </scene>
+ </scenes>
+</document>
diff --git a/unityplugin/UnityEmulator/Apple/Data/iOS/Images.xcassets/AppIcon.appiconset/Contents.json b/unityplugin/UnityEmulator/Apple/Data/iOS/Images.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..36d2c80
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/iOS/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,68 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/unityplugin/UnityEmulator/Apple/Data/iOS/info.plist b/unityplugin/UnityEmulator/Apple/Data/iOS/info.plist
new file mode 100644
index 0000000..d54bdf3
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Data/iOS/info.plist
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.example.apple-samplecode.GLEssentials</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.8</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UIMainStoryboardFile</key>
+ <string>Main</string>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
diff --git a/unityplugin/UnityEmulator/Apple/LICENSE.txt b/unityplugin/UnityEmulator/Apple/LICENSE.txt
new file mode 100644
index 0000000..73f0303
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/LICENSE.txt
@@ -0,0 +1,42 @@
+Sample code project: GLEssentials
+Version: 3.0
+
+IMPORTANT: This Apple software is supplied to you by Apple
+Inc. ("Apple") in consideration of your agreement to the following
+terms, and your use, installation, modification or redistribution of
+this Apple software constitutes acceptance of these terms. If you do
+not agree with these terms, please do not use, install, modify or
+redistribute this Apple software.
+
+In consideration of your agreement to abide by the following terms, and
+subject to these terms, Apple grants you a personal, non-exclusive
+license, under Apple's copyrights in this original Apple software (the
+"Apple Software"), to use, reproduce, modify and redistribute the Apple
+Software, with or without modifications, in source and/or binary forms;
+provided that if you redistribute the Apple Software in its entirety and
+without modifications, you must retain this notice and the following
+text and disclaimers in all such redistributions of the Apple Software.
+Neither the name, trademarks, service marks or logos of Apple Inc. may
+be used to endorse or promote products derived from the Apple Software
+without specific prior written permission from Apple. Except as
+expressly stated in this notice, no other rights or licenses, express or
+implied, are granted by Apple herein, including but not limited to any
+patent rights that may be infringed by your derivative works or by other
+works in which the Apple Software may be incorporated.
+
+The Apple Software is provided by Apple on an "AS IS" basis. APPLE
+MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+Copyright (C) 2015 Apple Inc. All Rights Reserved.
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.h b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.h
new file mode 100644
index 0000000..d38403c
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.h
@@ -0,0 +1,15 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The Application Delegate.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+
+@end
+
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.m b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.m
new file mode 100644
index 0000000..427caac
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/AppDelegate.m
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The Application Delegate.
+ */
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@end
+
+@implementation AppDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ // Insert code here to initialize your application
+}
+
+- (void)applicationWillTerminate:(NSNotification *)aNotification {
+ // Insert code here to tear down your application
+}
+
+- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
+ return YES;
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.h b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.h
new file mode 100644
index 0000000..2a61a51
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.h
@@ -0,0 +1,15 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Fullscreen window class.
+ All logic here could have been done in the window controller except that, by default, borderless windows cannot be made key and input cannot go to them.
+ Therefore, this class exists to override canBecomeKeyWindow allowing this borderless window to accept inputs.
+ This class is not part of the NIB and entirely managed in code by the window controller.
+ */
+#import <Cocoa/Cocoa.h>
+
+@interface FullscreenWindow : NSWindow
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.m b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.m
new file mode 100644
index 0000000..69c9063
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/FullscreenWindow.m
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Fullscreen window class.
+ All logic here could have been done in the window controller except that, by default, borderless windows cannot be made key and input cannot go to them.
+ Therefore, this class exists to override canBecomeKeyWindow allowing this borderless window to accept inputs.
+ This class is not part of the NIB and entirely managed in code by the window controller.
+ */
+
+#import "FullscreenWindow.h"
+
+@implementation FullscreenWindow
+
+-(instancetype)init
+{
+ // Create a screen-sized window on the display you want to take over
+ NSRect screenRect = [[NSScreen mainScreen] frame];
+
+ // Initialize the window making it size of the screen and borderless
+ self = [super initWithContentRect:screenRect
+ styleMask:NSWindowStyleMaskBorderless
+ backing:NSBackingStoreBuffered
+ defer:YES];
+
+ // Set the window level to be above the menu bar to cover everything else
+ [self setLevel:NSMainMenuWindowLevel+1];
+
+ // Set opaque
+ [self setOpaque:YES];
+
+ // Hide this when user switches to another window (or app)
+ [self setHidesOnDeactivate:YES];
+
+ return self;
+}
+
+-(BOOL)canBecomeKeyWindow
+{
+ // Return yes so that this borderless window can receive input
+ return YES;
+}
+
+- (void)keyDown:(NSEvent *)event
+{
+ // Implement keyDown since controller will not get [ESC] key event which
+ // the controller uses to kill fullscreen
+ [[self windowController] keyDown:event];
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.h b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.h
new file mode 100644
index 0000000..d07b0dd
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.h
@@ -0,0 +1,20 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ OpenGL view subclass.
+ */
+
+
+#import <Cocoa/Cocoa.h>
+#import <QuartzCore/CVDisplayLink.h>
+
+@interface GLView : NSOpenGLView {
+ CVDisplayLinkRef displayLink;
+}
+
+-(void)stopDisplayLink;
+-(void)startDisplayLink;
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.m b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.m
new file mode 100644
index 0000000..570952f
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/GLView.m
@@ -0,0 +1,262 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ OpenGL view subclass.
+ */
+
+#import "GLView.h"
+#include "Renderer.h"
+#include <memory>
+
+#define SUPPORT_RETINA_RESOLUTION 1
+
+@interface GLView ()
+{
+ std::unique_ptr<Renderer> _renderer;
+ NSRect _viewRectPixels;
+}
+@end
+
+@implementation GLView
+
+
+- (CVReturn) getFrameForTime:(const CVTimeStamp*)outputTime
+{
+ // There is no autorelease pool when this method is called
+ // because it will be called from a background thread.
+ // It's important to create one or app can leak objects.
+ @autoreleasepool {
+ [self drawView];
+ }
+ return kCVReturnSuccess;
+}
+
+// This is the renderer output callback function
+static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink,
+ const CVTimeStamp* now,
+ const CVTimeStamp* outputTime,
+ CVOptionFlags flagsIn,
+ CVOptionFlags* flagsOut,
+ void* displayLinkContext)
+{
+ CVReturn result = [(__bridge GLView*)displayLinkContext getFrameForTime:outputTime];
+ return result;
+}
+
+// Prepares the receiver for service after it has been loaded
+// from an Interface Builder archive, or nib file.
+- (void) awakeFromNib
+{
+ [super awakeFromNib];
+
+ NSOpenGLPixelFormatAttribute attrs[] =
+ {
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFADepthSize, 24,
+ NSOpenGLPFAOpenGLProfile,
+ NSOpenGLProfileVersion4_1Core,
+ 0
+ };
+
+ NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+
+ if (!pf)
+ {
+ NSLog(@"No OpenGL pixel format");
+ }
+
+ NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil];
+
+#if defined(DEBUG)
+ // When we're using a CoreProfile context, crash if we call a legacy OpenGL function
+ // This will make it much more obvious where and when such a function call is made so
+ // that we can remove such calls.
+ // Without this we'd simply get GL_INVALID_OPERATION error for calling legacy functions
+ // but it would be more difficult to see where that function was called.
+ CGLEnable([context CGLContextObj], kCGLCECrashOnRemovedFunctions);
+#endif
+
+ [self setPixelFormat:pf];
+
+ [self setOpenGLContext:context];
+
+#if SUPPORT_RETINA_RESOLUTION
+ // Opt-In to Retina resolution
+ [self setWantsBestResolutionOpenGLSurface:YES];
+#endif // SUPPORT_RETINA_RESOLUTION
+
+ _renderer.reset(new Renderer());
+}
+
+- (void) prepareOpenGL
+{
+ [super prepareOpenGL];
+
+ // Make all the OpenGL calls to setup rendering
+ // and build the necessary rendering objects
+ [self initGL];
+
+ // Create a display link capable of being used with all active displays
+ CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
+
+ // Set the renderer output callback function
+ CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, (__bridge void*)self);
+
+ // Set the display link for the current renderer
+ CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
+ CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
+ CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
+
+ // Activate the display link
+ CVDisplayLinkStart(displayLink);
+
+ // Register to be notified when the window closes so we can stop the displaylink
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(windowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:[self window]];
+}
+
+- (void) windowWillClose:(NSNotification*)notification
+{
+ // Stop the display link when the window is closing because default
+ // OpenGL render buffers will be destroyed. If display link continues to
+ // fire without renderbuffers, OpenGL draw calls will set errors.
+
+ CVDisplayLinkStop(displayLink);
+ // Stop the display link BEFORE releasing anything in the view
+ // otherwise the display link thread may call into the view and crash
+ // when it encounters something that has been released
+
+ _renderer.reset();
+}
+
+- (void) initGL
+{
+ // The reshape function may have changed the thread to which our OpenGL
+ // context is attached before prepareOpenGL and initGL are called. So call
+ // makeCurrentContext to ensure that our OpenGL context current to this
+ // thread (i.e. makeCurrentContext directs all OpenGL calls on this thread
+ // to [self openGLContext])
+ [[self openGLContext] makeCurrentContext];
+
+ // Synchronize buffer swaps with vertical refresh rate
+ GLint swapInt = 1;
+ [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
+
+ // Init our renderer.
+ _renderer->Init();
+}
+
+- (void)reshape
+{
+ [super reshape];
+
+ // We draw on a secondary thread through the display link. However, when
+ // resizing the view, -drawRect is called on the main thread.
+ // Add a mutex around to avoid the threads accessing the context
+ // simultaneously when resizing.
+ CGLLockContext([[self openGLContext] CGLContextObj]);
+
+ // Get the view size in Points
+ NSRect viewRectPoints = [self bounds];
+
+#if SUPPORT_RETINA_RESOLUTION
+
+ // Rendering at retina resolutions will reduce aliasing, but at the potential
+ // cost of framerate and battery life due to the GPU needing to render more
+ // pixels.
+
+ // Any calculations the renderer does which use pixel dimentions, must be
+ // in "retina" space. [NSView convertRectToBacking] converts point sizes
+ // to pixel sizes. Thus the renderer gets the size in pixels, not points,
+ // so that it can set it's viewport and perform and other pixel based
+ // calculations appropriately.
+ // viewRectPixels will be larger than viewRectPoints for retina displays.
+ // viewRectPixels will be the same as viewRectPoints for non-retina displays
+ _viewRectPixels = [self convertRectToBacking:viewRectPoints];
+
+#else //if !SUPPORT_RETINA_RESOLUTION
+
+ // App will typically render faster and use less power rendering at
+ // non-retina resolutions since the GPU needs to render less pixels.
+ // There is the cost of more aliasing, but it will be no-worse than
+ // on a Mac without a retina display.
+
+ // Points:Pixels is always 1:1 when not supporting retina resolutions
+ _viewRectPixels = viewRectPoints;
+
+#endif // !SUPPORT_RETINA_RESOLUTION
+
+ // Set the new dimensions in our renderer
+ _renderer->WindowResize(_viewRectPixels.size.width, _viewRectPixels.size.height);
+
+ CGLUnlockContext([[self openGLContext] CGLContextObj]);
+}
+
+
+- (void)renewGState
+{
+ // Called whenever graphics state updated (such as window resize)
+
+ // OpenGL rendering is not synchronous with other rendering on the OSX.
+ // Therefore, call disableScreenUpdatesUntilFlush so the window server
+ // doesn't render non-OpenGL content in the window asynchronously from
+ // OpenGL content, which could cause flickering. (non-OpenGL content
+ // includes the title bar and drawing done by the app with other APIs)
+ [[self window] disableScreenUpdatesUntilFlush];
+
+ [super renewGState];
+}
+
+- (void) drawRect: (NSRect) theRect
+{
+ // Called during resize operations
+
+ // Avoid flickering during resize by drawiing
+ [self drawView];
+}
+
+- (void) drawView
+{
+ [[self openGLContext] makeCurrentContext];
+
+ // We draw on a secondary thread through the display link
+ // When resizing the view, -reshape is called automatically on the main
+ // thread. Add a mutex around to avoid the threads accessing the context
+ // simultaneously when resizing
+ CGLLockContext([[self openGLContext] CGLContextObj]);
+
+ _renderer->Render();
+
+ CGLFlushDrawable([[self openGLContext] CGLContextObj]);
+ CGLUnlockContext([[self openGLContext] CGLContextObj]);
+}
+
+- (void) dealloc
+{
+ // Stop the display link BEFORE releasing anything in the view
+ // otherwise the display link thread may call into the view and crash
+ // when it encounters something that has been released
+ CVDisplayLinkStop(displayLink);
+
+ CVDisplayLinkRelease(displayLink);
+
+ _renderer.reset();
+
+ [super dealloc];
+}
+
+- (void)stopDisplayLink
+{
+ CVDisplayLinkStop(displayLink);
+}
+
+- (void)startDisplayLink
+{
+ CVDisplayLinkStart(displayLink);
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.h b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.h
new file mode 100644
index 0000000..bfa3e5a
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.h
@@ -0,0 +1,15 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Window controller subclass.
+ */
+
+
+#import <Cocoa/Cocoa.h>
+#import "GLView.h"
+
+@interface WindowController : NSWindowController
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.m b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.m
new file mode 100644
index 0000000..e85684b
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/OSX/WindowController.m
@@ -0,0 +1,154 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Window controller subclass.
+ */
+
+#import "WindowController.h"
+#import "FullscreenWindow.h"
+
+@interface WindowController ()
+
+// Fullscreen window
+@property(strong) FullscreenWindow *fullscreenWindow;
+
+// Non-Fullscreen window (also the initial window)
+@property(strong) NSWindow* standardWindow;
+
+@end
+
+@implementation WindowController
+
+- (instancetype)initWithWindow:(NSWindow *)window
+{
+ self = [super initWithWindow:window];
+
+ if (self)
+ {
+ // Initialize to nil since it indicates app is not fullscreen
+ _fullscreenWindow = nil;
+ }
+
+ return self;
+}
+
+- (void) goFullscreen
+{
+ // If app is already fullscreen...
+ if([self fullscreenWindow])
+ {
+ //...don't do anything
+ return;
+ }
+ // We must stop the display link while
+ // switching the windows to make sure
+ // that render commands are not issued
+ // from another thread
+ [self.window.contentView stopDisplayLink];
+
+ // Allocate a new fullscreen window
+ [self setFullscreenWindow: [[FullscreenWindow alloc] init]];
+
+ [[self fullscreenWindow] setAcceptsMouseMovedEvents:YES];
+
+ // Resize the view to screensize
+ NSRect viewRect = [[self fullscreenWindow] frame];
+
+ // Set the view to the size of the fullscreen window
+ [self.window.contentView setFrameSize: viewRect.size];
+
+ // Set the view in the fullscreen window
+ [[self fullscreenWindow] setContentView:self.window.contentView];
+
+ [self setStandardWindow:[self window]];
+
+ // Hide non-fullscreen window so it doesn't show up when switching out
+ // of this app (i.e. with CMD-TAB)
+ [[self standardWindow] orderOut:self];
+
+ // Set controller to the fullscreen window so that all input will go to
+ // this controller (self)
+ [self setWindow:[self fullscreenWindow]];
+
+ // Show the window and make it the key window for input
+ [[self fullscreenWindow] makeKeyAndOrderFront:self];
+
+ // Restore display link
+ [self.window.contentView startDisplayLink];
+}
+
+- (void) goWindow
+{
+ // If controller doesn't have a full screen window...
+ if([self fullscreenWindow] == nil)
+ {
+ //...app is already windowed so don't do anything
+ return;
+ }
+ // We must stop the display link while
+ // switching the windows to make sure
+ // that render commands are not issued
+ // from another thread
+ [self.window.contentView stopDisplayLink];
+
+ // Get the rectangle of the original window
+ NSRect viewRect = [[self standardWindow] frame];
+
+ // Set the view rect to the new size
+ [self.window.contentView setFrame:viewRect];
+
+ // Hide fullscreen window
+ [[self fullscreenWindow] orderOut:self];
+
+ // Set controller to the standard window so that all input will go to
+ // this controller (self)
+ [self setWindow:[self standardWindow]];
+
+ // Set the content of the orginal window to the view
+ [[self window] setContentView: [self fullscreenWindow].contentView];
+
+ // Show the window and make it the key window for input
+ [[self window] makeKeyAndOrderFront:self];
+
+ // Ensure we set fullscreen Window to nil so our checks for
+ // windowed vs. fullscreen mode elsewhere are correct
+ [self setFullscreenWindow: nil];
+
+ // Restore display link
+ [self.window.contentView startDisplayLink];
+}
+
+
+- (void) keyDown:(NSEvent *)event
+{
+ unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0];
+
+ switch (c)
+ {
+ // Handle [ESC] key
+ case 27:
+ if([self fullscreenWindow] != nil)
+ {
+ [self goWindow];
+ }
+ return;
+ // Have f key toggle fullscreen
+ case 'f':
+ if([self fullscreenWindow] == nil)
+ {
+ [self goFullscreen];
+ }
+ else
+ {
+ [self goWindow];
+ }
+ return;
+ }
+
+ // Allow other character to be handled (or not and beep)
+ [super keyDown:event];
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.h b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.h
new file mode 100644
index 0000000..bbb1f04
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.h
@@ -0,0 +1,21 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The application delegate
+ */
+
+
+#import <UIKit/UIKit.h>
+
+@class EAGLView;
+@class MainViewController;
+
+@interface AppDelegate : NSObject <UIApplicationDelegate> {
+}
+
+@property (nonatomic, retain) UIWindow *window;
+
+@end
+
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.m b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.m
new file mode 100644
index 0000000..a8a379f
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/AppDelegate.m
@@ -0,0 +1,88 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The application delegate
+*/
+
+#import "AppDelegate.h"
+#import "EAGLView.h"
+
+@implementation AppDelegate
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ // Override point for customization after application launch.
+
+ [self.window makeKeyAndVisible];
+
+ [(EAGLView*)self.window.rootViewController.view startAnimation];
+
+ return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ /*
+ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ */
+
+ [(EAGLView*)self.window.rootViewController.view stopAnimation];
+}
+
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ /*
+ Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
+ */
+
+ [(EAGLView*)self.window.rootViewController.view stopAnimation];
+}
+
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ /*
+ Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
+ */
+
+ [(EAGLView*)self.window.rootViewController.view startAnimation];
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ /*
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ */
+
+ [(EAGLView*)self.window.rootViewController.view startAnimation];
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ /*
+ Called when the application is about to terminate.
+ See also applicationDidEnterBackground:.
+ */
+
+ [(EAGLView*)self.window.rootViewController.view stopAnimation];
+}
+
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ /*
+ Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
+ */
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.h b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.h
new file mode 100644
index 0000000..73d18c8
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.h
@@ -0,0 +1,25 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The EAGLView class is a UIView subclass that renders OpenGL scene.
+*/
+
+#import <UIKit/UIKit.h>
+
+#import "ES2Renderer.h"
+
+// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
+// The view content is basically an EAGL surface you render your OpenGL scene into.
+// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
+@interface EAGLView : UIView
+
+@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
+@property (nonatomic) NSInteger animationFrameInterval;
+
+- (void) startAnimation;
+- (void) stopAnimation;
+- (void) drawView:(id)sender;
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.m b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.m
new file mode 100644
index 0000000..07a7787
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/EAGLView.m
@@ -0,0 +1,135 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The EAGLView class is a UIView subclass that renders OpenGL scene.
+*/
+
+#import "EAGLView.h"
+
+#import "ES2Renderer.h"
+@interface EAGLView ()
+{
+ ES2Renderer* _renderer;
+ EAGLContext* _context;
+ NSInteger _animationFrameInterval;
+ CADisplayLink* _displayLink;
+}
+@end
+
+@implementation EAGLView
+
+// Must return the CAEAGLLayer class so that CA allocates an EAGLLayer backing for this view
++ (Class) layerClass
+{
+ return [CAEAGLLayer class];
+}
+
+// The GL view is stored in the storyboard file. When it's unarchived it's sent -initWithCoder:
+- (instancetype) initWithCoder:(NSCoder*)coder
+{
+ if ((self = [super initWithCoder:coder]))
+ {
+ // Get the layer
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+
+ eaglLayer.opaque = TRUE;
+ eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
+
+
+ _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+
+ if (!_context || ![EAGLContext setCurrentContext:_context])
+ {
+ return nil;
+ }
+
+ _renderer = [[ES2Renderer alloc] initWithContext:_context AndDrawable:(id<EAGLDrawable>)self.layer];
+
+ if (!_renderer)
+ {
+ return nil;
+ }
+
+ _animating = FALSE;
+ _animationFrameInterval = 1;
+ _displayLink = nil;
+ }
+
+ return self;
+}
+
+- (void) drawView:(id)sender
+{
+ [EAGLContext setCurrentContext:_context];
+ [_renderer render];
+}
+
+- (void) layoutSubviews
+{
+ [_renderer resizeFromLayer:(CAEAGLLayer*)self.layer];
+ [self drawView:nil];
+}
+
+- (NSInteger) animationFrameInterval
+{
+ return _animationFrameInterval;
+}
+
+- (void) setAnimationFrameInterval:(NSInteger)frameInterval
+{
+ // Frame interval defines how many display frames must pass between each time the
+ // display link fires. The display link will only fire 30 times a second when the
+ // frame internal is two on a display that refreshes 60 times a second. The default
+ // frame interval setting of one will fire 60 times a second when the display refreshes
+ // at 60 times a second. A frame interval setting of less than one results in undefined
+ // behavior.
+ if (frameInterval >= 1)
+ {
+ _animationFrameInterval = frameInterval;
+
+ if (_animating)
+ {
+ [self stopAnimation];
+ [self startAnimation];
+ }
+ }
+}
+
+- (void) startAnimation
+{
+ if (!_animating)
+ {
+ // Create the display link and set the callback to our drawView method
+ _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView:)];
+
+ // Set it to our _animationFrameInterval
+ [_displayLink setFrameInterval:_animationFrameInterval];
+
+ // Have the display link run on the default runn loop (and the main thread)
+ [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+
+ _animating = TRUE;
+ }
+}
+
+- (void)stopAnimation
+{
+ if (_animating)
+ {
+ [_displayLink invalidate];
+ _displayLink = nil;
+ _animating = FALSE;
+ }
+}
+
+- (void) dealloc
+{
+ // tear down context
+ if ([EAGLContext currentContext] == _context)
+ [EAGLContext setCurrentContext:nil];
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.h b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.h
new file mode 100644
index 0000000..7b63b00
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.h
@@ -0,0 +1,25 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The main rendering code.
+ */
+
+#import <QuartzCore/QuartzCore.h>
+
+#import <OpenGLES/EAGL.h>
+#import <OpenGLES/EAGLDrawable.h>
+#import "OpenGLRenderer.h"
+
+@interface ES2Renderer : OpenGLRenderer
+{
+
+}
+
+- (instancetype)initWithContext:(EAGLContext*)context AndDrawable:(id<EAGLDrawable>)drawable;
+- (void)render;
+- (BOOL)resizeFromLayer:(CAEAGLLayer*)layer;
+
+@end
+
diff --git a/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.m b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.m
new file mode 100644
index 0000000..962aefe
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/Classes/iOS/ES2Renderer.m
@@ -0,0 +1,134 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ The main rendering code.
+ */
+
+#import "ES2Renderer.h"
+
+#import <OpenGLES/ES2/gl.h>
+#import <OpenGLES/ES2/glext.h>
+
+@interface ES2Renderer ()
+{
+ EAGLContext* _context;
+
+ // The OpenGL names for the framebuffer and renderbuffer used to render to this view
+ GLuint _colorRenderbuffer;
+ GLuint _depthRenderbuffer;
+}
+@end
+
+@implementation ES2Renderer
+
+// Create an ES 2.0 context
+- (instancetype)initWithContext:(EAGLContext*)context AndDrawable:(id<EAGLDrawable>)drawable
+{
+ // Create default framebuffer object. The backing will be allocated for the
+ // current layer in -resizeFromLayer
+ GLuint defaultFBOName;
+ glGenFramebuffers(1, &defaultFBOName);
+
+ glGenRenderbuffers(1, &_colorRenderbuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, defaultFBOName);
+ glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderbuffer);
+ _context = context;
+
+ // This call associates the storage for the current render buffer with the
+ // EAGLDrawable (our CAEAGLLayer) allowing us to draw into a buffer that
+ // will later be rendered to the screen wherever the layer is (which
+ // corresponds with our view).
+ [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:drawable];
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _colorRenderbuffer);
+
+ // Get the drawable buffer's width and height so we can create a depth buffer for the FBO
+ GLint backingWidth;
+ GLint backingHeight;
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
+
+ // Create a depth buffer to use with our drawable FBO
+ glGenRenderbuffers(1, &_depthRenderbuffer);
+ glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderbuffer);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer);
+
+ if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ {
+ NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
+ return nil;
+ }
+
+ self = [super initWithDefaultFBO:defaultFBOName];
+
+ if (nil == self)
+ {
+ glDeleteFramebuffers(1, &defaultFBOName);
+ glDeleteRenderbuffers(1, &_colorRenderbuffer);
+ glDeleteRenderbuffers(1, &_depthRenderbuffer);
+ }
+
+ return self;
+}
+
+- (void)render
+{
+ // Replace the implementation of this method to do your own custom drawing
+
+ glBindFramebuffer(GL_FRAMEBUFFER, super.defaultFBOName);
+
+ [super render];
+
+ glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderbuffer);
+ [_context presentRenderbuffer:GL_RENDERBUFFER];
+}
+
+- (BOOL)resizeFromLayer:(CAEAGLLayer*)layer
+{
+ // The pixel dimensions of the CAEAGLLayer
+ GLint backingWidth;
+ GLint backingHeight;
+
+ // Allocate color buffer backing based on the current layer size
+ glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderbuffer);
+ [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
+
+ glGenRenderbuffers(1, &_depthRenderbuffer);
+ glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderbuffer);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer);
+
+ [super resizeWithWidth:backingWidth AndHeight:backingHeight];
+
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ {
+ NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
+ return NO;
+ }
+
+ return YES;
+}
+
+- (void)dealloc
+{
+ // tear down GL
+ if (super.defaultFBOName)
+ {
+ GLuint defaultFBOName = super.defaultFBOName;
+ glDeleteFramebuffers(1, &defaultFBOName);
+ super.defaultFBOName = 0;
+ }
+
+ if (_colorRenderbuffer)
+ {
+ glDeleteRenderbuffers(1, &_colorRenderbuffer);
+ _colorRenderbuffer = 0;
+ }
+}
+
+@end
diff --git a/unityplugin/UnityEmulator/Apple/Source/main.m b/unityplugin/UnityEmulator/Apple/Source/main.m
new file mode 100644
index 0000000..f6fdd5b
--- /dev/null
+++ b/unityplugin/UnityEmulator/Apple/Source/main.m
@@ -0,0 +1,25 @@
+/*
+ Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Standard AppKit entry point.
+ */
+
+#ifdef TARGET_IOS
+#import <UIKit/UIKit.h>
+#import "AppDelegate.h"
+#else // OS X
+#import <Cocoa/Cocoa.h>
+#endif
+
+int main(int argc, char * argv[]) {
+
+#ifdef TARGET_IOS
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+#else
+ return NSApplicationMain(argc, (const char**)argv);
+#endif
+}
diff --git a/unityplugin/UnityEmulator/CMakeLists.txt b/unityplugin/UnityEmulator/CMakeLists.txt
index aa77ccb..c735671 100644
--- a/unityplugin/UnityEmulator/CMakeLists.txt
+++ b/unityplugin/UnityEmulator/CMakeLists.txt
@@ -86,6 +86,55 @@ elseif(PLATFORM_ANDROID)
list(APPEND SOURCE src/Android/AndroidMainImpl.cpp)
elseif(PLATFORM_LINUX)
list(APPEND SOURCE src/Linux/LinuxMain.cpp)
+elseif(PLATFORM_MACOS)
+ list(APPEND SOURCE
+ src/MacOS/Renderer.cpp
+ )
+ list(APPEND INCLUDE
+ src/MacOS/Renderer.h
+ )
+ set_source_files_properties(src/UnityGraphicsGLCore_Impl.cpp
+ PROPERTIES COMPILE_FLAGS "-x objective-c++"
+ )
+
+ function(get_emulator_macos_source MAC_SOURCE MAC_INCLUDE MAC_RESOURCES MAC_INFO_PLIST MAC_INCLUDE_DIRS)
+ get_target_property(EMULATOR_SOURCE_DIR UnityEmulator SOURCE_DIR)
+
+ set(${MAC_SOURCE}
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/main.m
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/WindowController.m
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.m
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.m
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.m
+ )
+ set_source_files_properties(${MAC_SOURCE} PROPERTIES
+ COMPILE_FLAGS "-x objective-c++"
+ )
+ set( MAC_SOURCE ${MAC_SOURCE} PARENT_SCOPE )
+
+ set(${MAC_INCLUDE}
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/WindowController.h
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.h
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.h
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.h
+ PARENT_SCOPE
+ )
+
+ set(${MAC_RESOURCES}
+ ${EMULATOR_SOURCE_DIR}/Apple/Data/OSX/Base.lproj/Main.storyboard
+ PARENT_SCOPE
+ )
+
+ set(${MAC_INFO_PLIST}
+ ${EMULATOR_SOURCE_DIR}/Apple/Data/OSX/Info.plist
+ PARENT_SCOPE
+ )
+
+ set(${MAC_INCLUDE_DIRS}
+ ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX
+ PARENT_SCOPE
+ )
+ endfunction()
else()
message(FATAL_ERROR "Unknown platform")
endif()
@@ -138,6 +187,10 @@ elseif(PLATFORM_ANDROID)
target_include_directories(UnityEmulator PRIVATE
${ANDROID_NDK}/sources/android/cpufeatures
)
+elseif(PLATFORM_MACOS)
+ target_include_directories(UnityEmulator PUBLIC
+ src/MacOS
+ )
endif()
source_group("src" FILES ${SOURCE})
diff --git a/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h b/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h
index 448c410..17f67f2 100644
--- a/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h
+++ b/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h
@@ -10,7 +10,7 @@
#if defined(PLATFORM_ANDROID)
class UnityGraphicsGLESAndroid_Impl;
using UnityGraphicsGL_Impl = UnityGraphicsGLESAndroid_Impl;
-#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX)
+#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
class UnityGraphicsGLCore_Impl;
using UnityGraphicsGL_Impl = UnityGraphicsGLCore_Impl;
#else
@@ -43,4 +43,4 @@ private:
static std::unique_ptr<UnityGraphicsGL_Impl> m_GraphicsImpl;
};
-#endif // OPENGL_SUPPORTED \ No newline at end of file
+#endif // OPENGL_SUPPORTED
diff --git a/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp b/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp
new file mode 100644
index 0000000..b793965
--- /dev/null
+++ b/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp
@@ -0,0 +1,126 @@
+/* Copyright 2015-2018 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include "Renderer.h"
+#include "Errors.h"
+#include "RenderDeviceFactoryOpenGL.h"
+
+#include "IUnityInterface.h"
+#include "UnityGraphicsGLCoreES_Emulator.h"
+#include "DiligentGraphicsAdapterGL.h"
+#include "StringTools.h"
+
+using namespace Diligent;
+
+extern "C"
+{
+ void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces);
+ void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginUnload();
+ UnityRenderingEvent __attribute__((visibility("default"))) UNITY_INTERFACE_API GetRenderEventFunc();
+}
+
+void* LoadPluginFunction(const char* FunctionName);
+
+bool LoadPlugin()
+{
+ // Do nothing. Function pointers are set automagically
+ return true;
+}
+
+void UnloadPlugin(UnityGraphicsEmulator *GraphicsEmulator)
+{
+ GraphicsEmulator->InvokeDeviceEventCallback(kUnityGfxDeviceEventShutdown);
+ UnityPluginUnload();
+}
+
+Renderer::Renderer()
+{
+}
+
+Renderer::~Renderer()
+{
+
+ pScene->OnPluginUnload();
+ pScene.reset();
+ UnloadPlugin(GraphicsEmulator);
+
+ pDiligentGraphics.reset();
+ GraphicsEmulator->Release();
+}
+
+void Renderer::Init()
+{
+ int major_version = 4;
+ int minor_version = 1;
+ auto &GraphicsGLCoreES_Emulator = UnityGraphicsGLCoreES_Emulator::GetInstance();
+ GraphicsGLCoreES_Emulator.InitGLContext(nullptr, major_version, minor_version);
+
+ pDiligentGraphics.reset(new DiligentGraphicsAdapterGL(GraphicsGLCoreES_Emulator));
+ GraphicsEmulator = &GraphicsGLCoreES_Emulator;
+
+ pScene.reset(CreateScene());
+ std::string Title = pScene->GetSceneName();
+ pScene->SetDiligentGraphicsAdapter(pDiligentGraphics.get());
+ pScene->OnGraphicsInitialized();
+ //if (DevType == DeviceType::D3D12)
+ //{
+ // UnityGraphicsD3D12Emulator::GetInstance().SetTransitionHandler(g_pScene->GetStateTransitionHandler());
+ //}
+
+ if (!LoadPlugin())
+ {
+ LOG_ERROR_AND_THROW("Failed to load the plugin");
+ }
+
+ pScene->OnPluginLoad(LoadPluginFunction);
+ UnityPluginLoad(&GraphicsEmulator->GeUnityInterfaces());
+
+ RenderEventFunc = GetRenderEventFunc();
+
+ PrevTime = timer.GetElapsedTime();
+}
+
+void Renderer::WindowResize(int width, int height)
+{
+ pDiligentGraphics->PreSwapChainResize();
+ GraphicsEmulator->ResizeSwapChain(static_cast<Uint32>(width), static_cast<Uint32>(height));
+ pDiligentGraphics->PostSwapChainResize();
+ pScene->OnWindowResize(static_cast<Uint32>(width), static_cast<Uint32>(height));
+}
+
+void Renderer::Render()
+{
+ // Render the scene
+ auto CurrTime = timer.GetElapsedTime();
+ auto ElapsedTime = CurrTime - PrevTime;
+ PrevTime = CurrTime;
+
+ GraphicsEmulator->BeginFrame();
+ pDiligentGraphics->BeginFrame();
+
+ pScene->Render(RenderEventFunc, CurrTime, ElapsedTime);
+
+ pDiligentGraphics->EndFrame();
+ GraphicsEmulator->EndFrame();
+}
+
diff --git a/unityplugin/UnityEmulator/src/MacOS/Renderer.h b/unityplugin/UnityEmulator/src/MacOS/Renderer.h
new file mode 100644
index 0000000..f22acc4
--- /dev/null
+++ b/unityplugin/UnityEmulator/src/MacOS/Renderer.h
@@ -0,0 +1,49 @@
+/* Copyright 2015-2018 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include "RenderDevice.h"
+#include "DeviceContext.h"
+#include "SwapChain.h"
+#include "RefCntAutoPtr.h"
+#include "UnitySceneBase.h"
+#include "Timer.h"
+#include <queue>
+
+class Renderer
+{
+public:
+ Renderer();
+ ~Renderer();
+ void Init();
+ void WindowResize(int width, int height);
+ void Render();
+
+private:
+ class UnityGraphicsEmulator *GraphicsEmulator = nullptr;
+ std::unique_ptr<class DiligentGraphicsAdapter> pDiligentGraphics;
+ std::unique_ptr<UnitySceneBase> pScene;
+ UnityRenderingEvent RenderEventFunc;
+ Diligent::Timer timer;
+ double PrevTime = 0.0;
+};
+
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
index f73db1a..30f1ae2 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
@@ -7,6 +7,12 @@
#include "DebugUtilities.h"
#include "Errors.h"
+#ifdef PLATFORM_MACOS
+#import <AppKit/AppKit.h>
+#endif
+
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
+
#ifndef APIENTRY
# define APIENTRY
#endif
@@ -71,6 +77,7 @@ void APIENTRY openglCallbackFunction( GLenum source,
#endif
}
+#endif // WIN32 or LINUX
UnityGraphicsGLCore_Impl::~UnityGraphicsGLCore_Impl()
{
@@ -79,7 +86,7 @@ UnityGraphicsGLCore_Impl::~UnityGraphicsGLCore_Impl()
#if defined(PLATFORM_WIN32)
wglMakeCurrent( m_WindowHandleToDeviceContext, 0 );
wglDeleteContext( m_Context );
-#elif defined(PLATFORM_LINUX)
+#elif defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
// Do nothing. Context is managed by the app
#else
# error Unknown platform
@@ -177,7 +184,17 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle,
GLenum err = glewInit();
if( GLEW_OK != err )
LOG_ERROR_AND_THROW( "Failed to initialize GLEW" );
-
+#elif defined(PLATFORM_MACOS)
+ NSOpenGLContext* CurrentCtx = [NSOpenGLContext currentContext];
+ m_Context = CurrentCtx;
+ if (m_Context == nullptr)
+ {
+ LOG_ERROR_AND_THROW("No current GL context found!");
+ }
+ // Initialize GLEW
+ GLenum err = glewInit();
+ if( GLEW_OK != err )
+ LOG_ERROR_AND_THROW( "Failed to initialize GLEW" );
#else
# error Unsupported platform
#endif
@@ -190,6 +207,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle,
glGetIntegerv( GL_MINOR_VERSION, &MinorVersion );
LOG_INFO_MESSAGE("Initialized OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ")");
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
if( glDebugMessageCallback )
{
glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS );
@@ -202,6 +220,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle,
&unusedIds,
true );
}
+#endif
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
if( glGetError() != GL_NO_ERROR )
@@ -225,9 +244,11 @@ void UnityGraphicsGLCore_Impl::SwapBuffers()
::SwapBuffers( m_WindowHandleToDeviceContext );
#elif defined(PLATFORM_LINUX)
glXSwapBuffers(m_Display, m_LinuxWindow);
+#elif defined(PLATFORM_MACOS)
+ UNEXPECTED("On MacOS, swap buffers operation is expected to be performed by the app");
#else
# error Unsupported platform
#endif
}
-#endif // OPENGL_SUPPORTED \ No newline at end of file
+#endif // OPENGL_SUPPORTED
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
index 31ec7ba..8ed3f90 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
@@ -43,6 +43,17 @@
# undef Success
# endif
+#elif defined(PLATFORM_MACOS)
+
+# ifndef GLEW_STATIC
+# define GLEW_STATIC // Must be defined to use static version of glew
+# endif
+# ifndef GLEW_NO_GLU
+# define GLEW_NO_GLU
+# endif
+
+# include "GL/glew.h"
+
#else
# error Unsupported platform
@@ -57,9 +68,11 @@ public:
typedef HGLRC NativeGLContextType;
#elif defined(PLATFORM_LINUX)
typedef GLXContext NativeGLContextType;
+#elif defined(PLATFORM_MACOS)
+ typedef void* NativeGLContextType;
#else
# error Unsupported platform
-#endif
+#endif
~UnityGraphicsGLCore_Impl();
@@ -88,6 +101,8 @@ private:
#elif defined(PLATFORM_LINUX)
Window m_LinuxWindow;
Display *m_Display;
+#elif defined(PLATFORM_MACOS)
+
#else
# error Unsupported platform
#endif
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h
index e636fc8..0c437ea 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h
@@ -4,7 +4,7 @@
#if defined(PLATFORM_ANDROID)
# include "Android/UnityGraphicsGLESAndroid_Impl.h"
-#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX)
+#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# include "UnityGraphicsGLCore_Impl.h"
#else
# error Unknown Platform