diff --git a/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m b/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m index 8ebcb77436..492fd2c63b 100644 --- a/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m +++ b/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m @@ -392,6 +392,10 @@ - (void)displayLayer:(CALayer *)layer { #pragma mark - ShaderRendererDelegate +- (BOOL)canDraw { + return _draw_data.points != NULL; +} + - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { float scale = (float)(viewParams.backingScaleFactor / [self scaleFactorForBackingScaleFactor:viewParams.backingScaleFactor]); diff --git a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h index df9c3c66f6..aa977153ef 100644 --- a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h +++ b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h @@ -32,6 +32,7 @@ typedef struct { } ShaderRendererParams; @protocol ShaderRendererDelegate +- (BOOL)canDraw; - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(nonnull id )device encoder:(nonnull id )encoder viewParams:(ShaderRendererParams)params; @end diff --git a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m index 9e54fed1f5..8797e69cc7 100644 --- a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m +++ b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m @@ -110,6 +110,9 @@ - (void)drawableResize:(CGSize)drawableSize } - (void)renderToMetalLayer:(nonnull CAMetalLayer*)metalLayer viewParams:(ShaderRendererParams)viewParams { + if (![self.delegate canDraw]) { + return; + } if (_viewportSize.width == 0 || _viewportSize.height == 0) { return; } @@ -132,7 +135,6 @@ - (void)renderToMetalLayer:(nonnull CAMetalLayer*)metalLayer viewParams:(ShaderR id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:_drawableRenderDescriptor]; - renderEncoder.label = @"MyRenderEncoder"; // begin diff --git a/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m b/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m index 96232c11c1..496308296f 100644 --- a/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m +++ b/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m @@ -437,6 +437,10 @@ - (void)displayLayer:(CALayer *)layer { #pragma mark - ShaderRendererDelegate +- (BOOL)canDraw { + return _draw_data.bars != NULL; +} + - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { struct SpectrumFragParams params; @@ -474,7 +478,9 @@ - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id // The buffer is not bigger than ~2.5KB (211 bars * 12 bytes), // therefore it should be safe to use setFragmentBytes. [encoder setFragmentBytes:_draw_data.bars length:_draw_data.bar_count * sizeof (struct SpectrumFragBar) atIndex:1]; - } + // This buffer is unused in this scenario, but necessary to shut up API validator + [encoder setFragmentBytes:_draw_data.bars length:4 atIndex:2]; + } } @end