Hi,
My macOS app has an NSScrollView to display an image. The document view is an MTKView. I have a Metal pipeline that renders the image and draws it into the view. The view supports "pinch and zoom" scaling. I set the view's drawableSize to be the size of the scaled data, and that works.
The problem I have is that when the image is zoomed in to a large size, I get:
MTKView's underlying texture is now exceeding the GPU RAM. This happens even if I don't draw anything into the drawable.
Is there a way I can get the functionality of the scroll view (i.e. scroll bars, response to mouse/touch) while still using a MTKView? A few thoughts:
Thanks!
My macOS app has an NSScrollView to display an image. The document view is an MTKView. I have a Metal pipeline that renders the image and draws it into the view. The view supports "pinch and zoom" scaling. I set the view's drawableSize to be the size of the scaled data, and that works.
The problem I have is that when the image is zoomed in to a large size, I get:
Code Block validateTextureDimensions, line 1081: error 'MTLTextureDescriptor has width (18798) greater than the maximum allowed size of 16384.'
MTKView's underlying texture is now exceeding the GPU RAM. This happens even if I don't draw anything into the drawable.
Is there a way I can get the functionality of the scroll view (i.e. scroll bars, response to mouse/touch) while still using a MTKView? A few thoughts:
Can I fix the size of the actual MTKView while "tricking" NSScrollView into thinking it was larger?
Can I make the document view large but draw into the visible (clipped) portion?
Is CATiledLayer an option? I could manage the Metal textures, but how would I draw them into the tiles?
Or another recommended option?
Thanks!
We don't have any GPU families that support textures greater than 16384 x 16384 in size, so I recommend trying your second option. You can put the MTKView inside of another NSView (see the following structure) and then synchronize its frame.
I recommend reading https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/SynchroScroll.html. It's related to synchronizing two scroll views, but you should be able to adapt it and synchronize the location of the MTKView within the parent NSView.
Code Block NSScrollView NSClipView NSView MTKView
I recommend reading https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/SynchroScroll.html. It's related to synchronizing two scroll views, but you should be able to adapt it and synchronize the location of the MTKView within the parent NSView.