mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-21 17:16:44 +00:00
Reorder stencil and framebuffer creation.
This commit is contained in:
@@ -390,7 +390,25 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
const NSUInteger frameBufferWidth = MIN(NSUInteger(size.width) * (_isUsingSupersampling ? 2 : 1), 16384);
|
const NSUInteger frameBufferWidth = MIN(NSUInteger(size.width) * (_isUsingSupersampling ? 2 : 1), 16384);
|
||||||
const NSUInteger frameBufferHeight = MIN(NSUInteger(size.height) * (_isUsingSupersampling ? 2 : 1), 16384);
|
const NSUInteger frameBufferHeight = MIN(NSUInteger(size.height) * (_isUsingSupersampling ? 2 : 1), 16384);
|
||||||
|
|
||||||
// Generate a framebuffer and a stencil.
|
// Generate stencil.
|
||||||
|
MTLTextureDescriptor *const stencilTextureDescriptor = [MTLTextureDescriptor
|
||||||
|
texture2DDescriptorWithPixelFormat:MTLPixelFormatStencil8
|
||||||
|
width:frameBufferWidth
|
||||||
|
height:frameBufferHeight
|
||||||
|
mipmapped:NO];
|
||||||
|
stencilTextureDescriptor.usage = MTLTextureUsageRenderTarget;
|
||||||
|
stencilTextureDescriptor.resourceOptions = MTLResourceStorageModePrivate;
|
||||||
|
_frameBufferStencil = [_view.device newTextureWithDescriptor:stencilTextureDescriptor];
|
||||||
|
|
||||||
|
// Establish intended stencil useage; it's only to track which pixels haven't been painted
|
||||||
|
// at all at the end of every frame. So: always paint, and replace the stored stencil value
|
||||||
|
// (which is seeded as 0) with the nominated one (a 1).
|
||||||
|
MTLDepthStencilDescriptor *depthStencilDescriptor = [[MTLDepthStencilDescriptor alloc] init];
|
||||||
|
depthStencilDescriptor.frontFaceStencil.stencilCompareFunction = MTLCompareFunctionAlways;
|
||||||
|
depthStencilDescriptor.frontFaceStencil.depthStencilPassOperation = MTLStencilOperationReplace;
|
||||||
|
_drawStencilState = [_view.device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
||||||
|
|
||||||
|
// Generate framebuffer.
|
||||||
MTLTextureDescriptor *const textureDescriptor = [MTLTextureDescriptor
|
MTLTextureDescriptor *const textureDescriptor = [MTLTextureDescriptor
|
||||||
texture2DDescriptorWithPixelFormat:_view.colorPixelFormat
|
texture2DDescriptorWithPixelFormat:_view.colorPixelFormat
|
||||||
width:frameBufferWidth
|
width:frameBufferWidth
|
||||||
@@ -401,15 +419,6 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
id<MTLTexture> _oldFrameBuffer = _frameBuffer;
|
id<MTLTexture> _oldFrameBuffer = _frameBuffer;
|
||||||
_frameBuffer = [_view.device newTextureWithDescriptor:textureDescriptor];
|
_frameBuffer = [_view.device newTextureWithDescriptor:textureDescriptor];
|
||||||
|
|
||||||
MTLTextureDescriptor *const stencilTextureDescriptor = [MTLTextureDescriptor
|
|
||||||
texture2DDescriptorWithPixelFormat:MTLPixelFormatStencil8
|
|
||||||
width:frameBufferWidth
|
|
||||||
height:frameBufferHeight
|
|
||||||
mipmapped:NO];
|
|
||||||
stencilTextureDescriptor.usage = MTLTextureUsageRenderTarget;
|
|
||||||
stencilTextureDescriptor.resourceOptions = MTLResourceStorageModePrivate;
|
|
||||||
_frameBufferStencil = [_view.device newTextureWithDescriptor:stencilTextureDescriptor];
|
|
||||||
|
|
||||||
// Generate a render pass with that framebuffer and stencil.
|
// Generate a render pass with that framebuffer and stencil.
|
||||||
_frameBufferRenderPass = [[MTLRenderPassDescriptor alloc] init];
|
_frameBufferRenderPass = [[MTLRenderPassDescriptor alloc] init];
|
||||||
_frameBufferRenderPass.colorAttachments[0].texture = _frameBuffer;
|
_frameBufferRenderPass.colorAttachments[0].texture = _frameBuffer;
|
||||||
@@ -421,14 +430,6 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
_frameBufferRenderPass.stencilAttachment.loadAction = MTLLoadActionLoad;
|
_frameBufferRenderPass.stencilAttachment.loadAction = MTLLoadActionLoad;
|
||||||
_frameBufferRenderPass.stencilAttachment.storeAction = MTLStoreActionStore;
|
_frameBufferRenderPass.stencilAttachment.storeAction = MTLStoreActionStore;
|
||||||
|
|
||||||
// Establish intended stencil useage; it's only to track which pixels haven't been painted
|
|
||||||
// at all at the end of every frame. So: always paint, and replace the stored stencil value
|
|
||||||
// (which is seeded as 0) with the nominated one (a 1).
|
|
||||||
MTLDepthStencilDescriptor *depthStencilDescriptor = [[MTLDepthStencilDescriptor alloc] init];
|
|
||||||
depthStencilDescriptor.frontFaceStencil.stencilCompareFunction = MTLCompareFunctionAlways;
|
|
||||||
depthStencilDescriptor.frontFaceStencil.depthStencilPassOperation = MTLStencilOperationReplace;
|
|
||||||
_drawStencilState = [_view.device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
|
||||||
|
|
||||||
// Draw from _oldFrameBuffer to _frameBuffer; otherwise clear the new framebuffer.
|
// Draw from _oldFrameBuffer to _frameBuffer; otherwise clear the new framebuffer.
|
||||||
if(_oldFrameBuffer) {
|
if(_oldFrameBuffer) {
|
||||||
[self copyTexture:_oldFrameBuffer to:_frameBuffer];
|
[self copyTexture:_oldFrameBuffer to:_frameBuffer];
|
||||||
|
|||||||
Reference in New Issue
Block a user