diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index a7d0d557..49d1c2d4 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -11,7 +11,9 @@ enum ToneMapper { ACES, FILMIC, LINEAR } class TextureDetails { final int textureId; - final int width; + + // both width and height are in physical, not logical pixels + final int width; final int height; TextureDetails( diff --git a/lib/filament_controller_ffi.dart b/lib/filament_controller_ffi.dart index d3cf90d9..fb566787 100644 --- a/lib/filament_controller_ffi.dart +++ b/lib/filament_controller_ffi.dart @@ -148,8 +148,7 @@ class FilamentControllerFFI extends FilamentController { /// @override Future createViewer(Rect rect) async { - double width = rect.width; - double height = rect.height; + if (_viewer != null) { throw Exception( "Viewer already exists, make sure you call destroyViewer first"); @@ -165,9 +164,7 @@ class FilamentControllerFFI extends FilamentController { throw Exception("Failed to get resource loader"); } - var size = ui.Size(width * _pixelRatio, height * _pixelRatio); - - print("Creating viewer with size $size"); + rect = rect.inflate(_pixelRatio); if (Platform.isWindows && requiresTextureWidget) { _driver = Pointer.fromAddress( @@ -220,7 +217,7 @@ class FilamentControllerFFI extends FilamentController { Future _createRenderingSurface(Rect rect) async { return RenderingSurface.from(await _channel.invokeMethod( "createTexture", - [rect.width, rect.height, _pixelRatio, rect.left, rect.top])); + [rect.width, rect.height, rect.left, rect.top])); } /// @@ -299,6 +296,8 @@ class FilamentControllerFFI extends FilamentController { throw Exception("Resize currently underway, ignoring"); } + rect = rect.inflate(_pixelRatio); + _resizing = true; _lib.set_rendering_ffi(_viewer!, false); @@ -315,7 +314,7 @@ class FilamentControllerFFI extends FilamentController { } else if(Platform.isWindows) { print("Resizing window with rect $rect"); await _channel.invokeMethod( - "resizeWindow", [rect.width, rect.height, _pixelRatio, rect.left, rect.top]); + "resizeWindow", [rect.width, rect.height, rect.left, rect.top]); } var renderingSurface = await _createRenderingSurface(rect); @@ -330,7 +329,7 @@ class FilamentControllerFFI extends FilamentController { _lib.create_swap_chain_ffi(_viewer!, renderingSurface.surface, rect.width.toInt(), rect.height.toInt()); } - + if (renderingSurface.textureHandle != 0) { print( "Creating render target from native texture ${renderingSurface.textureHandle}"); diff --git a/windows/polyvox_filament_plugin.cpp b/windows/polyvox_filament_plugin.cpp index f306a5a8..1c44cbfb 100644 --- a/windows/polyvox_filament_plugin.cpp +++ b/windows/polyvox_filament_plugin.cpp @@ -169,15 +169,14 @@ void PolyvoxFilamentPlugin::CreateTexture( double dWidth = *(std::get_if(&(args->at(0)))); double dHeight = *(std::get_if(&(args->at(1)))); - double pixelRatio = *(std::get_if(&(args->at(2)))); - double dLeft = *(std::get_if(&(args->at(3)))); - double dTop = *(std::get_if(&(args->at(4)))); - auto width = (uint32_t)round(dWidth * pixelRatio); - auto height = (uint32_t)round(dHeight * pixelRatio); - auto left = (uint32_t)round(dLeft * pixelRatio); - auto top = (uint32_t)round(dTop * pixelRatio); + double dLeft = *(std::get_if(&(args->at(2)))); + double dTop = *(std::get_if(&(args->at(3)))); + auto width = (uint32_t)round(dWidth ); + auto height = (uint32_t)round(dHeight ); + auto left = (uint32_t)round(dLeft ); + auto top = (uint32_t)round(dTop ); - std::cout << "Using " << width << "x" << height << " (pixel ratio " << pixelRatio << ")" << std::endl; + std::cout << "Using " << width << "x" << height << std::endl; // create a single shared context for the life of the application // this will be used to create a backing texture and passed to Filament @@ -234,13 +233,12 @@ void PolyvoxFilamentPlugin::HandleMethodCall( std::get_if(methodCall.arguments()); double dWidth = *(std::get_if(&(args->at(0)))); double dHeight = *(std::get_if(&(args->at(1)))); - double pixelRatio = *(std::get_if(&(args->at(2)))); - double dLeft = *(std::get_if(&(args->at(3)))); - double dTop = *(std::get_if(&(args->at(4)))); - auto width = (uint32_t)round(dWidth * pixelRatio); - auto height = (uint32_t)round(dHeight * pixelRatio); - auto left = (uint32_t)round(dLeft * pixelRatio); - auto top = (uint32_t)round(dTop * pixelRatio); + double dLeft = *(std::get_if(&(args->at(2)))); + double dTop = *(std::get_if(&(args->at(3)))); + auto width = (uint32_t)round(dWidth ); + auto height = (uint32_t)round(dHeight ); + auto left = (uint32_t)round(dLeft ); + auto top = (uint32_t)round(dTop ); _context->ResizeRenderingSurface(width, height, left, top); result->Success(); #else