add resize implementation on Linux and texture/render target destruction etc
This commit is contained in:
@@ -573,6 +573,15 @@ void FilamentViewer::createRenderTarget(uint32_t glTextureId, uint32_t width, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::destroySwapChain() {
|
void FilamentViewer::destroySwapChain() {
|
||||||
|
if(_rt) {
|
||||||
|
_view->setRenderTarget(nullptr);
|
||||||
|
_engine->destroy(_rtDepth);
|
||||||
|
_engine->destroy(_rtColor);
|
||||||
|
_engine->destroy(_rt);
|
||||||
|
_rt = nullptr;
|
||||||
|
_rtDepth = nullptr;
|
||||||
|
_rtColor = nullptr;
|
||||||
|
}
|
||||||
if (_swapChain) {
|
if (_swapChain) {
|
||||||
_engine->destroy(_swapChain);
|
_engine->destroy(_swapChain);
|
||||||
_swapChain = nullptr;
|
_swapChain = nullptr;
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ filament_texture_populate (FlTextureGL *texture,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void filament_texture_gl_dispose(GObject* object) {
|
void filament_texture_gl_dispose(GObject* object) {
|
||||||
G_OBJECT_CLASS(filament_texture_gl_parent_class)->dispose(object);
|
auto filamentTextureGL = FILAMENT_TEXTURE_GL(object);
|
||||||
|
glDeleteTextures(1, &(filamentTextureGL->texture_id));
|
||||||
|
filamentTextureGL->texture_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void filament_texture_gl_class_init(FilamentTextureGLClass* klass) {
|
void filament_texture_gl_class_init(FilamentTextureGLClass* klass) {
|
||||||
@@ -42,10 +44,15 @@ void filament_texture_gl_class_init(FilamentTextureGLClass* klass) {
|
|||||||
|
|
||||||
void filament_texture_gl_init(FilamentTextureGL* self) { }
|
void filament_texture_gl_init(FilamentTextureGL* self) { }
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT FlTexture* create_filament_texture(uint32_t width, uint32_t height, FlTextureRegistrar* registrar) {
|
void destroy_filament_texture(FlTexture* texture, FlTextureRegistrar* registrar) {
|
||||||
|
fl_texture_registrar_unregister_texture(registrar, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlTexture* create_filament_texture(uint32_t width, uint32_t height, FlTextureRegistrar* registrar) {
|
||||||
auto textureGL = FILAMENT_TEXTURE_GL(g_object_new(filament_texture_gl_get_type(), nullptr));
|
auto textureGL = FILAMENT_TEXTURE_GL(g_object_new(filament_texture_gl_get_type(), nullptr));
|
||||||
textureGL->width = width;
|
textureGL->width = width;
|
||||||
textureGL->height = height;
|
textureGL->height = height;
|
||||||
|
textureGL->registrar = registrar;
|
||||||
|
|
||||||
g_autoptr(FlTexture) texture = FL_TEXTURE(textureGL);
|
g_autoptr(FlTexture) texture = FL_TEXTURE(textureGL);
|
||||||
|
|
||||||
@@ -61,13 +68,13 @@ FLUTTER_PLUGIN_EXPORT FlTexture* create_filament_texture(uint32_t width, uint32_
|
|||||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureGL->width, textureGL->height, 0, GL_RGBA,
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureGL->width, textureGL->height, 0, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, 0);
|
GL_UNSIGNED_BYTE, 0);
|
||||||
|
|
||||||
if(fl_texture_registrar_register_texture(registrar, texture) == TRUE) {
|
if(fl_texture_registrar_register_texture(registrar, texture) == TRUE) {
|
||||||
|
|
||||||
if(fl_texture_registrar_mark_texture_frame_available(registrar,
|
if(fl_texture_registrar_mark_texture_frame_available(registrar,
|
||||||
texture) != TRUE) {
|
texture) != TRUE) {
|
||||||
std::cout << "FAILED" << std::endl;
|
std::cout << "FAILED" << std::endl;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,7 @@ struct _FilamentTextureGL {
|
|||||||
GLuint texture_id;
|
GLuint texture_id;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
FlTextureRegistrar* registrar;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _FilamentTextureGL FilamentTextureGL;
|
typedef struct _FilamentTextureGL FilamentTextureGL;
|
||||||
@@ -37,12 +38,12 @@ typedef struct {
|
|||||||
uint32_t* width,
|
uint32_t* width,
|
||||||
uint32_t* height,
|
uint32_t* height,
|
||||||
GError** error);
|
GError** error);
|
||||||
|
|
||||||
GLuint texture_id;
|
GLuint texture_id;
|
||||||
} FilamentTextureGLClass;
|
} FilamentTextureGLClass;
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT FlTexture* create_filament_texture(uint32_t width, uint32_t height, FlTextureRegistrar* registrar);
|
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
|
#endif
|
||||||
@@ -38,9 +38,11 @@ struct _PolyvoxFilamentPlugin {
|
|||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
FlTextureRegistrar* texture_registrar;
|
FlTextureRegistrar* texture_registrar;
|
||||||
FlView* fl_view;
|
FlView* fl_view;
|
||||||
|
|
||||||
FlTexture* texture;
|
FlTexture* texture;
|
||||||
void* _viewer;
|
void* _viewer;
|
||||||
|
|
||||||
|
double width;
|
||||||
|
double height;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(PolyvoxFilamentPlugin, polyvox_filament_plugin, g_object_get_type())
|
G_DEFINE_TYPE(PolyvoxFilamentPlugin, polyvox_filament_plugin, g_object_get_type())
|
||||||
@@ -72,7 +74,9 @@ static FlMethodResponse* _initialize(PolyvoxFilamentPlugin* self, FlMethodCall*
|
|||||||
const double width = fl_value_get_float(fl_value_get_list_value(args, 0));
|
const double width = fl_value_get_float(fl_value_get_list_value(args, 0));
|
||||||
const double height = fl_value_get_float(fl_value_get_list_value(args, 1));
|
const double height = fl_value_get_float(fl_value_get_list_value(args, 1));
|
||||||
|
|
||||||
|
self->width = width;
|
||||||
|
self->height = height;
|
||||||
|
|
||||||
auto texture = create_filament_texture(uint32_t(width), uint32_t(height), self->texture_registrar);
|
auto texture = create_filament_texture(uint32_t(width), uint32_t(height), self->texture_registrar);
|
||||||
//auto texture = create_filament_pb_texture(uint32_t(width), uint32_t(height), self->texture_registrar);
|
//auto texture = create_filament_pb_texture(uint32_t(width), uint32_t(height), self->texture_registrar);
|
||||||
self->texture = texture;
|
self->texture = texture;
|
||||||
@@ -364,6 +368,37 @@ static FlMethodResponse* _get_target_names(PolyvoxFilamentPlugin* self, FlMethod
|
|||||||
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
|
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - defer the destruction of the old texture until this call has returned
|
||||||
|
// otherwise the front-end may render using the destroyed texture ID for a single frame (hopefully no more)
|
||||||
|
static FlMethodResponse* _resize(PolyvoxFilamentPlugin* self, FlMethodCall* method_call) {
|
||||||
|
FlValue* args = fl_method_call_get_args(method_call);
|
||||||
|
|
||||||
|
const double width = fl_value_get_float(fl_value_get_list_value(args, 0));
|
||||||
|
const double height = fl_value_get_float(fl_value_get_list_value(args, 1));
|
||||||
|
|
||||||
|
if(width != self->width || height != self->height) {
|
||||||
|
|
||||||
|
destroy_swap_chain(self->_viewer);
|
||||||
|
|
||||||
|
destroy_filament_texture(self->texture, self->texture_registrar);
|
||||||
|
|
||||||
|
self->texture = create_filament_texture(uint32_t(width), uint32_t(height), self->texture_registrar);
|
||||||
|
|
||||||
|
create_swap_chain(self->_viewer, nullptr, width, height);
|
||||||
|
create_render_target(self->_viewer, ((FilamentTextureGL*)self->texture)->texture_id,width,height);
|
||||||
|
|
||||||
|
update_viewport_and_camera_projection(self->_viewer, width, height, 1.0f);
|
||||||
|
|
||||||
|
std::cout << "Created new texture " << self->texture << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_autoptr(FlValue) result =
|
||||||
|
fl_value_new_int(reinterpret_cast<int64_t>(self->texture));
|
||||||
|
|
||||||
|
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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,
|
||||||
@@ -380,13 +415,7 @@ static void polyvox_filament_plugin_handle_method_call(
|
|||||||
} else if(strcmp(method, "removeSkybox") == 0) {
|
} else if(strcmp(method, "removeSkybox") == 0) {
|
||||||
response = _removeSkybox(self, method_call);
|
response = _removeSkybox(self, method_call);
|
||||||
} else if(strcmp(method, "resize") == 0) {
|
} else if(strcmp(method, "resize") == 0) {
|
||||||
// val args = call.arguments as ArrayList<Int>
|
response = _resize(self, method_call);
|
||||||
// val width = args[0]
|
|
||||||
// val height = args[1]
|
|
||||||
// val scale = if(args.size > 2) (args[2] as Double).toFloat() else 1.0f
|
|
||||||
// surfaceTexture!!.setDefaultBufferSize(width, height)
|
|
||||||
// _lib.update_viewport_and_camera_projection(_viewer!!, width, height, scale);
|
|
||||||
// result.success(null)
|
|
||||||
} else if(strcmp(method, "render") == 0) {
|
} else if(strcmp(method, "render") == 0) {
|
||||||
render(self->_viewer, 0);
|
render(self->_viewer, 0);
|
||||||
g_autoptr(FlValue) result = fl_value_new_string("OK");
|
g_autoptr(FlValue) result = fl_value_new_string("OK");
|
||||||
|
|||||||
Reference in New Issue
Block a user