【问题标题】:3D JavaFX application running at 30 fps以 30 fps 运行的 3D JavaFX 应用程序
【发布时间】:2019-02-24 22:17:07
【问题描述】:

我正在用 Gluon 开发一个应用程序。目前,它只是一个简单的立方体。

我正在使用 AnimationTimer 来处理游戏循环。当动画计时器是句柄时,我比较系统的纳秒来计算帧增量时间。我通过以下方式显示 fps:1/DeltaTime。

在桌面上,fpsLabel 显示恒定的 60 fps。但是,在移动设备上,我只能收到 30 fps。我注意到控制台有时会写入 setSwapInterval(1),我知道这是 OpenGL 中的 VSYNC 设置。我的手机真的没有达到 60 fps 的目标并被限制吗?使用 Gluon 获得更直接的 OpenGLES 支持可能会有所帮助。

// Content pane
StackPane content = new StackPane();
content.setAlignment(Pos.TOP_LEFT);
content.setPadding(new Insets(8));
content.setPrefSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
this.setCenter(content);

// Holds 3d objects
Group root3D = new Group();

// Scene to view the 3d objects
SubScene subScene = new SubScene(root3D, MobileApplication.getInstance().getScreenWidth(), MobileApplication.getInstance().getScreenHeight(), true, SceneAntialiasing.DISABLED);
content.getChildren().add(subScene);

// Create camera
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(1000.0);
camera.setTranslateZ(-64);
root3D.getChildren().add(camera);

// Put camera in scene
Platform.runLater(()->{
    subScene.setCamera(camera);
    subScene.widthProperty().bind(MobileApplication.getInstance().getView().widthProperty());
    subScene.heightProperty().bind(MobileApplication.getInstance().getView().heightProperty());
});

// Put box in scene
Box box = new Box(8, 8, 8);
Rotate rxBox = new Rotate(0, 0, 0, 0, Rotate.X_AXIS);
boxRot = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
rxBox.setAngle(30);
boxRot.setAngle(50);
box.getTransforms().addAll(rxBox, boxRot);
root3D.getChildren().add(box);

// FPS Label
fpsLabel = new Label("Fps 60");
content.getChildren().add(fpsLabel);

【问题讨论】:

    标签: javafx gluon gluon-mobile


    【解决方案1】:

    在 iOS 上,CADisplayLink 是 AnimationTimer equivalent

    一个计时器对象,允许您的应用程序将其绘图与显示器的刷新率同步

    如果你查看JDK 1.8中的源代码,你会发现在图形模块中,在iOS的native-glass下,这个定时器的implementation

    displayLink = [[UIScreen mainScreen] displayLinkWithTarget:[GlassTimer getDelegate]
                                                                      selector:@selector(displayLinkUpdate:)];
    // 1 is 60hz, 2 is 30 Hz, 3 is 20 Hz ...
    [displayLink setFrameInterval:2];
    

    如您所见,您可以获得的 FPS 受限于设计

    虽然在过去可能有这个上限的原因,但我看不到它的技术原因,除了限制电池消耗之外,您将在移动设备中强制实现如此高的速率,在大多数情况下在这种情况下,30 fps 就绰绰有余了。

    我已将帧间隔修改为 1 (60 Hz),构建了适用于 iOS 的 SDK,并在我的 iPhone 上成功测试:

    但是,这当然不是应该修改的方式。这个参数应该以某种方式对开发者开放,并且需要某种 API。

    由于此限制也适用于 OpenJFX JavaFX 11 code base,我建议提交 issue,以便可以正确修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 2018-05-02
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多