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