testing iOS multithread rendering
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<?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">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<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"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
@@ -17,7 +17,7 @@
|
||||
<viewControllerLayoutGuide type="top" id="8aa-yV-Osq"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="qHh-Mt-9TT"/>
|
||||
</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"/>
|
||||
<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"/>
|
||||
|
||||
@@ -10,14 +10,17 @@
|
||||
#import <GLKit/GLKit.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface GameViewController : GLKViewController<
|
||||
@interface GameView : GLKView
|
||||
@end
|
||||
|
||||
@interface GameViewController : UIViewController<
|
||||
UIKeyInput,
|
||||
UIImagePickerControllerDelegate,
|
||||
UINavigationControllerDelegate,
|
||||
UIDocumentInteractionControllerDelegate
|
||||
>
|
||||
{
|
||||
@public GLKView* glview;
|
||||
@public GameView* glview;
|
||||
}
|
||||
- (void)display_file:(std::string)filename;
|
||||
- (void)reset_touch;
|
||||
|
||||
@@ -55,7 +55,7 @@ std::recursive_mutex lock_mutex;
|
||||
// lock_thread = [NSThread currentThread];
|
||||
// lock_count++;
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
GLKView* view = (GLKView*)self.view;
|
||||
GameView* view = (GameView*)self.view;
|
||||
[view bindDrawable];
|
||||
}
|
||||
- (void)async_unlock
|
||||
@@ -194,7 +194,7 @@ std::recursive_mutex lock_mutex;
|
||||
NSDictionary* info = [aNotification userInfo];
|
||||
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
|
||||
|
||||
GLKView *view = (GLKView *)self.view;
|
||||
GameView *view = (GameView *)self.view;
|
||||
CGRect frame = view.frame;
|
||||
frame.size.height -= kbSize.height;
|
||||
view.frame = frame;
|
||||
@@ -380,7 +380,7 @@ std::set<UITouch*> ignored_touch;
|
||||
App::I.initLog();
|
||||
App::I.ios_view = self;
|
||||
|
||||
self.preferredFramesPerSecond = 60;
|
||||
//self.preferredFramesPerSecond = 60;
|
||||
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
||||
|
||||
if (!self.context) {
|
||||
@@ -389,9 +389,10 @@ std::set<UITouch*> ignored_touch;
|
||||
|
||||
gl_lock = [[NSLock alloc] init];
|
||||
|
||||
GLKView *view = (GLKView *)self.view;
|
||||
GameView *view = (GameView *)self.view;
|
||||
view.context = self.context;
|
||||
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
|
||||
view.enableSetNeedsDisplay = NO;
|
||||
glview = view;
|
||||
|
||||
App::I.width = view.frame.size.width * view.contentScaleFactor;
|
||||
@@ -433,8 +434,59 @@ std::set<UITouch*> ignored_touch;
|
||||
|
||||
- (void)setupGL
|
||||
{
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
[self async_lock];
|
||||
App::I.init();
|
||||
[self async_unlock];
|
||||
|
||||
std::thread([self]{
|
||||
while (true)
|
||||
{
|
||||
static auto time = std::chrono::steady_clock::now();
|
||||
static double elapsed = 0;
|
||||
static double min_fps_timer = 0;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto dt = std::chrono::duration<float>(now - time);
|
||||
time = now;
|
||||
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;
|
||||
if (!tasklist.empty())
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
working_list = std::move(tasklist);
|
||||
}
|
||||
|
||||
App::I.tick(dt.count());
|
||||
|
||||
[self async_lock];
|
||||
if (!(App::I.redraw || App::I.animate || !working_list.empty()))
|
||||
{
|
||||
//[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||
[self async_unlock];
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
}
|
||||
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
App::I.clear();
|
||||
App::I.update(elapsed);
|
||||
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||
[self async_unlock];
|
||||
[self->glview display];
|
||||
elapsed = 0;
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
|
||||
- (void)tearDownGL
|
||||
@@ -442,44 +494,8 @@ std::set<UITouch*> ignored_touch;
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
}
|
||||
|
||||
#pragma mark - GLKView and GLKViewController delegate methods
|
||||
@end
|
||||
|
||||
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
||||
{
|
||||
static auto time = std::chrono::steady_clock::now();
|
||||
static double elapsed = 0;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto dt = std::chrono::duration<float>(now - time);
|
||||
time = now;
|
||||
elapsed += dt.count();
|
||||
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
if (!tasklist.empty())
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
working_list = std::move(tasklist);
|
||||
}
|
||||
|
||||
App::I.tick(dt.count());
|
||||
|
||||
[self async_lock];
|
||||
if (!(App::I.redraw || App::I.animate || !working_list.empty()))
|
||||
{
|
||||
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||
[self async_unlock];
|
||||
return;
|
||||
}
|
||||
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
App::I.clear();
|
||||
App::I.update(elapsed);
|
||||
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||
[self async_unlock];
|
||||
elapsed = 0;
|
||||
}
|
||||
@implementation GameView
|
||||
|
||||
@end
|
||||
|
||||
@@ -477,10 +477,6 @@ void NodeStrokePreview::draw_stroke()
|
||||
{
|
||||
if (m_size.x == 0 || m_size.y == 0)
|
||||
return;
|
||||
#if __IOS__
|
||||
draw_stroke_immediate();
|
||||
return;
|
||||
#endif
|
||||
s_queue.mutex.lock();
|
||||
if (!s_running)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user