Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/processing/core/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public static String getPlatform() {
*/
private static void loadNativeLibrary() throws IOException {
String platformTarget = platform + "-" + architecture;
String libraryFileName = "lib" + LIBRARY_NAME + "." + libraryExtension;
String libraryFileName = platform.equals("windows")
? LIBRARY_NAME + "." + libraryExtension
: "lib" + LIBRARY_NAME + "." + libraryExtension;
String resourcePath = "/native/" + platformTarget + "/" + libraryFileName;

// check classloader for resource in jar
Expand Down
3 changes: 3 additions & 0 deletions core/src/processing/webgpu/PSurfaceGLFW.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
import org.lwjgl.glfw.GLFWNativeCocoa;
import org.lwjgl.glfw.GLFWNativeWin32;
import org.lwjgl.glfw.GLFWWindowPosCallback;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.Platform;
Expand Down Expand Up @@ -120,6 +121,8 @@ public Object getNative() {
public long getWindowHandle() {
if (Platform.get() == Platform.MACOSX) {
return GLFWNativeCocoa.glfwGetCocoaWindow(window);
} else if (Platform.get() == Platform.WINDOWS) {
return GLFWNativeWin32.glfwGetWin32Window(window);
} else {
throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform");
}
Expand Down
1 change: 1 addition & 0 deletions libProcessing/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion libProcessing/renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ raw-window-handle = "0.6"

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = { version = "0.6", default-features = false }
objc2-app-kit = { version = "0.3", features = ["NSWindow", "NSView"] }
objc2-app-kit = { version = "0.3", features = ["NSWindow", "NSView"] }

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.58", features = ["Win32_Foundation", "Win32_System_LibraryLoader"] }
37 changes: 35 additions & 2 deletions libProcessing/renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,41 @@ pub fn create_surface(
};

#[cfg(target_os = "windows")]
let (raw_window_handle, raw_display_handle) =
{ todo!("implemnt windows raw window handle conversion") };
let (raw_window_handle, raw_display_handle) = {
use raw_window_handle::{Win32WindowHandle, WindowsDisplayHandle};
use std::num::NonZeroIsize;
use windows::Win32::Foundation::HINSTANCE;
use windows::Win32::System::LibraryLoader::GetModuleHandleW;

if window_handle == 0 {
return Err(error::ProcessingError::InvalidWindowHandle);
}

// HWND is isize, so cast it
let hwnd_isize = window_handle as isize;
let hwnd_nonzero = match NonZeroIsize::new(hwnd_isize) {
Some(nz) => nz,
None => return Err(error::ProcessingError::InvalidWindowHandle),
};

let mut window = Win32WindowHandle::new(hwnd_nonzero);

// VK_KHR_win32_surface requires hinstance *and* hwnd
// SAFETY: GetModuleHandleW(NULL) is safe
let hinstance = unsafe { GetModuleHandleW(None) }
.map_err(|_| error::ProcessingError::InvalidWindowHandle)?;

let hinstance_nonzero = NonZeroIsize::new(hinstance.0 as isize)
.ok_or(error::ProcessingError::InvalidWindowHandle)?;
window.hinstance = Some(hinstance_nonzero);

let display = WindowsDisplayHandle::new();

(
RawWindowHandle::Win32(window),
RawDisplayHandle::Windows(display),
)
};

#[cfg(target_os = "linux")]
let (raw_window_handle, raw_display_handle) =
Expand Down