mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Vulkan now fully working
Tested on Xiaomi Redmi Note 4X runnning latest global update
This commit is contained in:
parent
83c4c2d81a
commit
7848a3c72c
@ -29,19 +29,45 @@
|
|||||||
#include <android_native_app_glue.h>
|
#include <android_native_app_glue.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
|
struct android_app* app;
|
||||||
|
|
||||||
struct engine {
|
void handle_cmd(struct android_app* _app, int32_t cmd) {
|
||||||
struct android_app* app;
|
switch (cmd) {
|
||||||
};
|
case APP_CMD_INIT_WINDOW:
|
||||||
struct engine engine;
|
// The window is being shown, get it ready.
|
||||||
|
app = _app;
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "GLFW",
|
||||||
|
"Window initialized", cmd);
|
||||||
|
default:
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "GLFW",
|
||||||
|
"event not handled: %d", cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Android Entry Point
|
// Android Entry Point
|
||||||
void android_main(struct android_app *app) {
|
void android_main(struct android_app *app) {
|
||||||
memset(&engine, 0, sizeof(engine));
|
app->onAppCmd = handle_cmd;
|
||||||
app->userData = &engine;
|
pthread_t my_thread;
|
||||||
engine.app = &app;
|
pthread_create(&my_thread, NULL, &glfwMain, NULL);
|
||||||
|
|
||||||
glfwMain();
|
while (1) {
|
||||||
|
int ident;
|
||||||
|
int events;
|
||||||
|
struct android_poll_source* source;
|
||||||
|
|
||||||
|
while ((ident=ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0) {
|
||||||
|
|
||||||
|
// Process this event.
|
||||||
|
if (source != NULL) {
|
||||||
|
source->process(app, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we are exiting.
|
||||||
|
if (app->destroyRequested != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -53,7 +79,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||||||
const _GLFWctxconfig* ctxconfig,
|
const _GLFWctxconfig* ctxconfig,
|
||||||
const _GLFWfbconfig* fbconfig)
|
const _GLFWfbconfig* fbconfig)
|
||||||
{
|
{
|
||||||
window->android.app = &engine.app;
|
|
||||||
if (ctxconfig->client != GLFW_NO_API)
|
if (ctxconfig->client != GLFW_NO_API)
|
||||||
{
|
{
|
||||||
if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
|
if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
|
||||||
@ -279,7 +304,7 @@ int _glfwPlatformGetKeyScancode(int key)
|
|||||||
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
||||||
{
|
{
|
||||||
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_android_surface)
|
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_android_surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
extensions[0] = "VK_KHR_surface";
|
extensions[0] = "VK_KHR_surface";
|
||||||
extensions[1] = "VK_KHR_android_surface";
|
extensions[1] = "VK_KHR_android_surface";
|
||||||
@ -302,7 +327,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|||||||
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
|
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
|
||||||
|
|
||||||
vkCreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)
|
vkCreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)
|
||||||
vkGetInstanceProcAddr(instance, "vkCreateAndroidSurfaceKHR");
|
vkGetInstanceProcAddr(instance, "vkCreateAndroidSurfaceKHR");
|
||||||
if (!vkCreateAndroidSurfaceKHR)
|
if (!vkCreateAndroidSurfaceKHR)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||||
@ -312,7 +337,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|||||||
|
|
||||||
memset(&sci, 0, sizeof(sci));
|
memset(&sci, 0, sizeof(sci));
|
||||||
sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
||||||
sci.window = &window->android.app->window;
|
sci.window = app->window;
|
||||||
|
|
||||||
err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface);
|
err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface);
|
||||||
if (err)
|
if (err)
|
||||||
@ -333,6 +358,5 @@ GLFWAPI struct android_app * glfwGetAndroidApp(GLFWwindow* handle)
|
|||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
return window->android.app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user