Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 模擬器開啟 GPU 加速:原理、踩坑與虛擬機環境實測

編輯:關於 Android 程式設計

模擬器的 3D 加速架構

Android 模擬器有個 GPU 開關。打開之後,3D 加速的工作會轉交給宿主機(HOST)的 GPU;不開的話就退回 Soft 3D,也就是純靠 CPU 模擬 GPU 的運作。所以想讓 3D 程式跑得順,這個選項一定要勾。

架構設計可參考官方 SDK 中的 emulator/opengl/DESIGN 文件。

正常情況下該看到的訊息

在 Ubuntu Linux 上執行 sdk on Linux,若一切正常,模擬器會顯示類似下面的訊息:

emulator: Initializing hardware OpenGLES emulation support
emulator: ERROR: Could not create Context 0x3005
emulator: Could not start OpenGLES renderer?

而失敗時則會看到:

emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.

也就是退回軟體渲染。

自行編譯的 SDK 開不了 GPU

如果是自己編譯出來的 SDK,照著上面步驟做,Android 依然起不來,會出現這類錯誤:

emulator: Initializing hardware OpenGLES emulation support
Failed to create Context 0x3005
emulator: KVM mode auto-enabled!

destroyOpenGLSubwindow not implemented for separate renderer process !!!
createOpenGLSubwindow not implemented for separate renderer process !!!
repaintOpenGLDisplay not implemented for separate renderer process !!!
emulator: Realistic sensor emulation is not available, since the remote controller is not accessible:

看起來是模擬器沒有自動退回 soft 3D,仍然試圖向那個並不存在的 renderer 進程要求 pipe 通信,結果當然失敗。

VirtualBox 裡跑 Ubuntu 再跑模擬器

另一種常見情境是在 VirtualBox 中裝 Ubuntu 12.04,再啟動 Android 模擬器。模擬器可以跑起來,但速度慢得令人難以忍受。

原因是 VirtualBox 虛擬出來的環境沒有 3D 設備,所以會看到:

emulator: Initializing hardware OpenGLES emulation support
OpenGL Warning:Failed to connect to host. Make sure 3D acceleration is enabled for this VM.

於是在 VirtualBox 設定中勾選 3D 加速,重新開機再啟動模擬器,結果得到:

Failed to create Context 0x3005
emulator: Can't start OpenGLES renderer?
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.

可見 VirtualBox 提供的 3D 支援要跑 Android 模擬器,目前仍有問題。結論是:想穩定使用 GPU 加速,直接跑在實體機器的 Linux 上會省下很多時間。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved