@defold-typescript/types 0.19.4 → 0.20.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 (86) hide show
  1. package/api-availability.json +2755 -0
  2. package/api-migrations.json +31 -0
  3. package/api-signatures.json +2324 -0
  4. package/api-targets.json +493 -45
  5. package/generated/b2d.d.ts +6 -0
  6. package/generated/b2d_body.d.ts +329 -1
  7. package/generated/b2d_chain.d.ts +106 -0
  8. package/generated/b2d_fixture.d.ts +155 -0
  9. package/generated/b2d_joint.d.ts +823 -0
  10. package/generated/b2d_shape.d.ts +215 -0
  11. package/generated/b2d_world.d.ts +314 -0
  12. package/generated/builtin-messages.d.ts +18 -0
  13. package/generated/camera.d.ts +62 -5
  14. package/generated/compute.d.ts +306 -0
  15. package/generated/go.d.ts +29 -4
  16. package/generated/graphics.d.ts +95 -0
  17. package/generated/gui.d.ts +1 -3
  18. package/generated/json.d.ts +2 -2
  19. package/generated/kinds/gui-script.d.ts +7 -0
  20. package/generated/kinds/render-script.d.ts +7 -0
  21. package/generated/kinds/script.d.ts +7 -0
  22. package/generated/label.d.ts +1 -1
  23. package/generated/liveupdate.d.ts +22 -4
  24. package/generated/material.d.ts +444 -0
  25. package/generated/model.d.ts +46 -5
  26. package/generated/physics.d.ts +1 -3
  27. package/generated/profiler.d.ts +2 -3
  28. package/generated/render.d.ts +25 -9
  29. package/generated/resource.d.ts +2 -2
  30. package/generated/sprite.d.ts +15 -1
  31. package/generated/tilemap.d.ts +14 -0
  32. package/generated/versions/defold-1.12.4/b2d.d.ts +27 -0
  33. package/generated/versions/defold-1.12.4/b2d_body.d.ts +348 -0
  34. package/generated/versions/defold-1.12.4/buffer.d.ts +176 -0
  35. package/generated/versions/defold-1.12.4/camera.d.ts +245 -0
  36. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +146 -0
  37. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +71 -0
  38. package/generated/versions/defold-1.12.4/crash.d.ts +143 -0
  39. package/generated/versions/defold-1.12.4/factory.d.ts +123 -0
  40. package/generated/versions/defold-1.12.4/font.d.ts +81 -0
  41. package/generated/versions/defold-1.12.4/go.d.ts +1029 -0
  42. package/generated/versions/defold-1.12.4/graphics.d.ts +226 -0
  43. package/generated/versions/defold-1.12.4/gui.d.ts +2372 -0
  44. package/generated/versions/defold-1.12.4/html5.d.ts +53 -0
  45. package/generated/versions/defold-1.12.4/http.d.ts +84 -0
  46. package/generated/versions/defold-1.12.4/iac.d.ts +18 -0
  47. package/generated/versions/defold-1.12.4/iap.d.ts +60 -0
  48. package/generated/versions/defold-1.12.4/image.d.ts +139 -0
  49. package/generated/versions/defold-1.12.4/index.d.ts +41 -0
  50. package/generated/versions/defold-1.12.4/json.d.ts +76 -0
  51. package/generated/versions/defold-1.12.4/label.d.ts +94 -0
  52. package/generated/versions/defold-1.12.4/liveupdate.d.ts +122 -0
  53. package/generated/versions/defold-1.12.4/model.d.ts +205 -0
  54. package/generated/versions/defold-1.12.4/msg.d.ts +10 -0
  55. package/generated/versions/defold-1.12.4/particlefx.d.ts +166 -0
  56. package/generated/versions/defold-1.12.4/physics.d.ts +547 -0
  57. package/generated/versions/defold-1.12.4/profiler.d.ts +234 -0
  58. package/generated/versions/defold-1.12.4/push.d.ts +66 -0
  59. package/generated/versions/defold-1.12.4/render.d.ts +1149 -0
  60. package/generated/versions/defold-1.12.4/resource.d.ts +1518 -0
  61. package/generated/versions/defold-1.12.4/socket.d.ts +795 -0
  62. package/generated/versions/defold-1.12.4/sound.d.ts +291 -0
  63. package/generated/versions/defold-1.12.4/sprite.d.ts +143 -0
  64. package/generated/versions/defold-1.12.4/sys.d.ts +695 -0
  65. package/generated/versions/defold-1.12.4/tilemap.d.ts +181 -0
  66. package/generated/versions/defold-1.12.4/timer.d.ts +114 -0
  67. package/generated/versions/defold-1.12.4/types.d.ts +61 -0
  68. package/generated/versions/defold-1.12.4/vmath.d.ts +806 -0
  69. package/generated/versions/defold-1.12.4/webview.d.ts +68 -0
  70. package/generated/versions/defold-1.12.4/window.d.ts +198 -0
  71. package/generated/versions/defold-1.12.4/zlib.d.ts +40 -0
  72. package/index.d.ts +22 -0
  73. package/package.json +8 -1
  74. package/scripts/fidelity-audit.ts +69 -12
  75. package/scripts/fidelity-baseline.json +56 -0
  76. package/scripts/generate-api-availability.ts +139 -0
  77. package/scripts/generate-api-signatures.ts +66 -0
  78. package/scripts/import-defold-release.ts +480 -0
  79. package/scripts/regen.ts +53 -6
  80. package/scripts/sync-api-docs.ts +89 -41
  81. package/src/api-availability.ts +0 -0
  82. package/src/core-types.ts +9 -0
  83. package/src/emit-dts.ts +674 -17
  84. package/src/emit-messages.ts +72 -2
  85. package/src/index.ts +26 -1
  86. package/src/lifecycle.ts +43 -2
@@ -0,0 +1,1149 @@
1
+ /** @noSelfInFile */
2
+ import type { Hash, Matrix4, Opaque, Url, Vector4 } from "../../../src/core-types";
3
+
4
+ declare global {
5
+ /**
6
+ * Rendering functions, messages and constants. The "render" namespace is
7
+ * accessible only from render scripts.
8
+ *
9
+ * The rendering API was originally built on top of OpenGL ES 2.0, and it uses a subset of the
10
+ * OpenGL computer graphics rendering API for rendering 2D and 3D computer
11
+ * graphics. Our current target is OpenGLES 3.0 with fallbacks to 2.0 on some platforms.
12
+ *
13
+ * [icon:attention] It is possible to create materials and write shaders that
14
+ * require features not in OpenGL ES 2.0, but those will not work cross platform.
15
+ */
16
+ namespace render {
17
+ type constant_buffer = Opaque<"constant_buffer">;
18
+ type render_target = Opaque<"render_target">;
19
+ type texture = Opaque<"texture">;
20
+ const FRUSTUM_PLANES_ALL: number & { readonly __brand: "render.FRUSTUM_PLANES_ALL" };
21
+ const FRUSTUM_PLANES_SIDES: number & { readonly __brand: "render.FRUSTUM_PLANES_SIDES" };
22
+ const RENDER_TARGET_DEFAULT: number & { readonly __brand: "render.RENDER_TARGET_DEFAULT" };
23
+ /**
24
+ * Depth sort far-to-near (default; good for transparent passes).
25
+ */
26
+ const SORT_BACK_TO_FRONT: number & { readonly __brand: "render.SORT_BACK_TO_FRONT" };
27
+ /**
28
+ * Depth sort near-to-far (good for opaque passes to reduce overdraw).
29
+ */
30
+ const SORT_FRONT_TO_BACK: number & { readonly __brand: "render.SORT_FRONT_TO_BACK" };
31
+ /**
32
+ * No per-call sorting; draw entries in insertion order.
33
+ */
34
+ const SORT_NONE: number & { readonly __brand: "render.SORT_NONE" };
35
+ /**
36
+ * Clear buffers in the currently enabled render target with specified value. If the render target has been created with multiple
37
+ * color attachments, all buffers will be cleared with the same value.
38
+ *
39
+ * @param buffers - table with keys specifying which buffers to clear and values set to clear values. Available keys are:
40
+ *
41
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
42
+ *
43
+ * - `graphics.BUFFER_TYPE_DEPTH_BIT`
44
+ *
45
+ * - `graphics.BUFFER_TYPE_STENCIL_BIT`
46
+ * @example
47
+ * ```ts
48
+ * // Clear the color buffer and the depth buffer.
49
+ * render.clear({
50
+ * [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),
51
+ * [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,
52
+ * });
53
+ * ```
54
+ */
55
+ function clear(buffers: LuaMap<number, number | Vector4>): void;
56
+ /**
57
+ * Constant buffers are used to set shader program variables and are optionally passed to the `render.draw()` function.
58
+ * The buffer's constant elements can be indexed like an ordinary Lua table, but you can't iterate over them with pairs() or ipairs().
59
+ *
60
+ * @returns new constant buffer
61
+ * @example
62
+ * ```ts
63
+ * // Set a "tint" constant in a constant buffer in the render script:
64
+ * const constants = render.constant_buffer();
65
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
66
+ *
67
+ * // Then use the constant buffer when drawing a predicate:
68
+ * render.draw(self.my_pred, { constants });
69
+ *
70
+ * // The constant buffer also supports array values by specifying constants in an array:
71
+ * const constants2 = render.constant_buffer();
72
+ * constants2.light_colors = [];
73
+ * constants2.light_colors[0] = vmath.vector4(1, 0, 0, 1);
74
+ * constants2.light_colors[1] = vmath.vector4(0, 1, 0, 1);
75
+ * constants2.light_colors[2] = vmath.vector4(0, 0, 1, 1);
76
+ *
77
+ * // You can also create the array by passing the vectors directly:
78
+ * const constants3 = render.constant_buffer();
79
+ * constants3.light_colors = [
80
+ * vmath.vector4(1, 0, 0, 1),
81
+ * vmath.vector4(0, 1, 0, 1),
82
+ * vmath.vector4(0, 0, 1, 1),
83
+ * ];
84
+ *
85
+ * // Add more constants to the array
86
+ * constants3.light_colors[3] = vmath.vector4(1, 1, 1, 1);
87
+ * ```
88
+ */
89
+ function constant_buffer(): Opaque<"constant_buffer">;
90
+ /**
91
+ * Deletes a render target created by a render script.
92
+ * You cannot delete a render target resource.
93
+ *
94
+ * @param render_target - render target to delete
95
+ * @example
96
+ * ```ts
97
+ * // How to delete a render target:
98
+ * render.delete_render_target(self.my_render_target);
99
+ * ```
100
+ */
101
+ function delete_render_target(render_target: Opaque<"render_target">): void;
102
+ /**
103
+ * If a material is currently enabled, disable it.
104
+ * The name of the material must be specified in the ".render" resource set
105
+ * in the "game.project" setting.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * // Enable material named "glow", then draw my_pred with it.
110
+ * render.enable_material("glow");
111
+ * render.draw(self.my_pred);
112
+ * render.disable_material();
113
+ * ```
114
+ */
115
+ function disable_material(): void;
116
+ /**
117
+ * Disables a render state.
118
+ *
119
+ * @param state - state to disable
120
+ *
121
+ * - `graphics.STATE_DEPTH_TEST`
122
+ *
123
+ * - `graphics.STATE_STENCIL_TEST`
124
+ *
125
+ * - `graphics.STATE_BLEND`
126
+ *
127
+ * - `graphics.STATE_ALPHA_TEST` ( not available on iOS and Android)
128
+ *
129
+ * - `graphics.STATE_CULL_FACE`
130
+ *
131
+ * - `graphics.STATE_POLYGON_OFFSET_FILL`
132
+ * @example
133
+ * ```ts
134
+ * // Disable face culling when drawing the tile predicate:
135
+ * render.disable_state(graphics.STATE_CULL_FACE);
136
+ * render.draw(self.tile_pred);
137
+ * ```
138
+ */
139
+ function disable_state(state: Opaque<"constant">): void;
140
+ /**
141
+ * Disables a texture that has previourly been enabled.
142
+ *
143
+ * @param binding - texture binding, either by texture unit, string or hash that should be disabled
144
+ * @example
145
+ * ```ts
146
+ * export default defineScript({
147
+ * update(self, dt) {
148
+ * render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);
149
+ * // draw a predicate with the render target available as texture 0 in the predicate
150
+ * // material shader.
151
+ * render.draw(self.my_pred);
152
+ * // done, disable the texture
153
+ * render.disable_texture(0);
154
+ * },
155
+ * });
156
+ * ```
157
+ */
158
+ function disable_texture(binding: Opaque<"texture"> | string | Hash): void;
159
+ /**
160
+ * Dispatches the currently enabled compute program. The dispatch call takes three arguments x,y,z which constitutes
161
+ * the 'global working group' of the compute dispatch. Together with the 'local working group' specified in the compute shader
162
+ * as a layout qualifier, these two sets of parameters forms the number of invocations the compute shader will execute.
163
+ * An optional constant buffer can be provided to override the default constants. If no constants buffer is provided, a default
164
+ * system constants buffer is used containing constants as defined in the compute program.
165
+ *
166
+ * @param x - global work group size X
167
+ * @param y - global work group size Y
168
+ * @param z - global work group size Z
169
+ * @param options - optional table with properties:
170
+ *
171
+ * `constants`
172
+ * constant_buffer optional constants to use while rendering
173
+ * @example
174
+ * ```ts
175
+ * export default defineScript({
176
+ * init() {
177
+ * const color_params = {
178
+ * format: graphics.TEXTURE_FORMAT_RGBA,
179
+ * width: render.get_window_width(),
180
+ * height: render.get_window_height(),
181
+ * };
182
+ * return {
183
+ * scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
184
+ * };
185
+ * },
186
+ *
187
+ * update(self, dt) {
188
+ * render.set_compute("bloom");
189
+ * render.enable_texture(0, self.backing_texture);
190
+ * render.enable_texture(1, self.scene_rt);
191
+ * render.dispatch_compute(128, 128, 1);
192
+ * render.set_compute();
193
+ * },
194
+ * });
195
+ *
196
+ * // Dispatch a compute program with a constant buffer:
197
+ * const constants = render.constant_buffer();
198
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
199
+ * render.dispatch_compute(32, 32, 32, { constants });
200
+ * ```
201
+ */
202
+ function dispatch_compute(x: number, y: number, z: number, options?: { constants?: Opaque<"constant_buffer"> }): void;
203
+ /**
204
+ * Draws all objects that match a specified predicate. An optional constant buffer can be
205
+ * provided to override the default constants. If no constants buffer is provided, a default
206
+ * system constants buffer is used containing constants as defined in materials and set through
207
+ * go.set (or particlefx.set_constant) on visual components.
208
+ *
209
+ * @param predicate - predicate to draw for
210
+ * @param options - optional table with properties:
211
+ *
212
+ * `frustum`
213
+ * matrix4 A frustum matrix used to cull renderable items. (E.g. `local frustum = proj * view`). default=nil
214
+ * `frustum_planes`
215
+ * int Determines which sides of the frustum will be used. Default is render.FRUSTUM_PLANES_SIDES.
216
+ *
217
+ * - render.FRUSTUM_PLANES_SIDES : The left, right, top and bottom sides of the frustum.
218
+ *
219
+ * - render.FRUSTUM_PLANES_ALL : All 6 sides of the frustum.
220
+ *
221
+ * `constants`
222
+ * constant_buffer optional constants to use while rendering
223
+ * `sort_order`
224
+ * int How to sort draw order for world-ordered entries. Default uses the renderer's preferred world sorting (back-to-front).
225
+ * @example
226
+ * ```ts
227
+ * export default defineScript({
228
+ * init() {
229
+ * // define a predicate matching anything with material tag "my_tag"
230
+ * return { my_pred: render.predicate([hash("my_tag")]) };
231
+ * },
232
+ *
233
+ * update(self, dt) {
234
+ * // draw everything in the my_pred predicate
235
+ * render.draw(self.my_pred);
236
+ * },
237
+ * });
238
+ *
239
+ * // Draw predicate with constants:
240
+ * const constants = render.constant_buffer();
241
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
242
+ * render.draw(self.my_pred, { constants });
243
+ *
244
+ * // Draw with predicate and frustum culling (without near+far planes):
245
+ * const frustum = self.proj.mul(self.view);
246
+ * render.draw(self.my_pred, { frustum });
247
+ *
248
+ * // Draw with predicate and frustum culling (with near+far planes):
249
+ * const frustum2 = self.proj.mul(self.view);
250
+ * render.draw(self.my_pred, { frustum: frustum2, frustum_planes: render.FRUSTUM_PLANES_ALL });
251
+ * ```
252
+ */
253
+ function draw(predicate: number, options?: { frustum?: Matrix4; frustum_planes?: number; constants?: Opaque<"constant_buffer">; sort_order?: number }): void;
254
+ /**
255
+ * Draws all 3d debug graphics such as lines drawn with "draw_line" messages and physics visualization.
256
+ *
257
+ * @param options - optional table with properties:
258
+ *
259
+ * `frustum`
260
+ * matrix4 A frustum matrix used to cull renderable items. (E.g. `local frustum = proj * view`). May be nil.
261
+ * `frustum_planes`
262
+ * int Determines which sides of the frustum will be used. Default is render.FRUSTUM_PLANES_SIDES.
263
+ *
264
+ * - render.FRUSTUM_PLANES_SIDES : The left, right, top and bottom sides of the frustum.
265
+ *
266
+ * - render.FRUSTUM_PLANES_ALL : All sides of the frustum.
267
+ * @example
268
+ * ```ts
269
+ * export default defineScript({
270
+ * update(self, dt) {
271
+ * // draw debug visualization
272
+ * render.draw_debug3d();
273
+ * },
274
+ * });
275
+ * ```
276
+ */
277
+ function draw_debug3d(options?: { frustum?: Matrix4; frustum_planes?: number }): void;
278
+ /**
279
+ * If another material was already enabled, it will be automatically disabled
280
+ * and the specified material is used instead.
281
+ * The name of the material must be specified in the ".render" resource set
282
+ * in the "game.project" setting.
283
+ *
284
+ * @param material_id - material id to enable
285
+ * @example
286
+ * ```ts
287
+ * // Enable material named "glow", then draw my_pred with it.
288
+ * render.enable_material("glow");
289
+ * render.draw(self.my_pred);
290
+ * render.disable_material();
291
+ * ```
292
+ */
293
+ function enable_material(material_id: string | Hash): void;
294
+ /**
295
+ * Enables a particular render state. The state will be enabled until disabled.
296
+ *
297
+ * @param state - state to enable
298
+ *
299
+ * - `graphics.STATE_DEPTH_TEST`
300
+ *
301
+ * - `graphics.STATE_STENCIL_TEST`
302
+ *
303
+ * - `graphics.STATE_BLEND`
304
+ *
305
+ * - `graphics.STATE_ALPHA_TEST` ( not available on iOS and Android)
306
+ *
307
+ * - `graphics.STATE_CULL_FACE`
308
+ *
309
+ * - `graphics.STATE_POLYGON_OFFSET_FILL`
310
+ * @example
311
+ * ```ts
312
+ * // Enable stencil test when drawing the gui predicate, then disable it:
313
+ * render.enable_state(graphics.STATE_STENCIL_TEST);
314
+ * render.draw(self.gui_pred);
315
+ * render.disable_state(graphics.STATE_STENCIL_TEST);
316
+ * ```
317
+ */
318
+ function enable_state(state: Opaque<"constant">): void;
319
+ /**
320
+ * Sets the specified texture handle for a render target attachment or a regular texture
321
+ * that should be used for rendering. The texture can be bound to either a texture unit
322
+ * or to a sampler name by a hash or a string.
323
+ * A texture can be bound to multiple units and sampler names at the same time,
324
+ * the actual binding will be applied to the shaders when a shader program is bound.
325
+ * When mixing binding using both units and sampler names, you might end up in situations
326
+ * where two different textures will be applied to the same bind location in the shader.
327
+ * In this case, the texture set to the named sampler will take precedence over the unit.
328
+ * Note that you can bind multiple sampler names to the same texture, in case you want to reuse
329
+ * the same texture for differnt use-cases. It is however recommended that you use the same name
330
+ * everywhere for the textures that should be shared across different materials.
331
+ *
332
+ * @param binding - texture binding, either by texture unit, string or hash for the sampler name that the texture should be bound to
333
+ * @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
334
+ * @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:
335
+ *
336
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
337
+ *
338
+ * If The render target has been created as depth and/or stencil textures, these buffer types can be used:
339
+ *
340
+ * - `graphics.BUFFER_TYPE_DEPTH_BIT`
341
+ *
342
+ * - `graphics.BUFFER_TYPE_STENCIL_BIT`
343
+ *
344
+ * If the render target has been created with multiple color attachments, these buffer types can be used
345
+ * to enable those textures as well. Currently 4 color attachments are supported:
346
+ *
347
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
348
+ *
349
+ * - `graphics.BUFFER_TYPE_COLOR1_BIT`
350
+ *
351
+ * - `graphics.BUFFER_TYPE_COLOR2_BIT`
352
+ *
353
+ * - `graphics.BUFFER_TYPE_COLOR3_BIT`
354
+ * @example
355
+ * ```ts
356
+ * export default defineScript({
357
+ * update(self, dt) {
358
+ * // enable target so all drawing is done to it
359
+ * render.set_render_target(self.my_render_target);
360
+ *
361
+ * // draw a predicate to the render target
362
+ * render.draw(self.my_pred);
363
+ *
364
+ * // disable target
365
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
366
+ *
367
+ * render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);
368
+ * // draw a predicate with the render target available as texture 0 in the predicate
369
+ * // material shader.
370
+ * render.draw(self.my_pred);
371
+ * },
372
+ * });
373
+ *
374
+ * // Or enable a render target by resource id:
375
+ * export default defineScript({
376
+ * update(self, dt) {
377
+ * render.set_render_target("my_rt_resource");
378
+ * render.draw(self.my_pred);
379
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
380
+ *
381
+ * render.enable_texture(0, "my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
382
+ * // draw a predicate with the render target available as texture 0 in the predicate
383
+ * // material shader.
384
+ * render.draw(self.my_pred);
385
+ * },
386
+ * });
387
+ *
388
+ * // Or bind a texture handle directly:
389
+ * export default defineScript({
390
+ * update(self, dt) {
391
+ * // bind a texture to the texture unit 0
392
+ * render.enable_texture(0, self.my_texture_handle);
393
+ * // bind the same texture to a named sampler
394
+ * render.enable_texture("my_texture_sampler", self.my_texture_handle);
395
+ * },
396
+ * });
397
+ * ```
398
+ */
399
+ function enable_texture(binding: number | string | Hash, handle_or_name: Opaque<"texture"> | string | Hash, buffer_type?: number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR1_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR2_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR3_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }): void;
400
+ /**
401
+ * Returns the logical window height that is set in the "game.project" settings.
402
+ * Note that the actual window pixel size can change, either by device constraints
403
+ * or user input.
404
+ *
405
+ * @returns specified window height
406
+ * @example
407
+ * ```ts
408
+ * // Get the height of the window
409
+ * const h = render.get_height();
410
+ * ```
411
+ */
412
+ function get_height(): number;
413
+ /**
414
+ * Returns the specified buffer height from a render target.
415
+ *
416
+ * @param render_target - render target from which to retrieve the buffer height
417
+ * @param buffer_type - which type of buffer to retrieve the height from
418
+ *
419
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
420
+ *
421
+ * - `graphics.BUFFER_TYPE_DEPTH_BIT`
422
+ *
423
+ * - `graphics.BUFFER_TYPE_STENCIL_BIT`
424
+ * @returns the height of the render target buffer texture
425
+ * @example
426
+ * ```ts
427
+ * // get the height of the render target color buffer
428
+ * const h = render.get_render_target_height(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);
429
+ * // get the height of a render target resource
430
+ * const w = render.get_render_target_height("my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
431
+ * ```
432
+ */
433
+ function get_render_target_height(render_target: Opaque<"render_target">, buffer_type: number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR1_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR2_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR3_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }): number;
434
+ /**
435
+ * Returns the specified buffer width from a render target.
436
+ *
437
+ * @param render_target - render target from which to retrieve the buffer width
438
+ * @param buffer_type - which type of buffer to retrieve the width from
439
+ *
440
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
441
+ *
442
+ * - `graphics.BUFFER_TYPE_COLOR[x]_BIT` (x: [0..3], if supported!)
443
+ *
444
+ * - `graphics.BUFFER_TYPE_DEPTH_BIT`
445
+ *
446
+ * - `graphics.BUFFER_TYPE_STENCIL_BIT`
447
+ * @returns the width of the render target buffer texture
448
+ * @example
449
+ * ```ts
450
+ * // get the width of the render target color buffer
451
+ * const w = render.get_render_target_width(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);
452
+ * // get the width of a render target resource
453
+ * const w2 = render.get_render_target_width("my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
454
+ * ```
455
+ */
456
+ function get_render_target_width(render_target: Opaque<"render_target">, buffer_type: number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR1_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR2_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR3_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }): number;
457
+ /**
458
+ * Returns the logical window width that is set in the "game.project" settings.
459
+ * Note that the actual window pixel size can change, either by device constraints
460
+ * or user input.
461
+ *
462
+ * @returns specified window width (number)
463
+ * @example
464
+ * ```ts
465
+ * // Get the width of the window.
466
+ * const w = render.get_width();
467
+ * ```
468
+ */
469
+ function get_width(): number;
470
+ /**
471
+ * Returns the actual physical window height.
472
+ * Note that this value might differ from the logical height that is set in the
473
+ * "game.project" settings.
474
+ *
475
+ * @returns actual window height
476
+ * @example
477
+ * ```ts
478
+ * // Get the actual height of the window
479
+ * const h = render.get_window_height();
480
+ * ```
481
+ */
482
+ function get_window_height(): number;
483
+ /**
484
+ * Returns the actual physical window width.
485
+ * Note that this value might differ from the logical width that is set in the
486
+ * "game.project" settings.
487
+ *
488
+ * @returns actual window width
489
+ * @example
490
+ * ```ts
491
+ * // Get the actual width of the window
492
+ * const w = render.get_window_width();
493
+ * ```
494
+ */
495
+ function get_window_width(): number;
496
+ /**
497
+ * This function returns a new render predicate for objects with materials matching
498
+ * the provided material tags. The provided tags are combined into a bit mask
499
+ * for the predicate. If multiple tags are provided, the predicate matches materials
500
+ * with all tags ANDed together.
501
+ * The current limit to the number of tags that can be defined is `64`.
502
+ *
503
+ * @param tags - table of tags that the predicate should match. The tags can be of either hash or string type
504
+ * @returns new predicate
505
+ * @example
506
+ * ```ts
507
+ * // Create a new render predicate containing all visual objects that
508
+ * // have a material with material tags "opaque" AND "smoke".
509
+ * const p = render.predicate([hash("opaque"), hash("smoke")]);
510
+ * ```
511
+ */
512
+ function predicate(tags: (string | Hash)[]): number;
513
+ /**
514
+ * Creates a new render target according to the supplied
515
+ * specification table.
516
+ * The table should contain keys specifying which buffers should be created
517
+ * with what parameters. Each buffer key should have a table value consisting
518
+ * of parameters. The following parameter keys are available:
519
+ *
520
+ * Key
521
+ * Values
522
+ *
523
+ * `format`
524
+ * `graphics.TEXTURE_FORMAT_LUMINANCE`
525
+ * `graphics.TEXTURE_FORMAT_RGB`
526
+ * `graphics.TEXTURE_FORMAT_RGBA`
527
+ * `graphics.TEXTURE_FORMAT_DEPTH`
528
+ * `graphics.TEXTURE_FORMAT_STENCIL`
529
+ * `graphics.TEXTURE_FORMAT_RGBA32F`
530
+ * `graphics.TEXTURE_FORMAT_RGBA16F`
531
+ *
532
+ * `width`
533
+ * number
534
+ *
535
+ * `height`
536
+ * number
537
+ *
538
+ * `min_filter` (optional)
539
+ * `graphics.TEXTURE_FILTER_LINEAR`
540
+ * `graphics.TEXTURE_FILTER_NEAREST`
541
+ *
542
+ * `mag_filter` (optional)
543
+ * `graphics.TEXTURE_FILTER_LINEAR`
544
+ * `graphics.TEXTURE_FILTER_NEAREST`
545
+ *
546
+ * `u_wrap` (optional)
547
+ * `graphics.TEXTURE_WRAP_CLAMP_TO_BORDER`
548
+ * `graphics.TEXTURE_WRAP_CLAMP_TO_EDGE`
549
+ * `graphics.TEXTURE_WRAP_MIRRORED_REPEAT`
550
+ * `graphics.TEXTURE_WRAP_REPEAT`
551
+ *
552
+ * `v_wrap` (optional)
553
+ * `graphics.TEXTURE_WRAP_CLAMP_TO_BORDER`
554
+ * `graphics.TEXTURE_WRAP_CLAMP_TO_EDGE`
555
+ * `graphics.TEXTURE_WRAP_MIRRORED_REPEAT`
556
+ * `graphics.TEXTURE_WRAP_REPEAT`
557
+ *
558
+ * `flags` (optional)
559
+ * `render.TEXTURE_BIT` (only applicable to depth and stencil buffers)
560
+ *
561
+ * The render target can be created to support multiple color attachments. Each attachment can have different format settings and texture filters,
562
+ * but attachments must be added in sequence, meaning you cannot create a render target at slot 0 and 3.
563
+ * Instead it has to be created with all four buffer types ranging from [0..3] (as denoted by graphics.BUFFER_TYPE_COLORX_BIT where 'X' is the attachment you want to create).
564
+ * It is not guaranteed that the device running the script can support creating render targets with multiple color attachments. To check if the device can support multiple attachments,
565
+ * you can check if the `render` table contains any of the `BUFFER_TYPE_COLOR1_BIT`, `BUFFER_TYPE_COLOR2_BIT` or `BUFFER_TYPE_COLOR3_BIT` constants:
566
+ *
567
+ * `function init(self)
568
+ * if graphics.BUFFER_TYPE_COLOR1_BIT == nil then
569
+ * -- this devices does not support multiple color attachments
570
+ * end
571
+ * end
572
+ * `
573
+ *
574
+ * @param name - render target name
575
+ * @param parameters - table of buffer parameters, see the description for available keys and values
576
+ * @returns new render target
577
+ * @example
578
+ * ```lua
579
+ * How to create a new render target and draw to it:
580
+ * function init(self)
581
+ * -- render target buffer parameters
582
+ * local color_params = { format = graphics.TEXTURE_FORMAT_RGBA,
583
+ * width = render.get_window_width(),
584
+ * height = render.get_window_height(),
585
+ * min_filter = graphics.TEXTURE_FILTER_LINEAR,
586
+ * mag_filter = graphics.TEXTURE_FILTER_LINEAR,
587
+ * u_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
588
+ * v_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE }
589
+ * local depth_params = { format = graphics.TEXTURE_FORMAT_DEPTH,
590
+ * width = render.get_window_width(),
591
+ * height = render.get_window_height(),
592
+ * u_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
593
+ * v_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE }
594
+ * self.my_render_target = render.render_target({[graphics.BUFFER_TYPE_COLOR0_BIT] = color_params, [graphics.BUFFER_TYPE_DEPTH_BIT] = depth_params })
595
+ * end
596
+ *
597
+ * function update(self, dt)
598
+ * -- enable target so all drawing is done to it
599
+ * render.set_render_target(self.my_render_target)
600
+ *
601
+ * -- draw a predicate to the render target
602
+ * render.draw(self.my_pred)
603
+ * end
604
+ *
605
+ * How to create a render target with multiple outputs:
606
+ * function init(self)
607
+ * -- render target buffer parameters
608
+ * local color_params_rgba = { format = graphics.TEXTURE_FORMAT_RGBA,
609
+ * width = render.get_window_width(),
610
+ * height = render.get_window_height(),
611
+ * min_filter = graphics.TEXTURE_FILTER_LINEAR,
612
+ * mag_filter = graphics.TEXTURE_FILTER_LINEAR,
613
+ * u_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
614
+ * v_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE }
615
+ * local color_params_float = { format = graphics.TEXTURE_FORMAT_RG32F,
616
+ * width = render.get_window_width(),
617
+ * height = render.get_window_height(),
618
+ * min_filter = graphics.TEXTURE_FILTER_LINEAR,
619
+ * mag_filter = graphics.TEXTURE_FILTER_LINEAR,
620
+ * u_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
621
+ * v_wrap = graphics.TEXTURE_WRAP_CLAMP_TO_EDGE }
622
+ *
623
+ * -- Create a render target with three color attachments
624
+ * -- Note: No depth buffer is attached here
625
+ * self.my_render_target = render.render_target({
626
+ * [graphics.BUFFER_TYPE_COLOR0_BIT] = color_params_rgba,
627
+ * [graphics.BUFFER_TYPE_COLOR1_BIT] = color_params_rgba,
628
+ * [graphics.BUFFER_TYPE_COLOR2_BIT] = color_params_float, })
629
+ * end
630
+ *
631
+ * function update(self, dt)
632
+ * -- enable target so all drawing is done to it
633
+ * render.enable_render_target(self.my_render_target)
634
+ *
635
+ * -- draw a predicate to the render target
636
+ * render.draw(self.my_pred)
637
+ * end
638
+ * ```
639
+ */
640
+ function render_target(name: string, parameters: Record<string | number, unknown>): Opaque<"render_target">;
641
+ /**
642
+ * Specifies the arithmetic used when computing pixel values that are written to the frame
643
+ * buffer. In RGBA mode, pixels can be drawn using a function that blends the source RGBA
644
+ * pixel values with the destination pixel values already in the frame buffer.
645
+ * Blending is initially disabled.
646
+ * `source_factor` specifies which method is used to scale the source color components.
647
+ * `destination_factor` specifies which method is used to scale the destination color
648
+ * components.
649
+ * Source color components are referred to as (Rs,Gs,Bs,As).
650
+ * Destination color components are referred to as (Rd,Gd,Bd,Ad).
651
+ * The color specified by setting the blendcolor is referred to as (Rc,Gc,Bc,Ac).
652
+ * The source scale factor is referred to as (sR,sG,sB,sA).
653
+ * The destination scale factor is referred to as (dR,dG,dB,dA).
654
+ * 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`.
655
+ * Available factor constants and corresponding scale factors:
656
+ *
657
+ * Factor constant
658
+ * Scale factor (fR,fG,fB,fA)
659
+ *
660
+ * `graphics.BLEND_FACTOR_ZERO`
661
+ * (0,0,0,0)
662
+ *
663
+ * `graphics.BLEND_FACTOR_ONE`
664
+ * (1,1,1,1)
665
+ *
666
+ * `graphics.BLEND_FACTOR_SRC_COLOR`
667
+ * (Rs/kR,Gs/kG,Bs/kB,As/kA)
668
+ *
669
+ * `graphics.BLEND_FACTOR_ONE_MINUS_SRC_COLOR`
670
+ * (1,1,1,1) - (Rs/kR,Gs/kG,Bs/kB,As/kA)
671
+ *
672
+ * `graphics.BLEND_FACTOR_DST_COLOR`
673
+ * (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
674
+ *
675
+ * `graphics.BLEND_FACTOR_ONE_MINUS_DST_COLOR`
676
+ * (1,1,1,1) - (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
677
+ *
678
+ * `graphics.BLEND_FACTOR_SRC_ALPHA`
679
+ * (As/kA,As/kA,As/kA,As/kA)
680
+ *
681
+ * `graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA`
682
+ * (1,1,1,1) - (As/kA,As/kA,As/kA,As/kA)
683
+ *
684
+ * `graphics.BLEND_FACTOR_DST_ALPHA`
685
+ * (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
686
+ *
687
+ * `graphics.BLEND_FACTOR_ONE_MINUS_DST_ALPHA`
688
+ * (1,1,1,1) - (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
689
+ *
690
+ * `graphics.BLEND_FACTOR_CONSTANT_COLOR`
691
+ * (Rc,Gc,Bc,Ac)
692
+ *
693
+ * `graphics.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR`
694
+ * (1,1,1,1) - (Rc,Gc,Bc,Ac)
695
+ *
696
+ * `graphics.BLEND_FACTOR_CONSTANT_ALPHA`
697
+ * (Ac,Ac,Ac,Ac)
698
+ *
699
+ * `graphics.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA`
700
+ * (1,1,1,1) - (Ac,Ac,Ac,Ac)
701
+ *
702
+ * `graphics.BLEND_FACTOR_SRC_ALPHA_SATURATE`
703
+ * (i,i,i,1) where i = min(As, kA - Ad) /kA
704
+ *
705
+ * The blended RGBA values of a pixel comes from the following equations:
706
+ *
707
+ * - Rd = min(kR, Rs * sR + Rd * dR)
708
+ *
709
+ * - Gd = min(kG, Gs * sG + Gd * dG)
710
+ *
711
+ * - Bd = min(kB, Bs * sB + Bd * dB)
712
+ *
713
+ * - Ad = min(kA, As * sA + Ad * dA)
714
+ *
715
+ * Blend function `(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA)` is useful for
716
+ * drawing with transparency when the drawn objects are sorted from farthest to nearest.
717
+ * It is also useful for drawing antialiased points and lines in arbitrary order.
718
+ *
719
+ * @param source_factor - source factor
720
+ * @param destination_factor - destination factor
721
+ * @example
722
+ * ```ts
723
+ * // Set the blend func to the most common one:
724
+ * render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
725
+ * ```
726
+ */
727
+ function set_blend_func(source_factor: number, destination_factor: number): void;
728
+ /**
729
+ * Sets the current render camera to be used for rendering. If a render camera
730
+ * has been set by the render script, the renderer will be using its projection and view matrix
731
+ * during rendering. If a projection and/or view matrix has been set by the render script,
732
+ * they will not be used until the current render camera has been reset by calling `render.set_camera()`.
733
+ * If the 'use_frustum' flag in the options table has been set to true, the renderer will automatically use the
734
+ * camera frustum for frustum culling regardless of what frustum is being passed into the render.draw() function.
735
+ * Note that the frustum plane option in render.draw can still be used together with the camera.
736
+ *
737
+ * @param camera - camera id to use, or nil to reset
738
+ * @param options - optional table with properties:
739
+ *
740
+ * `use_frustum`
741
+ * boolean If true, the renderer will use the cameras view-projection matrix for frustum culling (default: false)
742
+ * @example
743
+ * ```ts
744
+ * // Set the current camera to be used for rendering
745
+ * render.set_camera("main:/my_go#camera");
746
+ * render.draw(self.my_pred);
747
+ * render.set_camera(undefined);
748
+ *
749
+ * // Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command
750
+ * // The camera frustum will take precedence over the frustum plane option in render.draw
751
+ * render.set_camera("main:/my_go#camera", { use_frustum: true });
752
+ * // However, we can still customize the frustum planes regardless of the camera option!
753
+ * render.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });
754
+ * render.set_camera();
755
+ * ```
756
+ */
757
+ function set_camera(camera?: Url | number, options?: { use_frustum?: boolean }): void;
758
+ /**
759
+ * 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.
760
+ * The component masks are all initially `true`.
761
+ *
762
+ * @param red - red mask
763
+ * @param green - green mask
764
+ * @param blue - blue mask
765
+ * @param alpha - alpha mask
766
+ * @example
767
+ * ```ts
768
+ * // alpha cannot be written to frame buffer
769
+ * render.set_color_mask(true, true, true, false);
770
+ * ```
771
+ */
772
+ function set_color_mask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void;
773
+ /**
774
+ * The name of the compute program must be specified in the ".render" resource set
775
+ * in the "game.project" setting. If nil (or no arguments) are passed to this function,
776
+ * the current compute program will instead be disabled.
777
+ *
778
+ * @param compute - compute id to use, or nil to disable
779
+ * @example
780
+ * ```ts
781
+ * // Enable compute program named "fractals", then dispatch it.
782
+ * render.set_compute("fractals");
783
+ * render.enable_texture(0, self.backing_texture);
784
+ * render.dispatch_compute(128, 128, 1);
785
+ * render.set_compute();
786
+ * ```
787
+ */
788
+ function set_compute(compute?: string | Hash): void;
789
+ /**
790
+ * Specifies whether front- or back-facing polygons can be culled
791
+ * when polygon culling is enabled. Polygon culling is initially disabled.
792
+ * If mode is `graphics.FACE_TYPE_FRONT_AND_BACK`, no polygons are drawn, but other
793
+ * primitives such as points and lines are drawn. The initial value for
794
+ * `face_type` is `graphics.FACE_TYPE_BACK`.
795
+ *
796
+ * @param face_type - face type
797
+ *
798
+ * - `graphics.FACE_TYPE_FRONT`
799
+ *
800
+ * - `graphics.FACE_TYPE_BACK`
801
+ *
802
+ * - `graphics.FACE_TYPE_FRONT_AND_BACK`
803
+ * @example
804
+ * ```ts
805
+ * // How to enable polygon culling and set front face culling:
806
+ * render.enable_state(graphics.STATE_CULL_FACE);
807
+ * render.set_cull_face(graphics.FACE_TYPE_FRONT);
808
+ * ```
809
+ */
810
+ function set_cull_face(face_type: number): void;
811
+ /**
812
+ * Specifies the function that should be used to compare each incoming pixel
813
+ * depth value with the value present in the depth buffer.
814
+ * The comparison is performed only if depth testing is enabled and specifies
815
+ * the conditions under which a pixel will be drawn.
816
+ * Function constants:
817
+ *
818
+ * - `graphics.COMPARE_FUNC_NEVER` (never passes)
819
+ *
820
+ * - `graphics.COMPARE_FUNC_LESS` (passes if the incoming depth value is less than the stored value)
821
+ *
822
+ * - `graphics.COMPARE_FUNC_LEQUAL` (passes if the incoming depth value is less than or equal to the stored value)
823
+ *
824
+ * - `graphics.COMPARE_FUNC_GREATER` (passes if the incoming depth value is greater than the stored value)
825
+ *
826
+ * - `graphics.COMPARE_FUNC_GEQUAL` (passes if the incoming depth value is greater than or equal to the stored value)
827
+ *
828
+ * - `graphics.COMPARE_FUNC_EQUAL` (passes if the incoming depth value is equal to the stored value)
829
+ *
830
+ * - `graphics.COMPARE_FUNC_NOTEQUAL` (passes if the incoming depth value is not equal to the stored value)
831
+ *
832
+ * - `graphics.COMPARE_FUNC_ALWAYS` (always passes)
833
+ *
834
+ * The depth function is initially set to `graphics.COMPARE_FUNC_LESS`.
835
+ *
836
+ * @param func - depth test function, see the description for available values
837
+ * @example
838
+ * ```ts
839
+ * // Enable depth test and set the depth test function to "not equal".
840
+ * render.enable_state(graphics.STATE_DEPTH_TEST);
841
+ * render.set_depth_func(graphics.COMPARE_FUNC_NOTEQUAL);
842
+ * ```
843
+ */
844
+ function set_depth_func(func: number): void;
845
+ /**
846
+ * Specifies whether the depth buffer is enabled for writing. The supplied mask governs
847
+ * if depth buffer writing is enabled (`true`) or disabled (`false`).
848
+ * The mask is initially `true`.
849
+ *
850
+ * @param depth - depth mask
851
+ * @example
852
+ * ```ts
853
+ * // How to turn off writing to the depth buffer:
854
+ * render.set_depth_mask(false);
855
+ * ```
856
+ */
857
+ function set_depth_mask(depth: boolean): void;
858
+ /**
859
+ * Set or remove listener. Currenly only only two type of events can arrived:
860
+ * `render.CONTEXT_EVENT_CONTEXT_LOST` - when rendering context lost. Rending paused and all graphics resources become invalid.
861
+ * `render.CONTEXT_EVENT_CONTEXT_RESTORED` - when rendering context was restored. Rendering still paused and graphics resources still
862
+ * invalid but can be reloaded.
863
+ *
864
+ * @param callback - A callback that receives all render related events.
865
+ * Pass `nil` if want to remove listener.
866
+ *
867
+ * `self`
868
+ * object The render script
869
+ * `event_type`
870
+ * string Rendering event. Possible values: `render.CONTEXT_EVENT_CONTEXT_LOST`, `render.CONTEXT_EVENT_CONTEXT_RESTORED`
871
+ * @example
872
+ * ```ts
873
+ * // Set listener and handle render context events.
874
+ * // custom.render_script
875
+ * export default defineScript({
876
+ * init() {
877
+ * render.set_listener((self, event_type) => {
878
+ * if (event_type === render.CONTEXT_EVENT_CONTEXT_LOST) {
879
+ * // Some stuff when rendering context is lost
880
+ * } else if (event_type === render.CONTEXT_EVENT_CONTEXT_RESTORED) {
881
+ * // Start reload resources, reload game, etc.
882
+ * }
883
+ * });
884
+ * },
885
+ * });
886
+ * ```
887
+ */
888
+ function set_listener(callback?: (self: unknown, event_type: unknown) => void): void;
889
+ /**
890
+ * Sets the scale and units used to calculate depth values.
891
+ * If `graphics.STATE_POLYGON_OFFSET_FILL` is enabled, each fragment's depth value
892
+ * is offset from its interpolated value (depending on the depth value of the
893
+ * appropriate vertices). Polygon offset can be used when drawing decals, rendering
894
+ * hidden-line images etc.
895
+ * `factor` specifies a scale factor that is used to create a variable depth
896
+ * offset for each polygon. The initial value is `0`.
897
+ * `units` is multiplied by an implementation-specific value to create a
898
+ * constant depth offset. The initial value is `0`.
899
+ * The value of the offset is computed as `factor` &times; `DZ` + `r` &times; `units`
900
+ * `DZ` is a measurement of the depth slope of the polygon which is the change in z (depth)
901
+ * values divided by the change in either x or y coordinates, as you traverse a polygon.
902
+ * The depth values are in window coordinates, clamped to the range [0, 1].
903
+ * `r` is the smallest value that is guaranteed to produce a resolvable difference.
904
+ * It's value is an implementation-specific constant.
905
+ * The offset is added before the depth test is performed and before the
906
+ * value is written into the depth buffer.
907
+ *
908
+ * @param factor - polygon offset factor
909
+ * @param units - polygon offset units
910
+ * @example
911
+ * ```ts
912
+ * render.enable_state(graphics.STATE_POLYGON_OFFSET_FILL);
913
+ * render.set_polygon_offset(1.0, 1.0);
914
+ * ```
915
+ */
916
+ function set_polygon_offset(factor: number, units: number): void;
917
+ /**
918
+ * Sets the projection matrix to use when rendering.
919
+ *
920
+ * @param matrix - projection matrix
921
+ * @example
922
+ * ```ts
923
+ * // How to set the projection to orthographic with world origo at lower left,
924
+ * // width and height as set in project settings and depth (z) between -1 and 1:
925
+ * render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1));
926
+ * ```
927
+ */
928
+ function set_projection(matrix: Matrix4): void;
929
+ /**
930
+ * Sets a render target. Subsequent draw operations will be to the
931
+ * render target until it is replaced by a subsequent call to set_render_target.
932
+ * This function supports render targets created by a render script, or a render target resource.
933
+ *
934
+ * @param render_target - render target to set. render.RENDER_TARGET_DEFAULT to set the default render target
935
+ * @param options - optional table with behaviour parameters
936
+ *
937
+ * `transient`
938
+ * 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.
939
+ * 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!
940
+ * A buffer type defined that doesn't exist in the render target is silently ignored.
941
+ *
942
+ * - `graphics.BUFFER_TYPE_COLOR0_BIT`
943
+ *
944
+ * - `graphics.BUFFER_TYPE_DEPTH_BIT`
945
+ *
946
+ * - `graphics.BUFFER_TYPE_STENCIL_BIT`
947
+ * @example
948
+ * ```ts
949
+ * // How to set a render target and draw to it and then switch back to the default render target
950
+ * // 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
951
+ * export default defineScript({
952
+ * update(self, dt) {
953
+ * // set render target so all drawing is done to it
954
+ * render.set_render_target(self.my_render_target, {
955
+ * transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],
956
+ * });
957
+ *
958
+ * // draw a predicate to the render target
959
+ * render.draw(self.my_pred);
960
+ *
961
+ * // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)
962
+ * // which can be an optimisation on some hardware
963
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
964
+ * },
965
+ * });
966
+ *
967
+ * // Or set the render target by a render target resource identifier:
968
+ * export default defineScript({
969
+ * update(self, dt) {
970
+ * render.set_render_target("my_rt_resource");
971
+ *
972
+ * // draw a predicate to the render target
973
+ * render.draw(self.my_pred);
974
+ *
975
+ * // reset the render target to the default backbuffer
976
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
977
+ * },
978
+ * });
979
+ * ```
980
+ */
981
+ function set_render_target(render_target: Opaque<"render_target">, options?: { transient?: Record<string | number, unknown> }): void;
982
+ /**
983
+ * Sets the render target size for a render target created from
984
+ * either a render script, or from a render target resource.
985
+ *
986
+ * @param render_target - render target to set size for
987
+ * @param width - new render target width
988
+ * @param height - new render target height
989
+ * @example
990
+ * ```ts
991
+ * // Resize render targets to the current window size:
992
+ * render.set_render_target_size(self.my_render_target, render.get_window_width(), render.get_window_height());
993
+ * render.set_render_target_size("my_rt_resource", render.get_window_width(), render.get_window_height());
994
+ * ```
995
+ */
996
+ function set_render_target_size(render_target: Opaque<"render_target">, width: number, height: number): void;
997
+ /**
998
+ * Stenciling is similar to depth-buffering as it enables and disables drawing on a
999
+ * per-pixel basis. First, GL drawing primitives are drawn into the stencil planes.
1000
+ * Second, geometry and images are rendered but using the stencil planes to mask out
1001
+ * where to draw.
1002
+ * The stencil test discards a pixel based on the outcome of a comparison between the
1003
+ * reference value `ref` and the corresponding value in the stencil buffer.
1004
+ * `func` specifies the comparison function. See the table below for values.
1005
+ * The initial value is `graphics.COMPARE_FUNC_ALWAYS`.
1006
+ * `ref` specifies the reference value for the stencil test. The value is clamped to
1007
+ * the range [0, 2n-1], where n is the number of bitplanes in the stencil buffer.
1008
+ * The initial value is `0`.
1009
+ * `mask` is ANDed with both the reference value and the stored stencil value when the test
1010
+ * is done. The initial value is all `1`'s.
1011
+ * Function constant:
1012
+ *
1013
+ * - `graphics.COMPARE_FUNC_NEVER` (never passes)
1014
+ *
1015
+ * - `graphics.COMPARE_FUNC_LESS` (passes if (ref & mask) < (stencil & mask))
1016
+ *
1017
+ * - `graphics.COMPARE_FUNC_LEQUAL` (passes if (ref & mask) <= (stencil & mask))
1018
+ *
1019
+ * - `graphics.COMPARE_FUNC_GREATER` (passes if (ref & mask) > (stencil & mask))
1020
+ *
1021
+ * - `graphics.COMPARE_FUNC_GEQUAL` (passes if (ref & mask) >= (stencil & mask))
1022
+ *
1023
+ * - `graphics.COMPARE_FUNC_EQUAL` (passes if (ref & mask) = (stencil & mask))
1024
+ *
1025
+ * - `graphics.COMPARE_FUNC_NOTEQUAL` (passes if (ref & mask) != (stencil & mask))
1026
+ *
1027
+ * - `graphics.COMPARE_FUNC_ALWAYS` (always passes)
1028
+ *
1029
+ * @param func - stencil test function, see the description for available values
1030
+ * @param ref - reference value for the stencil test
1031
+ * @param mask - mask that is ANDed with both the reference value and the stored stencil value when the test is done
1032
+ * @example
1033
+ * ```ts
1034
+ * // let only 0's pass the stencil test
1035
+ * render.set_stencil_func(graphics.COMPARE_FUNC_EQUAL, 0, 1);
1036
+ * ```
1037
+ */
1038
+ function set_stencil_func(func: number, ref: number, mask: number): void;
1039
+ /**
1040
+ * The stencil mask controls the writing of individual bits in the stencil buffer.
1041
+ * The least significant `n` bits of the parameter `mask`, where `n` is the number of
1042
+ * bits in the stencil buffer, specify the mask.
1043
+ * Where a `1` bit appears in the mask, the corresponding
1044
+ * bit in the stencil buffer can be written. Where a `0` bit appears in the mask,
1045
+ * the corresponding bit in the stencil buffer is never written.
1046
+ * The mask is initially all `1`'s.
1047
+ *
1048
+ * @param mask - stencil mask
1049
+ * @example
1050
+ * ```ts
1051
+ * // set the stencil mask to all 1:s
1052
+ * render.set_stencil_mask(0xff);
1053
+ * ```
1054
+ */
1055
+ function set_stencil_mask(mask: number): void;
1056
+ /**
1057
+ * The stencil test discards a pixel based on the outcome of a comparison between the
1058
+ * reference value `ref` and the corresponding value in the stencil buffer.
1059
+ * To control the test, call render.set_stencil_func.
1060
+ * This function takes three arguments that control what happens to the stored stencil
1061
+ * value while stenciling is enabled. If the stencil test fails, no change is made to the
1062
+ * pixel's color or depth buffers, and `sfail` specifies what happens to the stencil buffer
1063
+ * contents.
1064
+ * Operator constants:
1065
+ *
1066
+ * - `graphics.STENCIL_OP_KEEP` (keeps the current value)
1067
+ *
1068
+ * - `graphics.STENCIL_OP_ZERO` (sets the stencil buffer value to 0)
1069
+ *
1070
+ * - `graphics.STENCIL_OP_REPLACE` (sets the stencil buffer value to `ref`, as specified by render.set_stencil_func)
1071
+ *
1072
+ * - `graphics.STENCIL_OP_INCR` (increments the stencil buffer value and clamp to the maximum representable unsigned value)
1073
+ *
1074
+ * - `graphics.STENCIL_OP_INCR_WRAP` (increments the stencil buffer value and wrap to zero when incrementing the maximum representable unsigned value)
1075
+ *
1076
+ * - `graphics.STENCIL_OP_DECR` (decrements the current stencil buffer value and clamp to 0)
1077
+ *
1078
+ * - `graphics.STENCIL_OP_DECR_WRAP` (decrements the current stencil buffer value and wrap to the maximum representable unsigned value when decrementing zero)
1079
+ *
1080
+ * - `graphics.STENCIL_OP_INVERT` (bitwise inverts the current stencil buffer value)
1081
+ *
1082
+ * `dppass` and `dpfail` specify the stencil buffer actions depending on whether subsequent
1083
+ * depth buffer tests succeed (dppass) or fail (dpfail).
1084
+ * The initial value for all operators is `graphics.STENCIL_OP_KEEP`.
1085
+ *
1086
+ * @param sfail - action to take when the stencil test fails
1087
+ * @param dpfail - the stencil action when the stencil test passes
1088
+ * @param dppass - the stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled
1089
+ * @example
1090
+ * ```ts
1091
+ * // Set the stencil function to never pass and operator to always draw 1's
1092
+ * // on test fail.
1093
+ * render.set_stencil_func(graphics.COMPARE_FUNC_NEVER, 1, 0xFF);
1094
+ * // always draw 1's on test fail
1095
+ * render.set_stencil_op(graphics.STENCIL_OP_REPLACE, graphics.STENCIL_OP_KEEP, graphics.STENCIL_OP_KEEP);
1096
+ * ```
1097
+ */
1098
+ function set_stencil_op(sfail: number, dpfail: number, dppass: number): void;
1099
+ /**
1100
+ * Sets the view matrix to use when rendering.
1101
+ *
1102
+ * @param matrix - view matrix to set
1103
+ * @example
1104
+ * ```ts
1105
+ * // How to set the view and projection matrices according to
1106
+ * // the values supplied by a camera.
1107
+ * export default defineScript({
1108
+ * init() {
1109
+ * return {
1110
+ * view: vmath.matrix4(),
1111
+ * projection: vmath.matrix4(),
1112
+ * };
1113
+ * },
1114
+ *
1115
+ * update(self, dt) {
1116
+ * // set the view to the stored view value
1117
+ * render.set_view(self.view);
1118
+ * // now we can draw with this view
1119
+ * },
1120
+ *
1121
+ * on_message(self, message_id, message) {
1122
+ * if (message_id === hash("set_view_projection")) {
1123
+ * // camera view and projection arrives here.
1124
+ * self.view = message.view;
1125
+ * self.projection = message.projection;
1126
+ * }
1127
+ * },
1128
+ * });
1129
+ * ```
1130
+ */
1131
+ function set_view(matrix: Matrix4): void;
1132
+ /**
1133
+ * Set the render viewport to the specified rectangle.
1134
+ *
1135
+ * @param x - left corner
1136
+ * @param y - bottom corner
1137
+ * @param width - viewport width
1138
+ * @param height - viewport height
1139
+ * @example
1140
+ * ```ts
1141
+ * // Set the viewport to the window dimensions.
1142
+ * render.set_viewport(0, 0, render.get_window_width(), render.get_window_height());
1143
+ * ```
1144
+ */
1145
+ function set_viewport(x: number, y: number, width: number, height: number): void;
1146
+ }
1147
+ }
1148
+
1149
+ export {};