Closed okuma10 closed 4 years ago
Hello @okuma10,
currently no specific Vulkan wrapper is supported by pyGLFW, so you will need to cast the wrapper-specific arguments to ctypes.c_void_p
, e.g. using ctypes.cast(instance_pointer, ctypes.c_void_p)
. Depening on the technology used by the Vulkan wrapper you are using, you may need to perform an additional step to retrieve the instance pointer first.
Please let me know if this solved your issue, otherwise please tell me which Vulkan wrapper you are using so I can look into it.
hi I'm using this wrapper https://github.com/realitix/vulkan
the ctypes.cast suggestion didn't work
Thanks, the wrapper is using cffi, so you need to convert the cffi pointer to a ctypes pointer. I'll look into it.
Instead of using ctypes.cast(instance_pointer, ctypes.c_void_p)
you will need to use ctypes.c_void_p(int(ffi.cast('uintptr_t', instance_pointer)))
to convert the cffi pointer to a ctypes pointer. You should be able to import ffi
from the vulkan package, otherwise you can create a new one using:
from cffi import FFI
ffi = FFI()
I tried your first suggestion but I get an error
File "C:\Users\Okuma_10\AppData\Roaming\Python\Python37\site-packages\glfw\__init__.py", line 2561, in create_window_surface
return _glfw.glfwCreateWindowSurface(instance, window, allocator, surface)
OSError: exception: access violation writing 0x0000000000000000
glfw_VKinstance = ctypes.c_void_p(int(ffi.cast('uintptr_t',self.VKinstance)))
glfw.create_window_surface(glfw_VKinstance, self.window, None, self.surface)
self.window is the window handle I get from glfw. and self.surface is just set to None
at the moment of the function call.
On the tutorial ...since it's in C++ the variable type is pre-defined as VkSurfaceKHR . But up to this point in the tutorial the vulkan wrapper always returns the the correct type.
I just checked their repo and they have an example for using pyGLFW: https://github.com/realitix/vulkan/blob/master/example/contribs/example_glfw.py The example has the following code:
surface = ctypes.c_void_p(0)
instance = ctypes.cast(int(ffi.cast('uintptr_t', self.__instance)), ctypes.c_void_p)
glfw.create_window_surface(instance, self.__window, None, ctypes.byref(surface))
Please try and use the code from the example. I'll try to get it set up on my system and maybe I can add some support for this wrapper to pyGLFW.
I have just released pyGLFW1.12.0 which contains some utilities for working with CFFI based Vulkan wrappers. You can now do the following:
surface_ptr = ffi.new('VkSurfaceKHR[1]')
glfw.create_window_surface(instance, window, None, surface_ptr)
surface = surface_ptr[0]
and pyGLFW will automatically convert the CFFI pointers to ctypes pointers.
yes it works now! Thank you for addressing this so quickly!
using
glfw.create_window_surface
I get an error:ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
argument 1 is the vulkan instance and mine was created as it should :
<cdata 'struct VkInstance_T *' 0x0000022EF5F83520>