Moved android_app object to global scope
This commit is contained in:
parent
3dfb17c89a
commit
839fc84d69
7 changed files with 40 additions and 51 deletions
|
|
@ -87,10 +87,6 @@ namespace vks
|
|||
uint32_t indexCount = 0;
|
||||
uint32_t vertexCount = 0;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
AAssetManager* assetManager = nullptr;
|
||||
#endif
|
||||
|
||||
/** @brief Stores vertex and index base and counts for each part of a model */
|
||||
struct ModelPart {
|
||||
uint32_t vertexBase;
|
||||
|
|
@ -121,7 +117,7 @@ namespace vks
|
|||
}
|
||||
}
|
||||
|
||||
boolean loadFromFile(
|
||||
bool loadFromFile(
|
||||
vk::VulkanDevice *device,
|
||||
const std::string& filename,
|
||||
vks::VertexLayout layout,
|
||||
|
|
@ -139,7 +135,7 @@ namespace vks
|
|||
// Meshes are stored inside the apk on Android (compressed)
|
||||
// So they need to be loaded via the asset manager
|
||||
|
||||
AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
assert(asset);
|
||||
size_t size = AAsset_getLength(asset);
|
||||
|
||||
|
|
|
|||
|
|
@ -67,10 +67,6 @@ namespace vkTools
|
|||
VkCommandBuffer cmdBuffer;
|
||||
VkCommandPool cmdPool;
|
||||
public:
|
||||
#if defined(__ANDROID__)
|
||||
AAssetManager* assetManager = nullptr;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
|
|
@ -126,11 +122,9 @@ namespace vkTools
|
|||
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
{
|
||||
#if defined(__ANDROID__)
|
||||
assert(assetManager != nullptr);
|
||||
|
||||
// Textures are stored inside the apk on Android (compressed)
|
||||
// So they need to be loaded via the asset manager
|
||||
AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
assert(asset);
|
||||
size_t size = AAsset_getLength(asset);
|
||||
assert(size > 0);
|
||||
|
|
@ -457,11 +451,9 @@ namespace vkTools
|
|||
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
{
|
||||
#if defined(__ANDROID__)
|
||||
assert(assetManager != nullptr);
|
||||
|
||||
// Textures are stored inside the apk on Android (compressed)
|
||||
// So they need to be loaded via the asset manager
|
||||
AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
assert(asset);
|
||||
size_t size = AAsset_getLength(asset);
|
||||
assert(size > 0);
|
||||
|
|
@ -680,11 +672,9 @@ namespace vkTools
|
|||
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
{
|
||||
#if defined(__ANDROID__)
|
||||
assert(assetManager != nullptr);
|
||||
|
||||
// Textures are stored inside the apk on Android (compressed)
|
||||
// So they need to be loaded via the asset manager
|
||||
AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||
assert(asset);
|
||||
size_t size = AAsset_getLength(asset);
|
||||
assert(size > 0);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@
|
|||
#include "vulkanandroid.h"
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#include <dlfcn.h>
|
||||
#include <android/log.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
android_app* androidApp;
|
||||
|
||||
PFN_vkCreateInstance vkCreateInstance;
|
||||
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
||||
|
|
@ -122,40 +124,40 @@ void *libVulkan;
|
|||
// Dynamically load Vulkan library and base function pointers
|
||||
bool loadVulkanLibrary()
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Loading libvulkan.so...\n");
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Loading libvulkan.so...\n");
|
||||
|
||||
// Load vulkan library
|
||||
libVulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!libVulkan)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Could not load vulkan library : %s!\n", dlerror());
|
||||
return false;
|
||||
}
|
||||
// Load vulkan library
|
||||
libVulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!libVulkan)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Could not load vulkan library : %s!\n", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load base function pointers
|
||||
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(dlsym(libVulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
vkEnumerateInstanceLayerProperties = reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(dlsym(libVulkan, "vkEnumerateInstanceLayerProperties"));
|
||||
vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(dlsym(libVulkan, "vkCreateInstance"));
|
||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libVulkan, "vkGetInstanceProcAddr"));
|
||||
// Load base function pointers
|
||||
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(dlsym(libVulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
vkEnumerateInstanceLayerProperties = reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(dlsym(libVulkan, "vkEnumerateInstanceLayerProperties"));
|
||||
vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(dlsym(libVulkan, "vkCreateInstance"));
|
||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libVulkan, "vkGetInstanceProcAddr"));
|
||||
vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(dlsym(libVulkan, "vkGetDeviceProcAddr"));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load instance based Vulkan function pointers
|
||||
void loadVulkanFunctions(VkInstance instance)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Loading instance based function pointers...\n");
|
||||
__android_log_print(ANDROID_LOG_INFO, "vulkanandroid", "Loading instance based function pointers...\n");
|
||||
|
||||
vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"));
|
||||
vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties"));
|
||||
vkEnumerateDeviceLayerProperties = reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(vkGetInstanceProcAddr(instance, "vkEnumerateDeviceLayerProperties"));
|
||||
vkEnumerateDeviceExtensionProperties = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(vkGetInstanceProcAddr(instance, "vkEnumerateDeviceExtensionProperties"));
|
||||
vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures"));
|
||||
vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(vkGetInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
vkGetPhysicalDeviceFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFormatProperties"));
|
||||
vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"));
|
||||
vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties"));
|
||||
vkEnumerateDeviceLayerProperties = reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(vkGetInstanceProcAddr(instance, "vkEnumerateDeviceLayerProperties"));
|
||||
vkEnumerateDeviceExtensionProperties = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(vkGetInstanceProcAddr(instance, "vkEnumerateDeviceExtensionProperties"));
|
||||
vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures"));
|
||||
vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(vkGetInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
vkGetPhysicalDeviceFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFormatProperties"));
|
||||
vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
|
||||
vkCmdPipelineBarrier = reinterpret_cast<PFN_vkCmdPipelineBarrier>(vkGetInstanceProcAddr(instance, "vkCmdPipelineBarrier"));
|
||||
vkCreateShaderModule = reinterpret_cast<PFN_vkCreateShaderModule>(vkGetInstanceProcAddr(instance, "vkCreateShaderModule"));
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#if defined(__ANDROID__)
|
||||
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
#include <memory>
|
||||
|
||||
// Missing from the NDK
|
||||
|
|
@ -35,6 +36,9 @@ namespace std
|
|||
}
|
||||
}
|
||||
|
||||
// Global reference to android application object
|
||||
extern android_app* androidApp;
|
||||
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "vulkanExample", __VA_ARGS__))
|
||||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "vulkanExample", __VA_ARGS__))
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "vulkanExample", __VA_ARGS__))
|
||||
|
|
|
|||
|
|
@ -173,9 +173,6 @@ void VulkanExampleBase::prepare()
|
|||
setupFrameBuffer();
|
||||
// Create a simple texture loader class
|
||||
textureLoader = new vkTools::VulkanTextureLoader(vulkanDevice, queue, cmdPool);
|
||||
#if defined(__ANDROID__)
|
||||
textureLoader->assetManager = androidApp->activity->assetManager;
|
||||
#endif
|
||||
if (enableTextOverlay)
|
||||
{
|
||||
// Load the text rendering shaders
|
||||
|
|
@ -1101,7 +1098,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
|||
break;
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
LOGD("APP_CMD_INIT_WINDOW");
|
||||
if (vulkanExample->androidApp->window != NULL)
|
||||
if (androidApp->window != NULL)
|
||||
{
|
||||
vulkanExample->initVulkan();
|
||||
vulkanExample->initSwapchain();
|
||||
|
|
|
|||
|
|
@ -188,7 +188,6 @@ public:
|
|||
HWND window;
|
||||
HINSTANCE windowInstance;
|
||||
#elif defined(__ANDROID__)
|
||||
android_app* androidApp;
|
||||
// true if application has focused, false if moved to background
|
||||
bool focused = false;
|
||||
#elif defined(__linux__)
|
||||
|
|
@ -359,7 +358,7 @@ void android_main(android_app* state) \
|
|||
state->userData = vulkanExample; \
|
||||
state->onAppCmd = VulkanExample::handleAppCommand; \
|
||||
state->onInputEvent = VulkanExample::handleAppInput; \
|
||||
vulkanExample->androidApp = state; \
|
||||
androidApp = state; \
|
||||
vulkanExample->renderLoop(); \
|
||||
delete(vulkanExample); \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Base", "Base", "{09B9A54B-F
|
|||
base\vulkanheightmap.hpp = base\vulkanheightmap.hpp
|
||||
base\VulkanInitializers.hpp = base\VulkanInitializers.hpp
|
||||
base\vulkanMeshLoader.hpp = base\vulkanMeshLoader.hpp
|
||||
base\VulkanModelLoader.hpp = base\VulkanModelLoader.hpp
|
||||
base\vulkanscene.hpp = base\vulkanscene.hpp
|
||||
base\vulkanswapchain.hpp = base\vulkanswapchain.hpp
|
||||
base\vulkantextoverlay.hpp = base\vulkantextoverlay.hpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue