Metal backend resource for MacOS fixes (#4020)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#import <mbgl/map/map_observer.hpp>
|
||||
#import <mbgl/util/image.hpp>
|
||||
|
||||
#import "MLNBackendResource.h"
|
||||
|
||||
@class MLNMapView;
|
||||
|
||||
typedef struct _CGLContextObject* CGLContextObj;
|
||||
@@ -20,6 +22,11 @@ class MLNMapViewImpl : public mbgl::MapObserver {
|
||||
|
||||
virtual CGLContextObj getCGLContextObj() { return nullptr; }
|
||||
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
// Returns the backend resource for Metal rendering in custom layers
|
||||
virtual MLNBackendResource* getObject() { return nullptr; }
|
||||
#endif
|
||||
|
||||
// Called by the view delegate when it's time to render.
|
||||
void render();
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class MLNMapViewMetalImpl final : public MLNMapViewImpl,
|
||||
mbgl::gfx::RendererBackend& getRendererBackend() override { return *this; }
|
||||
|
||||
mbgl::PremultipliedImage readStillImage() override;
|
||||
MLNBackendResource* getObject() override;
|
||||
|
||||
private:
|
||||
bool presentsWithTransaction = false;
|
||||
|
||||
@@ -44,8 +44,10 @@ public:
|
||||
commandQueue = [mtlView.device newCommandQueue];
|
||||
}
|
||||
|
||||
commandBuffer = [commandQueue commandBuffer];
|
||||
commandBufferPtr = NS::RetainPtr((__bridge MTL::CommandBuffer*)commandBuffer);
|
||||
if (!commandBuffer) {
|
||||
commandBuffer = [commandQueue commandBuffer];
|
||||
commandBufferPtr = NS::RetainPtr((__bridge MTL::CommandBuffer*)commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
const mbgl::mtl::RendererBackend& getBackend() const override { return backend; }
|
||||
@@ -158,3 +160,12 @@ mbgl::PremultipliedImage MLNMapViewMetalImpl::readStillImage() {
|
||||
// return readFramebuffer(mapView.framebufferSize); // TODO: RendererBackend::readFramebuffer
|
||||
return {};
|
||||
}
|
||||
|
||||
MLNBackendResource* MLNMapViewMetalImpl::getObject() {
|
||||
auto& resource = getResource<MLNMapViewMetalRenderableResource>();
|
||||
|
||||
return [[MLNBackendResource alloc] initWithMTKView:resource.mtlView
|
||||
device:resource.mtlView.device
|
||||
renderPassDescriptor:resource.mtlView.currentRenderPassDescriptor
|
||||
commandBuffer:resource.commandBuffer];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "MLNBackendResource.h"
|
||||
#import "MLNFoundation.h"
|
||||
#import "MLNGeometry.h"
|
||||
#import "MLNMapOptions.h"
|
||||
@@ -1336,6 +1337,16 @@ around the returned camera object if it were set as the receiver’s camera.
|
||||
*/
|
||||
- (void)clearActionJournalLog;
|
||||
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
/**
|
||||
Returns the Metal backend resource for use in custom style layers.
|
||||
|
||||
This property provides access to the Metal device, command buffer, and other
|
||||
resources needed for custom Metal rendering in MLNCustomStyleLayer subclasses.
|
||||
*/
|
||||
- (MLNBackendResource *)backendResource;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#import <unordered_set>
|
||||
|
||||
#import "MLNMapView+Impl.h"
|
||||
#import "MLNBackendResource.h"
|
||||
#import "NSBundle+MLNAdditions.h"
|
||||
#import "NSDate+MLNAdditions.h"
|
||||
#import "NSProcessInfo+MLNAdditions.h"
|
||||
@@ -3314,4 +3315,10 @@ public:
|
||||
actionJournal->clearLog();
|
||||
}
|
||||
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
- (MLNBackendResource *)backendResource {
|
||||
return _mbglView->getObject();
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user