This commit is contained in:
Nick Fisher
2023-10-13 17:22:31 +11:00
parent df4f647333
commit 4ebd5a6645
2 changed files with 22 additions and 17 deletions

View File

@@ -132,7 +132,7 @@ class _FilamentWidgetState extends State<FilamentWidget> {
var size = ((context.findRenderObject()) as RenderBox).size; var size = ((context.findRenderObject()) as RenderBox).size;
try { try {
widget.controller.createViewer(size.width.toInt(), size.height.toInt()); await widget.controller.createViewer(size.width.toInt(), size.height.toInt());
} catch (err) { } catch (err) {
setState(() { setState(() {
_error = err.toString(); _error = err.toString();
@@ -188,21 +188,21 @@ class _FilamentWidgetState extends State<FilamentWidget> {
_resizeTimer?.cancel(); _resizeTimer?.cancel();
_resizeTimer = Timer(Duration(milliseconds: 500), () async { _resizeTimer = Timer(Duration(milliseconds: 500), () async {
setState(() { // setState(() {
_resizing = true; // _resizing = true;
}); // });
// TODO - we could snapshot the widget to display while we resize? // TODO - we could snapshot the widget to display while we resize?
print("Resizing to $newSize"); print("Resizing to $newSize");
await widget.controller // await widget.controller
.resize(newSize.width.toInt(), newSize.height.toInt()); // .resize(newSize.width.toInt(), newSize.height.toInt());
WidgetsBinding.instance.addPostFrameCallback((_) async { // WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() { // setState(() {
_resizing = false; // _resizing = false;
widget.onResize?.call(); // widget.onResize?.call();
}); // });
}); // });
}); });
}); });
}, },

View File

@@ -403,8 +403,9 @@ bool PolyvoxFilamentPlugin::MakeOpenGLTexture(uint32_t width, uint32_t height,st
if(!_context || !wglMakeCurrent(whdc, _context)) { if(!_context || !wglMakeCurrent(whdc, _context)) {
std::cout << "Failed to switch OpenGL context." << std::endl; std::cout << "Failed to switch OpenGL context." << std::endl;
} else { } else if (_glTextureId != 0) {
uint8_t* data = (uint8_t*)_pixelData.get(); // uint8_t* data = (uint8_t*)_pixelData.get();
uint8_t* data = new uint8_t[width*height*4];
glBindTexture(GL_TEXTURE_2D, _glTextureId); glBindTexture(GL_TEXTURE_2D, _glTextureId);
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data); glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
@@ -470,6 +471,8 @@ void PolyvoxFilamentPlugin::DestroyTexture(
// TODO // TODO
result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name()); result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name());
#else #else
std::lock_guard<std::mutex> guard(_renderMutex);
HWND hwnd = _pluginRegistrar->GetView() HWND hwnd = _pluginRegistrar->GetView()
->GetNativeWindow(); ->GetNativeWindow();
@@ -482,9 +485,11 @@ void PolyvoxFilamentPlugin::DestroyTexture(
// for now we will just unregister the Flutter texture and delete the GL texture // for now we will just unregister the Flutter texture and delete the GL texture
// we will leave the pixel data/PixelBufferTexture intact - these will be replaced on the next call to createTexture // we will leave the pixel data/PixelBufferTexture intact - these will be replaced on the next call to createTexture
// if we wanted to be militant about cleaning up unused memory we could delete here first // if we wanted to be militant about cleaning up unused memory we could delete here first
_textureRegistrar->UnregisterTexture(_flutterTextureId); // _textureRegistrar->UnregisterTexture(_flutterTextureId);
_flutterTextureId = -1; // _flutterTextureId = -1;
glDeleteTextures(1, &_glTextureId); // glDeleteTextures(1, &_glTextureId);
// _glTextureId = 0;
// wglMakeCurrent(NULL, NULL);
result->Success(flutter::EncodableValue(true)); result->Success(flutter::EncodableValue(true));
#endif #endif
} }