mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
Add support for GLFW on Windows
This commit is contained in:
parent
26f965cfbb
commit
3d98457eb9
@ -7,7 +7,7 @@ set(TARGET_NAME hello_triangle)
|
|||||||
add_executable(hello_triangle main.c)
|
add_executable(hello_triangle main.c)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX)
|
target_compile_options(${TARGET_NAME} PRIVATE /W4)
|
||||||
else(MSVC)
|
else(MSVC)
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
@ -24,4 +24,4 @@ find_library(WGPU_LIBRARY wgpu_native
|
|||||||
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug"
|
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME} glfw ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
target_link_libraries(${TARGET_NAME} glfw3 ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
||||||
|
@ -191,7 +191,9 @@ int main()
|
|||||||
}
|
}
|
||||||
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
||||||
{
|
{
|
||||||
// TODO
|
HWND hwnd = glfwGetWin32Window(window);
|
||||||
|
HINSTANCE hinstance = GetModuleHandle(NULL);
|
||||||
|
surface = wgpu_instance_create_surface_from_windows_hwnd(instance, hinstance, hwnd);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -206,7 +208,7 @@ int main()
|
|||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
WGPUSwapChainOutput next_texture = wgpu_swap_chain_get_next_texture(swap_chain);
|
WGPUSwapChainOutput next_texture = wgpu_swap_chain_get_next_texture(swap_chain);
|
||||||
WGPUCommandBufferDescriptor cmd_buf_desc = {};
|
WGPUCommandBufferDescriptor cmd_buf_desc = { .todo = 0 };
|
||||||
WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, &cmd_buf_desc);
|
WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, &cmd_buf_desc);
|
||||||
WGPURenderPassColorAttachmentDescriptor_TextureViewId color_attachments[ATTACHMENTS_LENGTH] = {
|
WGPURenderPassColorAttachmentDescriptor_TextureViewId color_attachments[ATTACHMENTS_LENGTH] = {
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (_, view) = swap_chain.get_next_texture();
|
let (_, view) = swap_chain.get_next_texture();
|
||||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {});
|
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor { todo: 0 });
|
||||||
{
|
{
|
||||||
let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
|
@ -257,7 +257,7 @@ typedef struct {
|
|||||||
} WGPUBufferDescriptor;
|
} WGPUBufferDescriptor;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uint32_t todo;
|
||||||
} WGPUCommandBufferDescriptor;
|
} WGPUCommandBufferDescriptor;
|
||||||
|
|
||||||
typedef WGPUId WGPUDepthStencilStateId;
|
typedef WGPUId WGPUDepthStencilStateId;
|
||||||
@ -509,6 +509,10 @@ WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
|
|||||||
WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id,
|
WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id,
|
||||||
void *layer);
|
void *layer);
|
||||||
|
|
||||||
|
WGPUSurfaceId wgpu_instance_create_surface_from_windows_hwnd(WGPUInstanceId instance_id,
|
||||||
|
void *hinstance,
|
||||||
|
void *hwnd);
|
||||||
|
|
||||||
WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id,
|
WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id,
|
||||||
const WGPUAdapterDescriptor *desc);
|
const WGPUAdapterDescriptor *desc);
|
||||||
|
|
||||||
|
@ -145,7 +145,11 @@ impl CommandBuffer<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct CommandBufferDescriptor {}
|
pub struct CommandBufferDescriptor {
|
||||||
|
// MSVC doesn't allow zero-sized structs
|
||||||
|
// We can remove this when we actually have a field
|
||||||
|
pub todo: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||||
|
@ -63,6 +63,7 @@ pub extern "C" fn wgpu_instance_create_surface_from_winit(
|
|||||||
.register(surface)
|
.register(surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_instance_create_surface_from_macos_layer(
|
pub extern "C" fn wgpu_instance_create_surface_from_macos_layer(
|
||||||
instance_id: InstanceId,
|
instance_id: InstanceId,
|
||||||
@ -87,6 +88,49 @@ pub extern "C" fn wgpu_instance_create_surface_from_macos_layer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wgpu_instance_create_surface_from_windows_hwnd(
|
||||||
|
instance_id: InstanceId,
|
||||||
|
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")))]
|
||||||
|
unimplemented!();
|
||||||
|
|
||||||
|
#[cfg(any(feature = "gfx-backend-dx11", feature = "gfx-backend-dx12"))]
|
||||||
|
{
|
||||||
|
let raw = HUB.instances
|
||||||
|
.read()
|
||||||
|
.get(instance_id)
|
||||||
|
.create_surface_from_hwnd(hwnd);
|
||||||
|
|
||||||
|
let surface = Surface {
|
||||||
|
raw,
|
||||||
|
};
|
||||||
|
|
||||||
|
HUB.surfaces
|
||||||
|
.write()
|
||||||
|
.register(surface)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "gfx-backend-vulkan"))]
|
||||||
|
{
|
||||||
|
let raw = HUB.instances
|
||||||
|
.read()
|
||||||
|
.get(instance_id)
|
||||||
|
.create_surface_from_hwnd(hinstance, hwnd);
|
||||||
|
|
||||||
|
let surface = Surface {
|
||||||
|
raw,
|
||||||
|
};
|
||||||
|
|
||||||
|
HUB.surfaces
|
||||||
|
.write()
|
||||||
|
.register(surface)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_instance_get_adapter(
|
pub extern "C" fn wgpu_instance_get_adapter(
|
||||||
instance_id: InstanceId,
|
instance_id: InstanceId,
|
||||||
|
Loading…
Reference in New Issue
Block a user