private unsafe void CreateSurface()
        {
            // Check for Window Handle parameter
            if (Description.DeviceWindowHandle == null)
            {
                throw new ArgumentException("DeviceWindowHandle cannot be null");
            }
            // Create surface
#if SILICONSTUDIO_PLATFORM_WINDOWS
            var controlHandle = Description.DeviceWindowHandle.Handle;
            if (controlHandle == IntPtr.Zero)
            {
                throw new NotSupportedException($"Form of type [{Description.DeviceWindowHandle.GetType().Name}] is not supported. Only System.Windows.Control are supported");
            }

            var surfaceCreateInfo = new Win32SurfaceCreateInfo
            {
                StructureType = StructureType.Win32SurfaceCreateInfo,
#if !SILICONSTUDIO_RUNTIME_CORECLR
                InstanceHandle = Process.GetCurrentProcess().Handle,
#else
                // To implement for CoreCLR, currently passing a NULL pointer seems to work
                InstanceHandle = IntPtr.Zero,
#endif
                WindowHandle = controlHandle,
            };
            surface = GraphicsDevice.NativeInstance.CreateWin32Surface(surfaceCreateInfo);
#elif SILICONSTUDIO_PLATFORM_ANDROID
            throw new NotImplementedException();
#elif SILICONSTUDIO_PLATFORM_LINUX
#if SILICONSTUDIO_XENKO_UI_SDL
            var control = Description.DeviceWindowHandle.NativeWindow as SDL.Window;
            if (control == null)
            {
                throw new NotSupportedException("Non SDL Window used in SDL setup.");
            }

            if (GraphicsAdapterFactory.GetInstance(GraphicsDevice.IsDebugMode).HasXlibSurfaceSupport)
            {
                var createInfo = new XlibSurfaceCreateInfo
                {
                    StructureType = StructureType.XlibSurfaceCreateInfo,
                    Window = checked((uint)control.Handle), // On Linux, a Window identifier is 32-bit
                    Dpy = control.Display,
                };
                surface =GraphicsDevice.NativeInstance.CreateXlibSurface(ref createInfo);
            }
            else
            {
                var createInfo = new XcbSurfaceCreateInfo()
                {
                    StructureType = StructureType.XcbSurfaceCreateInfo,
                    Window = checked((uint)control.Handle), // On Linux, a Window identifier is 32-bit
                    Connection = control.XcbConnection,
                };
                surface = GraphicsDevice.NativeInstance.CreateXcbSurface(ref createInfo);
            }
#else
            throw new NotSupportedException("Only SDL is supported for the time being on Linux");
#endif
#else
            throw new NotSupportedException();
#endif
        }
Example #2
0
 internal static unsafe extern Result vkCreateXcbSurfaceKHR(Instance instance, XcbSurfaceCreateInfo* createInfo, AllocationCallbacks* allocator, Surface* surface);
        private unsafe void CreateSurface()
        {
            // Check for Window Handle parameter
            if (Description.DeviceWindowHandle == null)
            {
                throw new ArgumentException("DeviceWindowHandle cannot be null");
            }
            // Create surface
#if XENKO_PLATFORM_WINDOWS
            var controlHandle = Description.DeviceWindowHandle.Handle;
            if (controlHandle == IntPtr.Zero)
            {
                throw new NotSupportedException($"Form of type [{Description.DeviceWindowHandle.GetType().Name}] is not supported. Only System.Windows.Control are supported");
            }

            var surfaceCreateInfo = new Win32SurfaceCreateInfo
            {
                StructureType = StructureType.Win32SurfaceCreateInfo,
#if !XENKO_RUNTIME_CORECLR
                InstanceHandle = Process.GetCurrentProcess().Handle,
#else
                // To implement for CoreCLR, currently passing a NULL pointer seems to work
                InstanceHandle = IntPtr.Zero,
#endif
                WindowHandle = controlHandle,
            };
            surface = GraphicsDevice.NativeInstance.CreateWin32Surface(surfaceCreateInfo);
#elif XENKO_PLATFORM_ANDROID
            throw new NotImplementedException();
#elif XENKO_PLATFORM_LINUX
#if XENKO_UI_SDL
            var control = Description.DeviceWindowHandle.NativeWindow as SDL.Window;
            if (control == null)
            {
                throw new NotSupportedException("Non SDL Window used in SDL setup.");
            }

            if (GraphicsAdapterFactory.GetInstance(GraphicsDevice.IsDebugMode).HasXlibSurfaceSupport)
            {
                var createInfo = new XlibSurfaceCreateInfo
                {
                    StructureType = StructureType.XlibSurfaceCreateInfo,
                    Window        = checked ((uint)control.Handle), // On Linux, a Window identifier is 32-bit
                    Dpy           = control.Display,
                };
                surface = GraphicsDevice.NativeInstance.CreateXlibSurface(ref createInfo);
            }
            else
            {
                var createInfo = new XcbSurfaceCreateInfo()
                {
                    StructureType = StructureType.XcbSurfaceCreateInfo,
                    Window        = checked ((uint)control.Handle), // On Linux, a Window identifier is 32-bit
                    Connection    = control.XcbConnection,
                };
                surface = GraphicsDevice.NativeInstance.CreateXcbSurface(ref createInfo);
            }
#else
            throw new NotSupportedException("Only SDL is supported for the time being on Linux");
#endif
#else
            throw new NotSupportedException();
#endif
        }
Example #4
0
 public unsafe Surface CreateXcbSurface(ref XcbSurfaceCreateInfo createInfo, AllocationCallbacks* allocator = null)
 {
     Surface surface;
     fixed (XcbSurfaceCreateInfo* __createInfo__ = &createInfo)
     {
         vkCreateXcbSurfaceKHR(this, __createInfo__, allocator, &surface).CheckError();
     }
     return surface;
 }