testing iOS multithread rendering

This commit is contained in:
2019-03-01 10:07:54 +01:00
parent 44ca908c6d
commit 8cd02787b3
4 changed files with 67 additions and 52 deletions

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13156.6" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13137.5"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
@@ -17,7 +17,7 @@
<viewControllerLayoutGuide type="top" id="8aa-yV-Osq"/> <viewControllerLayoutGuide type="top" id="8aa-yV-Osq"/>
<viewControllerLayoutGuide type="bottom" id="qHh-Mt-9TT"/> <viewControllerLayoutGuide type="bottom" id="qHh-Mt-9TT"/>
</layoutGuides> </layoutGuides>
<view key="view" contentMode="scaleToFill" id="3se-qz-xqx" customClass="GLKView"> <view key="view" contentMode="scaleToFill" id="3se-qz-xqx" customClass="GameView">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>

View File

@@ -10,14 +10,17 @@
#import <GLKit/GLKit.h> #import <GLKit/GLKit.h>
#import "AppDelegate.h" #import "AppDelegate.h"
@interface GameViewController : GLKViewController< @interface GameView : GLKView
@end
@interface GameViewController : UIViewController<
UIKeyInput, UIKeyInput,
UIImagePickerControllerDelegate, UIImagePickerControllerDelegate,
UINavigationControllerDelegate, UINavigationControllerDelegate,
UIDocumentInteractionControllerDelegate UIDocumentInteractionControllerDelegate
> >
{ {
@public GLKView* glview; @public GameView* glview;
} }
- (void)display_file:(std::string)filename; - (void)display_file:(std::string)filename;
- (void)reset_touch; - (void)reset_touch;

View File

@@ -55,7 +55,7 @@ std::recursive_mutex lock_mutex;
// lock_thread = [NSThread currentThread]; // lock_thread = [NSThread currentThread];
// lock_count++; // lock_count++;
[EAGLContext setCurrentContext:self.context]; [EAGLContext setCurrentContext:self.context];
GLKView* view = (GLKView*)self.view; GameView* view = (GameView*)self.view;
[view bindDrawable]; [view bindDrawable];
} }
- (void)async_unlock - (void)async_unlock
@@ -194,7 +194,7 @@ std::recursive_mutex lock_mutex;
NSDictionary* info = [aNotification userInfo]; NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
GLKView *view = (GLKView *)self.view; GameView *view = (GameView *)self.view;
CGRect frame = view.frame; CGRect frame = view.frame;
frame.size.height -= kbSize.height; frame.size.height -= kbSize.height;
view.frame = frame; view.frame = frame;
@@ -380,7 +380,7 @@ std::set<UITouch*> ignored_touch;
App::I.initLog(); App::I.initLog();
App::I.ios_view = self; App::I.ios_view = self;
self.preferredFramesPerSecond = 60; //self.preferredFramesPerSecond = 60;
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (!self.context) { if (!self.context) {
@@ -389,9 +389,10 @@ std::set<UITouch*> ignored_touch;
gl_lock = [[NSLock alloc] init]; gl_lock = [[NSLock alloc] init];
GLKView *view = (GLKView *)self.view; GameView *view = (GameView *)self.view;
view.context = self.context; view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24; view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.enableSetNeedsDisplay = NO;
glview = view; glview = view;
App::I.width = view.frame.size.width * view.contentScaleFactor; App::I.width = view.frame.size.width * view.contentScaleFactor;
@@ -433,25 +434,27 @@ std::set<UITouch*> ignored_touch;
- (void)setupGL - (void)setupGL
{ {
[EAGLContext setCurrentContext:self.context]; [self async_lock];
App::I.init(); App::I.init();
} [self async_unlock];
- (void)tearDownGL std::thread([self]{
{ while (true)
[EAGLContext setCurrentContext:self.context];
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{ {
static auto time = std::chrono::steady_clock::now(); static auto time = std::chrono::steady_clock::now();
static double elapsed = 0; static double elapsed = 0;
static double min_fps_timer = 0;
auto now = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now();
auto dt = std::chrono::duration<float>(now - time); auto dt = std::chrono::duration<float>(now - time);
time = now; time = now;
elapsed += dt.count(); elapsed += dt.count();
min_fps_timer += dt.count();
if (min_fps_timer > 0.1)
{
App::I.redraw = true;
min_fps_timer = 0;
}
std::deque<std::packaged_task<void()>> working_list; std::deque<std::packaged_task<void()>> working_list;
if (!tasklist.empty()) if (!tasklist.empty())
@@ -465,9 +468,10 @@ std::set<UITouch*> ignored_touch;
[self async_lock]; [self async_lock];
if (!(App::I.redraw || App::I.animate || !working_list.empty())) if (!(App::I.redraw || App::I.animate || !working_list.empty()))
{ {
[self.context presentRenderbuffer:GL_FRAMEBUFFER]; //[self.context presentRenderbuffer:GL_FRAMEBUFFER];
[self async_unlock]; [self async_unlock];
return; std::this_thread::sleep_for(std::chrono::milliseconds(100));
continue;
} }
while (!working_list.empty()) while (!working_list.empty())
@@ -479,7 +483,19 @@ std::set<UITouch*> ignored_touch;
App::I.update(elapsed); App::I.update(elapsed);
[self.context presentRenderbuffer:GL_FRAMEBUFFER]; [self.context presentRenderbuffer:GL_FRAMEBUFFER];
[self async_unlock]; [self async_unlock];
[self->glview display];
elapsed = 0; elapsed = 0;
} }
}).detach();
}
- (void)tearDownGL
{
[EAGLContext setCurrentContext:self.context];
}
@end
@implementation GameView
@end @end

View File

@@ -477,10 +477,6 @@ void NodeStrokePreview::draw_stroke()
{ {
if (m_size.x == 0 || m_size.y == 0) if (m_size.x == 0 || m_size.y == 0)
return; return;
#if __IOS__
draw_stroke_immediate();
return;
#endif
s_queue.mutex.lock(); s_queue.mutex.lock();
if (!s_running) if (!s_running)
{ {