From 4a12cbf882512903450490c5baeaaacc29527c15 Mon Sep 17 00:00:00 2001 From: Yousif Aldolaijan Date: Tue, 11 Feb 2025 14:53:30 +0300 Subject: [PATCH] fix macos builds --- platform/BUILD.bazel | 5 +- platform/darwin/bazel/files.bzl | 54 +++++++++---------- ...TFMTLRenderItem.m => GLTFMTLRenderItem.mm} | 0 platform/darwin/src/gltf/GLTFModelLayer.mm | 6 --- .../{GLTFModelLoader.m => GLTFModelLoader.mm} | 0 .../{GLTFAccessor.m => GLTFAccessor.mm} | 0 .../{GLTFAnimation.m => GLTFAnimation.mm} | 21 ++++---- .../gltfkit/{GLTFAsset.m => GLTFAsset.mm} | 35 ++++++------ .../{GLTFBinaryChunk.m => GLTFBinaryChunk.mm} | 0 .../{GLTFBufferView.m => GLTFBufferView.mm} | 0 .../gltfkit/{GLTFCamera.m => GLTFCamera.mm} | 0 ...ocator.m => GLTFDefaultBufferAllocator.mm} | 0 ...ExtensionNames.m => GLTFExtensionNames.mm} | 0 .../gltfkit/{GLTFImage.m => GLTFImage.mm} | 0 .../{GLTFKHRLight.m => GLTFKHRLight.mm} | 0 ...rAllocator.m => GLTFMTLBufferAllocator.mm} | 0 ...haderBuilder.m => GLTFMTLShaderBuilder.mm} | 0 ...extureLoader.m => GLTFMTLTextureLoader.mm} | 8 +-- ...GLTFMTLUtilities.m => GLTFMTLUtilities.mm} | 5 +- .../{GLTFMaterial.m => GLTFMaterial.mm} | 0 .../gltf/gltfkit/{GLTFMesh.m => GLTFMesh.mm} | 0 .../gltf/gltfkit/{GLTFNode.m => GLTFNode.mm} | 4 +- .../gltfkit/{GLTFObject.m => GLTFObject.mm} | 0 .../gltfkit/{GLTFScene.m => GLTFScene.mm} | 2 +- .../gltf/gltfkit/{GLTFSkin.m => GLTFSkin.mm} | 0 ...TextureSampler.m => GLTFTextureSampler.mm} | 0 .../{GLTFUtilities.m => GLTFUtilities.mm} | 3 +- ...exDescriptor.m => GLTFVertexDescriptor.mm} | 0 platform/macos/src/MLNMapView+Impl.h | 4 ++ platform/macos/src/MLNMapView+Metal.h | 2 + platform/macos/src/MLNMapView+Metal.mm | 11 ++++ platform/macos/src/MLNMapView+OpenGL.h | 2 + platform/macos/src/MLNMapView+OpenGL.mm | 4 ++ platform/macos/src/MLNMapView.h | 2 + platform/macos/src/MLNMapView.mm | 4 ++ 35 files changed, 99 insertions(+), 73 deletions(-) rename platform/darwin/src/gltf/{GLTFMTLRenderItem.m => GLTFMTLRenderItem.mm} (100%) rename platform/darwin/src/gltf/{GLTFModelLoader.m => GLTFModelLoader.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFAccessor.m => GLTFAccessor.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFAnimation.m => GLTFAnimation.mm} (87%) rename platform/darwin/src/gltf/gltfkit/{GLTFAsset.m => GLTFAsset.mm} (96%) rename platform/darwin/src/gltf/gltfkit/{GLTFBinaryChunk.m => GLTFBinaryChunk.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFBufferView.m => GLTFBufferView.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFCamera.m => GLTFCamera.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFDefaultBufferAllocator.m => GLTFDefaultBufferAllocator.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFExtensionNames.m => GLTFExtensionNames.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFImage.m => GLTFImage.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFKHRLight.m => GLTFKHRLight.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFMTLBufferAllocator.m => GLTFMTLBufferAllocator.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFMTLShaderBuilder.m => GLTFMTLShaderBuilder.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFMTLTextureLoader.m => GLTFMTLTextureLoader.mm} (97%) rename platform/darwin/src/gltf/gltfkit/{GLTFMTLUtilities.m => GLTFMTLUtilities.mm} (98%) rename platform/darwin/src/gltf/gltfkit/{GLTFMaterial.m => GLTFMaterial.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFMesh.m => GLTFMesh.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFNode.m => GLTFNode.mm} (98%) rename platform/darwin/src/gltf/gltfkit/{GLTFObject.m => GLTFObject.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFScene.m => GLTFScene.mm} (97%) rename platform/darwin/src/gltf/gltfkit/{GLTFSkin.m => GLTFSkin.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFTextureSampler.m => GLTFTextureSampler.mm} (100%) rename platform/darwin/src/gltf/gltfkit/{GLTFUtilities.m => GLTFUtilities.mm} (99%) rename platform/darwin/src/gltf/gltfkit/{GLTFVertexDescriptor.m => GLTFVertexDescriptor.mm} (100%) diff --git a/platform/BUILD.bazel b/platform/BUILD.bazel index 9d961d07115..ae82104a002 100644 --- a/platform/BUILD.bazel +++ b/platform/BUILD.bazel @@ -4,6 +4,8 @@ load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS", "WARNING_FLAGS") objc_library( name = "macos-objcpp", srcs = [ + "//platform/darwin:darwin_gltf_hdrs", + "//platform/darwin:darwin_gltf_srcs", "//platform/darwin:darwin_objcpp_custom_drawable_srcs", "//platform/darwin:darwin_objcpp_srcs", "//platform/darwin:darwin_private_hdrs", @@ -36,6 +38,7 @@ objc_library( "CoreLocation", "AppKit", "SystemConfiguration", + "Accelerate", ], visibility = ["//visibility:public"], deps = [ @@ -50,8 +53,6 @@ objc_library( objc_library( name = "macos-objc", srcs = [ - "//platform/darwin:darwin_gltf_hdrs", - "//platform/darwin:darwin_gltf_srcs", "//platform/darwin:darwin_objc_hdrs", "//platform/darwin:darwin_objc_srcs", "//platform/darwin:darwin_private_hdrs", diff --git a/platform/darwin/bazel/files.bzl b/platform/darwin/bazel/files.bzl index 8776c4c0fd2..460747b2771 100644 --- a/platform/darwin/bazel/files.bzl +++ b/platform/darwin/bazel/files.bzl @@ -1,5 +1,5 @@ MLN_GLTF_HEADERS = [ - "src/gltf/GLTFModelLayer.h" + "src/gltf/GLTFModelLayer.h", ] MLN_GLTF_SOURCE = [ @@ -20,68 +20,66 @@ MLN_GLTF_SOURCE = [ "src/gltf/GLTFModelLayer.h", "src/gltf/GLTFModelLayer.mm", "src/gltf/GLTFModelLoader.h", - "src/gltf/GLTFModelLoader.m", + "src/gltf/GLTFModelLoader.mm", "src/gltf/GLTFMTLRenderItem.h", - "src/gltf/GLTFMTLRenderItem.m", + "src/gltf/GLTFMTLRenderItem.mm", "src/gltf/GLTFRenderer.hpp", "src/gltf/GLTFRenderer.cpp", "src/gltf/MetalRenderer+GLTFAsset.mm", "src/gltf/gltfkit/GLTFAsset.h", - "src/gltf/gltfkit/GLTFAsset.m", + "src/gltf/gltfkit/GLTFAsset.mm", "src/gltf/gltfkit/GLTFAccessor.h", - "src/gltf/gltfkit/GLTFAccessor.m", + "src/gltf/gltfkit/GLTFAccessor.mm", "src/gltf/gltfkit/GLTFAnimation.h", - "src/gltf/gltfkit/GLTFAnimation.m", + "src/gltf/gltfkit/GLTFAnimation.mm", "src/gltf/gltfkit/GLTFBinaryChunk.h", - "src/gltf/gltfkit/GLTFBinaryChunk.m", + "src/gltf/gltfkit/GLTFBinaryChunk.mm", "src/gltf/gltfkit/GLTFBuffer.h", "src/gltf/gltfkit/GLTFBufferAllocator.h", "src/gltf/gltfkit/GLTFBufferView.h", - "src/gltf/gltfkit/GLTFBufferView.m", + "src/gltf/gltfkit/GLTFBufferView.mm", "src/gltf/gltfkit/GLTFCamera.h", - "src/gltf/gltfkit/GLTFCamera.m", + "src/gltf/gltfkit/GLTFCamera.mm", "src/gltf/gltfkit/GLTFDefaultBufferAllocator.h", - "src/gltf/gltfkit/GLTFDefaultBufferAllocator.m", + "src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm", "src/gltf/gltfkit/GLTFEnums.h", "src/gltf/gltfkit/GLTFExtensionNames.h", - "src/gltf/gltfkit/GLTFExtensionNames.m", + "src/gltf/gltfkit/GLTFExtensionNames.mm", "src/gltf/gltfkit/GLTFImage.h", - "src/gltf/gltfkit/GLTFImage.m", + "src/gltf/gltfkit/GLTFImage.mm", "src/gltf/gltfkit/GLTFKHRLight.h", - "src/gltf/gltfkit/GLTFKHRLight.m", + "src/gltf/gltfkit/GLTFKHRLight.mm", "src/gltf/gltfkit/GLTFMaterial.h", - "src/gltf/gltfkit/GLTFMaterial.m", + "src/gltf/gltfkit/GLTFMaterial.mm", "src/gltf/gltfkit/GLTFMesh.h", - "src/gltf/gltfkit/GLTFMesh.m", + "src/gltf/gltfkit/GLTFMesh.mm", "src/gltf/gltfkit/GLTFMTLBufferAllocator.h", - "src/gltf/gltfkit/GLTFMTLBufferAllocator.m", + "src/gltf/gltfkit/GLTFMTLBufferAllocator.mm", "src/gltf/gltfkit/GLTFMTLShaderBuilder.h", - "src/gltf/gltfkit/GLTFMTLShaderBuilder.m", + "src/gltf/gltfkit/GLTFMTLShaderBuilder.mm", "src/gltf/gltfkit/GLTFMTLTextureLoader.h", - "src/gltf/gltfkit/GLTFMTLTextureLoader.m", + "src/gltf/gltfkit/GLTFMTLTextureLoader.mm", "src/gltf/gltfkit/GLTFMTLUtilities.h", - "src/gltf/gltfkit/GLTFMTLUtilities.m", + "src/gltf/gltfkit/GLTFMTLUtilities.mm", "src/gltf/gltfkit/GLTFNode.h", - "src/gltf/gltfkit/GLTFNode.m", + "src/gltf/gltfkit/GLTFNode.mm", "src/gltf/gltfkit/GLTFNodeVisitor.h", "src/gltf/gltfkit/GLTFObject.h", - "src/gltf/gltfkit/GLTFObject.m", + "src/gltf/gltfkit/GLTFObject.mm", "src/gltf/gltfkit/GLTFScene.h", - "src/gltf/gltfkit/GLTFScene.m", + "src/gltf/gltfkit/GLTFScene.mm", "src/gltf/gltfkit/GLTFSkin.h", - "src/gltf/gltfkit/GLTFSkin.m", + "src/gltf/gltfkit/GLTFSkin.mm", "src/gltf/gltfkit/GLTFTexture.h", "src/gltf/gltfkit/GLTFTexture.mm", "src/gltf/gltfkit/GLTFTextureSampler.h", - "src/gltf/gltfkit/GLTFTextureSampler.m", + "src/gltf/gltfkit/GLTFTextureSampler.mm", "src/gltf/gltfkit/GLTFUtilities.h", - "src/gltf/gltfkit/GLTFUtilities.m", + "src/gltf/gltfkit/GLTFUtilities.mm", "src/gltf/gltfkit/GLTFVertexDescriptor.h", - "src/gltf/gltfkit/GLTFVertexDescriptor.m", - + "src/gltf/gltfkit/GLTFVertexDescriptor.mm", ] - MLN_GENERATED_DARWIN_STYLE_SOURCE = [ "src/MLNLight.mm", "src/MLNBackgroundStyleLayer.mm", diff --git a/platform/darwin/src/gltf/GLTFMTLRenderItem.m b/platform/darwin/src/gltf/GLTFMTLRenderItem.mm similarity index 100% rename from platform/darwin/src/gltf/GLTFMTLRenderItem.m rename to platform/darwin/src/gltf/GLTFMTLRenderItem.mm diff --git a/platform/darwin/src/gltf/GLTFModelLayer.mm b/platform/darwin/src/gltf/GLTFModelLayer.mm index c88150a4e31..b21e7e46a7f 100644 --- a/platform/darwin/src/gltf/GLTFModelLayer.mm +++ b/platform/darwin/src/gltf/GLTFModelLayer.mm @@ -9,7 +9,6 @@ #import #import "MLNBackendResource.h" #import "MLNMapView.h" -#import "MLNMapProjection.h" #include #import "GLTFManagerRenderingEnvironmentMetal.hpp" #import "GLTFManager.hpp" @@ -344,11 +343,6 @@ - (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingCon _viewportSize.y = resource.mtkView.drawableSize.height; _manager->setDrawableSize(_viewportSize.x, _viewportSize.y); - MLNMapProjection *proj2 = mapView.mapProjection; - _manager->_metersPerPixel = proj2.metersPerPoint / 2.0; - _manager->setTiltDeg(90-mapView.camera.pitch); - _manager->setRotationDeg(-mapView.camera.heading); - float timestep = (1 / 60.0f); _manager->updateScene(timestep); diff --git a/platform/darwin/src/gltf/GLTFModelLoader.m b/platform/darwin/src/gltf/GLTFModelLoader.mm similarity index 100% rename from platform/darwin/src/gltf/GLTFModelLoader.m rename to platform/darwin/src/gltf/GLTFModelLoader.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAccessor.m b/platform/darwin/src/gltf/gltfkit/GLTFAccessor.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFAccessor.m rename to platform/darwin/src/gltf/gltfkit/GLTFAccessor.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.m b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm similarity index 87% rename from platform/darwin/src/gltf/gltfkit/GLTFAnimation.m rename to platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm index 7bde7e06013..e716fc0113f 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm @@ -15,6 +15,7 @@ // #import "GLTFAnimation.h" +#include "GLTFUtilities.h" #import "GLTFAccessor.h" #import "GLTFBufferView.h" #import "GLTFBuffer.h" @@ -27,11 +28,11 @@ - (NSString *)description { } - (const void *)inputValues { - return [self.inputAccessor.bufferView.buffer contents] + self.inputAccessor.bufferView.offset + self.inputAccessor.offset; + return (uint8_t*)[self.inputAccessor.bufferView.buffer contents] + self.inputAccessor.bufferView.offset + self.inputAccessor.offset; } - (const void *)outputValues { - return [self.outputAccessor.bufferView.buffer contents] + self.outputAccessor.bufferView.offset + self.outputAccessor.offset; + return (uint8_t*)[self.outputAccessor.bufferView.buffer contents] + self.outputAccessor.bufferView.offset + self.outputAccessor.offset; } - (int)keyFrameCount { @@ -48,14 +49,14 @@ - (NSString *)description { - (NSTimeInterval)startTime { GLTFAnimationSampler *sampler = self.sampler; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; float startTime = timeValues[0]; return startTime; } - (NSTimeInterval)endTime { GLTFAnimationSampler *sampler = self.sampler; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; int keyFrameCount = sampler.keyFrameCount; float endTime = timeValues[keyFrameCount - 1]; return endTime; @@ -81,7 +82,7 @@ - (void)runAtTime:(NSTimeInterval)time { int keyFrameCount = sampler.keyFrameCount; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; float minTime = timeValues[0]; float maxTime = timeValues[keyFrameCount - 1]; @@ -115,7 +116,7 @@ - (void)runAtTime:(NSTimeInterval)time { NSLog(@"WARNING: Only float accessors are supported for rotation animations. This will only be reported once."); }); } - const GLTFQuaternion *rotationValues = sampler.outputValues; + const GLTFQuaternion *rotationValues = (const GLTFQuaternion*)sampler.outputValues; GLTFQuaternion previousRotation = rotationValues[previousKeyFrame]; GLTFQuaternion nextRotation = rotationValues[nextKeyFrame]; @@ -123,11 +124,11 @@ - (void)runAtTime:(NSTimeInterval)time { target.rotationQuaternion = interpRotation; } else if ([path isEqualToString:@"translation"]) { - const GLTFVector3 *translationValues = sampler.outputValues; + const GLTFVector3 *translationValues = (const GLTFVector3*)sampler.outputValues; GLTFVector3 previousTranslation = translationValues[previousKeyFrame]; GLTFVector3 nextTranslation = translationValues[nextKeyFrame]; - + GLTFVector3 interpTranslation = (GLTFVector3) { ((1 - frameProgress) * previousTranslation.x) + (frameProgress * nextTranslation.x), ((1 - frameProgress) * previousTranslation.y) + (frameProgress * nextTranslation.y), @@ -136,7 +137,7 @@ - (void)runAtTime:(NSTimeInterval)time { target.translation = (simd_float3){ interpTranslation.x, interpTranslation.y, interpTranslation.z }; } else if ([path isEqualToString:@"scale"]) { - const float *scaleValues = sampler.outputValues; + const float *scaleValues = (const float*)sampler.outputValues; float previousScale = scaleValues[previousKeyFrame]; float nextScale = scaleValues[nextKeyFrame]; @@ -151,7 +152,7 @@ - (void)runAtTime:(NSTimeInterval)time { NSLog(@"WARNING: Only scalar float accessors are supported for weight animations. This will only be reported once."); }); } - const float *weightValues = sampler.outputValues; + const float *weightValues = (const float*)sampler.outputValues; long weightCount = sampler.outputAccessor.count / keyFrameCount; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAsset.m b/platform/darwin/src/gltf/gltfkit/GLTFAsset.mm similarity index 96% rename from platform/darwin/src/gltf/gltfkit/GLTFAsset.m rename to platform/darwin/src/gltf/gltfkit/GLTFAsset.mm index b54289e4dde..ccda5f5ed2d 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAsset.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFAsset.mm @@ -15,6 +15,7 @@ // #import "GLTFAsset.h" +#include "GLTFEnums.h" #import "GLTFAnimation.h" #import "GLTFAccessor.h" #import "GLTFBinaryChunk.h" @@ -263,11 +264,11 @@ - (void)readBinaryChunks:(NSData *)assetData { [assetData getBytes:&chunkHeader range:NSMakeRange(offset, sizeof(chunkHeader))]; - NSData *chunkData = [NSData dataWithBytesNoCopy:(void *)(assetData.bytes + offset + sizeof(chunkHeader)) + NSData *chunkData = [NSData dataWithBytesNoCopy:(void *)((uint8_t*)assetData.bytes + offset + sizeof(chunkHeader)) length:chunkHeader.length freeWhenDone:NO]; chunk.data = chunkData; - chunk.chunkType = chunkHeader.type; + chunk.chunkType = (GLTFChunkType)chunkHeader.type; [chunks addObject:chunk]; @@ -296,7 +297,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { NSMutableArray *accessors = [NSMutableArray arrayWithCapacity:accessorsMap.count]; for (NSDictionary *properties in accessorsMap) { GLTFAccessor *accessor = [[GLTFAccessor alloc] init]; - accessor.componentType = [properties[@"componentType"] integerValue]; + accessor.componentType = (GLTFDataType)[properties[@"componentType"] integerValue]; accessor.dimension = GLTFDataDimensionForName(properties[@"type"]); accessor.offset = [properties[@"byteOffset"] integerValue]; accessor.count = [properties[@"count"] integerValue]; @@ -315,7 +316,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { NSLog(@"WARNING: Accessor had misaligned offset %d, which is not a multiple of %d. Building auxiliary buffer of length %d and continuing...", (int)dataOffset, (int)alignment, (int)length); id buffer = [_bufferAllocator newBufferWithLength:length]; - memcpy(buffer.contents, accessor.bufferView.buffer.contents + accessor.bufferView.offset + accessor.offset, buffer.length); + memcpy(buffer.contents, (uint8_t*)accessor.bufferView.buffer.contents + accessor.bufferView.offset + accessor.offset, buffer.length); _buffers = [_buffers arrayByAddingObject:buffer]; GLTFBufferView *bufferView = [GLTFBufferView new]; @@ -329,7 +330,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { } } - __block GLTFValueRange valueRange = { 0 }; + __block GLTFValueRange valueRange = { {}, {} }; NSArray *minValues = properties[@"min"]; [minValues enumerateObjectsUsingBlock:^(NSNumber *num, NSUInteger index, BOOL *stop) { valueRange.minValue[index] = num.floatValue; @@ -408,7 +409,7 @@ - (BOOL)loadBufferViews:(NSArray *)bufferViewsMap { bufferView.length = [properties[@"byteLength"] integerValue]; bufferView.stride = [properties[@"byteStride"] integerValue]; bufferView.offset = [properties[@"byteOffset"] integerValue]; - bufferView.target = [properties[@"target"] integerValue]; + bufferView.target = (GLTFTarget)[properties[@"target"] integerValue]; // if ((bufferView.buffer != nil) && (bufferView.offset % 16 != 0)) { // NSLog(@"WARNING: Buffer view %d had misaligned offset of %d. Creating auxilliary buffer of length %d and continuing...", @@ -435,10 +436,10 @@ - (BOOL)loadSamplers:(NSArray *)samplersMap { NSMutableArray *samplers = [NSMutableArray arrayWithCapacity:samplersMap.count]; for (NSDictionary *properties in samplersMap) { GLTFTextureSampler *sampler = [[GLTFTextureSampler alloc] init]; - sampler.minFilter = [properties[@"minFilter"] integerValue] ?: sampler.minFilter; - sampler.magFilter = [properties[@"magFilter"] integerValue] ?: sampler.magFilter; - sampler.sAddressMode = [properties[@"wrapS"] integerValue] ?: sampler.sAddressMode; - sampler.tAddressMode = [properties[@"wrapT"] integerValue] ?: sampler.tAddressMode; + sampler.minFilter = (GLTFSamplingFilter)([properties[@"minFilter"] integerValue] ?: sampler.minFilter); + sampler.magFilter = (GLTFSamplingFilter)([properties[@"magFilter"] integerValue] ?: sampler.magFilter); + sampler.sAddressMode = (GLTFAddressMode)([properties[@"wrapS"] integerValue] ?: sampler.sAddressMode); + sampler.tAddressMode = (GLTFAddressMode)([properties[@"wrapT"] integerValue] ?: sampler.tAddressMode); sampler.name = properties[@"name"]; sampler.extensions = properties[@"extensions"]; sampler.extras = properties[@"extras"]; @@ -510,10 +511,10 @@ - (BOOL)loadTextures:(NSArray *)texturesMap { texture.image = _images[imageIndex]; } - texture.format = [properties[@"format"] integerValue] ?: texture.format; - texture.internalFormat = [properties[@"internalFormat"] integerValue] ?: texture.internalFormat; - texture.target = [properties[@"target"] integerValue] ?: texture.target; - texture.type = [properties[@"type"] integerValue] ?: texture.type; + texture.format = (GLTFTextureFormat)([properties[@"format"] integerValue] ?: texture.format); + texture.internalFormat = (GLTFTextureFormat)([properties[@"internalFormat"] integerValue] ?: texture.internalFormat); + texture.target = (GLTFTextureTarget)([properties[@"target"] integerValue] ?: texture.target); + texture.type = (GLTFTextureType)([properties[@"type"] integerValue] ?: texture.type); texture.name = properties[@"name"]; texture.extensions = properties[@"extensions"]; texture.extras = properties[@"extras"]; @@ -665,12 +666,12 @@ - (BOOL)loadMeshes:(NSArray *)meshesMap { NSUInteger indexAccessorIndex = [submeshProperties[@"indices"] intValue]; if (indexAccessorIndex < _accessors.count) { GLTFAccessor *indexAccessor = _accessors[indexAccessorIndex]; - if (indexAccessor.componentType == GLTFTextureTypeUChar) { + if (indexAccessor.componentType == (GLTFDataType)GLTFTextureTypeUChar) { // Fix up 8-bit indices, since they're unsupported in modern APIs - uint8_t *sourceIndices = indexAccessor.bufferView.buffer.contents + indexAccessor.offset + indexAccessor.bufferView.offset; + uint8_t *sourceIndices = (uint8_t*)indexAccessor.bufferView.buffer.contents + indexAccessor.offset + indexAccessor.bufferView.offset; id shortBuffer = [_bufferAllocator newBufferWithLength:indexAccessor.count * sizeof(uint16_t)]; - uint16_t *destIndices = shortBuffer.contents; + uint16_t *destIndices = (uint16_t*)shortBuffer.contents; for (int i = 0; i < indexAccessor.count; ++i) { destIndices[i] = (uint16_t)sourceIndices[i]; } diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.m b/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.m rename to platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBufferView.m b/platform/darwin/src/gltf/gltfkit/GLTFBufferView.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFBufferView.m rename to platform/darwin/src/gltf/gltfkit/GLTFBufferView.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFCamera.m b/platform/darwin/src/gltf/gltfkit/GLTFCamera.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFCamera.m rename to platform/darwin/src/gltf/gltfkit/GLTFCamera.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.m b/platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.m rename to platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.m b/platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.m rename to platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFImage.m b/platform/darwin/src/gltf/gltfkit/GLTFImage.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFImage.m rename to platform/darwin/src/gltf/gltfkit/GLTFImage.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.m b/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFKHRLight.m rename to platform/darwin/src/gltf/gltfkit/GLTFKHRLight.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm similarity index 97% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm index ba6f8eb1e04..95c113d17c1 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm @@ -77,7 +77,7 @@ vImageConverter_Release(converter); CFRelease(srcData); - return dstPixels; + return (__fp16*)dstPixels; } unsigned char *GLTFMTLConvertImageToRGBA8U(CGImageRef image) @@ -108,7 +108,7 @@ .bitsPerComponent = sizeof(unsigned char) * 8, .bitsPerPixel = sizeof(unsigned char) * 8 * 4, .colorSpace = dstColorSpace, - .bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaLast + .bitmapInfo = (CGBitmapInfo)kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaLast }; vImage_Error error = kvImageNoError; @@ -138,7 +138,7 @@ vImageConverter_Release(converter); CFRelease(srcData); - return dstPixels; + return (unsigned char*)dstPixels; } @interface GLTFMTLTextureLoader () @@ -201,7 +201,7 @@ - (instancetype)initWithDevice:(id)device { height:height mipmapped:mipmapped]; - id texture = [self newTextureWithBytes:dstBytes + id texture = [self newTextureWithBytes:(const unsigned char*)dstBytes bytesPerRow:bytesPerRow descriptor:descriptor options:options diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm similarity index 98% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm index 182067e1b40..1dc446902fb 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm @@ -29,11 +29,12 @@ MTLPrimitiveType GLTFMTLPrimitiveTypeForPrimitiveType(GLTFPrimitiveType gltfType case GLTFPrimitiveTypeTriangleStrip: return MTLPrimitiveTypeTriangleStrip; - // Not supported; need to duplicate first element and restitch into tri strip, respectively + // Not supported; need to duplicate first element and restitch into tri strip, respectively case GLTFPrimitiveTypeLineLoop: case GLTFPrimitiveTypeTriangleFan: default: - return -1; + NSLog(@"Unsupported primitive type function %d", (int)gltfType); + return MTLPrimitiveTypePoint; } } diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMaterial.m b/platform/darwin/src/gltf/gltfkit/GLTFMaterial.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMaterial.m rename to platform/darwin/src/gltf/gltfkit/GLTFMaterial.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMesh.m b/platform/darwin/src/gltf/gltfkit/GLTFMesh.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMesh.m rename to platform/darwin/src/gltf/gltfkit/GLTFMesh.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFNode.m b/platform/darwin/src/gltf/gltfkit/GLTFNode.mm similarity index 98% rename from platform/darwin/src/gltf/gltfkit/GLTFNode.m rename to platform/darwin/src/gltf/gltfkit/GLTFNode.mm index 52dd177fde1..2630d49960c 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFNode.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFNode.mm @@ -119,11 +119,11 @@ - (GLTFBoundingBox)approximateBounds { } - (GLTFBoundingBox)_approximateBoundsRecursive:(simd_float4x4)transform { - GLTFBoundingBox bounds = { 0 }; + GLTFBoundingBox bounds = { 0, 0 }; if (self.mesh != nil) { for (GLTFSubmesh *submesh in self.mesh.submeshes) { - GLTFBoundingBox submeshBounds = { 0 }; + GLTFBoundingBox submeshBounds = { 0, 0 }; GLTFAccessor *positionAccessor = submesh.accessorsForAttributes[GLTFAttributeSemanticPosition]; GLTFValueRange positionRange = positionAccessor.valueRange; submeshBounds.minPoint.x = positionRange.minValue[0]; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFObject.m b/platform/darwin/src/gltf/gltfkit/GLTFObject.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFObject.m rename to platform/darwin/src/gltf/gltfkit/GLTFObject.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFScene.m b/platform/darwin/src/gltf/gltfkit/GLTFScene.mm similarity index 97% rename from platform/darwin/src/gltf/gltfkit/GLTFScene.m rename to platform/darwin/src/gltf/gltfkit/GLTFScene.mm index 3ec31b78f08..b3f0a690127 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFScene.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFScene.mm @@ -40,7 +40,7 @@ - (void)addNode:(GLTFNode *)node { } - (GLTFBoundingBox)approximateBounds { - GLTFBoundingBox sceneBounds = { 0 }; + GLTFBoundingBox sceneBounds = { 0, 0 }; for (GLTFNode *node in self.nodes) { GLTFBoundingBox nodeBounds = node.approximateBounds; GLTFBoundingBoxUnion(&sceneBounds, nodeBounds); diff --git a/platform/darwin/src/gltf/gltfkit/GLTFSkin.m b/platform/darwin/src/gltf/gltfkit/GLTFSkin.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFSkin.m rename to platform/darwin/src/gltf/gltfkit/GLTFSkin.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.m b/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.m rename to platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.m b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm similarity index 99% rename from platform/darwin/src/gltf/gltfkit/GLTFUtilities.m rename to platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm index effa58a0669..ecce6e6fc0b 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm @@ -15,6 +15,7 @@ // #import "GLTFUtilities.h" +#include "GLTFEnums.h" bool GLTFBoundingBoxIsEmpty(GLTFBoundingBox b) { return (b.minPoint.x == b.maxPoint.x) && (b.minPoint.y == b.maxPoint.y) && (b.minPoint.z == b.maxPoint.z); @@ -115,7 +116,7 @@ GLTFDataDimension GLTFDataDimensionForName(NSString *name) { return GLTFDataDimensionMatrix4x4; } - return -1; + return GLTFDataDimensionUnknown; } size_t GLTFSizeOfDataType(GLTFDataType type) { diff --git a/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.m b/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.m rename to platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.mm diff --git a/platform/macos/src/MLNMapView+Impl.h b/platform/macos/src/MLNMapView+Impl.h index bb66a2966fb..18868475e27 100644 --- a/platform/macos/src/MLNMapView+Impl.h +++ b/platform/macos/src/MLNMapView+Impl.h @@ -2,6 +2,8 @@ #import #import +#import "MLNBackendResource.h" + @class MLNMapView; typedef struct _CGLContextObject* CGLContextObj; @@ -23,6 +25,8 @@ class MLNMapViewImpl : public mbgl::MapObserver { // Called by the view delegate when it's time to render. void render(); + virtual MLNBackendResource getObject() = 0; + // mbgl::MapObserver implementation void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) override; void onCameraIsChanging() override; diff --git a/platform/macos/src/MLNMapView+Metal.h b/platform/macos/src/MLNMapView+Metal.h index f6d12e66c60..a366e38a1ba 100644 --- a/platform/macos/src/MLNMapView+Metal.h +++ b/platform/macos/src/MLNMapView+Metal.h @@ -37,6 +37,8 @@ class MLNMapViewMetalImpl final : public MLNMapViewImpl, mbgl::PremultipliedImage readStillImage() override; + MLNBackendResource getObject() override; + private: bool presentsWithTransaction = false; }; diff --git a/platform/macos/src/MLNMapView+Metal.mm b/platform/macos/src/MLNMapView+Metal.mm index 6628d85cb28..e0f8abe6c3b 100644 --- a/platform/macos/src/MLNMapView+Metal.mm +++ b/platform/macos/src/MLNMapView+Metal.mm @@ -158,3 +158,14 @@ void swap() override { // return readFramebuffer(mapView.framebufferSize); // TODO: RendererBackend::readFramebuffer return {}; } + +MLNBackendResource MLNMapViewMetalImpl::getObject() { + auto& resource = getResource(); + auto renderPassDescriptor = resource.getRenderPassDescriptor().get(); + return { + resource.mtlView, + resource.mtlView.device, + [MTLRenderPassDescriptor renderPassDescriptor], + resource.commandBuffer + }; +} \ No newline at end of file diff --git a/platform/macos/src/MLNMapView+OpenGL.h b/platform/macos/src/MLNMapView+OpenGL.h index fb882b7072b..2daf3aaab9d 100644 --- a/platform/macos/src/MLNMapView+OpenGL.h +++ b/platform/macos/src/MLNMapView+OpenGL.h @@ -38,4 +38,6 @@ class MLNMapViewOpenGLImpl final : public MLNMapViewImpl, mbgl::PremultipliedImage readStillImage() override; CGLContextObj getCGLContextObj() override; + + MLNBackendResource getObject() override; }; diff --git a/platform/macos/src/MLNMapView+OpenGL.mm b/platform/macos/src/MLNMapView+OpenGL.mm index de747afbcd3..83409e00a35 100644 --- a/platform/macos/src/MLNMapView+OpenGL.mm +++ b/platform/macos/src/MLNMapView+OpenGL.mm @@ -87,3 +87,7 @@ void bind() override { MLNOpenGLLayer* layer = (MLNOpenGLLayer*)mapView.layer; return layer.openGLContext.CGLContextObj; } + +MLNBackendResource MLNMapViewOpenGLImpl::getObject() { + return MLNBackendResource(); +} \ No newline at end of file diff --git a/platform/macos/src/MLNMapView.h b/platform/macos/src/MLNMapView.h index d3db2ea6f98..42f93147f79 100644 --- a/platform/macos/src/MLNMapView.h +++ b/platform/macos/src/MLNMapView.h @@ -2,6 +2,7 @@ #import #import +#import "MLNBackendResource.h" #import "MLNFoundation.h" #import "MLNGeometry.h" #import "MLNStyle.h" @@ -1270,6 +1271,7 @@ around the returned camera object if it were set as the receiver’s camera. */ @property (nonatomic) MLNMapDebugMaskOptions debugMask; +- (MLNBackendResource)backendResource; @end NS_ASSUME_NONNULL_END diff --git a/platform/macos/src/MLNMapView.mm b/platform/macos/src/MLNMapView.mm index c8d54085e18..657b1ec37a4 100644 --- a/platform/macos/src/MLNMapView.mm +++ b/platform/macos/src/MLNMapView.mm @@ -3083,4 +3083,8 @@ - (void)setDebugMask:(MLNMapDebugMaskOptions)debugMask { _mbglMap->setDebug(options); } +- (MLNBackendResource)backendResource { + return _mbglView->getObject(); +} + @end