This commit is contained in:
Nick Fisher
2024-04-30 14:14:54 +08:00
parent 8f9e309c34
commit 14b0b674c5
28 changed files with 423 additions and 1787 deletions

View File

@@ -25,6 +25,29 @@ void main(List<String> args) async {
"${config.packageRoot.toFilePath()}/native/include/material/image.c",
]);
var frameworks = [];
if (platform == "ios") {
frameworks.addAll([
'Foundation',
'CoreGraphics',
'QuartzCore',
'GLKit',
"Metal",
'CoreVideo',
'OpenGLES'
]);
} else if (platform == "macos") {
frameworks.addAll([
'Foundation',
'CoreVideo',
'Cocoa',
"Metal",
]);
}
frameworks = frameworks.expand((f) => ["-framework", f]).toList();
final cbuilder = CBuilder.library(
name: packageName,
language: Language.cpp,
@@ -32,16 +55,10 @@ void main(List<String> args) async {
sources: sources,
includes: ['native/include', 'native/include/filament'],
flags: [
'-mmacosx-version-min=13.0',
if (platform == "macos") '-mmacosx-version-min=13.0',
if (platform == "ios") '-mios-version-min=13.0',
...frameworks,
'-std=c++17',
'-framework',
'Foundation',
'-framework',
'CoreVideo',
'-framework',
'Cocoa',
'-framework',
'Metal',
"-lfilament",
"-lbackend",
"-lfilameshio",
@@ -68,8 +85,8 @@ void main(List<String> args) async {
"-luberarchive",
"-lzstd",
"-lstdc++",
"-lbluegl",
"-lbluevk",
if (platform == "macos") "-lbluegl",
if (platform == "macos") "-lbluevk",
"-lbasis_transcoder",
"-L$libDir",
"-force_load",

View File

@@ -48,8 +48,6 @@ class FilamentViewer extends AbstractFilamentViewer {
var _sharedContext = nullptr.cast<Void>();
late final Pointer<Void> _surface;
///
/// This controller uses platform channels to bridge Dart with the C/C++ code for the Filament API.
/// Setting up the context/texture (since this is platform-specific) and the render ticker are platform-specific; all other methods are passed through by the platform channel to the methods specified in FlutterFilamentApi.h.
@@ -57,14 +55,12 @@ class FilamentViewer extends AbstractFilamentViewer {
FilamentViewer(
{RenderCallback? renderCallback,
Pointer<Void>? renderCallbackOwner,
Pointer<Void>? surface,
required this.resourceLoader,
Pointer<Void>? driver,
Pointer<Void>? sharedContext,
this.uberArchivePath}) {
this._renderCallbackOwner = renderCallbackOwner ?? nullptr;
this._renderCallback = renderCallback ?? nullptr;
this._surface = surface ?? nullptr;
this._driver = driver ?? nullptr;
this._sharedContext = sharedContext ?? nullptr;
@@ -87,11 +83,11 @@ class FilamentViewer extends AbstractFilamentViewer {
});
}
Future createSwapChain(double width, double height) async {
Future createSwapChain(double width, double height,
{Pointer<Void>? surface}) async {
await _withVoidCallback((callback) {
print("VIEWER IS $_viewer");
create_swap_chain_ffi(
_viewer!, _surface, width.toInt(), height.toInt(), callback);
create_swap_chain_ffi(_viewer!, surface ?? nullptr, width.toInt(),
height.toInt(), callback);
});
}

View File

@@ -0,0 +1,46 @@
#ifndef RESOURCE_BUFFER_H
#define RESOURCE_BUFFER_H
#include <stdint.h>
#include <stdlib.h>
//
// A ResourceBuffer is a unified interface for working with
// binary assets across various platforms.
// This is simply:
// 1) a pointer to some data
// 2) the length of the data
// 3) an ID that can be passed back to the native platform to release the underlying asset when needed.
//
struct ResourceBuffer
{
const void *const data;
const int32_t size;
const int32_t id;
#if defined(__cplusplus)
ResourceBuffer(void *const data, int32_t size, int32_t id) : data(data), size(size), id(id) {}
#endif
};
typedef struct ResourceBuffer ResourceBuffer;
typedef void (*LoadFilamentResourceIntoOutPointer)(const char *uri, ResourceBuffer *out);
typedef ResourceBuffer (*LoadFilamentResource)(const char *uri);
typedef ResourceBuffer (*LoadFilamentResourceFromOwner)(const char *const, void *const owner);
typedef void (*FreeFilamentResource)(ResourceBuffer);
typedef void (*FreeFilamentResourceFromOwner)(ResourceBuffer, void *const owner);
struct ResourceLoaderWrapper
{
LoadFilamentResource loadResource;
FreeFilamentResource freeResource;
LoadFilamentResourceFromOwner loadFromOwner;
FreeFilamentResourceFromOwner freeFromOwner;
void *owner;
LoadFilamentResourceIntoOutPointer loadToOut;
};
typedef struct ResourceLoaderWrapper ResourceLoaderWrapper;
ResourceLoaderWrapper *make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void *const owner);
#endif

View File

@@ -1,45 +1,7 @@
#ifndef RESOURCE_BUFFER_H
#define RESOURCE_BUFFER_H
#ifndef RESOURCE_BUFFER_HPP
#define RESOURCE_BUFFER_HPP
#include <stdint.h>
#include <stdlib.h>
//
// A ResourceBuffer is a unified interface for working with
// binary assets across various platforms.
// This is simply:
// 1) a pointer to some data
// 2) the length of the data
// 3) an ID that can be passed back to the native platform to release the underlying asset when needed.
//
struct ResourceBuffer
{
const void *const data;
const int32_t size;
const int32_t id;
#if defined(__cplusplus)
ResourceBuffer(void *const data, int32_t size, int32_t id) : data(data), size(size), id(id) {}
#endif
};
typedef struct ResourceBuffer ResourceBuffer;
typedef void (*LoadFilamentResourceIntoOutPointer)(const char *uri, ResourceBuffer *out);
typedef ResourceBuffer (*LoadFilamentResource)(const char *uri);
typedef ResourceBuffer (*LoadFilamentResourceFromOwner)(const char *const, void *const owner);
typedef void (*FreeFilamentResource)(ResourceBuffer);
typedef void (*FreeFilamentResourceFromOwner)(ResourceBuffer, void *const owner);
struct ResourceLoaderWrapper
{
LoadFilamentResource loadResource;
FreeFilamentResource freeResource;
LoadFilamentResourceFromOwner loadFromOwner;
FreeFilamentResourceFromOwner freeFromOwner;
void *owner;
LoadFilamentResourceIntoOutPointer loadToOut;
};
typedef struct ResourceLoaderWrapper ResourceLoaderWrapper;
#include "ResourceBuffer.h"
#if defined(__cplusplus)