1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg: native rendering mode on macOS

This commit is contained in:
Alexander Medvednikov
2021-01-23 10:25:40 +01:00
parent a3908414e4
commit d991712b3c
32 changed files with 492 additions and 152 deletions

View File

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

View File

@@ -2,93 +2,93 @@ module sapp
pub struct C.sapp_desc {
pub:
init_cb fn() // these are the user-provided callbacks without user data
frame_cb fn()
cleanup_cb fn()
event_cb fn(&C.sapp_event) //&sapp_event)
fail_cb fn(byteptr)
user_data voidptr // these are the user-provided callbacks with user data
init_userdata_cb fn(voidptr)
frame_userdata_cb fn(voidptr)
cleanup_userdata_cb fn(voidptr)
event_userdata_cb fn(&C.sapp_event, voidptr)
fail_userdata_cb fn(byteptr,voidptr)
width int /* the preferred width of the window / canvas */
height int /* the preferred height of the window / canvas */
sample_count int /* MSAA sample count */
swap_interval int /* the preferred swap interval (ignored on some platforms) */
high_dpi bool /* whether the rendering canvas is full-resolution on HighDPI displays */
fullscreen bool /* whether the window should be created in fullscreen mode */
alpha bool /* whether the framebuffer should have an alpha channel (ignored on some platforms) */
window_title byteptr /* the window title as UTF-8 encoded string */
user_cursor bool /* if true, user is expected to manage cursor image in SAPP_EVENTTYPE_UPDATE_CURSOR */
enable_clipboard bool /* enable clipboard access, default is false */
clipboard_size int /* max size of clipboard content in bytes */
html5_canvas_name byteptr /* the name (id) of the HTML5 canvas element, default is "canvas" */
html5_canvas_resize bool /* if true, the HTML5 canvas size is set to sapp_desc.width/height, otherwise canvas size is tracked */
html5_preserve_drawing_buffer bool /* HTML5 only: whether to preserve default framebuffer content between frames */
html5_premultiplied_alpha bool /* HTML5 only: whether the rendered pixels use premultiplied alpha convention */
html5_ask_leave_site bool /* initial state of the internal html5_ask_leave_site flag (see sapp_html5_ask_leave_site()) */
ios_keyboard_resizes_canvas bool /* if true, showing the iOS keyboard shrinks the canvas */
gl_force_gles2 bool /* if true, setup GLES2/WebGL even if GLES3/WebGL2 is available */
init_cb fn () // these are the user-provided callbacks without user data
frame_cb fn ()
cleanup_cb fn ()
event_cb fn (&C.sapp_event) //&sapp_event)
fail_cb fn (byteptr)
user_data voidptr // these are the user-provided callbacks with user data
init_userdata_cb fn (voidptr)
frame_userdata_cb fn (voidptr)
cleanup_userdata_cb fn (voidptr)
event_userdata_cb fn (&C.sapp_event, voidptr)
fail_userdata_cb fn (byteptr, voidptr)
width int // the preferred width of the window / canvas
height int // the preferred height of the window / canvas
sample_count int // MSAA sample count
swap_interval int // the preferred swap interval (ignored on some platforms)
high_dpi bool // whether the rendering canvas is full-resolution on HighDPI displays
fullscreen bool // whether the window should be created in fullscreen mode
alpha bool // whether the framebuffer should have an alpha channel (ignored on some platforms)
window_title byteptr // the window title as UTF-8 encoded string
user_cursor bool // if true, user is expected to manage cursor image in SAPP_EVENTTYPE_UPDATE_CURSOR
enable_clipboard bool // enable clipboard access, default is false
clipboard_size int // max size of clipboard content in bytes
html5_canvas_name byteptr // the name (id) of the HTML5 canvas element, default is "canvas"
html5_canvas_resize bool // if true, the HTML5 canvas size is set to sapp_desc.width/height, otherwise canvas size is tracked
html5_preserve_drawing_buffer bool // HTML5 only: whether to preserve default framebuffer content between frames
html5_premultiplied_alpha bool // HTML5 only: whether the rendered pixels use premultiplied alpha convention
html5_ask_leave_site bool // initial state of the internal html5_ask_leave_site flag (see sapp_html5_ask_leave_site())
ios_keyboard_resizes_canvas bool // if true, showing the iOS keyboard shrinks the canvas
gl_force_gles2 bool // if true, setup GLES2/WebGL even if GLES3/WebGL2 is available
native_render bool
}
pub struct Event {
pub:
frame_count u64
typ EventType
key_code KeyCode
char_code u32
key_repeat bool
modifiers u32
mouse_button MouseButton
mouse_x f32
mouse_y f32
mouse_dx f32
mouse_dy f32
scroll_x f32
scroll_y f32
num_touches int
touches [8]C.sapp_touchpoint
window_width int
window_height int
framebuffer_width int
framebuffer_height int
frame_count u64
typ EventType
key_code KeyCode
char_code u32
key_repeat bool
modifiers u32
mouse_button MouseButton
mouse_x f32
mouse_y f32
mouse_dx f32
mouse_dy f32
scroll_x f32
scroll_y f32
num_touches int
touches [8]C.sapp_touchpoint
window_width int
window_height int
framebuffer_width int
framebuffer_height int
}
pub struct C.sapp_event {
pub:
frame_count u64
@type EventType
key_code KeyCode
char_code u32
key_repeat bool
modifiers u32
mouse_button MouseButton
mouse_x f32
mouse_y f32
mouse_dx f32
mouse_dy f32
scroll_x f32
scroll_y f32
num_touches int
touches [8]C.sapp_touchpoint
window_width int
window_height int
framebuffer_width int
framebuffer_height int
frame_count u64
@type EventType
key_code KeyCode
char_code u32
key_repeat bool
modifiers u32
mouse_button MouseButton
mouse_x f32
mouse_y f32
mouse_dx f32
mouse_dy f32
scroll_x f32
scroll_y f32
num_touches int
touches [8]C.sapp_touchpoint
window_width int
window_height int
framebuffer_width int
framebuffer_height int
}
pub fn (e &C.sapp_event) str() string {
return 'evt: frame_count=$e.frame_count, type=${e.@type}'
t := e.@type
return 'evt: frame_count=$e.frame_count, type=$t'
}
pub struct C.sapp_touchpoint {
pub:
identifier u64
pos_x f32
pos_y f32
changed bool
identifier u64
pos_x f32
pos_y f32
changed bool
}