diff options
Diffstat (limited to 'src/platform.cc')
| -rw-r--r-- | src/platform.cc | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/src/platform.cc b/src/platform.cc index 8df9992..5d5c082 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -8,40 +8,45 @@ // --- Callbacks --- -static void framebuffer_size_callback(GLFWwindow* window, int width, int height) { - PlatformState* state = (PlatformState*)glfwGetWindowUserPointer(window); - if (state) { - state->width = width; - state->height = height; - } +static void framebuffer_size_callback(GLFWwindow* window, int width, + int height) { + PlatformState* state = (PlatformState*)glfwGetWindowUserPointer(window); + if (state) { + state->width = width; + state->height = height; + } } -static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - PlatformState* state = (PlatformState*)glfwGetWindowUserPointer(window); - if (action == GLFW_PRESS) { - if (key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) { - glfwSetWindowShouldClose(window, GLFW_TRUE); - } else if (key == GLFW_KEY_F) { - if (state) platform_toggle_fullscreen(state); - } +static void glfw_key_callback(GLFWwindow* window, int key, int scancode, + int action, int mods) { + PlatformState* state = (PlatformState*)glfwGetWindowUserPointer(window); + if (action == GLFW_PRESS) { + if (key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) { + glfwSetWindowShouldClose(window, GLFW_TRUE); + } else if (key == GLFW_KEY_F) { + if (state) + platform_toggle_fullscreen(state); } + } } // --- Public API Implementation --- -void platform_init(PlatformState* state, bool fullscreen, int* width_ptr, int* height_ptr) { +void platform_init(PlatformState* state, bool fullscreen, int* width_ptr, + int* height_ptr) { if (width_ptr && height_ptr) { - state->width = *width_ptr; - state->height = *height_ptr; + state->width = *width_ptr; + state->height = *height_ptr; } glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - state->window = glfwCreateWindow(state->width, state->height, "demo64k", nullptr, nullptr); - + state->window = glfwCreateWindow(state->width, state->height, "demo64k", + nullptr, nullptr); + // Store our state pointer in the window for callbacks glfwSetWindowUserPointer(state->window, state); - + // Immediately query the actual framebuffer size for high-DPI displays glfwGetFramebufferSize(state->window, &state->width, &state->height); @@ -55,7 +60,8 @@ void platform_init(PlatformState* state, bool fullscreen, int* width_ptr, int* h GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); - glfwSetWindowMonitor(state->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + glfwSetWindowMonitor(state->window, monitor, 0, 0, mode->width, + mode->height, mode->refreshRate); } } @@ -82,13 +88,17 @@ void platform_toggle_fullscreen(PlatformState* state) { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); - glfwSetWindowMonitor(state->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + glfwSetWindowMonitor(state->window, monitor, 0, 0, mode->width, + mode->height, mode->refreshRate); } else { - glfwSetWindowMonitor(state->window, nullptr, state->windowed_x, state->windowed_y, state->windowed_w, state->windowed_h, 0); + glfwSetWindowMonitor(state->window, nullptr, state->windowed_x, + state->windowed_y, state->windowed_w, + state->windowed_h, 0); } } -WGPUSurface platform_create_wgpu_surface(WGPUInstance instance, PlatformState* state) { +WGPUSurface platform_create_wgpu_surface(WGPUInstance instance, + PlatformState* state) { return glfwCreateWindowWGPUSurface(instance, state->window); } |
