LoginSignup
1
1

More than 3 years have passed since last update.

Android Vulkan で画面回転の取り扱いのメモ

Last updated at Posted at 2020-03-28

Vulkan では, いろいろ自前で処理コードをかかないといけません.

Android で, 画面が回転したり, 非アクティブになったりだと SwapChain の作り直しになります.

Android 側で回転させる

Android のコンポジターのほうで画面回転させて表示させる方法があります(筆者は試したことありません)

GPU 負荷がかかるとありますので, できれば自前で処理したほうがよさそうです.

回転を固定する

AndroidManifest.xml に screenOrientation 記述でとりあえず固定して, 回転を考えるのを止める手があります.

https://developer.android.com/guide/topics/manifest/activity-element
(orientation にもいろいろパターンあってめんどいですね..)

ただ, 条件によっては回転してしまったり, OS 側の機能かなにか無理やり回転させることはできるっぽいので, Google Play できちんとしたアプリ公開するなら回転対応は必須そうです.

How to force landscape or portrait mode in apps like Instagram and others (Android)
https://www.phonearena.com/news/How-to-force-landscape-or-portrait-mode-in-apps-like-Instagram-and-others-Android_id78439

how to force landscape mode with NDK using pure c++ codes
https://stackoverflow.com/questions/12702868/how-to-force-landscape-mode-with-ndk-using-pure-c-codes

注意点

<activity> のタグに android:screenOrientation を記載しないといけません!

筆者は上位の <application> タグに記載してしまい, 設定が反映されず 1/2 営業日を浪費してしまいました :cry:

回転の処理をいい感じに扱う

Handling Device Orientation Efficiently in Vulkan With Pre-Rotation
https://android-developers.googleblog.com/2020/02/handling-device-orientation-efficiently.html

めんどくさいですね...

画面が回転したかどうかの判定は, Android 10 だと vkQueuePresentKHR で取得できて楽です.
Android 9 or earlier だとめんどいです.

まとめ

画面がリサイズとかしたらいずれにせよ SwapChain 作り直しになりますので, SwapChain になるべく依存しないデータ構造にしておくのがベターですね.
(UniformBufferObject とか, swapChain の枚数ぶん Descriptor 作成が必要になったりする. 画面リサイズとかで swapChain の枚数が変わるというのは基本ないですが...)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1