factor out resource loading into header
This commit is contained in:
@@ -7,7 +7,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.8.2"
|
version: "2.9.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -21,28 +21,21 @@ packages:
|
|||||||
name: characters
|
name: characters
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.2.1"
|
||||||
charcode:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: charcode
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.3.1"
|
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: clock
|
name: clock
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0"
|
version: "1.16.0"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -56,7 +49,7 @@ packages:
|
|||||||
name: fake_async
|
name: fake_async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.3.1"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -87,28 +80,28 @@ packages:
|
|||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.11"
|
version: "0.12.12"
|
||||||
|
material_color_utilities:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: material_color_utilities
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.5"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
version: "1.8.0"
|
||||||
mimetic_filament:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
path: ".."
|
|
||||||
relative: true
|
|
||||||
source: path
|
|
||||||
version: "0.0.1"
|
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0"
|
version: "1.8.2"
|
||||||
plugin_platform_interface:
|
plugin_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -116,6 +109,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.0.1"
|
||||||
|
polyvox_filament:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: ".."
|
||||||
|
relative: true
|
||||||
|
source: path
|
||||||
|
version: "0.0.1"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -127,7 +127,7 @@ packages:
|
|||||||
name: source_span
|
name: source_span
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.1"
|
version: "1.9.0"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -148,35 +148,28 @@ packages:
|
|||||||
name: string_scanner
|
name: string_scanner
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
term_glyph:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: term_glyph
|
name: term_glyph
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.1"
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.3"
|
version: "0.4.12"
|
||||||
typed_data:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: typed_data
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.3.0"
|
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.12.0 <3.0.0"
|
dart: ">=2.17.1 <3.0.0"
|
||||||
flutter: ">=1.20.0"
|
flutter: ">=1.20.0"
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
|
#include <polyvox_filament/polyvox_filament_plugin.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
|
PolyvoxFilamentPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("PolyvoxFilamentPlugin"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
|
polyvox_filament
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||||
@@ -13,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
|||||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
||||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
||||||
endforeach(plugin)
|
endforeach(plugin)
|
||||||
|
|
||||||
|
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
|
||||||
|
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
|
||||||
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
|
||||||
|
endforeach(ffi_plugin)
|
||||||
|
|||||||
63
linux/include/polyvox_filament/resource_loader.hpp
Normal file
63
linux/include/polyvox_filament/resource_loader.hpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#ifndef POLYVOX_FILAMENT_LINUX_RESOURCE_LOADER_H
|
||||||
|
#define POLYVOX_FILAMENT_LINUX_RESOURCE_LOADER_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "ResourceBuffer.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
static map<uint32_t, void*> _file_assets;
|
||||||
|
static uint32_t _i = 0;
|
||||||
|
|
||||||
|
ResourceBuffer loadResource(const char* name) {
|
||||||
|
|
||||||
|
char cwd[PATH_MAX];
|
||||||
|
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||||
|
std::cout << "Current working dir: " << cwd << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name_str(name);
|
||||||
|
auto id = _i++;
|
||||||
|
|
||||||
|
if (name_str.rfind("file://", 0) == 0) {
|
||||||
|
name_str = name_str.substr(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
name_str = string(cwd) + string("/") + name_str;
|
||||||
|
|
||||||
|
std::cout << "Loading resource at " << name_str.c_str() << std::endl;
|
||||||
|
|
||||||
|
streampos length;
|
||||||
|
ifstream is(name_str, ios::binary);
|
||||||
|
if(!is) {
|
||||||
|
std::cout << "Failed to find resource at file path " << name_str.c_str() << std::endl;
|
||||||
|
return ResourceBuffer(nullptr, 0, -1);
|
||||||
|
}
|
||||||
|
is.seekg (0, ios::end);
|
||||||
|
length = is.tellg();
|
||||||
|
char * buffer;
|
||||||
|
buffer = new char [length];
|
||||||
|
is.seekg (0, ios::beg);
|
||||||
|
is.read (buffer, length);
|
||||||
|
is.close();
|
||||||
|
_file_assets[id] = buffer;
|
||||||
|
return ResourceBuffer(buffer, length, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void freeResource(uint32_t id) {
|
||||||
|
std::cout << "Freeing resource " << id << std::endl;
|
||||||
|
auto it = _file_assets.find(id);
|
||||||
|
if (it != _file_assets.end()) {
|
||||||
|
free(it->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <flutter_linux/fl_texture_gl.h>
|
#include <flutter_linux/fl_texture_gl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -18,6 +17,7 @@
|
|||||||
|
|
||||||
#include "include/polyvox_filament/filament_texture.h"
|
#include "include/polyvox_filament/filament_texture.h"
|
||||||
#include "include/polyvox_filament/filament_pb_texture.h"
|
#include "include/polyvox_filament/filament_pb_texture.h"
|
||||||
|
#include "include/polyvox_filament/resource_loader.hpp"
|
||||||
|
|
||||||
#include "FilamentViewer.hpp"
|
#include "FilamentViewer.hpp"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -44,52 +44,6 @@ struct _PolyvoxFilamentPlugin {
|
|||||||
|
|
||||||
G_DEFINE_TYPE(PolyvoxFilamentPlugin, polyvox_filament_plugin, g_object_get_type())
|
G_DEFINE_TYPE(PolyvoxFilamentPlugin, polyvox_filament_plugin, g_object_get_type())
|
||||||
|
|
||||||
static map<uint32_t, void*> _file_assets;
|
|
||||||
static uint32_t _i = 0;
|
|
||||||
|
|
||||||
static ResourceBuffer loadResource(const char* name) {
|
|
||||||
|
|
||||||
char cwd[PATH_MAX];
|
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
|
||||||
std::cout << "Current working dir: " << cwd << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
string name_str(name);
|
|
||||||
auto id = _i++;
|
|
||||||
|
|
||||||
if (name_str.rfind("file://", 0) == 0) {
|
|
||||||
name_str = name_str.substr(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
name_str = string(cwd) + string("/") + name_str;
|
|
||||||
|
|
||||||
std::cout << "Loading resource at " << name_str.c_str() << std::endl;
|
|
||||||
|
|
||||||
streampos length;
|
|
||||||
ifstream is(name_str, ios::binary);
|
|
||||||
if(!is) {
|
|
||||||
std::cout << "Failed to find resource at file path " << name_str.c_str() << std::endl;
|
|
||||||
return ResourceBuffer(nullptr, 0, -1);
|
|
||||||
}
|
|
||||||
is.seekg (0, ios::end);
|
|
||||||
length = is.tellg();
|
|
||||||
char * buffer;
|
|
||||||
buffer = new char [length];
|
|
||||||
is.seekg (0, ios::beg);
|
|
||||||
is.read (buffer, length);
|
|
||||||
is.close();
|
|
||||||
_file_assets[id] = buffer;
|
|
||||||
return ResourceBuffer(buffer, length, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void freeResource(uint32_t id) {
|
|
||||||
std::cout << "Freeing resource " << id << std::endl;
|
|
||||||
auto it = _file_assets.find(id);
|
|
||||||
if (it != _file_assets.end()) {
|
|
||||||
free(it->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a method call is received from Flutter.
|
// Called when a method call is received from Flutter.
|
||||||
static void polyvox_filament_plugin_handle_method_call(
|
static void polyvox_filament_plugin_handle_method_call(
|
||||||
PolyvoxFilamentPlugin* self,
|
PolyvoxFilamentPlugin* self,
|
||||||
|
|||||||
Reference in New Issue
Block a user