rename plugin from PolyvoxFilament to FlutterFilament

rename plugin from PolyvoxFilament to FlutterFilament
This commit is contained in:
Nick Fisher
2023-10-26 14:05:03 +11:00
parent b42d31a773
commit 8b9e6a2b3a
125 changed files with 1539 additions and 1460 deletions

View File

@@ -0,0 +1,44 @@
#ifndef FILAMENT_PB_TEXTURE_H
#define FILAMENT_PB_TEXTURE_H
#include <gtk/gtk.h>
#include <glib-object.h>
#include <flutter_linux/flutter_linux.h>
#include <flutter_linux/fl_texture_gl.h>
#include <flutter_linux/fl_texture.h>
#include <flutter_linux/fl_pixel_buffer_texture.h>
#include <flutter_linux/fl_texture_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif
G_BEGIN_DECLS
#define FILAMENT_PB_TEXTURE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), filament_pb_texture_get_type(), \
FilamentPBTexture))
struct _FilamentPBTexture {
FlPixelBufferTexture parent_instance;
};
typedef struct _FilamentPBTexture FilamentPBTexture;
typedef struct {
FlPixelBufferTextureClass parent_instance;
gboolean (*copy_pixels)(FlPixelBufferTexture* texture,
const uint8_t** buffer,
uint32_t* width,
uint32_t* height,
GError** error);
} FilamentPBTextureClass;
G_END_DECLS
FLUTTER_PLUGIN_EXPORT FlTexture* create_filament_pb_texture(uint32_t width, uint32_t height, FlTextureRegistrar* registrar);
#endif

View File

@@ -0,0 +1,49 @@
#ifndef FILAMENT_TEXTURE_H
#define FILAMENT_TEXTURE_H
#include <gtk/gtk.h>
#include <glib-object.h>
#include <flutter_linux/flutter_linux.h>
#include <flutter_linux/fl_texture_gl.h>
#include <flutter_linux/fl_texture.h>
#include <flutter_linux/fl_texture_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif
G_BEGIN_DECLS
#define FILAMENT_TEXTURE_GL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), filament_texture_gl_get_type(), \
FilamentTextureGL))
struct _FilamentTextureGL {
FlTextureGL parent_instance;
GLuint texture_id;
uint32_t width;
uint32_t height;
FlTextureRegistrar* registrar;
};
typedef struct _FilamentTextureGL FilamentTextureGL;
typedef struct {
FlTextureGLClass parent_instance;
gboolean (*populate)(FlTextureGL* texture,
uint32_t* target,
uint32_t* name,
uint32_t* width,
uint32_t* height,
GError** error);
GLuint texture_id;
} FilamentTextureGLClass;
G_END_DECLS
FLUTTER_PLUGIN_EXPORT FlTexture* create_filament_texture(uint32_t width, uint32_t height, FlTextureRegistrar* registrar);
FLUTTER_PLUGIN_EXPORT void destroy_filament_texture(FlTexture* texture, FlTextureRegistrar* registrar);
#endif

View File

@@ -0,0 +1,27 @@
#ifndef FLUTTER_PLUGIN_FLUTTER_FILAMENT_PLUGIN_H_
#define FLUTTER_PLUGIN_FLUTTER_FILAMENT_PLUGIN_H_
#include <flutter_linux/flutter_linux.h>
#include <epoxy/gl.h>
G_BEGIN_DECLS
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif
typedef struct _FlutterFilamentPlugin FlutterFilamentPlugin;
typedef struct {
GObjectClass parent_class;
} FlutterFilamentPluginClass;
FLUTTER_PLUGIN_EXPORT GType flutter_filament_plugin_get_type();
FLUTTER_PLUGIN_EXPORT void flutter_filament_plugin_register_with_registrar(
FlPluginRegistrar* registrar);
G_END_DECLS
#endif // FLUTTER_PLUGIN_FLUTTER_FILAMENT_PLUGIN_H_

View File

@@ -0,0 +1,71 @@
#ifndef FLUTTER_FILAMENT_LINUX_RESOURCE_LOADER_H
#define FLUTTER_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) {
std::cout << "LOADING RESOURCE" << std::endl;
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++;
// this functions accepts URIs, so
// - file:// points to a file on the filesystem
// - asset:// points to an asset, usually resolved relative to the current working directory
// - no prefix is presumed to be an asset
if (name_str.rfind("file://", 0) == 0) {
name_str = name_str.substr(7);
} else if(name_str.rfind("asset://", 0) == 0) {
name_str = name_str.substr(7);
name_str = string(cwd) + string("/") + name_str;
} else {
name_str = string(cwd) + string("/build/linux/x64/debug/bundle/data/flutter_assets/") + 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(ResourceBuffer rbuf) {
auto it = _file_assets.find(rbuf.id);
if (it != _file_assets.end()) {
free(it->second);
}
}
#endif