mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-06 01:28:57 +00:00
Got rid of the thread hopping in order to redraw the GL view. Which appears to help significantly with total application cost.
This commit is contained in:
parent
92c7d56cc3
commit
cbe76ea5d5
@ -43,14 +43,10 @@ struct Atari2600CRTDelegate: public Outputs::CRT::CRTDelegate {
|
|||||||
_failedVSyncCount = MAX(_failedVSyncCount - 1, 0);
|
_failedVSyncCount = MAX(_failedVSyncCount - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
BOOL hasReturn = [self.view pushFrame:frame];
|
||||||
BOOL hasReturn = [self.view pushFrame:frame];
|
|
||||||
|
|
||||||
if(hasReturn)
|
if(hasReturn)
|
||||||
dispatch_async(_serialDispatchQueue, ^{
|
_atari2600.get_crt()->return_frame();
|
||||||
_atari2600.get_crt()->return_frame();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)runForNumberOfCycles:(int)cycles {
|
- (void)runForNumberOfCycles:(int)cycles {
|
||||||
|
@ -91,9 +91,13 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||||||
[super reshape];
|
[super reshape];
|
||||||
|
|
||||||
[self.openGLContext makeCurrentContext];
|
[self.openGLContext makeCurrentContext];
|
||||||
|
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||||
|
|
||||||
NSPoint backingSize = {.x = self.bounds.size.width, .y = self.bounds.size.height};
|
NSPoint backingSize = {.x = self.bounds.size.width, .y = self.bounds.size.height};
|
||||||
NSPoint viewSize = [self convertPointToBacking:backingSize];
|
NSPoint viewSize = [self convertPointToBacking:backingSize];
|
||||||
glViewport(0, 0, viewSize.x, viewSize.y);
|
glViewport(0, 0, viewSize.x, viewSize.y);
|
||||||
|
|
||||||
|
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) awakeFromNib
|
- (void) awakeFromNib
|
||||||
@ -138,26 +142,27 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||||||
|
|
||||||
- (BOOL)pushFrame:(CRTFrame * __nonnull)crtFrame
|
- (BOOL)pushFrame:(CRTFrame * __nonnull)crtFrame
|
||||||
{
|
{
|
||||||
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||||
|
|
||||||
BOOL hadFrame = _crtFrame ? YES : NO;
|
BOOL hadFrame = _crtFrame ? YES : NO;
|
||||||
_crtFrame = crtFrame;
|
_crtFrame = crtFrame;
|
||||||
[self setNeedsDisplay:YES];
|
|
||||||
|
|
||||||
if(crtFrame)
|
glBufferData(GL_ARRAY_BUFFER, _crtFrame->number_of_runs * kCRTSizeOfVertex * 6, _crtFrame->runs, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, _textureName);
|
||||||
|
if(_textureSize.width != _crtFrame->size.width || _textureSize.height != _crtFrame->size.height)
|
||||||
{
|
{
|
||||||
[self.openGLContext makeCurrentContext];
|
GLint format = [self formatForDepth:_crtFrame->buffers[0].depth];
|
||||||
glBufferData(GL_ARRAY_BUFFER, _crtFrame->number_of_runs * kCRTSizeOfVertex * 6, _crtFrame->runs, GL_DYNAMIC_DRAW);
|
glTexImage2D(GL_TEXTURE_2D, 0, format, _crtFrame->size.width, _crtFrame->size.height, 0, format, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
|
||||||
|
_textureSize = _crtFrame->size;
|
||||||
glBindTexture(GL_TEXTURE_2D, _textureName);
|
|
||||||
|
|
||||||
if(_textureSize.width != _crtFrame->size.width || _textureSize.height != _crtFrame->size.height)
|
|
||||||
{
|
|
||||||
GLint format = [self formatForDepth:_crtFrame->buffers[0].depth];
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, format, _crtFrame->size.width, _crtFrame->size.height, 0, format, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
|
|
||||||
_textureSize = _crtFrame->size;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, [self formatForDepth:_crtFrame->buffers[0].depth], GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, [self formatForDepth:_crtFrame->buffers[0].depth], GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
|
||||||
|
|
||||||
|
[self drawView];
|
||||||
|
|
||||||
|
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||||
|
|
||||||
return hadFrame;
|
return hadFrame;
|
||||||
}
|
}
|
||||||
@ -275,8 +280,14 @@ const char *fragmentShader =
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawRect:(NSRect)dirtyRect
|
- (void)drawRect:(NSRect)dirtyRect
|
||||||
|
{
|
||||||
|
[self drawView];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)drawView
|
||||||
{
|
{
|
||||||
[self.openGLContext makeCurrentContext];
|
[self.openGLContext makeCurrentContext];
|
||||||
|
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
@ -287,6 +298,9 @@ const char *fragmentShader =
|
|||||||
}
|
}
|
||||||
|
|
||||||
glSwapAPPLE();
|
glSwapAPPLE();
|
||||||
|
|
||||||
|
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
|
||||||
|
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user