Skip to main content

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

NameType
Textends TextureOptions = TextureOptions

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Texture<T>(renderer, options?, needsUpdate?): Texture<T>

Type parameters

NameType
Textends TextureOptions = TextureOptions

Parameters

NameTypeDefault valueDescription
rendererRendererundefinedRenderer 对象
optionsPartial<T>{}配置项
needsUpdatebooleantrue是否需要update

Returns

Texture<T>

Overrides

Resource.constructor

Defined in

src/core/Texture.ts:180

Properties

renderer

renderer: Renderer

Inherited from

Resource.renderer

Defined in

src/core/Base.ts:7


id

id: string

Inherited from

Resource.id

Defined in

src/core/Resource.ts:21


name

name: WithUndef<string>

Inherited from

Resource.name

Defined in

src/core/Resource.ts:23


userData

userData: any

Inherited from

Resource.userData

Defined in

src/core/Resource.ts:25


byteLength

byteLength: number

Inherited from

Resource.byteLength

Defined in

src/core/Resource.ts:28


options

options: Partial<T>

Inherited from

Resource.options

Defined in

src/core/Resource.ts:30


needsUpdate

needsUpdate: boolean = false

设置纹理是否需要更新,一般我们会在纹理数据或者配置变更时将此配置项设置为 true 这样会在下一次渲染时应用对应的纹理数据和配置。

Defined in

src/core/Texture.ts:146


textureUnit

textureUnit: number = 0

设置纹理单位

Defined in

src/core/Texture.ts:151


image

image: any

纹理数据

Defined in

src/core/Texture.ts:156


width

width: number

纹理宽度

Defined in

src/core/Texture.ts:161


height

height: number

纹理高度

Defined in

src/core/Texture.ts:166


target

target: number

texImage2D target

Defined in

src/core/Texture.ts:171

Accessors

gl

get gl(): WebGLRenderingContext | WebGL2RenderingContext

获取 webgl 实例

Returns

WebGLRenderingContext | WebGL2RenderingContext

Inherited from

Resource.gl

Defined in

src/core/Base.ts:16


rendererState

get rendererState(): State

获取渲染状态

Returns

State

Inherited from

Resource.rendererState

Defined in

src/core/Base.ts:23


handle

get handle(): any

Returns

any

Inherited from

Resource.handle

Defined in

src/core/Resource.ts:47

Methods

swapHandle

swapHandle(handle): void

交换为新的 handle(一般我们会用在虚拟 webgl 环境中)

Parameters

NameType
handleany

Returns

void

Inherited from

Resource.swapHandle

Defined in

src/core/Resource.ts:55


restoreHandle

restoreHandle(): void

恢复为原有 handle

Returns

void

Inherited from

Resource.restoreHandle

Defined in

src/core/Resource.ts:63


delete

delete(«destructured»?): Texture<T>

Parameters

NameTypeDefault value
«destructured»Object{}
› deleteChildrenundefined | booleanfalse

Returns

Texture<T>

Inherited from

Resource.delete

Defined in

src/core/Resource.ts:74


setData

setData(image, width?, height?): void

设置纹理数据

Parameters

NameTypeDescription
imageany纹理数据
widthnumber纹理宽度,默认为原始宽度
heightnumber纹理高度,默认为原始高度

Returns

void

Defined in

src/core/Texture.ts:219


setOptions

setOptions(options): void

设置纹理配置(默认进行合并)

Parameters

NameTypeDescription
optionsPartial<T>配置项

Returns

void

Defined in

src/core/Texture.ts:230


fromSrc

fromSrc(url): Promise<unknown>

从 Url 设置纹理对象的数据,会默认标记为需要更新 needsUpdate = true

Parameters

NameType
urlstring

Returns

Promise<unknown>

Defined in

src/core/Texture.ts:241


update

update(units?): void

更新纹理数据或者纹理相关配置

Parameters

NameTypeDefault valueDescription
unitsnumber0纹理单位,默认为 0

Returns

void

Defined in

src/core/Texture.ts:260


bind

bind(unit?): void

绑定纹理

Parameters

NameTypeDescription
unitnumber纹理单位,默认为 this.textureUnit

Returns

void

Overrides

Resource.bind

Defined in

src/core/Texture.ts:458


unbind

unbind(): void

解绑纹理

Returns

void

Overrides

Resource.unbind

Defined in

src/core/Texture.ts:468


destroy

destroy(): void

销毁纹理

Returns

void

Overrides

Resource.destroy

Defined in

src/core/Texture.ts:477


removeStats

removeStats(): void

移除相关状态

Returns

void

Overrides

Resource.removeStats

Defined in

src/core/Texture.ts:485


toString

toString(): string

获取字符串数据

Returns

string

Overrides

Resource.toString

Defined in

src/core/Texture.ts:511