44using System ;
55using System . Runtime . InteropServices ;
66using Veldrid ;
7+ using Veldrid . OpenGL ;
78
89[ assembly: Eto . ExportHandler ( typeof ( VeldridSurface ) , typeof ( WpfVeldridSurfaceHandler ) ) ]
910
@@ -20,6 +21,51 @@ public WpfVeldridSurfaceHandler() : base(new WinFormsVeldridUserControl())
2021 Control . Loaded += Control_Loaded ;
2122 }
2223
24+ public void InitializeGraphicsDevice ( VeldridSurface surface , InitializeEventArgs e )
25+ {
26+ switch ( surface . Backend )
27+ {
28+ case GraphicsBackend . Metal :
29+ surface . GraphicsDevice = GraphicsDevice . CreateMetal ( surface . GraphicsDeviceOptions ) ;
30+ break ;
31+ case GraphicsBackend . Direct3D11 :
32+ surface . GraphicsDevice = GraphicsDevice . CreateD3D11 ( surface . GraphicsDeviceOptions ) ;
33+ break ;
34+ case GraphicsBackend . Vulkan :
35+ surface . GraphicsDevice = GraphicsDevice . CreateVulkan ( surface . GraphicsDeviceOptions ) ;
36+ break ;
37+ case GraphicsBackend . OpenGL :
38+ surface . GraphicsDevice = GraphicsDevice . CreateOpenGL (
39+ surface . GraphicsDeviceOptions ,
40+ new OpenGLPlatformInfo (
41+ surface . OpenGL . OpenGLContextHandle ,
42+ surface . OpenGL . GetProcAddress ,
43+ surface . OpenGL . MakeCurrent ,
44+ surface . OpenGL . GetCurrentContext ,
45+ surface . OpenGL . ClearCurrentContext ,
46+ surface . OpenGL . DeleteContext ,
47+ surface . OpenGL . SwapBuffers ,
48+ surface . OpenGL . SetSyncToVerticalBlank ,
49+ surface . OpenGL . SetSwapchainFramebuffer ,
50+ surface . OpenGL . ResizeSwapchain ) ,
51+ ( uint ) e . Width ,
52+ ( uint ) e . Height ) ;
53+ break ;
54+ default :
55+ string message ;
56+ if ( ! Enum . IsDefined ( typeof ( GraphicsBackend ) , surface . Backend ) )
57+ {
58+ message = "Unrecognized backend!" ;
59+ }
60+ else
61+ {
62+ message = "Specified backend not supported on this platform!" ;
63+ }
64+
65+ throw new ArgumentException ( message ) ;
66+ }
67+ }
68+
2369 public Swapchain ? CreateSwapchain ( )
2470 {
2571 Swapchain ? swapchain ;
0 commit comments