Class: Texture<T>
纹理
一般在 webgl
中会将纹理用于贴图,或者作为 renderTarget
代码示例:
const texture = new ve.Texture(renderer, {
generateMipmaps: true,
flipY: true,
});
const image = new Image();
image.onload = () => {
texture.setData(image, image.width, image.height);
};
image.src = './assets/posx.jpg';
Type parameters
Name | Type |
---|---|
T | extends TextureOptions = TextureOptions |
Hierarchy
-
Resource
<T
>↳
Texture
↳↳
Texture3D
↳↳
DataTexture
Table of contents
Constructors
Properties
Accessors
Methods
- swapHandle
- restoreHandle
- delete
- setData
- setOptions
- fromSrc
- update
- bind
- unbind
- destroy
- removeStats
- toString
Constructors
constructor
• new Texture<T
>(renderer
, options?
, needsUpdate?
): Texture
<T
>
Type parameters
Name | Type |
---|---|
T | extends TextureOptions = TextureOptions |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
renderer | Renderer | undefined | Renderer 对象 |
options | Partial <T > | {} | 配置项 |
needsUpdate | boolean | true | 是否需要update |
Returns
Texture
<T
>
Overrides
Defined in
Properties
renderer
• renderer: Renderer
Inherited from
Defined in
id
• id: string
Inherited from
Defined in
name
• name: WithUndef
<string
>
Inherited from
Defined in
userData
• userData: any
Inherited from
Defined in
byteLength
• byteLength: number
Inherited from
Defined in
options
• options: Partial
<T
>
Inherited from
Defined in
needsUpdate
• needsUpdate: boolean
= false
设置纹理是否需要更新,一般我们会在纹理数据或者配置变更时将此配置项设置为 true
这样会在下一次渲染时应用对应的纹理数据和配置。
Defined in
textureUnit
• textureUnit: number
= 0
设置纹理单位
Defined in
image
• image: any
纹理数据
Defined in
width
• width: number
纹理宽度
Defined in
height
• height: number
纹理高度
Defined in
target
• target: number
texImage2D
target
Defined in
Accessors
gl
• get
gl(): WebGLRenderingContext
| WebGL2RenderingContext
获取 webgl
实例
Returns
WebGLRenderingContext
| WebGL2RenderingContext
Inherited from
Resource.gl
Defined in
rendererState
• get
rendererState(): State
获取渲染状态
Returns
Inherited from
Resource.rendererState
Defined in
handle
• get
handle(): any
Returns
any
Inherited from
Resource.handle
Defined in
Methods
swapHandle
▸ swapHandle(handle
): void
交换为新的 handle
(一般我们会用在虚拟 webgl 环境中)
Parameters
Name | Type |
---|---|
handle | any |
Returns
void
Inherited from
Defined in
restoreHandle
▸ restoreHandle(): void
恢复为原有 handle
Returns
void
Inherited from
Defined in
delete
▸ delete(«destructured»?
): Texture
<T
>
Parameters
Name | Type | Default value |
---|---|---|
«destructured» | Object | {} |
› deleteChildren | undefined | boolean | false |
Returns
Texture
<T
>
Inherited from
Defined in
setData
▸ setData(image
, width?
, height?
): void
设置 纹理数据
Parameters
Name | Type | Description |
---|---|---|
image | any | 纹理数据 |
width | number | 纹理宽度,默认为原始宽度 |
height | number | 纹理高度,默认为原始高度 |
Returns
void
Defined in
setOptions
▸ setOptions(options
): void
设置纹理配置(默认进行合并)
Parameters
Name | Type | Description |
---|---|---|
options | Partial <T > | 配置项 |
Returns
void
Defined in
fromSrc
▸ fromSrc(url
): Promise
<unknown
>
从 Url 设置纹理对象的数据,会默认标记为需要更新 needsUpdate = true
Parameters
Name | Type |
---|---|
url | string |
Returns
Promise
<unknown
>
Defined in
update
▸ update(units?
): void
更新纹理数据或者纹理相关配置
Parameters
Name | Type | Default value | Description |
---|---|---|---|
units | number | 0 | 纹理单位,默认为 0 |
Returns
void
Defined in
bind
▸ bind(unit?
): void
绑定纹理
Parameters
Name | Type | Description |
---|---|---|
unit | number | 纹理单位,默认为 this.textureUnit |
Returns
void
Overrides
Defined in
unbind
▸ unbind(): void
解绑纹理
Returns
void
Overrides
Defined in
destroy
▸ destroy(): void
销毁纹理
Returns
void
Overrides
Defined in
removeStats
▸ removeStats(): void
移除相关状态
Returns
void
Overrides
Defined in
toString
▸ toString(): string
获取字符串数据
Returns
string