Skip to content

Commit

Permalink
Optimize first render time of the RoboVM backend. Fixes #6971 (#6972)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderBaron committed Sep 5, 2022
1 parent b86c20c commit 0f24d72
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [BREAKING CHANGE] Android: Immersive mode is now true by default. Set `useImmersiveMode` config to `false` to disable it.
- [BREAKING CHANGE] iOS: `hideHomeIndicator` set to `false` by default (was `true`).
- [BREAKING CHANGE] iOS: `screenEdgesDeferringSystemGestures` set to `UIRectEdge.All` by default (was `UIRectEdge.None`).
- [BREAKING CHANGE] iOS: `ApplicationListener.create` and first `resize` are now called within `UIApplicationDelegate.didFinishLaunching`. Allows for earlier rendering and prevents black screen frames after launch screen. NOTE: App will get terminated if this method is blocked for more than 10-20 sec.
- [BREAKING CHANGE] Actor#localToAscendantCoordinates throws an exception if the specified actor is not an ascendant.
- [BREAKING CHANGE] WidgetGroup#hit first validates the layout.
- iOS: Add new MobiVM MetalANGLE backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ final boolean didFinishLaunching (UIApplication uiApp, UIApplicationLaunchOption
Gdx.net = this.net;
this.input.setupPeripherals();
this.uiWindow.setRootViewController(this.graphics.viewController);
this.graphics.updateSafeInsets();
Gdx.app.debug("IOSApplication", "created");
listener.create();
listener.resize(this.graphics.getWidth(), this.graphics.getHeight());
// make sure the OpenGL view has contents before displaying it
this.graphics.view.display();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ public void draw (CGRect rect) {
// time + FPS
lastFrameTime = System.nanoTime();
framesStart = lastFrameTime;
// enable OpenGL
makeCurrent();
// OpenGL glViewport() function expects backbuffer coordinates instead of logical coordinates
gl20.glViewport(0, 0, screenBounds.backBufferWidth, screenBounds.backBufferHeight);
String versionString = gl20.glGetString(GL20.GL_VERSION);
String vendorString = gl20.glGetString(GL20.GL_VENDOR);
String rendererString = gl20.glGetString(GL20.GL_RENDERER);
glVersion = new GLVersion(Application.ApplicationType.iOS, versionString, vendorString, rendererString);
appPaused = false;
}

Expand Down Expand Up @@ -214,25 +222,11 @@ public void pause () {
app.listener.pause();
}

boolean created = false;

public void draw (MGLKView view, CGRect rect) {
makeCurrent();
// massive hack, GLKView resets the viewport on each draw call, so IOSGLES20
// stores the last known viewport and we reset it here...
gl20.glViewport(IOSGLES20.x, IOSGLES20.y, IOSGLES20.width, IOSGLES20.height);
if (!created) {
// OpenGL glViewport() function expects backbuffer coordinates instead of logical coordinates
gl20.glViewport(0, 0, screenBounds.backBufferWidth, screenBounds.backBufferHeight);
String versionString = gl20.glGetString(GL20.GL_VERSION);
String vendorString = gl20.glGetString(GL20.GL_VENDOR);
String rendererString = gl20.glGetString(GL20.GL_RENDERER);
glVersion = new GLVersion(Application.ApplicationType.iOS, versionString, vendorString, rendererString);
updateSafeInsets();
app.listener.create();
app.listener.resize(getWidth(), getHeight());
created = true;
}
if (appPaused) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ protected IOSUIViewController (IOSApplication app, IOSGraphics graphics) {
}

@Override
public void viewWillAppear (boolean arg0) {
super.viewWillAppear(arg0);
public void viewWillAppear (boolean animated) {
super.viewWillAppear(animated);
// start GLKViewController even though we may only draw a single frame
// (we may be in non-continuous mode)
setPaused(false);
Expand Down Expand Up @@ -74,7 +74,7 @@ public void viewDidLayoutSubviews () {
final IOSScreenBounds newBounds = app.computeBounds();
graphics.screenBounds = newBounds;
// Layout may happen without bounds changing, don't trigger resize in that case
if (graphics.created && (newBounds.width != oldBounds.width || newBounds.height != oldBounds.height)) {
if (newBounds.width != oldBounds.width || newBounds.height != oldBounds.height) {
graphics.makeCurrent();
graphics.updateSafeInsets();
graphics.gl20.glViewport(0, 0, newBounds.backBufferWidth, newBounds.backBufferHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ final boolean didFinishLaunching (UIApplication uiApp, UIApplicationLaunchOption
this.input.setupPeripherals();

this.uiWindow.setRootViewController(this.graphics.viewController);
this.graphics.updateSafeInsets();

Gdx.app.debug("IOSApplication", "created");

listener.create();
listener.resize(this.graphics.getWidth(), this.graphics.getHeight());

// make sure the OpenGL view has contents before displaying it
this.graphics.view.display();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ public void draw (CGRect rect) {
lastFrameTime = System.nanoTime();
framesStart = lastFrameTime;

// enable OpenGL
makeCurrent();
// OpenGL glViewport() function expects backbuffer coordinates instead of logical coordinates
gl20.glViewport(0, 0, screenBounds.backBufferWidth, screenBounds.backBufferHeight);

String versionString = gl20.glGetString(GL20.GL_VERSION);
String vendorString = gl20.glGetString(GL20.GL_VENDOR);
String rendererString = gl20.glGetString(GL20.GL_RENDERER);
glVersion = new GLVersion(Application.ApplicationType.iOS, versionString, vendorString, rendererString);

appPaused = false;
}

Expand Down Expand Up @@ -215,28 +225,12 @@ public void pause () {
app.listener.pause();
}

boolean created = false;

public void draw (GLKView view, CGRect rect) {
makeCurrent();
// massive hack, GLKView resets the viewport on each draw call, so IOSGLES20
// stores the last known viewport and we reset it here...
gl20.glViewport(IOSGLES20.x, IOSGLES20.y, IOSGLES20.width, IOSGLES20.height);

if (!created) {
// OpenGL glViewport() function expects backbuffer coordinates instead of logical coordinates
gl20.glViewport(0, 0, screenBounds.backBufferWidth, screenBounds.backBufferHeight);

String versionString = gl20.glGetString(GL20.GL_VERSION);
String vendorString = gl20.glGetString(GL20.GL_VENDOR);
String rendererString = gl20.glGetString(GL20.GL_RENDERER);
glVersion = new GLVersion(Application.ApplicationType.iOS, versionString, vendorString, rendererString);

updateSafeInsets();
app.listener.create();
app.listener.resize(getWidth(), getHeight());
created = true;
}
if (appPaused) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ protected IOSUIViewController (IOSApplication app, IOSGraphics graphics) {
}

@Override
public void viewWillAppear (boolean arg0) {
super.viewWillAppear(arg0);
public void viewWillAppear (boolean animated) {
super.viewWillAppear(animated);
// start GLKViewController even though we may only draw a single frame
// (we may be in non-continuous mode)
setPaused(false);
Expand Down Expand Up @@ -70,7 +70,7 @@ public void viewDidLayoutSubviews () {
final IOSScreenBounds newBounds = app.computeBounds();
graphics.screenBounds = newBounds;
// Layout may happen without bounds changing, don't trigger resize in that case
if (graphics.created && (newBounds.width != oldBounds.width || newBounds.height != oldBounds.height)) {
if (newBounds.width != oldBounds.width || newBounds.height != oldBounds.height) {
graphics.makeCurrent();
graphics.updateSafeInsets();
graphics.gl20.glViewport(0, 0, newBounds.backBufferWidth, newBounds.backBufferHeight);
Expand Down

0 comments on commit 0f24d72

Please sign in to comment.