Reputation: 21
I'm develoing an application in Gluon. At the moment, it is just a simple cube.
I'm using an AnimationTimer to handle the game loop. When the animation timer is handles I compare the system's nanoseconds to compute the frames delta time. I display the fps via: 1/DeltaTime.
On desktop, the fpsLabel display a constant 60 fps. On mobile, however, I receive only 30 fps. I noticed the console sometimes writes setSwapInterval(1), which I know is a VSYNC setting in OpenGL. Is my phone really not hitting the target 60 fps and getting throttled down? Might be beneficial to have more direct OpenGLES support with Gluon.
// 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);
Upvotes: 1
Views: 315
Reputation: 45456
On iOS, CADisplayLink
is the AnimationTimer equivalent:
A timer object that allows your application to synchronize its drawing to the refresh rate of the display
If you check the source code in the JDK 1.8, you will find in the graphics module, under native-glass
for iOS, the implementation of this timer:
displayLink = [[UIScreen mainScreen] displayLinkWithTarget:[GlassTimer getDelegate]
selector:@selector(displayLinkUpdate:)];
// 1 is 60hz, 2 is 30 Hz, 3 is 20 Hz ...
[displayLink setFrameInterval:2];
As you can see, the FPS you can get is limited by design.
While in the past there could be a reason for this cap, I don't see a technical reason for it anymore, other than limiting the battery drain you will get forcing this high rate in a mobile device, where in most of the cases, 30 fps will be more than enough.
I've modified the frame interval to 1 (60 Hz), built the SDK for iOS, and successfully tested it on my iPhone:
However, this is not how it should be modified, of course. This parameter should be somehow open to the developer, and some kind of API will be desirable.
Since this limit is applied also to the OpenJFX JavaFX 11 code base, I'd suggest filing an issue, so it can be modified properly.
Upvotes: 1