แสดงผลแอป AR โดยใช้ Vulkan ใน Android SDK (Kotlin/Java)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อตั้งค่า Config.TextureUpdateMode
เป็น TextureUpdateMode.EXPOSE_HARDWARE_BUFFER
แล้ว ARCore จะให้ hardware buffer ของ Android เมื่อเรียกใช้ Session.update()
บัฟเฟอร์ฮาร์ดแวร์นี้สามารถเชื่อมโยงกับ VkImage
ของ Vulkan ได้
ดูตัวอย่างแอปพลิเคชัน
การสนับสนุนการแสดงผล Vulkan แสดงอยู่ในแอปตัวอย่าง hello_ar_vulkan_c
เปิดใช้โหมดเอาต์พุตบัฟเฟอร์ฮาร์ดแวร์
Config.TextureUpdateMode
ที่กําหนดค่าไว้จะกําหนดวิธีที่ ARCore จะอัปเดตพื้นผิวของกล้อง เมื่อตั้งค่าเป็น TextureUpdateMode.EXPOSE_HARDWARE_BUFFER
แล้ว ARCore จะแสดงภาพจากกล้องผ่าน HardwareBuffer
กำหนดค่าเซสชันให้ใช้ TextureUpdateMode.EXPOSE_HARDWARE_BUFFER
Java
Config config = session.getConfig();
config.setTextureUpdateMode(Config.TextureUpdateMode.EXPOSE_HARDWARE_BUFFER);
session.configure(config);
Kotlin
session.configure(
session.config.apply { textureUpdateMode = Config.TextureUpdateMode.EXPOSE_HARDWARE_BUFFER }
)
รับบัฟเฟอร์ฮาร์ดแวร์
เมื่อเปิดใช้ TextureUpdateMode.EXPOSE_HARDWARE_BUFFER
ให้ใช้ Frame.getHardwareBuffer()
เพื่อรับบัฟเฟอร์ฮาร์ดแวร์
Java
try {
HardwareBuffer buffer = frame.getHardwareBuffer();
// Use the buffer object in your rendering.
} catch (NotYetAvailableException e) {
// The hardware buffer is not ready yet.
}
Kotlin
try {
val buffer = frame.hardwareBuffer
// Use the buffer object in your rendering.
} catch (e: NotYetAvailableException) {
// The hardware buffer is not ready yet.
}
ใช้บัฟเฟอร์ฮาร์ดแวร์ระหว่างการแสดงผล Vulkan
ดูตัวอย่างวิธีแสดงผลแอปพลิเคชัน AR โดยใช้ Vulkan ได้ที่ vulkan_handler.cc
อุปกรณ์ที่รองรับ
การรองรับการแสดงผล Vulkan ใช้ได้ใน Android API ระดับ 27 ขึ้นไปเท่านั้น นอกจากนี้ อุปกรณ์ต้องรองรับส่วนขยาย VK_ANDROID_external_memory_android_hardware_buffer
ด้วย
กำหนดให้ต้องใช้ Vulkan ในไฟล์ Manifest ของแอป
Google Play ใช้ <uses-feature>
ที่ประกาศในไฟล์ Manifest ของแอปเพื่อกรองแอปของคุณออกจากอุปกรณ์ที่ไม่เป็นไปตามข้อกำหนดของฟีเจอร์ฮาร์ดแวร์และซอฟต์แวร์
อุปกรณ์ที่ใช้ Vulkan 1.0 อาจไม่รองรับส่วนขยายที่จำเป็น แต่อุปกรณ์ที่เข้ากันได้กับ Vulkan 1.1 ต้องมีส่วนขยายที่จำเป็นตั้งแต่ Android 10 (API ระดับ 29) เป็นต้นไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eARCore can provide the camera image as an Android hardware buffer for efficient Vulkan rendering when \u003ccode\u003eTextureUpdateMode.EXPOSE_HARDWARE_BUFFER\u003c/code\u003e is enabled.\u003c/p\u003e\n"],["\u003cp\u003eThis hardware buffer can be accessed using \u003ccode\u003eFrame.getHardwareBuffer()\u003c/code\u003e and bound to a Vulkan \u003ccode\u003eVkImage\u003c/code\u003e for rendering.\u003c/p\u003e\n"],["\u003cp\u003eVulkan rendering with ARCore requires Android API level 27 or higher and device support for the \u003ccode\u003eVK_ANDROID_external_memory_android_hardware_buffer\u003c/code\u003e extension.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ehello_ar_vulkan_c\u003c/code\u003e sample app demonstrates how to implement Vulkan rendering with ARCore.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure your app is only available on compatible devices, declare the Vulkan feature requirement in your app's manifest.\u003c/p\u003e\n"]]],["To utilize hardware buffer output, set `Config.TextureUpdateMode` to `EXPOSE_HARDWARE_BUFFER` during session configuration. This enables ARCore to provide a hardware buffer via `Session.update()`. Retrieve this buffer using `Frame.getHardwareBuffer()`. It can then be bound to a Vulkan `VkImage`. Vulkan rendering is demonstrated in the `hello_ar_vulkan_c` sample app. Support requires Android API level 27+, with the `VK_ANDROID_external_memory_android_hardware_buffer` extension and ensure your manifest declares Vulkan usage.\n"],null,["# Render your AR app using Vulkan on Android SDK (Kotlin/Java)\n\nWhen the [`Config.TextureUpdateMode`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode) is set to [`TextureUpdateMode.EXPOSE_HARDWARE_BUFFER`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode#expose_hardware_buffer), ARCore will provide an Android [hardware buffer](https://developer.android.com/ndk/reference/group/a-hardware-buffer) when [`Session.update()`](/ar/reference/java/com/google/ar/core/Session#update-) is called. This hardware buffer can be bound to a Vulkan [`VkImage`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImage.html).\n\nView the sample application\n---------------------------\n\nVulkan rendering support is demonstrated in the [hello_ar_vulkan_c sample app](https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_vulkan_c).\n\nEnable the hardware buffer output mode\n--------------------------------------\n\nThe configured [`Config.TextureUpdateMode`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode) determines how ARCore will update the camera texture. When it is set to [`TextureUpdateMode.EXPOSE_HARDWARE_BUFFER`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode#expose_hardware_buffer), ARCore will provide the camera image through a [`HardwareBuffer`](https://developer.android.com/reference/android/hardware/HardwareBuffer).\n\nConfigure the session to use [`TextureUpdateMode.EXPOSE_HARDWARE_BUFFER`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode#expose_hardware_buffer): \n\n### Java\n\n```java\nConfig config = session.getConfig();\nconfig.setTextureUpdateMode(Config.TextureUpdateMode.EXPOSE_HARDWARE_BUFFER);\nsession.configure(config);\n```\n\n### Kotlin\n\n```kotlin\nsession.configure(\n session.config.apply { textureUpdateMode = Config.TextureUpdateMode.EXPOSE_HARDWARE_BUFFER }\n)\n```\n| **Note:** When using [`TextureUpdateMode.EXPOSE_HARDWARE_BUFFER`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode#expose_hardware_buffer) on incompatible devices, [`Session.configure()`](/ar/reference/java/com/google/ar/core/Session#configure(com.google.ar.core.Config)) will fail and throw [`UnsupportedConfigurationException`](/ar/reference/java/com/google/ar/core/exceptions/UnsupportedConfigurationException).\n\nObtain the hardware buffer\n--------------------------\n\nWhen [`TextureUpdateMode.EXPOSE_HARDWARE_BUFFER`](/ar/reference/java/com/google/ar/core/Config.TextureUpdateMode#expose_hardware_buffer) is enabled, use [`Frame.getHardwareBuffer()`](/ar/reference/java/com/google/ar/core/Frame#getHardwareBuffer-) to get the hardware buffer: \n\n### Java\n\n```java\ntry {\n HardwareBuffer buffer = frame.getHardwareBuffer();\n // Use the buffer object in your rendering.\n} catch (NotYetAvailableException e) {\n // The hardware buffer is not ready yet.\n}\n```\n\n### Kotlin\n\n```kotlin\ntry {\n val buffer = frame.hardwareBuffer\n // Use the buffer object in your rendering.\n} catch (e: NotYetAvailableException) {\n // The hardware buffer is not ready yet.\n}\n```\n\nUse the hardware buffer during Vulkan rendering\n-----------------------------------------------\n\nSee [`vulkan_handler.cc`](https://github.com/google-ar/arcore-android-sdk/blob/master/samples/hello_ar_vulkan_c/app/src/main/cpp/vulkan_handler.cc) for an example of how to render an AR application using Vulkan.\n\nSupported devices\n-----------------\n\nVulkan rendering support is only available on Android API levels **27** and\nabove. Additionally, the device must support the `VK_ANDROID_external_memory_android_hardware_buffer` extension.\n\n### Require Vulkan in your app's manifest\n\nGoogle Play uses `\u003cuses-feature\u003e` declared in your app manifest to filter your\napp from devices that don't meet its hardware and software feature requirements.\nDevices using Vulkan 1.0 **might not** support the required extension, but devices\ncompatible with Vulkan 1.1 **must** have the required extension starting in Android 10 (API level 29)."]]