@defold-typescript/types 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/api-availability.json +4024 -716
  2. package/api-migrations.json +27 -0
  3. package/api-signatures.json +18118 -10264
  4. package/api-targets.json +448 -11
  5. package/examples/translations.json +619 -148
  6. package/fixtures/messages_doc.json +96 -0
  7. package/generated/b2d.d.ts +680 -4
  8. package/generated/b2d_body.d.ts +29 -103
  9. package/generated/b2d_chain.d.ts +5 -6
  10. package/generated/b2d_fixture.d.ts +34 -38
  11. package/generated/b2d_joint.d.ts +503 -25
  12. package/generated/b2d_shape.d.ts +199 -14
  13. package/generated/b2d_world.d.ts +57 -63
  14. package/generated/buffer.d.ts +33 -29
  15. package/generated/builtin-messages.d.ts +7 -1
  16. package/generated/bullet3d.d.ts +91 -0
  17. package/generated/bullet3d_collision_object.d.ts +433 -0
  18. package/generated/bullet3d_constraint.d.ts +818 -0
  19. package/generated/bullet3d_rigid_body.d.ts +429 -0
  20. package/generated/bullet3d_shape.d.ts +123 -0
  21. package/generated/bullet3d_world.d.ts +492 -0
  22. package/generated/camera.d.ts +31 -34
  23. package/generated/collectionfactory.d.ts +26 -27
  24. package/generated/collectionproxy.d.ts +22 -6
  25. package/generated/compute.d.ts +12 -238
  26. package/generated/crash.d.ts +24 -10
  27. package/generated/editor-vm/http.d.ts +90 -7
  28. package/generated/editor-vm/image.d.ts +7 -7
  29. package/generated/editor-vm/json.d.ts +11 -0
  30. package/generated/editor-vm/localization.d.ts +7 -7
  31. package/generated/editor-vm/tilemap_tiles.d.ts +56 -10
  32. package/generated/editor-vm/zip.d.ts +28 -0
  33. package/generated/editor.d.ts +1496 -430
  34. package/generated/factory.d.ts +21 -25
  35. package/generated/font.d.ts +64 -22
  36. package/generated/go.d.ts +243 -186
  37. package/generated/graphics.d.ts +374 -84
  38. package/generated/gui.d.ts +282 -492
  39. package/generated/html5.d.ts +5 -3
  40. package/generated/http.d.ts +31 -36
  41. package/generated/image.d.ts +127 -85
  42. package/generated/json.d.ts +34 -16
  43. package/generated/kinds/gui-script.d.ts +8 -0
  44. package/generated/kinds/render-script.d.ts +8 -0
  45. package/generated/kinds/script.d.ts +8 -0
  46. package/generated/label.d.ts +77 -7
  47. package/generated/liveupdate.d.ts +13 -10
  48. package/generated/material.d.ts +312 -360
  49. package/generated/model.d.ts +72 -42
  50. package/generated/particlefx.d.ts +19 -28
  51. package/generated/physics.d.ts +378 -144
  52. package/generated/profiler.d.ts +14 -24
  53. package/generated/render.d.ts +294 -297
  54. package/generated/resource.d.ts +753 -641
  55. package/generated/socket.d.ts +131 -134
  56. package/generated/sound.d.ts +65 -34
  57. package/generated/sprite.d.ts +39 -17
  58. package/generated/sys.d.ts +237 -182
  59. package/generated/tilemap.d.ts +21 -16
  60. package/generated/timer.d.ts +34 -21
  61. package/generated/versions/defold-1.12.4/b2d_body.d.ts +0 -7
  62. package/generated/versions/defold-1.12.4/buffer.d.ts +18 -17
  63. package/generated/versions/defold-1.12.4/camera.d.ts +23 -23
  64. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +21 -19
  65. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +2 -2
  66. package/generated/versions/defold-1.12.4/crash.d.ts +2 -2
  67. package/generated/versions/defold-1.12.4/factory.d.ts +15 -16
  68. package/generated/versions/defold-1.12.4/go.d.ts +15 -17
  69. package/generated/versions/defold-1.12.4/gui.d.ts +111 -193
  70. package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
  71. package/generated/versions/defold-1.12.4/http.d.ts +4 -15
  72. package/generated/versions/defold-1.12.4/image.d.ts +38 -46
  73. package/generated/versions/defold-1.12.4/index.d.ts +2 -0
  74. package/generated/versions/defold-1.12.4/json.d.ts +10 -6
  75. package/generated/versions/defold-1.12.4/label.d.ts +2 -3
  76. package/generated/versions/defold-1.12.4/liveupdate.d.ts +5 -3
  77. package/generated/versions/defold-1.12.4/model.d.ts +34 -13
  78. package/generated/versions/defold-1.12.4/particlefx.d.ts +2 -5
  79. package/generated/versions/defold-1.12.4/physics.d.ts +82 -78
  80. package/generated/versions/defold-1.12.4/profiler.d.ts +3 -6
  81. package/generated/versions/defold-1.12.4/render.d.ts +160 -132
  82. package/generated/versions/defold-1.12.4/resource.d.ts +212 -209
  83. package/generated/versions/defold-1.12.4/socket.d.ts +45 -61
  84. package/generated/versions/defold-1.12.4/sound.d.ts +11 -11
  85. package/generated/versions/defold-1.12.4/sprite.d.ts +24 -6
  86. package/generated/versions/defold-1.12.4/sys.d.ts +45 -68
  87. package/generated/versions/defold-1.12.4/tilemap.d.ts +18 -11
  88. package/generated/versions/defold-1.12.4/timer.d.ts +5 -3
  89. package/generated/versions/defold-1.12.4/vmath.d.ts +5 -26
  90. package/generated/versions/defold-1.12.4/window.d.ts +1 -16
  91. package/generated/versions/defold-1.13.0/b2d_body.d.ts +10 -55
  92. package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +25 -25
  93. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +188 -5
  94. package/generated/versions/defold-1.13.0/b2d_world.d.ts +16 -10
  95. package/generated/versions/defold-1.13.0/buffer.d.ts +18 -17
  96. package/generated/versions/defold-1.13.0/camera.d.ts +27 -27
  97. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +21 -19
  98. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +2 -2
  99. package/generated/versions/defold-1.13.0/compute.d.ts +1 -70
  100. package/generated/versions/defold-1.13.0/crash.d.ts +2 -2
  101. package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +3 -3
  102. package/generated/versions/defold-1.13.0/editor.d.ts +34 -24
  103. package/generated/versions/defold-1.13.0/factory.d.ts +15 -16
  104. package/generated/versions/defold-1.13.0/go.d.ts +15 -17
  105. package/generated/versions/defold-1.13.0/graphics.d.ts +121 -37
  106. package/generated/versions/defold-1.13.0/gui.d.ts +111 -193
  107. package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
  108. package/generated/versions/defold-1.13.0/http.d.ts +4 -15
  109. package/generated/versions/defold-1.13.0/image.d.ts +38 -46
  110. package/generated/versions/defold-1.13.0/index.d.ts +2 -0
  111. package/generated/versions/defold-1.13.0/json.d.ts +10 -6
  112. package/generated/versions/defold-1.13.0/label.d.ts +2 -3
  113. package/generated/versions/defold-1.13.0/liveupdate.d.ts +7 -5
  114. package/generated/versions/defold-1.13.0/material.d.ts +69 -107
  115. package/generated/versions/defold-1.13.0/model.d.ts +34 -13
  116. package/generated/versions/defold-1.13.0/particlefx.d.ts +2 -5
  117. package/generated/versions/defold-1.13.0/physics.d.ts +82 -78
  118. package/generated/versions/defold-1.13.0/profiler.d.ts +3 -6
  119. package/generated/versions/defold-1.13.0/render.d.ts +160 -132
  120. package/generated/versions/defold-1.13.0/resource.d.ts +217 -210
  121. package/generated/versions/defold-1.13.0/socket.d.ts +45 -61
  122. package/generated/versions/defold-1.13.0/sound.d.ts +11 -11
  123. package/generated/versions/defold-1.13.0/sprite.d.ts +24 -6
  124. package/generated/versions/defold-1.13.0/sys.d.ts +45 -68
  125. package/generated/versions/defold-1.13.0/tilemap.d.ts +18 -11
  126. package/generated/versions/defold-1.13.0/timer.d.ts +5 -3
  127. package/generated/versions/defold-1.13.0/vmath.d.ts +5 -26
  128. package/generated/versions/defold-1.13.0/window.d.ts +1 -16
  129. package/generated/versions/defold-1.13.1/b2d.d.ts +33 -0
  130. package/generated/versions/defold-1.13.1/b2d_body.d.ts +636 -0
  131. package/generated/versions/defold-1.13.1/b2d_chain.d.ts +106 -0
  132. package/generated/versions/defold-1.13.1/b2d_fixture.d.ts +157 -0
  133. package/generated/versions/defold-1.13.1/b2d_joint.d.ts +823 -0
  134. package/generated/versions/defold-1.13.1/b2d_shape.d.ts +400 -0
  135. package/generated/versions/defold-1.13.1/b2d_world.d.ts +320 -0
  136. package/generated/versions/defold-1.13.1/buffer.d.ts +189 -0
  137. package/generated/versions/defold-1.13.1/camera.d.ts +303 -0
  138. package/generated/versions/defold-1.13.1/collectionfactory.d.ts +151 -0
  139. package/generated/versions/defold-1.13.1/collectionproxy.d.ts +93 -0
  140. package/generated/versions/defold-1.13.1/compute.d.ts +237 -0
  141. package/generated/versions/defold-1.13.1/crash.d.ts +143 -0
  142. package/generated/versions/defold-1.13.1/editor-vm/http.d.ts +56 -0
  143. package/generated/versions/defold-1.13.1/editor-vm/image.d.ts +48 -0
  144. package/generated/versions/defold-1.13.1/editor-vm/json.d.ts +10 -0
  145. package/generated/versions/defold-1.13.1/editor-vm/localization.d.ts +42 -0
  146. package/generated/versions/defold-1.13.1/editor-vm/tilemap_tiles.d.ts +80 -0
  147. package/generated/versions/defold-1.13.1/editor-vm/zip.d.ts +10 -0
  148. package/generated/versions/defold-1.13.1/editor-vm/zlib.d.ts +24 -0
  149. package/generated/versions/defold-1.13.1/editor.d.ts +1121 -0
  150. package/generated/versions/defold-1.13.1/factory.d.ts +124 -0
  151. package/generated/versions/defold-1.13.1/font.d.ts +81 -0
  152. package/generated/versions/defold-1.13.1/go.d.ts +1107 -0
  153. package/generated/versions/defold-1.13.1/graphics.d.ts +411 -0
  154. package/generated/versions/defold-1.13.1/gui.d.ts +2353 -0
  155. package/generated/versions/defold-1.13.1/html5.d.ts +55 -0
  156. package/generated/versions/defold-1.13.1/http.d.ts +77 -0
  157. package/generated/versions/defold-1.13.1/image.d.ts +131 -0
  158. package/generated/versions/defold-1.13.1/index.d.ts +57 -0
  159. package/generated/versions/defold-1.13.1/json.d.ts +80 -0
  160. package/generated/versions/defold-1.13.1/kinds/editor-script.d.ts +14 -0
  161. package/generated/versions/defold-1.13.1/label.d.ts +93 -0
  162. package/generated/versions/defold-1.13.1/liveupdate.d.ts +142 -0
  163. package/generated/versions/defold-1.13.1/material.d.ts +408 -0
  164. package/generated/versions/defold-1.13.1/model.d.ts +272 -0
  165. package/generated/versions/defold-1.13.1/msg.d.ts +10 -0
  166. package/generated/versions/defold-1.13.1/particlefx.d.ts +163 -0
  167. package/generated/versions/defold-1.13.1/physics.d.ts +559 -0
  168. package/generated/versions/defold-1.13.1/profiler.d.ts +235 -0
  169. package/generated/versions/defold-1.13.1/render.d.ts +1190 -0
  170. package/generated/versions/defold-1.13.1/resource.d.ts +1523 -0
  171. package/generated/versions/defold-1.13.1/socket.d.ts +784 -0
  172. package/generated/versions/defold-1.13.1/sound.d.ts +292 -0
  173. package/generated/versions/defold-1.13.1/sprite.d.ts +175 -0
  174. package/generated/versions/defold-1.13.1/sys.d.ts +678 -0
  175. package/generated/versions/defold-1.13.1/tilemap.d.ts +208 -0
  176. package/generated/versions/defold-1.13.1/timer.d.ts +125 -0
  177. package/generated/versions/defold-1.13.1/types.d.ts +61 -0
  178. package/generated/versions/defold-1.13.1/vmath.d.ts +774 -0
  179. package/generated/versions/defold-1.13.1/window.d.ts +183 -0
  180. package/generated/versions/defold-1.13.1/zlib.d.ts +41 -0
  181. package/generated/vmath.d.ts +6 -26
  182. package/generated/window.d.ts +71 -71
  183. package/identity-vocabulary.json +561 -0
  184. package/index.d.ts +8 -0
  185. package/package.json +13 -2
  186. package/scripts/example-store-io.ts +12 -1
  187. package/scripts/extension-goldens.ts +1 -0
  188. package/scripts/fidelity-baseline.json +146 -46
  189. package/scripts/generate-api-availability.ts +90 -12
  190. package/scripts/generate-api-signatures.ts +14 -3
  191. package/scripts/import-defold-release.ts +85 -24
  192. package/scripts/prose-constants.ts +157 -0
  193. package/scripts/regen.ts +396 -78
  194. package/scripts/shared-handle-methods.ts +53 -0
  195. package/scripts/signature-store-fs.ts +1 -0
  196. package/scripts/sync-api-docs.ts +16 -5
  197. package/src/api-availability.ts +0 -0
  198. package/src/api-doc.ts +201 -3
  199. package/src/api-identity.ts +252 -0
  200. package/src/component-properties.d.ts +33 -0
  201. package/src/core-types.ts +28 -3
  202. package/src/correction-pins.ts +49 -0
  203. package/src/custom-messages.d.ts +4 -3
  204. package/src/doc-comment.ts +139 -23
  205. package/src/doc-corrections.ts +108 -0
  206. package/src/editor-vm-globals.d.ts +5 -2
  207. package/src/emit-dts.ts +2474 -281
  208. package/src/emit-messages.ts +52 -0
  209. package/src/engine-globals.d.ts +2 -2
  210. package/src/example-store.ts +125 -14
  211. package/src/field-correction-coverage.ts +204 -0
  212. package/src/fnv1a.ts +16 -0
  213. package/src/go-overloads.d.ts +33 -13
  214. package/src/index-base-table.ts +145 -0
  215. package/src/index-slot-classifications.ts +588 -0
  216. package/src/index.ts +39 -2
  217. package/src/library-index-slot-classifications.ts +332 -0
  218. package/src/lifecycle.ts +61 -199
  219. package/src/luals-type-expr.ts +354 -0
  220. package/src/msg-overloads.d.ts +0 -1
  221. package/src/param-correction-provenance.ts +64 -0
  222. package/src/return-correction-provenance.ts +58 -16
  223. package/src/script-api.ts +3 -1
  224. package/src/sys-overloads.d.ts +48 -0
  225. package/src/vmath-overloads.d.ts +27 -1
  226. package/src/window-event-guard.d.ts +6 -9
  227. package/url-parameters.json +1 -2
@@ -6,13 +6,135 @@ declare global {
6
6
  * Rendering API documentation
7
7
  */
8
8
  namespace render {
9
- type constant_buffer = Opaque<"constant_buffer">;
9
+ /**
10
+ * Render-camera options
11
+ */
12
+ interface camera_options {
13
+ /**
14
+ * Use the camera view-projection matrix for frustum culling. The default is false.
15
+ */
16
+ use_frustum?: boolean;
17
+ }
18
+ type constant_buffer = Opaque<"constant_buffer"> & { [name: string]: Vector4 | Matrix4 | Vector4[] | Matrix4[] };
19
+ /**
20
+ * Debug-draw options
21
+ */
22
+ interface debug_draw_options {
23
+ /**
24
+ * Frustum matrix used for culling renderable items.
25
+ */
26
+ frustum?: Matrix4;
27
+ /**
28
+ * Frustum planes used for culling. The default is render.FRUSTUM_PLANES_SIDES.
29
+ */
30
+ frustum_planes?: render.FRUSTUM_PLANES;
31
+ }
32
+ /**
33
+ * Compute-dispatch options
34
+ */
35
+ interface dispatch_options {
36
+ /**
37
+ * Constants used by the compute program. The values are copied when `render.dispatch_compute()` is called.
38
+ */
39
+ constants?: Opaque<"constant_buffer"> & { [name: string]: Vector4 | Matrix4 | Vector4[] | Matrix4[] };
40
+ }
41
+ /**
42
+ * Render draw options
43
+ */
44
+ interface draw_options {
45
+ /**
46
+ * Frustum matrix used for culling renderable items.
47
+ */
48
+ frustum?: Matrix4;
49
+ /**
50
+ * Frustum planes used for culling. The default is render.FRUSTUM_PLANES_SIDES.
51
+ */
52
+ frustum_planes?: render.FRUSTUM_PLANES;
53
+ /**
54
+ * Constants used while rendering. The values are copied when `render.draw()` is called.
55
+ */
56
+ constants?: Opaque<"constant_buffer"> & { [name: string]: Vector4 | Matrix4 | Vector4[] | Matrix4[] };
57
+ /**
58
+ * World-entry sort order. The default is the renderer's preferred back-to-front order.
59
+ */
60
+ sort_order?: render.SORT;
61
+ }
62
+ type render_predicate = number;
10
63
  type render_target = Opaque<"render_target">;
64
+ /**
65
+ * Render-target attachment parameters
66
+ */
67
+ interface render_target_buffer_params {
68
+ /**
69
+ * Attachment texture format.
70
+ */
71
+ format: graphics.TEXTURE_FORMAT;
72
+ /**
73
+ * Attachment width.
74
+ */
75
+ width: number;
76
+ /**
77
+ * Attachment height.
78
+ */
79
+ height: number;
80
+ /**
81
+ * Minification filter.
82
+ */
83
+ min_filter?: graphics.TEXTURE_FILTER;
84
+ /**
85
+ * Magnification filter.
86
+ */
87
+ mag_filter?: graphics.TEXTURE_FILTER;
88
+ /**
89
+ * Horizontal wrap mode.
90
+ */
91
+ u_wrap?: graphics.TEXTURE_WRAP;
92
+ /**
93
+ * Vertical wrap mode.
94
+ */
95
+ v_wrap?: graphics.TEXTURE_WRAP;
96
+ /**
97
+ * Depth wrap mode.
98
+ */
99
+ w_wrap?: graphics.TEXTURE_WRAP;
100
+ /**
101
+ * Attachment creation flags, applicable only to depth and stencil buffers.
102
+ */
103
+ flags?: render.RENDER_TARGET_FLAG | number;
104
+ }
105
+ type render_target_params = { sample_count?: number } & { [key: number]: render.render_target_buffer_params };
106
+ /**
107
+ * Render-target activation options
108
+ */
109
+ interface set_render_target_options {
110
+ /**
111
+ * Buffers whose contents become undefined after the target is deactivated. Missing buffers are ignored; combined depth-stencil buffers remain non-transient unless both are selected.
112
+ */
113
+ transient?: graphics.BUFFER_TYPE[];
114
+ }
11
115
  type texture = Opaque<"texture">;
12
116
  type ClearBufferKey = typeof graphics.BUFFER_TYPE_COLOR0_BIT | typeof graphics.BUFFER_TYPE_DEPTH_BIT | typeof graphics.BUFFER_TYPE_STENCIL_BIT;
117
+ type CONTEXT_EVENT = typeof render.CONTEXT_EVENT_CONTEXT_LOST | typeof render.CONTEXT_EVENT_CONTEXT_RESTORED;
118
+ type FRUSTUM_PLANES = typeof render.FRUSTUM_PLANES_ALL | typeof render.FRUSTUM_PLANES_SIDES;
119
+ type RENDER_TARGET_FLAG = typeof render.TEXTURE_BIT;
120
+ type SORT = typeof render.SORT_BACK_TO_FRONT | typeof render.SORT_FRONT_TO_BACK | typeof render.SORT_NONE;
121
+ /**
122
+ * rendering context was lost; rendering pauses and graphics resources become invalid
123
+ */
124
+ const CONTEXT_EVENT_CONTEXT_LOST: number & { readonly __brand: "render.CONTEXT_EVENT_CONTEXT_LOST" };
125
+ /**
126
+ * rendering context was restored; rendering remains paused while resources can be reloaded
127
+ */
128
+ const CONTEXT_EVENT_CONTEXT_RESTORED: number & { readonly __brand: "render.CONTEXT_EVENT_CONTEXT_RESTORED" };
129
+ /**
130
+ * All six frustum planes.
131
+ */
13
132
  const FRUSTUM_PLANES_ALL: number & { readonly __brand: "render.FRUSTUM_PLANES_ALL" };
133
+ /**
134
+ * Left, right, top, and bottom frustum planes.
135
+ */
14
136
  const FRUSTUM_PLANES_SIDES: number & { readonly __brand: "render.FRUSTUM_PLANES_SIDES" };
15
- const RENDER_TARGET_DEFAULT: number & { readonly __brand: "render.RENDER_TARGET_DEFAULT" };
137
+ const RENDER_TARGET_DEFAULT: undefined;
16
138
  /**
17
139
  * Depth sort far-to-near (default; good for transparent passes).
18
140
  */
@@ -25,6 +147,10 @@ declare global {
25
147
  * No per-call sorting; draw entries in insertion order.
26
148
  */
27
149
  const SORT_NONE: number & { readonly __brand: "render.SORT_NONE" };
150
+ /**
151
+ * Create a texture-backed depth or stencil attachment.
152
+ */
153
+ const TEXTURE_BIT: number & { readonly __brand: "render.TEXTURE_BIT" };
28
154
  /**
29
155
  * Clear buffers in the currently enabled render target with specified value. If the render target has been created with multiple
30
156
  * color attachments, all buffers will be cleared with the same value.
@@ -32,9 +158,7 @@ declare global {
32
158
  * @param buffers - table with keys specifying which buffers to clear and values set to clear values. Available keys are:
33
159
  *
34
160
  * - `graphics.BUFFER_TYPE_COLOR0_BIT`
35
- *
36
161
  * - `graphics.BUFFER_TYPE_DEPTH_BIT`
37
- *
38
162
  * - `graphics.BUFFER_TYPE_STENCIL_BIT`
39
163
  * @example
40
164
  * ```ts
@@ -52,42 +176,44 @@ declare global {
52
176
  *
53
177
  * @returns new constant buffer
54
178
  * @example
179
+ * Set a "tint" constant in a constant buffer in the render script:
55
180
  * ```ts
56
- * export default defineRenderScript({
57
- * init() {
58
- * return { my_pred: render.predicate([hash("my_tag")]) };
59
- * },
60
- *
61
- * update(self, dt) {
62
- * // Set a "tint" constant in a constant buffer in the render script:
63
- * const constants = render.constant_buffer();
64
- * constants.tint = vmath.vector4(1, 1, 1, 1);
65
- *
66
- * // Then use the constant buffer when drawing a predicate:
67
- * render.draw(self.my_pred, { constants });
68
- *
69
- * // The constant buffer also supports array values by specifying constants in an array:
70
- * const constants2 = render.constant_buffer();
71
- * constants2.light_colors = [];
72
- * constants2.light_colors[0] = vmath.vector4(1, 0, 0, 1);
73
- * constants2.light_colors[1] = vmath.vector4(0, 1, 0, 1);
74
- * constants2.light_colors[2] = vmath.vector4(0, 0, 1, 1);
75
- *
76
- * // You can also create the array by passing the vectors directly:
77
- * const constants3 = render.constant_buffer();
78
- * constants3.light_colors = [
79
- * vmath.vector4(1, 0, 0, 1),
80
- * vmath.vector4(0, 1, 0, 1),
81
- * vmath.vector4(0, 0, 1, 1),
82
- * ];
83
- *
84
- * // Add more constants to the array
85
- * constants3.light_colors[3] = vmath.vector4(1, 1, 1, 1);
86
- * },
87
- * });
181
+ * const constants = render.constant_buffer();
182
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
183
+ * ```
184
+ * @example
185
+ * Then use the constant buffer when drawing a predicate:
186
+ * ```ts
187
+ * function draw_tinted(self: { my_pred: Opaque<"render_predicate"> }) {
188
+ * const constants = render.constant_buffer();
189
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
190
+ * render.draw(self.my_pred, { constants });
191
+ * }
192
+ * ```
193
+ * @example
194
+ * The constant buffer also supports array values by specifying constants in a table:
195
+ * ```ts
196
+ * const constants = render.constant_buffer();
197
+ * constants.light_colors = [];
198
+ * constants.light_colors[0] = vmath.vector4(1, 0, 0, 1);
199
+ * constants.light_colors[1] = vmath.vector4(0, 1, 0, 1);
200
+ * constants.light_colors[2] = vmath.vector4(0, 0, 1, 1);
201
+ * ```
202
+ * @example
203
+ * You can also create the table by passing the vectors directly when creating the table:
204
+ * ```ts
205
+ * const constants = render.constant_buffer();
206
+ * constants.light_colors = [
207
+ * vmath.vector4(1, 0, 0, 1),
208
+ * vmath.vector4(0, 1, 0, 1),
209
+ * vmath.vector4(0, 0, 1, 1),
210
+ * ];
211
+ *
212
+ * // Add more constants to the array
213
+ * constants.light_colors[3] = vmath.vector4(1, 1, 1, 1);
88
214
  * ```
89
215
  */
90
- function constant_buffer(): Opaque<"constant_buffer">;
216
+ function constant_buffer(): Opaque<"constant_buffer"> & { [name: string]: Vector4 | Matrix4 | Vector4[] | Matrix4[] };
91
217
  /**
92
218
  * Deletes a render target created by a render script.
93
219
  * You cannot delete a render target resource.
@@ -136,15 +262,10 @@ declare global {
136
262
  * @param state - state to disable
137
263
  *
138
264
  * - `graphics.STATE_DEPTH_TEST`
139
- *
140
265
  * - `graphics.STATE_STENCIL_TEST`
141
- *
142
266
  * - `graphics.STATE_BLEND`
143
- *
144
267
  * - `graphics.STATE_ALPHA_TEST` ( not available on iOS and Android)
145
- *
146
268
  * - `graphics.STATE_CULL_FACE`
147
- *
148
269
  * - `graphics.STATE_POLYGON_OFFSET_FILL`
149
270
  * @example
150
271
  * ```ts
@@ -161,7 +282,7 @@ declare global {
161
282
  * });
162
283
  * ```
163
284
  */
164
- function disable_state(state: graphics.State): void;
285
+ function disable_state(state: graphics.STATE): void;
165
286
  /**
166
287
  * Disables a texture that has previourly been enabled.
167
288
  *
@@ -169,6 +290,18 @@ declare global {
169
290
  * @example
170
291
  * ```ts
171
292
  * export default defineRenderScript({
293
+ * init() {
294
+ * const color_params = {
295
+ * format: graphics.TEXTURE_FORMAT_RGBA,
296
+ * width: render.get_window_width(),
297
+ * height: render.get_window_height(),
298
+ * };
299
+ * return {
300
+ * my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
301
+ * my_pred: render.predicate([hash("my_tag")]),
302
+ * };
303
+ * },
304
+ *
172
305
  * update(self, dt) {
173
306
  * render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);
174
307
  * // draw a predicate with the render target available as texture 0 in the predicate
@@ -180,7 +313,7 @@ declare global {
180
313
  * });
181
314
  * ```
182
315
  */
183
- function disable_texture(binding: Opaque<"texture"> | string | Hash): void;
316
+ function disable_texture(binding: Opaque<"texture"> | string | Hash | number): void;
184
317
  /**
185
318
  * Dispatches the currently enabled compute program. The dispatch call takes three arguments x,y,z which constitutes
186
319
  * the 'global working group' of the compute dispatch. Together with the 'local working group' specified in the compute shader
@@ -191,10 +324,7 @@ declare global {
191
324
  * @param x - global work group size X
192
325
  * @param y - global work group size Y
193
326
  * @param z - global work group size Z
194
- * @param options - optional table with properties:
195
- *
196
- * `constants`
197
- * constant_buffer optional constants to use while rendering
327
+ * @param options - optional compute-dispatch options
198
328
  * @example
199
329
  * ```ts
200
330
  * export default defineRenderScript({
@@ -205,6 +335,7 @@ declare global {
205
335
  * height: render.get_window_height(),
206
336
  * };
207
337
  * return {
338
+ * backing_texture: resource.get_texture_info("/main/backing.texturec").handle,
208
339
  * scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
209
340
  * };
210
341
  * },
@@ -217,14 +348,16 @@ declare global {
217
348
  * render.set_compute();
218
349
  * },
219
350
  * });
220
- *
221
- * // Dispatch a compute program with a constant buffer:
351
+ * ```
352
+ * @example
353
+ * Dispatch a compute program with a constant buffer:
354
+ * ```ts
222
355
  * const constants = render.constant_buffer();
223
356
  * constants.tint = vmath.vector4(1, 1, 1, 1);
224
357
  * render.dispatch_compute(32, 32, 32, { constants });
225
358
  * ```
226
359
  */
227
- function dispatch_compute(x: number, y: number, z: number, options?: { constants?: Opaque<"constant_buffer"> }): void;
360
+ function dispatch_compute(x: number, y: number, z: number, options?: render.dispatch_options): void;
228
361
  /**
229
362
  * Draws all objects that match a specified predicate. An optional constant buffer can be
230
363
  * provided to override the default constants. If no constants buffer is provided, a default
@@ -232,21 +365,7 @@ declare global {
232
365
  * go.set (or particlefx.set_constant) on visual components.
233
366
  *
234
367
  * @param predicate - predicate to draw for
235
- * @param options - optional table with properties:
236
- *
237
- * `frustum`
238
- * matrix4 A frustum matrix used to cull renderable items. (E.g. `local frustum = proj * view`). default=nil
239
- * `frustum_planes`
240
- * int Determines which sides of the frustum will be used. Default is render.FRUSTUM_PLANES_SIDES.
241
- *
242
- * - render.FRUSTUM_PLANES_SIDES : The left, right, top and bottom sides of the frustum.
243
- *
244
- * - render.FRUSTUM_PLANES_ALL : All 6 sides of the frustum.
245
- *
246
- * `constants`
247
- * constant_buffer optional constants to use while rendering
248
- * `sort_order`
249
- * int How to sort draw order for world-ordered entries. Default uses the renderer's preferred world sorting (back-to-front).
368
+ * @param options - optional draw options
250
369
  * @example
251
370
  * ```ts
252
371
  * export default defineRenderScript({
@@ -258,37 +377,40 @@ declare global {
258
377
  * update(self, dt) {
259
378
  * // draw everything in the my_pred predicate
260
379
  * render.draw(self.my_pred);
261
- *
262
- * // Draw predicate with constants:
263
- * const constants = render.constant_buffer();
264
- * constants.tint = vmath.vector4(1, 1, 1, 1);
265
- * render.draw(self.my_pred, { constants });
266
- *
267
- * // Draw with predicate and frustum culling (without near+far planes):
268
- * const frustum = self.proj.mul(self.view);
269
- * render.draw(self.my_pred, { frustum });
270
- *
271
- * // Draw with predicate and frustum culling (with near+far planes):
272
- * const frustum2 = self.proj.mul(self.view);
273
- * render.draw(self.my_pred, { frustum: frustum2, frustum_planes: render.FRUSTUM_PLANES_ALL });
274
380
  * },
275
381
  * });
276
382
  * ```
383
+ * @example
384
+ * Draw predicate with constants:
385
+ * ```ts
386
+ * function draw_tinted(self: { my_pred: Opaque<"render_predicate"> }) {
387
+ * const constants = render.constant_buffer();
388
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
389
+ * render.draw(self.my_pred, { constants });
390
+ * }
391
+ * ```
392
+ * @example
393
+ * Draw with predicate and frustum culling (without near+far planes):
394
+ * ```ts
395
+ * function draw_culled(self: { my_pred: Opaque<"render_predicate">; proj: Matrix4; view: Matrix4 }) {
396
+ * const frustum = self.proj.mul(self.view);
397
+ * render.draw(self.my_pred, { frustum });
398
+ * }
399
+ * ```
400
+ * @example
401
+ * Draw with predicate and frustum culling (with near+far planes):
402
+ * ```ts
403
+ * function draw_culled(self: { my_pred: Opaque<"render_predicate">; proj: Matrix4; view: Matrix4 }) {
404
+ * const frustum = self.proj.mul(self.view);
405
+ * render.draw(self.my_pred, { frustum, frustum_planes: render.FRUSTUM_PLANES_ALL });
406
+ * }
407
+ * ```
277
408
  */
278
- function draw(predicate: number, options?: { frustum?: Matrix4; frustum_planes?: number; constants?: Opaque<"constant_buffer">; sort_order?: number }): void;
409
+ function draw(predicate: Opaque<"render_predicate">, options?: render.draw_options): void;
279
410
  /**
280
411
  * Draws all 3d debug graphics such as lines drawn with "draw_line" messages and physics visualization.
281
412
  *
282
- * @param options - optional table with properties:
283
- *
284
- * `frustum`
285
- * matrix4 A frustum matrix used to cull renderable items. (E.g. `local frustum = proj * view`). May be nil.
286
- * `frustum_planes`
287
- * int Determines which sides of the frustum will be used. Default is render.FRUSTUM_PLANES_SIDES.
288
- *
289
- * - render.FRUSTUM_PLANES_SIDES : The left, right, top and bottom sides of the frustum.
290
- *
291
- * - render.FRUSTUM_PLANES_ALL : All sides of the frustum.
413
+ * @param options - optional debug-draw options
292
414
  * @example
293
415
  * ```ts
294
416
  * export default defineRenderScript({
@@ -299,7 +421,7 @@ declare global {
299
421
  * });
300
422
  * ```
301
423
  */
302
- function draw_debug3d(options?: { frustum?: Matrix4; frustum_planes?: number }): void;
424
+ function draw_debug3d(options?: render.debug_draw_options): void;
303
425
  /**
304
426
  * If another material was already enabled, it will be automatically disabled
305
427
  * and the specified material is used instead.
@@ -330,15 +452,10 @@ declare global {
330
452
  * @param state - state to enable
331
453
  *
332
454
  * - `graphics.STATE_DEPTH_TEST`
333
- *
334
455
  * - `graphics.STATE_STENCIL_TEST`
335
- *
336
456
  * - `graphics.STATE_BLEND`
337
- *
338
457
  * - `graphics.STATE_ALPHA_TEST` ( not available on iOS and Android)
339
- *
340
458
  * - `graphics.STATE_CULL_FACE`
341
- *
342
459
  * - `graphics.STATE_POLYGON_OFFSET_FILL`
343
460
  * @example
344
461
  * ```ts
@@ -356,7 +473,7 @@ declare global {
356
473
  * });
357
474
  * ```
358
475
  */
359
- function enable_state(state: graphics.State): void;
476
+ function enable_state(state: graphics.STATE): void;
360
477
  /**
361
478
  * Sets the specified texture handle for a render target attachment or a regular texture
362
479
  * that should be used for rendering. The texture can be bound to either a texture unit
@@ -372,29 +489,22 @@ declare global {
372
489
  *
373
490
  * @param binding - texture binding, either by texture unit, string or hash for the sampler name that the texture should be bound to
374
491
  * @param handle_or_name - render target or texture handle that should be bound, or a named resource in the "Render Resource" table in the currently assigned .render file
375
- * @param buffer_type - optional buffer type from which to enable the texture. Note that this argument only applies to render targets. Defaults to `graphics.BUFFER_TYPE_COLOR0_BIT`. These values are supported:
376
- *
377
- * - `graphics.BUFFER_TYPE_COLOR0_BIT`
378
- *
379
- * If The render target has been created as depth and/or stencil textures, these buffer types can be used:
380
- *
381
- * - `graphics.BUFFER_TYPE_DEPTH_BIT`
382
- *
383
- * - `graphics.BUFFER_TYPE_STENCIL_BIT`
384
- *
385
- * If the render target has been created with multiple color attachments, these buffer types can be used
386
- * to enable those textures as well. Currently 4 color attachments are supported:
387
- *
388
- * - `graphics.BUFFER_TYPE_COLOR0_BIT`
389
- *
390
- * - `graphics.BUFFER_TYPE_COLOR1_BIT`
391
- *
392
- * - `graphics.BUFFER_TYPE_COLOR2_BIT`
393
- *
394
- * - `graphics.BUFFER_TYPE_COLOR3_BIT`
492
+ * @param buffer_type - optional render-target attachment. Defaults to `graphics.BUFFER_TYPE_COLOR0_BIT`. Depth and stencil attachments must have been created as textures; color attachments beyond the first require a render target with multiple color attachments (up to four are supported).
395
493
  * @example
396
494
  * ```ts
397
495
  * export default defineRenderScript({
496
+ * init() {
497
+ * const color_params = {
498
+ * format: graphics.TEXTURE_FORMAT_RGBA,
499
+ * width: render.get_window_width(),
500
+ * height: render.get_window_height(),
501
+ * };
502
+ * return {
503
+ * my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
504
+ * my_pred: render.predicate([hash("my_tag")]),
505
+ * };
506
+ * },
507
+ *
398
508
  * update(self, dt) {
399
509
  * // enable target so all drawing is done to it
400
510
  * render.set_render_target(self.my_render_target);
@@ -416,6 +526,10 @@ declare global {
416
526
  * ```ts
417
527
  * // Or enable a render target by resource id:
418
528
  * export default defineRenderScript({
529
+ * init() {
530
+ * return { my_pred: render.predicate([hash("my_tag")]) };
531
+ * },
532
+ *
419
533
  * update(self, dt) {
420
534
  * render.set_render_target("my_rt_resource");
421
535
  * render.draw(self.my_pred);
@@ -432,6 +546,10 @@ declare global {
432
546
  * ```ts
433
547
  * // Or bind a texture handle directly:
434
548
  * export default defineRenderScript({
549
+ * init() {
550
+ * return { my_texture_handle: resource.get_texture_info("/main/my_texture.texturec").handle };
551
+ * },
552
+ *
435
553
  * update(self, dt) {
436
554
  * // bind a texture to the texture unit 0
437
555
  * render.enable_texture(0, self.my_texture_handle);
@@ -441,7 +559,7 @@ declare global {
441
559
  * });
442
560
  * ```
443
561
  */
444
- function enable_texture(binding: number | string | Hash, handle_or_name: Opaque<"texture"> | string | Hash, buffer_type?: graphics.BufferType): void;
562
+ function enable_texture(binding: number | string | Hash, handle_or_name: Opaque<"texture"> | string | Hash | Opaque<"render_target"> | number, buffer_type?: graphics.BUFFER_TYPE): void;
445
563
  /**
446
564
  * Returns the logical window height that is set in the "game.project" settings.
447
565
  * Note that the actual window pixel size can change, either by device constraints
@@ -462,9 +580,7 @@ declare global {
462
580
  * @param buffer_type - which type of buffer to retrieve the height from
463
581
  *
464
582
  * - `graphics.BUFFER_TYPE_COLOR0_BIT`
465
- *
466
583
  * - `graphics.BUFFER_TYPE_DEPTH_BIT`
467
- *
468
584
  * - `graphics.BUFFER_TYPE_STENCIL_BIT`
469
585
  * @returns the height of the render target buffer texture
470
586
  * @example
@@ -497,7 +613,7 @@ declare global {
497
613
  * });
498
614
  * ```
499
615
  */
500
- function get_render_target_height(render_target: Opaque<"render_target">, buffer_type: graphics.BufferType): number;
616
+ function get_render_target_height(render_target: Opaque<"render_target"> | string | Hash, buffer_type: graphics.BUFFER_TYPE): number;
501
617
  /**
502
618
  * Returns the specified buffer width from a render target.
503
619
  *
@@ -505,11 +621,8 @@ declare global {
505
621
  * @param buffer_type - which type of buffer to retrieve the width from
506
622
  *
507
623
  * - `graphics.BUFFER_TYPE_COLOR0_BIT`
508
- *
509
624
  * - `graphics.BUFFER_TYPE_COLOR[x]_BIT` (x: [0..3], if supported!)
510
- *
511
625
  * - `graphics.BUFFER_TYPE_DEPTH_BIT`
512
- *
513
626
  * - `graphics.BUFFER_TYPE_STENCIL_BIT`
514
627
  * @returns the width of the render target buffer texture
515
628
  * @example
@@ -542,13 +655,13 @@ declare global {
542
655
  * });
543
656
  * ```
544
657
  */
545
- function get_render_target_width(render_target: Opaque<"render_target">, buffer_type: graphics.BufferType): number;
658
+ function get_render_target_width(render_target: Opaque<"render_target"> | string | Hash, buffer_type: graphics.BUFFER_TYPE): number;
546
659
  /**
547
660
  * Returns the logical window width that is set in the "game.project" settings.
548
661
  * Note that the actual window pixel size can change, either by device constraints
549
662
  * or user input.
550
663
  *
551
- * @returns specified window width (number)
664
+ * @returns specified window width
552
665
  * @example
553
666
  * ```ts
554
667
  * // Get the width of the window.
@@ -598,7 +711,7 @@ declare global {
598
711
  * const p = render.predicate([hash("opaque"), hash("smoke")]);
599
712
  * ```
600
713
  */
601
- function predicate(tags: (string | Hash)[]): number;
714
+ function predicate(tags: (string | Hash)[]): Opaque<"render_predicate">;
602
715
  /**
603
716
  * Sets the blend equation with separate equations for the color and alpha channels.
604
717
  *
@@ -609,7 +722,7 @@ declare global {
609
722
  * render.set_blend_equation_separate(graphics.BLEND_EQUATION_ADD, graphics.BLEND_EQUATION_REVERSE_SUBTRACT);
610
723
  * ```
611
724
  */
612
- function set_blend_equation_separate(equation_color: number, equation_alpha: number): void;
725
+ function set_blend_equation_separate(equation_color: graphics.BLEND_EQUATION, equation_alpha: graphics.BLEND_EQUATION): void;
613
726
  /**
614
727
  * Specifies the arithmetic used when computing pixel values that are written to the frame
615
728
  * buffer. In RGBA mode, pixels can be drawn using a function that blends the source RGBA
@@ -624,64 +737,11 @@ declare global {
624
737
  * The source scale factor is referred to as (sR,sG,sB,sA).
625
738
  * The destination scale factor is referred to as (dR,dG,dB,dA).
626
739
  * The color values have integer values between 0 and (kR,kG,kB,kA), where kc = 2mc - 1 and mc is the number of bitplanes for that color. I.e for 8 bit color depth, color values are between `0` and `255`.
627
- * Available factor constants and corresponding scale factors:
628
- *
629
- * Factor constant
630
- * Scale factor (fR,fG,fB,fA)
631
- *
632
- * `graphics.BLEND_FACTOR_ZERO`
633
- * (0,0,0,0)
634
- *
635
- * `graphics.BLEND_FACTOR_ONE`
636
- * (1,1,1,1)
637
- *
638
- * `graphics.BLEND_FACTOR_SRC_COLOR`
639
- * (Rs/kR,Gs/kG,Bs/kB,As/kA)
640
- *
641
- * `graphics.BLEND_FACTOR_ONE_MINUS_SRC_COLOR`
642
- * (1,1,1,1) - (Rs/kR,Gs/kG,Bs/kB,As/kA)
643
- *
644
- * `graphics.BLEND_FACTOR_DST_COLOR`
645
- * (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
646
- *
647
- * `graphics.BLEND_FACTOR_ONE_MINUS_DST_COLOR`
648
- * (1,1,1,1) - (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
649
- *
650
- * `graphics.BLEND_FACTOR_SRC_ALPHA`
651
- * (As/kA,As/kA,As/kA,As/kA)
652
- *
653
- * `graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA`
654
- * (1,1,1,1) - (As/kA,As/kA,As/kA,As/kA)
655
- *
656
- * `graphics.BLEND_FACTOR_DST_ALPHA`
657
- * (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
658
- *
659
- * `graphics.BLEND_FACTOR_ONE_MINUS_DST_ALPHA`
660
- * (1,1,1,1) - (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
661
- *
662
- * `graphics.BLEND_FACTOR_CONSTANT_COLOR`
663
- * (Rc,Gc,Bc,Ac)
664
- *
665
- * `graphics.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR`
666
- * (1,1,1,1) - (Rc,Gc,Bc,Ac)
667
- *
668
- * `graphics.BLEND_FACTOR_CONSTANT_ALPHA`
669
- * (Ac,Ac,Ac,Ac)
670
- *
671
- * `graphics.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA`
672
- * (1,1,1,1) - (Ac,Ac,Ac,Ac)
673
- *
674
- * `graphics.BLEND_FACTOR_SRC_ALPHA_SATURATE`
675
- * (i,i,i,1) where i = min(As, kA - Ad) /kA
676
- *
677
740
  * The blended RGBA values of a pixel comes from the following equations:
678
741
  *
679
742
  * - Rd = min(kR, Rs * sR + Rd * dR)
680
- *
681
743
  * - Gd = min(kG, Gs * sG + Gd * dG)
682
- *
683
744
  * - Bd = min(kB, Bs * sB + Bd * dB)
684
- *
685
745
  * - Ad = min(kA, As * sA + Ad * dA)
686
746
  *
687
747
  * Blend function `(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA)` is useful for
@@ -696,7 +756,7 @@ declare global {
696
756
  * render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
697
757
  * ```
698
758
  */
699
- function set_blend_func(source_factor: number, destination_factor: number): void;
759
+ function set_blend_func(source_factor: graphics.BLEND_FACTOR, destination_factor: graphics.BLEND_FACTOR): void;
700
760
  /**
701
761
  * Sets the blend function with separate blend factors for the color and alpha channels.
702
762
  *
@@ -720,34 +780,29 @@ declare global {
720
780
  * Note that the frustum plane option in render.draw can still be used together with the camera.
721
781
  *
722
782
  * @param camera - camera id to use, or nil to reset
723
- * @param options - optional table with properties:
724
- *
725
- * `use_frustum`
726
- * boolean If true, the renderer will use the cameras view-projection matrix for frustum culling (default: false)
783
+ * @param options - optional camera options
727
784
  * @example
785
+ * Set the current camera to be used for rendering
728
786
  * ```ts
729
- * export default defineRenderScript({
730
- * init() {
731
- * return { my_pred: render.predicate([hash("my_tag")]) };
732
- * },
733
- *
734
- * update(self, dt) {
735
- * // Set the current camera to be used for rendering
736
- * render.set_camera("main:/my_go#camera");
737
- * render.draw(self.my_pred);
738
- * render.set_camera(undefined);
739
- *
740
- * // Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command
741
- * // The camera frustum will take precedence over the frustum plane option in render.draw
742
- * render.set_camera("main:/my_go#camera", { use_frustum: true });
743
- * // However, we can still customize the frustum planes regardless of the camera option!
744
- * render.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });
745
- * render.set_camera();
746
- * },
747
- * });
787
+ * function draw_through_camera(self: { my_pred: Opaque<"render_predicate"> }) {
788
+ * render.set_camera("main:/my_go#camera");
789
+ * render.draw(self.my_pred);
790
+ * render.set_camera(undefined);
791
+ * }
792
+ * ```
793
+ * @example
794
+ * Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command
795
+ * ```ts
796
+ * function draw_through_camera(self: { my_pred: Opaque<"render_predicate"> }) {
797
+ * // The camera frustum will take precedence over the frustum plane option in render.draw
798
+ * render.set_camera("main:/my_go#camera", { use_frustum: true });
799
+ * // However, we can still customize the frustum planes regardless of the camera option!
800
+ * render.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });
801
+ * render.set_camera();
802
+ * }
748
803
  * ```
749
804
  */
750
- function set_camera(camera?: Url | number, options?: { use_frustum?: boolean }): void;
805
+ function set_camera(camera?: Url | number | string | Hash, options?: render.camera_options): void;
751
806
  /**
752
807
  * Specifies whether the individual color components in the frame buffer is enabled for writing (`true`) or disabled (`false`). For example, if `blue` is `false`, nothing is written to the blue component of any pixel in any of the color buffers, regardless of the drawing operation attempted. Note that writing are either enabled or disabled for entire color components, not the individual bits of a component.
753
808
  * The component masks are all initially `true`.
@@ -795,12 +850,6 @@ declare global {
795
850
  * `face_type` is `graphics.FACE_TYPE_BACK`.
796
851
  *
797
852
  * @param face_type - face type
798
- *
799
- * - `graphics.FACE_TYPE_FRONT`
800
- *
801
- * - `graphics.FACE_TYPE_BACK`
802
- *
803
- * - `graphics.FACE_TYPE_FRONT_AND_BACK`
804
853
  * @example
805
854
  * ```ts
806
855
  * // How to enable polygon culling and set front face culling:
@@ -808,30 +857,12 @@ declare global {
808
857
  * render.set_cull_face(graphics.FACE_TYPE_FRONT);
809
858
  * ```
810
859
  */
811
- function set_cull_face(face_type: number): void;
860
+ function set_cull_face(face_type: graphics.FACE_TYPE): void;
812
861
  /**
813
862
  * Specifies the function that should be used to compare each incoming pixel
814
863
  * depth value with the value present in the depth buffer.
815
864
  * The comparison is performed only if depth testing is enabled and specifies
816
865
  * the conditions under which a pixel will be drawn.
817
- * Function constants:
818
- *
819
- * - `graphics.COMPARE_FUNC_NEVER` (never passes)
820
- *
821
- * - `graphics.COMPARE_FUNC_LESS` (passes if the incoming depth value is less than the stored value)
822
- *
823
- * - `graphics.COMPARE_FUNC_LEQUAL` (passes if the incoming depth value is less than or equal to the stored value)
824
- *
825
- * - `graphics.COMPARE_FUNC_GREATER` (passes if the incoming depth value is greater than the stored value)
826
- *
827
- * - `graphics.COMPARE_FUNC_GEQUAL` (passes if the incoming depth value is greater than or equal to the stored value)
828
- *
829
- * - `graphics.COMPARE_FUNC_EQUAL` (passes if the incoming depth value is equal to the stored value)
830
- *
831
- * - `graphics.COMPARE_FUNC_NOTEQUAL` (passes if the incoming depth value is not equal to the stored value)
832
- *
833
- * - `graphics.COMPARE_FUNC_ALWAYS` (always passes)
834
- *
835
866
  * The depth function is initially set to `graphics.COMPARE_FUNC_LESS`.
836
867
  *
837
868
  * @param func - depth test function, see the description for available values
@@ -842,7 +873,7 @@ declare global {
842
873
  * render.set_depth_func(graphics.COMPARE_FUNC_NOTEQUAL);
843
874
  * ```
844
875
  */
845
- function set_depth_func(func: number): void;
876
+ function set_depth_func(func: graphics.COMPARE_FUNC): void;
846
877
  /**
847
878
  * Specifies whether the depth buffer is enabled for writing. The supplied mask governs
848
879
  * if depth buffer writing is enabled (`true`) or disabled (`false`).
@@ -857,18 +888,10 @@ declare global {
857
888
  */
858
889
  function set_depth_mask(depth: boolean): void;
859
890
  /**
860
- * Set or remove listener. Currenly only only two type of events can arrived:
861
- * `render.CONTEXT_EVENT_CONTEXT_LOST` - when rendering context lost. Rending paused and all graphics resources become invalid.
862
- * `render.CONTEXT_EVENT_CONTEXT_RESTORED` - when rendering context was restored. Rendering still paused and graphics resources still
863
- * invalid but can be reloaded.
891
+ * Set or remove the rendering-context event listener.
864
892
  *
865
893
  * @param callback - A callback that receives all render related events.
866
894
  * Pass `nil` if want to remove listener.
867
- *
868
- * `self`
869
- * object The render script
870
- * `event_type`
871
- * string Rendering event. Possible values: `render.CONTEXT_EVENT_CONTEXT_LOST`, `render.CONTEXT_EVENT_CONTEXT_RESTORED`
872
895
  * @example
873
896
  * ```ts
874
897
  * // Set listener and handle render context events.
@@ -886,7 +909,7 @@ declare global {
886
909
  * });
887
910
  * ```
888
911
  */
889
- function set_listener(callback?: (self: unknown, event_type: unknown) => void): void;
912
+ function set_listener(callback?: (self: unknown, event_type: render.CONTEXT_EVENT) => void): void;
890
913
  /**
891
914
  * Sets the scale and units used to calculate depth values.
892
915
  * If `graphics.STATE_POLYGON_OFFSET_FILL` is enabled, each fragment's depth value
@@ -897,7 +920,7 @@ declare global {
897
920
  * offset for each polygon. The initial value is `0`.
898
921
  * `units` is multiplied by an implementation-specific value to create a
899
922
  * constant depth offset. The initial value is `0`.
900
- * The value of the offset is computed as `factor` &times; `DZ` + `r` &times; `units`
923
+ * The value of the offset is computed as `factor` × `DZ` + `r` × `units`
901
924
  * `DZ` is a measurement of the depth slope of the polygon which is the change in z (depth)
902
925
  * values divided by the change in either x or y coordinates, as you traverse a polygon.
903
926
  * The depth values are in window coordinates, clamped to the range [0, 1].
@@ -932,19 +955,8 @@ declare global {
932
955
  * render target until it is replaced by a subsequent call to set_render_target.
933
956
  * This function supports render targets created by a render script, or a render target resource.
934
957
  *
935
- * @param render_target - render target to set. render.RENDER_TARGET_DEFAULT to set the default render target
936
- * @param options - optional table with behaviour parameters
937
- *
938
- * `transient`
939
- * table Transient frame buffer types are only valid while the render target is active, i.e becomes undefined when a new target is set by a subsequent call to set_render_target.
940
- * Default is all non-transient. Be aware that some hardware uses a combined depth stencil buffer and when this is the case both are considered non-transient if exclusively selected!
941
- * A buffer type defined that doesn't exist in the render target is silently ignored.
942
- *
943
- * - `graphics.BUFFER_TYPE_COLOR0_BIT`
944
- *
945
- * - `graphics.BUFFER_TYPE_DEPTH_BIT`
946
- *
947
- * - `graphics.BUFFER_TYPE_STENCIL_BIT`
958
+ * @param render_target - render target to set. Omit it, pass `nil`, or use render.RENDER_TARGET_DEFAULT to set the default render target
959
+ * @param options - optional render-target activation options
948
960
  * @example
949
961
  * How to set a render target and draw to it and then switch back to the default render target
950
962
  * The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support
@@ -952,6 +964,18 @@ declare global {
952
964
  * // How to set a render target and draw to it and then switch back to the default render target
953
965
  * // The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support
954
966
  * export default defineRenderScript({
967
+ * init() {
968
+ * const color_params = {
969
+ * format: graphics.TEXTURE_FORMAT_RGBA,
970
+ * width: render.get_window_width(),
971
+ * height: render.get_window_height(),
972
+ * };
973
+ * return {
974
+ * my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
975
+ * my_pred: render.predicate([hash("my_tag")]),
976
+ * };
977
+ * },
978
+ *
955
979
  * update(self, dt) {
956
980
  * // set render target so all drawing is done to it
957
981
  * render.set_render_target(self.my_render_target, {
@@ -971,6 +995,10 @@ declare global {
971
995
  * ```ts
972
996
  * // Or set the render target by a render target resource identifier:
973
997
  * export default defineRenderScript({
998
+ * init() {
999
+ * return { my_pred: render.predicate([hash("my_tag")]) };
1000
+ * },
1001
+ *
974
1002
  * update(self, dt) {
975
1003
  * render.set_render_target("my_rt_resource");
976
1004
  *
@@ -983,7 +1011,7 @@ declare global {
983
1011
  * });
984
1012
  * ```
985
1013
  */
986
- function set_render_target(render_target: Opaque<"render_target">, options?: { transient?: Record<string | number, unknown> }): void;
1014
+ function set_render_target(render_target?: Opaque<"render_target"> | string | Hash | typeof render.RENDER_TARGET_DEFAULT, options?: render.set_render_target_options): void;
987
1015
  /**
988
1016
  * Sets the render target size for a render target created from
989
1017
  * either a render script, or from a render target resource.
@@ -1006,7 +1034,7 @@ declare global {
1006
1034
  * });
1007
1035
  * ```
1008
1036
  */
1009
- function set_render_target_size(render_target: Opaque<"render_target">, width: number, height: number): void;
1037
+ function set_render_target_size(render_target: Opaque<"render_target"> | string | Hash, width: number, height: number): void;
1010
1038
  /**
1011
1039
  * Stenciling is similar to depth-buffering as it enables and disables drawing on a
1012
1040
  * per-pixel basis. First, GL drawing primitives are drawn into the stencil planes.
@@ -1014,30 +1042,13 @@ declare global {
1014
1042
  * where to draw.
1015
1043
  * The stencil test discards a pixel based on the outcome of a comparison between the
1016
1044
  * reference value `ref` and the corresponding value in the stencil buffer.
1017
- * `func` specifies the comparison function. See the table below for values.
1045
+ * `func` specifies the comparison function.
1018
1046
  * The initial value is `graphics.COMPARE_FUNC_ALWAYS`.
1019
1047
  * `ref` specifies the reference value for the stencil test. The value is clamped to
1020
1048
  * the range [0, 2n-1], where n is the number of bitplanes in the stencil buffer.
1021
1049
  * The initial value is `0`.
1022
1050
  * `mask` is ANDed with both the reference value and the stored stencil value when the test
1023
1051
  * is done. The initial value is all `1`'s.
1024
- * Function constant:
1025
- *
1026
- * - `graphics.COMPARE_FUNC_NEVER` (never passes)
1027
- *
1028
- * - `graphics.COMPARE_FUNC_LESS` (passes if (ref & mask) < (stencil & mask))
1029
- *
1030
- * - `graphics.COMPARE_FUNC_LEQUAL` (passes if (ref & mask) <= (stencil & mask))
1031
- *
1032
- * - `graphics.COMPARE_FUNC_GREATER` (passes if (ref & mask) > (stencil & mask))
1033
- *
1034
- * - `graphics.COMPARE_FUNC_GEQUAL` (passes if (ref & mask) >= (stencil & mask))
1035
- *
1036
- * - `graphics.COMPARE_FUNC_EQUAL` (passes if (ref & mask) = (stencil & mask))
1037
- *
1038
- * - `graphics.COMPARE_FUNC_NOTEQUAL` (passes if (ref & mask) != (stencil & mask))
1039
- *
1040
- * - `graphics.COMPARE_FUNC_ALWAYS` (always passes)
1041
1052
  *
1042
1053
  * @param func - stencil test function, see the description for available values
1043
1054
  * @param ref - reference value for the stencil test
@@ -1048,7 +1059,7 @@ declare global {
1048
1059
  * render.set_stencil_func(graphics.COMPARE_FUNC_EQUAL, 0, 1);
1049
1060
  * ```
1050
1061
  */
1051
- function set_stencil_func(func: number, ref: number, mask: number): void;
1062
+ function set_stencil_func(func: graphics.COMPARE_FUNC, ref: number, mask: number): void;
1052
1063
  /**
1053
1064
  * The stencil mask controls the writing of individual bits in the stencil buffer.
1054
1065
  * The least significant `n` bits of the parameter `mask`, where `n` is the number of
@@ -1074,24 +1085,6 @@ declare global {
1074
1085
  * value while stenciling is enabled. If the stencil test fails, no change is made to the
1075
1086
  * pixel's color or depth buffers, and `sfail` specifies what happens to the stencil buffer
1076
1087
  * contents.
1077
- * Operator constants:
1078
- *
1079
- * - `graphics.STENCIL_OP_KEEP` (keeps the current value)
1080
- *
1081
- * - `graphics.STENCIL_OP_ZERO` (sets the stencil buffer value to 0)
1082
- *
1083
- * - `graphics.STENCIL_OP_REPLACE` (sets the stencil buffer value to `ref`, as specified by render.set_stencil_func)
1084
- *
1085
- * - `graphics.STENCIL_OP_INCR` (increments the stencil buffer value and clamp to the maximum representable unsigned value)
1086
- *
1087
- * - `graphics.STENCIL_OP_INCR_WRAP` (increments the stencil buffer value and wrap to zero when incrementing the maximum representable unsigned value)
1088
- *
1089
- * - `graphics.STENCIL_OP_DECR` (decrements the current stencil buffer value and clamp to 0)
1090
- *
1091
- * - `graphics.STENCIL_OP_DECR_WRAP` (decrements the current stencil buffer value and wrap to the maximum representable unsigned value when decrementing zero)
1092
- *
1093
- * - `graphics.STENCIL_OP_INVERT` (bitwise inverts the current stencil buffer value)
1094
- *
1095
1088
  * `dppass` and `dpfail` specify the stencil buffer actions depending on whether subsequent
1096
1089
  * depth buffer tests succeed (dppass) or fail (dpfail).
1097
1090
  * The initial value for all operators is `graphics.STENCIL_OP_KEEP`.
@@ -1108,7 +1101,7 @@ declare global {
1108
1101
  * render.set_stencil_op(graphics.STENCIL_OP_REPLACE, graphics.STENCIL_OP_KEEP, graphics.STENCIL_OP_KEEP);
1109
1102
  * ```
1110
1103
  */
1111
- function set_stencil_op(sfail: number, dpfail: number, dppass: number): void;
1104
+ function set_stencil_op(sfail: graphics.STENCIL_OP, dpfail: graphics.STENCIL_OP, dppass: graphics.STENCIL_OP): void;
1112
1105
  /**
1113
1106
  * Sets the view matrix to use when rendering.
1114
1107
  *
@@ -1132,7 +1125,11 @@ declare global {
1132
1125
  * },
1133
1126
  *
1134
1127
  * on_message(self, message_id, message) {
1135
- * if (message_id === hash("set_view_projection")) {
1128
+ * if (
1129
+ * message_id === hash("set_view_projection") &&
1130
+ * types.is_matrix4(message.view) &&
1131
+ * types.is_matrix4(message.projection)
1132
+ * ) {
1136
1133
  * // camera view and projection arrives here.
1137
1134
  * self.view = message.view;
1138
1135
  * self.projection = message.projection;