Skip to content

Commit 227dbc7

Browse files
committed
sokol: remove duplicate types
1 parent e3a161e commit 227dbc7

25 files changed

Lines changed: 769 additions & 2915 deletions

vlib/sokol/c/declaration.c.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,8 @@ $if !no_sokol_app ? {
117117
#define SOKOL_NO_DEPRECATED
118118
#include "sokol_gfx.h"
119119

120+
@[use_once]
121+
#define SOKOL_IMPL
122+
#include "util/sokol_gl.h"
123+
120124
#include "sokol_v.post.h"

vlib/sokol/f/f.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module f
2+
3+
import fontstash as _
4+
import sokol.c as _
5+
6+
#flag linux -I.
7+
8+
//#include "ft2build.h"
9+
10+
@[use_once]
11+
#define SOKOL_FONTSTASH_IMPL
12+
#include "util/sokol_fontstash.h"
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,17 @@ pub enum MouseButton {
3636
}
3737

3838
pub enum MouseCursor {
39-
default = 0
40-
arrow = 1
41-
ibeam = 2
42-
crosshair = 3
43-
pointing_hand = 4
44-
resize_ew = 5
45-
resize_ns = 6
46-
resize_nwse = 7
47-
resize_nesw = 8
48-
resize_all = 9
49-
not_allowed = 10
50-
custom_0 = 11
51-
custom_1 = 12
52-
custom_2 = 13
53-
custom_3 = 14
54-
custom_4 = 15
55-
custom_5 = 16
56-
custom_6 = 17
57-
custom_7 = 18
58-
custom_8 = 19
59-
custom_9 = 20
60-
custom_10 = 21
61-
custom_11 = 22
62-
custom_12 = 23
63-
custom_13 = 24
64-
custom_14 = 25
65-
custom_15 = 26
39+
default = C.SAPP_MOUSECURSOR_DEFAULT
40+
arrow = C.SAPP_MOUSECURSOR_ARROW
41+
ibeam = C.SAPP_MOUSECURSOR_IBEAM
42+
crosshair = C.SAPP_MOUSECURSOR_CROSSHAIR
43+
pointing_hand = C.SAPP_MOUSECURSOR_POINTING_HAND
44+
resize_ew = C.SAPP_MOUSECURSOR_RESIZE_EW
45+
resize_ns = C.SAPP_MOUSECURSOR_RESIZE_NS
46+
resize_nwse = C.SAPP_MOUSECURSOR_RESIZE_NWSE
47+
resize_nesw = C.SAPP_MOUSECURSOR_RESIZE_NESW
48+
resize_all = C.SAPP_MOUSECURSOR_RESIZE_ALL
49+
not_allowed = C.SAPP_MOUSECURSOR_NOT_ALLOWED
6650
}
6751

6852
pub enum Modifier {
Lines changed: 15 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import sokol.gfx
55
import 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`.
1110
pub 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.srgb8a8 } // 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
4628
pub 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
6748
pub 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]
187141
pub 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]
193146
pub 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]
199151
pub 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)
270216
pub 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]
301235
pub 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]
325241
pub 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]
343253
pub 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]
367259
pub 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]
397282
pub 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]
403287
pub 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-
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module sapp
2+
3+
import sokol.memory
4+
5+
@[typedef]
6+
pub struct C.sapp_allocator {
7+
pub mut:
8+
alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
9+
free_fn memory.FnAllocatorFree = unsafe { nil }
10+
user_data voidptr
11+
}
12+
13+
@[typedef]
14+
pub struct C.sapp_logger {
15+
pub mut:
16+
func memory.FnLogCb = unsafe { nil }
17+
user_data voidptr
18+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module sapp
33
import os
44
import stbi
55

6+
#define SOKOL_VALIDATE_NON_FATAL 1
7+
8+
// v_sapp_gl_read_rgba_pixels reads pixles from the OpenGL buffer into `pixels`.
9+
fn C.v_sapp_gl_read_rgba_pixels(x int, y int, width int, height int, pixels charptr)
10+
611
// screenshot takes a screenshot of the current window and
712
// saves it to `path`. The format is inferred from the extension
813
// of the file name in `path`.
@@ -42,7 +47,6 @@ pub fn screenshot_png(path string) ! {
4247
}
4348

4449
// write_rgba_to_ppm writes `pixels` data in RGBA format to PPM3 format.
45-
@[direct_array_access]
4650
fn write_rgba_to_ppm(path string, w int, h int, components int, pixels &u8) ! {
4751
mut f_out := os.create(path)!
4852
defer {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mut:
99
pixels &u8 = unsafe { nil }
1010
}
1111

12-
// screenshot_window captures a screenshot of the current window.
1312
@[manualfree]
1413
pub fn screenshot_window() &Screenshot {
1514
img_width := width()

0 commit comments

Comments
 (0)