forked from SaschaWillems/Vulkan
-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathutils.cpp
69 lines (62 loc) · 1.62 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "utils.hpp"
#include <mutex>
#include <algorithm>
#include <stdarg.h>
#if defined(__ANDROID__)
#include <memory>
#include <android/log.h>
#include <android/configuration.h>
#else
#ifdef WIN32
#include <Windows.h>
#endif
#include <iostream>
#endif
#if defined(__ANDROID__)
inline int logLevelToAndroidPriority(vkx::LogLevel level) {
switch (level) {
case vkx::LogLevel::LOG_DEBUG:
return ANDROID_LOG_DEBUG;
case vkx::LogLevel::LOG_INFO:
return ANDROID_LOG_INFO;
case vkx::LogLevel::LOG_WARN:
return ANDROID_LOG_WARN;
case vkx::LogLevel::LOG_ERROR:
return ANDROID_LOG_ERROR;
}
}
#endif
void vkx::logMessage(vkx::LogLevel level, const char* format, ...) {
va_list arglist;
va_start(arglist, format);
#if defined(__ANDROID__)
int prio = logLevelToAndroidPriority(level);
__android_log_vprint(prio, "vulkanExample", format, arglist);
#else
char buffer[8192];
vsnprintf(buffer, 8192, format, arglist);
#ifdef WIN32
OutputDebugStringA(buffer);
OutputDebugStringA("\n");
#endif
std::cout << buffer << std::endl;
#endif
va_end(arglist);
}
const std::string& vkx::getAssetPath() {
#if defined(__ANDROID__)
static const std::string NOTHING;
return NOTHING;
#else
static std::string path;
static std::once_flag once;
std::call_once(once, [] {
std::string file(__FILE__);
std::replace(file.begin(), file.end(), '\\', '/');
std::string::size_type lastSlash = file.rfind("/");
file = file.substr(0, lastSlash);
path = file + "/../data/";
});
return path;
#endif
}