mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-21 05:29:13 +00:00
Makes thread safe.
This commit is contained in:
parent
645c29f853
commit
512c0079a9
@ -99,6 +99,14 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
// Set initial aspect-ratio multiplier.
|
// Set initial aspect-ratio multiplier.
|
||||||
_view = view;
|
_view = view;
|
||||||
[self mtkView:view drawableSizeWillChange:view.drawableSize];
|
[self mtkView:view drawableSizeWillChange:view.drawableSize];
|
||||||
|
|
||||||
|
// Generate copy pipeline.
|
||||||
|
id<MTLLibrary> library = [_view.device newDefaultLibrary];
|
||||||
|
MTLRenderPipelineDescriptor *const pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
|
||||||
|
pipelineDescriptor.colorAttachments[0].pixelFormat = _view.colorPixelFormat;
|
||||||
|
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"copyVertex"];
|
||||||
|
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"copyFragment"];
|
||||||
|
_copyPipeline = [_view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@ -119,6 +127,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
|
|
||||||
// TODO: attach a stencil buffer.
|
// TODO: attach a stencil buffer.
|
||||||
|
|
||||||
|
@synchronized(self) {
|
||||||
// Generate a framebuffer and a pipeline that targets it.
|
// Generate a framebuffer and a pipeline that targets it.
|
||||||
MTLTextureDescriptor *const textureDescriptor = [MTLTextureDescriptor
|
MTLTextureDescriptor *const textureDescriptor = [MTLTextureDescriptor
|
||||||
texture2DDescriptorWithPixelFormat:view.colorPixelFormat
|
texture2DDescriptorWithPixelFormat:view.colorPixelFormat
|
||||||
@ -134,6 +143,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
_frameBufferRenderPass.colorAttachments[0].loadAction = MTLLoadActionLoad;
|
_frameBufferRenderPass.colorAttachments[0].loadAction = MTLLoadActionLoad;
|
||||||
_frameBufferRenderPass.colorAttachments[0].storeAction = MTLStoreActionStore;
|
_frameBufferRenderPass.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setAspectRatio {
|
- (void)setAspectRatio {
|
||||||
uniforms()->aspectRatioMultiplier = float(_scanTarget.modals().aspect_ratio / (_view.bounds.size.width / _view.bounds.size.height));
|
uniforms()->aspectRatioMultiplier = float(_scanTarget.modals().aspect_ratio / (_view.bounds.size.width / _view.bounds.size.height));
|
||||||
@ -248,17 +258,6 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
||||||
|
|
||||||
_scanPipeline = [_view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
_scanPipeline = [_view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate copy pipeline.
|
|
||||||
//
|
|
||||||
pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
|
|
||||||
pipelineDescriptor.colorAttachments[0].pixelFormat = _view.colorPixelFormat;
|
|
||||||
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"copyVertex"];
|
|
||||||
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"copyFragment"];
|
|
||||||
_copyPipeline = [_view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)checkModals {
|
- (void)checkModals {
|
||||||
@ -271,11 +270,10 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//- (void)updateFrameBuffer {
|
|
||||||
//}
|
|
||||||
|
|
||||||
- (void)updateFrameBuffer {
|
- (void)updateFrameBuffer {
|
||||||
[self checkModals];
|
[self checkModals];
|
||||||
|
|
||||||
|
@synchronized(self) {
|
||||||
if(!_frameBufferRenderPass) return;
|
if(!_frameBufferRenderPass) return;
|
||||||
|
|
||||||
// Generate a command encoder for the view.
|
// Generate a command encoder for the view.
|
||||||
@ -330,6 +328,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
// Commit the drawing.
|
// Commit the drawing.
|
||||||
[commandBuffer commit];
|
[commandBuffer commit];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@method drawInMTKView:
|
@method drawInMTKView:
|
||||||
@ -337,9 +336,6 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
@discussion Called on the delegate when it is asked to render into the view
|
@discussion Called on the delegate when it is asked to render into the view
|
||||||
*/
|
*/
|
||||||
- (void)drawInMTKView:(nonnull MTKView *)view {
|
- (void)drawInMTKView:(nonnull MTKView *)view {
|
||||||
[self checkModals];
|
|
||||||
// [self updateFrameBuffer];
|
|
||||||
|
|
||||||
// Schedule a copy from the current framebuffer to the view; blitting is unavailable as the target is a framebuffer texture.
|
// Schedule a copy from the current framebuffer to the view; blitting is unavailable as the target is a framebuffer texture.
|
||||||
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||||
id<MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:view.currentRenderPassDescriptor];
|
id<MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:view.currentRenderPassDescriptor];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user