@@ -5,9 +5,8 @@ import sokol.gfx
55import sokol.memory
66
77// Android needs a global reference to `g_desc`
8- __global g_desc Desc
8+ __global g_desc C.sapp_desc
99
10- // create_desc creates a default `gfx.Desc` configured for use with `sapp`.
1110pub fn create_desc () gfx.Desc {
1211 return gfx.Desc{
1312 environment: glue_environment ()
@@ -23,46 +22,28 @@ pub fn create_default_pass(action gfx.PassAction) gfx.Pass {
2322 }
2423}
2524
26- // sapp_to_gfx_pixel_format translates sapp_pixel_format to gfx.PixelFormat.
27- // sokol_app.h uses a compact pixel format enum (sapp_pixel_format) that does NOT
28- // match the sg_pixel_format numbering used by sokol_gfx.h.
29- fn sapp_to_gfx_pixel_format (sapp_fmt int ) gfx.PixelFormat {
30- return match sapp_fmt {
31- 0 { gfx.PixelFormat._default } // _SAPP_PIXELFORMAT_DEFAULT
32- 1 { gfx.PixelFormat.none } // SAPP_PIXELFORMAT_NONE
33- 2 { gfx.PixelFormat.rgba8 } // SAPP_PIXELFORMAT_RGBA8
34- 3 { gfx.PixelFormat.srgb8 a8 } // SAPP_PIXELFORMAT_SRGB8A8
35- 4 { gfx.PixelFormat.bgra8 } // SAPP_PIXELFORMAT_BGRA8
36- 5 { gfx.PixelFormat.bgra8 } // SAPP_PIXELFORMAT_SBGRA8 (no exact sg match, use bgra8)
37- 6 { gfx.PixelFormat.depth } // SAPP_PIXELFORMAT_DEPTH
38- 7 { gfx.PixelFormat.depth_stencil } // SAPP_PIXELFORMAT_DEPTH_STENCIL
39- else { gfx.PixelFormat.none }
40- }
41- }
42-
4325// glue_environment returns a `gfx.Environment` compatible for use with `sapp` specific `gfx.Pass`es.
44- // The returned `gfx.Environment` can be used when rendering via `sapp`.
26+ // The retuned `gfx.Environment` can be used when rendering via `sapp`.
4527// See also: documentation at the top of thirdparty/sokol/sokol_gfx.h
4628pub fn glue_environment () gfx.Environment {
4729 sapp_env := C.sapp_get_environment ()
4830 mut env := gfx.Environment{}
4931 unsafe { vmemset (& env, 0 , int (sizeof (env))) }
50- env.defaults.color_format = sapp_to_gfx_pixel_format (sapp_env.defaults.color_format)
51- env.defaults.depth_format = sapp_to_gfx_pixel_format (sapp_env.defaults.depth_format)
32+ env.defaults.color_format = gfx.PixelFormat.from (sapp_env.defaults.color_format) or {
33+ gfx.PixelFormat.none
34+ }
35+ env.defaults.depth_format = gfx.PixelFormat.from (sapp_env.defaults.depth_format) or {
36+ gfx.PixelFormat.none
37+ }
5238 env.defaults.sample_count = sapp_env.defaults.sample_count
5339 $if macos && ! darwin_sokol_glcore33 ? {
5440 env.metal.device = sapp_env.metal.device
5541 }
56- // if windows and dx3d11
57- // env.d3d11.device = sapp_env.d3d11.device
58- // env.d3d11.device_context = sapp_env.d3d11.device_context
59- // if webgpu
60- // env.wgpu.device = sapp_env.wgpu.device
6142 return env
6243}
6344
6445// glue_swapchain returns a `gfx.Swapchain` compatible for use with `sapp` specific display/rendering `gfx.Pass`es.
65- // The returned `gfx.Swapchain` can be used when rendering via `sapp`.
46+ // The retuned `gfx.Swapchain` can be used when rendering via `sapp`.
6647// See also: documentation at the top of thirdparty/sokol/sokol_gfx.h
6748pub fn glue_swapchain () gfx.Swapchain {
6849 sapp_sc := C.sapp_get_swapchain ()
@@ -71,22 +52,13 @@ pub fn glue_swapchain() gfx.Swapchain {
7152 swapchain.width = sapp_sc.width
7253 swapchain.height = sapp_sc.height
7354 swapchain.sample_count = sapp_sc.sample_count
74- swapchain.color_format = sapp_to_gfx_pixel_format (sapp_sc.color_format)
75- swapchain.depth_format = sapp_to_gfx_pixel_format (sapp_sc.depth_format)
55+ swapchain.color_format = gfx.PixelFormat. from (sapp_sc.color_format) or { gfx.PixelFormat. none }
56+ swapchain.depth_format = gfx.PixelFormat. from (sapp_sc.depth_format) or { gfx.PixelFormat. none }
7657 $if macos && ! darwin_sokol_glcore33 ? {
7758 swapchain.metal.current_drawable = sapp_sc.metal.current_drawable
7859 swapchain.metal.depth_stencil_texture = sapp_sc.metal.depth_stencil_texture
7960 swapchain.metal.msaa_color_texture = sapp_sc.metal.msaa_color_texture
80- }
81- // if windows and dx3d11
82- // swapchain.d3d11.render_view = sapp_sc.d3d11.render_view
83- // swapchain.d3d11.resolve_view = sapp_sc.d3d11.resolve_view
84- // swapchain.d3d11.depth_stencil_view = sapp_sc.d3d11.depth_stencil_view
85- // if webgpu
86- // swapchain.wgpu.render_view = sapp_sc.wgpu.render_view
87- // swapchain.wgpu.resolve_view = sapp_sc.wgpu.resolve_view
88- // swapchain.wgpu.depth_stencil_view = sapp_sc.wgpu.depth_stencil_view
89- $else {
61+ } $else {
9062 swapchain.gl.framebuffer = sapp_sc.gl.framebuffer
9163 }
9264 return swapchain
@@ -164,37 +136,17 @@ pub fn set_mouse_cursor(cursor MouseCursor) {
164136 C.sapp_set_mouse_cursor (cursor)
165137}
166138
167- // get current mouse cursor type
168- @[inline]
169- pub fn get_mouse_cursor () MouseCursor {
170- return C.sapp_get_mouse_cursor ()
171- }
172-
173- // bind a custom mouse cursor image to a cursor type
174- @[inline]
175- pub fn bind_mouse_cursor_image (cursor MouseCursor, desc & ImageDesc) MouseCursor {
176- return C.sapp_bind_mouse_cursor_image (cursor, desc)
177- }
178-
179- // unbind a custom mouse cursor image
180- @[inline]
181- pub fn unbind_mouse_cursor_image (cursor MouseCursor) {
182- C.sapp_unbind_mouse_cursor_image (cursor)
183- }
184-
185139// show or hide the mouse cursor
186140@[inline]
187141pub fn mouse_shown () bool {
188142 return C.sapp_mouse_shown ()
189143}
190144
191- // lock_mouse locks or unlocks the mouse cursor, confining it to the window.
192145@[inline]
193146pub fn lock_mouse (locked bool ) {
194147 C.sapp_lock_mouse (locked)
195148}
196149
197- // mouse_locked returns true if the mouse is currently locked to the window.
198150@[inline]
199151pub fn mouse_locked () bool {
200152 return C.sapp_mouse_locked ()
@@ -260,12 +212,6 @@ pub fn get_clipboard_string() &char {
260212 return & char (C.sapp_get_clipboard_string ())
261213}
262214
263- // set the window icon (only on Windows and Linux)
264- @[inline]
265- pub fn set_icon (icon_desc & IconDesc) {
266- C.sapp_set_icon (icon_desc)
267- }
268-
269215// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
270216pub fn run (desc & Desc) {
271217 if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
@@ -284,42 +230,12 @@ pub fn run(desc &Desc) {
284230 C.sapp_run (desc)
285231}
286232
287- // get runtime environment information
288- @[inline]
289- pub fn get_environment () Environment {
290- return C.sapp_get_environment ()
291- }
292-
293- // get current frame's swapchain information (call once per frame!)
294- @[inline]
295- pub fn get_swapchain () Swapchain {
296- return C.sapp_get_swapchain ()
297- }
298-
299233// HTML5: enable or disable the hardwired "Leave Site?" dialog box
300234@[inline]
301235pub fn html5_ask_leave_site (ask bool ) {
302236 C.sapp_html5_ask_leave_site (ask)
303237}
304238
305- // HTML5: get byte size of a dropped file
306- @[inline]
307- pub fn html5_get_dropped_file_size (index int ) u32 {
308- return C.sapp_html5_get_dropped_file_size (index)
309- }
310-
311- // EGL: get EGLDisplay object
312- @[inline]
313- pub fn egl_get_display () voidptr {
314- return C.sapp_egl_get_display ()
315- }
316-
317- // EGL: get EGLContext object
318- @[inline]
319- pub fn egl_get_context () voidptr {
320- return C.sapp_egl_get_context ()
321- }
322-
323239// macOS: get ARC-bridged pointer to macOS NSWindow
324240@[inline]
325241pub fn macos_get_window () voidptr {
@@ -332,52 +248,22 @@ pub fn ios_get_window() voidptr {
332248 return voidptr (C.sapp_ios_get_window ())
333249}
334250
335- // D3D11: get pointer to IDXGISwapChain object
336- @[inline]
337- pub fn d3d11_get_swap_chain () voidptr {
338- return voidptr (C.sapp_d3d11_get_swap_chain ())
339- }
340-
341251// Win32: get the HWND window handle
342252@[inline]
343253pub fn win32_get_hwnd () voidptr {
344254 return voidptr (C.sapp_win32_get_hwnd ())
345255}
346256
347- // GL: get major version
348- @[inline]
349- pub fn gl_get_major_version () int {
350- return C.sapp_gl_get_major_version ()
351- }
352-
353- // GL: get minor version
354- @[inline]
355- pub fn gl_get_minor_version () int {
356- return C.sapp_gl_get_minor_version ()
357- }
358-
359- // GL: return true if the context is GLES
360- @[inline]
361- pub fn gl_is_gles () bool {
362- return C.sapp_gl_is_gles ()
363- }
364-
365257// GL: get framebuffer object
366258@[inline]
367259pub fn gl_get_framebuffer () u32 {
368260 return C.sapp_gl_get_framebuffer ()
369261}
370262
371- // X11: get Window
372- @[inline]
373- pub fn x11_get_window () voidptr {
374- return voidptr (C.sapp_x11_get_window ())
375- }
376-
377- // X11: get Display
263+ // Android: get native activity handle
378264@[inline]
379- pub fn x11_get_display () voidptr {
380- return voidptr (C.sapp_x11_get_display ())
265+ pub fn android_get_native_activity () voidptr {
266+ return voidptr (C.sapp_android_get_native_activity ())
381267}
382268
383269// Toggle full screen
@@ -392,22 +278,14 @@ pub fn is_fullscreen() bool {
392278 return C.sapp_is_fullscreen ()
393279}
394280
395- // get_num_dropped_files returns the number of files dropped onto the window.
396281@[inline]
397282pub fn get_num_dropped_files () int {
398283 return C.sapp_get_num_dropped_files ()
399284}
400285
401- // get_dropped_file_path returns the path of a dropped file by index.
402286@[inline]
403287pub fn get_dropped_file_path (index int ) string {
404288 unsafe {
405289 return cstring_to_vstring (C.sapp_get_dropped_file_path (index))
406290 }
407291}
408-
409- // Android: get native activity handle
410- @[inline]
411- pub fn android_get_native_activity () voidptr {
412- return voidptr (C.sapp_android_get_native_activity ())
413- }
0 commit comments