mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-27 00:30:26 +00:00
Ensure defined initial state for the frame buffer.
This commit is contained in:
parent
49cee90b4d
commit
4bf85abf30
@ -443,19 +443,36 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
depthStencilDescriptor.frontFaceStencil.depthStencilPassOperation = MTLStencilOperationReplace;
|
||||
_drawStencilState = [_view.device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
||||
|
||||
// Draw from _oldFrameBuffer to _frameBuffer.
|
||||
// Draw from _oldFrameBuffer to _frameBuffer; otherwise clear the new framebuffer.
|
||||
if(_oldFrameBuffer) {
|
||||
[self copyTexture:_oldFrameBuffer to:_frameBuffer];
|
||||
|
||||
// Don't clear the framebuffer at the end of this frame.
|
||||
_dontClearFrameBuffer = YES;
|
||||
} else {
|
||||
[self clearTexture:_frameBuffer];
|
||||
}
|
||||
|
||||
// Don't clear the framebuffer at the end of this frame.
|
||||
_dontClearFrameBuffer = YES;
|
||||
}
|
||||
|
||||
- (BOOL)shouldApplyGamma {
|
||||
return fabsf(float(uniforms()->outputGamma) - 1.0f) > 0.01f;
|
||||
}
|
||||
|
||||
- (void)clearTexture:(id<MTLTexture>)texture {
|
||||
id<MTLLibrary> library = [_view.device newDefaultLibrary];
|
||||
|
||||
// Ensure finalised line texture is initially clear.
|
||||
id<MTLComputePipelineState> clearPipeline = [_view.device newComputePipelineStateWithFunction:[library newFunctionWithName:@"clearKernel"] error:nil];
|
||||
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||
id<MTLComputeCommandEncoder> computeEncoder = [commandBuffer computeCommandEncoder];
|
||||
|
||||
[computeEncoder setTexture:texture atIndex:0];
|
||||
[self dispatchComputeCommandEncoder:computeEncoder pipelineState:clearPipeline width:texture.width height:texture.height offsetBuffer:[self bufferForOffset:0]];
|
||||
|
||||
[computeEncoder endEncoding];
|
||||
[commandBuffer commit];
|
||||
}
|
||||
|
||||
- (void)updateModalBuffers {
|
||||
// Build a descriptor for any intermediate line texture.
|
||||
MTLTextureDescriptor *const lineTextureDescriptor = [MTLTextureDescriptor
|
||||
@ -490,20 +507,10 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
// The finalised texture will definitely exist, and may or may not require a gamma conversion when written to.
|
||||
if(!_finalisedLineTexture) {
|
||||
_finalisedLineTexture = [_view.device newTextureWithDescriptor:lineTextureDescriptor];
|
||||
[self clearTexture:_finalisedLineTexture];
|
||||
|
||||
NSString *const kernelFunction = [self shouldApplyGamma] ? @"filterChromaKernelWithGamma" : @"filterChromaKernelNoGamma";
|
||||
_finalisedLineState = [_view.device newComputePipelineStateWithFunction:[library newFunctionWithName:kernelFunction] error:nil];
|
||||
|
||||
// Ensure finalised line texture is initially clear.
|
||||
id<MTLComputePipelineState> clearPipeline = [_view.device newComputePipelineStateWithFunction:[library newFunctionWithName:@"clearKernel"] error:nil];
|
||||
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||
id<MTLComputeCommandEncoder> computeEncoder = [commandBuffer computeCommandEncoder];
|
||||
|
||||
[computeEncoder setTexture:_finalisedLineTexture atIndex:0];
|
||||
[self dispatchComputeCommandEncoder:computeEncoder pipelineState:clearPipeline width:lineTextureDescriptor.width height:lineTextureDescriptor.height offsetBuffer:[self bufferForOffset:0]];
|
||||
|
||||
[computeEncoder endEncoding];
|
||||
[commandBuffer commit];
|
||||
}
|
||||
|
||||
// A luma separation texture will exist only for composite colour.
|
||||
|
Loading…
x
Reference in New Issue
Block a user