mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Linux support for GLFW example
This commit is contained in:
parent
2a47ced556
commit
e8e5938e06
2
Makefile
2
Makefile
@ -54,7 +54,7 @@ lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
|
||||
cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST)
|
||||
|
||||
wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
|
||||
cargo run --manifest-path wgpu-bindings/Cargo.toml
|
||||
cargo +nightly-2018-12-27 run --manifest-path wgpu-bindings/Cargo.toml
|
||||
|
||||
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)
|
||||
$(MAKE) -C examples
|
||||
|
@ -8,12 +8,16 @@ add_executable(hello_triangle main.c)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(${TARGET_NAME} PRIVATE /W4)
|
||||
add_compile_definitions(WGPU_TARGET=WGPU_TARGET_WINDOWS)
|
||||
set(GLFW_LIBRARY glfw3)
|
||||
else(MSVC)
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
||||
add_compile_definitions(WGPU_TARGET=WGPU_TARGET_LINUX)
|
||||
set(GLFW_LIBRARY glfw)
|
||||
endif(MSVC)
|
||||
|
||||
if(APPLE)
|
||||
add_compile_definitions(WGPU_TARGET WGPU_TARGET_MACOS)
|
||||
add_compile_definitions(WGPU_TARGET=WGPU_TARGET_MACOS)
|
||||
set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore")
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -x objective-c)
|
||||
endif(APPLE)
|
||||
@ -24,4 +28,4 @@ find_library(WGPU_LIBRARY wgpu_native
|
||||
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug"
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} glfw3 ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
||||
target_link_libraries(${TARGET_NAME} ${GLFW_LIBRARY} ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
||||
|
@ -14,7 +14,8 @@
|
||||
#if WGPU_TARGET == WGPU_TARGET_MACOS
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX
|
||||
// TODO
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#endif
|
||||
@ -187,7 +188,9 @@ int main()
|
||||
}
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX
|
||||
{
|
||||
// TODO
|
||||
Display* x11_display = glfwGetX11Display();
|
||||
Window x11_window = glfwGetX11Window(window);
|
||||
surface = wgpu_instance_create_surface_from_xlib(instance, (const void**)x11_display, x11_window);
|
||||
}
|
||||
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
||||
{
|
||||
|
@ -513,6 +513,10 @@ WGPUSurfaceId wgpu_instance_create_surface_from_windows_hwnd(WGPUInstanceId inst
|
||||
void *hinstance,
|
||||
void *hwnd);
|
||||
|
||||
WGPUSurfaceId wgpu_instance_create_surface_from_xlib(WGPUInstanceId instance_id,
|
||||
const void **display,
|
||||
uint64_t window);
|
||||
|
||||
WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id,
|
||||
const WGPUAdapterDescriptor *desc);
|
||||
|
||||
|
@ -63,6 +63,32 @@ pub extern "C" fn wgpu_instance_create_surface_from_winit(
|
||||
.register(surface)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_instance_create_surface_from_xlib(
|
||||
instance_id: InstanceId,
|
||||
display: *mut *const std::ffi::c_void,
|
||||
window: u64,
|
||||
) -> SurfaceId {
|
||||
#[cfg(not(feature = "gfx-backend-vulkan"))]
|
||||
unimplemented!();
|
||||
|
||||
#[cfg(feature = "gfx-backend-vulkan")]
|
||||
{
|
||||
let raw = HUB.instances
|
||||
.read()
|
||||
.get(instance_id)
|
||||
.create_surface_from_xlib(display, window);
|
||||
let surface = Surface {
|
||||
raw,
|
||||
};
|
||||
|
||||
HUB.surfaces
|
||||
.write()
|
||||
.register(surface)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_instance_create_surface_from_macos_layer(
|
||||
@ -95,7 +121,7 @@ pub extern "C" fn wgpu_instance_create_surface_from_windows_hwnd(
|
||||
hinstance: *mut std::ffi::c_void,
|
||||
hwnd: *mut std::ffi::c_void,
|
||||
) -> SurfaceId {
|
||||
#[cfg(not(any(feature = "gfx-backend-dx11", feature = "gfx-backend-dx12", feature = "gfx-backend-vulkan")))]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
unimplemented!();
|
||||
|
||||
#[cfg(any(feature = "gfx-backend-dx11", feature = "gfx-backend-dx12"))]
|
||||
@ -114,7 +140,7 @@ pub extern "C" fn wgpu_instance_create_surface_from_windows_hwnd(
|
||||
.register(surface)
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gfx-backend-vulkan"))]
|
||||
#[cfg(all(target_os = "windows", feature = "gfx-backend-vulkan"))]
|
||||
{
|
||||
let raw = HUB.instances
|
||||
.read()
|
||||
|
Loading…
Reference in New Issue
Block a user