2020-01-16 20:45:47 +01:00
|
|
|
module sapp
|
|
|
|
|
2020-12-07 06:16:21 +01:00
|
|
|
import sokol.gfx
|
|
|
|
|
2021-08-12 21:31:04 +02:00
|
|
|
pub const used_import = gfx.used_import
|
2020-12-07 06:16:21 +01:00
|
|
|
|
2020-08-19 07:10:42 +02:00
|
|
|
// Android needs a global reference to `g_desc`
|
2021-05-08 12:32:29 +02:00
|
|
|
__global (
|
|
|
|
g_desc C.sapp_desc
|
|
|
|
)
|
2020-08-19 07:10:42 +02:00
|
|
|
|
2020-08-23 07:47:50 +02:00
|
|
|
pub fn create_desc() C.sg_desc {
|
2021-04-07 20:39:23 +02:00
|
|
|
metal_desc := C.sg_metal_context_desc{
|
2020-08-23 07:47:50 +02:00
|
|
|
device: metal_get_device()
|
|
|
|
renderpass_descriptor_cb: metal_get_renderpass_descriptor
|
|
|
|
drawable_cb: metal_get_drawable
|
|
|
|
}
|
2021-01-23 10:25:40 +01:00
|
|
|
d3d11_desc := C.sg_d3d11_context_desc{
|
2020-08-23 07:47:50 +02: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
|
|
|
|
}
|
|
|
|
return C.sg_desc{
|
|
|
|
context: C.sg_context_desc{
|
2021-04-07 20:39:23 +02:00
|
|
|
metal: metal_desc
|
2020-08-23 07:47:50 +02:00
|
|
|
d3d11: d3d11_desc
|
2021-07-25 16:27:07 +02:00
|
|
|
color_format: .bgra8
|
2020-08-23 07:47:50 +02:00
|
|
|
}
|
2021-01-23 10:25:40 +01:00
|
|
|
image_pool_size: 1000
|
2020-08-23 07:47:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// returns true after sokol-app has been initialized
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn isvalid() bool {
|
|
|
|
return C.sapp_isvalid()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// returns the current framebuffer width in pixels
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn width() int {
|
|
|
|
return C.sapp_width()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// returns the current framebuffer height in pixels
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn height() int {
|
|
|
|
return C.sapp_height()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// returns true when high_dpi was requested and actually running in a high-dpi scenario
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn high_dpi() bool {
|
|
|
|
return C.sapp_high_dpi()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// returns the dpi scaling factor (window pixels to framebuffer pixels)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn dpi_scale() f32 {
|
|
|
|
return C.sapp_dpi_scale()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// show or hide the mobile device onscreen keyboard
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn show_keyboard(visible bool) {
|
|
|
|
C.sapp_show_keyboard(visible)
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// return true if the mobile device onscreen keyboard is currently shown
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn keyboard_shown() bool {
|
|
|
|
return C.sapp_keyboard_shown()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// show or hide the mouse cursor
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn show_mouse(visible bool) {
|
|
|
|
C.sapp_show_mouse(visible)
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// show or hide the mouse cursor
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn mouse_shown() bool {
|
|
|
|
return C.sapp_mouse_shown()
|
|
|
|
}
|
|
|
|
|
2021-07-06 19:43:41 +02: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 10:25:40 +01:00
|
|
|
// return the userdata pointer optionally provided in sapp_desc
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn userdata() voidptr {
|
|
|
|
return C.sapp_userdata()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// return a copy of the sapp_desc structure
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn query_desc() C.sapp_desc {
|
|
|
|
return C.sapp_query_desc()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn request_quit() {
|
|
|
|
C.sapp_request_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn cancel_quit() {
|
|
|
|
C.sapp_cancel_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// intiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn quit() {
|
|
|
|
C.sapp_quit()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// call from inside event callback to consume the current event (don't forward to platform)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn consume_event() {
|
|
|
|
C.sapp_consume_event()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// get the current frame counter (for comparison with sapp_event.frame_count)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn frame_count() u64 {
|
|
|
|
return C.sapp_frame_count()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// write string into clipboard
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
2021-04-19 14:38:48 +02:00
|
|
|
pub fn set_clipboard_string(str &char) {
|
2020-01-16 20:45:47 +01:00
|
|
|
C.sapp_set_clipboard_string(str)
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
2021-04-19 14:38:48 +02:00
|
|
|
pub fn get_clipboard_string() &char {
|
|
|
|
return &char(C.sapp_get_clipboard_string())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
2021-04-07 20:39:23 +02:00
|
|
|
pub fn run(desc &C.sapp_desc) {
|
2020-08-19 07:10:42 +02:00
|
|
|
g_desc = desc
|
2021-04-07 20:39:23 +02:00
|
|
|
C.sapp_run(desc)
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// GL: return true when GLES2 fallback is active (to detect fallback from GLES3)
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn gles2() bool {
|
|
|
|
return C.sapp_gles2()
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// HTML5: enable or disable the hardwired "Leave Site?" dialog box
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn html5_ask_leave_site(ask bool) {
|
|
|
|
C.sapp_html5_ask_leave_site(ask)
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// Metal: get ARC-bridged pointer to Metal device object
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_device() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_metal_get_device())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// Metal: get ARC-bridged pointer to this frame's renderpass descriptor
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_renderpass_descriptor() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_metal_get_renderpass_descriptor())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// Metal: get ARC-bridged pointer to current drawable
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn metal_get_drawable() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_metal_get_drawable())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// macOS: get ARC-bridged pointer to macOS NSWindow
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn macos_get_window() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_macos_get_window())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// iOS: get ARC-bridged pointer to iOS UIWindow
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn ios_get_window() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_ios_get_window())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// D3D11: get pointer to ID3D11Device object
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_device() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_d3d11_get_device())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// D3D11: get pointer to ID3D11DeviceContext object
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_device_context() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_d3d11_get_device_context())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// D3D11: get pointer to ID3D11RenderTargetView object
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_render_target_view() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_d3d11_get_render_target_view())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// D3D11: get pointer to ID3D11DepthStencilView
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn d3d11_get_depth_stencil_view() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_d3d11_get_depth_stencil_view())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// Win32: get the HWND window handle
|
2020-01-16 20:45:47 +01:00
|
|
|
[inline]
|
|
|
|
pub fn win32_get_hwnd() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_win32_get_hwnd())
|
2020-01-16 20:45:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:25:40 +01:00
|
|
|
// Android: get native activity handle
|
2020-02-24 18:02:22 +01:00
|
|
|
[inline]
|
|
|
|
pub fn android_get_native_activity() voidptr {
|
2021-04-19 14:38:48 +02:00
|
|
|
return voidptr(C.sapp_android_get_native_activity())
|
2020-02-24 18:02:22 +01:00
|
|
|
}
|
2021-08-30 16:10:14 +02: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 08:21:27 +02: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))
|
|
|
|
}
|
|
|
|
}
|