برنامه AR خود را با استفاده از Vulkan در Android NDK (C) رندر کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
زمانی که ArTextureUpdateMode
روی AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER
تنظیم شود، ARCore با فراخوانی ArSession_update()
یک بافر سخت افزار اندروید ارائه می دهد. این بافر سخت افزاری را می توان به Vulkan VkImage
متصل کرد.
مشاهده نمونه برنامه
پشتیبانی از رندر Vulkan در برنامه نمونه hello_ar_vulkan_c نشان داده شده است.
حالت خروجی بافر سخت افزاری را فعال کنید
ArTextureUpdateMode
پیکربندی شده تعیین می کند که ARCore چگونه بافت دوربین را به روز کند. وقتی روی AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER
تنظیم شود، ARCore تصویر دوربین را از طریق AHardwareBuffer
ارائه می کند.
جلسه را برای استفاده از AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER
پیکربندی کنید:
ArConfig* ar_config = NULL;
ArConfig_create(ar_session, &ar_config);
ArConfig_setTextureUpdateMode(ar_session, ar_config,
AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER);
CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);
ArConfig_destroy(ar_config);
بافر سخت افزاری را بدست آورید
وقتی AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER
فعال است، از ArFrame_getHardwareBuffer()
برای دریافت بافر سخت افزار استفاده کنید:
void* native_hardware_buffer = NULL;
ArFrame_getHardwareBuffer(ar_session, ar_frame, &native_hardware_buffer);
if ((int64_t)native_hardware_buffer == 0) {
// The hardware buffer isn't ready yet.
return;
}
در حین رندرینگ Vulkan از بافر سخت افزاری استفاده کنید
برای مثالی از نحوه ارائه یک برنامه AR با استفاده از Vulkan به vulkan_handler.cc
مراجعه کنید.
دستگاه های پشتیبانی شده
پشتیبانی از رندر Vulkan فقط در سطوح Android API 27 و بالاتر در دسترس است. علاوه بر این، دستگاه باید از افزونه VK_ANDROID_external_memory_android_hardware_buffer
پشتیبانی کند.
Vulkan را در مانیفست برنامه خود الزامی کنید
Google Play از <uses-feature>
اعلامشده در مانیفست برنامه شما استفاده میکند تا برنامه شما را از دستگاههایی که الزامات ویژگیهای سختافزاری و نرمافزاری آن را برآورده نمیکنند فیلتر کند. دستگاههایی که از Vulkan 1.0 استفاده میکنند ممکن است از برنامه افزودنی مورد نیاز پشتیبانی نکنند ، اما دستگاههای سازگار با Vulkan 1.1 باید برنامه افزودنی لازم را که از Android 10 شروع میشود (سطح API 29) داشته باشند.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eARCore can provide the camera image as an Android hardware buffer for efficient Vulkan rendering by setting \u003ccode\u003eArTextureUpdateMode\u003c/code\u003e to \u003ccode\u003eAR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis hardware buffer can be accessed using \u003ccode\u003eArFrame_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 is supported on Android API levels 27 and above, requiring devices to support the \u003ccode\u003eVK_ANDROID_external_memory_android_hardware_buffer\u003c/code\u003e extension.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure compatibility, declare Vulkan requirements in your app's manifest using \u003ccode\u003e<uses-feature>\u003c/code\u003e, targeting devices with Vulkan 1.1 for guaranteed support on Android 10 and above.\u003c/p\u003e\n"],["\u003cp\u003eA sample implementation of Vulkan rendering with ARCore can be found in the \u003ccode\u003ehello_ar_vulkan_c\u003c/code\u003e sample app.\u003c/p\u003e\n"]]],["To enable hardware buffer access, set `ArTextureUpdateMode` to `AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER` using `ArConfig_setTextureUpdateMode`. After calling `ArSession_update()`, use `ArFrame_getHardwareBuffer()` to obtain the `AHardwareBuffer`. If using the buffer beyond the next `ArSession_update()`, call `AHardwareBuffer_acquire()` and `AHardwareBuffer_release()`. Vulkan rendering is supported on Android API 27+ with the `VK_ANDROID_external_memory_android_hardware_buffer` extension. Incompatible devices will return an error.\n"],null,["# Render your AR app using Vulkan on Android NDK (C)\n\nWhen the [`ArTextureUpdateMode`](/ar/reference/c/group/ar-config#artextureupdatemode) is set to [`AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER`](/ar/reference/c/group/ar-config#ar_texture_update_mode_expose_hardware_buffer), ARCore will provide an Android [hardware buffer](https://developer.android.com/ndk/reference/group/a-hardware-buffer) when [`ArSession_update()`](/ar/reference/c/group/ar-session#arsession_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 [`ArTextureUpdateMode`](/ar/reference/c/group/ar-config#artextureupdatemode) determines how ARCore will update the camera texture. When it is set to [`AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER`](/ar/reference/c/group/ar-config#ar_texture_update_mode_expose_hardware_buffer), ARCore will provide the camera image through a [`AHardwareBuffer`](https://developer.android.com/ndk/reference/group/a-hardware-buffer).\n\nConfigure the session to use [`AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER`](/ar/reference/c/group/ar-config#ar_texture_update_mode_expose_hardware_buffer): \n\n```c\nArConfig* ar_config = NULL;\nArConfig_create(ar_session, &ar_config);\nArConfig_setTextureUpdateMode(ar_session, ar_config,\n AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER);\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\nArConfig_destroy(ar_config);\n```\n| **Note:** When using [`AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER`](/ar/reference/c/group/ar-config#ar_texture_update_mode_expose_hardware_buffer) on incompatible devices, [`ArSession_configure()`](/ar/reference/c/group/ar-session#arsession_configure) will fail and return [`AR_ERROR_UNSUPPORTED_CONFIGURATION`](/ar/reference/c/group/shared-types#ar_error_unsupported_configuration).\n\nObtain the hardware buffer\n--------------------------\n\nWhen [`AR_TEXTURE_UPDATE_MODE_EXPOSE_HARDWARE_BUFFER`](/ar/reference/c/group/ar-config#ar_texture_update_mode_expose_hardware_buffer) is enabled, use [`ArFrame_getHardwareBuffer()`](/ar/reference/c/group/ar-frame#arframe_gethardwarebuffer) to get the hardware buffer: \n\n```c\nvoid* native_hardware_buffer = NULL;\nArFrame_getHardwareBuffer(ar_session, ar_frame, &native_hardware_buffer);\n\nif ((int64_t)native_hardware_buffer == 0) {\n // The hardware buffer isn't ready yet.\n return;\n}\n```\n| **Note:** This [`AHardwareBuffer`](https://developer.android.com/ndk/reference/group/a-hardware-buffer) is only guaranteed to be valid until the next call to `ArSession_update()`. If you want to use the hardware buffer beyond that, such as for rendering, you must call [`AHardwareBuffer_acquire()`](https://developer.android.com/ndk/reference/group/a-hardware-buffer#ahardwarebuffer_acquire) and then call [`AHardwareBuffer_release()`](https://developer.android.com/ndk/reference/group/a-hardware-buffer#ahardwarebuffer_release) after your rendering is complete.\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)."]]