debugtext.odin 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // machine generated, do not edit
  2. package sokol_debugtext
  3. /*
  4. sokol_debugtext.h - simple ASCII debug text rendering on top of sokol_gfx.h
  5. Project URL: https://github.com/floooh/sokol
  6. Do this:
  7. #define SOKOL_IMPL or
  8. #define SOKOL_DEBUGTEXT_IMPL
  9. before you include this file in *one* C or C++ file to create the
  10. implementation.
  11. The following defines are used by the implementation to select the
  12. platform-specific embedded shader code (these are the same defines as
  13. used by sokol_gfx.h and sokol_app.h):
  14. SOKOL_GLCORE
  15. SOKOL_GLES3
  16. SOKOL_D3D11
  17. SOKOL_METAL
  18. SOKOL_WGPU
  19. SOKOL_VULKAN
  20. ...optionally provide the following macros to override defaults:
  21. SOKOL_VSNPRINTF - the function name of an alternative vsnprintf() function (default: vsnprintf)
  22. SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
  23. SOKOL_DEBUGTEXT_API_DECL - public function declaration prefix (default: extern)
  24. SOKOL_API_DECL - same as SOKOL_DEBUGTEXT_API_DECL
  25. SOKOL_API_IMPL - public function implementation prefix (default: -)
  26. SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
  27. If sokol_debugtext.h is compiled as a DLL, define the following before
  28. including the declaration or implementation:
  29. SOKOL_DLL
  30. On Windows, SOKOL_DLL will define SOKOL_DEBUGTEXT_API_DECL as __declspec(dllexport)
  31. or __declspec(dllimport) as needed.
  32. Include the following headers before including sokol_debugtext.h:
  33. sokol_gfx.h
  34. FEATURES AND CONCEPTS
  35. =====================
  36. - renders 8-bit ASCII text as fixed-size 8x8 pixel characters
  37. - comes with 6 embedded 8-bit home computer fonts (each taking up 2 KBytes)
  38. - easily plug in your own fonts
  39. - create multiple contexts for rendering text in different layers or render passes
  40. STEP BY STEP
  41. ============
  42. --- to initialize sokol-debugtext, call sdtx_setup() *after* initializing
  43. sokol-gfx:
  44. sdtx_setup(&(sdtx_desc_t){ ... });
  45. To see any warnings and errors, you should always install a logging callback.
  46. The easiest way is via sokol_log.h:
  47. #include "sokol_log.h"
  48. sdtx_setup(&(sdtx_desc_t){
  49. .logger.func = slog_func,
  50. });
  51. --- configure sokol-debugtext by populating the sdtx_desc_t struct:
  52. .context_pool_size (default: 8)
  53. The max number of text contexts that can be created.
  54. .printf_buf_size (default: 4096)
  55. The size of the internal text formatting buffer used by
  56. sdtx_printf() and sdtx_vprintf().
  57. .fonts (default: none)
  58. An array of sdtx_font_desc_t structs used to configure the
  59. fonts that can be used for rendering. To use all builtin
  60. fonts call sdtx_setup() like this (in C99):
  61. sdtx_setup(&(sdtx_desc_t){
  62. .fonts = {
  63. [0] = sdtx_font_kc853(),
  64. [1] = sdtx_font_kc854(),
  65. [2] = sdtx_font_z1013(),
  66. [3] = sdtx_font_cpc(),
  67. [4] = sdtx_font_c64(),
  68. [5] = sdtx_font_oric()
  69. }
  70. });
  71. For documentation on how to use you own font data, search
  72. below for "USING YOUR OWN FONT DATA".
  73. .context
  74. The setup parameters for the default text context. This will
  75. be active right after sdtx_setup(), or when calling
  76. sdtx_set_context(SDTX_DEFAULT_CONTEXT):
  77. .max_commands (default: 4096)
  78. The max number of render commands that can be recorded
  79. into the internal command buffer. This directly translates
  80. to the number of render layer changes in a single frame.
  81. .char_buf_size (default: 4096)
  82. The number of characters that can be rendered per frame in this
  83. context, defines the size of an internal fixed-size vertex
  84. buffer. Any additional characters will be silently ignored.
  85. .canvas_width (default: 640)
  86. .canvas_height (default: 480)
  87. The 'virtual canvas size' in pixels. This defines how big
  88. characters will be rendered relative to the default framebuffer
  89. dimensions. Each character occupies a grid of 8x8 'virtual canvas
  90. pixels' (so a virtual canvas size of 640x480 means that 80x60 characters
  91. fit on the screen). For rendering in a resizeable window, you
  92. should dynamically update the canvas size in each frame by
  93. calling sdtx_canvas(w, h).
  94. .tab_width (default: 4)
  95. The width of a tab character in number of character cells.
  96. .color_format (default: 0)
  97. .depth_format (default: 0)
  98. .sample_count (default: 0)
  99. The pixel format description for the default context needed
  100. for creating the context's sg_pipeline object. When
  101. rendering to the default framebuffer you can leave those
  102. zero-initialized, in this case the proper values will be
  103. filled in by sokol-gfx. You only need to provide non-default
  104. values here when rendering to render targets with different
  105. pixel format attributes than the default framebuffer.
  106. --- Before starting to render text, optionally call sdtx_canvas() to
  107. dynamically resize the virtual canvas. This is recommended when
  108. rendering to a resizeable window. The virtual canvas size can
  109. also be used to scale text in relation to the display resolution.
  110. Examples when using sokol-app:
  111. - to render characters at 8x8 'physical pixels':
  112. sdtx_canvas(sapp_width(), sapp_height());
  113. - to render characters at 16x16 physical pixels:
  114. sdtx_canvas(sapp_width()/2.0f, sapp_height()/2.0f);
  115. Do *not* use integer math here, since this will not look nice
  116. when the render target size isn't divisible by 2.
  117. --- Optionally define the origin for the character grid with:
  118. sdtx_origin(x, y);
  119. The provided coordinates are in character grid cells, not in
  120. virtual canvas pixels. E.g. to set the origin to 2 character tiles
  121. from the left and top border:
  122. sdtx_origin(2, 2);
  123. You can define fractions, e.g. to start rendering half
  124. a character tile from the top-left corner:
  125. sdtx_origin(0.5f, 0.5f);
  126. --- Optionally set a different font by calling:
  127. sdtx_font(font_index)
  128. sokol-debugtext provides 8 font slots which can be populated
  129. with the builtin fonts or with user-provided font data, so
  130. 'font_index' must be a number from 0 to 7.
  131. --- Position the text cursor with one of the following calls. All arguments
  132. are in character grid cells as floats and relative to the
  133. origin defined with sdtx_origin():
  134. sdtx_pos(x, y) - sets absolute cursor position
  135. sdtx_pos_x(x) - only set absolute x cursor position
  136. sdtx_pos_y(y) - only set absolute y cursor position
  137. sdtx_move(x, y) - move cursor relative in x and y direction
  138. sdtx_move_x(x) - move cursor relative only in x direction
  139. sdtx_move_y(y) - move cursor relative only in y direction
  140. sdtx_crlf() - set cursor to beginning of next line
  141. (same as sdtx_pos_x(0) + sdtx_move_y(1))
  142. sdtx_home() - resets the cursor to the origin
  143. (same as sdtx_pos(0, 0))
  144. --- Set a new text color with any of the following functions:
  145. sdtx_color3b(r, g, b) - RGB 0..255, A=255
  146. sdtx_color3f(r, g, b) - RGB 0.0f..1.0f, A=1.0f
  147. sdtx_color4b(r, g, b, a) - RGBA 0..255
  148. sdtx_color4f(r, g, b, a) - RGBA 0.0f..1.0f
  149. sdtx_color1i(uint32_t rgba) - ABGR (0xAABBGGRR)
  150. --- Output 8-bit ASCII text with the following functions:
  151. sdtx_putc(c) - output a single character
  152. sdtx_puts(str) - output a null-terminated C string, note that
  153. this will *not* append a newline (so it behaves
  154. differently than the CRT's puts() function)
  155. sdtx_putr(str, len) - 'put range' output the first 'len' characters of
  156. a C string or until the zero character is encountered
  157. sdtx_printf(fmt, ...) - output with printf-formatting, note that you
  158. can inject your own printf-compatible function
  159. by overriding the SOKOL_VSNPRINTF define before
  160. including the implementation
  161. sdtx_vprintf(fmt, args) - same as sdtx_printf() but with the arguments
  162. provided in a va_list
  163. - Note that the text will not yet be rendered, only recorded for rendering
  164. at a later time, the actual rendering happens when sdtx_draw() is called
  165. inside a sokol-gfx render pass.
  166. - This means also you can output text anywhere in the frame, it doesn't
  167. have to be inside a render pass.
  168. - Note that character codes <32 are reserved as control characters
  169. and won't render anything. Currently only the following control
  170. characters are implemented:
  171. \r - carriage return (same as sdtx_pos_x(0))
  172. \n - carriage return + line feed (same as stdx_crlf())
  173. \t - a tab character
  174. --- You can 'record' text into render layers, this allows to mix/interleave
  175. sokol-debugtext rendering with other rendering operations inside
  176. sokol-gfx render passes. To start recording text into a different render
  177. layer, call:
  178. sdtx_layer(int layer_id)
  179. ...outside a sokol-gfx render pass.
  180. --- finally, from within a sokol-gfx render pass, call:
  181. sdtx_draw()
  182. ...for non-layered rendering, or to draw a specific layer:
  183. sdtx_draw_layer(int layer_id)
  184. NOTE that sdtx_draw() is equivalent to:
  185. sdtx_draw_layer(0)
  186. ...so sdtx_draw() will *NOT* render all text layers, instead it will
  187. only render the 'default layer' 0.
  188. --- at the end of a frame (defined by the call to sg_commit()), sokol-debugtext
  189. will rewind all contexts:
  190. - the internal vertex index is set to 0
  191. - the internal command index is set to 0
  192. - the current layer id is set to 0
  193. - the current font is set to 0
  194. - the cursor position is reset
  195. RENDERING WITH MULTIPLE CONTEXTS
  196. ================================
  197. Use multiple text contexts if you need to render debug text in different
  198. sokol-gfx render passes, or want to render text to different layers
  199. in the same render pass, each with its own set of parameters.
  200. To create a new text context call:
  201. sdtx_context ctx = sdtx_make_context(&(sdtx_context_desc_t){ ... });
  202. The creation parameters in the sdtx_context_desc_t struct are the same
  203. as already described above in the sdtx_setup() function:
  204. .char_buf_size -- max number of characters rendered in one frame, default: 4096
  205. .canvas_width -- the initial virtual canvas width, default: 640
  206. .canvas_height -- the initial virtual canvas height, default: 400
  207. .tab_width -- tab width in number of characters, default: 4
  208. .color_format -- color pixel format of target render pass
  209. .depth_format -- depth pixel format of target render pass
  210. .sample_count -- MSAA sample count of target render pass
  211. To make a new context the active context, call:
  212. sdtx_set_context(ctx)
  213. ...and after that call the text output functions as described above, and
  214. finally, inside a sokol-gfx render pass, call sdtx_draw() to actually
  215. render the text for this context.
  216. A context keeps track of the following parameters:
  217. - the active font
  218. - the virtual canvas size
  219. - the origin position
  220. - the current cursor position
  221. - the current tab width
  222. - the current color
  223. - and the current layer-id
  224. You can get the currently active context with:
  225. sdtx_get_context()
  226. To make the default context current, call sdtx_set_context() with the
  227. special SDTX_DEFAULT_CONTEXT handle:
  228. sdtx_set_context(SDTX_DEFAULT_CONTEXT)
  229. Alternatively, use the function sdtx_default_context() to get the default
  230. context handle:
  231. sdtx_set_context(sdtx_default_context());
  232. To destroy a context, call:
  233. sdtx_destroy_context(ctx)
  234. If a context is set as active that no longer exists, all sokol-debugtext
  235. functions that require an active context will silently fail.
  236. You can directly draw the recorded text in a specific context without
  237. setting the active context:
  238. sdtx_context_draw(ctx)
  239. sdtx_context_draw_layer(ctx, layer_id)
  240. USING YOUR OWN FONT DATA
  241. ========================
  242. Instead of the built-in fonts you can also plug your own font data
  243. into sokol-debugtext by providing one or several sdtx_font_desc_t
  244. structures in the sdtx_setup call.
  245. For instance to use a built-in font at slot 0, and a user-font at
  246. font slot 1, the sdtx_setup() call might look like this:
  247. sdtx_setup(&sdtx_desc_t){
  248. .fonts = {
  249. [0] = sdtx_font_kc853(),
  250. [1] = {
  251. .data = {
  252. .ptr = my_font_data,
  253. .size = sizeof(my_font_data)
  254. },
  255. .first_char = ...,
  256. .last_char = ...
  257. }
  258. }
  259. });
  260. Where 'my_font_data' is a byte array where every character is described
  261. by 8 bytes arranged like this:
  262. bits
  263. 7 6 5 4 3 2 1 0
  264. . . . X X . . . byte 0: 0x18
  265. . . X X X X . . byte 1: 0x3C
  266. . X X . . X X . byte 2: 0x66
  267. . X X . . X X . byte 3: 0x66
  268. . X X X X X X . byte 4: 0x7E
  269. . X X . . X X . byte 5: 0x66
  270. . X X . . X X . byte 6: 0x66
  271. . . . . . . . . byte 7: 0x00
  272. A complete font consists of 256 characters, resulting in 2048 bytes for
  273. the font data array (but note that the character codes 0..31 will never
  274. be rendered).
  275. If you provide such a complete font data array, you can drop the .first_char
  276. and .last_char initialization parameters since those default to 0 and 255,
  277. note that you can also use the SDTX_RANGE() helper macro to build the
  278. .data item:
  279. sdtx_setup(&sdtx_desc_t){
  280. .fonts = {
  281. [0] = sdtx_font_kc853(),
  282. [1] = {
  283. .data = SDTX_RANGE(my_font_data)
  284. }
  285. }
  286. });
  287. If the font doesn't define all 256 character tiles, or you don't need an
  288. entire 256-character font and want to save a couple of bytes, use the
  289. .first_char and .last_char initialization parameters to define a sub-range.
  290. For instance if the font only contains the characters between the Space
  291. (ASCII code 32) and uppercase character 'Z' (ASCII code 90):
  292. sdtx_setup(&sdtx_desc_t){
  293. .fonts = {
  294. [0] = sdtx_font_kc853(),
  295. [1] = {
  296. .data = SDTX_RANGE(my_font_data),
  297. .first_char = 32, // could also write ' '
  298. .last_char = 90 // could also write 'Z'
  299. }
  300. }
  301. });
  302. Character tiles that haven't been defined in the font will be rendered
  303. as a solid 8x8 quad.
  304. MEMORY ALLOCATION OVERRIDE
  305. ==========================
  306. You can override the memory allocation functions at initialization time
  307. like this:
  308. void* my_alloc(size_t size, void* user_data) {
  309. return malloc(size);
  310. }
  311. void my_free(void* ptr, void* user_data) {
  312. free(ptr);
  313. }
  314. ...
  315. sdtx_setup(&(sdtx_desc_t){
  316. // ...
  317. .allocator = {
  318. .alloc_fn = my_alloc,
  319. .free_fn = my_free,
  320. .user_data = ...;
  321. }
  322. });
  323. ...
  324. If no overrides are provided, malloc and free will be used.
  325. ERROR REPORTING AND LOGGING
  326. ===========================
  327. To get any logging information at all you need to provide a logging callback in the setup call,
  328. the easiest way is to use sokol_log.h:
  329. #include "sokol_log.h"
  330. sdtx_setup(&(sdtx_desc_t){
  331. // ...
  332. .logger.func = slog_func
  333. });
  334. To override logging with your own callback, first write a logging function like this:
  335. void my_log(const char* tag, // e.g. 'sdtx'
  336. uint32_t log_level, // 0=panic, 1=error, 2=warn, 3=info
  337. uint32_t log_item_id, // SDTX_LOGITEM_*
  338. const char* message_or_null, // a message string, may be nullptr in release mode
  339. uint32_t line_nr, // line number in sokol_debugtext.h
  340. const char* filename_or_null, // source filename, may be nullptr in release mode
  341. void* user_data)
  342. {
  343. ...
  344. }
  345. ...and then setup sokol-debugtext like this:
  346. sdtx_setup(&(sdtx_desc_t){
  347. .logger = {
  348. .func = my_log,
  349. .user_data = my_user_data,
  350. }
  351. });
  352. The provided logging function must be reentrant (e.g. be callable from
  353. different threads).
  354. If you don't want to provide your own custom logger it is highly recommended to use
  355. the standard logger in sokol_log.h instead, otherwise you won't see any warnings or
  356. errors.
  357. LICENSE
  358. =======
  359. zlib/libpng license
  360. Copyright (c) 2020 Andre Weissflog
  361. This software is provided 'as-is', without any express or implied warranty.
  362. In no event will the authors be held liable for any damages arising from the
  363. use of this software.
  364. Permission is granted to anyone to use this software for any purpose,
  365. including commercial applications, and to alter it and redistribute it
  366. freely, subject to the following restrictions:
  367. 1. The origin of this software must not be misrepresented; you must not
  368. claim that you wrote the original software. If you use this software in a
  369. product, an acknowledgment in the product documentation would be
  370. appreciated but is not required.
  371. 2. Altered source versions must be plainly marked as such, and must not
  372. be misrepresented as being the original software.
  373. 3. This notice may not be removed or altered from any source
  374. distribution.
  375. */
  376. import sg "../gfx"
  377. import "core:fmt"
  378. import "core:strings"
  379. printf :: proc(s: string, args: ..any) {
  380. fstr := fmt.tprintf(s, ..args)
  381. putr(strings.unsafe_string_to_cstring(fstr), len(fstr))
  382. }
  383. import "core:c"
  384. _ :: c
  385. SOKOL_DEBUG :: #config(SOKOL_DEBUG, ODIN_DEBUG)
  386. DEBUG :: #config(SOKOL_DEBUGTEXT_DEBUG, SOKOL_DEBUG)
  387. USE_GL :: #config(SOKOL_USE_GL, false)
  388. USE_DLL :: #config(SOKOL_DLL, false)
  389. when ODIN_OS == .Windows {
  390. when USE_DLL {
  391. when USE_GL {
  392. when DEBUG { foreign import sokol_debugtext_clib { "../sokol_dll_windows_x64_gl_debug.lib" } }
  393. else { foreign import sokol_debugtext_clib { "../sokol_dll_windows_x64_gl_release.lib" } }
  394. } else {
  395. when DEBUG { foreign import sokol_debugtext_clib { "../sokol_dll_windows_x64_d3d11_debug.lib" } }
  396. else { foreign import sokol_debugtext_clib { "../sokol_dll_windows_x64_d3d11_release.lib" } }
  397. }
  398. } else {
  399. when USE_GL {
  400. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_windows_x64_gl_debug.lib" } }
  401. else { foreign import sokol_debugtext_clib { "sokol_debugtext_windows_x64_gl_release.lib" } }
  402. } else {
  403. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_windows_x64_d3d11_debug.lib" } }
  404. else { foreign import sokol_debugtext_clib { "sokol_debugtext_windows_x64_d3d11_release.lib" } }
  405. }
  406. }
  407. } else when ODIN_OS == .Darwin {
  408. when USE_DLL {
  409. when USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_arm64_gl_debug.dylib" } }
  410. else when USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_arm64_gl_release.dylib" } }
  411. else when USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_x64_gl_debug.dylib" } }
  412. else when USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_x64_gl_release.dylib" } }
  413. else when !USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_arm64_metal_debug.dylib" } }
  414. else when !USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_arm64_metal_release.dylib" } }
  415. else when !USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_x64_metal_debug.dylib" } }
  416. else when !USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_debugtext_clib { "../dylib/sokol_dylib_macos_x64_metal_release.dylib" } }
  417. } else {
  418. when USE_GL {
  419. when ODIN_ARCH == .arm64 {
  420. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_arm64_gl_debug.a" } }
  421. else { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_arm64_gl_release.a" } }
  422. } else {
  423. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_x64_gl_debug.a" } }
  424. else { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_x64_gl_release.a" } }
  425. }
  426. } else {
  427. when ODIN_ARCH == .arm64 {
  428. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_arm64_metal_debug.a" } }
  429. else { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_arm64_metal_release.a" } }
  430. } else {
  431. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_x64_metal_debug.a" } }
  432. else { foreign import sokol_debugtext_clib { "sokol_debugtext_macos_x64_metal_release.a" } }
  433. }
  434. }
  435. }
  436. } else when ODIN_OS == .Linux {
  437. when USE_DLL {
  438. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_linux_x64_gl_debug.so" } }
  439. else { foreign import sokol_debugtext_clib { "sokol_debugtext_linux_x64_gl_release.so" } }
  440. } else {
  441. when DEBUG { foreign import sokol_debugtext_clib { "sokol_debugtext_linux_x64_gl_debug.a" } }
  442. else { foreign import sokol_debugtext_clib { "sokol_debugtext_linux_x64_gl_release.a" } }
  443. }
  444. } else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
  445. // Feed sokol_debugtext_wasm_gl_debug.a or sokol_debugtext_wasm_gl_release.a into emscripten compiler.
  446. foreign import sokol_debugtext_clib { "env.o" }
  447. } else {
  448. #panic("This OS is currently not supported")
  449. }
  450. @(default_calling_convention="c", link_prefix="sdtx_")
  451. foreign sokol_debugtext_clib {
  452. // initialization/shutdown
  453. setup :: proc(#by_ptr desc: Desc) ---
  454. shutdown :: proc() ---
  455. // builtin font data (use to populate sdtx_desc.font[])
  456. font_kc853 :: proc() -> Font_Desc ---
  457. font_kc854 :: proc() -> Font_Desc ---
  458. font_z1013 :: proc() -> Font_Desc ---
  459. font_cpc :: proc() -> Font_Desc ---
  460. font_c64 :: proc() -> Font_Desc ---
  461. font_oric :: proc() -> Font_Desc ---
  462. // context functions
  463. make_context :: proc(#by_ptr desc: Context_Desc) -> Context ---
  464. destroy_context :: proc(ctx: Context) ---
  465. set_context :: proc(ctx: Context) ---
  466. get_context :: proc() -> Context ---
  467. default_context :: proc() -> Context ---
  468. // drawing functions (call inside sokol-gfx render pass)
  469. draw :: proc() ---
  470. context_draw :: proc(ctx: Context) ---
  471. draw_layer :: proc(#any_int layer_id: c.int) ---
  472. context_draw_layer :: proc(ctx: Context, #any_int layer_id: c.int) ---
  473. // switch render layer
  474. layer :: proc(#any_int layer_id: c.int) ---
  475. // switch to a different font
  476. font :: proc(#any_int font_index: c.int) ---
  477. // set a new virtual canvas size in screen pixels
  478. canvas :: proc(w: f32, h: f32) ---
  479. // set a new origin in character grid coordinates
  480. origin :: proc(x: f32, y: f32) ---
  481. // cursor movement functions (relative to origin in character grid coordinates)
  482. home :: proc() ---
  483. pos :: proc(x: f32, y: f32) ---
  484. pos_x :: proc(x: f32) ---
  485. pos_y :: proc(y: f32) ---
  486. move :: proc(dx: f32, dy: f32) ---
  487. move_x :: proc(dx: f32) ---
  488. move_y :: proc(dy: f32) ---
  489. crlf :: proc() ---
  490. // set the current text color
  491. color3b :: proc(r: u8, g: u8, b: u8) ---
  492. color3f :: proc(r: f32, g: f32, b: f32) ---
  493. color4b :: proc(r: u8, g: u8, b: u8, a: u8) ---
  494. color4f :: proc(r: f32, g: f32, b: f32, a: f32) ---
  495. color1i :: proc(rgba: u32) ---
  496. // text rendering
  497. putc :: proc(c: u8) ---
  498. puts :: proc(str: cstring) ---
  499. putr :: proc(str: cstring, #any_int len: c.int) ---
  500. // language bindings helper: get the internal printf format buffer
  501. get_cleared_fmt_buffer :: proc() -> Range ---
  502. }
  503. Log_Item :: enum i32 {
  504. OK,
  505. MALLOC_FAILED,
  506. ADD_COMMIT_LISTENER_FAILED,
  507. COMMAND_BUFFER_FULL,
  508. CONTEXT_POOL_EXHAUSTED,
  509. CANNOT_DESTROY_DEFAULT_CONTEXT,
  510. }
  511. /*
  512. sdtx_logger_t
  513. Used in sdtx_desc_t to provide a custom logging and error reporting
  514. callback to sokol-debugtext.
  515. */
  516. Logger :: struct {
  517. func : proc "c" (a0: cstring, a1: u32, a2: u32, a3: cstring, a4: u32, a5: cstring, a6: rawptr),
  518. user_data : rawptr,
  519. }
  520. // a rendering context handle
  521. Context :: struct {
  522. id : u32,
  523. }
  524. /*
  525. sdtx_range is a pointer-size-pair struct used to pass memory
  526. blobs into sokol-debugtext. When initialized from a value type
  527. (array or struct), use the SDTX_RANGE() macro to build
  528. an sdtx_range struct.
  529. */
  530. Range :: struct {
  531. ptr : rawptr,
  532. size : c.size_t,
  533. }
  534. Font_Desc :: struct {
  535. data : Range,
  536. first_char : u8,
  537. last_char : u8,
  538. }
  539. /*
  540. sdtx_context_desc_t
  541. Describes the initialization parameters of a rendering context. Creating
  542. additional rendering contexts is useful if you want to render in
  543. different sokol-gfx rendering passes, or when rendering several layers
  544. of text.
  545. */
  546. Context_Desc :: struct {
  547. max_commands : c.int,
  548. char_buf_size : c.int,
  549. canvas_width : f32,
  550. canvas_height : f32,
  551. tab_width : c.int,
  552. color_format : sg.Pixel_Format,
  553. depth_format : sg.Pixel_Format,
  554. sample_count : c.int,
  555. }
  556. /*
  557. sdtx_allocator_t
  558. Used in sdtx_desc_t to provide custom memory-alloc and -free functions
  559. to sokol_debugtext.h. If memory management should be overridden, both the
  560. alloc_fn and free_fn function must be provided (e.g. it's not valid to
  561. override one function but not the other).
  562. */
  563. Allocator :: struct {
  564. alloc_fn : proc "c" (a0: c.size_t, a1: rawptr) -> rawptr,
  565. free_fn : proc "c" (a0: rawptr, a1: rawptr),
  566. user_data : rawptr,
  567. }
  568. /*
  569. sdtx_desc_t
  570. Describes the sokol-debugtext API initialization parameters. Passed
  571. to the sdtx_setup() function.
  572. NOTE: to populate the fonts item array with builtin fonts, use any
  573. of the following functions:
  574. sdtx_font_kc853()
  575. sdtx_font_kc854()
  576. sdtx_font_z1013()
  577. sdtx_font_cpc()
  578. sdtx_font_c64()
  579. sdtx_font_oric()
  580. */
  581. Desc :: struct {
  582. context_pool_size : c.int,
  583. printf_buf_size : c.int,
  584. fonts : [8]Font_Desc,
  585. ctx : Context_Desc,
  586. allocator : Allocator,
  587. logger : Logger,
  588. }