fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
library filament_dart;
|
||||
|
||||
export 'dart_filament/entities/filament_entity.dart';
|
||||
export 'dart_filament/abstract_filament_viewer.dart';
|
||||
export 'dart_filament/filament_viewer_impl.dart';
|
||||
export 'dart_filament/dart_filament.g.dart';
|
||||
|
||||
@@ -1017,6 +1017,7 @@ namespace flutter_filament
|
||||
else if (!_swapChain)
|
||||
{
|
||||
Log("No swapchain");
|
||||
return;
|
||||
}
|
||||
|
||||
// if (_frameCount == 60)
|
||||
|
||||
@@ -61,7 +61,8 @@ class FlutterFilamentPlugin extends FilamentViewer {
|
||||
int width, int height, int offsetLeft, int offsetRight) async {
|
||||
var result = await _channel
|
||||
.invokeMethod("createTexture", [width, height, offsetLeft, offsetLeft]);
|
||||
if (result == null) {
|
||||
|
||||
if (result == null || result[0] == -1) {
|
||||
throw Exception("Failed to create texture");
|
||||
}
|
||||
viewportDimensions = (width.toDouble(), height.toDouble());
|
||||
@@ -99,7 +100,7 @@ class FlutterFilamentPlugin extends FilamentViewer {
|
||||
|
||||
var newTexture =
|
||||
await createTexture(width, height, offsetLeft, offsetRight);
|
||||
if (newTexture == null) {
|
||||
if (newTexture == null || newTexture.flutterTextureId == -1) {
|
||||
throw Exception("Failed to create texture");
|
||||
}
|
||||
await createSwapChain(width.toDouble(), height.toDouble(),
|
||||
|
||||
@@ -7,8 +7,7 @@ import GLKit
|
||||
|
||||
var pixelBufferAttrs = [
|
||||
kCVPixelBufferPixelFormatTypeKey: NSNumber(value: kCVPixelFormatType_32ABGR ),
|
||||
kCVPixelBufferOpenGLCompatibilityKey: kCFBooleanFalse!,
|
||||
// kCVPixelBufferIOSurfacePropertiesKey: [Any:Any] as CFDictionary
|
||||
kCVPixelBufferIOSurfacePropertiesKey: [:] as CFDictionary
|
||||
] as [CFString : Any] as CFDictionary
|
||||
|
||||
@objc public var cvMetalTextureCache:CVMetalTextureCache?
|
||||
@@ -22,6 +21,7 @@ import GLKit
|
||||
}
|
||||
|
||||
@objc public init(width:Int64, height:Int64) {
|
||||
|
||||
self.metalDevice = MTLCreateSystemDefaultDevice()!
|
||||
|
||||
// create pixel buffer
|
||||
@@ -39,6 +39,7 @@ import GLKit
|
||||
nil,
|
||||
&cvMetalTextureCache);
|
||||
if(cvret != 0) {
|
||||
print("Error creating Metal texture cache")
|
||||
metalTextureAddress = -1
|
||||
return
|
||||
}
|
||||
@@ -51,6 +52,7 @@ import GLKit
|
||||
0,
|
||||
&cvMetalTexture)
|
||||
if(cvret != 0) {
|
||||
print("Error creating texture from image")
|
||||
metalTextureAddress = -1
|
||||
return
|
||||
}
|
||||
@@ -60,35 +62,35 @@ import GLKit
|
||||
|
||||
print("Created metal texture @ \(metalTextureAddress)")
|
||||
|
||||
CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
||||
let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
||||
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
||||
// CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
// let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
||||
// let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
||||
// let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
||||
|
||||
guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
||||
return
|
||||
}
|
||||
// guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
||||
// return
|
||||
// }
|
||||
|
||||
for row in 0..<bufferHeight {
|
||||
var pixel = baseAddress + row * bytesPerRow
|
||||
for col in 0..<bufferWidth {
|
||||
let blue = pixel
|
||||
blue.storeBytes(of: 255, as: UInt8.self)
|
||||
// for row in 0..<bufferHeight {
|
||||
// var pixel = baseAddress + row * bytesPerRow
|
||||
// for col in 0..<bufferWidth {
|
||||
// let blue = pixel
|
||||
// blue.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
let red = pixel + 1
|
||||
red.storeBytes(of: 0, as: UInt8.self)
|
||||
// let red = pixel + 1
|
||||
// red.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
let green = pixel + 2
|
||||
green.storeBytes(of: 0, as: UInt8.self)
|
||||
// let green = pixel + 2
|
||||
// green.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
let alpha = pixel + 3
|
||||
alpha.storeBytes(of: 255, as: UInt8.self)
|
||||
// let alpha = pixel + 3
|
||||
// alpha.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
pixel += 4;
|
||||
}
|
||||
}
|
||||
// pixel += 4;
|
||||
// }
|
||||
// }
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
// CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,20 @@ import Foundation
|
||||
import GLKit
|
||||
import FlutterMacOS
|
||||
|
||||
public class FlutterFilamentTexture : NSObject, FlutterTexture {
|
||||
public class FlutterFilamentTexture : DartFilamentTexture, FlutterTexture {
|
||||
|
||||
var texture:DartFilamentTexture
|
||||
var flutterTextureId: Int64 = -1
|
||||
var registry: FlutterTextureRegistry
|
||||
|
||||
init(registry:FlutterTextureRegistry, texture:DartFilamentTexture) {
|
||||
self.texture = texture
|
||||
init(registry:FlutterTextureRegistry, width:Int64, height:Int64) {
|
||||
self.registry = registry
|
||||
super.init()
|
||||
|
||||
super.init(width:width, height:height)
|
||||
self.flutterTextureId = registry.register(self)
|
||||
|
||||
|
||||
}
|
||||
|
||||
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
||||
return Unmanaged.passRetained(texture.pixelBuffer!);
|
||||
return Unmanaged.passRetained(pixelBuffer!);
|
||||
}
|
||||
|
||||
public func onTextureUnregistered(_ texture:FlutterTexture) {
|
||||
@@ -27,7 +24,7 @@ public class FlutterFilamentTexture : NSObject, FlutterTexture {
|
||||
|
||||
public func destroy() {
|
||||
self.registry.unregisterTexture(self.flutterTextureId)
|
||||
self.texture.destroyTexture()
|
||||
self.destroyTexture()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -96,10 +96,13 @@ public class SwiftFlutterFilamentPlugin: NSObject, FlutterPlugin {
|
||||
let width = args[0] as! Int64
|
||||
let height = args[1] as! Int64
|
||||
|
||||
let texture = DartFilamentTexture(width: width, height: height)
|
||||
self.texture = FlutterFilamentTexture(registry: registry, texture: texture)
|
||||
self.texture = FlutterFilamentTexture(registry: registry, width: width, height: height)
|
||||
|
||||
result([self.texture!.flutterTextureId as Any, texture.metalTextureAddress, nil])
|
||||
if(self.texture?.metalTextureAddress == -1) {
|
||||
result(nil)
|
||||
} else {
|
||||
result([self.texture!.flutterTextureId as Any, self.texture?.metalTextureAddress, nil])
|
||||
}
|
||||
case "destroyTexture":
|
||||
self.texture?.destroy()
|
||||
self.texture = nil
|
||||
|
||||
Reference in New Issue
Block a user