Skip to content

Commit 0b943b5

Browse files
committed
Add opt-in Dawn and MetalANGLE backends
Default windows stay desktop OpenGL and iOS GLES. OF_USE_DAWN=1 selects a WebGPU renderer on a CAMetalLayer (ofAppDawnWindow on macOS, ofxiOSDawnView on iOS) and draws the graphicsExample shapes. OF_USE_ANGLE=1 selects iOS MetalANGLE + MGLKit for OpenGL ES 1.1, 2.0, and 3.0. The two flags cannot both be set, and neither library is on the default link line. graphicsExample screenshots from the local macOS and iOS simulator runs are in screenshots/gles-matrix/.
1 parent 04d2e08 commit 0b943b5

39 files changed

Lines changed: 2333 additions & 7 deletions

‎addons/ofxiOS/src/app/ofAppiOSWindow.mm‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
#endif
4646
#include "ofxiOSGLKView.h"
4747
#include "ofxiOSEAGLView.h"
48+
#if OF_USE_DAWN
49+
#include "ofWebGPURenderer.h"
50+
#include "ofxiOSDawnView.h"
51+
#elif OF_USE_ANGLE
52+
#include "ofxiOSMGLView.h"
53+
#endif
4854

4955
//----------------------------------------------------------------------------------- instance.
5056
static ofAppiOSWindow * _instance = NULL;
@@ -106,11 +112,23 @@
106112
settings.setupOrientation = OF_ORIENTATION_DEFAULT;
107113
}
108114
setOrientation(settings.setupOrientation);
115+
#if OF_USE_DAWN
116+
currentRenderer = std::shared_ptr<ofBaseRenderer>(new ofWebGPURenderer(this));
117+
settings.windowControllerType = ofxiOSWindowControllerType::DAWN_KIT;
118+
#elif OF_USE_ANGLE
119+
if(settings.glesVersion >= ESRendererVersion_20) {
120+
currentRenderer = std::shared_ptr<ofBaseRenderer>(new ofGLProgrammableRenderer(this));
121+
} else {
122+
currentRenderer = std::shared_ptr<ofBaseRenderer>(new ofGLRenderer(this));
123+
}
124+
settings.windowControllerType = ofxiOSWindowControllerType::ANGLE_KIT;
125+
#else
109126
if(settings.glesVersion >= ESRendererVersion_20) {
110127
currentRenderer = std::shared_ptr<ofBaseRenderer>(new ofGLProgrammableRenderer(this));
111128
} else {
112129
currentRenderer = std::shared_ptr<ofBaseRenderer>(new ofGLRenderer(this));
113130
}
131+
#endif
114132

115133
hasExited = false;
116134
}
@@ -170,20 +188,41 @@
170188
glm::vec2 ofAppiOSWindow::getWindowPosition() {
171189
if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT)
172190
return *[[ofxiOSGLKView getInstance] getWindowPosition];
191+
#if OF_USE_DAWN
192+
else if(settings.windowControllerType == DAWN_KIT && [ofxiOSDawnView getInstance])
193+
return *[[ofxiOSDawnView getInstance] getWindowPosition];
194+
#elif OF_USE_ANGLE
195+
else if(settings.windowControllerType == ANGLE_KIT && [ofxiOSMGLViewController getInstance])
196+
return *[[ofxiOSMGLViewController getInstance] getWindowPosition];
197+
#endif
173198
else
174199
return *[[ofxiOSEAGLView getInstance] getWindowPosition];
175200
}
176201

177202
glm::vec2 ofAppiOSWindow::getWindowSize() {
178203
if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT)
179204
return *[[ofxiOSGLKView getInstance] getWindowSize];
205+
#if OF_USE_DAWN
206+
else if(settings.windowControllerType == DAWN_KIT && [ofxiOSDawnView getInstance])
207+
return *[[ofxiOSDawnView getInstance] getWindowSize];
208+
#elif OF_USE_ANGLE
209+
else if(settings.windowControllerType == ANGLE_KIT && [ofxiOSMGLViewController getInstance])
210+
return *[[ofxiOSMGLViewController getInstance] getWindowSize];
211+
#endif
180212
else
181213
return *[[ofxiOSEAGLView getInstance] getWindowSize];
182214
}
183215

184216
glm::vec2 ofAppiOSWindow::getScreenSize() {
185217
if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT)
186218
return *[[ofxiOSGLKView getInstance] getScreenSize];
219+
#if OF_USE_DAWN
220+
else if(settings.windowControllerType == DAWN_KIT && [ofxiOSDawnView getInstance])
221+
return *[[ofxiOSDawnView getInstance] getScreenSize];
222+
#elif OF_USE_ANGLE
223+
else if(settings.windowControllerType == ANGLE_KIT && [ofxiOSMGLViewController getInstance])
224+
return *[[ofxiOSMGLViewController getInstance] getScreenSize];
225+
#endif
187226
else
188227
return *[[ofxiOSEAGLView getInstance] getScreenSize];
189228
}

‎addons/ofxiOS/src/core/ofxiOSAppDelegate.mm‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "ofxiOSExtras.h"
3939
#include "ofxiOSAlerts.h"
4040
#include "ofxiOSEAGLView.h"
41+
#if OF_USE_DAWN
42+
#include "ofxiOSDawnView.h"
43+
#elif OF_USE_ANGLE
44+
#include "ofxiOSMGLView.h"
45+
#endif
4146
#include "ofAppiOSWindow.h"
4247
#include "ofAppRunner.h"
4348
#include "ofUtils.h"
@@ -137,6 +142,15 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
137142
if ([appDelegateClassName isEqualToString:@"ofxiOSAppDelegate"]) { // app delegate is not being extended.
138143

139144
switch(ofxiOSGetOFWindow()->getWindowControllerType()) {
145+
#if OF_USE_DAWN
146+
case DAWN_KIT:
147+
self.uiViewController = [[ofxiOSDawnViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr()];
148+
break;
149+
#elif OF_USE_ANGLE
150+
case ANGLE_KIT:
151+
self.uiViewController = [[ofxiOSMGLViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr()];
152+
break;
153+
#endif
140154
case METAL_KIT:
141155
NSLog(@"No MetalKit yet supported for openFrameworks: Falling back to GLKit");
142156
case GL_KIT:
@@ -194,11 +208,15 @@ - (void)applicationWillResignActive:(UIApplication *)application {
194208
if(ofxiOSGetOFWindow()->getWindowControllerType() == CORE_ANIMATION)
195209
[ofxiOSGetGLView() stopAnimation];
196210
ofxiOSAlerts.lostFocus();
211+
#if !OF_USE_DAWN
197212
glFinish();
213+
#endif
198214
}
199215

200216
- (void)applicationDidEnterBackground:(UIApplication *)application {
217+
#if !OF_USE_DAWN
201218
glFinish();
219+
#endif
202220
}
203221

204222
- (void)applicationDidBecomeActive:(UIApplication *)application {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
#include "ofxiOSConstants.h"
3+
#if defined(TARGET_OF_IOS) && OF_USE_DAWN
4+
5+
#import <UIKit/UIKit.h>
6+
#include "ofConstants.h"
7+
#include <glm/vec2.hpp>
8+
9+
class ofxiOSApp;
10+
class ofAppiOSWindow;
11+
12+
@interface ofxiOSDawnView : UIView
13+
+ (ofxiOSDawnView *)getInstance;
14+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app;
15+
- (void *)metalLayer;
16+
- (glm::vec2 *)getWindowPosition;
17+
- (glm::vec2 *)getWindowSize;
18+
- (glm::vec2 *)getScreenSize;
19+
- (void)startRender;
20+
- (void)finishRender;
21+
@end
22+
23+
@interface ofxiOSDawnViewController : UIViewController
24+
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app;
25+
@property (nonatomic, strong) ofxiOSDawnView * dawnView;
26+
@end
27+
28+
#endif

0 commit comments

Comments
 (0)