Skip to content

Commit

Permalink
Merge pull request #600 from TomHarte/MacCrash
Browse files Browse the repository at this point in the history
Reintroduces proper locking of the Mac OpenGL context.
  • Loading branch information
TomHarte committed Mar 3, 2019
2 parents 05d483b + ccdeb3f commit 72b4bf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
16 changes: 10 additions & 6 deletions OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m
Expand Up @@ -52,16 +52,20 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt

- (void)drawAtTime:(const CVTimeStamp *)now frequency:(double)frequency
{
// Draw the display now regardless of other activity.
[self performWithGLContext:^{
[self.delegate openGLViewRedraw:self event:CSOpenGLViewRedrawEventTimer];
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
}];
[self redrawWithEvent:CSOpenGLViewRedrawEventTimer];
}

- (void)drawRect:(NSRect)dirtyRect
{
[self.delegate openGLViewRedraw:self event:CSOpenGLViewRedrawEventAppKit];
[self redrawWithEvent:CSOpenGLViewRedrawEventAppKit];
}

- (void)redrawWithEvent:(CSOpenGLViewRedrawEvent)event
{
[self performWithGLContext:^{
[self.delegate openGLViewRedraw:self event:event];
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
}];
}

- (void)invalidate
Expand Down
18 changes: 10 additions & 8 deletions Outputs/OpenGL/ScanTarget.cpp
Expand Up @@ -679,14 +679,16 @@ void ScanTarget::update(int output_width, int output_height) {
void ScanTarget::draw(int output_width, int output_height) {
while(is_drawing_.test_and_set());

// Copy the accumulation texture to the target.
test_gl(glBindFramebuffer, GL_FRAMEBUFFER, target_framebuffer_);
test_gl(glViewport, 0, 0, (GLsizei)output_width, (GLsizei)output_height);

test_gl(glClearColor, 0.0f, 0.0f, 0.0f, 0.0f);
test_gl(glClear, GL_COLOR_BUFFER_BIT);
accumulation_texture_->bind_texture();
accumulation_texture_->draw(float(output_width) / float(output_height), 4.0f / 255.0f);
if(accumulation_texture_) {
// Copy the accumulation texture to the target.
test_gl(glBindFramebuffer, GL_FRAMEBUFFER, target_framebuffer_);
test_gl(glViewport, 0, 0, (GLsizei)output_width, (GLsizei)output_height);

test_gl(glClearColor, 0.0f, 0.0f, 0.0f, 0.0f);
test_gl(glClear, GL_COLOR_BUFFER_BIT);
accumulation_texture_->bind_texture();
accumulation_texture_->draw(float(output_width) / float(output_height), 4.0f / 255.0f);
}

is_drawing_.clear();
}

0 comments on commit 72b4bf9

Please sign in to comment.