(macos) add isStencil argument for creating depth texture on macOS (if true, creates texture with .depth24Unorm_stencil8

This commit is contained in:
Nick Fisher
2025-06-09 18:24:15 +08:00
parent 8866ffe210
commit 4c95bc5b70
2 changed files with 3 additions and 6 deletions

View File

@@ -310,7 +310,7 @@ SWIFT_CLASS("_TtC12swift_module20ThermionTextureSwift")
@property (nonatomic, strong) id <MTLTexture> _Nullable metalTexture;
@property (nonatomic) NSInteger metalTextureAddress;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithWidth:(int64_t)width height:(int64_t)height isDepth:(BOOL)isDepth OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithWidth:(int64_t)width height:(int64_t)height isDepth:(BOOL)isDepth isStencil:(BOOL)isStencil OBJC_DESIGNATED_INITIALIZER;
- (void)destroyTexture;
- (BOOL)fillWithPNGImageWithImageURL:(NSURL * _Nonnull)imageURL SWIFT_WARN_UNUSED_RESULT;
- (void)fillColor;

View File

@@ -21,7 +21,7 @@ import GLKit
}
@objc public init(width:Int64, height:Int64, isDepth:Bool) {
@objc public init(width:Int64, height:Int64, isDepth:Bool, isStencil:Bool) {
if(self.metalDevice == nil) {
self.metalDevice = MTLCreateSystemDefaultDevice()!
}
@@ -30,7 +30,7 @@ import GLKit
print("Creating depth texture")
// Create a proper depth texture without IOSurface backing
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: .depth32Float,
pixelFormat: isStencil ? .depth24Unorm_stencil8 : .depth32Float_stencil8,
width: Int(width),
height: Int(height),
mipmapped: false)
@@ -45,9 +45,6 @@ import GLKit
print("Creating color texture")
// let pixelFormat: MTLPixelFormat = isDepth ? .depth32Float : .bgra8Unorm
// let cvPixelFormat = isDepth ? kCVPixelFormatType_DepthFloat32 : kCVPixelFormatType_32BGRA
if(CVPixelBufferCreate(kCFAllocatorDefault, Int(width), Int(height),
kCVPixelFormatType_32BGRA, pixelBufferAttrs, &pixelBuffer) != kCVReturnSuccess) {