Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
#
# Copyright 2013 Pixar
#
# Licensed under the terms set forth in the LICENSE.txt file available at
# https://opensubdiv.org/license.
#
# *** mtlPtexViewer ***
if(IOS)
set(BUNDLE_FILES
"iOS/Base.lproj/LaunchScreen.storyboard"
"iOS/Base.lproj/Main.storyboard"
)
set(PLATFORM_PLIST "iOS/Info.plist")
set(PLATFORM_FILES
"iOS/AppDelegate.h"
"iOS/AppDelegate.m"
"iOS/main.m"
"iOS/ViewController.h"
"iOS/ViewController.mm"
)
list(APPEND PLATFORM_LIBRARIES
"-framework UIKit"
"z"
)
set_source_files_properties("${BUNDLE_FILES}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
else()
set(BUNDLE_FILES
"OSX/MainMenu.xib"
)
set(PLATFORM_PLIST "OSX/Info.plist")
set(PLATFORM_FILES
"OSX/AppDelegate.h"
"OSX/AppDelegate.m"
"OSX/main.m"
"OSX/ViewController.h"
"OSX/ViewController.mm"
)
list(APPEND PLATFORM_LIBRARIES
"-framework OpenGL"
"-framework AppKit"
)
set_source_files_properties("${BUNDLE_FILES}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endif()
include_directories(
"${OPENSUBDIV_INCLUDE_DIR}"
"${METAL_INCLUDE_DIR}"
"${PTEX_INCLUDE_DIR}"
)
list(APPEND PLATFORM_FILES
"mtlPtexViewer.h"
"mtlPtexViewer.mm"
)
list(APPEND PLATFORM_LIBRARIES
"osd_static_framework"
"${METAL_LIBRARY}"
"-framework MetalKit"
"-framework Foundation"
"-framework QuartzCore"
"${PTEX_LIBRARY}"
"${ZLIB_LIBRARY}"
)
osd_stringify("mtlPtexViewer.metal" INC_FILES)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
osd_add_executable(mtlPtexViewer "examples/mtlPtexViewer"
MACOSX_BUNDLE
"${PLATFORM_FILES}"
"${INC_FILES}"
"${BUNDLE_FILES}"
$<TARGET_OBJECTS:regression_common_obj>
$<TARGET_OBJECTS:regression_far_utils_obj>
$<TARGET_OBJECTS:examples_common_mtl_obj>
$<TARGET_OBJECTS:examples_common_ptex_obj>
)
set_target_properties (mtlPtexViewer PROPERTIES
LINKER_LANGUAGE CXX
RESOURCE "${BUNDLE_FILES}"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/${PLATFORM_PLIST}"
)
if(IOS)
set_target_properties(mtlPtexViewer PROPERTIES
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2"
)
endif()
target_link_libraries(mtlPtexViewer
${PLATFORM_LIBRARIES}
)
install(TARGETS mtlPtexViewer DESTINATION "${CMAKE_BINDIR_BASE}")

View File

@@ -0,0 +1,14 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end

View File

@@ -0,0 +1,25 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import "AppDelegate.h"
@implementation AppDelegate
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return true;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end

View File

@@ -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"
}
}

View File

@@ -0,0 +1,34 @@
<?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>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</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.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Pixar. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
</dict>
</plist>

View File

@@ -0,0 +1,686 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16C20" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject">
<connections>
<outlet property="delegate" destination="aZQ-9t-9YL" id="ke3-sq-jK1"/>
</connections>
</customObject>
<customObject id="aZQ-9t-9YL" customClass="AppDelegate"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="Test" id="1Xt-HY-uBw">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Test" systemMenu="apple" id="uQy-DD-JDr">
<items>
<menuItem title="About mtlPtexViewer" id="5kV-Vb-QxS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontStandardAboutPanel:" target="-1" 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 mtlPtexViewer" keyEquivalent="h" id="Olw-nP-bQN">
<connections>
<action selector="hide:" target="-1" 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="-1" id="VT4-aY-XCT"/>
</connections>
</menuItem>
<menuItem title="Show All" id="Kd2-mp-pUS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
<menuItem title="Quit mtlPtexViewer" keyEquivalent="q" id="4sb-4s-VLi">
<connections>
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="File" id="dMs-cI-mzQ">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="File" id="bib-Uj-vzu">
<items>
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
<connections>
<action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
</connections>
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
</connections>
</menuItem>
<menuItem title="Open Recent" id="tXI-mr-wws">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
<items>
<menuItem title="Clear Menu" id="vNY-rz-j42">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
<connections>
<action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
</connections>
</menuItem>
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
<connections>
<action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
</connections>
</menuItem>
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
<connections>
<action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
</connections>
</menuItem>
<menuItem title="Revert to Saved" id="KaW-ft-85H">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
<action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
</connections>
</menuItem>
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
<connections>
<action selector="print:" target="-1" id="qaZ-4w-aoO"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Edit" id="5QF-Oa-p0T">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Edit" id="W48-6f-4Dl">
<items>
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
<connections>
<action selector="undo:" target="-1" id="M6e-cu-g7V"/>
</connections>
</menuItem>
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
<connections>
<action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
<menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
<connections>
<action selector="cut:" target="-1" id="YJe-68-I9s"/>
</connections>
</menuItem>
<menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
<connections>
<action selector="copy:" target="-1" id="G1f-GL-Joy"/>
</connections>
</menuItem>
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
<connections>
<action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
</connections>
</menuItem>
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
</connections>
</menuItem>
<menuItem title="Delete" id="pa3-QI-u2k">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
</connections>
</menuItem>
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
<connections>
<action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
<menuItem title="Find" id="4EN-yA-p0u">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Find" id="1b7-l0-nxx">
<items>
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
<connections>
<action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
</connections>
</menuItem>
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
</connections>
</menuItem>
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
<connections>
<action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
</connections>
</menuItem>
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
<connections>
<action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
</connections>
</menuItem>
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
<connections>
<action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
</connections>
</menuItem>
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
<connections>
<action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
<items>
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
<connections>
<action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
</connections>
</menuItem>
<menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
<connections>
<action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
<menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
</connections>
</menuItem>
<menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
</connections>
</menuItem>
<menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Substitutions" id="9ic-FL-obx">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
<items>
<menuItem title="Show Substitutions" id="z6F-FW-3nz">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
<menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
</connections>
</menuItem>
<menuItem title="Smart Quotes" id="hQb-2v-fYv">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
</connections>
</menuItem>
<menuItem title="Smart Dashes" id="rgM-f4-ycn">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
</connections>
</menuItem>
<menuItem title="Smart Links" id="cwL-P1-jid">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
</connections>
</menuItem>
<menuItem title="Data Detectors" id="tRr-pd-1PS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
</connections>
</menuItem>
<menuItem title="Text Replacement" id="HFQ-gK-NFA">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Transformations" id="2oI-Rn-ZJC">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Transformations" id="c8a-y6-VQd">
<items>
<menuItem title="Make Upper Case" id="vmV-6d-7jI">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
</connections>
</menuItem>
<menuItem title="Make Lower Case" id="d9M-CD-aMd">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
</connections>
</menuItem>
<menuItem title="Capitalize" id="UEZ-Bs-lqG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Speech" id="xrE-MZ-jX0">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Speech" id="3rS-ZA-NoH">
<items>
<menuItem title="Start Speaking" id="Ynk-f8-cLZ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
</connections>
</menuItem>
<menuItem title="Stop Speaking" id="Oyz-dy-DGm">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Format" id="jxT-CU-nIS">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Format" id="GEO-Iw-cKr">
<items>
<menuItem title="Font" id="Gi5-1S-RQB">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
<items>
<menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
<connections>
<action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
</connections>
</menuItem>
<menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
<connections>
<action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
</connections>
</menuItem>
<menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
<connections>
<action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
</connections>
</menuItem>
<menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
<connections>
<action selector="underline:" target="-1" id="FYS-2b-JAY"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
<menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
<connections>
<action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
</connections>
</menuItem>
<menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
<connections>
<action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
<menuItem title="Kern" id="jBQ-r6-VK2">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Kern" id="tlD-Oa-oAM">
<items>
<menuItem title="Use Default" id="GUa-eO-cwY">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
</connections>
</menuItem>
<menuItem title="Use None" id="cDB-IK-hbR">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
</connections>
</menuItem>
<menuItem title="Tighten" id="46P-cB-AYj">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
</connections>
</menuItem>
<menuItem title="Loosen" id="ogc-rX-tC1">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Ligatures" id="o6e-r0-MWq">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
<items>
<menuItem title="Use Default" id="agt-UL-0e3">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
</connections>
</menuItem>
<menuItem title="Use None" id="J7y-lM-qPV">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
</connections>
</menuItem>
<menuItem title="Use All" id="xQD-1f-W4t">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Baseline" id="OaQ-X3-Vso">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Baseline" id="ijk-EB-dga">
<items>
<menuItem title="Use Default" id="3Om-Ey-2VK">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
</connections>
</menuItem>
<menuItem title="Superscript" id="Rqc-34-cIF">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
</connections>
</menuItem>
<menuItem title="Subscript" id="I0S-gh-46l">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
</connections>
</menuItem>
<menuItem title="Raise" id="2h7-ER-AoG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
</connections>
</menuItem>
<menuItem title="Lower" id="1tx-W0-xDw">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
<menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
<connections>
<action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
<menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
</connections>
</menuItem>
<menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Text" id="Fal-I4-PZk">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Text" id="d9c-me-L2H">
<items>
<menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
<connections>
<action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
</connections>
</menuItem>
<menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
<connections>
<action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
</connections>
</menuItem>
<menuItem title="Justify" id="J5U-5w-g23">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
</connections>
</menuItem>
<menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
<connections>
<action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
<menuItem title="Writing Direction" id="H1b-Si-o9J">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
<items>
<menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem id="YGs-j5-SAR">
<string key="title"> Default</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
</connections>
</menuItem>
<menuItem id="Lbh-J2-qVU">
<string key="title"> Left to Right</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
</connections>
</menuItem>
<menuItem id="jFq-tB-4Kx">
<string key="title"> Right to Left</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
<menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem id="Nop-cj-93Q">
<string key="title"> Default</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
</connections>
</menuItem>
<menuItem id="BgM-ve-c93">
<string key="title"> Left to Right</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
</connections>
</menuItem>
<menuItem id="RB4-Sm-HuC">
<string key="title"> Right to Left</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
<menuItem title="Show Ruler" id="vLm-3I-IUL">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
</connections>
</menuItem>
<menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
</connections>
</menuItem>
<menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
</connections>
</menuItem>
</items>
</menu>
</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="-1" id="BXY-wc-z0C"/>
</connections>
</menuItem>
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="runToolbarCustomizationPalette:" target="-1" 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="-1" id="VwT-WD-YPe"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="R4o-n2-Eq4">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="performZoom:" target="-1" 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="-1" 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="mtlPtexViewer Help" keyEquivalent="?" id="FKE-Sm-Kum">
<connections>
<action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
</menu>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hasShadow="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="1920" height="1080"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<view key="contentView" id="se5-gp-TjO" customClass="OSDView">
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<connections>
<outlet property="menu" destination="AYu-sK-qS6" id="0eg-gK-PK4"/>
</connections>
</view>
<point key="canvasLocation" x="172" y="11"/>
</window>
<viewController id="tdF-Vh-f4K" customClass="ViewController">
<connections>
<outlet property="view" destination="se5-gp-TjO" id="fc1-e3-wEk"/>
</connections>
</viewController>
</objects>
</document>

View File

@@ -0,0 +1,45 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import <AppKit/AppKit.h>
#import <MetalKit/MetalKit.h>
#import "../mtlPtexViewer.h"
#import "../../common/mtlHud.h"
@class ViewController;
@interface OSDView : MTKView {
@public
MTLhud hud;
};
@property (nonatomic) ViewController* controller;
@end
@interface ViewController : NSViewController<MTKViewDelegate, OSDRendererDelegate>
@property (weak) IBOutlet OSDView *view;
@property (nonatomic) OSDRenderer* osdRenderer;
@property (weak) IBOutlet NSTextField *frameTimeLabel;
@property (weak) IBOutlet NSButton *wireframeCheckbox;
@property (weak) IBOutlet NSButton *singleCreaseCheckbox;
@property (weak) IBOutlet NSButton *patchIndexCheckbox;
@property (weak) IBOutlet NSButton *patchClipCullingCheckbox;
@property (weak) IBOutlet NSButton *backfaceCullingCheckbox;
@property (weak) IBOutlet NSButton *backpatchCullingCheckbox;
@property (weak) IBOutlet NSButton *screenspaceTessellationCheckbox;
@property (weak) IBOutlet NSPopUpButton *modelPopup;
@property (weak) IBOutlet NSPopUpButton *refinementLevelPopup;
@property (weak) IBOutlet NSPopUpButton *tessellationLevelPopup;
@property (weak) IBOutlet NSPopUpButton *displacementModePopup;
@property (weak) IBOutlet NSPopUpButton *normalModePopup;
@property (weak) IBOutlet NSPopUpButton *colorModePopup;
@property (weak) IBOutlet NSSlider *displacementScaleSlider;
@property (weak) IBOutlet NSSlider *mipmapBiasSlider;
@end

View File

@@ -0,0 +1,450 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import "ViewController.h"
enum {
kHUD_RB_COLOR,
kHUD_RB_SCHEME,
kHUD_RB_LEVEL,
kHUD_RB_DISPLACEMENT,
kHUD_RB_NORMAL
};
enum {
kHUD_SL_MIPMAPBIAS,
kHUD_SL_DISPLACEMENT,
};
enum {
kHUD_CB_DISPLAY_OCCLUSION,
kHUD_CB_DISPLAY_SPECULAR,
kHUD_CB_ANIMATE_VERTICES,
kHUD_CB_VIEW_LOD,
kHUD_CB_FRACTIONAL_SPACING,
kHUD_CB_PATCH_CULL,
kHUD_CB_FREEZE,
kHUD_CB_ADAPTIVE,
kHUD_CB_SEAMLESS_MIPMAP,
};
@implementation OSDView {
bool _mouseDown;
NSPoint _lastMouse;
}
-(void)mouseDown:(NSEvent *)event {
if(event.buttonNumber == 0) {
_lastMouse = [event locationInWindow];
_mouseDown = !hud.MouseClick(_lastMouse.x, (self.bounds.size.height - _lastMouse.y));
}
[super mouseDown:event];
}
-(void)mouseUp:(NSEvent *)event {
if(event.buttonNumber == 0) {
_mouseDown = false;
_lastMouse = [event locationInWindow];
hud.MouseRelease();
}
[super mouseUp:event];
}
-(void)mouseDragged:(NSEvent *)event {
auto mouse = [NSEvent mouseLocation];
hud.MouseMotion(mouse.x, mouse.y);
if(_mouseDown) {
CGPoint delta;
delta.x = mouse.x - _lastMouse.x;
delta.y = mouse.y - _lastMouse.y;
_lastMouse = mouse;
_controller.osdRenderer.camera->rotationX += delta.x / 2.0;
_controller.osdRenderer.camera->rotationY -= delta.y / 2.0;
}
[super mouseDragged:event];
}
-(void)keyDown:(NSEvent *)event {
const auto key = [event.charactersIgnoringModifiers characterAtIndex:0];
if (hud.KeyDown(key)) {
return;
} else if(key == '=') {
_controller.osdRenderer.tessellationLevel = std::min(_controller.osdRenderer.tessellationLevel + 1, 16);
} else if (key == '-') {
_controller.osdRenderer.tessellationLevel = std::max(_controller.osdRenderer.tessellationLevel - 1, 0);
} else if (key == 'f') {
[_controller.osdRenderer fitFrame];
} else {
[super keyDown:event];
}
}
-(void)scrollWheel:(NSEvent *)event {
_controller.osdRenderer.camera->dollyDistance += event.deltaY / 100.0;
}
-(BOOL)acceptsFirstResponder {
return true;
}
@end
#define FRAME_HISTORY 30
@implementation ViewController {
id<MTLDevice> _device;
id<MTLCommandQueue> _commandQueue;
dispatch_semaphore_t _frameSemaphore;
OSDRenderer* _osdRenderer;
unsigned _currentFrame;
double _frameBeginTimestamp[FRAME_HISTORY];
NSMagnificationGestureRecognizer* _magnificationGesture;
}
-(void)viewDidLoad {
_device = MTLCreateSystemDefaultDevice();
_commandQueue = [_device newCommandQueue];
_osdRenderer = [[OSDRenderer alloc] initWithDelegate:self];
_frameSemaphore = dispatch_semaphore_create(3);
self.view.device = _device;
self.view.delegate = self;
self.view.depthStencilPixelFormat = MTLPixelFormatDepth32Float;
self.view.clearColor = MTLClearColorMake(0.4245, 0.4167, 0.4245, 1);
self.view.controller = self;
self.view.sampleCount = 2;
_osdRenderer.camera->aspectRatio = self.view.bounds.size.width / self.view.bounds.size.height;
_currentFrame = 0;
auto renderPipelineDescriptor = [MTLRenderPipelineDescriptor new];
renderPipelineDescriptor.colorAttachments[0].pixelFormat = self.view.colorPixelFormat;
renderPipelineDescriptor.depthAttachmentPixelFormat = self.view.depthStencilPixelFormat;
renderPipelineDescriptor.sampleCount = self.view.sampleCount;
auto depthStencilDescriptor = [MTLDepthStencilDescriptor new];
depthStencilDescriptor.depthWriteEnabled = false;
depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
auto& hud = self.view->hud;
hud.Init(_device, renderPipelineDescriptor, depthStencilDescriptor, self.view.bounds.size.width, self.view.bounds.size.height, self.view.drawableSize.width, self.view.drawableSize.height);
auto callbackCheckbox = [=](bool checked, int ID) {
switch(ID) {
case kHUD_CB_FREEZE:
self.osdRenderer.freeze = checked;
break;
case kHUD_CB_ADAPTIVE:
self.osdRenderer.useAdaptive = checked;
break;
case kHUD_CB_VIEW_LOD:
self.osdRenderer.useScreenspaceTessellation = checked;
break;
case kHUD_CB_PATCH_CULL:
self.osdRenderer.usePatchClipCulling = checked;
break;
case kHUD_CB_ANIMATE_VERTICES:
self.osdRenderer.animateVertices = checked;
break;
case kHUD_CB_DISPLAY_SPECULAR:
self.osdRenderer.displaySpecular = checked;
break;
case kHUD_CB_DISPLAY_OCCLUSION:
self.osdRenderer.displayOcclusion = checked;
break;
case kHUD_CB_FRACTIONAL_SPACING:
self.osdRenderer.useFractionalTessellation = checked;
break;
case kHUD_CB_SEAMLESS_MIPMAP:
self.osdRenderer.useSeamlessMipmap = checked;
break;
default:
assert("Unknown checkbox ID" && 0);
}
};
auto callbackScheme = [=](int) {
return;
};
auto callbackLevel = [=](int level) {
self.osdRenderer.refinementLevel = level;
};
auto callbackKernel = [=](int kernelType) {
switch((KernelType)kernelType) {
case kCPU:
case kMetal:
self.osdRenderer.kernelType = (KernelType)(kernelType);
break;
default:
assert("Unknown kernelType" && 0);
}
};
auto callbackDisplayStyle = [=](int displayStyle) {
switch((DisplayStyle)displayStyle) {
case kDisplayStyleWire:
case kDisplayStyleShaded:
case kDisplayStyleWireOnShaded:
self.osdRenderer.displayStyle = (DisplayStyle)displayStyle;
break;
default:
assert("Unknown displayStyle" && 0);
}
};
auto callbackColor = [=](int colorMode) {
switch((ColorMode)colorMode) {
case kColorModeNone:
case kColorModeNormal:
case kColorModePatchType:
case kColorModePatchCoord:
case kColorModePtexNearest:
case kColorModePtexBilinear:
case kColorModePtexHWBilinear:
case kColorModePtexBiQuadratic:
self.osdRenderer.colorMode = (ColorMode)colorMode;
break;
default:
assert("Unknown colorMode" && 0);
}
};
auto callbackDisplacement = [=](int displacementMode) {
switch((DisplacementMode)displacementMode) {
case kDisplacementModeNone:
case kDisplacementModeBilinear:
case kDisplacementModeHWBilinear:
case kDisplacementModeBiQuadratic:
self.osdRenderer.displacementMode = (DisplacementMode)displacementMode;
break;
default:
assert("Unknown displacementMode" && 0);
}
};
auto callbackNormal = [=](int normalMode) {
switch((NormalMode)normalMode) {
case kNormalModeBiQuadraticWG:
case kNormalModeBiQuadratic:
case kNormalModeScreenspace:
case kNormalModeHWScreenspace:
case kNormalModeSurface:
self.osdRenderer.normalMode = (NormalMode)normalMode;
break;
default:
assert("Unknown normalMode" && 0);
}
};
auto callbackSlider = [=](float sliderValue, int sliderID) {
switch(sliderID) {
case kHUD_SL_DISPLACEMENT:
self.osdRenderer.displacementScale = sliderValue;
break;
case kHUD_SL_MIPMAPBIAS:
self.osdRenderer.mipmapBias = sliderValue;
break;
default:
assert("Unknown slider ID" && 0);
}
};
if (_osdRenderer.ptexOcclusionFilename != NULL) {
hud.AddCheckBox("Ambient Occlusion (A)", _osdRenderer.ptexOcclusionFilename,
-200, 570, callbackCheckbox, kHUD_CB_DISPLAY_OCCLUSION, 'a');
}
if (_osdRenderer.ptexSpecularFilename != NULL)
hud.AddCheckBox("Specular (S)", _osdRenderer.ptexSpecularFilename,
-200, 590, callbackCheckbox, kHUD_CB_DISPLAY_SPECULAR, 's');
// if (_osdRenderer.ptexColorFilename || g_diffuseEnvironmentMap) {
// hud.AddCheckBox("IBL (I)", g_ibl,
// -200, 610, callbackCheckbox, HUD_CB_IBL, 'i');
// }
hud.AddCheckBox("Animate vertices (M)", _osdRenderer.animateVertices,
10, 30, callbackCheckbox, kHUD_CB_ANIMATE_VERTICES, 'm');
hud.AddCheckBox("Screen space LOD (V)", _osdRenderer.useScreenspaceTessellation,
10, 50, callbackCheckbox, kHUD_CB_VIEW_LOD, 'v');
hud.AddCheckBox("Fractional spacing (T)", _osdRenderer.useFractionalTessellation,
10, 70, callbackCheckbox, kHUD_CB_FRACTIONAL_SPACING, 't');
hud.AddCheckBox("Frustum Patch Culling (B)", _osdRenderer.usePatchClipCulling,
10, 90, callbackCheckbox, kHUD_CB_PATCH_CULL, 'b');
hud.AddCheckBox("Freeze (spc)", _osdRenderer.freeze,
10, 110, callbackCheckbox, kHUD_CB_FREEZE, ' ');
// hud.AddCheckBox("Bloom (Y)", g_bloom,
// 10, 130, callbackCheckbox, HUD_CB_BLOOM, 'y');
hud.AddRadioButton(kHUD_RB_SCHEME, "CATMARK", true, 10, 190, callbackScheme, 0);
// Ptex without Adaptive is not supported
// hud.AddCheckBox("Adaptive (`)", _osdRenderer.useAdaptive,
// 10, 300, callbackCheckbox, kHUD_CB_ADAPTIVE, '`');
for (int i = 1; i < 8; ++i) {
NSString *level = [NSString stringWithFormat:@"Lv. %d", i];
hud.AddRadioButton(kHUD_RB_LEVEL, [level UTF8String],
i==(int)_osdRenderer.refinementLevel,
10, 320+i*20, callbackLevel, i, '0'+i);
}
int compute_pulldown = hud.AddPullDown("Compute (K)", 475, 10, 300, callbackKernel, 'k');
hud.AddPullDownButton(compute_pulldown, "CPU", kCPU);
hud.AddPullDownButton(compute_pulldown, "Metal", kMetal);
int shading_pulldown = hud.AddPullDown("Shading (W)", 250, 10, 250, callbackDisplayStyle, 'w');
hud.AddPullDownButton(shading_pulldown, "Wire", kDisplayStyleWire, _osdRenderer.displayStyle == kDisplayStyleWire);
hud.AddPullDownButton(shading_pulldown, "Shaded", kDisplayStyleShaded, _osdRenderer.displayStyle == kDisplayStyleShaded);
hud.AddPullDownButton(shading_pulldown, "Wire+Shaded", kDisplayStyleWireOnShaded, _osdRenderer.displayStyle ==kDisplayStyleWireOnShaded);
hud.AddLabel("Color (C)", -200, 10);
hud.AddRadioButton(kHUD_RB_COLOR, "None", (_osdRenderer.colorMode == kColorModeNone),
-200, 30, callbackColor, kColorModeNone, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Ptex Nearest", (_osdRenderer.colorMode == kColorModePtexNearest),
-200, 50, callbackColor, kColorModePtexNearest, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Ptex HW bilinear", (_osdRenderer.colorMode == kColorModePtexHWBilinear),
-200, 70, callbackColor, kColorModePtexHWBilinear, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Ptex bilinear", (_osdRenderer.colorMode == kColorModePtexBilinear),
-200, 90, callbackColor, kColorModePtexBilinear, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Ptex biquadratic", (_osdRenderer.colorMode == kColorModePtexBiQuadratic),
-200, 110, callbackColor, kColorModePtexBiQuadratic, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Patch type", (_osdRenderer.colorMode == kColorModePatchType),
-200, 130, callbackColor, kColorModePatchType, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Patch coord", (_osdRenderer.colorMode == kColorModePatchCoord),
-200, 150, callbackColor, kColorModePatchCoord, 'c');
hud.AddRadioButton(kHUD_RB_COLOR, "Normal", (_osdRenderer.colorMode == kColorModeNormal),
-200, 170, callbackColor, kColorModeNormal, 'c');
if (_osdRenderer.ptexDisplacementFilename) {
hud.AddLabel("Displacement (D)", -200, 200);
hud.AddRadioButton(kHUD_RB_DISPLACEMENT, "None",
(_osdRenderer.displacementMode == kDisplacementModeNone),
-200, 220, callbackDisplacement, kDisplacementModeNone, 'd');
hud.AddRadioButton(kHUD_RB_DISPLACEMENT, "HW bilinear",
(_osdRenderer.displacementMode == kDisplacementModeHWBilinear),
-200, 240, callbackDisplacement, kDisplacementModeHWBilinear, 'd');
hud.AddRadioButton(kHUD_RB_DISPLACEMENT, "Bilinear",
(_osdRenderer.displacementMode == kDisplacementModeBilinear),
-200, 260, callbackDisplacement, kDisplacementModeBilinear, 'd');
hud.AddRadioButton(kHUD_RB_DISPLACEMENT, "Biquadratic",
(_osdRenderer.displacementMode == kDisplacementModeBiQuadratic),
-200, 280, callbackDisplacement, kDisplacementModeBiQuadratic, 'd');
{
int y = 310;
hud.AddLabel("Normal (N)", -200, y); y += 20;
hud.AddRadioButton(kHUD_RB_NORMAL, "Surface",
(_osdRenderer.normalMode == kNormalModeSurface),
-200, y, callbackNormal, kNormalModeSurface, 'n'); y += 20;
// hud.AddRadioButton(kHUD_RB_NORMAL, "Facet", //We can't really do NORMAL_FACET
// (_osdRenderer.normalMode == NORMAL_FACET),
// -200, y, callbackNormal, NORMAL_FACET, 'n'); y += 20;
hud.AddRadioButton(kHUD_RB_NORMAL, "HW Screen space",
(_osdRenderer.normalMode == kNormalModeHWScreenspace),
-200, y, callbackNormal, kNormalModeHWScreenspace, 'n'); y += 20;
hud.AddRadioButton(kHUD_RB_NORMAL, "Screen space",
(_osdRenderer.normalMode == kNormalModeScreenspace),
-200, y, callbackNormal, kNormalModeScreenspace, 'n'); y += 20;
hud.AddRadioButton(kHUD_RB_NORMAL, "Biquadratic",
(_osdRenderer.normalMode == kNormalModeBiQuadratic),
-200, y, callbackNormal, kNormalModeBiQuadratic, 'n'); y += 20;
hud.AddRadioButton(kHUD_RB_NORMAL, "Biquadratic WG",
(_osdRenderer.normalMode == kNormalModeBiQuadraticWG),
-200, y, callbackNormal, kNormalModeBiQuadraticWG, 'n'); y += 20;
}
}
hud.AddSlider("Mipmap Bias", 0, 5, 0,
-200, 450, 20, false, callbackSlider, kHUD_SL_MIPMAPBIAS);
hud.AddSlider("Displacement", 0, 5, 1,
-200, 490, 20, false, callbackSlider, kHUD_SL_DISPLACEMENT);
hud.AddCheckBox("Seamless Mipmap", _osdRenderer.useSeamlessMipmap,
-200, 530, callbackCheckbox, kHUD_CB_SEAMLESS_MIPMAP, 'j');
hud.Rebuild(self.view.bounds.size.width, self.view.bounds.size.height, self.view.drawableSize.width, self.view.drawableSize.height);
}
-(void)drawInMTKView:(MTKView *)view {
dispatch_semaphore_wait(_frameSemaphore, DISPATCH_TIME_FOREVER);
auto commandBuffer = [_commandQueue commandBuffer];
double avg = 0;
for(int i = 0; i < FRAME_HISTORY; i++)
avg += _frameBeginTimestamp[i];
avg /= FRAME_HISTORY;
auto renderEncoder = [_osdRenderer drawFrame:commandBuffer];
auto& hud = self.view->hud;
if(hud.IsVisible()) {
hud.DrawString(10, -120, "Tess level : %d", _osdRenderer.tessellationLevel);
hud.DrawString(10, -20, "FPS = %3.1f", 1.0 / avg);
//Disable Culling & Force Fill mode when drawing the UI
[renderEncoder setTriangleFillMode:MTLTriangleFillModeFill];
[renderEncoder setCullMode:MTLCullModeNone];
self.view->hud.Flush(renderEncoder);
};
[renderEncoder endEncoding];
__weak auto blockSemaphore = _frameSemaphore;
unsigned frameId = _currentFrame % FRAME_HISTORY;
auto frameBeginTime = CACurrentMediaTime();
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> _Nonnull) {
dispatch_semaphore_signal(blockSemaphore);
_frameBeginTimestamp[frameId] = CACurrentMediaTime() - frameBeginTime;
}];
[commandBuffer presentDrawable:view.currentDrawable];
[commandBuffer commit];
_currentFrame++;
}
-(void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
_osdRenderer.camera->aspectRatio = size.width / size.height;
}
-(void)setupDepthStencilState:(MTLDepthStencilDescriptor *)descriptor for:(OSDRenderer *)renderer {
}
-(void)setupRenderPipelineState:(MTLRenderPipelineDescriptor *)descriptor for:(OSDRenderer *)renderer {
descriptor.depthAttachmentPixelFormat = self.view.depthStencilPixelFormat;
descriptor.colorAttachments[0].pixelFormat = self.view.colorPixelFormat;
descriptor.sampleCount = self.view.sampleCount;
}
-(id<MTLCommandQueue>)commandQueueFor:(OSDRenderer *)renderer {
return _commandQueue;
}
-(id<MTLDevice>)deviceFor:(OSDRenderer *)renderer {
return _device;
}
-(MTLRenderPassDescriptor *)renderPassDescriptorFor:(OSDRenderer *)renderer {
return self.view.currentRenderPassDescriptor;
}
@end

View File

@@ -0,0 +1,5 @@
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
}

View File

@@ -0,0 +1,16 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -0,0 +1,44 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
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.
}
- (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, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (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.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end

View File

@@ -0,0 +1,73 @@
{
"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"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11147" systemVersion="16A201u" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11119"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="1024" height="1366"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,265 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11173.2" systemVersion="16A264" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11143.2"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" 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="MTKView">
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Information Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ze8-2s-lED">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minimumValue="1" maximumValue="5" translatesAutoresizingMaskIntoConstraints="NO" id="QQ6-5o-gla">
<connections>
<action selector="stepperChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="uHZ-dB-XZV"/>
</connections>
</stepper>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Ref Lvl." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="N12-GK-yLY">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="16" translatesAutoresizingMaskIntoConstraints="NO" id="eYp-5M-Rgk">
<connections>
<action selector="stepperChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="mBg-38-OPM"/>
</connections>
</stepper>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="8kP-4Y-wzA">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="UsH-Nw-M31"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Wireframe" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FvR-NK-6s0" userLabel="Wireframe">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Backpatch Culling" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="esT-7h-XLG">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="P8z-O2-OLV">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="w7T-KH-L3E"/>
</connections>
</switch>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="5Ns-3P-r13">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="ym1-Xw-wU6"/>
</connections>
</switch>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="fw1-9C-P6U">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="8kp-Rh-Yua"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Backface Culling" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Iw4-VH-Zwm">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Patch Clip Culling" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5xP-bY-PgM">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Single Crease" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kuw-3r-nzl">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7yA-a6-Sq7">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="Yg5-z5-avS"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Screenspace Tessellation" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ioY-T2-PEM">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tes Lvl." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dlx-hC-oDg">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sDC-ZC-b6I">
<connections>
<action selector="switchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="ebT-0s-gYR"/>
</connections>
</switch>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lKi-xk-48C">
<constraints>
<constraint firstAttribute="width" constant="229" id="Wpt-NP-71K"/>
<constraint firstAttribute="height" constant="100" id="zRD-L8-taf"/>
</constraints>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="9Fy-8F-lh4"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="AGI-ts-ucC"/>
</connections>
</pickerView>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MhN-MJ-gcY">
<constraints>
<constraint firstAttribute="width" constant="229" id="2un-1F-Mel"/>
<constraint firstAttribute="height" constant="100" id="e85-YP-l4W"/>
</constraints>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="fva-Gz-Lm9"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="vnc-OK-4c7"/>
</connections>
</pickerView>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="pci-qy-cH2">
<constraints>
<constraint firstAttribute="width" constant="229" id="ZYQ-3j-No7"/>
<constraint firstAttribute="height" constant="100" id="iBl-mj-oGZ"/>
</constraints>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="e4g-y8-rgS"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="txx-qB-tmn"/>
</connections>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Color Mode" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Q2s-bO-zy8">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Normal Mode" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I4F-1D-Czt">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Displacement Mode" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uci-PY-aOB">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="5Ee-cu-NZx">
<constraints>
<constraint firstAttribute="width" constant="300" id="zHK-PA-cxQ"/>
</constraints>
<connections>
<action selector="sliderChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="x6e-A1-PtP"/>
</connections>
</slider>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Mipmap Bias" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ep7-AF-66o">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Displacement" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2eJ-wE-QUZ">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="lg4-UF-DUA">
<constraints>
<constraint firstAttribute="width" constant="300" id="SAY-uf-0VR"/>
</constraints>
<connections>
<action selector="sliderChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="T6h-NW-Qz3"/>
</connections>
</slider>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="P8z-O2-OLV" firstAttribute="leading" secondItem="esT-7h-XLG" secondAttribute="trailing" constant="8" id="0zt-WU-LC3"/>
<constraint firstItem="fw1-9C-P6U" firstAttribute="top" secondItem="5Ns-3P-r13" secondAttribute="bottom" constant="8" id="404-z0-Fv7"/>
<constraint firstItem="pci-qy-cH2" firstAttribute="centerY" secondItem="uci-PY-aOB" secondAttribute="centerY" id="51c-EC-nM4"/>
<constraint firstAttribute="trailing" secondItem="pci-qy-cH2" secondAttribute="trailing" constant="8" id="5JD-9Q-LoS"/>
<constraint firstItem="MhN-MJ-gcY" firstAttribute="top" secondItem="pci-qy-cH2" secondAttribute="bottom" constant="8" id="5We-Fg-mqK"/>
<constraint firstItem="8kP-4Y-wzA" firstAttribute="leading" secondItem="FvR-NK-6s0" secondAttribute="trailing" constant="8" id="5rd-n5-Uxl"/>
<constraint firstItem="5Ee-cu-NZx" firstAttribute="trailing" secondItem="lg4-UF-DUA" secondAttribute="trailing" id="7wp-4z-St6"/>
<constraint firstItem="8kP-4Y-wzA" firstAttribute="top" secondItem="7yA-a6-Sq7" secondAttribute="bottom" constant="8" id="81h-8V-det"/>
<constraint firstItem="lKi-xk-48C" firstAttribute="leading" secondItem="Q2s-bO-zy8" secondAttribute="trailing" constant="8" id="9Hf-nv-kO7"/>
<constraint firstItem="eYp-5M-Rgk" firstAttribute="leading" secondItem="dlx-hC-oDg" secondAttribute="trailing" constant="8" id="B0o-kO-368"/>
<constraint firstAttribute="trailing" secondItem="MhN-MJ-gcY" secondAttribute="trailing" constant="8" id="B5N-TG-DvY"/>
<constraint firstAttribute="trailing" secondItem="lKi-xk-48C" secondAttribute="trailing" constant="8" id="Dsf-kk-VQH"/>
<constraint firstItem="8kP-4Y-wzA" firstAttribute="trailing" secondItem="7yA-a6-Sq7" secondAttribute="trailing" id="HIl-Xg-PwW"/>
<constraint firstItem="ioY-T2-PEM" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="25" id="Kg5-1N-BpG"/>
<constraint firstItem="P8z-O2-OLV" firstAttribute="centerY" secondItem="esT-7h-XLG" secondAttribute="centerY" id="Oxf-2f-wTD"/>
<constraint firstItem="eYp-5M-Rgk" firstAttribute="top" secondItem="QQ6-5o-gla" secondAttribute="bottom" constant="8" id="PJS-Lq-bIL"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="lKi-xk-48C" secondAttribute="bottom" constant="25" id="PnT-0o-uNH"/>
<constraint firstItem="7yA-a6-Sq7" firstAttribute="top" secondItem="sDC-ZC-b6I" secondAttribute="bottom" constant="8" id="QC2-TN-FjW"/>
<constraint firstItem="Ze8-2s-lED" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="20" id="SZK-UA-BiA"/>
<constraint firstItem="MhN-MJ-gcY" firstAttribute="leading" secondItem="I4F-1D-Czt" secondAttribute="trailing" constant="8" id="T1r-ZQ-Jxi"/>
<constraint firstItem="MhN-MJ-gcY" firstAttribute="centerY" secondItem="I4F-1D-Czt" secondAttribute="centerY" id="Tdj-kw-7IN"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="dlx-hC-oDg" secondAttribute="bottom" constant="25" id="U0T-iQ-NLt"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="fw1-9C-P6U" secondAttribute="bottom" constant="20" id="Uw7-fz-We7"/>
<constraint firstItem="sDC-ZC-b6I" firstAttribute="leading" secondItem="kuw-3r-nzl" secondAttribute="trailing" constant="8" id="W06-wv-gqs"/>
<constraint firstItem="QQ6-5o-gla" firstAttribute="centerY" secondItem="N12-GK-yLY" secondAttribute="centerY" id="bqu-uw-PqG"/>
<constraint firstItem="eYp-5M-Rgk" firstAttribute="centerY" secondItem="dlx-hC-oDg" secondAttribute="centerY" id="cV6-GZ-8IP"/>
<constraint firstItem="7yA-a6-Sq7" firstAttribute="leading" secondItem="ioY-T2-PEM" secondAttribute="trailing" constant="8" id="cqL-gl-vn2"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="5xP-bY-PgM" secondAttribute="bottom" constant="25" id="cqZ-ZJ-qwf"/>
<constraint firstItem="fw1-9C-P6U" firstAttribute="leading" secondItem="5xP-bY-PgM" secondAttribute="trailing" constant="8" id="dhX-z5-kgA"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="5Ee-cu-NZx" secondAttribute="bottom" constant="25" id="erc-MZ-6N2"/>
<constraint firstItem="5Ns-3P-r13" firstAttribute="centerY" secondItem="Iw4-VH-Zwm" secondAttribute="centerY" id="fEO-gM-cmZ"/>
<constraint firstItem="lg4-UF-DUA" firstAttribute="leading" secondItem="2eJ-wE-QUZ" secondAttribute="trailing" constant="8" id="gne-Dp-lLU"/>
<constraint firstItem="5Ns-3P-r13" firstAttribute="trailing" secondItem="8kP-4Y-wzA" secondAttribute="trailing" id="gqA-q9-SK3"/>
<constraint firstItem="lKi-xk-48C" firstAttribute="centerY" secondItem="Q2s-bO-zy8" secondAttribute="centerY" id="hdJ-mn-wba"/>
<constraint firstItem="pci-qy-cH2" firstAttribute="leading" secondItem="uci-PY-aOB" secondAttribute="trailing" constant="8" id="huu-H0-Tby"/>
<constraint firstItem="5Ee-cu-NZx" firstAttribute="centerY" secondItem="ep7-AF-66o" secondAttribute="centerY" id="iXa-Hm-SyL"/>
<constraint firstItem="Ze8-2s-lED" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="20" id="kTX-YC-JKR"/>
<constraint firstItem="dlx-hC-oDg" firstAttribute="leading" secondItem="fw1-9C-P6U" secondAttribute="trailing" constant="57" id="kk2-dV-2jk"/>
<constraint firstItem="lKi-xk-48C" firstAttribute="top" secondItem="MhN-MJ-gcY" secondAttribute="bottom" constant="8" id="m49-1U-Jcw"/>
<constraint firstItem="8kP-4Y-wzA" firstAttribute="centerY" secondItem="FvR-NK-6s0" secondAttribute="centerY" id="n3L-qM-7Pr"/>
<constraint firstItem="fw1-9C-P6U" firstAttribute="centerY" secondItem="5xP-bY-PgM" secondAttribute="centerY" id="nP1-Bt-GuV"/>
<constraint firstItem="lKi-xk-48C" firstAttribute="top" secondItem="MhN-MJ-gcY" secondAttribute="bottom" constant="8" id="nrc-E0-3gd"/>
<constraint firstItem="7yA-a6-Sq7" firstAttribute="trailing" secondItem="sDC-ZC-b6I" secondAttribute="trailing" id="pkW-Gf-A1P"/>
<constraint firstItem="5Ns-3P-r13" firstAttribute="top" secondItem="P8z-O2-OLV" secondAttribute="bottom" constant="8" id="pwK-2F-IIf"/>
<constraint firstItem="P8z-O2-OLV" firstAttribute="top" secondItem="8kP-4Y-wzA" secondAttribute="bottom" constant="8" id="q11-mD-QDz"/>
<constraint firstItem="QQ6-5o-gla" firstAttribute="leading" secondItem="N12-GK-yLY" secondAttribute="trailing" constant="8" id="qBz-A8-IZc"/>
<constraint firstItem="P8z-O2-OLV" firstAttribute="trailing" secondItem="8kP-4Y-wzA" secondAttribute="trailing" id="rha-qA-vsj"/>
<constraint firstItem="fw1-9C-P6U" firstAttribute="trailing" secondItem="8kP-4Y-wzA" secondAttribute="trailing" id="ro3-hx-iLk"/>
<constraint firstItem="5Ns-3P-r13" firstAttribute="leading" secondItem="Iw4-VH-Zwm" secondAttribute="trailing" constant="8" id="ry7-bQ-bRa"/>
<constraint firstItem="MhN-MJ-gcY" firstAttribute="top" secondItem="pci-qy-cH2" secondAttribute="bottom" constant="8" id="sR8-Lw-q9X"/>
<constraint firstItem="eYp-5M-Rgk" firstAttribute="trailing" secondItem="QQ6-5o-gla" secondAttribute="trailing" id="syp-eW-H7w"/>
<constraint firstItem="fw1-9C-P6U" firstAttribute="top" secondItem="5Ns-3P-r13" secondAttribute="bottom" constant="8" id="tsW-3r-293"/>
<constraint firstItem="7yA-a6-Sq7" firstAttribute="centerY" secondItem="ioY-T2-PEM" secondAttribute="centerY" id="wE0-Cg-4Qf"/>
<constraint firstItem="sDC-ZC-b6I" firstAttribute="centerY" secondItem="kuw-3r-nzl" secondAttribute="centerY" id="wTg-7H-KXF"/>
<constraint firstItem="lg4-UF-DUA" firstAttribute="centerY" secondItem="2eJ-wE-QUZ" secondAttribute="centerY" id="x0b-B2-XkG"/>
<constraint firstItem="ep7-AF-66o" firstAttribute="leading" secondItem="eYp-5M-Rgk" secondAttribute="trailing" constant="52" id="xFx-Kb-IBp"/>
<constraint firstItem="5Ee-cu-NZx" firstAttribute="leading" secondItem="ep7-AF-66o" secondAttribute="trailing" constant="8" id="xye-mn-VX2"/>
<constraint firstItem="5Ee-cu-NZx" firstAttribute="top" secondItem="lg4-UF-DUA" secondAttribute="bottom" constant="8" id="zVK-yu-Uuz"/>
</constraints>
</view>
<connections>
<outlet property="backfaceCullingSwitch" destination="5Ns-3P-r13" id="n8X-2V-BRl"/>
<outlet property="backpatchCullingSwitch" destination="P8z-O2-OLV" id="VIe-Lv-hsC"/>
<outlet property="colorModePickerView" destination="lKi-xk-48C" id="u5F-aY-10I"/>
<outlet property="displacementModePickerView" destination="pci-qy-cH2" id="jaV-1A-n0X"/>
<outlet property="displacementSlider" destination="lg4-UF-DUA" id="BWG-lH-Qfm"/>
<outlet property="frameTimeLabel" destination="Ze8-2s-lED" id="vLj-Id-oiv"/>
<outlet property="mipmapBiasSlider" destination="5Ee-cu-NZx" id="WGF-bb-PaA"/>
<outlet property="normalModePickerView" destination="MhN-MJ-gcY" id="LJw-CH-3Im"/>
<outlet property="patchClipCullingSwitch" destination="fw1-9C-P6U" id="P2G-3F-eJh"/>
<outlet property="refLvlLabel" destination="N12-GK-yLY" id="lXc-6r-pZY"/>
<outlet property="refinementStepper" destination="QQ6-5o-gla" id="URK-fS-krY"/>
<outlet property="screenspaceTessellationSwitch" destination="7yA-a6-Sq7" id="RpM-ER-4Oy"/>
<outlet property="singleCreaseSwitch" destination="sDC-ZC-b6I" id="Arw-OY-Z4A"/>
<outlet property="tesLvLlabel" destination="dlx-hC-oDg" id="haB-Hi-A9B"/>
<outlet property="tessellationStepper" destination="eYp-5M-Rgk" id="IFG-H5-rJS"/>
<outlet property="wireframeSwitch" destination="8kP-4Y-wzA" id="y3a-yu-4cs"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="463.83601756954607" y="406.640625"/>
</scene>
</scenes>
<color key="tintColor" cocoaTouchSystemColor="darkTextColor"/>
</document>

View File

@@ -0,0 +1,50 @@
<?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>mtlPtexViewer</string>
<key>CFBundleIdentifier</key>
<string>com.osd.mtlPtexViewer</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>mtlPtexViewer</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</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>arm64</string>
<string>metal</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,40 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import <UIKit/UIKit.h>
#import <MetalKit/MetalKit.h>
#import "../mtlPtexViewer.h"
@interface ViewController : UIViewController<
MTKViewDelegate,
UIPickerViewDelegate,
UIPickerViewDataSource,
OSDRendererDelegate
>
@property (weak, nonatomic) IBOutlet UILabel *refLvlLabel;
@property (weak, nonatomic) IBOutlet UILabel *tesLvLlabel;
@property (weak, nonatomic) IBOutlet UILabel *frameTimeLabel;
@property (weak, nonatomic) IBOutlet UIPickerView *colorModePickerView;
@property (weak, nonatomic) IBOutlet UIPickerView *normalModePickerView;
@property (weak, nonatomic) IBOutlet UIPickerView *displacementModePickerView;
@property (weak, nonatomic) IBOutlet UIStepper *tessellationStepper;
@property (weak, nonatomic) IBOutlet UIStepper *refinementStepper;
@property (weak, nonatomic) IBOutlet UISwitch *wireframeSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *backpatchCullingSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *backfaceCullingSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *patchClipCullingSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *singleCreaseSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *screenspaceTessellationSwitch;
@property (weak, nonatomic) IBOutlet UISlider *displacementSlider;
@property (weak, nonatomic) IBOutlet UISlider *mipmapBiasSlider;
- (IBAction)stepperChanged:(UIStepper *)sender;
- (IBAction)switchChanged:(UISwitch *)sender;
- (IBAction)sliderChanged:(UISlider*)sender;
@end

View File

@@ -0,0 +1,280 @@
//
// Copyright 2013 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#import "ViewController.h"
#define FRAME_HISTORY 30
@interface ViewController ()
{
dispatch_semaphore_t _frameSemaphore;
CGPoint _startTouch;
bool _isTouching;
OSDRenderer* _osdRenderer;
MTKView* _view;
id<MTLDevice> _device;
id<MTLCommandQueue> _commandQueue;
double _frameTimes[FRAME_HISTORY];
uint64_t _currentFrame;
UIPanGestureRecognizer *_zoomGesture;
}
@end
@implementation ViewController
-(void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
_osdRenderer.camera->aspectRatio = size.width / size.height;
}
-(void)drawInMTKView:(MTKView *)view {
dispatch_semaphore_wait(_frameSemaphore, DISPATCH_TIME_FOREVER);
auto commandBuffer = [_commandQueue commandBuffer];
[_osdRenderer drawFrame:commandBuffer];
__weak auto blockSemaphore = _frameSemaphore;
unsigned frameIndex = _currentFrame % FRAME_HISTORY;
const auto beginTime = CACurrentMediaTime();
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> _Nonnull c) {
dispatch_semaphore_signal(blockSemaphore);
_frameTimes[frameIndex] = CACurrentMediaTime() - beginTime;
}];
[commandBuffer presentDrawable:_view.currentDrawable];
[commandBuffer commit];
_currentFrame++;
double frameAverage = 0;
for(auto& x : _frameTimes)
frameAverage += x;
frameAverage /= 30.0;
_frameTimeLabel.text = [NSString stringWithFormat:@"%0.2f ms", frameAverage * 1000.0];
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)viewDidLoad {
[super viewDidLoad];
_view = (MTKView*)self.view;
_frameSemaphore = dispatch_semaphore_create(3);
_device = MTLCreateSystemDefaultDevice();
_commandQueue = [_device newCommandQueue];
_view.device = _device;
_view.depthStencilPixelFormat = MTLPixelFormatDepth32Float;
_view.sampleCount = 2;
_view.frame = CGRectMake(0, 0, 1920, 1080);
_view.contentScaleFactor = 1;
_view.clearColor = MTLClearColorMake(0.4245, 0.4167, 0.4245, 1);
_osdRenderer = [[OSDRenderer alloc] initWithDelegate:self];
_view.delegate = self;
_zoomGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_zoomView)];
_zoomGesture.minimumNumberOfTouches = 2;
_zoomGesture.maximumNumberOfTouches = 2;
_zoomGesture.cancelsTouchesInView = true;
[_view addGestureRecognizer:_zoomGesture];
[self _applyOptions];
}
-(void)_applyOptions {
_osdRenderer.useSingleCrease = _singleCreaseSwitch.isOn;
_osdRenderer.usePatchBackfaceCulling = _backpatchCullingSwitch.isOn;
_osdRenderer.usePrimitiveBackfaceCulling = _backfaceCullingSwitch.isOn;
_osdRenderer.useScreenspaceTessellation = sender.isOn;
_osdRenderer.useFractionalTessellation = _osdRenderer.useScreenspaceTessellation;
_osdRenderer.displayStyle = _wireframeSwitch.isOn ? kDisplayStyleWireOnShaded : kDisplayStyleShaded;
_osdRenderer.usePatchClipCulling = _patchClipCullingSwitch.isOn;
_osdRenderer.useAdaptive = true;
_osdRenderer.freeze = true;
_osdRenderer.animateVertices = false;
_osdRenderer.kernelType = kMetal;
_osdRenderer.refinementLevel = _refinementStepper.value;
_osdRenderer.tessellationLevel = _tessellationStepper.value;
_osdRenderer.colorMode = (ColorMode)[_colorModePickerView selectedRowInComponent:0];
_osdRenderer.normalMode = (NormalMode)[_normalModePickerView selectedRowInComponent:0];
_osdRenderer.displacementMode = (DisplacementMode)[_displacementModePickerView selectedRowInComponent:0];
_osdRenderer.mipmapBias = _mipmapBiasSlider.value;
_osdRenderer.displacementScale = _displacementSlider.value;
_tesLvLlabel.text = [NSString stringWithFormat:@"Tes Lvl. %d", (int)_osdRenderer.tessellationLevel];
[_tesLvLlabel sizeToFit];
_refLvlLabel.text = [NSString stringWithFormat:@"Ref Lvl. %d", _osdRenderer.refinementLevel];
[_refLvlLabel sizeToFit];
}
-(void)_zoomView {
static float lastY = 0;
if(_zoomGesture.state == UIGestureRecognizerStateBegan) {
lastY = [_zoomGesture translationInView:_view].y;
} else if(_zoomGesture.state == UIGestureRecognizerStateChanged) {
const auto currentY = [_zoomGesture translationInView:_view].y;
const auto deltaY = (currentY - lastY) / 100.0;
lastY = currentY;
_osdRenderer.camera->dollyDistance += deltaY;
}
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
_isTouching = true;
_startTouch = [touches.anyObject locationInView:self.view];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
_isTouching = false;
[super touchesEnded:touches withEvent:event];
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if(_isTouching)
{
for(UITouch* touch in touches)
{
CGPoint location = [touch locationInView:self.view];
_startTouch = [touch previousLocationInView:self.view];
double deltaX = location.x - _startTouch.x;
double deltaY = location.y - _startTouch.y;
_osdRenderer.camera->rotationX += deltaX / 5.0;
_osdRenderer.camera->rotationY += deltaY / 5.0;
}
}
[super touchesMoved:touches withEvent:event];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(id<MTLDevice>)deviceFor:(OSDRenderer *)renderer {
return _device;
}
-(id<MTLCommandQueue>)commandQueueFor:(OSDRenderer *)renderer {
return _commandQueue;
}
-(MTLRenderPassDescriptor *)renderPassDescriptorFor:(OSDRenderer *)renderer {
return _view.currentRenderPassDescriptor;
}
-(void)setupDepthStencilState:(MTLDepthStencilDescriptor *)descriptor for:(OSDRenderer *)renderer {
}
-(void)setupRenderPipelineState:(MTLRenderPipelineDescriptor *)descriptor for:(OSDRenderer *)renderer {
descriptor.colorAttachments[0].pixelFormat = _view.colorPixelFormat;
descriptor.depthAttachmentPixelFormat = _view.depthStencilPixelFormat;
descriptor.sampleCount = _view.sampleCount;
}
- (IBAction)stepperChanged:(UIStepper *)sender {
if(sender == _tessellationStepper) {
_osdRenderer.tessellationLevel = sender.value;
_tesLvLlabel.text = [NSString stringWithFormat:@"Tes Lvl. %d", (int)_osdRenderer.tessellationLevel];
[_tesLvLlabel sizeToFit];
} else if (sender == _refinementStepper) {
_osdRenderer.refinementLevel = sender.value;
_refLvlLabel.text = [NSString stringWithFormat:@"Ref Lvl. %d", _osdRenderer.refinementLevel];
[_refLvlLabel sizeToFit];
}
}
- (IBAction)switchChanged:(UISwitch *)sender {
if(sender == _wireframeSwitch) {
_osdRenderer.displayStyle = _wireframeSwitch.isOn ? kDisplayStyleWireOnShaded : kDisplayStyleShaded;
} else if(sender == _backpatchCullingSwitch) {
_osdRenderer.usePatchBackfaceCulling = sender.isOn;
} else if(sender == _backfaceCullingSwitch) {
_osdRenderer.usePrimitiveBackfaceCulling = sender.isOn;
} else if(sender == _patchClipCullingSwitch) {
_osdRenderer.usePatchClipCulling = sender.isOn;
} else if(sender == _singleCreaseSwitch) {
_osdRenderer.useSingleCrease = sender.isOn;
} else if(sender == _screenspaceTessellationSwitch) {
_osdRenderer.useScreenspaceTessellation = sender.isOn;
_osdRenderer.useFractionalTessellation = _osdRenderer.useScreenspaceTessellation;
}
}
-(void)sliderChanged:(UISlider *)sender {
if(sender == _displacementSlider) {
_osdRenderer.displacementScale = sender.value;
} else if(sender == _mipmapBiasSlider) {
_osdRenderer.mipmapBias = sender.value;
}
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if(pickerView == _colorModePickerView) {
return 8;
} else if(pickerView == _normalModePickerView) {
return 5;
} else if(pickerView == _displacementModePickerView) {
return 4;
}
return 0;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if(pickerView == _colorModePickerView) {
switch(row) {
case kColorModePtexNearest: return @"Ptex Nearest";
case kColorModeNormal: return @"Normal";
case kColorModeNone: return @"None";
case kColorModePatchType: return @"Patch Type";
case kColorModePatchCoord: return @"Patch Coord";
case kColorModePtexBilinear: return @"Ptex Bilinear";
case kColorModePtexHWBilinear: return @"Ptex HW Bilinear";
case kColorModePtexBiQuadratic: return @"Ptex BiQuadratic";
}
} else if(pickerView == _normalModePickerView) {
switch(row) {
case kNormalModeSurface: return @"Surface";
case kNormalModeBiQuadratic: return @"BiQuadratic";
case kNormalModeScreenspace: return @"Screenspace";
case kNormalModeBiQuadraticWG: return @"BiQuadratic WG";
case kNormalModeHWScreenspace: return @"HW Screenspace";
}
} else if(pickerView == _displacementModePickerView) {
switch (row) {
case kDisplacementModeBilinear: return @"Bilinear";
case KDisplacementModeNone: return @"None";
case kDisplacementModeHWBilinear: return @"HW Bilinear";
case kDisplacementModeBiQuadratic: return @"BiQuadratic";
}
}
return @"";
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if(pickerView == _colorModePickerView) {
_osdRenderer.colorMode = (ColorMode)row;
} else if(pickerView == _normalModePickerView) {
_osdRenderer.normalMode = (NormalMode)row;
} else if(pickerView == _displacementModePickerView) {
_osdRenderer.displacementMode = (DisplacementMode)row;
}
}
@end

View File

@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

View File

@@ -0,0 +1,115 @@
//
// Copyright 2016 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#pragma once
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
typedef enum {
kCPU = 0,
kMetal,
} KernelType;
typedef enum {
kDisplacementModeHWBilinear = 0,
kDisplacementModeBilinear,
kDisplacementModeBiQuadratic,
kDisplacementModeNone
} DisplacementMode;
typedef enum {
kNormalModeHWScreenspace = 0,
kNormalModeScreenspace,
kNormalModeBiQuadratic,
kNormalModeBiQuadraticWG,
kNormalModeSurface
} NormalMode;
typedef enum {
kDisplayStyleWire = 0,
kDisplayStyleShaded,
kDisplayStyleWireOnShaded,
} DisplayStyle;
typedef enum {
kColorModePtexNearest = 0,
kColorModePtexBilinear,
kColorModePtexHWBilinear,
kColorModePtexBiQuadratic,
kColorModePatchType,
kColorModePatchCoord,
kColorModeNormal,
kColorModeNone
} ColorMode;
typedef struct {
float rotationX;
float rotationY;
float dollyDistance;
float aspectRatio;
} Camera;
@class OSDRenderer;
@protocol OSDRendererDelegate <NSObject>
-(id<MTLDevice>)deviceFor:(OSDRenderer*)renderer;
-(id<MTLCommandQueue>)commandQueueFor:(OSDRenderer*)renderer;
-(MTLRenderPassDescriptor*)renderPassDescriptorFor:(OSDRenderer*)renderer;
-(void)setupDepthStencilState:(MTLDepthStencilDescriptor*)descriptor for:(OSDRenderer*)renderer;
-(void)setupRenderPipelineState:(MTLRenderPipelineDescriptor*)descriptor for:(OSDRenderer*)renderer;
@end
@interface OSDRenderer : NSObject
-(instancetype)initWithDelegate:(id<OSDRendererDelegate>)delegate;
-(id<MTLRenderCommandEncoder>)drawFrame:(id<MTLCommandBuffer>)commandBuffer;
-(void)fitFrame;
@property (readonly, nonatomic) id<OSDRendererDelegate> delegate;
@property (nonatomic) unsigned refinementLevel;
@property (nonatomic) int tessellationLevel;
@property (readonly, nonatomic) Camera* camera;
@property (nonatomic) bool useSeamlessMipmap;
@property (nonatomic) bool useFractionalTessellation;
@property (nonatomic) bool useScreenspaceTessellation;
@property (nonatomic) bool usePatchIndexBuffer;
@property (nonatomic) bool usePatchBackfaceCulling;
@property (nonatomic) bool usePatchClipCulling;
@property (nonatomic) bool useSmoothCornerPatch;
@property (nonatomic) bool useSingleCreasePatch;
@property (nonatomic) bool useInfinitelySharpPatch;
@property (nonatomic) bool useStageIn;
@property (nonatomic) bool usePrimitiveBackfaceCulling;
@property (nonatomic) bool useAdaptive;
@property (nonatomic) bool freeze;
@property (nonatomic) bool animateVertices;
@property (nonatomic) bool displayControlMeshEdges;
@property (nonatomic) bool displayControlMeshVertices;
@property (nonatomic) bool displaySpecular;
@property (nonatomic) bool displayOcclusion;
@property (nonatomic) bool yup;
@property (nonatomic) float mipmapBias;
@property (nonatomic) float displacementScale;
@property (nonatomic) NSString* ptexColorFilename;
@property (nonatomic) NSString* ptexDisplacementFilename;
@property (nonatomic) NSString* ptexOcclusionFilename;
@property (nonatomic) NSString* ptexSpecularFilename;
@property (nonatomic) ColorMode colorMode;
@property (nonatomic) NormalMode normalMode;
@property (nonatomic) DisplacementMode displacementMode;
@property (nonatomic) DisplayStyle displayStyle;
@property (nonatomic) KernelType kernelType;
@end

View File

@@ -0,0 +1,700 @@
#line 0 "examples/mtlPtexViewer/mtlPtexViewer.metal"
//
// Copyright 2013-2019 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
#include <metal_stdlib>
using namespace metal;
#if OSD_IS_ADAPTIVE
static_assert(!OSD_ENABLE_SCREENSPACE_TESSELLATION || !USE_PTVS_FACTORS, "USE_PTVS_FACTORS cannot be enabled if OSD_ENABLE_SCREENSPACE_TESSELLATION is enabled");
#endif
struct Config {
float displacementScale;
float mipmapBias;
};
struct PerFrameConstants {
float4x4 ModelViewMatrix;
float4x4 ProjectionMatrix;
float4x4 ModelViewProjectionMatrix;
float4x4 ModelViewInverseMatrix;
float TessLevel;
};
// ---------------------------------------------------------------------------
const constant float4 patchColors[] = {
float4(1.0f, 1.0f, 1.0f, 1.0f), // regular
float4(0.0f, 1.0f, 1.0f, 1.0f), // regular pattern 0
float4(0.0f, 0.5f, 1.0f, 1.0f), // regular pattern 1
float4(0.0f, 0.5f, 0.5f, 1.0f), // regular pattern 2
float4(0.5f, 0.0f, 1.0f, 1.0f), // regular pattern 3
float4(1.0f, 0.5f, 1.0f, 1.0f), // regular pattern 4
float4(1.0f, 0.5f, 0.5f, 1.0f), // single crease
float4(1.0f, 0.70f, 0.6f, 1.0f), // single crease pattern 0
float4(1.0f, 0.65f, 0.6f, 1.0f), // single crease pattern 1
float4(1.0f, 0.60f, 0.6f, 1.0f), // single crease pattern 2
float4(1.0f, 0.55f, 0.6f, 1.0f), // single crease pattern 3
float4(1.0f, 0.50f, 0.6f, 1.0f), // single crease pattern 4
float4(0.8f, 0.0f, 0.0f, 1.0f), // boundary
float4(0.0f, 0.0f, 0.75f, 1.0f), // boundary pattern 0
float4(0.0f, 0.2f, 0.75f, 1.0f), // boundary pattern 1
float4(0.0f, 0.4f, 0.75f, 1.0f), // boundary pattern 2
float4(0.0f, 0.6f, 0.75f, 1.0f), // boundary pattern 3
float4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4
float4(0.0f, 1.0f, 0.0f, 1.0f), // corner
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
float4(1.0f, 0.7f, 0.3f, 1.0f) // gregory basis
};
float4
getAdaptivePatchColor(int3 patchParam, float sharpness)
{
int patchType = 0;
int edgeCount = popcount(OsdGetPatchBoundaryMask(patchParam));
if (edgeCount == 1) {
patchType = 2; // BOUNDARY
}
if (edgeCount > 1) {
patchType = 3; // CORNER
}
#if OSD_PATCH_ENABLE_SINGLE_CREASE
if (sharpness > 0) {
patchType = 1;
}
#elif OSD_PATCH_GREGORY
patchType = 4;
#elif OSD_PATCH_GREGORY_BOUNDARY
patchType = 5;
#elif OSD_PATCH_GREGORY_BASIS
patchType = 6;
#elif OSD_PATCH_GREGORY_TRIANGLE
patchType = 6;
#endif
int pattern = popcount(OsdGetPatchTransitionMask(patchParam));
return patchColors[6*patchType + pattern];
}
#if DISPLACEMENT_HW_BILINEAR \
|| DISPLACEMENT_BILINEAR \
|| DISPLACEMENT_BIQUADRATIC \
|| NORMAL_HW_SCREENSPACE \
|| NORMAL_SCREENSPACE \
|| NORMAL_BIQUADRATIC \
|| NORMAL_BIQUADRATIC_WG
#define USE_DISPLACEMENT_RESOURCES 1
#endif
#if DISPLACEMENT_HW_BILINEAR \
|| DISPLACEMENT_BILINEAR \
|| DISPLACEMENT_BIQUADRATIC
#define USE_DISPLACEMENT 1
#undef OSD_DISPLACEMENT_CALLBACK
#define OSD_DISPLACEMENT_CALLBACK \
float3 displacement(float3 position, float3 normal, float4 patchCoord, float mipmapBias, float displacementScale
#if USE_DISPLACEMENT_RESOURCES
,texture2d_array<float, access::sample> textureDisplace_Data
,device ushort* textureDisplace_Packing
#endif
)
{
#if DISPLACEMENT_HW_BILINEAR
float disp = PtexLookupFast(patchCoord, mipmapBias,
textureDisplace_Data,
textureDisplace_Packing).x;
#elif DISPLACEMENT_BILINEAR
float disp = PtexMipmapLookup(patchCoord, mipmapBias,
textureDisplace_Data,
textureDisplace_Packing).x;
#elif DISPLACEMENT_BIQUADRATIC
float disp = PtexMipmapLookupQuadratic(patchCoord, mipmapBias,
textureDisplace_Data,
textureDisplace_Packing).x;
#else
float disp(0);
#endif
return position + disp*normal * displacementScale;
}
#endif
float4 GeneratePatchCoord(float2 uv, int3 patchParam) // for non-adaptive
{
return OsdInterpolatePatchCoord(uv, patchParam);
}
#if NORMAL_HW_SCREENSPACE || NORMAL_SCREENSPACE
float3
perturbNormalFromDisplacement(float3 position, float3 normal, float4 patchCoord, float mipmapBias
,texture2d_array<float, access::sample> textureDisplace_Data
,device ushort* textureDisplace_Packing
,float displacementScale)
{
// by Morten S. Mikkelsen
// http://jbit.net/~sparky/sfgrad_bump/mm_sfgrad_bump.pdf
// slightly modified for ptex guttering
float3 vSigmaS = dfdx(position);
float3 vSigmaT = dfdy(position);
float3 vN = normal;
float3 vR1 = cross(vSigmaT, vN);
float3 vR2 = cross(vN, vSigmaS);
float fDet = dot(vSigmaS, vR1);
#if 0
// not work well with ptex
float dBs = dfdx(disp);
float dBt = dfdy(disp);
#else
float2 texDx = dfdx(patchCoord.xy);
float2 texDy = dfdy(patchCoord.xy);
// limit forward differencing to the width of ptex gutter
const float resolution = 128.0;
float d = min(1.0f, (0.5/resolution)/max(length(texDx), length(texDy)));
float4 STll = patchCoord;
float4 STlr = patchCoord + d * float4(texDx.x, texDx.y, 0, 0);
float4 STul = patchCoord + d * float4(texDy.x, texDy.y, 0, 0);
#if NORMAL_HW_SCREENSPACE
float Hll = PtexLookupFast(STll, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
float Hlr = PtexLookupFast(STlr, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
float Hul = PtexLookupFast(STul, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
#elif NORMAL_SCREENSPACE
float Hll = PtexMipmapLookup(STll, mipmapBias, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
float Hlr = PtexMipmapLookup(STlr, mipmapBias, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
float Hul = PtexMipmapLookup(STul, mipmapBias, textureDisplace_Data, textureDisplace_Packing).x * displacementScale;
#endif
float dBs = (Hlr - Hll)/d;
float dBt = (Hul - Hll)/d;
#endif
float3 vSurfGrad = sign(fDet) * (dBs * vR1 + dBt * vR2);
return normalize(abs(fDet) * vN - vSurfGrad);
}
#endif // NORMAL_SCREENSPACE
// ---------------------------------------------------------------------------
// Vertex Shader
// ---------------------------------------------------------------------------
struct FragmentInput
{
float4 positionOut [[position]];
float3 position;
float3 normal;
float3 tangent;
float3 bitangent;
float4 patchCoord;
#if COLOR_PATCHTYPE
float4 patchColor;
#endif
#if OSD_COMPUTE_NORMAL_DERIVATIVES
float3 Nu;
float3 Nv;
#endif
};
#if OSD_IS_ADAPTIVE
#if USE_STAGE_IN
#if OSD_PATCH_REGULAR || OSD_PATCH_BOX_SPLINE_TRIANGLE
struct ControlPoint
{
float3 P [[attribute(0)]];
#if OSD_PATCH_ENABLE_SINGLE_CREASE
float3 P1 [[attribute(1)]];
float3 P2 [[attribute(2)]];
#if !USE_PTVS_SHARPNESS
float2 vSegments [[attribute(3)]];
#endif
#endif
};
#elif OSD_PATCH_GREGORY || OSD_PATCH_GREGORY_BOUNDARY
struct ControlPoint
{
float3 P [[attribute(0)]];
float3 Ep [[attribute(1)]];
float3 Em [[attribute(2)]];
float3 Fp [[attribute(3)]];
float3 Fm [[attribute(4)]];
};
#elif OSD_PATCH_GREGORY_BASIS || OSD_PATCH_GREGORY_TRIANGLE
struct ControlPoint
{
float3 position [[attribute(0)]];
};
#endif
struct PatchInput
{
patch_control_point<ControlPoint> cv;
#if !USE_PTVS_FACTORS
float4 tessOuterLo [[attribute(5)]];
float4 tessOuterHi [[attribute(6)]];
#endif
int3 patchParam [[attribute(10)]];
};
#endif
#if OSD_PATCH_REGULAR || OSD_PATCH_GREGORY_BASIS || OSD_PATCH_GREGORY || OSD_PATCH_GREGORY_BOUNDARY
typedef MTLQuadTessellationFactorsHalf PatchTessFactors;
#elif OSD_PATCH_BOX_SPLINE_TRIANGLE || OSD_PATCH_GREGORY_TRIANGLE
typedef MTLTriangleTessellationFactorsHalf PatchTessFactors;
#endif
kernel void compute_main(
const constant PerFrameConstants& frameConsts [[buffer(FRAME_CONST_BUFFER_INDEX)]],
unsigned thread_position_in_grid [[thread_position_in_grid]],
unsigned thread_position_in_threadgroup [[thread_position_in_threadgroup]],
unsigned threadgroup_position_in_grid [[threadgroup_position_in_grid]],
OsdPatchParamBufferSet osdBuffers,
device PatchTessFactors* patchTessellationFactors [[buffer(PATCH_TESSFACTORS_INDEX)]]
#if OSD_USE_PATCH_INDEX_BUFFER
,device unsigned* patchIndex [[buffer(OSD_PATCH_INDEX_BUFFER_INDEX)]]
,device MTLDrawPatchIndirectArguments* drawIndirectCommands [[buffer(OSD_DRAWINDIRECT_BUFFER_INDEX)]]
#endif
)
{
//----------------------------------------------------------
// OSD Kernel Setup
//----------------------------------------------------------
#define PATCHES_PER_THREADGROUP (THREADS_PER_THREADGROUP / THREADS_PER_PATCH)
int const primitiveID = thread_position_in_grid / THREADS_PER_PATCH;
int const primitiveIDInTG = thread_position_in_threadgroup / THREADS_PER_PATCH;
int const vertexIndex = threadgroup_position_in_grid * PATCHES_PER_THREADGROUP * CONTROL_POINTS_PER_PATCH +
thread_position_in_threadgroup * CONTROL_POINTS_PER_THREAD;
int const vertexIndexInTG = thread_position_in_threadgroup * CONTROL_POINTS_PER_THREAD;
int const invocationID = (thread_position_in_threadgroup * VERTEX_CONTROL_POINTS_PER_THREAD) % (THREADS_PER_PATCH*VERTEX_CONTROL_POINTS_PER_THREAD);
//Contains the shared patchParam value used by all threads that act upon a single patch
//the .z (sharpness) field is set to -1 (NAN) if that patch should be culled to signal other threads to return.
threadgroup int3 patchParam[PATCHES_PER_THREADGROUP];
threadgroup PatchVertexType patchVertices[PATCHES_PER_THREADGROUP * CONTROL_POINTS_PER_PATCH];
//----------------------------------------------------------
// OSD Vertex Transform
//----------------------------------------------------------
{
patchParam[primitiveIDInTG] = OsdGetPatchParam(primitiveID, osdBuffers.patchParamBuffer);
for (unsigned threadOffset = 0; threadOffset < CONTROL_POINTS_PER_THREAD; ++threadOffset)
{
if (vertexIndexInTG + threadOffset < PATCHES_PER_THREADGROUP * CONTROL_POINTS_PER_PATCH)
{
const auto vertexId = osdBuffers.indexBuffer[(vertexIndex + threadOffset)];
const auto v = osdBuffers.vertexBuffer[vertexId];
threadgroup auto& patchVertex = patchVertices[vertexIndexInTG + threadOffset];
//----------------------------------------------------------
// User Vertex Transform
//----------------------------------------------------------
OsdComputePerVertex(float4(v.position,1), patchVertex, vertexId, frameConsts.ModelViewProjectionMatrix, osdBuffers);
}
}
}
#if NEEDS_BARRIER
threadgroup_barrier(mem_flags::mem_threadgroup);
#endif
//----------------------------------------------------------
// OSD Patch Cull
//----------------------------------------------------------
{
auto patch = patchVertices + primitiveIDInTG * CONTROL_POINTS_PER_PATCH;
if (!OsdCullPerPatchVertex(patch, frameConsts.ModelViewMatrix))
{
#if !OSD_USE_PATCH_INDEX_BUFFER
#if OSD_PATCH_REGULAR || OSD_PATCH_GREGORY_BASIS || OSD_PATCH_GREGORY || OSD_PATCH_GREGORY_BOUNDARY
patchTessellationFactors[primitiveID].edgeTessellationFactor[0] = 0.0h;
patchTessellationFactors[primitiveID].edgeTessellationFactor[1] = 0.0h;
patchTessellationFactors[primitiveID].edgeTessellationFactor[2] = 0.0h;
patchTessellationFactors[primitiveID].edgeTessellationFactor[3] = 0.0h;
patchTessellationFactors[primitiveID].insideTessellationFactor[0] = 0.0h;
patchTessellationFactors[primitiveID].insideTessellationFactor[1] = 0.0h;
#elif OSD_PATCH_BOX_SPLINE_TRIANGLE || OSD_PATCH_GREGORY_TRIANGLE
patchTessellationFactors[primitiveID].edgeTessellationFactor[0] = 0.0h;
patchTessellationFactors[primitiveID].edgeTessellationFactor[1] = 0.0h;
patchTessellationFactors[primitiveID].edgeTessellationFactor[2] = 0.0h;
patchTessellationFactors[primitiveID].insideTessellationFactor = 0.0h;
#endif
#endif
patchParam[primitiveIDInTG].z = -1;
#if !NEEDS_BARRIER
return;
#endif
}
}
#if NEEDS_BARRIER
threadgroup_barrier(mem_flags::mem_threadgroup);
#endif
//----------------------------------------------------------
// OSD Patch Compute
//----------------------------------------------------------
if (patchParam[primitiveIDInTG].z != -1)
{
for (unsigned threadOffset = 0; threadOffset < VERTEX_CONTROL_POINTS_PER_THREAD; ++threadOffset)
{
if (invocationID + threadOffset < VERTEX_CONTROL_POINTS_PER_PATCH)
{
OsdComputePerPatchVertex(
patchParam[primitiveIDInTG],
invocationID + threadOffset,
primitiveID,
invocationID + threadOffset + primitiveID * VERTEX_CONTROL_POINTS_PER_PATCH,
patchVertices + primitiveIDInTG * CONTROL_POINTS_PER_PATCH,
osdBuffers
);
}
}
}
#if NEEDS_BARRIER
threadgroup_barrier(mem_flags::mem_device_and_threadgroup);
#endif
//----------------------------------------------------------
// OSD Tessellation Factors
//----------------------------------------------------------
if (invocationID == 0)
{
#if OSD_USE_PATCH_INDEX_BUFFER
const auto patchId = atomic_fetch_add_explicit((device atomic_uint*)&drawIndirectCommands->patchCount, 1, memory_order_relaxed);
patchIndex[patchId] = primitiveID;
#else
const auto patchId = primitiveID;
#endif
OsdComputePerPatchFactors(
patchParam[primitiveIDInTG],
frameConsts.TessLevel,
primitiveID,
frameConsts.ProjectionMatrix,
frameConsts.ModelViewMatrix,
osdBuffers,
patchVertices + primitiveIDInTG * CONTROL_POINTS_PER_PATCH,
patchTessellationFactors[patchId]
);
}
}
[[patch(quad, VERTEX_CONTROL_POINTS_PER_PATCH)]]
vertex FragmentInput vertex_main(
const constant Config& config [[buffer(CONFIG_BUFFER_INDEX)]],
const constant PerFrameConstants& frameConsts [[buffer(FRAME_CONST_BUFFER_INDEX)]],
#if USE_STAGE_IN
const PatchInput patchInput [[stage_in]],
#else
const OsdVertexBufferSet patchInput,
#endif
float2 position_in_patch [[position_in_patch]],
uint patch_id [[patch_id]]
#if USE_DISPLACEMENT_RESOURCES
,texture2d_array<float, access::sample> textureDisplace_Data [[texture(DISPLACEMENT_TEXTURE_INDEX)]]
,device ushort* textureDisplace_Packing [[buffer(DISPLACEMENT_BUFFER_INDEX)]]
#endif
)
{
FragmentInput out;
#if USE_STAGE_IN
int3 patchParam = patchInput.patchParam;
#else
int3 patchParam = patchInput.patchParamBuffer[patch_id];
#endif
int refinementLevel = OsdGetPatchRefinementLevel(patchParam);
float tessLevel = min(frameConsts.TessLevel, (float)OSD_MAX_TESS_LEVEL) /
exp2((float)refinementLevel - 1);
auto patchVertex = OsdComputePatch(tessLevel, position_in_patch, patch_id, patchInput);
#if USE_DISPLACEMENT
float3 position = displacement(patchVertex.position,
patchVertex.normal,
patchVertex.patchCoord,
config.mipmapBias,
config.displacementScale
#if USE_DISPLACEMENT_RESOURCES
,textureDisplace_Data, textureDisplace_Packing
#endif
);
#else
float3 position = patchVertex.position;
#endif
out.positionOut = mul(frameConsts.ModelViewProjectionMatrix, float4(position, 1));
out.position = mul(frameConsts.ModelViewMatrix, float4(position,1)).xyz;
out.normal = mul(frameConsts.ModelViewMatrix,float4(patchVertex.normal, 0)).xyz;
out.tangent = mul(frameConsts.ModelViewMatrix,float4(patchVertex.tangent,0)).xyz;
out.bitangent = mul(frameConsts.ModelViewMatrix,float4(patchVertex.bitangent,0)).xyz;
out.patchCoord = patchVertex.patchCoord;
#if COLOR_PATCHTYPE
out.patchColor = getAdaptivePatchColor(patchParam, OsdGetPatchSharpness(patchParam));
#endif
#if OSD_COMPUTE_NORMAL_DERIVATIVES
out.Nu = mul(frameConsts.ModelViewMatrix, float4(patchVertex.Nu, 0)).xyz;
out.Nv = mul(frameConsts.ModelViewMatrix, float4(patchVertex.Nv, 0)).xyz;
#endif
return out;
}
#endif
const constant float VIEWPORT_SCALE = 1024.0; // XXXdyu
// ---------------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------------
#define NUM_LIGHTS 1
struct LightSource {
float4 position;
float4 ambient;
float4 diffuse;
float4 specular;
};
float4
lighting(float4 texColor, float3 Peye, float3 Neye, float occ, const constant LightSource (&lightSource)[NUM_LIGHTS])
{
float4 color = float4(0.0, 0.0, 0.0, 0.0);
float3 n = Neye;
for (int i = 0; i < NUM_LIGHTS; ++i) {
float4 Plight = lightSource[i].position;
float3 l = (Plight.w == 0.0)
? normalize(Plight.xyz) : normalize(Plight.xyz - Peye);
float3 h = normalize(l + float3(0,0,1)); // directional viewer
float d = max(0.0, dot(n, l));
float s = pow(max(0.0, dot(n, h)), 64.0f);
color += (1.0 - occ) * ((lightSource[i].ambient +
d * lightSource[i].diffuse) * texColor +
s * lightSource[i].specular);
}
color.a = 1.0;
return color;
}
// ---------------------------------------------------------------------------
// Pixel Shader
// ---------------------------------------------------------------------------
float4
edgeColor(float4 Cfill, float4 edgeDistance)
{
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
#ifdef PRIM_TRI
float d =
min(edgeDistance[0], min(edgeDistance[1], edgeDistance[2]));
#endif
#ifdef PRIM_QUAD
float d =
min(min(edgeDistance[0], edgeDistance[1]),
min(edgeDistance[2], edgeDistance[3]));
#endif
float4 Cedge = float4(1.0, 1.0, 0.0, 1.0);
float p = exp2(-2 * d * d);
#if defined(GEOMETRY_OUT_WIRE)
if (p < 0.25) discard;
#endif
Cfill.rgb = lerp(Cfill.rgb, Cedge.rgb, p);
#endif
return Cfill;
}
// ---------------------------------------------------------------------------
// Pixel Shader
// ---------------------------------------------------------------------------
#if COLOR_PTEX_NEAREST || \
COLOR_PTEX_HW_BILINEAR || \
COLOR_PTEX_BILINEAR || \
COLOR_PTEX_BIQUADRATIC
#define USE_IMAGE_RESOURCES 1
#endif
#if USE_PTEX_OCCLUSION
#define USE_OCCLUSION_RESOURCES 1
#endif
#if USE_PTEX_SPECULAR
#define USE_SPECULAR_RESOURCES 1
#endif
fragment float4 fragment_main(
FragmentInput input [[stage_in]]
#if USE_DISPLACEMENT_RESOURCES
,texture2d_array<float, access::sample> textureDisplace_Data [[texture(DISPLACEMENT_TEXTURE_INDEX)]]
,device ushort* textureDisplace_Packing [[buffer(DISPLACEMENT_BUFFER_INDEX)]]
#endif
#if USE_IMAGE_RESOURCES
,texture2d_array<float, access::sample> textureImage_Data [[texture(IMAGE_TEXTURE_INDEX)]]
,device ushort* textureImage_Packing [[buffer(IMAGE_BUFFER_INDEX)]]
#endif
#if USE_OCCLUSION_RESOURCES
,texture2d_array<float, access::sample> textureOcclusion_Data [[texture(OCCLUSION_TEXTURE_INDEX)]]
,device ushort* textureOcclusion_Packing [[buffer(OCCLUSION_BUFFER_INDEX)]]
#endif
#if USE_SPECULAR_RESOURCES
,texture2d_array<float, acess::read> textureSpecular_Data [[texture(SPECULAR_TEXTURE_INDEX)]]
,device ushort* textureSpecular_Packing [[buffer(SPECULAR_BUFFER_INDEX)]]
#endif
,const constant LightSource (&lightSource [[buffer(0)]]) [NUM_LIGHTS]
,const constant Config& config [[buffer(1)]]
,const constant float4& shade [[buffer(2)]]
)
{
const auto displacementScale = config.displacementScale;
const auto mipmapBias = config.mipmapBias;
float4 outColor;
// ------------ normal ---------------
#if NORMAL_HW_SCREENSPACE || NORMAL_SCREENSPACE
float3 normal = perturbNormalFromDisplacement(input.position.xyz,
input.normal,
input.patchCoord,
mipmapBias,
textureDisplace_Data,
textureDisplace_Packing,
displacementScale);
#elif NORMAL_BIQUADRATIC || NORMAL_BIQUADRATIC_WG
float4 du, dv;
float4 disp = PtexMipmapLookupQuadratic(du, dv, input.patchCoord,
mipmapBias,
textureDisplace_Data,
textureDisplace_Packing);
disp *= displacementScale;
du *= displacementScale;
dv *= displacementScale;
float3 n = normalize(cross(input.tangent, input.bitangent));
float3 tangent = input.tangent + n * du.x;
float3 bitangent = input.bitangent + n * dv.x;
#if NORMAL_BIQUADRATIC_WG
tangent += input.Nu * disp.x;
bitangent += input.Nv * disp.x;
#endif
float3 normal = normalize(cross(tangent, bitangent));
#else
float3 normal = input.normal;
#endif
// ------------ color ---------------
#if COLOR_PTEX_NEAREST
float4 texColor = PtexLookupNearest(input.patchCoord,
textureImage_Data,
textureImage_Packing);
#elif COLOR_PTEX_HW_BILINEAR
float4 texColor = PtexLookupFast(input.patchCoord,
textureImage_Data,
textureImage_Packing);
#elif COLOR_PTEX_BILINEAR
float4 texColor = PtexMipmapLookup(input.patchCoord, mipmapBias,
textureImage_Data,
textureImage_Packing);
#elif COLOR_PTEX_BIQUADRATIC
float4 texColor = PtexMipmapLookupQuadratic(input.patchCoord, mipmapBias,
textureImage_Data,
textureImage_Packing);
#elif COLOR_PATCHTYPE
float4 texColor = lighting(float4(input.patchColor), input.position.xyz, normal, 0, lightSource);
outColor = max(texColor, shade);
return outColor;
#elif COLOR_PATCHCOORD
float4 texColor = lighting(input.patchCoord, input.position.xyz, normal, 0, lightSource);
outColor = max(texColor, shade);
return outColor;
#elif COLOR_NORMAL
float4 texColor = float4(normal.x, normal.y, normal.z, 1);
outColor = max(texColor, shade);
return outColor;
#else // COLOR_NONE
float4 texColor = float4(0.5, 0.5, 0.5, 1);
#endif
// ------------ occlusion ---------------
#if USE_PTEX_OCCLUSION
float occ = PtexMipmapLookup(input.patchCoord, mipmapBias,
textureOcclusion_Data,
textureOcclusion_Packing).x;
#else
float occ = 0.0;
#endif
// ------------ specular ---------------
#if USE_PTEX_SPECULAR
float specular = PtexMipmapLookup(input.patchCoord, mipmapBias,
textureSpecular_Data,
textureSpecular_Packing).x;
#else
float specular = 1.0;
#endif
// ------------ lighting ---------------
float4 Cf = lighting(texColor, input.position.xyz, normal, occ, lightSource);
// ------------ wireframe ---------------
outColor = max(Cf, shade);
return outColor;
}

File diff suppressed because it is too large Load Diff