diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-04-09 00:16:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 00:16:26 +0200 |
commit | 23d786d6fbcd374f464155c5f17f1951a664ece9 (patch) | |
tree | 689d5fdef20ddf5a9bb82e2fe9347fa2d473b4af /platform/android/vulkan | |
parent | b3310a00743d65d8baa2b5730ecfaed8bf8842a6 (diff) | |
parent | e167af37373dd14e9d1fe888bcc482d0bd071951 (diff) |
Merge pull request #36919 from nekomatata/android-vulkan-rendering
Vulkan rendering support on Android
Diffstat (limited to 'platform/android/vulkan')
-rw-r--r-- | platform/android/vulkan/vulkan_context_android.cpp (renamed from platform/android/vulkan/vk_renderer_jni.cpp) | 46 | ||||
-rw-r--r-- | platform/android/vulkan/vulkan_context_android.h (renamed from platform/android/vulkan/vk_renderer_jni.h) | 31 |
2 files changed, 45 insertions, 32 deletions
diff --git a/platform/android/vulkan/vk_renderer_jni.cpp b/platform/android/vulkan/vulkan_context_android.cpp index 3026e7daad..b238f849fc 100644 --- a/platform/android/vulkan/vk_renderer_jni.cpp +++ b/platform/android/vulkan/vulkan_context_android.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vk_renderer_jni.cpp */ +/* vulkan_context_android.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,31 +28,41 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "vk_renderer_jni.h" +#include "vulkan_context_android.h" +#include <vulkan/vulkan_android.h> -extern "C" { +#define VMA_IMPLEMENTATION +#ifdef DEBUG_ENABLED +#ifndef _DEBUG +#define _DEBUG +#endif +#endif +#include <vk_mem_alloc.h> -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated(JNIEnv *env, jobject obj, jobject j_surface) { - // TODO: complete +const char *VulkanContextAndroid::_get_platform_surface_extension() const { + return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; } -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged(JNIEnv *env, jobject object, jobject j_surface, jint width, jint height) { - // TODO: complete -} +int VulkanContextAndroid::window_create(ANativeWindow *p_window, int p_width, int p_height) { + VkAndroidSurfaceCreateInfoKHR createInfo; + createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; + createInfo.pNext = nullptr; + createInfo.flags = 0; + createInfo.window = p_window; -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume(JNIEnv *env, jobject obj) { - // TODO: complete -} + VkSurfaceKHR surface; + VkResult err = vkCreateAndroidSurfaceKHR(_get_instance(), &createInfo, nullptr, &surface); + if (err != VK_SUCCESS) { + ERR_FAIL_V_MSG(-1, "vkCreateAndroidSurfaceKHR failed with error " + itos(err)); + } -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame(JNIEnv *env, jobject obj) { - // TODO: complete + return _window_create(DisplayServer::MAIN_WINDOW_ID, surface, p_width, p_height); } -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause(JNIEnv *env, jobject obj) { - // TODO: complete +VulkanContextAndroid::VulkanContextAndroid() { + // TODO: fix validation layers + use_validation_layers = false; } -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy(JNIEnv *env, jobject obj) { - // TODO: complete -} +VulkanContextAndroid::~VulkanContextAndroid() { } diff --git a/platform/android/vulkan/vk_renderer_jni.h b/platform/android/vulkan/vulkan_context_android.h index 017766fea2..7e698ada4f 100644 --- a/platform/android/vulkan/vk_renderer_jni.h +++ b/platform/android/vulkan/vulkan_context_android.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vk_renderer_jni.h */ +/* vulkan_context_android.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef VK_RENDERER_JNI_H -#define VK_RENDERER_JNI_H +#ifndef VULKAN_CONTEXT_ANDROID_H +#define VULKAN_CONTEXT_ANDROID_H -#include <android/log.h> -#include <jni.h> +#include "drivers/vulkan/vulkan_context.h" -extern "C" { -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated(JNIEnv *env, jobject obj, jobject j_surface); -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged(JNIEnv *env, jobject object, jobject j_surface, jint width, jint height); -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume(JNIEnv *env, jobject obj); -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame(JNIEnv *env, jobject obj); -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause(JNIEnv *env, jobject obj); -JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy(JNIEnv *env, jobject obj); -} +struct ANativeWindow; -#endif // VK_RENDERER_JNI_H +class VulkanContextAndroid : public VulkanContext { + + virtual const char *_get_platform_surface_extension() const; + +public: + int window_create(ANativeWindow *p_window, int p_width, int p_height); + + VulkanContextAndroid(); + ~VulkanContextAndroid(); +}; + +#endif // VULKAN_CONTEXT_ANDROID_H |