forked from catsout/wallpaper-engine-kde-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glfwviewer.cpp
111 lines (88 loc) · 3.37 KB
/
glfwviewer.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <set>
#include <fstream>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <atomic>
#include "arg.hpp"
#include "SceneWallpaper.hpp"
#include "SceneWallpaperSurface.hpp"
#include "Utils/Platform.hpp"
using namespace std;
atomic<bool> renderCall(false);
struct UserData {
wallpaper::SceneWallpaper* psw { nullptr };
uint16_t width;
uint16_t height;
};
extern "C" {
void framebuffer_size_callback(GLFWwindow*, int width, int height) {}
void mouse_button_callback(GLFWwindow* win, int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
UserData* data = static_cast<UserData*>(glfwGetWindowUserPointer(win));
// data->psw->setPropertyString(wallpaper::PROPERTY_SOURCE,
}
}
void cursor_position_callback(GLFWwindow* win, double xpos, double ypos) {
UserData* data = static_cast<UserData*>(glfwGetWindowUserPointer(win));
data->psw->mouseInput(xpos / data->width, ypos / data->height);
}
}
void updateCallback() {
renderCall = true;
glfwPostEmptyEvent();
}
int main(int argc, char** argv) {
argparse::ArgumentParser program("scene-viewer");
setAndParseArg(program, argc, argv);
auto [w_width, w_height] = program.get<Resolution>(OPT_RESOLUTION);
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(w_width, w_height, "WP", nullptr, nullptr);
UserData data;
data.width = w_width;
data.height = w_height;
wallpaper::RenderInitInfo info;
info.enable_valid_layer = program.get<bool>(OPT_VALID_LAYER);
info.width = w_width;
info.height = w_height;
auto& sf_info = info.surface_info;
{
uint32_t glfwExtCount = 0;
auto exts = glfwGetRequiredInstanceExtensions(&glfwExtCount);
for (int i = 0; i < glfwExtCount; i++) {
sf_info.instanceExts.emplace_back(exts[i]);
}
sf_info.createSurfaceOp = [window](VkInstance inst, VkSurfaceKHR* surface) {
return glfwCreateWindowSurface(inst, window, NULL, surface);
};
}
if (window == nullptr) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
auto* psw = new wallpaper::SceneWallpaper();
data.psw = psw;
psw->init();
psw->initVulkan(info);
psw->setPropertyString(wallpaper::PROPERTY_ASSETS, program.get<std::string>(ARG_ASSETS));
psw->setPropertyString(wallpaper::PROPERTY_SOURCE, program.get<std::string>(ARG_SCENE));
psw->setPropertyBool(wallpaper::PROPERTY_GRAPHIVZ, program.get<bool>(OPT_GRAPHVIZ));
psw->setPropertyInt32(wallpaper::PROPERTY_FPS, program.get<int32_t>(OPT_FPS));
std::string cache_path = program.get<std::string>(OPT_CACHE_PATH);
if (cache_path.empty()) cache_path = wallpaper::platform::GetCachePath("wescene-renderer");
psw->setPropertyString(wallpaper::PROPERTY_CACHE_PATH, cache_path);
glfwSetWindowUserPointer(window, &data);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
while (! glfwWindowShouldClose(window)) {
glfwPollEvents();
}
delete psw;
// wgl.Clear();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}