Skip to content

Commit

Permalink
update glfw to v3.4 (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajveermalviya authored Mar 17, 2024
1 parent 8f94e25 commit 1ac3a5c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 58 deletions.
1 change: 0 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ add_subdirectory(texture_arrays)
add_subdirectory(triangle)

set(GLFW_BUILD_DOCS OFF)
set(GLFW_USE_WAYLAND ON)
add_subdirectory(vendor/glfw)
7 changes: 4 additions & 3 deletions examples/texture_arrays/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers)
include_directories(${CMAKE_SOURCE_DIR}/framework)

if (WIN32)
add_definitions(-DWGPU_TARGET_WINDOWS)
add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
add_definitions(-DWGPU_TARGET_LINUX_X11)
add_definitions(-DGLFW_EXPOSE_NATIVE_X11)
add_definitions(-DGLFW_EXPOSE_NATIVE_WAYLAND)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
add_definitions(-DWGPU_TARGET_MACOS)
add_definitions(-DGLFW_EXPOSE_NATIVE_COCOA)
set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal")
endif()

Expand Down
36 changes: 11 additions & 25 deletions examples/texture_arrays/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@
#include <stdlib.h>
#include <string.h>

#if defined(WGPU_TARGET_MACOS)
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
#include <Foundation/Foundation.h>
#include <QuartzCore/CAMetalLayer.h>
#endif

#include <GLFW/glfw3.h>
#if defined(WGPU_TARGET_MACOS)
#define GLFW_EXPOSE_NATIVE_COCOA
#elif defined(WGPU_TARGET_LINUX_X11)
#define GLFW_EXPOSE_NATIVE_X11
#elif defined(WGPU_TARGET_LINUX_WAYLAND)
#define GLFW_EXPOSE_NATIVE_WAYLAND
#elif defined(WGPU_TARGET_WINDOWS)
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#include <GLFW/glfw3native.h>

#define LOG_PREFIX "[texture_arrays]"
Expand Down Expand Up @@ -129,10 +121,8 @@ int main(int argc, char *argv[]) {
UNUSED(argv)
frmwrk_setup_logging(WGPULogLevel_Warn);

#if defined(WGPU_TARGET_LINUX_WAYLAND)
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
#endif
assert(glfwInit());
if (!glfwInit())
exit(EXIT_FAILURE);

struct demo demo = {0};
demo.instance = wgpuCreateInstance(NULL);
Expand All @@ -145,7 +135,7 @@ int main(int argc, char *argv[]) {
glfwSetWindowUserPointer(window, (void *)&demo);
glfwSetFramebufferSizeCallback(window, handle_glfw_framebuffer_size);

#if defined(WGPU_TARGET_MACOS)
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
{
id metal_layer = NULL;
NSWindow *ns_window = glfwGetCocoaWindow(window);
Expand All @@ -165,10 +155,9 @@ int main(int argc, char *argv[]) {
.layer = metal_layer,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_LINUX_X11)
{
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) && defined(GLFW_EXPOSE_NATIVE_X11)
if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
Display *x11_display = glfwGetX11Display();
Window x11_window = glfwGetX11Window(window);
demo.surface = wgpuInstanceCreateSurface(
Expand All @@ -185,10 +174,8 @@ int main(int argc, char *argv[]) {
.window = x11_window,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_LINUX_WAYLAND)
{
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
struct wl_display *wayland_display = glfwGetWaylandDisplay();
struct wl_surface *wayland_surface = glfwGetWaylandWindow(window);
demo.surface = wgpuInstanceCreateSurface(
Expand All @@ -206,9 +193,8 @@ int main(int argc, char *argv[]) {
.surface = wayland_surface,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_WINDOWS)
#elif defined(GLFW_EXPOSE_NATIVE_WIN32)
{
HWND hwnd = glfwGetWin32Window(window);
HINSTANCE hinstance = GetModuleHandle(NULL);
Expand All @@ -226,11 +212,11 @@ int main(int argc, char *argv[]) {
.hwnd = hwnd,
},
});
assert(demo.surface);
}
#else
#error "Unsupported WGPU_TARGET"
#error "Unsupported GLFW native platform"
#endif
assert(demo.surface);

wgpuInstanceRequestAdapter(demo.instance,
&(const WGPURequestAdapterOptions){
Expand Down
7 changes: 4 additions & 3 deletions examples/triangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers)
include_directories(${CMAKE_SOURCE_DIR}/framework)

if (WIN32)
add_definitions(-DWGPU_TARGET_WINDOWS)
add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
add_definitions(-DWGPU_TARGET_LINUX_X11)
add_definitions(-DGLFW_EXPOSE_NATIVE_X11)
add_definitions(-DGLFW_EXPOSE_NATIVE_WAYLAND)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
add_definitions(-DWGPU_TARGET_MACOS)
add_definitions(-DGLFW_EXPOSE_NATIVE_COCOA)
set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal")
endif()

Expand Down
35 changes: 10 additions & 25 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,12 @@
#include <stdlib.h>
#include <string.h>

#if defined(WGPU_TARGET_MACOS)
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
#include <Foundation/Foundation.h>
#include <QuartzCore/CAMetalLayer.h>
#endif

#include <GLFW/glfw3.h>
#if defined(WGPU_TARGET_MACOS)
#define GLFW_EXPOSE_NATIVE_COCOA
#elif defined(WGPU_TARGET_LINUX_X11)
#define GLFW_EXPOSE_NATIVE_X11
#elif defined(WGPU_TARGET_LINUX_WAYLAND)
#define GLFW_EXPOSE_NATIVE_WAYLAND
#elif defined(WGPU_TARGET_WINDOWS)
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#include <GLFW/glfw3native.h>

#define LOG_PREFIX "[triangle]"
Expand Down Expand Up @@ -91,10 +82,8 @@ int main(int argc, char *argv[]) {
UNUSED(argv)
frmwrk_setup_logging(WGPULogLevel_Warn);

#if defined(WGPU_TARGET_LINUX_WAYLAND)
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
#endif
assert(glfwInit());
if (!glfwInit())
exit(EXIT_FAILURE);

struct demo demo = {0};
demo.instance = wgpuCreateInstance(NULL);
Expand All @@ -109,7 +98,7 @@ int main(int argc, char *argv[]) {
glfwSetKeyCallback(window, handle_glfw_key);
glfwSetFramebufferSizeCallback(window, handle_glfw_framebuffer_size);

#if defined(WGPU_TARGET_MACOS)
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
{
id metal_layer = NULL;
NSWindow *ns_window = glfwGetCocoaWindow(window);
Expand All @@ -129,10 +118,9 @@ int main(int argc, char *argv[]) {
.layer = metal_layer,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_LINUX_X11)
{
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) && defined(GLFW_EXPOSE_NATIVE_X11)
if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
Display *x11_display = glfwGetX11Display();
Window x11_window = glfwGetX11Window(window);
demo.surface = wgpuInstanceCreateSurface(
Expand All @@ -149,10 +137,8 @@ int main(int argc, char *argv[]) {
.window = x11_window,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_LINUX_WAYLAND)
{
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
struct wl_display *wayland_display = glfwGetWaylandDisplay();
struct wl_surface *wayland_surface = glfwGetWaylandWindow(window);
demo.surface = wgpuInstanceCreateSurface(
Expand All @@ -170,9 +156,8 @@ int main(int argc, char *argv[]) {
.surface = wayland_surface,
},
});
assert(demo.surface);
}
#elif defined(WGPU_TARGET_WINDOWS)
#elif defined(GLFW_EXPOSE_NATIVE_WIN32)
{
HWND hwnd = glfwGetWin32Window(window);
HINSTANCE hinstance = GetModuleHandle(NULL);
Expand All @@ -190,11 +175,11 @@ int main(int argc, char *argv[]) {
.hwnd = hwnd,
},
});
assert(demo.surface);
}
#else
#error "Unsupported WGPU_TARGET"
#error "Unsupported GLFW native platform"
#endif
assert(demo.surface);

wgpuInstanceRequestAdapter(demo.instance,
&(const WGPURequestAdapterOptions){
Expand Down
2 changes: 1 addition & 1 deletion examples/vendor/glfw
Submodule glfw updated 99 files
+5 −5 .appveyor.yml
+67 −0 .editorconfig
+0 −2 .github/CODEOWNERS
+60 −54 .github/workflows/build.yml
+1 −0 .gitignore
+1 −1 CMake/glfw3.pc.in
+8 −14 CMakeLists.txt
+29 −0 CONTRIBUTORS.md
+75 −39 README.md
+0 −247 deps/vs2008/stdint.h
+102 −0 deps/wayland/fractional-scale-v1.xml
+83 −0 deps/wayland/idle-inhibit-unstable-v1.xml
+339 −0 deps/wayland/pointer-constraints-unstable-v1.xml
+136 −0 deps/wayland/relative-pointer-unstable-v1.xml
+180 −0 deps/wayland/viewporter.xml
+3,151 −0 deps/wayland/wayland.xml
+200 −0 deps/wayland/xdg-activation-v1.xml
+156 −0 deps/wayland/xdg-decoration-unstable-v1.xml
+1,370 −0 deps/wayland/xdg-shell.xml
+37 −26 docs/CMakeLists.txt
+8 −9 docs/CONTRIBUTING.md
+113 −67 docs/Doxyfile.in
+1 −1 docs/DoxygenLayout.xml
+1 −2 docs/SUPPORT.md
+159 −78 docs/build.md
+85 −77 docs/compat.md
+90 −113 docs/compile.md
+45 −47 docs/context.md
+1 −1 docs/extra.css
+1 −1 docs/extra.css.map
+4 −0 docs/extra.scss
+167 −163 docs/input.md
+9 −12 docs/internal.md
+93 −85 docs/intro.md
+2 −10 docs/main.md
+44 −55 docs/monitor.md
+149 −141 docs/moving.md
+0 −292 docs/news.dox
+402 −0 docs/news.md
+58 −60 docs/quick.md
+34 −37 docs/vulkan.md
+253 −212 docs/window.md
+0 −1 examples/sharing.c
+215 −100 include/GLFW/glfw3.h
+63 −34 include/GLFW/glfw3native.h
+31 −63 src/CMakeLists.txt
+72 −74 src/cocoa_init.m
+8 −5 src/cocoa_joystick.m
+15 −3 src/cocoa_monitor.m
+2 −2 src/cocoa_platform.h
+0 −2 src/cocoa_time.c
+32 −13 src/cocoa_window.m
+2 −2 src/context.c
+12 −10 src/egl_context.c
+1 −2 src/glx_context.c
+11 −34 src/init.c
+13 −8 src/input.c
+25 −28 src/internal.h
+6 −5 src/linux_joystick.c
+1 −0 src/linux_joystick.h
+4 −4 src/monitor.c
+13 −9 src/nsgl_context.m
+72 −74 src/null_init.c
+0 −2 src/null_joystick.c
+3 −4 src/null_monitor.c
+1 −3 src/null_platform.h
+2 −3 src/null_window.c
+2 −5 src/osmesa_context.c
+22 −5 src/platform.c
+9 −0 src/platform.h
+0 −2 src/posix_module.c
+0 −2 src/posix_poll.c
+0 −2 src/posix_poll.h
+0 −2 src/posix_thread.c
+0 −2 src/posix_time.c
+0 −2 src/vulkan.c
+18 −2 src/wgl_context.c
+75 −75 src/win32_init.c
+7 −2 src/win32_joystick.c
+0 −2 src/win32_module.c
+22 −4 src/win32_monitor.c
+4 −1 src/win32_platform.h
+0 −2 src/win32_thread.c
+5 −0 src/win32_thread.h
+0 −2 src/win32_time.c
+5 −0 src/win32_time.h
+109 −20 src/win32_window.c
+26 −9 src/window.c
+177 −96 src/wl_init.c
+17 −21 src/wl_monitor.c
+31 −26 src/wl_platform.h
+545 −421 src/wl_window.c
+77 −79 src/x11_init.c
+27 −6 src/x11_monitor.c
+1 −1 src/x11_platform.h
+17 −15 src/x11_window.c
+0 −2 src/xkb_unicode.c
+23 −13 tests/events.c
+36 −7 tests/window.c

0 comments on commit 1ac3a5c

Please sign in to comment.