Add support for GLFW on Windows

This commit is contained in:
Joshua Groves 2019-01-23 21:59:34 -07:00 committed by Dzmitry Malyshau
parent 26f965cfbb
commit 3d98457eb9
6 changed files with 61 additions and 7 deletions

View File

@ -7,7 +7,7 @@ set(TARGET_NAME hello_triangle)
add_executable(hello_triangle main.c)
if(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX)
target_compile_options(${TARGET_NAME} PRIVATE /W4)
else(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
endif(MSVC)
@ -24,4 +24,4 @@ find_library(WGPU_LIBRARY wgpu_native
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})

View File

@ -191,7 +191,9 @@ int main()
}
#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
@ -206,7 +208,7 @@ int main()
while (!glfwWindowShouldClose(window))
{
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);
WGPURenderPassColorAttachmentDescriptor_TextureViewId color_attachments[ATTACHMENTS_LENGTH] = {
{

View File

@ -93,7 +93,7 @@ fn main() {
}
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 {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {

View File

@ -257,7 +257,7 @@ typedef struct {
} WGPUBufferDescriptor;
typedef struct {
uint32_t todo;
} WGPUCommandBufferDescriptor;
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,
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,
const WGPUAdapterDescriptor *desc);

View File

@ -145,7 +145,11 @@ impl CommandBuffer<B> {
}
#[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]
pub extern "C" fn wgpu_command_buffer_begin_render_pass(

View File

@ -63,6 +63,7 @@ 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_macos_layer(
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]
pub extern "C" fn wgpu_instance_get_adapter(
instance_id: InstanceId,