implement multithreaded rendering with context switch, gl state save/restore, add progress bar ui node, implement stencil texture for brush, implement multithreaded canvas load/save/export pano. Missing multithread in windows.

This commit is contained in:
2017-10-20 09:16:12 +01:00
parent 32ede1be90
commit 283e4e2b5c
42 changed files with 610 additions and 65 deletions

View File

@@ -12,6 +12,7 @@
#include "app.h"
@interface GameViewController () {
NSLock* gl_lock;
}
@property (strong, nonatomic) EAGLContext *context;
@@ -24,6 +25,21 @@ int t_count = 0;
glm::vec2 t_pos;
@implementation GameViewController
- (void)async_lock
{
[gl_lock lock];
[EAGLContext setCurrentContext:self.context];
GLKView* view = (GLKView*)self.view;
//[view bindDrawable];
}
- (void)async_unlock
{
[gl_lock unlock];
}
- (void)async_swap
{
[[EAGLContext currentContext] presentRenderbuffer:GL_RENDERBUFFER];
}
- (void)insertText:(NSString *)text
{
@@ -84,9 +100,11 @@ glm::vec2 t_pos;
frame.size.height -= kbSize.height;
view.frame = frame;
[gl_lock lock];
App::I.resize(frame.size.width * view.contentScaleFactor,
frame.size.height * view.contentScaleFactor);
App::I.animate = false;
[gl_lock unlock];
}
// Called when the UIKeyboardWillHideNotification is sent
@@ -94,17 +112,21 @@ glm::vec2 t_pos;
{
CGRect frame = [[UIScreen mainScreen] bounds];
self.view.frame = frame;
[gl_lock lock];
App::I.resize(frame.size.width * self.view.contentScaleFactor,
frame.size.height * self.view.contentScaleFactor);
App::I.animate = true;
[gl_lock unlock];
}
- (void)reset_touch
{
[gl_lock lock];
if (t_count == 2)
App::I.gesture_end();
else
App::I.mouse_cancel(0);
[gl_lock unlock];
t_count = 0;
}
@@ -116,7 +138,9 @@ glm::vec2 t_pos;
float scale = self.view.contentScaleFactor;
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
[gl_lock lock];
App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force, source);
[gl_lock unlock];
t_count = 1;
t_pos = {touchLocation.x * scale, touchLocation.y * scale};
}
@@ -139,6 +163,7 @@ glm::vec2 t_pos;
p1 = glm::vec2(tl1.x * scale, tl1.y * scale);
}
[gl_lock lock];
if (n == 2)
{
if (t_count == 1)
@@ -167,6 +192,7 @@ glm::vec2 t_pos;
App::I.mouse_move(touchLocation.x * scale, touchLocation.y * scale, force, source);
}
}
[gl_lock unlock];
t_pos = {tl0.x * scale, tl0.y * scale};
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
@@ -177,18 +203,23 @@ glm::vec2 t_pos;
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
[gl_lock lock];
if (t_count == 2)
App::I.gesture_end();
else
App::I.mouse_up(0, touchLocation.x * scale, touchLocation.y * scale, source);
[gl_lock unlock];
t_count = 0;
t_pos = {touchLocation.x * scale, touchLocation.y * scale};
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[gl_lock lock];
App::I.resize(size.width * self.view.contentScaleFactor,
size.height * self.view.contentScaleFactor);
[gl_lock unlock];
}
- (void)viewDidAppear:(BOOL)animated
@@ -211,9 +242,12 @@ glm::vec2 t_pos;
NSLog(@"Failed to create ES context");
}
gl_lock = [[NSLock alloc] init];
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
glview = view;
App::I.width = view.frame.size.width * view.contentScaleFactor;
App::I.height = view.frame.size.height * view.contentScaleFactor;
@@ -273,10 +307,18 @@ glm::vec2 t_pos;
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
[gl_lock lock];
if (!(App::I.redraw || App::I.animate))
{
[gl_lock unlock];
return;
}
[EAGLContext setCurrentContext:self.context];
[view bindDrawable];
App::I.clear();
App::I.update(0);
//[self.context presentRenderbuffer:GL_FRAMEBUFFER];
[gl_lock unlock];
}
@end