@defold-typescript/types 0.4.2 → 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/resource.d.ts
CHANGED
|
@@ -3,29 +3,1256 @@ import type { Hash, Opaque } from "../src/core-types";
|
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace resource {
|
|
6
|
+
/**
|
|
7
|
+
* Constructor-like function with two purposes:
|
|
8
|
+
* - Load the specified resource as part of loading the script
|
|
9
|
+
* - Return a hash to the run-time version of the resource
|
|
10
|
+
* This function can only be called within go.property function calls.
|
|
11
|
+
*
|
|
12
|
+
* @param path - optional resource path string to the resource
|
|
13
|
+
* @returns a path hash to the binary version of the resource
|
|
14
|
+
* @example
|
|
15
|
+
* ```lua
|
|
16
|
+
* Load an atlas and set it to a sprite:
|
|
17
|
+
* go.property("my_atlas", resource.atlas("/atlas.atlas"))
|
|
18
|
+
* function init(self)
|
|
19
|
+
* go.set("#sprite", "image", self.my_atlas)
|
|
20
|
+
* end
|
|
21
|
+
*
|
|
22
|
+
* Load an atlas and set it to a gui:
|
|
23
|
+
* go.property("my_atlas", resource.atlas("/atlas.atlas"))
|
|
24
|
+
* function init(self)
|
|
25
|
+
* go.set("#gui", "textures", self.my_atlas, {key = "my_atlas"})
|
|
26
|
+
* end
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
6
29
|
function atlas(path?: string): Hash;
|
|
30
|
+
/**
|
|
31
|
+
* Constructor-like function with two purposes:
|
|
32
|
+
* - Load the specified resource as part of loading the script
|
|
33
|
+
* - Return a hash to the run-time version of the resource
|
|
34
|
+
* This function can only be called within go.property function calls.
|
|
35
|
+
*
|
|
36
|
+
* @param path - optional resource path string to the resource
|
|
37
|
+
* @returns a path hash to the binary version of the resource
|
|
38
|
+
* @example
|
|
39
|
+
* ```lua
|
|
40
|
+
* Set a unique buffer it to a sprite:
|
|
41
|
+
* go.property("my_buffer", resource.buffer("/cube.buffer"))
|
|
42
|
+
* function init(self)
|
|
43
|
+
* go.set("#mesh", "vertices", self.my_buffer)
|
|
44
|
+
* end
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
7
47
|
function buffer(path?: string): Hash;
|
|
48
|
+
/**
|
|
49
|
+
* This function creates a new atlas resource that can be used in the same way as any atlas created during build time.
|
|
50
|
+
* The path used for creating the atlas must be unique, trying to create a resource at a path that is already
|
|
51
|
+
* registered will trigger an error. If the intention is to instead modify an existing atlas, use the resource.set_atlas
|
|
52
|
+
* function. Also note that the path to the new atlas resource must have a '.texturesetc' extension,
|
|
53
|
+
* meaning "/path/my_atlas" is not a valid path but "/path/my_atlas.texturesetc" is.
|
|
54
|
+
* When creating the atlas, at least one geometry and one animation is required, and an error will be
|
|
55
|
+
* raised if these requirements are not met. A reference to the resource will be held by the collection
|
|
56
|
+
* that created the resource and will automatically be released when that collection is destroyed.
|
|
57
|
+
* Note that releasing a resource essentially means decreasing the reference count of that resource,
|
|
58
|
+
* and not necessarily that it will be deleted.
|
|
59
|
+
*
|
|
60
|
+
* @param path - The path to the resource.
|
|
61
|
+
* @param table - A table containing info about how to create the atlas. Supported entries:
|
|
62
|
+
-
|
|
63
|
+
`texture`
|
|
64
|
+
string | hash the path to the texture resource, e.g "/main/my_texture.texturec"
|
|
65
|
+
-
|
|
66
|
+
`animations`
|
|
67
|
+
table a list of the animations in the atlas. Supports the following fields:
|
|
68
|
+
-
|
|
69
|
+
`id`
|
|
70
|
+
string the id of the animation, used in e.g sprite.play_animation
|
|
71
|
+
-
|
|
72
|
+
`width`
|
|
73
|
+
number the width of the animation
|
|
74
|
+
-
|
|
75
|
+
`height`
|
|
76
|
+
number the height of the animation
|
|
77
|
+
-
|
|
78
|
+
`frame_start`
|
|
79
|
+
number index to the first geometry of the animation. Indices are lua based and must be in the range of 1 .. in atlas.
|
|
80
|
+
-
|
|
81
|
+
`frame_end`
|
|
82
|
+
number index to the last geometry of the animation (non-inclusive). Indices are lua based and must be in the range of 1 .. in atlas.
|
|
83
|
+
-
|
|
84
|
+
`playback`
|
|
85
|
+
constant optional playback mode of the animation, the default value is go.PLAYBACK_ONCE_FORWARD
|
|
86
|
+
-
|
|
87
|
+
`fps`
|
|
88
|
+
number optional fps of the animation, the default value is 30
|
|
89
|
+
-
|
|
90
|
+
`flip_vertical`
|
|
91
|
+
boolean optional flip the animation vertically, the default value is false
|
|
92
|
+
-
|
|
93
|
+
`flip_horizontal`
|
|
94
|
+
boolean optional flip the animation horizontally, the default value is false
|
|
95
|
+
-
|
|
96
|
+
`geometries`
|
|
97
|
+
table A list of the geometries that should map to the texture data. Supports the following fields:
|
|
98
|
+
-
|
|
99
|
+
`id`
|
|
100
|
+
string The name of the geometry. Used when matching animations between multiple atlases
|
|
101
|
+
-
|
|
102
|
+
`width`
|
|
103
|
+
number The width of the image the sprite geometry represents
|
|
104
|
+
-
|
|
105
|
+
`height`
|
|
106
|
+
number The height of the image the sprite geometry represents
|
|
107
|
+
-
|
|
108
|
+
`pivot_x`
|
|
109
|
+
number The pivot x value of the image in unit coords. (0,0) is upper left corner, (1,1) is bottom right. Default is 0.5.
|
|
110
|
+
-
|
|
111
|
+
`pivot_y`
|
|
112
|
+
number The pivot y value of the image in unit coords. (0,0) is upper left corner, (1,1) is bottom right. Default is 0.5.
|
|
113
|
+
-
|
|
114
|
+
`rotated`
|
|
115
|
+
boolean Whether the image is rotated 90 degrees counter-clockwise in the atlas. This affects UV coordinate generation for proper rendering. Default is false.
|
|
116
|
+
-
|
|
117
|
+
`vertices`
|
|
118
|
+
table a list of the vertices in image space of the geometry in the form {px0, py0, px1, py1, ..., pxn, pyn}
|
|
119
|
+
-
|
|
120
|
+
`uvs`
|
|
121
|
+
table a list of the uv coordinates in image space of the geometry in the form of {u0, v0, u1, v1, ..., un, vn}.
|
|
122
|
+
-
|
|
123
|
+
`indices`
|
|
124
|
+
table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
|
|
125
|
+
* @returns Returns the atlas resource path
|
|
126
|
+
* @example
|
|
127
|
+
* ```lua
|
|
128
|
+
* Create a backing texture and an atlas
|
|
129
|
+
* function init(self)
|
|
130
|
+
* -- create an empty texture
|
|
131
|
+
* local tparams = {
|
|
132
|
+
* width = 128,
|
|
133
|
+
* height = 128,
|
|
134
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
135
|
+
* format = graphics.TEXTURE_FORMAT_RGBA,
|
|
136
|
+
* }
|
|
137
|
+
* local my_texture_id = resource.create_texture("/my_texture.texturec", tparams)
|
|
138
|
+
*
|
|
139
|
+
* -- optionally use resource.set_texture to upload data to texture
|
|
140
|
+
*
|
|
141
|
+
* -- create an atlas with one animation and one square geometry
|
|
142
|
+
* -- note that the function doesn't support hashes for the texture,
|
|
143
|
+
* -- you need to use a string for the texture path here aswell
|
|
144
|
+
* local aparams = {
|
|
145
|
+
* texture = "/my_texture.texturec",
|
|
146
|
+
* animations = {
|
|
147
|
+
* {
|
|
148
|
+
* id = "my_animation",
|
|
149
|
+
* width = 128,
|
|
150
|
+
* height = 128,
|
|
151
|
+
* frames = { 1 }
|
|
152
|
+
* }
|
|
153
|
+
* },
|
|
154
|
+
* geometries = {
|
|
155
|
+
* {
|
|
156
|
+
* id = 'idle0',
|
|
157
|
+
* width = 128,
|
|
158
|
+
* height = 128,
|
|
159
|
+
* pivot_x = 0.5,
|
|
160
|
+
* pivot_y = 0.5,
|
|
161
|
+
* vertices = {
|
|
162
|
+
* 0, 0,
|
|
163
|
+
* 0, 128,
|
|
164
|
+
* 128, 128,
|
|
165
|
+
* 128, 0
|
|
166
|
+
* },
|
|
167
|
+
* uvs = {
|
|
168
|
+
* 0, 0,
|
|
169
|
+
* 0, 128,
|
|
170
|
+
* 128, 128,
|
|
171
|
+
* 128, 0
|
|
172
|
+
* },
|
|
173
|
+
* indices = {0,1,2,0,2,3}
|
|
174
|
+
* }
|
|
175
|
+
* }
|
|
176
|
+
* }
|
|
177
|
+
* local my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams)
|
|
178
|
+
*
|
|
179
|
+
* -- assign the atlas to the 'sprite' component on the same go
|
|
180
|
+
* go.set("#sprite", "image", my_atlas_id)
|
|
181
|
+
* end
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
8
184
|
function create_atlas(path: string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): Hash;
|
|
185
|
+
/**
|
|
186
|
+
* This function creates a new buffer resource that can be used in the same way as any buffer created during build time.
|
|
187
|
+
* The function requires a valid buffer created from either buffer.create or another pre-existing buffer resource.
|
|
188
|
+
* By default, the new resource will take ownership of the buffer lua reference, meaning the buffer will not automatically be removed
|
|
189
|
+
* when the lua reference to the buffer is garbage collected. This behaviour can be overruled by specifying 'transfer_ownership = false'
|
|
190
|
+
* in the argument table. If the new buffer resource is created from a buffer object that is created by another resource,
|
|
191
|
+
* the buffer object will be copied and the new resource will effectively own a copy of the buffer instead.
|
|
192
|
+
* Note that the path to the new resource must have the '.bufferc' extension, "/path/my_buffer" is not a valid path but "/path/my_buffer.bufferc" is.
|
|
193
|
+
* The path must also be unique, attempting to create a buffer with the same name as an existing resource will raise an error.
|
|
194
|
+
*
|
|
195
|
+
* @param path - The path to the resource.
|
|
196
|
+
* @param table - A table containing info about how to create the buffer. Supported entries:
|
|
197
|
+
-
|
|
198
|
+
`buffer`
|
|
199
|
+
buffer the buffer to bind to this resource
|
|
200
|
+
-
|
|
201
|
+
`transfer_ownership`
|
|
202
|
+
boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default true)
|
|
203
|
+
* @returns Returns the buffer resource path
|
|
204
|
+
* @example
|
|
205
|
+
* ```lua
|
|
206
|
+
* Create a buffer object and bind it to a buffer resource
|
|
207
|
+
* function init(self)
|
|
208
|
+
* local size = 1
|
|
209
|
+
* local positions = {
|
|
210
|
+
* -- triangle 1
|
|
211
|
+
* size, size, 0,
|
|
212
|
+
* -size, -size, 0,
|
|
213
|
+
* size, -size, 0,
|
|
214
|
+
* -- triangle 2
|
|
215
|
+
* size, size, 0,
|
|
216
|
+
* -size, size, 0,
|
|
217
|
+
* -size, -size, 0,
|
|
218
|
+
* }
|
|
219
|
+
*
|
|
220
|
+
* local buffer_handle = buffer.create(#positions, {
|
|
221
|
+
* {
|
|
222
|
+
* name = hash("position"),
|
|
223
|
+
* type = buffer.VALUE_TYPE_FLOAT32,
|
|
224
|
+
* count = 3
|
|
225
|
+
* }
|
|
226
|
+
* })
|
|
227
|
+
*
|
|
228
|
+
* local stream = buffer.get_stream(buffer_handle, hash("position"))
|
|
229
|
+
*
|
|
230
|
+
* -- transfer vertex data to buffer
|
|
231
|
+
* for k=1,#positions do
|
|
232
|
+
* stream[k] = positions[k]
|
|
233
|
+
* end
|
|
234
|
+
*
|
|
235
|
+
* local my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer = buffer_handle })
|
|
236
|
+
* go.set("/go#mesh", "vertices", my_buffer)
|
|
237
|
+
* end
|
|
238
|
+
* ```Create a buffer resource from existing resource
|
|
239
|
+
*
|
|
240
|
+
* ```lua
|
|
241
|
+
* function init(self)
|
|
242
|
+
* local res = resource.get_buffer("/my_buffer_path.bufferc")
|
|
243
|
+
* -- create a cloned buffer resource from another resource buffer
|
|
244
|
+
* local buf = reource.create_buffer("/my_cloned_buffer.bufferc", { buffer = res })
|
|
245
|
+
* -- assign cloned buffer to a mesh component
|
|
246
|
+
* go.set("/go#mesh", "vertices", buf)
|
|
247
|
+
* end
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
9
250
|
function create_buffer(path: string, table?: { buffer?: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
|
|
251
|
+
/**
|
|
252
|
+
* Creates a sound data resource
|
|
253
|
+
* Supported formats are .oggc, .opusc and .wavc
|
|
254
|
+
*
|
|
255
|
+
* @param path - the path to the resource. Must not already exist.
|
|
256
|
+
* @param options - A table containing parameters for the text. Supported entries:
|
|
257
|
+
`data`
|
|
258
|
+
string The raw data of the file. May be partial, but must include the header of the file
|
|
259
|
+
`filesize`
|
|
260
|
+
number If the file is partial, it must also specify the full size of the complete file.
|
|
261
|
+
`partial`
|
|
262
|
+
boolean Is the data not representing the full file, but just the initial chunk?
|
|
263
|
+
* @returns the resulting path hash to the resource
|
|
264
|
+
* @example
|
|
265
|
+
* ```lua
|
|
266
|
+
* function init(self)
|
|
267
|
+
* -- create a new sound resource, given the initial chunk of the file
|
|
268
|
+
* local relative_path = "/a/unique/resource/name.oggc"
|
|
269
|
+
* local hash = resource.create_sound_data(relative_path, { data = data, filesize = filesize, partial = true })
|
|
270
|
+
* go.set("#music", "sound", hash) -- override the previous sound resource
|
|
271
|
+
* sound.play("#music") -- start the playing
|
|
272
|
+
* end
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
10
275
|
function create_sound_data(path: string, options?: { data?: string; filesize?: number; partial?: boolean }): Hash;
|
|
276
|
+
/**
|
|
277
|
+
* Creates a new texture resource that can be used in the same way as any texture created during build time.
|
|
278
|
+
* The path used for creating the texture must be unique, trying to create a resource at a path that is already
|
|
279
|
+
* registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
|
|
280
|
+
* function. Also note that the path to the new texture resource must have a '.texturec' extension,
|
|
281
|
+
* meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
|
|
282
|
+
* If the texture is created without a buffer, the pixel data will be blank.
|
|
283
|
+
*
|
|
284
|
+
* @param path - The path to the resource.
|
|
285
|
+
* @param table - A table containing info about how to create the texture. Supported entries:
|
|
286
|
+
`type`
|
|
287
|
+
number The texture type. Supported values:
|
|
288
|
+
- `graphics.TEXTURE_TYPE_2D`
|
|
289
|
+
- `graphics.TEXTURE_TYPE_IMAGE_2D`
|
|
290
|
+
- `graphics.TEXTURE_TYPE_3D`
|
|
291
|
+
- `graphics.TEXTURE_TYPE_IMAGE_3D`
|
|
292
|
+
- `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
293
|
+
`width`
|
|
294
|
+
number The width of the texture (in pixels). Must be larger than 0.
|
|
295
|
+
`height`
|
|
296
|
+
number The width of the texture (in pixels). Must be larger than 0.
|
|
297
|
+
`depth`
|
|
298
|
+
number The depth of the texture (in pixels). Must be larger than 0. Only used when `type` is `graphics.TEXTURE_TYPE_3D` or `graphics.TEXTURE_TYPE_IMAGE_3D`.
|
|
299
|
+
`format`
|
|
300
|
+
number The texture format, note that some of these formats might not be supported by the running device. Supported values:
|
|
301
|
+
- `graphics.TEXTURE_FORMAT_LUMINANCE`
|
|
302
|
+
- `graphics.TEXTURE_FORMAT_RGB`
|
|
303
|
+
- `graphics.TEXTURE_FORMAT_RGBA`
|
|
304
|
+
These constants might not be available on the device:
|
|
305
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
|
|
306
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
|
|
307
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
|
|
308
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
|
|
309
|
+
- `graphics.TEXTURE_FORMAT_RGB_ETC1`
|
|
310
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ETC2`
|
|
311
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
|
|
312
|
+
- `graphics.TEXTURE_FORMAT_RGB_BC1`
|
|
313
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC3`
|
|
314
|
+
- `graphics.TEXTURE_FORMAT_R_BC4`
|
|
315
|
+
- `graphics.TEXTURE_FORMAT_RG_BC5`
|
|
316
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC7`
|
|
317
|
+
- `graphics.TEXTURE_FORMAT_RGB16F`
|
|
318
|
+
- `graphics.TEXTURE_FORMAT_RGB32F`
|
|
319
|
+
- `graphics.TEXTURE_FORMAT_RGBA16F`
|
|
320
|
+
- `graphics.TEXTURE_FORMAT_RGBA32F`
|
|
321
|
+
- `graphics.TEXTURE_FORMAT_R16F`
|
|
322
|
+
- `graphics.TEXTURE_FORMAT_RG16F`
|
|
323
|
+
- `graphics.TEXTURE_FORMAT_R32F`
|
|
324
|
+
- `graphics.TEXTURE_FORMAT_RG32F`
|
|
325
|
+
You can test if the device supports these values by checking if a specific enum is nil or not:
|
|
326
|
+
`if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
|
|
327
|
+
-- it is safe to use this format
|
|
328
|
+
end
|
|
329
|
+
`
|
|
330
|
+
`flags`
|
|
331
|
+
number Texture creation flags that can be used to dictate how the texture is created. The default value is graphics.TEXTURE_USAGE_FLAG_SAMPLE, which means that the texture can be sampled from a shader.
|
|
332
|
+
These flags may or may not be supported on the running device and/or the underlying graphics API and is simply used internally as a 'hint' when creating the texture. There is no guarantee that any of these will have any effect. Supported values:
|
|
333
|
+
- `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
|
|
334
|
+
- `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
|
|
335
|
+
- `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
|
|
336
|
+
`max_mipmaps`
|
|
337
|
+
number optional max number of mipmaps. Defaults to zero, i.e no mipmap support
|
|
338
|
+
`compression_type`
|
|
339
|
+
number optional specify the compression type for the data in the buffer object that holds the texture data. Will only be used when a compressed buffer has been passed into the function.
|
|
340
|
+
Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
|
|
341
|
+
- `COMPRESSION_TYPE_DEFAULT`
|
|
342
|
+
- `COMPRESSION_TYPE_BASIS_UASTC`
|
|
343
|
+
* @param buffer - optional buffer of precreated pixel data
|
|
344
|
+
* @returns The path to the resource.
|
|
345
|
+
3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
|
|
346
|
+
```lua
|
|
347
|
+
if graphics.TEXTURE_TYPE_3D ~= nil then
|
|
348
|
+
-- Device and graphics adapter support 3D textures
|
|
349
|
+
end
|
|
350
|
+
* @example
|
|
351
|
+
* ```lua
|
|
352
|
+
* How to create an 128x128 RGBA texture resource and assign it to a model
|
|
353
|
+
* function init(self)
|
|
354
|
+
* local tparams = {
|
|
355
|
+
* width = 128,
|
|
356
|
+
* height = 128,
|
|
357
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
358
|
+
* format = graphics.TEXTURE_FORMAT_RGBA,
|
|
359
|
+
* }
|
|
360
|
+
* local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams)
|
|
361
|
+
* go.set("#model", "texture0", my_texture_id)
|
|
362
|
+
* end
|
|
363
|
+
* ```How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
|
|
364
|
+
*
|
|
365
|
+
* ```lua
|
|
366
|
+
* function init(self)
|
|
367
|
+
* -- Create a new buffer with 4 components and FLOAT32 type
|
|
368
|
+
* local tbuffer = buffer.create(128 * 128, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
|
|
369
|
+
* local tstream = buffer.get_stream(tbuffer, hash("rgba"))
|
|
370
|
+
*
|
|
371
|
+
* -- Fill the buffer stream with some float values
|
|
372
|
+
* for y=1,128 do
|
|
373
|
+
* for x=1,128 do
|
|
374
|
+
* local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
|
|
375
|
+
* tstream[index + 0] = 999.0
|
|
376
|
+
* tstream[index + 1] = -1.0
|
|
377
|
+
* tstream[index + 2] = 0.5
|
|
378
|
+
* tstream[index + 3] = 1.0
|
|
379
|
+
* end
|
|
380
|
+
* end
|
|
381
|
+
*
|
|
382
|
+
* -- Create a 2D Texture with a RGBA23F format
|
|
383
|
+
* local tparams = {
|
|
384
|
+
* width = 128,
|
|
385
|
+
* height = 128,
|
|
386
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
387
|
+
* format = graphics.TEXTURE_FORMAT_RGBA32F,
|
|
388
|
+
* }
|
|
389
|
+
*
|
|
390
|
+
* -- Note that we pass the buffer as the last argument here!
|
|
391
|
+
* local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer)
|
|
392
|
+
*
|
|
393
|
+
* -- assign the texture to a model
|
|
394
|
+
* go.set("#model", "texture0", my_texture_id)
|
|
395
|
+
* end
|
|
396
|
+
* ```How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
|
|
397
|
+
*
|
|
398
|
+
* ```lua
|
|
399
|
+
* function init(self)
|
|
400
|
+
* local t_volume = resource.create_texture("/my_backing_texture.texturec", {
|
|
401
|
+
* type = graphics.TEXTURE_TYPE_IMAGE_3D,
|
|
402
|
+
* width = 32,
|
|
403
|
+
* height = 32,
|
|
404
|
+
* depth = 32,
|
|
405
|
+
* format = resource.TEXTURE_FORMAT_RGBA32F,
|
|
406
|
+
* flags = resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
|
|
407
|
+
* })
|
|
408
|
+
*
|
|
409
|
+
* -- pass the backing texture to the render script
|
|
410
|
+
* msg.post("@render:", "add_textures", { t_volume })
|
|
411
|
+
* end
|
|
412
|
+
* ```How to create 512x512 texture array with 5 pages.
|
|
413
|
+
*
|
|
414
|
+
* ```lua
|
|
415
|
+
* local new_tex = resource.create_texture("/runtime/example_array.texturec", {
|
|
416
|
+
* type = graphics.TEXTURE_TYPE_2D_ARRAY,
|
|
417
|
+
* width = 512,
|
|
418
|
+
* height = 512,
|
|
419
|
+
* page_count = 5,
|
|
420
|
+
* format = graphics.TEXTURE_FORMAT_RGB,
|
|
421
|
+
* })
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
11
424
|
function create_texture(path: string, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">): Hash;
|
|
425
|
+
/**
|
|
426
|
+
* Creates a new texture resource that can be used in the same way as any texture created during build time.
|
|
427
|
+
* The path used for creating the texture must be unique, trying to create a resource at a path that is already
|
|
428
|
+
* registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
|
|
429
|
+
* function. Also note that the path to the new texture resource must have a '.texturec' extension,
|
|
430
|
+
* meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
|
|
431
|
+
* If the texture is created without a buffer, the pixel data will be blank.
|
|
432
|
+
* The difference between the async version and resource.create_texture is that the texture data will be uploaded
|
|
433
|
+
* in a graphics worker thread. The function will return a resource immediately that contains a 1x1 blank texture which can be used
|
|
434
|
+
* immediately after the function call. When the new texture has been uploaded, the initial blank texture will be deleted and replaced with the
|
|
435
|
+
* new texture. Be careful when using the initial texture handle handle as it will not be valid after the upload has finished.
|
|
436
|
+
*
|
|
437
|
+
* @param path - The path to the resource.
|
|
438
|
+
* @param table - A table containing info about how to create the texture. Supported entries:
|
|
439
|
+
`type`
|
|
440
|
+
number The texture type. Supported values:
|
|
441
|
+
- `graphics.TEXTURE_TYPE_2D`
|
|
442
|
+
- `graphics.TEXTURE_TYPE_IMAGE_2D`
|
|
443
|
+
- `graphics.TEXTURE_TYPE_3D`
|
|
444
|
+
- `graphics.TEXTURE_TYPE_IMAGE_3D`
|
|
445
|
+
- `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
446
|
+
`width`
|
|
447
|
+
number The width of the texture (in pixels). Must be larger than 0.
|
|
448
|
+
`height`
|
|
449
|
+
number The width of the texture (in pixels). Must be larger than 0.
|
|
450
|
+
`depth`
|
|
451
|
+
number The depth of the texture (in pixels). Must be larger than 0. Only used when `type` is `graphics.TEXTURE_TYPE_3D` or `graphics.TEXTURE_TYPE_IMAGE_3D`.
|
|
452
|
+
`format`
|
|
453
|
+
number The texture format, note that some of these formats might not be supported by the running device. Supported values:
|
|
454
|
+
- `graphics.TEXTURE_FORMAT_LUMINANCE`
|
|
455
|
+
- `graphics.TEXTURE_FORMAT_RGB`
|
|
456
|
+
- `graphics.TEXTURE_FORMAT_RGBA`
|
|
457
|
+
These constants might not be available on the device:
|
|
458
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
|
|
459
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
|
|
460
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
|
|
461
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
|
|
462
|
+
- `graphics.TEXTURE_FORMAT_RGB_ETC1`
|
|
463
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ETC2`
|
|
464
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
|
|
465
|
+
- `graphics.TEXTURE_FORMAT_RGB_BC1`
|
|
466
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC3`
|
|
467
|
+
- `graphics.TEXTURE_FORMAT_R_BC4`
|
|
468
|
+
- `graphics.TEXTURE_FORMAT_RG_BC5`
|
|
469
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC7`
|
|
470
|
+
- `graphics.TEXTURE_FORMAT_RGB16F`
|
|
471
|
+
- `graphics.TEXTURE_FORMAT_RGB32F`
|
|
472
|
+
- `graphics.TEXTURE_FORMAT_RGBA16F`
|
|
473
|
+
- `graphics.TEXTURE_FORMAT_RGBA32F`
|
|
474
|
+
- `graphics.TEXTURE_FORMAT_R16F`
|
|
475
|
+
- `graphics.TEXTURE_FORMAT_RG16F`
|
|
476
|
+
- `graphics.TEXTURE_FORMAT_R32F`
|
|
477
|
+
- `graphics.TEXTURE_FORMAT_RG32F`
|
|
478
|
+
You can test if the device supports these values by checking if a specific enum is nil or not:
|
|
479
|
+
`if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
|
|
480
|
+
-- it is safe to use this format
|
|
481
|
+
end
|
|
482
|
+
`
|
|
483
|
+
`flags`
|
|
484
|
+
number Texture creation flags that can be used to dictate how the texture is created. Supported values:
|
|
485
|
+
- `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
|
|
486
|
+
- `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
|
|
487
|
+
- `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
|
|
488
|
+
`max_mipmaps`
|
|
489
|
+
number optional max number of mipmaps. Defaults to zero, i.e no mipmap support
|
|
490
|
+
`compression_type`
|
|
491
|
+
number optional specify the compression type for the data in the buffer object that holds the texture data. Will only be used when a compressed buffer has been passed into the function.
|
|
492
|
+
Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
|
|
493
|
+
- `COMPRESSION_TYPE_DEFAULT`
|
|
494
|
+
- `COMPRESSION_TYPE_BASIS_UASTC`
|
|
495
|
+
* @param buffer - optional buffer of precreated pixel data
|
|
496
|
+
* @param callback - callback function when texture is created (self, request_id, resource)
|
|
497
|
+
* @example
|
|
498
|
+
* ```lua
|
|
499
|
+
* Create a texture resource asyncronously with a buffer and a callback
|
|
500
|
+
* function callback(self, request_id, resource)
|
|
501
|
+
* -- The resource has been updated with a new texture,
|
|
502
|
+
* -- so we can update other systems with the new handle,
|
|
503
|
+
* -- or update components to use the resource if we want
|
|
504
|
+
* local tinfo = resource.get_texture_info(resource)
|
|
505
|
+
* msg.post("@render:", "set_backing_texture", tinfo.handle)
|
|
506
|
+
* end
|
|
507
|
+
* function init(self)
|
|
508
|
+
* -- Create a texture resource async
|
|
509
|
+
* local tparams = {
|
|
510
|
+
* width = 128,
|
|
511
|
+
* height = 128,
|
|
512
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
513
|
+
* format = graphics.TEXTURE_FORMAT_RGBA,
|
|
514
|
+
* }
|
|
515
|
+
*
|
|
516
|
+
* -- Create a new buffer with 4 components
|
|
517
|
+
* local tbuffer = buffer.create(tparams.width * tparams.height, { {name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4} } )
|
|
518
|
+
* local tstream = buffer.get_stream(tbuffer, hash("rgba"))
|
|
519
|
+
*
|
|
520
|
+
* -- Fill the buffer stream with some float values
|
|
521
|
+
* for y=1,tparams.width do
|
|
522
|
+
* for x=1,tparams.height do
|
|
523
|
+
* local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
|
|
524
|
+
* tstream[index + 0] = 255
|
|
525
|
+
* tstream[index + 1] = 0
|
|
526
|
+
* tstream[index + 2] = 255
|
|
527
|
+
* tstream[index + 3] = 255
|
|
528
|
+
* end
|
|
529
|
+
* end
|
|
530
|
+
* -- create the texture
|
|
531
|
+
* local tpath, request_id = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback)
|
|
532
|
+
* -- at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
|
|
533
|
+
* -- that will be removed once the new texture has been updated
|
|
534
|
+
* go.set("#model", "texture0", tpath)
|
|
535
|
+
* end
|
|
536
|
+
* ```Create a texture resource asyncronously without a callback
|
|
537
|
+
*
|
|
538
|
+
* ```lua
|
|
539
|
+
* function init(self)
|
|
540
|
+
* -- Create a texture resource async
|
|
541
|
+
* local tparams = {
|
|
542
|
+
* width = 128,
|
|
543
|
+
* height = 128,
|
|
544
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
545
|
+
* format = graphics.TEXTURE_FORMAT_RGBA,
|
|
546
|
+
* }
|
|
547
|
+
*
|
|
548
|
+
* -- Create a new buffer with 4 components
|
|
549
|
+
* local tbuffer = buffer.create(tparams.width * tparams.height, { {name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4} } )
|
|
550
|
+
* local tstream = buffer.get_stream(tbuffer, hash("rgba"))
|
|
551
|
+
*
|
|
552
|
+
* -- Fill the buffer stream with some float values
|
|
553
|
+
* for y=1,tparams.width do
|
|
554
|
+
* for x=1,tparams.height do
|
|
555
|
+
* local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
|
|
556
|
+
* tstream[index + 0] = 255
|
|
557
|
+
* tstream[index + 1] = 0
|
|
558
|
+
* tstream[index + 2] = 255
|
|
559
|
+
* tstream[index + 3] = 255
|
|
560
|
+
* end
|
|
561
|
+
* end
|
|
562
|
+
* -- create the texture
|
|
563
|
+
* local tpath, request_id = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer)
|
|
564
|
+
* -- at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
|
|
565
|
+
* -- that will be removed once the new texture has been updated
|
|
566
|
+
* go.set("#model", "texture0", tpath)
|
|
567
|
+
* end
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
12
570
|
function create_texture_async(path: string | Hash, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">, callback: (...args: unknown[]) => unknown): LuaMultiReturn<[Hash, number]>;
|
|
571
|
+
/**
|
|
572
|
+
* Constructor-like function with two purposes:
|
|
573
|
+
* - Load the specified resource as part of loading the script
|
|
574
|
+
* - Return a hash to the run-time version of the resource
|
|
575
|
+
* This function can only be called within go.property function calls.
|
|
576
|
+
*
|
|
577
|
+
* @param path - optional resource path string to the resource
|
|
578
|
+
* @returns a path hash to the binary version of the resource
|
|
579
|
+
* @example
|
|
580
|
+
* ```lua
|
|
581
|
+
* Load a font and set it to a label:
|
|
582
|
+
* go.property("my_font", resource.font("/font.font"))
|
|
583
|
+
* function init(self)
|
|
584
|
+
* go.set("#label", "font", self.my_font)
|
|
585
|
+
* end
|
|
586
|
+
*
|
|
587
|
+
* Load a font and set it to a gui:
|
|
588
|
+
* go.property("my_font", resource.font("/font.font"))
|
|
589
|
+
* function init(self)
|
|
590
|
+
* go.set("#gui", "fonts", self.my_font, {key = "my_font"})
|
|
591
|
+
* end
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
13
594
|
function font(path?: string): Hash;
|
|
595
|
+
/**
|
|
596
|
+
* Returns the atlas data for an atlas
|
|
597
|
+
*
|
|
598
|
+
* @param path - The path to the atlas resource
|
|
599
|
+
* @returns A table with the following entries:
|
|
600
|
+
- texture
|
|
601
|
+
- geometries
|
|
602
|
+
- animations
|
|
603
|
+
Each animation entry also contains a `frames` table with indices into
|
|
604
|
+
`geometries`, preserving the frame-to-geometry mapping used by the atlas.
|
|
605
|
+
See resource.set_atlas for a detailed description of each field
|
|
606
|
+
*/
|
|
14
607
|
function get_atlas(path: Hash | string): { texture: string | Hash; animations: { id: string; width: number; height: number; frame_start: number; frame_end: number; playback: Opaque<"constant">; fps: number; flip_vertical: boolean; flip_horizontal: boolean }[]; geometries: Record<string | number, unknown> };
|
|
608
|
+
/**
|
|
609
|
+
* gets the buffer from a resource
|
|
610
|
+
*
|
|
611
|
+
* @param path - The path to the resource
|
|
612
|
+
* @returns The resource buffer
|
|
613
|
+
* @example
|
|
614
|
+
* ```lua
|
|
615
|
+
* How to get the data from a buffer
|
|
616
|
+
* function init(self)
|
|
617
|
+
*
|
|
618
|
+
* local res_path = go.get("#mesh", "vertices")
|
|
619
|
+
* local buf = resource.get_buffer(res_path)
|
|
620
|
+
* local stream_positions = buffer.get_stream(buf, "position")
|
|
621
|
+
*
|
|
622
|
+
* for i=1,#stream_positions do
|
|
623
|
+
* print(i, stream_positions[i])
|
|
624
|
+
* end
|
|
625
|
+
* end
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
15
628
|
function get_buffer(path: Hash | string): Opaque<"buffer">;
|
|
629
|
+
/**
|
|
630
|
+
* Gets render target info from a render target resource path or a render target handle
|
|
631
|
+
*
|
|
632
|
+
* @param path - The path to the resource or a render target handle
|
|
633
|
+
* @returns A table containing info about the render target:
|
|
634
|
+
`handle`
|
|
635
|
+
number the opaque handle to the texture resource
|
|
636
|
+
'attachments'
|
|
637
|
+
table a table of attachments, where each attachment contains the following entries:
|
|
638
|
+
`width`
|
|
639
|
+
number width of the texture
|
|
640
|
+
`height`
|
|
641
|
+
number height of the texture
|
|
642
|
+
`depth`
|
|
643
|
+
number depth of the texture (i.e 1 for a 2D texture and 6 for a cube map)
|
|
644
|
+
`mipmaps`
|
|
645
|
+
number number of mipmaps of the texture
|
|
646
|
+
`type`
|
|
647
|
+
number The texture type. Supported values:
|
|
648
|
+
- `graphics.TEXTURE_TYPE_2D`
|
|
649
|
+
- `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
650
|
+
- `graphics.TEXTURE_TYPE_2D_ARRAY`
|
|
651
|
+
`buffer_type`
|
|
652
|
+
number The attachment buffer type. Supported values:
|
|
653
|
+
- `resource.BUFFER_TYPE_COLOR0`
|
|
654
|
+
- `resource.BUFFER_TYPE_COLOR1`
|
|
655
|
+
- `resource.BUFFER_TYPE_COLOR2`
|
|
656
|
+
- `resource.BUFFER_TYPE_COLOR3`
|
|
657
|
+
- `resource.BUFFER_TYPE_DEPTH`
|
|
658
|
+
-
|
|
659
|
+
`resource.BUFFER_TYPE_STENCIL`
|
|
660
|
+
-
|
|
661
|
+
`texture`
|
|
662
|
+
hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
|
|
663
|
+
* @example
|
|
664
|
+
* ```lua
|
|
665
|
+
* Get the metadata from a render target resource
|
|
666
|
+
* function init(self)
|
|
667
|
+
* local info = resource.get_render_target_info("/my_render_target.render_targetc")
|
|
668
|
+
* -- the info table contains meta data about all the render target attachments
|
|
669
|
+
* -- so it's not necessary to use resource.get_texture here, but we do it here
|
|
670
|
+
* -- just to show that it's possible:
|
|
671
|
+
* local info_attachment_1 = resource.get_texture_info(info.attachments[1].handle)
|
|
672
|
+
* end
|
|
673
|
+
* ```Get a texture attachment from a render target and set it on a model component
|
|
674
|
+
*
|
|
675
|
+
* ```lua
|
|
676
|
+
* function init(self)
|
|
677
|
+
* local info = resource.get_render_target_info("/my_render_target.render_targetc")
|
|
678
|
+
* local attachment = info.attachments[1].texture
|
|
679
|
+
* -- you can also get texture info from the 'texture' field, since it's a resource hash
|
|
680
|
+
* local texture_info = resource.get_texture_info(attachment)
|
|
681
|
+
* go.set("#model", "texture0", attachment)
|
|
682
|
+
* end
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
16
685
|
function get_render_target_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; mipmaps: number; type: number; buffer_type: number; texture: Hash };
|
|
686
|
+
/**
|
|
687
|
+
* Gets the text metrics from a font
|
|
688
|
+
*
|
|
689
|
+
* @param url - the font to get the (unscaled) metrics from
|
|
690
|
+
* @param text - text to measure
|
|
691
|
+
* @param options - A table containing parameters for the text. Supported entries:
|
|
692
|
+
`width`
|
|
693
|
+
number The width of the text field. Not used if `line_break` is false.
|
|
694
|
+
`leading`
|
|
695
|
+
number The leading (default 1.0)
|
|
696
|
+
`tracking`
|
|
697
|
+
number The tracking (default 0.0)
|
|
698
|
+
`line_break`
|
|
699
|
+
boolean If the calculation should consider line breaks (default false)
|
|
700
|
+
* @returns a table with the following fields:
|
|
701
|
+
- width
|
|
702
|
+
- height
|
|
703
|
+
- max_ascent
|
|
704
|
+
- max_descent
|
|
705
|
+
* @example
|
|
706
|
+
* ```lua
|
|
707
|
+
* function init(self)
|
|
708
|
+
* local font = go.get("#label", "font")
|
|
709
|
+
* local metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog")
|
|
710
|
+
* pprint(metrics)
|
|
711
|
+
* end
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
17
714
|
function get_text_metrics(url: Hash, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): Record<string | number, unknown>;
|
|
715
|
+
/**
|
|
716
|
+
* Gets texture info from a texture resource path or a texture handle
|
|
717
|
+
*
|
|
718
|
+
* @param path - The path to the resource or a texture handle
|
|
719
|
+
* @returns A table containing info about the texture:
|
|
720
|
+
`handle`
|
|
721
|
+
number the opaque handle to the texture resource
|
|
722
|
+
`width`
|
|
723
|
+
number width of the texture
|
|
724
|
+
`height`
|
|
725
|
+
number height of the texture
|
|
726
|
+
`depth`
|
|
727
|
+
number depth of the texture (i.e 1 for a 2D texture, 6 for a cube map, the actual depth of a 3D texture)
|
|
728
|
+
`page_count`
|
|
729
|
+
number number of pages of the texture array. For 2D texture value is 1. For cube map - 6
|
|
730
|
+
`mipmaps`
|
|
731
|
+
number number of mipmaps of the texture
|
|
732
|
+
`flags`
|
|
733
|
+
number usage hints of the texture.
|
|
734
|
+
`type`
|
|
735
|
+
number The texture type. Supported values:
|
|
736
|
+
- `graphics.TEXTURE_TYPE_2D`
|
|
737
|
+
- `graphics.TEXTURE_TYPE_2D_ARRAY`
|
|
738
|
+
- `graphics.TEXTURE_TYPE_IMAGE_2D`
|
|
739
|
+
- `graphics.TEXTURE_TYPE_3D`
|
|
740
|
+
- `graphics.TEXTURE_TYPE_IMAGE_3D`
|
|
741
|
+
- `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
742
|
+
* @example
|
|
743
|
+
* ```lua
|
|
744
|
+
* Create a new texture and get the metadata from it
|
|
745
|
+
* function init(self)
|
|
746
|
+
* -- create an empty texture
|
|
747
|
+
* local tparams = {
|
|
748
|
+
* width = 128,
|
|
749
|
+
* height = 128,
|
|
750
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
751
|
+
* format = graphics.TEXTURE_FORMAT_RGBA,
|
|
752
|
+
* }
|
|
753
|
+
*
|
|
754
|
+
* local my_texture_path = resource.create_texture("/my_texture.texturec", tparams)
|
|
755
|
+
* local my_texture_info = resource.get_texture_info(my_texture_path)
|
|
756
|
+
*
|
|
757
|
+
* -- my_texture_info now contains
|
|
758
|
+
* -- {
|
|
759
|
+
* -- handle = <the-numeric-handle>,
|
|
760
|
+
* -- width = 128,
|
|
761
|
+
* -- height = 128,
|
|
762
|
+
* -- depth = 1
|
|
763
|
+
* -- mipmaps = 1,
|
|
764
|
+
* -- page_count = 1,
|
|
765
|
+
* -- type = graphics.TEXTURE_TYPE_2D,
|
|
766
|
+
* -- flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
|
|
767
|
+
* -- }
|
|
768
|
+
* end
|
|
769
|
+
* ```Get the meta data from an atlas resource
|
|
770
|
+
*
|
|
771
|
+
* ```lua
|
|
772
|
+
* function init(self)
|
|
773
|
+
* local my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc")
|
|
774
|
+
* local my_texture_info = resource.get_texture_info(my_atlas_info.texture)
|
|
775
|
+
*
|
|
776
|
+
* -- my_texture_info now contains the information about the texture that is backing the atlas
|
|
777
|
+
* end
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
18
780
|
function get_texture_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; page_count: number; mipmaps: number; flags: number; type: number };
|
|
781
|
+
/**
|
|
782
|
+
* Loads the resource data for a specific resource.
|
|
783
|
+
*
|
|
784
|
+
* @param path - The path to the resource
|
|
785
|
+
* @returns Returns the buffer stored on disc
|
|
786
|
+
* @example
|
|
787
|
+
* ```lua
|
|
788
|
+
* -- read custom resource data into buffer
|
|
789
|
+
* local buffer = resource.load("/resources/datafile")
|
|
790
|
+
*
|
|
791
|
+
* In order for the engine to include custom resources in the build process, you need
|
|
792
|
+
* to specify them in the "game.project" settings file:
|
|
793
|
+
* [project]
|
|
794
|
+
* title = My project
|
|
795
|
+
* version = 0.1
|
|
796
|
+
* custom_resources = resources/,assets/level_data.json
|
|
797
|
+
* ```
|
|
798
|
+
*/
|
|
19
799
|
function load(path: string): Opaque<"buffer">;
|
|
800
|
+
/**
|
|
801
|
+
* Constructor-like function with two purposes:
|
|
802
|
+
* - Load the specified resource as part of loading the script
|
|
803
|
+
* - Return a hash to the run-time version of the resource
|
|
804
|
+
* This function can only be called within go.property function calls.
|
|
805
|
+
*
|
|
806
|
+
* @param path - optional resource path string to the resource
|
|
807
|
+
* @returns a path hash to the binary version of the resource
|
|
808
|
+
* @example
|
|
809
|
+
* ```lua
|
|
810
|
+
* Load a material and set it to a sprite:
|
|
811
|
+
* go.property("my_material", resource.material("/material.material"))
|
|
812
|
+
* function init(self)
|
|
813
|
+
* go.set("#sprite", "material", self.my_material)
|
|
814
|
+
* end
|
|
815
|
+
*
|
|
816
|
+
* Load a material resource and update a named material with the resource:
|
|
817
|
+
* go.property("my_material", resource.material("/material.material"))
|
|
818
|
+
* function init(self)
|
|
819
|
+
* go.set("#gui", "materials", self.my_material, {key = "my_material"})
|
|
820
|
+
* end
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
20
823
|
function material(path?: string): Hash;
|
|
824
|
+
/**
|
|
825
|
+
* Release a resource.
|
|
826
|
+
* This is a potentially dangerous operation, releasing resources currently being used can cause unexpected behaviour.
|
|
827
|
+
*
|
|
828
|
+
* @param path - The path to the resource.
|
|
829
|
+
*/
|
|
21
830
|
function release(path: Hash | string): void;
|
|
831
|
+
/**
|
|
832
|
+
* Constructor-like function with two purposes:
|
|
833
|
+
* - Load the specified resource as part of loading the script
|
|
834
|
+
* - Return a hash to the run-time version of the resource
|
|
835
|
+
* This function can only be called within go.property function calls.
|
|
836
|
+
*
|
|
837
|
+
* @param path - optional resource path string to the resource
|
|
838
|
+
* @returns a path hash to the binary version of the resource
|
|
839
|
+
* @example
|
|
840
|
+
* ```lua
|
|
841
|
+
* Set a render target color attachment as a model texture:
|
|
842
|
+
* go.property("my_render_target", resource.render_target("/rt.render_target"))
|
|
843
|
+
* function init(self)
|
|
844
|
+
* local rt_info = resource.get_render_target_info(self.my_render_target)
|
|
845
|
+
* go.set("#model", "texture0", rt_info.attachments[1].texture)
|
|
846
|
+
* end
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
22
849
|
function render_target(path?: string): Hash;
|
|
850
|
+
/**
|
|
851
|
+
* Sets the resource data for a specific resource
|
|
852
|
+
*
|
|
853
|
+
* @param path - The path to the resource
|
|
854
|
+
* @param buffer - The buffer of precreated data, suitable for the intended resource type
|
|
855
|
+
* @example
|
|
856
|
+
* ```lua
|
|
857
|
+
* Assuming the folder "/res" is added to the project custom resources:
|
|
858
|
+
* -- load a texture resource and set it on a sprite
|
|
859
|
+
* local buffer = resource.load("/res/new.texturec")
|
|
860
|
+
* resource.set(go.get("#sprite", "texture0"), buffer)
|
|
861
|
+
* ```
|
|
862
|
+
*/
|
|
23
863
|
function set(path: string | Hash, buffer: Opaque<"buffer">): void;
|
|
864
|
+
/**
|
|
865
|
+
* Sets the data for a specific atlas resource. Setting new atlas data is specified by passing in
|
|
866
|
+
* a texture path for the backing texture of the atlas, a list of geometries and a list of animations
|
|
867
|
+
* that map to the entries in the geometry list. The geometry entries are represented by three lists:
|
|
868
|
+
* vertices, uvs and indices that together represent triangles that are used in other parts of the
|
|
869
|
+
* engine to produce render objects from.
|
|
870
|
+
* Vertex and uv coordinates for the geometries are expected to be
|
|
871
|
+
* in pixel coordinates where 0,0 is the top left corner of the texture.
|
|
872
|
+
* There is no automatic padding or margin support when setting custom data,
|
|
873
|
+
* which could potentially cause filtering artifacts if used with a material sampler that has linear filtering.
|
|
874
|
+
* If that is an issue, you need to calculate padding and margins manually before passing in the geometry data to
|
|
875
|
+
* this function.
|
|
876
|
+
*
|
|
877
|
+
* @param path - The path to the atlas resource
|
|
878
|
+
* @param table - A table containing info about the atlas. Supported entries:
|
|
879
|
+
-
|
|
880
|
+
`texture`
|
|
881
|
+
string | hash the path to the texture resource, e.g "/main/my_texture.texturec"
|
|
882
|
+
-
|
|
883
|
+
`animations`
|
|
884
|
+
table a list of the animations in the atlas. Supports the following fields:
|
|
885
|
+
-
|
|
886
|
+
`id`
|
|
887
|
+
string the id of the animation, used in e.g sprite.play_animation
|
|
888
|
+
-
|
|
889
|
+
`width`
|
|
890
|
+
number the width of the animation
|
|
891
|
+
-
|
|
892
|
+
`height`
|
|
893
|
+
number the height of the animation
|
|
894
|
+
-
|
|
895
|
+
`frame_start`
|
|
896
|
+
number index to the first geometry of the animation. Indices are lua based and must be in the range of 1 .. in atlas.
|
|
897
|
+
-
|
|
898
|
+
`frame_end`
|
|
899
|
+
number index to the last geometry of the animation (non-inclusive). Indices are lua based and must be in the range of 1 .. in atlas.
|
|
900
|
+
-
|
|
901
|
+
`playback`
|
|
902
|
+
constant optional playback mode of the animation, the default value is go.PLAYBACK_ONCE_FORWARD
|
|
903
|
+
-
|
|
904
|
+
`fps`
|
|
905
|
+
number optional fps of the animation, the default value is 30
|
|
906
|
+
-
|
|
907
|
+
`flip_vertical`
|
|
908
|
+
boolean optional flip the animation vertically, the default value is false
|
|
909
|
+
-
|
|
910
|
+
`flip_horizontal`
|
|
911
|
+
boolean optional flip the animation horizontally, the default value is false
|
|
912
|
+
-
|
|
913
|
+
`geometries`
|
|
914
|
+
table A list of the geometries that should map to the texture data. Supports the following fields:
|
|
915
|
+
-
|
|
916
|
+
`vertices`
|
|
917
|
+
table a list of the vertices in texture space of the geometry in the form {px0, py0, px1, py1, ..., pxn, pyn}
|
|
918
|
+
-
|
|
919
|
+
`uvs`
|
|
920
|
+
table a list of the uv coordinates in texture space of the geometry in the form of {u0, v0, u1, v1, ..., un, vn}
|
|
921
|
+
-
|
|
922
|
+
`indices`
|
|
923
|
+
table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
|
|
924
|
+
* @example
|
|
925
|
+
* ```lua
|
|
926
|
+
* Add a new animation to an existing atlas
|
|
927
|
+
* function init(self)
|
|
928
|
+
* local data = resource.get_atlas("/main/my_atlas.a.texturesetc")
|
|
929
|
+
* local my_animation = {
|
|
930
|
+
* id = "my_new_animation",
|
|
931
|
+
* width = 128,
|
|
932
|
+
* height = 128,
|
|
933
|
+
* frame_start = 1,
|
|
934
|
+
* frame_end = 6,
|
|
935
|
+
* playback = go.PLAYBACK_LOOP_PINGPONG,
|
|
936
|
+
* fps = 8
|
|
937
|
+
* }
|
|
938
|
+
* table.insert(data.animations, my_animation)
|
|
939
|
+
* resource.set_atlas("/main/my_atlas.a.texturesetc", data)
|
|
940
|
+
* end
|
|
941
|
+
* ```Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
|
|
942
|
+
*
|
|
943
|
+
* ```lua
|
|
944
|
+
* function init(self)
|
|
945
|
+
* local params = {
|
|
946
|
+
* texture = "/main/my_256x256_texture.texturec",
|
|
947
|
+
* animations = {
|
|
948
|
+
* {
|
|
949
|
+
* id = "my_animation",
|
|
950
|
+
* width = 256,
|
|
951
|
+
* height = 256,
|
|
952
|
+
* frames = { 1 }
|
|
953
|
+
* }
|
|
954
|
+
* },
|
|
955
|
+
* geometries = {
|
|
956
|
+
* {
|
|
957
|
+
* vertices = {
|
|
958
|
+
* 0, 0,
|
|
959
|
+
* 0, 256,
|
|
960
|
+
* 256, 256,
|
|
961
|
+
* 256, 0
|
|
962
|
+
* },
|
|
963
|
+
* uvs = {
|
|
964
|
+
* 0, 0,
|
|
965
|
+
* 0, 256,
|
|
966
|
+
* 256, 256,
|
|
967
|
+
* 256, 0
|
|
968
|
+
* },
|
|
969
|
+
* indices = { 0,1,2,0,2,3 }
|
|
970
|
+
* }
|
|
971
|
+
* }
|
|
972
|
+
* }
|
|
973
|
+
* resource.set_atlas("/main/test.a.texturesetc", params)
|
|
974
|
+
* end
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
24
977
|
function set_atlas(path: Hash | string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: Record<string | number, unknown>; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
|
|
978
|
+
/**
|
|
979
|
+
* Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object
|
|
980
|
+
* to the buffer stored in the destination resource, or make a new buffer object if the sizes between the source buffer and the destination buffer
|
|
981
|
+
* stored in the resource differs. In some cases, e.g performance reasons, it might be beneficial to just set the buffer object on the resource without copying or cloning.
|
|
982
|
+
* To achieve this, set the `transfer_ownership` flag to true in the argument table. Transferring ownership from a lua buffer to a resource with this function
|
|
983
|
+
* works exactly the same as resource.create_buffer: the destination resource will take ownership of the buffer held by the lua reference, i.e the buffer will not automatically be removed
|
|
984
|
+
* when the lua reference to the buffer is garbage collected.
|
|
985
|
+
* Note: When setting a buffer with `transfer_ownership = true`, the currently bound buffer in the resource will be destroyed.
|
|
986
|
+
*
|
|
987
|
+
* @param path - The path to the resource
|
|
988
|
+
* @param buffer - The resource buffer
|
|
989
|
+
* @param table - A table containing info about how to set the buffer. Supported entries:
|
|
990
|
+
-
|
|
991
|
+
`transfer_ownership`
|
|
992
|
+
boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default false)
|
|
993
|
+
* @example
|
|
994
|
+
* ```lua
|
|
995
|
+
* How to set the data from a buffer
|
|
996
|
+
* local function fill_stream(stream, verts)
|
|
997
|
+
* for key, value in ipairs(verts) do
|
|
998
|
+
* stream[key] = verts[key]
|
|
999
|
+
* end
|
|
1000
|
+
* end
|
|
1001
|
+
*
|
|
1002
|
+
* function init(self)
|
|
1003
|
+
*
|
|
1004
|
+
* local res_path = go.get("#mesh", "vertices")
|
|
1005
|
+
*
|
|
1006
|
+
* local positions = {
|
|
1007
|
+
* 1, -1, 0,
|
|
1008
|
+
* 1, 1, 0,
|
|
1009
|
+
* -1, -1, 0
|
|
1010
|
+
* }
|
|
1011
|
+
*
|
|
1012
|
+
* local num_verts = #positions / 3
|
|
1013
|
+
*
|
|
1014
|
+
* -- create a new buffer
|
|
1015
|
+
* local buf = buffer.create(num_verts, {
|
|
1016
|
+
* { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 }
|
|
1017
|
+
* })
|
|
1018
|
+
*
|
|
1019
|
+
* local buf = resource.get_buffer(res_path)
|
|
1020
|
+
* local stream_positions = buffer.get_stream(buf, "position")
|
|
1021
|
+
*
|
|
1022
|
+
* fill_stream(stream_positions, positions)
|
|
1023
|
+
*
|
|
1024
|
+
* resource.set_buffer(res_path, buf)
|
|
1025
|
+
* end
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
25
1028
|
function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: { transfer_ownership?: boolean }): void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Update internal sound resource (wavc/oggc/opusc) with new data
|
|
1031
|
+
*
|
|
1032
|
+
* @param path - The path to the resource
|
|
1033
|
+
* @param buffer - A lua string containing the binary sound data
|
|
1034
|
+
*/
|
|
26
1035
|
function set_sound(path: Hash | string, buffer: string): void;
|
|
1036
|
+
/**
|
|
1037
|
+
* Sets the pixel data for a specific texture.
|
|
1038
|
+
*
|
|
1039
|
+
* @param path - The path to the resource
|
|
1040
|
+
* @param table - A table containing info about the texture. Supported entries:
|
|
1041
|
+
`type`
|
|
1042
|
+
number The texture type. Supported values:
|
|
1043
|
+
- `graphics.TEXTURE_TYPE_2D`
|
|
1044
|
+
- `graphics.TEXTURE_TYPE_IMAGE_2D`
|
|
1045
|
+
- `graphics.TEXTURE_TYPE_3D`
|
|
1046
|
+
- `graphics.TEXTURE_TYPE_IMAGE_3D`
|
|
1047
|
+
- `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
1048
|
+
`width`
|
|
1049
|
+
number The width of the texture (in pixels)
|
|
1050
|
+
`height`
|
|
1051
|
+
number The width of the texture (in pixels)
|
|
1052
|
+
`format`
|
|
1053
|
+
number The texture format, note that some of these formats are platform specific. Supported values:
|
|
1054
|
+
- `graphics.TEXTURE_FORMAT_LUMINANCE`
|
|
1055
|
+
- `graphics.TEXTURE_FORMAT_RGB`
|
|
1056
|
+
- `graphics.TEXTURE_FORMAT_RGBA`
|
|
1057
|
+
These constants might not be available on the device:
|
|
1058
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
|
|
1059
|
+
- `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
|
|
1060
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
|
|
1061
|
+
- `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
|
|
1062
|
+
- `graphics.TEXTURE_FORMAT_RGB_ETC1`
|
|
1063
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ETC2`
|
|
1064
|
+
- `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
|
|
1065
|
+
- `graphics.TEXTURE_FORMAT_RGB_BC1`
|
|
1066
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC3`
|
|
1067
|
+
- `graphics.TEXTURE_FORMAT_R_BC4`
|
|
1068
|
+
- `graphics.TEXTURE_FORMAT_RG_BC5`
|
|
1069
|
+
- `graphics.TEXTURE_FORMAT_RGBA_BC7`
|
|
1070
|
+
- `graphics.TEXTURE_FORMAT_RGB16F`
|
|
1071
|
+
- `graphics.TEXTURE_FORMAT_RGB32F`
|
|
1072
|
+
- `graphics.TEXTURE_FORMAT_RGBA16F`
|
|
1073
|
+
- `graphics.TEXTURE_FORMAT_RGBA32F`
|
|
1074
|
+
- `graphics.TEXTURE_FORMAT_R16F`
|
|
1075
|
+
- `graphics.TEXTURE_FORMAT_RG16F`
|
|
1076
|
+
- `graphics.TEXTURE_FORMAT_R32F`
|
|
1077
|
+
- `graphics.TEXTURE_FORMAT_RG32F`
|
|
1078
|
+
You can test if the device supports these values by checking if a specific enum is nil or not:
|
|
1079
|
+
`if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
|
|
1080
|
+
-- it is safe to use this format
|
|
1081
|
+
end
|
|
1082
|
+
`
|
|
1083
|
+
`x`
|
|
1084
|
+
number optional x offset of the texture (in pixels)
|
|
1085
|
+
`y`
|
|
1086
|
+
number optional y offset of the texture (in pixels)
|
|
1087
|
+
`z`
|
|
1088
|
+
number optional z offset of the texture (in pixels). Only applies to 3D textures
|
|
1089
|
+
`page`
|
|
1090
|
+
number optional slice of the array texture. Only applies to 2D texture arrays. Zero-based
|
|
1091
|
+
`mipmap`
|
|
1092
|
+
number optional mipmap to upload the data to
|
|
1093
|
+
`compression_type`
|
|
1094
|
+
number optional specify the compression type for the data in the buffer object that holds the texture data. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
|
|
1095
|
+
- `COMPRESSION_TYPE_DEFAULT`
|
|
1096
|
+
- `COMPRESSION_TYPE_BASIS_UASTC`
|
|
1097
|
+
* @param buffer - The buffer of precreated pixel data
|
|
1098
|
+
To update a cube map texture you need to pass in six times the amount of data via the buffer, since a cube map has six sides!
|
|
1099
|
+
3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
|
|
1100
|
+
```lua
|
|
1101
|
+
if graphics.TEXTURE_TYPE_3D ~= nil then
|
|
1102
|
+
-- Device and graphics adapter support 3D textures
|
|
1103
|
+
end
|
|
1104
|
+
* @example
|
|
1105
|
+
* ```lua
|
|
1106
|
+
* How to set all pixels of an atlas
|
|
1107
|
+
* function init(self)
|
|
1108
|
+
* self.height = 128
|
|
1109
|
+
* self.width = 128
|
|
1110
|
+
* self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
|
|
1111
|
+
* self.stream = buffer.get_stream(self.buffer, hash("rgb"))
|
|
1112
|
+
*
|
|
1113
|
+
* for y=1,self.height do
|
|
1114
|
+
* for x=1,self.width do
|
|
1115
|
+
* local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
|
|
1116
|
+
* self.stream[index + 0] = 0xff
|
|
1117
|
+
* self.stream[index + 1] = 0x80
|
|
1118
|
+
* self.stream[index + 2] = 0x10
|
|
1119
|
+
* end
|
|
1120
|
+
* end
|
|
1121
|
+
*
|
|
1122
|
+
* local resource_path = go.get("#model", "texture0")
|
|
1123
|
+
* local args = { width=self.width, height=self.height, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
|
|
1124
|
+
* resource.set_texture( resource_path, args, self.buffer )
|
|
1125
|
+
* end
|
|
1126
|
+
* ```How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
|
|
1127
|
+
*
|
|
1128
|
+
* ```lua
|
|
1129
|
+
* function init(self)
|
|
1130
|
+
* self.x = 16
|
|
1131
|
+
* self.y = 16
|
|
1132
|
+
* self.height = 128 - self.x * 2
|
|
1133
|
+
* self.width = 128 - self.y * 2
|
|
1134
|
+
* self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
|
|
1135
|
+
* self.stream = buffer.get_stream(self.buffer, hash("rgb"))
|
|
1136
|
+
*
|
|
1137
|
+
* for y=1,self.height do
|
|
1138
|
+
* for x=1,self.width do
|
|
1139
|
+
* local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
|
|
1140
|
+
* self.stream[index + 0] = 0xff
|
|
1141
|
+
* self.stream[index + 1] = 0x80
|
|
1142
|
+
* self.stream[index + 2] = 0x10
|
|
1143
|
+
* end
|
|
1144
|
+
* end
|
|
1145
|
+
*
|
|
1146
|
+
* local resource_path = go.get("#model", "texture0")
|
|
1147
|
+
* local args = { width=self.width, height=self.height, x=self.x, y=self.y, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
|
|
1148
|
+
* resource.set_texture(resource_path, args, self.buffer )
|
|
1149
|
+
* end
|
|
1150
|
+
* ```Update a texture from a buffer resource
|
|
1151
|
+
* ```lua
|
|
1152
|
+
* go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"))
|
|
1153
|
+
*
|
|
1154
|
+
* function init(self)
|
|
1155
|
+
* local resource_path = go.get("#model", "texture0")
|
|
1156
|
+
* -- the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
|
|
1157
|
+
* local args = {
|
|
1158
|
+
* width = 128,
|
|
1159
|
+
* height = 128,
|
|
1160
|
+
* type = graphics.TEXTURE_TYPE_2D,
|
|
1161
|
+
* format = graphics.TEXTURE_FORMAT_RGB
|
|
1162
|
+
* }
|
|
1163
|
+
* -- Note that the extra resource.get_buffer call is a requirement here
|
|
1164
|
+
* -- since the "self.my_buffer" is just pointing to a buffer resource path
|
|
1165
|
+
* -- and not an actual buffer object or buffer resource.
|
|
1166
|
+
* resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer))
|
|
1167
|
+
* end
|
|
1168
|
+
* ```Update an existing 3D texture from a lua buffer
|
|
1169
|
+
*
|
|
1170
|
+
* ```lua
|
|
1171
|
+
*
|
|
1172
|
+
* function init(self)
|
|
1173
|
+
* -- create a buffer that can hold the data of a 8x8x8 texture
|
|
1174
|
+
* local tbuffer = buffer.create(8 * 8 * 8, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
|
|
1175
|
+
* local tstream = buffer.get_stream(tbuffer, hash("rgba"))
|
|
1176
|
+
*
|
|
1177
|
+
* -- populate the buffer with some data
|
|
1178
|
+
* local index = 1
|
|
1179
|
+
* for z=1,8 do
|
|
1180
|
+
* for y=1,8 do
|
|
1181
|
+
* for x=1,8 do
|
|
1182
|
+
* tstream[index + 0] = x
|
|
1183
|
+
* tstream[index + 1] = y
|
|
1184
|
+
* tstream[index + 2] = z
|
|
1185
|
+
* tstream[index + 3] = 1.0
|
|
1186
|
+
* index = index + 4
|
|
1187
|
+
* end
|
|
1188
|
+
* end
|
|
1189
|
+
* end
|
|
1190
|
+
*
|
|
1191
|
+
* local t_args = {
|
|
1192
|
+
* type = graphics.TEXTURE_TYPE_IMAGE_3D,
|
|
1193
|
+
* width = 8,
|
|
1194
|
+
* height = 8,
|
|
1195
|
+
* depth = 8,
|
|
1196
|
+
* format = resource.TEXTURE_FORMAT_RGBA32F
|
|
1197
|
+
* }
|
|
1198
|
+
*
|
|
1199
|
+
* -- This expects that the texture resource "/my_3d_texture.texturec" already exists
|
|
1200
|
+
* -- and is a 3D texture resource. To create a dynamic 3D texture resource
|
|
1201
|
+
* -- use the "resource.create_texture" function.
|
|
1202
|
+
* resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer)
|
|
1203
|
+
* endUpdate texture 2nd array page with loaded texture from png
|
|
1204
|
+
*
|
|
1205
|
+
* ```lua
|
|
1206
|
+
* -- new_tex is resource handle of texture which was created via resource.create_resource
|
|
1207
|
+
* local tex_path = "/bundle_resources/page_02.png"
|
|
1208
|
+
* local data = sys.load_resource(tex_path)
|
|
1209
|
+
* local buf = image.load_buffer(data)
|
|
1210
|
+
* resource.set_texture(new_tex, {
|
|
1211
|
+
* type = graphics.TEXTURE_TYPE_2D_ARRAY,
|
|
1212
|
+
* width = buf.width,
|
|
1213
|
+
* height = buf.height,
|
|
1214
|
+
* page = 1,
|
|
1215
|
+
* format = graphics.TEXTURE_FORMAT_RGB
|
|
1216
|
+
* }, buf.buffer)
|
|
1217
|
+
* go.set("#mesh", "texture0", new_tex)
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
27
1220
|
function set_texture(path: Hash | string, table: { type?: number; width?: number; height?: number; format?: number; x?: number; y?: number; z?: number; page?: number; mipmap?: number; compression_type?: number }, buffer: Opaque<"buffer">): void;
|
|
1221
|
+
/**
|
|
1222
|
+
* Constructor-like function with two purposes:
|
|
1223
|
+
* - Load the specified resource as part of loading the script
|
|
1224
|
+
* - Return a hash to the run-time version of the resource
|
|
1225
|
+
* This function can only be called within go.property function calls.
|
|
1226
|
+
*
|
|
1227
|
+
* @param path - optional resource path string to the resource
|
|
1228
|
+
* @returns a path hash to the binary version of the resource
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```lua
|
|
1231
|
+
* Load a texture and set it to a model:
|
|
1232
|
+
* go.property("my_texture", resource.texture("/texture.png"))
|
|
1233
|
+
* function init(self)
|
|
1234
|
+
* go.set("#model", "texture0", self.my_texture)
|
|
1235
|
+
* end
|
|
1236
|
+
* ```
|
|
1237
|
+
*/
|
|
28
1238
|
function texture(path?: string): Hash;
|
|
1239
|
+
/**
|
|
1240
|
+
* Constructor-like function with two purposes:
|
|
1241
|
+
* - Load the specified resource as part of loading the script
|
|
1242
|
+
* - Return a hash to the run-time version of the resource
|
|
1243
|
+
* This function can only be called within go.property function calls.
|
|
1244
|
+
*
|
|
1245
|
+
* @param path - optional resource path string to the resource
|
|
1246
|
+
* @returns a path hash to the binary version of the resource
|
|
1247
|
+
* @example
|
|
1248
|
+
* ```lua
|
|
1249
|
+
* Load tile source and set it to a tile map:
|
|
1250
|
+
* go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"))
|
|
1251
|
+
* function init(self)
|
|
1252
|
+
* go.set("#tilemap", "tile_source", self.my_tile_source)
|
|
1253
|
+
* end
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
29
1256
|
function tile_source(path?: string): Hash;
|
|
30
1257
|
}
|
|
31
1258
|
}
|