Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #76

Merged
merged 16 commits into from
Sep 20, 2024
Merged

Dev #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ source_group("Textures" FILES ${texture_files})
add_custom_target(
Assets
DEPENDS ${copied_fonts} ${copied_locale} ${copied_models} ${compiled_shaders} ${copied_textures}
SOURCES ${font_files} ${model_files} ${shader_files} ${shader_extra_files} ${texture_files} ${shader_common_files})
SOURCES ${font_files} ${locale_files} ${model_files} ${shader_files} ${shader_extra_files} ${texture_files} ${shader_common_files})


# Shader compilation -> POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
if defined FOUND (
set CMAKE=cmake
) ELSE (
set CMAKE="%CD%\build\vcpkg.windows\downloads\tools\cmake-3.27.1-windows\cmake-3.27.1-windows-i386\bin\cmake.exe"
set CMAKE="%CD%\build\vcpkg.windows\downloads\tools\cmake-3.29.2-windows\cmake-3.29.2-windows-i386\bin\cmake.exe"
)

for %%X in (msbuild.exe) do (set FOUND=%%~$PATH:X)
Expand Down
2 changes: 1 addition & 1 deletion build_windows_oidn.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
if defined FOUND (
set CMAKE=cmake
) ELSE (
set CMAKE="%CD%\build\vcpkg.windows\downloads\tools\cmake-3.27.1-windows\cmake-3.27.1-windows-i386\bin\cmake.exe"
set CMAKE="%CD%\build\vcpkg.windows\downloads\tools\cmake-3.29.2-windows\cmake-3.29.2-windows-i386\bin\cmake.exe"
)

for %%X in (msbuild.exe) do (set FOUND=%%~$PATH:X)
Expand Down
136 changes: 136 additions & 0 deletions src/AndroidMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "Vulkan/Enumerate.hpp"
#include "Vulkan/Strings.hpp"
#include "Utilities/Console.hpp"
#include "Utilities/Exception.hpp"
#include "Options.hpp"
#include "Runtime/Application.hpp"
#include <algorithm>
#include <cstdlib>
#include <fmt/format.h>
#include <iostream>
#include <filesystem>

#include "Runtime/Platform/PlatformCommon.h"

#include <imgui_impl_android.h>
#include <android/log.h>
#include <game-activity/native_app_glue/android_native_app_glue.h>

std::unique_ptr<NextRendererApplication> GApplication = nullptr;

void handle_cmd(android_app* app, int32_t cmd) {
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
{
MakeExternalDirectory(app, "assets/fonts");
MakeExternalDirectory(app, "assets/models");
MakeExternalDirectory(app, "assets/shaders");
MakeExternalDirectory(app, "assets/textures");
MakeExternalDirectory(app, "assets/locale");

const char* argv[] = { "gkNextRenderer", "--renderer=4", "--scene=1", "--load-scene=qx50.glb"};
const Options options(4, argv);
GOption = &options;
GApplication.reset(new NextRendererApplication(options));
__android_log_print(ANDROID_LOG_INFO, "vkdemo",
"start gknextrenderer: %d", options.RendererType);
GApplication->Start();
}
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
{

}
break;
default:
__android_log_print(ANDROID_LOG_INFO, "Vulkan Tutorials",
"event not handled: %d", cmd);
}
}

static int32_t engine_handle_input(struct android_app* app) {
ImGuiIO& io = ImGui::GetIO();
//auto* engine = (struct engine*)app->userData;
auto ib = android_app_swap_input_buffers(app);
if (ib && ib->motionEventsCount) {
for (int i = 0; i < ib->motionEventsCount; i++) {
auto *event = &ib->motionEvents[i];
int32_t ptrIdx = 0;
switch (event->action & AMOTION_EVENT_ACTION_MASK) {
case AMOTION_EVENT_ACTION_POINTER_DOWN:
case AMOTION_EVENT_ACTION_POINTER_UP:
// Retrieve the index for the starting and the ending of any secondary pointers
ptrIdx = (event->action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
case AMOTION_EVENT_ACTION_DOWN:
case AMOTION_EVENT_ACTION_UP:
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
io.AddMousePosEvent(GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_X) * 0.75, GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_Y) * 0.75);
io.AddMouseButtonEvent(0, event->action == AMOTION_EVENT_ACTION_DOWN);

GApplication->OnTouch(event->action == AMOTION_EVENT_ACTION_DOWN, GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_Y) * 0.75,
GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_X) * 0.75);

break;
case AMOTION_EVENT_ACTION_MOVE:
// Process the move action: the new coordinates for all active touch pointers
// are inside the event->pointers[]. Compare with our internally saved
// coordinates to find out which pointers are actually moved. Note that there is
// no index embedded inside event->action for AMOTION_EVENT_ACTION_MOVE (there
// might be multiple pointers moved at the same time).
//...
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
io.AddMousePosEvent(GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_X) * 0.75,
GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_Y) * 0.75);

GApplication->OnTouchMove(GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_Y) * 0.75,
GameActivityPointerAxes_getAxisValue(
&event->pointers[ptrIdx], AMOTION_EVENT_AXIS_X) * 0.75);
break;
}
}
android_app_clear_motion_events(ib);
}

// Process the KeyEvent in a similar way.
//...

return 0;
}

void android_main(struct android_app* app)
{
std::cout.rdbuf(new androidbuf);

app->onAppCmd = handle_cmd;

// Used to poll the events in the main loop
int events;
android_poll_source* source;

// Main loop
do {
if (ALooper_pollAll(GApplication != nullptr ? 1 : 0, nullptr,
&events, (void**)&source) >= 0) {
if (source != NULL) source->process(app, source);
}

engine_handle_input(app);

// render if vulkan is ready
if (GApplication != nullptr) {
GApplication->Tick();
}
} while (app->destroyRequested == 0);

delete std::cout.rdbuf(0);
}
Loading
Loading