gpt4 book ai didi

android - 我是否必须创建一个 native Activity 来获取窗口,或者我可以从 Android 设备上的窗口管理器为 vulkan 应用程序提供一个?

转载 作者:行者123 更新时间:2023-11-29 01:11:34 25 4
gpt4 key购买 nike

无论我在 Internet 上找到什么资源,从创建 native Activity 并提供 android_app->window 来创建 vkAndroidSurfaceKHR 进行初始化。所以,我只想知道我们能否有一个窗口管理器来提供这个窗口来创建表面。

最佳答案

要从简单的 Java 应用程序创建 vkAndroidSurfaceKHR,您需要获取 android.view.View 的实例并执行对 ANativeWindow_fromSurface(env, win) 的 native 调用。注意 View 及其子类能够从 GPU 绘制 3D 内容,如 OpenGL 和 Vulkan。

我在 api 中就是这样做的9100行左右,

 /**
* Get display handles for Android and AWT Canvas
* @param win - a java.awt.Canvas instance or a android.view.Surface
* @param displayHandles - return native surface handle
*
* @return true if all goes Ok.
*/
protected static native boolean getDisplayHandles0(Object win, long[] displayHandles);/*

#ifdef VK_USE_PLATFORM_ANDROID_KHR
ANativeWindow* window;
// Return the ANativeWindow associated with a Java Surface object,
// for interacting with it through native code. This acquires a reference
// on the ANativeWindow that is returned; be sure to use ANativeWindow_release()
// when done with it so that it doesn't leak.
window = ANativeWindow_fromSurface(env, win);
displayHandles[0] = reinterpret_cast<jlong>(window);
return JNI_TRUE;
#else
...
#endif
*/
}

我还以另一种方式实现了这一点,大约在第 10370 行,来源相同:

/**
*
* @see http://www.javaworld.com/article/2075263/core-java/embed-java-code-into-your-native-apps.html
*
* @param instance - Vulkan instance
* @param nativeWindow - instance of android.view.Surface or java.awt.Canvas
* @param pAllocatorHandle - native handle to a VkAllocationCallbacks
* @param pSurface
* @return
*/
protected static native int vkCreateWindowSurface0(long instance,
Object nativeWindow,
long pAllocatorHandle,
long[] pSurface,
long[] awtDrawingSurface);/*

VkAllocationCallbacks* pAllocator = reinterpret_cast<VkAllocationCallbacks*>(pAllocatorHandle);
VkInstance vkInstance = reinterpret_cast<VkInstance>(instance);
VkSurfaceKHR* _pSurface = new VkSurfaceKHR[1];
VkResult res = VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;

#ifdef VK_USE_PLATFORM_ANDROID_KHR
ANativeWindow* window = NULL;
window = ANativeWindow_fromSurface(env, nativeWindow);
if (window == NULL)
return VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;

VkAndroidSurfaceCreateInfoKHR info;
info.sType = VkStructureType::VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
info.pNext = NULL;
info.flags = 0;
info.window = window;
res = vkCreateAndroidSurfaceKHR(vkInstance, &info, pAllocator, _pSurface);
#else
...
#endif

if(res >= 0){
pSurface[0] = reinterpret_cast<jlong>(_pSurface[0]);
}else{
pSurface[0] = (jlong)0;
fprintf(stderr,"Failed to create Vulkan SurfaceKHR.");
}

delete[] _pSurface;
return res;
}

关于android - 我是否必须创建一个 native Activity 来获取窗口,或者我可以从 Android 设备上的窗口管理器为 vulkan 应用程序提供一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42643206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com