2021-11-16 12:44:36 +03:00
|
|
|
[has_globals]
|
2020-01-16 22:45:47 +03:00
|
|
|
module sapp
|
|
|
|
|
2020-12-07 08:16:21 +03:00
|
|
|
import sokol.gfx
|
|
|
|
|
2021-08-12 22:31:04 +03:00
|
|
|
pub const used_import = gfx.used_import
|
2020-12-07 08:16:21 +03:00
|
|
|
|
2020-08-19 08:10:42 +03:00
|
|
|
// Android needs a global reference to `g_desc`
|
2021-11-16 12:44:36 +03:00
|
|
|
__global g_desc C.sapp_desc
|
2020-08-19 08:10:42 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn create_desc() gfx.Desc {
|
|
|
|
metal_desc := gfx.MetalContextDesc{
|
2020-08-23 08:47:50 +03:00
|
|
|
device: metal_get_device()
|
|
|
|
renderpass_descriptor_cb: metal_get_renderpass_descriptor
|
|
|
|
drawable_cb: metal_get_drawable
|
|
|
|
}
|
2022-01-02 21:36:01 +03:00
|
|
|
d3d11_desc := gfx.D3D11ContextDesc{
|
2020-08-23 08:47:50 +03:00
|
|
|
device: d3d11_get_device()
|
|
|
|
device_context: d3d11_get_device_context()
|
|
|
|
render_target_view_cb: d3d11_get_render_target_view
|
|
|
|
depth_stencil_view_cb: d3d11_get_depth_stencil_view
|
|
|
|
}
|
2022-01-27 22:16:00 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
return gfx.Desc{
|
|
|
|
context: gfx.ContextDesc{
|
2021-04-07 21:39:23 +03:00
|
|
|
metal: metal_desc
|
2020-08-23 08:47:50 +03:00
|
|
|
d3d11: d3d11_desc
|
2021-07-25 17:27:07 +03:00
|
|
|
color_format: .bgra8
|
2020-08-23 08:47:50 +03:00
|
|
|
}
|
2021-01-23 12:25:40 +03:00
|
|
|
image_pool_size: 1000
|
2020-08-23 08:47:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// returns true after sokol-app has been initialized
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn isvalid() bool {
|
|
|
|
return C.sapp_isvalid()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// returns the current framebuffer width in pixels
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn width() int {
|
|
|
|
return C.sapp_width()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// returns the current framebuffer height in pixels
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn height() int {
|
|
|
|
return C.sapp_height()
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:16:00 +03:00
|
|
|
// color_format gets default framebuffer color pixel format
|
|
|
|
[inline]
|
|
|
|
pub fn color_format() int {
|
|
|
|
return C.sapp_color_format()
|
|
|
|
}
|
|
|
|
|
|
|
|
// depth_format gets default framebuffer depth pixel format
|
|
|
|
[inline]
|
|
|
|
pub fn depth_format() int {
|
|
|
|
return C.sapp_depth_format()
|
|
|
|
}
|
|
|
|
|
|
|
|
// sample_count gets default framebuffer sample count
|
|
|
|
[inline]
|
|
|
|
pub fn sample_count() int {
|
|
|
|
return C.sapp_sample_count()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// returns true when high_dpi was requested and actually running in a high-dpi scenario
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn high_dpi() bool {
|
|
|
|
return C.sapp_high_dpi()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// returns the dpi scaling factor (window pixels to framebuffer pixels)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn dpi_scale() f32 {
|
|
|
|
return C.sapp_dpi_scale()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// show or hide the mobile device onscreen keyboard
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn show_keyboard(visible bool) {
|
|
|
|
C.sapp_show_keyboard(visible)
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// return true if the mobile device onscreen keyboard is currently shown
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn keyboard_shown() bool {
|
|
|
|
return C.sapp_keyboard_shown()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// show or hide the mouse cursor
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn show_mouse(visible bool) {
|
|
|
|
C.sapp_show_mouse(visible)
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// show or hide the mouse cursor
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn mouse_shown() bool {
|
|
|
|
return C.sapp_mouse_shown()
|
|
|
|
}
|
|
|
|
|
2021-07-06 20:43:41 +03:00
|
|
|
[inline]
|
|
|
|
pub fn lock_mouse(locked bool) {
|
|
|
|
C.sapp_lock_mouse(locked)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn mouse_locked() bool {
|
|
|
|
return C.sapp_mouse_locked()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// return the userdata pointer optionally provided in sapp_desc
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn userdata() voidptr {
|
|
|
|
return C.sapp_userdata()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// return a copy of the sapp_desc structure
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2021-12-26 14:02:51 +03:00
|
|
|
pub fn query_desc() Desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sapp_query_desc()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn request_quit() {
|
|
|
|
C.sapp_request_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn cancel_quit() {
|
|
|
|
C.sapp_cancel_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// intiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn quit() {
|
|
|
|
C.sapp_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// call from inside event callback to consume the current event (don't forward to platform)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn consume_event() {
|
|
|
|
C.sapp_consume_event()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// get the current frame counter (for comparison with sapp_event.frame_count)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn frame_count() u64 {
|
|
|
|
return C.sapp_frame_count()
|
|
|
|
}
|
|
|
|
|
2022-01-05 19:23:14 +03:00
|
|
|
// get an averaged/smoothed frame duration in seconds
|
|
|
|
[inline]
|
|
|
|
pub fn frame_duration() f64 {
|
|
|
|
return C.sapp_frame_duration()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// write string into clipboard
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2022-04-15 16:12:05 +03:00
|
|
|
pub fn set_clipboard_string(str &u8) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sapp_set_clipboard_string(str)
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2021-04-19 15:38:48 +03:00
|
|
|
pub fn get_clipboard_string() &char {
|
|
|
|
return &char(C.sapp_get_clipboard_string())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2021-12-26 14:02:51 +03:00
|
|
|
pub fn run(desc &Desc) {
|
2021-09-09 20:21:01 +03:00
|
|
|
g_desc = *desc
|
2021-04-07 21:39:23 +03:00
|
|
|
C.sapp_run(desc)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// GL: return true when GLES2 fallback is active (to detect fallback from GLES3)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn gles2() bool {
|
|
|
|
return C.sapp_gles2()
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// HTML5: enable or disable the hardwired "Leave Site?" dialog box
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn html5_ask_leave_site(ask bool) {
|
|
|
|
C.sapp_html5_ask_leave_site(ask)
|
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// Metal: get ARC-bridged pointer to Metal device object
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_device() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_metal_get_device())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// Metal: get ARC-bridged pointer to this frame's renderpass descriptor
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_renderpass_descriptor() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_metal_get_renderpass_descriptor())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// Metal: get ARC-bridged pointer to current drawable
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_drawable() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_metal_get_drawable())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// macOS: get ARC-bridged pointer to macOS NSWindow
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn macos_get_window() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_macos_get_window())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// iOS: get ARC-bridged pointer to iOS UIWindow
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn ios_get_window() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_ios_get_window())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// D3D11: get pointer to ID3D11Device object
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_device() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_d3d11_get_device())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// D3D11: get pointer to ID3D11DeviceContext object
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_device_context() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_d3d11_get_device_context())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// D3D11: get pointer to ID3D11RenderTargetView object
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_render_target_view() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_d3d11_get_render_target_view())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// D3D11: get pointer to ID3D11DepthStencilView
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_depth_stencil_view() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_d3d11_get_depth_stencil_view())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// Win32: get the HWND window handle
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn win32_get_hwnd() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_win32_get_hwnd())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
// Android: get native activity handle
|
2020-02-24 20:02:22 +03:00
|
|
|
[inline]
|
|
|
|
pub fn android_get_native_activity() voidptr {
|
2021-04-19 15:38:48 +03:00
|
|
|
return voidptr(C.sapp_android_get_native_activity())
|
2020-02-24 20:02:22 +03:00
|
|
|
}
|
2021-08-30 17:10:14 +03:00
|
|
|
|
|
|
|
// Toggle full screen
|
|
|
|
[inline]
|
|
|
|
pub fn toggle_fullscreen() {
|
|
|
|
C.sapp_toggle_fullscreen()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if full screen rendering
|
|
|
|
[inline]
|
|
|
|
pub fn is_fullscreen() bool {
|
|
|
|
return C.sapp_is_fullscreen()
|
|
|
|
}
|
2021-09-01 09:21:27 +03:00
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn get_num_dropped_files() int {
|
|
|
|
return C.sapp_get_num_dropped_files()
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn get_dropped_file_path(index int) string {
|
|
|
|
unsafe {
|
|
|
|
return cstring_to_vstring(C.sapp_get_dropped_file_path(index))
|
|
|
|
}
|
|
|
|
}
|