@defold-typescript/types 0.5.4 → 0.6.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.
- package/api-targets.json +1 -1
- package/generated/b2d.d.ts +3 -0
- package/generated/buffer.d.ts +44 -38
- package/generated/builtin-messages.d.ts +1 -1
- package/generated/camera.d.ts +3 -0
- package/generated/collectionfactory.d.ts +47 -40
- package/generated/collectionproxy.d.ts +23 -18
- package/generated/crash.d.ts +3 -0
- package/generated/factory.d.ts +32 -24
- package/generated/go.d.ts +293 -293
- package/generated/graphics.d.ts +3 -0
- package/generated/gui.d.ts +303 -283
- package/generated/http.d.ts +26 -16
- package/generated/iac.d.ts +3 -0
- package/generated/iap.d.ts +6 -3
- package/generated/image.d.ts +30 -26
- package/generated/json.d.ts +36 -32
- package/generated/kinds/gui-script.d.ts +7 -5
- package/generated/kinds/render-script.d.ts +7 -5
- package/generated/kinds/script.d.ts +7 -5
- package/generated/label.d.ts +16 -9
- package/generated/liveupdate.d.ts +29 -26
- package/generated/model.d.ts +57 -45
- package/generated/msg.d.ts +12 -9
- package/generated/particlefx.d.ts +50 -34
- package/generated/physics.d.ts +153 -133
- package/generated/profiler.d.ts +45 -41
- package/generated/push.d.ts +5 -2
- package/generated/render.d.ts +410 -349
- package/generated/resource.d.ts +619 -572
- package/generated/socket.d.ts +49 -33
- package/generated/sound.d.ts +83 -72
- package/generated/sprite.d.ts +36 -32
- package/generated/sys.d.ts +198 -189
- package/generated/tilemap.d.ts +43 -39
- package/generated/timer.d.ts +42 -36
- package/generated/vmath.d.ts +254 -229
- package/generated/webview.d.ts +3 -0
- package/generated/window.d.ts +23 -17
- package/generated/zlib.d.ts +15 -12
- package/index.d.ts +3 -1
- package/package.json +6 -2
- package/scripts/example-store-io.ts +18 -0
- package/scripts/fidelity-audit.ts +61 -1
- package/scripts/fidelity-baseline.json +10 -10
- package/scripts/ref-doc-delta.ts +143 -0
- package/scripts/regen.ts +23 -10
- package/src/core-types.ts +14 -0
- package/src/doc-comment.ts +2 -1
- package/src/emit-dts.ts +238 -18
- package/src/engine-globals.d.ts +2 -0
- package/src/example-store.ts +44 -0
- package/src/go-overloads.d.ts +73 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +157 -16
- package/src/message-dispatch.d.ts +21 -0
- package/src/message-guard.d.ts +19 -0
- package/src/msg-overloads.d.ts +20 -0
- package/src/publish-dts.ts +1 -1
package/generated/render.d.ts
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
import type { Hash, Matrix4, Opaque, Url } from "../src/core-types";
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Rendering functions, messages and constants. The "render" namespace is
|
|
7
|
+
* accessible only from render scripts.
|
|
8
|
+
* The rendering API was originally built on top of OpenGL ES 2.0, and it uses a subset of the
|
|
9
|
+
* OpenGL computer graphics rendering API for rendering 2D and 3D computer
|
|
10
|
+
* graphics. Our current target is OpenGLES 3.0 with fallbacks to 2.0 on some platforms.
|
|
11
|
+
* [icon:attention] It is possible to create materials and write shaders that
|
|
12
|
+
* require features not in OpenGL ES 2.0, but those will not work cross platform.
|
|
13
|
+
*/
|
|
5
14
|
namespace render {
|
|
6
15
|
type constant_buffer = Opaque<"constant_buffer">;
|
|
7
16
|
type render_target = Opaque<"render_target">;
|
|
@@ -30,9 +39,12 @@ declare global {
|
|
|
30
39
|
* - `graphics.BUFFER_TYPE_DEPTH_BIT`
|
|
31
40
|
* - `graphics.BUFFER_TYPE_STENCIL_BIT`
|
|
32
41
|
* @example
|
|
33
|
-
* ```
|
|
34
|
-
* Clear the color buffer and the depth buffer.
|
|
35
|
-
* render.clear({
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Clear the color buffer and the depth buffer.
|
|
44
|
+
* render.clear({
|
|
45
|
+
* [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),
|
|
46
|
+
* [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,
|
|
47
|
+
* });
|
|
36
48
|
* ```
|
|
37
49
|
*/
|
|
38
50
|
function clear(buffers: Record<string | number, unknown>): void;
|
|
@@ -42,31 +54,31 @@ declare global {
|
|
|
42
54
|
*
|
|
43
55
|
* @returns new constant buffer
|
|
44
56
|
* @example
|
|
45
|
-
* ```
|
|
46
|
-
* Set a "tint" constant in a constant buffer in the render script:
|
|
47
|
-
*
|
|
48
|
-
* constants.tint = vmath.vector4(1, 1, 1, 1)
|
|
49
|
-
*
|
|
50
|
-
* Then use the constant buffer when drawing a predicate:
|
|
51
|
-
* render.draw(self.my_pred, {constants
|
|
52
|
-
*
|
|
53
|
-
* The constant buffer also supports array values by specifying constants in
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* You can also create the
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Set a "tint" constant in a constant buffer in the render script:
|
|
59
|
+
* const constants = render.constant_buffer();
|
|
60
|
+
* constants.tint = vmath.vector4(1, 1, 1, 1);
|
|
61
|
+
*
|
|
62
|
+
* // Then use the constant buffer when drawing a predicate:
|
|
63
|
+
* render.draw(self.my_pred, { constants });
|
|
64
|
+
*
|
|
65
|
+
* // The constant buffer also supports array values by specifying constants in an array:
|
|
66
|
+
* const constants2 = render.constant_buffer();
|
|
67
|
+
* constants2.light_colors = [];
|
|
68
|
+
* constants2.light_colors[0] = vmath.vector4(1, 0, 0, 1);
|
|
69
|
+
* constants2.light_colors[1] = vmath.vector4(0, 1, 0, 1);
|
|
70
|
+
* constants2.light_colors[2] = vmath.vector4(0, 0, 1, 1);
|
|
71
|
+
*
|
|
72
|
+
* // You can also create the array by passing the vectors directly:
|
|
73
|
+
* const constants3 = render.constant_buffer();
|
|
74
|
+
* constants3.light_colors = [
|
|
75
|
+
* vmath.vector4(1, 0, 0, 1),
|
|
76
|
+
* vmath.vector4(0, 1, 0, 1),
|
|
77
|
+
* vmath.vector4(0, 0, 1, 1),
|
|
78
|
+
* ];
|
|
79
|
+
*
|
|
80
|
+
* // Add more constants to the array
|
|
81
|
+
* constants3.light_colors[3] = vmath.vector4(1, 1, 1, 1);
|
|
70
82
|
* ```
|
|
71
83
|
*/
|
|
72
84
|
function constant_buffer(): Opaque<"constant_buffer">;
|
|
@@ -76,9 +88,9 @@ declare global {
|
|
|
76
88
|
*
|
|
77
89
|
* @param render_target - render target to delete
|
|
78
90
|
* @example
|
|
79
|
-
* ```
|
|
80
|
-
* How to delete a render target:
|
|
81
|
-
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* // How to delete a render target:
|
|
93
|
+
* render.delete_render_target(self.my_render_target);
|
|
82
94
|
* ```
|
|
83
95
|
*/
|
|
84
96
|
function delete_render_target(render_target: Opaque<"render_target">): void;
|
|
@@ -88,11 +100,11 @@ declare global {
|
|
|
88
100
|
* in the "game.project" setting.
|
|
89
101
|
*
|
|
90
102
|
* @example
|
|
91
|
-
* ```
|
|
92
|
-
* Enable material named "glow", then draw my_pred with it.
|
|
93
|
-
* render.enable_material("glow")
|
|
94
|
-
* render.draw(self.my_pred)
|
|
95
|
-
* render.disable_material()
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Enable material named "glow", then draw my_pred with it.
|
|
105
|
+
* render.enable_material("glow");
|
|
106
|
+
* render.draw(self.my_pred);
|
|
107
|
+
* render.disable_material();
|
|
96
108
|
* ```
|
|
97
109
|
*/
|
|
98
110
|
function disable_material(): void;
|
|
@@ -107,10 +119,10 @@ declare global {
|
|
|
107
119
|
* - `graphics.STATE_CULL_FACE`
|
|
108
120
|
* - `graphics.STATE_POLYGON_OFFSET_FILL`
|
|
109
121
|
* @example
|
|
110
|
-
* ```
|
|
111
|
-
* Disable face culling when drawing the tile predicate:
|
|
112
|
-
* render.disable_state(graphics.STATE_CULL_FACE)
|
|
113
|
-
* render.draw(self.tile_pred)
|
|
122
|
+
* ```ts
|
|
123
|
+
* // Disable face culling when drawing the tile predicate:
|
|
124
|
+
* render.disable_state(graphics.STATE_CULL_FACE);
|
|
125
|
+
* render.draw(self.tile_pred);
|
|
114
126
|
* ```
|
|
115
127
|
*/
|
|
116
128
|
function disable_state(state: Opaque<"constant">): void;
|
|
@@ -119,15 +131,17 @@ declare global {
|
|
|
119
131
|
*
|
|
120
132
|
* @param binding - texture binding, either by texture unit, string or hash that should be disabled
|
|
121
133
|
* @example
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* export default defineScript({
|
|
136
|
+
* update(self, dt) {
|
|
137
|
+
* render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
138
|
+
* // draw a predicate with the render target available as texture 0 in the predicate
|
|
139
|
+
* // material shader.
|
|
140
|
+
* render.draw(self.my_pred);
|
|
141
|
+
* // done, disable the texture
|
|
142
|
+
* render.disable_texture(0);
|
|
143
|
+
* },
|
|
144
|
+
* });
|
|
131
145
|
* ```
|
|
132
146
|
*/
|
|
133
147
|
function disable_texture(binding: Opaque<"texture"> | string | Hash): void;
|
|
@@ -145,26 +159,32 @@ declare global {
|
|
|
145
159
|
* `constants`
|
|
146
160
|
* constant_buffer optional constants to use while rendering
|
|
147
161
|
* @example
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* export default defineScript({
|
|
164
|
+
* init() {
|
|
165
|
+
* const color_params = {
|
|
166
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
167
|
+
* width: render.get_window_width(),
|
|
168
|
+
* height: render.get_window_height(),
|
|
169
|
+
* };
|
|
170
|
+
* return {
|
|
171
|
+
* scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
|
|
172
|
+
* };
|
|
173
|
+
* },
|
|
174
|
+
*
|
|
175
|
+
* update(self, dt) {
|
|
176
|
+
* render.set_compute("bloom");
|
|
177
|
+
* render.enable_texture(0, self.backing_texture);
|
|
178
|
+
* render.enable_texture(1, self.scene_rt);
|
|
179
|
+
* render.dispatch_compute(128, 128, 1);
|
|
180
|
+
* render.set_compute();
|
|
181
|
+
* },
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* // Dispatch a compute program with a constant buffer:
|
|
185
|
+
* const constants = render.constant_buffer();
|
|
186
|
+
* constants.tint = vmath.vector4(1, 1, 1, 1);
|
|
187
|
+
* render.dispatch_compute(32, 32, 32, { constants });
|
|
168
188
|
* ```
|
|
169
189
|
*/
|
|
170
190
|
function dispatch_compute(x: number, y: number, z: number, options?: { constants?: Opaque<"constant_buffer"> }): void;
|
|
@@ -187,29 +207,31 @@ declare global {
|
|
|
187
207
|
* `sort_order`
|
|
188
208
|
* int How to sort draw order for world-ordered entries. Default uses the renderer's preferred world sorting (back-to-front).
|
|
189
209
|
* @example
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
210
|
+
* ```ts
|
|
211
|
+
* export default defineScript({
|
|
212
|
+
* init() {
|
|
213
|
+
* // define a predicate matching anything with material tag "my_tag"
|
|
214
|
+
* return { my_pred: render.predicate([hash("my_tag")]) };
|
|
215
|
+
* },
|
|
216
|
+
*
|
|
217
|
+
* update(self, dt) {
|
|
218
|
+
* // draw everything in the my_pred predicate
|
|
219
|
+
* render.draw(self.my_pred);
|
|
220
|
+
* },
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* // Draw predicate with constants:
|
|
224
|
+
* const constants = render.constant_buffer();
|
|
225
|
+
* constants.tint = vmath.vector4(1, 1, 1, 1);
|
|
226
|
+
* render.draw(self.my_pred, { constants });
|
|
227
|
+
*
|
|
228
|
+
* // Draw with predicate and frustum culling (without near+far planes):
|
|
229
|
+
* const frustum = self.proj.mul(self.view);
|
|
230
|
+
* render.draw(self.my_pred, { frustum });
|
|
231
|
+
*
|
|
232
|
+
* // Draw with predicate and frustum culling (with near+far planes):
|
|
233
|
+
* const frustum2 = self.proj.mul(self.view);
|
|
234
|
+
* render.draw(self.my_pred, { frustum: frustum2, frustum_planes: render.FRUSTUM_PLANES_ALL });
|
|
213
235
|
* ```
|
|
214
236
|
*/
|
|
215
237
|
function draw(predicate: number, options?: { frustum?: Matrix4; frustum_planes?: number; constants?: Opaque<"constant_buffer">; sort_order?: number }): void;
|
|
@@ -224,11 +246,13 @@ declare global {
|
|
|
224
246
|
* - render.FRUSTUM_PLANES_SIDES : The left, right, top and bottom sides of the frustum.
|
|
225
247
|
* - render.FRUSTUM_PLANES_ALL : All sides of the frustum.
|
|
226
248
|
* @example
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
249
|
+
* ```ts
|
|
250
|
+
* export default defineScript({
|
|
251
|
+
* update(self, dt) {
|
|
252
|
+
* // draw debug visualization
|
|
253
|
+
* render.draw_debug3d();
|
|
254
|
+
* },
|
|
255
|
+
* });
|
|
232
256
|
* ```
|
|
233
257
|
*/
|
|
234
258
|
function draw_debug3d(options?: { frustum?: Matrix4; frustum_planes?: number }): void;
|
|
@@ -240,11 +264,11 @@ declare global {
|
|
|
240
264
|
*
|
|
241
265
|
* @param material_id - material id to enable
|
|
242
266
|
* @example
|
|
243
|
-
* ```
|
|
244
|
-
* Enable material named "glow", then draw my_pred with it.
|
|
245
|
-
* render.enable_material("glow")
|
|
246
|
-
* render.draw(self.my_pred)
|
|
247
|
-
* render.disable_material()
|
|
267
|
+
* ```ts
|
|
268
|
+
* // Enable material named "glow", then draw my_pred with it.
|
|
269
|
+
* render.enable_material("glow");
|
|
270
|
+
* render.draw(self.my_pred);
|
|
271
|
+
* render.disable_material();
|
|
248
272
|
* ```
|
|
249
273
|
*/
|
|
250
274
|
function enable_material(material_id: string | Hash): void;
|
|
@@ -259,11 +283,11 @@ declare global {
|
|
|
259
283
|
* - `graphics.STATE_CULL_FACE`
|
|
260
284
|
* - `graphics.STATE_POLYGON_OFFSET_FILL`
|
|
261
285
|
* @example
|
|
262
|
-
* ```
|
|
263
|
-
* Enable stencil test when drawing the gui predicate, then disable it:
|
|
264
|
-
* render.enable_state(graphics.STATE_STENCIL_TEST)
|
|
265
|
-
* render.draw(self.gui_pred)
|
|
266
|
-
* render.disable_state(graphics.STATE_STENCIL_TEST)
|
|
286
|
+
* ```ts
|
|
287
|
+
* // Enable stencil test when drawing the gui predicate, then disable it:
|
|
288
|
+
* render.enable_state(graphics.STATE_STENCIL_TEST);
|
|
289
|
+
* render.draw(self.gui_pred);
|
|
290
|
+
* render.disable_state(graphics.STATE_STENCIL_TEST);
|
|
267
291
|
* ```
|
|
268
292
|
*/
|
|
269
293
|
function enable_state(state: Opaque<"constant">): void;
|
|
@@ -294,41 +318,48 @@ declare global {
|
|
|
294
318
|
* - `graphics.BUFFER_TYPE_COLOR2_BIT`
|
|
295
319
|
* - `graphics.BUFFER_TYPE_COLOR3_BIT`
|
|
296
320
|
* @example
|
|
297
|
-
* ```
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* render
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* render.
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* render.
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
321
|
+
* ```ts
|
|
322
|
+
* export default defineScript({
|
|
323
|
+
* update(self, dt) {
|
|
324
|
+
* // enable target so all drawing is done to it
|
|
325
|
+
* render.set_render_target(self.my_render_target);
|
|
326
|
+
*
|
|
327
|
+
* // draw a predicate to the render target
|
|
328
|
+
* render.draw(self.my_pred);
|
|
329
|
+
*
|
|
330
|
+
* // disable target
|
|
331
|
+
* render.set_render_target(render.RENDER_TARGET_DEFAULT);
|
|
332
|
+
*
|
|
333
|
+
* render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
334
|
+
* // draw a predicate with the render target available as texture 0 in the predicate
|
|
335
|
+
* // material shader.
|
|
336
|
+
* render.draw(self.my_pred);
|
|
337
|
+
* },
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* // Or enable a render target by resource id:
|
|
341
|
+
* export default defineScript({
|
|
342
|
+
* update(self, dt) {
|
|
343
|
+
* render.set_render_target("my_rt_resource");
|
|
344
|
+
* render.draw(self.my_pred);
|
|
345
|
+
* render.set_render_target(render.RENDER_TARGET_DEFAULT);
|
|
346
|
+
*
|
|
347
|
+
* render.enable_texture(0, "my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
348
|
+
* // draw a predicate with the render target available as texture 0 in the predicate
|
|
349
|
+
* // material shader.
|
|
350
|
+
* render.draw(self.my_pred);
|
|
351
|
+
* },
|
|
352
|
+
* });
|
|
353
|
+
*
|
|
354
|
+
* // Or bind a texture handle directly:
|
|
355
|
+
* export default defineScript({
|
|
356
|
+
* update(self, dt) {
|
|
357
|
+
* // bind a texture to the texture unit 0
|
|
358
|
+
* render.enable_texture(0, self.my_texture_handle);
|
|
359
|
+
* // bind the same texture to a named sampler
|
|
360
|
+
* render.enable_texture("my_texture_sampler", self.my_texture_handle);
|
|
361
|
+
* },
|
|
362
|
+
* });
|
|
332
363
|
* ```
|
|
333
364
|
*/
|
|
334
365
|
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;
|
|
@@ -339,9 +370,9 @@ declare global {
|
|
|
339
370
|
*
|
|
340
371
|
* @returns specified window height
|
|
341
372
|
* @example
|
|
342
|
-
* ```
|
|
343
|
-
* Get the height of the window
|
|
344
|
-
*
|
|
373
|
+
* ```ts
|
|
374
|
+
* // Get the height of the window
|
|
375
|
+
* const h = render.get_height();
|
|
345
376
|
* ```
|
|
346
377
|
*/
|
|
347
378
|
function get_height(): number;
|
|
@@ -355,11 +386,11 @@ declare global {
|
|
|
355
386
|
* - `graphics.BUFFER_TYPE_STENCIL_BIT`
|
|
356
387
|
* @returns the height of the render target buffer texture
|
|
357
388
|
* @example
|
|
358
|
-
* ```
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
389
|
+
* ```ts
|
|
390
|
+
* // get the height of the render target color buffer
|
|
391
|
+
* const h = render.get_render_target_height(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
392
|
+
* // get the height of a render target resource
|
|
393
|
+
* const w = render.get_render_target_height("my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
363
394
|
* ```
|
|
364
395
|
*/
|
|
365
396
|
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;
|
|
@@ -374,11 +405,11 @@ declare global {
|
|
|
374
405
|
* - `graphics.BUFFER_TYPE_STENCIL_BIT`
|
|
375
406
|
* @returns the width of the render target buffer texture
|
|
376
407
|
* @example
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
408
|
+
* ```ts
|
|
409
|
+
* // get the width of the render target color buffer
|
|
410
|
+
* const w = render.get_render_target_width(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
411
|
+
* // get the width of a render target resource
|
|
412
|
+
* const w2 = render.get_render_target_width("my_rt_resource", graphics.BUFFER_TYPE_COLOR0_BIT);
|
|
382
413
|
* ```
|
|
383
414
|
*/
|
|
384
415
|
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;
|
|
@@ -389,9 +420,9 @@ declare global {
|
|
|
389
420
|
*
|
|
390
421
|
* @returns specified window width (number)
|
|
391
422
|
* @example
|
|
392
|
-
* ```
|
|
393
|
-
* Get the width of the window.
|
|
394
|
-
*
|
|
423
|
+
* ```ts
|
|
424
|
+
* // Get the width of the window.
|
|
425
|
+
* const w = render.get_width();
|
|
395
426
|
* ```
|
|
396
427
|
*/
|
|
397
428
|
function get_width(): number;
|
|
@@ -402,9 +433,9 @@ declare global {
|
|
|
402
433
|
*
|
|
403
434
|
* @returns actual window height
|
|
404
435
|
* @example
|
|
405
|
-
* ```
|
|
406
|
-
* Get the actual height of the window
|
|
407
|
-
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* // Get the actual height of the window
|
|
438
|
+
* const h = render.get_window_height();
|
|
408
439
|
* ```
|
|
409
440
|
*/
|
|
410
441
|
function get_window_height(): number;
|
|
@@ -415,9 +446,9 @@ declare global {
|
|
|
415
446
|
*
|
|
416
447
|
* @returns actual window width
|
|
417
448
|
* @example
|
|
418
|
-
* ```
|
|
419
|
-
* Get the actual width of the window
|
|
420
|
-
*
|
|
449
|
+
* ```ts
|
|
450
|
+
* // Get the actual width of the window
|
|
451
|
+
* const w = render.get_window_width();
|
|
421
452
|
* ```
|
|
422
453
|
*/
|
|
423
454
|
function get_window_width(): number;
|
|
@@ -431,10 +462,10 @@ declare global {
|
|
|
431
462
|
* @param tags - table of tags that the predicate should match. The tags can be of either hash or string type
|
|
432
463
|
* @returns new predicate
|
|
433
464
|
* @example
|
|
434
|
-
* ```
|
|
435
|
-
* Create a new render predicate containing all visual objects that
|
|
436
|
-
* have a material with material tags "opaque" AND "smoke".
|
|
437
|
-
*
|
|
465
|
+
* ```ts
|
|
466
|
+
* // Create a new render predicate containing all visual objects that
|
|
467
|
+
* // have a material with material tags "opaque" AND "smoke".
|
|
468
|
+
* const p = render.predicate([hash("opaque"), hash("smoke")]);
|
|
438
469
|
* ```
|
|
439
470
|
*/
|
|
440
471
|
function predicate(tags: Record<string | number, unknown>): number;
|
|
@@ -492,66 +523,86 @@ declare global {
|
|
|
492
523
|
* @param parameters - table of buffer parameters, see the description for available keys and values
|
|
493
524
|
* @returns new render target
|
|
494
525
|
* @example
|
|
495
|
-
* ```
|
|
496
|
-
* How to create a new render target and draw to it:
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
526
|
+
* ```ts
|
|
527
|
+
* // How to create a new render target and draw to it:
|
|
528
|
+
* export default defineScript({
|
|
529
|
+
* init() {
|
|
530
|
+
* // render target buffer parameters
|
|
531
|
+
* const color_params = {
|
|
532
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
533
|
+
* width: render.get_window_width(),
|
|
534
|
+
* height: render.get_window_height(),
|
|
535
|
+
* min_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
536
|
+
* mag_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
537
|
+
* u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
538
|
+
* v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
539
|
+
* };
|
|
540
|
+
* const depth_params = {
|
|
541
|
+
* format: graphics.TEXTURE_FORMAT_DEPTH,
|
|
542
|
+
* width: render.get_window_width(),
|
|
543
|
+
* height: render.get_window_height(),
|
|
544
|
+
* u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
545
|
+
* v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
546
|
+
* };
|
|
547
|
+
* return {
|
|
548
|
+
* my_render_target: render.render_target({
|
|
549
|
+
* [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,
|
|
550
|
+
* [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,
|
|
551
|
+
* }),
|
|
552
|
+
* };
|
|
553
|
+
* },
|
|
554
|
+
*
|
|
555
|
+
* update(self, dt) {
|
|
556
|
+
* // enable target so all drawing is done to it
|
|
557
|
+
* render.set_render_target(self.my_render_target);
|
|
558
|
+
*
|
|
559
|
+
* // draw a predicate to the render target
|
|
560
|
+
* render.draw(self.my_pred);
|
|
561
|
+
* },
|
|
562
|
+
* });
|
|
563
|
+
*
|
|
564
|
+
* // How to create a render target with multiple outputs:
|
|
565
|
+
* export default defineScript({
|
|
566
|
+
* init() {
|
|
567
|
+
* // render target buffer parameters
|
|
568
|
+
* const color_params_rgba = {
|
|
569
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
570
|
+
* width: render.get_window_width(),
|
|
571
|
+
* height: render.get_window_height(),
|
|
572
|
+
* min_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
573
|
+
* mag_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
574
|
+
* u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
575
|
+
* v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
576
|
+
* };
|
|
577
|
+
* const color_params_float = {
|
|
578
|
+
* format: graphics.TEXTURE_FORMAT_RG32F,
|
|
579
|
+
* width: render.get_window_width(),
|
|
580
|
+
* height: render.get_window_height(),
|
|
581
|
+
* min_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
582
|
+
* mag_filter: graphics.TEXTURE_FILTER_LINEAR,
|
|
583
|
+
* u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
584
|
+
* v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
|
|
585
|
+
* };
|
|
586
|
+
*
|
|
587
|
+
* // Create a render target with three color attachments
|
|
588
|
+
* // Note: No depth buffer is attached here
|
|
589
|
+
* return {
|
|
590
|
+
* my_render_target: render.render_target({
|
|
591
|
+
* [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,
|
|
592
|
+
* [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,
|
|
593
|
+
* [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,
|
|
594
|
+
* }),
|
|
595
|
+
* };
|
|
596
|
+
* },
|
|
597
|
+
*
|
|
598
|
+
* update(self, dt) {
|
|
599
|
+
* // enable target so all drawing is done to it
|
|
600
|
+
* render.enable_render_target(self.my_render_target);
|
|
601
|
+
*
|
|
602
|
+
* // draw a predicate to the render target
|
|
603
|
+
* render.draw(self.my_pred);
|
|
604
|
+
* },
|
|
605
|
+
* });
|
|
555
606
|
* ```
|
|
556
607
|
*/
|
|
557
608
|
function render_target(name: string, parameters: Record<string | number, unknown>): Opaque<"render_target">;
|
|
@@ -614,9 +665,9 @@ declare global {
|
|
|
614
665
|
* @param source_factor - source factor
|
|
615
666
|
* @param destination_factor - destination factor
|
|
616
667
|
* @example
|
|
617
|
-
* ```
|
|
618
|
-
* Set the blend func to the most common one:
|
|
619
|
-
* render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA)
|
|
668
|
+
* ```ts
|
|
669
|
+
* // Set the blend func to the most common one:
|
|
670
|
+
* render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
|
|
620
671
|
* ```
|
|
621
672
|
*/
|
|
622
673
|
function set_blend_func(source_factor: number, destination_factor: number): void;
|
|
@@ -634,18 +685,18 @@ declare global {
|
|
|
634
685
|
* `use_frustum`
|
|
635
686
|
* boolean If true, the renderer will use the cameras view-projection matrix for frustum culling (default: false)
|
|
636
687
|
* @example
|
|
637
|
-
* ```
|
|
638
|
-
* Set the current camera to be used for rendering
|
|
639
|
-
* render.set_camera("main:/my_go#camera")
|
|
640
|
-
* render.draw(self.my_pred)
|
|
641
|
-
* render.set_camera(
|
|
642
|
-
*
|
|
643
|
-
* Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command
|
|
644
|
-
*
|
|
645
|
-
* render.set_camera("main:/my_go#camera", { use_frustum
|
|
646
|
-
*
|
|
647
|
-
* render.draw(self.my_pred, { frustum_planes
|
|
648
|
-
* render.set_camera()
|
|
688
|
+
* ```ts
|
|
689
|
+
* // Set the current camera to be used for rendering
|
|
690
|
+
* render.set_camera("main:/my_go#camera");
|
|
691
|
+
* render.draw(self.my_pred);
|
|
692
|
+
* render.set_camera(undefined);
|
|
693
|
+
*
|
|
694
|
+
* // Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command
|
|
695
|
+
* // The camera frustum will take precedence over the frustum plane option in render.draw
|
|
696
|
+
* render.set_camera("main:/my_go#camera", { use_frustum: true });
|
|
697
|
+
* // However, we can still customize the frustum planes regardless of the camera option!
|
|
698
|
+
* render.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });
|
|
699
|
+
* render.set_camera();
|
|
649
700
|
* ```
|
|
650
701
|
*/
|
|
651
702
|
function set_camera(camera?: Url | number, options?: { use_frustum?: boolean }): void;
|
|
@@ -658,9 +709,9 @@ declare global {
|
|
|
658
709
|
* @param blue - blue mask
|
|
659
710
|
* @param alpha - alpha mask
|
|
660
711
|
* @example
|
|
661
|
-
* ```
|
|
662
|
-
*
|
|
663
|
-
* render.set_color_mask(true, true, true, false)
|
|
712
|
+
* ```ts
|
|
713
|
+
* // alpha cannot be written to frame buffer
|
|
714
|
+
* render.set_color_mask(true, true, true, false);
|
|
664
715
|
* ```
|
|
665
716
|
*/
|
|
666
717
|
function set_color_mask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void;
|
|
@@ -671,12 +722,12 @@ declare global {
|
|
|
671
722
|
*
|
|
672
723
|
* @param compute - compute id to use, or nil to disable
|
|
673
724
|
* @example
|
|
674
|
-
* ```
|
|
675
|
-
* Enable compute program named "fractals", then dispatch it.
|
|
676
|
-
* render.set_compute("fractals")
|
|
677
|
-
* render.enable_texture(0, self.backing_texture)
|
|
678
|
-
* render.dispatch_compute(128, 128, 1)
|
|
679
|
-
* render.set_compute()
|
|
725
|
+
* ```ts
|
|
726
|
+
* // Enable compute program named "fractals", then dispatch it.
|
|
727
|
+
* render.set_compute("fractals");
|
|
728
|
+
* render.enable_texture(0, self.backing_texture);
|
|
729
|
+
* render.dispatch_compute(128, 128, 1);
|
|
730
|
+
* render.set_compute();
|
|
680
731
|
* ```
|
|
681
732
|
*/
|
|
682
733
|
function set_compute(compute?: string | Hash): void;
|
|
@@ -692,10 +743,10 @@ declare global {
|
|
|
692
743
|
* - `graphics.FACE_TYPE_BACK`
|
|
693
744
|
* - `graphics.FACE_TYPE_FRONT_AND_BACK`
|
|
694
745
|
* @example
|
|
695
|
-
* ```
|
|
696
|
-
* How to enable polygon culling and set front face culling:
|
|
697
|
-
* render.enable_state(graphics.STATE_CULL_FACE)
|
|
698
|
-
* render.set_cull_face(graphics.FACE_TYPE_FRONT)
|
|
746
|
+
* ```ts
|
|
747
|
+
* // How to enable polygon culling and set front face culling:
|
|
748
|
+
* render.enable_state(graphics.STATE_CULL_FACE);
|
|
749
|
+
* render.set_cull_face(graphics.FACE_TYPE_FRONT);
|
|
699
750
|
* ```
|
|
700
751
|
*/
|
|
701
752
|
function set_cull_face(face_type: number): void;
|
|
@@ -717,10 +768,10 @@ declare global {
|
|
|
717
768
|
*
|
|
718
769
|
* @param func - depth test function, see the description for available values
|
|
719
770
|
* @example
|
|
720
|
-
* ```
|
|
721
|
-
* Enable depth test and set the depth test function to "not equal".
|
|
722
|
-
* render.enable_state(graphics.STATE_DEPTH_TEST)
|
|
723
|
-
* render.set_depth_func(graphics.COMPARE_FUNC_NOTEQUAL)
|
|
771
|
+
* ```ts
|
|
772
|
+
* // Enable depth test and set the depth test function to "not equal".
|
|
773
|
+
* render.enable_state(graphics.STATE_DEPTH_TEST);
|
|
774
|
+
* render.set_depth_func(graphics.COMPARE_FUNC_NOTEQUAL);
|
|
724
775
|
* ```
|
|
725
776
|
*/
|
|
726
777
|
function set_depth_func(func: number): void;
|
|
@@ -731,9 +782,9 @@ declare global {
|
|
|
731
782
|
*
|
|
732
783
|
* @param depth - depth mask
|
|
733
784
|
* @example
|
|
734
|
-
* ```
|
|
735
|
-
* How to turn off writing to the depth buffer:
|
|
736
|
-
* render.set_depth_mask(false)
|
|
785
|
+
* ```ts
|
|
786
|
+
* // How to turn off writing to the depth buffer:
|
|
787
|
+
* render.set_depth_mask(false);
|
|
737
788
|
* ```
|
|
738
789
|
*/
|
|
739
790
|
function set_depth_mask(depth: boolean): void;
|
|
@@ -750,18 +801,20 @@ declare global {
|
|
|
750
801
|
* `event_type`
|
|
751
802
|
* string Rendering event. Possible values: `render.CONTEXT_EVENT_CONTEXT_LOST`, `render.CONTEXT_EVENT_CONTEXT_RESTORED`
|
|
752
803
|
* @example
|
|
753
|
-
* ```
|
|
754
|
-
* Set listener and handle render context events.
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
804
|
+
* ```ts
|
|
805
|
+
* // Set listener and handle render context events.
|
|
806
|
+
* // custom.render_script
|
|
807
|
+
* export default defineScript({
|
|
808
|
+
* init() {
|
|
809
|
+
* render.set_listener((self, event_type) => {
|
|
810
|
+
* if (event_type === render.CONTEXT_EVENT_CONTEXT_LOST) {
|
|
811
|
+
* // Some stuff when rendering context is lost
|
|
812
|
+
* } else if (event_type === render.CONTEXT_EVENT_CONTEXT_RESTORED) {
|
|
813
|
+
* // Start reload resources, reload game, etc.
|
|
814
|
+
* }
|
|
815
|
+
* });
|
|
816
|
+
* },
|
|
817
|
+
* });
|
|
765
818
|
* ```
|
|
766
819
|
*/
|
|
767
820
|
function set_listener(callback?: (self: unknown, event_type: unknown) => void): void;
|
|
@@ -787,9 +840,9 @@ declare global {
|
|
|
787
840
|
* @param factor - polygon offset factor
|
|
788
841
|
* @param units - polygon offset units
|
|
789
842
|
* @example
|
|
790
|
-
* ```
|
|
791
|
-
* render.enable_state(graphics.STATE_POLYGON_OFFSET_FILL)
|
|
792
|
-
* render.set_polygon_offset(1.0, 1.0)
|
|
843
|
+
* ```ts
|
|
844
|
+
* render.enable_state(graphics.STATE_POLYGON_OFFSET_FILL);
|
|
845
|
+
* render.set_polygon_offset(1.0, 1.0);
|
|
793
846
|
* ```
|
|
794
847
|
*/
|
|
795
848
|
function set_polygon_offset(factor: number, units: number): void;
|
|
@@ -798,10 +851,10 @@ declare global {
|
|
|
798
851
|
*
|
|
799
852
|
* @param matrix - projection matrix
|
|
800
853
|
* @example
|
|
801
|
-
* ```
|
|
802
|
-
* How to set the projection to orthographic with world origo at lower left,
|
|
803
|
-
* width and height as set in project settings and depth (z) between -1 and 1:
|
|
804
|
-
* render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))
|
|
854
|
+
* ```ts
|
|
855
|
+
* // How to set the projection to orthographic with world origo at lower left,
|
|
856
|
+
* // width and height as set in project settings and depth (z) between -1 and 1:
|
|
857
|
+
* render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1));
|
|
805
858
|
* ```
|
|
806
859
|
*/
|
|
807
860
|
function set_projection(matrix: Matrix4): void;
|
|
@@ -820,33 +873,37 @@ declare global {
|
|
|
820
873
|
* - `graphics.BUFFER_TYPE_DEPTH_BIT`
|
|
821
874
|
* - `graphics.BUFFER_TYPE_STENCIL_BIT`
|
|
822
875
|
* @example
|
|
823
|
-
* ```
|
|
824
|
-
* How to set a render target and draw to it and then switch back to the default render target
|
|
825
|
-
* 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
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
* render
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
* render
|
|
848
|
-
*
|
|
849
|
-
*
|
|
876
|
+
* ```ts
|
|
877
|
+
* // How to set a render target and draw to it and then switch back to the default render target
|
|
878
|
+
* // 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
|
|
879
|
+
* export default defineScript({
|
|
880
|
+
* update(self, dt) {
|
|
881
|
+
* // set render target so all drawing is done to it
|
|
882
|
+
* render.set_render_target(self.my_render_target, {
|
|
883
|
+
* transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],
|
|
884
|
+
* });
|
|
885
|
+
*
|
|
886
|
+
* // draw a predicate to the render target
|
|
887
|
+
* render.draw(self.my_pred);
|
|
888
|
+
*
|
|
889
|
+
* // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)
|
|
890
|
+
* // which can be an optimisation on some hardware
|
|
891
|
+
* render.set_render_target(render.RENDER_TARGET_DEFAULT);
|
|
892
|
+
* },
|
|
893
|
+
* });
|
|
894
|
+
*
|
|
895
|
+
* // Or set the render target by a render target resource identifier:
|
|
896
|
+
* export default defineScript({
|
|
897
|
+
* update(self, dt) {
|
|
898
|
+
* render.set_render_target("my_rt_resource");
|
|
899
|
+
*
|
|
900
|
+
* // draw a predicate to the render target
|
|
901
|
+
* render.draw(self.my_pred);
|
|
902
|
+
*
|
|
903
|
+
* // reset the render target to the default backbuffer
|
|
904
|
+
* render.set_render_target(render.RENDER_TARGET_DEFAULT);
|
|
905
|
+
* },
|
|
906
|
+
* });
|
|
850
907
|
* ```
|
|
851
908
|
*/
|
|
852
909
|
function set_render_target(render_target: Opaque<"render_target">, options?: { transient?: Record<string | number, unknown> }): void;
|
|
@@ -858,10 +915,10 @@ declare global {
|
|
|
858
915
|
* @param width - new render target width
|
|
859
916
|
* @param height - new render target height
|
|
860
917
|
* @example
|
|
861
|
-
* ```
|
|
862
|
-
* Resize render targets to the current window size:
|
|
863
|
-
* render.set_render_target_size(self.my_render_target, render.get_window_width(), render.get_window_height())
|
|
864
|
-
* render.set_render_target_size(
|
|
918
|
+
* ```ts
|
|
919
|
+
* // Resize render targets to the current window size:
|
|
920
|
+
* render.set_render_target_size(self.my_render_target, render.get_window_width(), render.get_window_height());
|
|
921
|
+
* render.set_render_target_size("my_rt_resource", render.get_window_width(), render.get_window_height());
|
|
865
922
|
* ```
|
|
866
923
|
*/
|
|
867
924
|
function set_render_target_size(render_target: Opaque<"render_target">, width: number, height: number): void;
|
|
@@ -893,9 +950,9 @@ declare global {
|
|
|
893
950
|
* @param ref - reference value for the stencil test
|
|
894
951
|
* @param mask - mask that is ANDed with both the reference value and the stored stencil value when the test is done
|
|
895
952
|
* @example
|
|
896
|
-
* ```
|
|
897
|
-
*
|
|
898
|
-
* render.set_stencil_func(graphics.COMPARE_FUNC_EQUAL, 0, 1)
|
|
953
|
+
* ```ts
|
|
954
|
+
* // let only 0's pass the stencil test
|
|
955
|
+
* render.set_stencil_func(graphics.COMPARE_FUNC_EQUAL, 0, 1);
|
|
899
956
|
* ```
|
|
900
957
|
*/
|
|
901
958
|
function set_stencil_func(func: number, ref: number, mask: number): void;
|
|
@@ -910,9 +967,9 @@ declare global {
|
|
|
910
967
|
*
|
|
911
968
|
* @param mask - stencil mask
|
|
912
969
|
* @example
|
|
913
|
-
* ```
|
|
914
|
-
*
|
|
915
|
-
* render.set_stencil_mask(0xff)
|
|
970
|
+
* ```ts
|
|
971
|
+
* // set the stencil mask to all 1:s
|
|
972
|
+
* render.set_stencil_mask(0xff);
|
|
916
973
|
* ```
|
|
917
974
|
*/
|
|
918
975
|
function set_stencil_mask(mask: number): void;
|
|
@@ -941,12 +998,12 @@ declare global {
|
|
|
941
998
|
* @param dpfail - the stencil action when the stencil test passes
|
|
942
999
|
* @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
|
|
943
1000
|
* @example
|
|
944
|
-
* ```
|
|
945
|
-
* Set the stencil function to never pass and operator to always draw 1's
|
|
946
|
-
* on test fail.
|
|
947
|
-
* render.set_stencil_func(graphics.COMPARE_FUNC_NEVER, 1, 0xFF)
|
|
948
|
-
*
|
|
949
|
-
* render.set_stencil_op(graphics.STENCIL_OP_REPLACE, graphics.STENCIL_OP_KEEP, graphics.STENCIL_OP_KEEP)
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* // Set the stencil function to never pass and operator to always draw 1's
|
|
1003
|
+
* // on test fail.
|
|
1004
|
+
* render.set_stencil_func(graphics.COMPARE_FUNC_NEVER, 1, 0xFF);
|
|
1005
|
+
* // always draw 1's on test fail
|
|
1006
|
+
* render.set_stencil_op(graphics.STENCIL_OP_REPLACE, graphics.STENCIL_OP_KEEP, graphics.STENCIL_OP_KEEP);
|
|
950
1007
|
* ```
|
|
951
1008
|
*/
|
|
952
1009
|
function set_stencil_op(sfail: number, dpfail: number, dppass: number): void;
|
|
@@ -955,27 +1012,31 @@ declare global {
|
|
|
955
1012
|
*
|
|
956
1013
|
* @param matrix - view matrix to set
|
|
957
1014
|
* @example
|
|
958
|
-
* ```
|
|
959
|
-
* How to set the view and projection matrices according to
|
|
960
|
-
* the values supplied by a camera.
|
|
961
|
-
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1015
|
+
* ```ts
|
|
1016
|
+
* // How to set the view and projection matrices according to
|
|
1017
|
+
* // the values supplied by a camera.
|
|
1018
|
+
* export default defineScript({
|
|
1019
|
+
* init() {
|
|
1020
|
+
* return {
|
|
1021
|
+
* view: vmath.matrix4(),
|
|
1022
|
+
* projection: vmath.matrix4(),
|
|
1023
|
+
* };
|
|
1024
|
+
* },
|
|
1025
|
+
*
|
|
1026
|
+
* update(self, dt) {
|
|
1027
|
+
* // set the view to the stored view value
|
|
1028
|
+
* render.set_view(self.view);
|
|
1029
|
+
* // now we can draw with this view
|
|
1030
|
+
* },
|
|
1031
|
+
*
|
|
1032
|
+
* on_message(self, message_id, message) {
|
|
1033
|
+
* if (message_id === hash("set_view_projection")) {
|
|
1034
|
+
* // camera view and projection arrives here.
|
|
1035
|
+
* self.view = message.view;
|
|
1036
|
+
* self.projection = message.projection;
|
|
1037
|
+
* }
|
|
1038
|
+
* },
|
|
1039
|
+
* });
|
|
979
1040
|
* ```
|
|
980
1041
|
*/
|
|
981
1042
|
function set_view(matrix: Matrix4): void;
|
|
@@ -987,9 +1048,9 @@ declare global {
|
|
|
987
1048
|
* @param width - viewport width
|
|
988
1049
|
* @param height - viewport height
|
|
989
1050
|
* @example
|
|
990
|
-
* ```
|
|
991
|
-
*
|
|
992
|
-
* render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
|
|
1051
|
+
* ```ts
|
|
1052
|
+
* // Set the viewport to the window dimensions.
|
|
1053
|
+
* render.set_viewport(0, 0, render.get_window_width(), render.get_window_height());
|
|
993
1054
|
* ```
|
|
994
1055
|
*/
|
|
995
1056
|
function set_viewport(x: number, y: number, width: number, height: number): void;
|