@predy-js/render-interface 0.1.61-beta.3 → 0.1.61-beta.5
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/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/src/render/MarsMaterialDataBlock.d.ts +4 -1
- package/dist/statistic.js +1 -1
- package/dist/types/Material.d.ts +6 -0
- package/package.json +3 -2
- package/types/Canvas.ts +20 -0
- package/types/GPUBuffer.ts +85 -0
- package/types/GPUCapability.ts +67 -0
- package/types/Geometry.ts +186 -0
- package/types/IGPURenderer.ts +18 -0
- package/types/Material.ts +193 -0
- package/types/Mesh.ts +82 -0
- package/types/RenderFrame.ts +70 -0
- package/types/RenderPass.ts +222 -0
- package/types/Renderer.ts +62 -0
- package/types/ShaderLibrary.ts +128 -0
- package/types/Texture.ts +236 -0
- package/types/constants.ts +7 -0
- package/types/index.ts +37 -0
- package/types/native/DataBlockInternal.ts +35 -0
- package/types/native/GPUBufferInternal.ts +46 -0
- package/types/native/GeometryInternal.ts +55 -0
- package/types/native/ImageBitmapInternal.ts +28 -0
- package/types/native/MaterialInternal.ts +31 -0
- package/types/native/MeshInternal.ts +25 -0
- package/types/native/RenderFrameInternal.ts +34 -0
- package/types/native/RenderPassInternal.ts +69 -0
- package/types/native/RendererInternal.ts +66 -0
- package/types/native/ResourceInternal.ts +12 -0
- package/types/native/ShaderLibraryInternal.ts +19 -0
- package/types/native/TextureInternal.ts +53 -0
- package/types/native/index.ts +12 -0
- package/types/type.ts +30 -0
package/types/Texture.ts
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
import type { IGPURenderer, IGPUResource } from './IGPURenderer';
|
2
|
+
import type { Immutable, TypedArray } from './type';
|
3
|
+
import type { GPURenderer } from './Renderer';
|
4
|
+
|
5
|
+
export enum TextureSourceType {
|
6
|
+
none,
|
7
|
+
data = 1,
|
8
|
+
image = 2,
|
9
|
+
compressed = 3,
|
10
|
+
video = 4,
|
11
|
+
canvas = 5,
|
12
|
+
framebuffer = 6,
|
13
|
+
mipmaps = 7
|
14
|
+
}
|
15
|
+
|
16
|
+
export interface TextureFactorySource2DFrom {
|
17
|
+
type: TextureSourceType.image | TextureSourceType.video,
|
18
|
+
url: string,
|
19
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
20
|
+
}
|
21
|
+
|
22
|
+
export interface TextureFactorySourceFromCompressed {
|
23
|
+
type: TextureSourceType.compressed,
|
24
|
+
url: string,
|
25
|
+
}
|
26
|
+
|
27
|
+
export type TextureFactorySourceCubeFrom = {
|
28
|
+
type: TextureSourceType.image,
|
29
|
+
map: TextureCubeSourceURLMap | string[],
|
30
|
+
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'],
|
31
|
+
};
|
32
|
+
|
33
|
+
type DataRange = [start: number, length: number];
|
34
|
+
|
35
|
+
export type TextureFactorySourceCubeBinaryMipmapsFrom = {
|
36
|
+
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'],
|
37
|
+
type: TextureSourceType.mipmaps,
|
38
|
+
bin: string,
|
39
|
+
mipmaps: Array<[
|
40
|
+
TEXTURE_CUBE_MAP_POSITIVE_X: DataRange,
|
41
|
+
TEXTURE_CUBE_MAP_NEGATIVE_X: DataRange,
|
42
|
+
TEXTURE_CUBE_MAP_POSITIVE_Y: DataRange,
|
43
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Y: DataRange,
|
44
|
+
TEXTURE_CUBE_MAP_POSITIVE_Z: DataRange,
|
45
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Z: DataRange
|
46
|
+
]>,
|
47
|
+
};
|
48
|
+
|
49
|
+
export type TextureFactorySource2DBinaryMipmapsFrom = {
|
50
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
51
|
+
type: TextureSourceType.mipmaps,
|
52
|
+
bin: string,
|
53
|
+
mipmaps: Array<DataRange>,
|
54
|
+
};
|
55
|
+
|
56
|
+
export interface TextureFactorySourceCubeMipmapsFrom {
|
57
|
+
type: TextureSourceType.mipmaps,
|
58
|
+
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'],
|
59
|
+
maps: TextureCubeSourceURLMap[] | string[][],
|
60
|
+
}
|
61
|
+
|
62
|
+
export interface TextureFactorySource2DMipmapsFrom {
|
63
|
+
type: TextureSourceType.mipmaps,
|
64
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
65
|
+
urls: string[],
|
66
|
+
}
|
67
|
+
|
68
|
+
export type TextureFactorySourceFrom =
|
69
|
+
TextureFactorySource2DBinaryMipmapsFrom
|
70
|
+
| TextureFactorySourceCubeBinaryMipmapsFrom
|
71
|
+
| TextureFactorySource2DFrom
|
72
|
+
| TextureFactorySourceCubeFrom
|
73
|
+
| TextureFactorySourceCubeMipmapsFrom
|
74
|
+
| TextureFactorySource2DMipmapsFrom
|
75
|
+
| TextureFactorySourceFromCompressed;
|
76
|
+
|
77
|
+
export interface TextureFactory {
|
78
|
+
loadSourceAsync (options: TextureFactorySourceFrom, config?: TextureConfigOptions): Promise<TextureOptions>,
|
79
|
+
|
80
|
+
canOffloadTexture (texture: Texture): boolean,
|
81
|
+
|
82
|
+
reloadTextureAsync (texture: Texture): Promise<Texture>,
|
83
|
+
|
84
|
+
loadCompressedTextureFromArrayBuffer (arrayBuffer: ArrayBuffer, options?: TextureOptions): TextureOptions,
|
85
|
+
}
|
86
|
+
|
87
|
+
export declare class Texture implements IGPUResource {
|
88
|
+
readonly width: number;
|
89
|
+
readonly height: number;
|
90
|
+
readonly id: string;
|
91
|
+
readonly options: Immutable<TextureOptions>;
|
92
|
+
readonly renderer?: IGPURenderer;
|
93
|
+
readonly sourceType: TextureSourceType;
|
94
|
+
readonly name: string;
|
95
|
+
readonly isDestroyed: boolean;
|
96
|
+
|
97
|
+
constructor (options: TextureOptions, renderer?: IGPURenderer);
|
98
|
+
|
99
|
+
destroy (): void;
|
100
|
+
|
101
|
+
updateSource (options: TextureSourceOptions): void;
|
102
|
+
|
103
|
+
uploadCurrentVideoFrame (): boolean;
|
104
|
+
|
105
|
+
offloadData (): void;
|
106
|
+
|
107
|
+
reloadDataAsync (): Promise<Texture>;
|
108
|
+
|
109
|
+
assignRenderer (renderer: GPURenderer): Texture;
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
type ImageSource = ImageBitmap | HTMLImageElement | HTMLCanvasElement;
|
114
|
+
|
115
|
+
export type TextureSourceCubeData = [
|
116
|
+
TEXTURE_CUBE_MAP_POSITIVE_X: ImageSource | { data: TypedArray, width: number, height: number },
|
117
|
+
TEXTURE_CUBE_MAP_NEGATIVE_X: ImageSource | { data: TypedArray, width: number, height: number },
|
118
|
+
TEXTURE_CUBE_MAP_POSITIVE_Y: ImageSource | { data: TypedArray, width: number, height: number },
|
119
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Y: ImageSource | { data: TypedArray, width: number, height: number },
|
120
|
+
TEXTURE_CUBE_MAP_POSITIVE_Z: ImageSource | { data: TypedArray, width: number, height: number },
|
121
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Z: ImageSource | { data: TypedArray, width: number, height: number }
|
122
|
+
];
|
123
|
+
|
124
|
+
// 为减少内存消耗,除了video之外,其余的数据内容会在texture生成后被置为undefined
|
125
|
+
// const tex = new Texture({image:myImage},renderer)
|
126
|
+
// tex.options.image === undefined
|
127
|
+
|
128
|
+
export type TextureSourceOptions = Texture2DSourceOptions | TextureCubeSourceOptions;
|
129
|
+
|
130
|
+
export interface Texture2DSourceOptionsNone extends TextureOptionsBase {
|
131
|
+
sourceType?: TextureSourceType.none,
|
132
|
+
target?: GLenum,
|
133
|
+
}
|
134
|
+
|
135
|
+
export interface Texture2DSourceOptionsImage extends TextureOptionsBase {
|
136
|
+
sourceType?: TextureSourceType.image,
|
137
|
+
image: ImageSource,
|
138
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
139
|
+
generateMipmap?: boolean,
|
140
|
+
}
|
141
|
+
|
142
|
+
export interface Texture2DSourceOptionsFrameBuffer extends TextureOptionsBase {
|
143
|
+
sourceType: TextureSourceType.framebuffer,
|
144
|
+
data?: { width: number, height: number },
|
145
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
146
|
+
}
|
147
|
+
|
148
|
+
export interface Texture2DSourceOptionsData extends TextureOptionsBase {
|
149
|
+
sourceType?: TextureSourceType.data,
|
150
|
+
data: { data: TypedArray, width: number, height: number },
|
151
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
152
|
+
}
|
153
|
+
|
154
|
+
export interface Texture2DSourceOptionsVideo extends TextureOptionsBase {
|
155
|
+
sourceType?: TextureSourceType.video,
|
156
|
+
video: HTMLVideoElement,
|
157
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
158
|
+
generateMipmap?: boolean,
|
159
|
+
}
|
160
|
+
|
161
|
+
export interface Texture2DSourceOptionsImageMipmaps extends TextureOptionsBase {
|
162
|
+
sourceType?: TextureSourceType.mipmaps,
|
163
|
+
mipmaps: Array<ImageSource | { data: TypedArray, width: number, height: number }>,
|
164
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
165
|
+
}
|
166
|
+
|
167
|
+
export interface Texture2DSourceOptionsCompressed extends TextureOptionsBase {
|
168
|
+
sourceType?: TextureSourceType.compressed,
|
169
|
+
mipmaps: Array<{ data: TypedArray, width: number, height: number }>,
|
170
|
+
target?: WebGLRenderingContext['TEXTURE_2D'],
|
171
|
+
}
|
172
|
+
|
173
|
+
export interface TextureCubeSourceOptionsImage extends TextureOptionsBase {
|
174
|
+
sourceType: TextureSourceType.image | TextureSourceType.data,
|
175
|
+
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'],
|
176
|
+
cube: TextureSourceCubeData,
|
177
|
+
generateMipmap?: boolean,
|
178
|
+
}
|
179
|
+
|
180
|
+
export interface TextureCubeSourceOptionsImageMipmaps extends TextureOptionsBase {
|
181
|
+
sourceType?: TextureSourceType.mipmaps,
|
182
|
+
mipmaps: Array<TextureSourceCubeData>,
|
183
|
+
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'],
|
184
|
+
}
|
185
|
+
|
186
|
+
export type TextureCubeSourceURLMap = [
|
187
|
+
TEXTURE_CUBE_MAP_POSITIVE_X: string,
|
188
|
+
TEXTURE_CUBE_MAP_NEGATIVE_X: string,
|
189
|
+
TEXTURE_CUBE_MAP_POSITIVE_Y: string,
|
190
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Y: string,
|
191
|
+
TEXTURE_CUBE_MAP_POSITIVE_Z: string,
|
192
|
+
TEXTURE_CUBE_MAP_NEGATIVE_Z: string
|
193
|
+
];
|
194
|
+
|
195
|
+
export interface TextureConfigOptionsBase {
|
196
|
+
name?: string,
|
197
|
+
wrapS?: GLenum, // GL_CLAMP_TO_EDGE
|
198
|
+
wrapT?: GLenum, // GL_CLAMP_TO_EDGE
|
199
|
+
magFilter?: GLenum, // GL_NEAREST
|
200
|
+
minFilter?: GLenum, // GL_NEAREST
|
201
|
+
anisotropic?: number, //0
|
202
|
+
flipY?: boolean,
|
203
|
+
premultiplyAlpha?: boolean,
|
204
|
+
//when use ImageBitMap, the bitmap content will be closed after sent to GPU
|
205
|
+
keepImageSource?: boolean,
|
206
|
+
}
|
207
|
+
|
208
|
+
export interface TextureConfigOptions extends TextureConfigOptionsBase {
|
209
|
+
sourceFrom?: TextureFactorySourceFrom,
|
210
|
+
}
|
211
|
+
|
212
|
+
export interface TextureFormatOptions {
|
213
|
+
format?: GLenum, // GL_RGBA
|
214
|
+
internalFormat?: GLenum, // GL_RGBA
|
215
|
+
type?: GLenum, //GL_UNSIGNED_BYTE
|
216
|
+
}
|
217
|
+
|
218
|
+
export interface TextureOptionsBase extends TextureConfigOptions, TextureFormatOptions {
|
219
|
+
sourceType?: TextureSourceType,
|
220
|
+
}
|
221
|
+
|
222
|
+
export type TextureCubeSourceOptions = TextureCubeSourceOptionsImage | TextureCubeSourceOptionsImageMipmaps;
|
223
|
+
|
224
|
+
export type Texture2DSourceOptions =
|
225
|
+
Texture2DSourceOptionsImage
|
226
|
+
| Texture2DSourceOptionsData
|
227
|
+
| Texture2DSourceOptionsVideo
|
228
|
+
| Texture2DSourceOptionsImageMipmaps
|
229
|
+
| Texture2DSourceOptionsCompressed
|
230
|
+
| Texture2DSourceOptionsFrameBuffer;
|
231
|
+
|
232
|
+
export type Texture2DOptions = Texture2DSourceOptions;
|
233
|
+
|
234
|
+
export type TextureCubeOptions = TextureCubeSourceOptions;
|
235
|
+
|
236
|
+
export type TextureOptions = Texture2DOptions | TextureCubeOptions;
|
package/types/index.ts
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
import type {
|
2
|
+
TextureFactory, Texture, TextureConfigOptions, TextureOptions, TextureFactorySourceFrom,
|
3
|
+
} from './Texture';
|
4
|
+
import type { GPUCapability } from './GPUCapability';
|
5
|
+
import type { TypedArray } from './type';
|
6
|
+
export * from './native/index';
|
7
|
+
export * from './constants';
|
8
|
+
export * from './GPUCapability';
|
9
|
+
export * from './Renderer';
|
10
|
+
export * from './RenderFrame';
|
11
|
+
export * from './Texture';
|
12
|
+
export * from './Material';
|
13
|
+
export * from './GPUBuffer';
|
14
|
+
export * from './RenderPass';
|
15
|
+
export * from './Mesh';
|
16
|
+
export * from './Geometry';
|
17
|
+
export * from './ShaderLibrary';
|
18
|
+
export { GPURenderer as Renderer } from './Renderer';
|
19
|
+
export * from './type';
|
20
|
+
|
21
|
+
export declare function getDefaultTextureFactory (): TextureFactory;
|
22
|
+
|
23
|
+
export declare function setDefaultTextureFactory (factory: TextureFactory): void;
|
24
|
+
|
25
|
+
export declare function getDefaultGPUCapability (): GPUCapability;
|
26
|
+
|
27
|
+
export declare class MarsTextureFactory implements TextureFactory {
|
28
|
+
canOffloadTexture (texture: Texture): boolean;
|
29
|
+
|
30
|
+
loadSourceAsync (options: TextureFactorySourceFrom, config?: TextureConfigOptions): Promise<TextureOptions>;
|
31
|
+
|
32
|
+
reloadTextureAsync (texture: Texture): Promise<Texture>;
|
33
|
+
|
34
|
+
loadCompressedTextureFromArrayBuffer (arrayBuffer: ArrayBuffer, options?: TextureOptions): TextureOptions;
|
35
|
+
|
36
|
+
loadImageBinaryAsync (binary: ArrayBuffer | TypedArray | Blob, mime?: string): Promise<HTMLImageElement | ImageBitmap>;
|
37
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { TypedArray } from '../type';
|
3
|
+
|
4
|
+
export interface DataBlockInternalOptions {
|
5
|
+
name: string,
|
6
|
+
}
|
7
|
+
export abstract class DataBlockInternal implements ResourceInternal {
|
8
|
+
readonly isDestroyed: boolean;
|
9
|
+
/**
|
10
|
+
* UBO的name,如果没有找到对应的UBO就用setUniform
|
11
|
+
* UBO的Layout只有一种,如果不同shader中使用同名UBO,请创建不同的DataBlock对象
|
12
|
+
*/
|
13
|
+
readonly name: string;
|
14
|
+
|
15
|
+
protected constructor (options: DataBlockInternalOptions) {}
|
16
|
+
|
17
|
+
abstract destroy (): void;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* uniform 的数据都以TypedArray形式传入,
|
21
|
+
* 在OpenGL中,使用UBO时,作为UBO的数据buffer,
|
22
|
+
* 不使用UBO时根据反射类型进行数据转化
|
23
|
+
* Metal中,直接当作 argument buffer
|
24
|
+
*/
|
25
|
+
abstract setUniformValue (name: string, value: TypedArray): void;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* 将uniform的数据拷贝到指定的TypedArray中,
|
29
|
+
* 如果传入的TypedArray buffer 长度不足,将只写入传入长度的数据
|
30
|
+
* @param name
|
31
|
+
* @param value
|
32
|
+
*/
|
33
|
+
abstract getUniformValue (name: string, value: TypedArray): boolean;
|
34
|
+
|
35
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { TypedArray } from '../type';
|
3
|
+
|
4
|
+
export const GPUBufferOptionsMemoryShared = 1 << 1;
|
5
|
+
|
6
|
+
export interface GPUBufferInternalOptions {
|
7
|
+
data?: TypedArray,
|
8
|
+
options?: typeof GPUBufferOptionsMemoryShared,
|
9
|
+
}
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 内存写入GPU的具体时机由框架自行决定,只要保证在渲染前输入GPU即可
|
13
|
+
*/
|
14
|
+
export abstract class GPUBufferInternal implements ResourceInternal {
|
15
|
+
readonly isDestroyed: boolean;
|
16
|
+
readonly byteLength: number;
|
17
|
+
|
18
|
+
protected constructor (options: GPUBufferInternalOptions) {
|
19
|
+
}
|
20
|
+
|
21
|
+
abstract destroy (): void;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* 整段替换数据,替换后byteLength会发生改变
|
25
|
+
* 内存写入GPU的具体时机由框架自行决定,只要保证在渲染前输入GPU即可
|
26
|
+
* 数据输入GPU后,可以丢弃内存端的数据
|
27
|
+
* @param typedArray
|
28
|
+
*/
|
29
|
+
abstract bufferData (typedArray: TypedArray): void;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 部分替换数据,如果offset+data的长度大于目前的byteLength,需要重新申请新的内存,整段替换
|
33
|
+
* @param byteOffset 指针的offset,无类型区分
|
34
|
+
* @param data
|
35
|
+
*/
|
36
|
+
abstract bufferSubData (byteOffset: number, data: TypedArray): void;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* 读取GPU数据,当创建参数有 GPUBufferOptionsMemoryShared 时,必须能读取到数据
|
40
|
+
* 当框架没有读取到数据时,返回false
|
41
|
+
* @param typedArray 将数据写入的arrayBuffer
|
42
|
+
* @param offset 写入的指针偏移
|
43
|
+
*/
|
44
|
+
abstract readSubData (typedArray: TypedArray, offset?: number): boolean;
|
45
|
+
|
46
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import type { AttributeWithType, GeometryOptions } from '../Geometry';
|
2
|
+
import type { ResourceInternal } from './ResourceInternal';
|
3
|
+
import type { GPUBufferInternal } from './GPUBufferInternal';
|
4
|
+
|
5
|
+
interface GeometryBufferLayout {
|
6
|
+
index: number,
|
7
|
+
name: string,
|
8
|
+
}
|
9
|
+
export interface GeometryInternalOptions extends Omit<GeometryOptions, 'attributes' | 'index'> {
|
10
|
+
attributes: Record<string, AttributeWithType>,
|
11
|
+
buffers: Record<string, GPUBufferInternal>,
|
12
|
+
bufferLayouts: GeometryBufferLayout[],
|
13
|
+
indexBuffer?: GPUBufferInternal,
|
14
|
+
indexBufferType?: IndexBufferType,
|
15
|
+
}
|
16
|
+
|
17
|
+
export type IndexBufferType = WebGLRenderingContext['UNSIGNED_SHORT'] | WebGLRenderingContext['UNSIGNED_INT'];
|
18
|
+
|
19
|
+
/**
|
20
|
+
* geometry中的数据都以buffer形式保存
|
21
|
+
*/
|
22
|
+
export abstract class GeometryInternal implements ResourceInternal {
|
23
|
+
readonly isDestroyed: boolean;
|
24
|
+
|
25
|
+
readonly name: string;
|
26
|
+
|
27
|
+
drawStart: number;
|
28
|
+
|
29
|
+
drawCount: number;
|
30
|
+
|
31
|
+
mode: GLenum;
|
32
|
+
|
33
|
+
protected constructor (options: GeometryInternalOptions) {
|
34
|
+
}
|
35
|
+
|
36
|
+
abstract setAttributeBuffer (name: string, buffer: GPUBufferInternal | undefined): void;
|
37
|
+
|
38
|
+
abstract getAttributeBuffer (name: string): GPUBufferInternal | undefined;
|
39
|
+
|
40
|
+
abstract getIndexBuffer (): [buffer: GPUBufferInternal | undefined, type: number];
|
41
|
+
|
42
|
+
/**
|
43
|
+
* 获得当前所有的attributeBuffer
|
44
|
+
*/
|
45
|
+
abstract getAttributeBufferMap (): Record<string, GPUBufferInternal>;
|
46
|
+
|
47
|
+
abstract setIndexBuffer (buffer: GPUBufferInternal | undefined, bufferType?: IndexBufferType): void;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* 并不会销毁attributeBuffers和IndexBuffer,
|
51
|
+
* 但会清除内部buffer的引用,如果需要销毁buffers,
|
52
|
+
* 调用destroy之前,需要手动调用 getAttributeBufferMap 和 getIndexBuffer 将获得的buffer显式销毁
|
53
|
+
*/
|
54
|
+
abstract destroy (): void;
|
55
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
export interface ImageBitmapConstructor {
|
2
|
+
flipY?: boolean,
|
3
|
+
premultiplyAlpha?: boolean,
|
4
|
+
resizeWidth?: number,
|
5
|
+
resizeHeight?: number,
|
6
|
+
}
|
7
|
+
|
8
|
+
export abstract class ImageBitmapInternal {
|
9
|
+
/**
|
10
|
+
* 释放内存,释放后不可再用,
|
11
|
+
* 释放后 width,height,byteLength都为0
|
12
|
+
*/
|
13
|
+
abstract close (): void;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* 将内存拷贝到指定的Uint8Array中
|
17
|
+
* @param target
|
18
|
+
*/
|
19
|
+
abstract copyTo (target: Uint8Array): void;
|
20
|
+
abstract readonly width: number;
|
21
|
+
abstract readonly height: number;
|
22
|
+
abstract readonly byteLength: number;
|
23
|
+
}
|
24
|
+
|
25
|
+
export type ImageBitmapCallback = (
|
26
|
+
error: Error | undefined,
|
27
|
+
image: ImageBitmapInternal
|
28
|
+
) => void;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { MaterialRenderStates } from '../Material';
|
3
|
+
import type { DataBlockInternal } from './DataBlockInternal';
|
4
|
+
import type { TextureInternal } from './TextureInternal';
|
5
|
+
export interface MaterialInternalOptions {
|
6
|
+
states: MaterialRenderStates,
|
7
|
+
dataBlocks: DataBlockInternal[],
|
8
|
+
shaderCacheId: string,
|
9
|
+
name: string,
|
10
|
+
}
|
11
|
+
export abstract class MaterialInternal implements ResourceInternal {
|
12
|
+
readonly isDestroyed: boolean;
|
13
|
+
readonly name: string;
|
14
|
+
readonly shaderCacheId: string;
|
15
|
+
|
16
|
+
dataBlocks: DataBlockInternal[];
|
17
|
+
|
18
|
+
protected constructor (options: MaterialInternalOptions) {
|
19
|
+
}
|
20
|
+
abstract destroy (): void;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* 对于 uniform sampler2D uTex
|
24
|
+
* 和 uniform sampler2D uTextures[4] 都使用此函数
|
25
|
+
* @param name
|
26
|
+
* @param value
|
27
|
+
*/
|
28
|
+
abstract setUniformTextures (name: string, value: TextureInternal[]): void;
|
29
|
+
|
30
|
+
abstract getUniformTextures (name: string): TextureInternal[];
|
31
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { GeometryInternal } from './GeometryInternal';
|
3
|
+
import type { MaterialInternal } from './MaterialInternal';
|
4
|
+
|
5
|
+
export interface MeshInternalOptions {
|
6
|
+
name: string,
|
7
|
+
geometries: GeometryInternal[],
|
8
|
+
material: MaterialInternal,
|
9
|
+
priority?: number,
|
10
|
+
hide?: boolean,
|
11
|
+
}
|
12
|
+
|
13
|
+
export abstract class MeshInternal implements ResourceInternal {
|
14
|
+
readonly isDestroyed: boolean;
|
15
|
+
readonly name: string;
|
16
|
+
geometries: GeometryInternal[];
|
17
|
+
material: MaterialInternal;
|
18
|
+
priority: number;
|
19
|
+
hide: boolean;
|
20
|
+
|
21
|
+
protected constructor (options: MeshInternalOptions) {
|
22
|
+
}
|
23
|
+
|
24
|
+
abstract destroy (): void;
|
25
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { RenderPassInternal } from './RenderPassInternal';
|
3
|
+
import type { RenderPassLoadAction } from '../RenderPass';
|
4
|
+
|
5
|
+
export interface RenderFrameInternalOptions {
|
6
|
+
renderPasses: RenderPassInternal[],
|
7
|
+
loadAction: RenderPassLoadAction,
|
8
|
+
name: string,
|
9
|
+
}
|
10
|
+
export abstract class RenderFrameInternal implements ResourceInternal {
|
11
|
+
readonly isDestroyed: boolean;
|
12
|
+
readonly loadAction: RenderPassLoadAction;
|
13
|
+
readonly name: string;
|
14
|
+
/**
|
15
|
+
* 增删改查的操作,在warp层对renderPassInternals进行后,得到的数据全部覆盖当前数据
|
16
|
+
*/
|
17
|
+
renderPasses: RenderPassInternal[];
|
18
|
+
|
19
|
+
protected constructor (options: RenderFrameInternalOptions) {
|
20
|
+
}
|
21
|
+
abstract destroy (): void;
|
22
|
+
/**
|
23
|
+
* warp层完成所有数据传输后,通知客户端,可以进行实际渲染,
|
24
|
+
* 实际渲染根据客户端时机进行,在调用end()之前,客户端会根据实际刷新进行绘制
|
25
|
+
*/
|
26
|
+
abstract begin (): void;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* 将RenderFrame移除渲染队列
|
30
|
+
*/
|
31
|
+
abstract end (): void;
|
32
|
+
|
33
|
+
abstract updateLoadAction (action: RenderPassLoadAction): void;
|
34
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import type { ResourceInternal } from './ResourceInternal';
|
2
|
+
import type { MeshInternal } from './MeshInternal';
|
3
|
+
import type { RenderPassLoadAction, RenderPassStoreAction } from '../RenderPass';
|
4
|
+
import type { TextureInternal } from './TextureInternal';
|
5
|
+
import type { RenderPassStorageObject } from '../RenderPass';
|
6
|
+
import type { RenderPassAttachmentStorageType } from '../RenderPass';
|
7
|
+
|
8
|
+
//--- color ---
|
9
|
+
export interface RenderPassColorAttachmentInternal {
|
10
|
+
readonly storageType: RenderPassAttachmentStorageType.color,
|
11
|
+
readonly texture: TextureInternal,
|
12
|
+
}
|
13
|
+
|
14
|
+
//--- depth stencil ---
|
15
|
+
export interface RenderPassDepthStencilAttachmentInternal {
|
16
|
+
readonly storageType: RenderPassAttachmentStorageType,
|
17
|
+
readonly texture?: TextureInternal,
|
18
|
+
readonly storage?: RenderPassStorageObjectInternal,
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* 在Metal里面,所有的RenderPassAttachment都以Texture存储
|
22
|
+
* 在GL中,可以使用RenderTarget/Texture作为fbo的attachment
|
23
|
+
*/
|
24
|
+
export interface RenderPassStorageObjectInternal extends RenderPassStorageObject {
|
25
|
+
_mtlTexture?: TextureInternal,
|
26
|
+
_glRenderBuffer?: WebGLRenderbuffer,
|
27
|
+
}
|
28
|
+
|
29
|
+
export interface RenderPassDepthStencilAttachmentOptionsInternal {
|
30
|
+
storageType: RenderPassAttachmentStorageType,
|
31
|
+
texture?: TextureInternal,
|
32
|
+
storage?: RenderPassStorageObjectInternal,
|
33
|
+
}
|
34
|
+
|
35
|
+
export interface RenderPassOptionsInternal {
|
36
|
+
loadAction: RenderPassLoadAction,
|
37
|
+
attachments: RenderPassColorAttachmentInternal[],
|
38
|
+
name: string,
|
39
|
+
meshes: MeshInternal[],
|
40
|
+
width: number,
|
41
|
+
height: number,
|
42
|
+
multiSample?: number,
|
43
|
+
storeAction?: RenderPassStoreAction,
|
44
|
+
depthStencilAttachment?: RenderPassDepthStencilAttachmentOptionsInternal,
|
45
|
+
}
|
46
|
+
|
47
|
+
export abstract class RenderPassInternal implements ResourceInternal {
|
48
|
+
readonly isDestroyed: boolean;
|
49
|
+
readonly name: string;
|
50
|
+
readonly storeAction: RenderPassStoreAction;
|
51
|
+
readonly loadAction: RenderPassLoadAction;
|
52
|
+
readonly multisample: number;
|
53
|
+
readonly depthStencilAttachment: RenderPassDepthStencilAttachmentInternal;
|
54
|
+
readonly attachments: RenderPassColorAttachmentInternal[];
|
55
|
+
readonly width: number;
|
56
|
+
readonly height: number;
|
57
|
+
/**
|
58
|
+
* 增删改查的操作,在warp层对Mesh进行后,得到的数据全部覆盖当前数据
|
59
|
+
*/
|
60
|
+
meshes: MeshInternal[];
|
61
|
+
|
62
|
+
priority: number;
|
63
|
+
|
64
|
+
protected constructor (options: RenderPassOptionsInternal) {
|
65
|
+
}
|
66
|
+
abstract destroy (): void;
|
67
|
+
|
68
|
+
abstract resize (width: number, height: number): void;
|
69
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
|
2
|
+
import type { GPUBufferInternal, GPUBufferInternalOptions } from './GPUBufferInternal';
|
3
|
+
import type { GeometryInternal, GeometryInternalOptions } from './GeometryInternal';
|
4
|
+
import type { ShaderLibraryInternal } from './ShaderLibraryInternal';
|
5
|
+
import type { DataBlockInternal, DataBlockInternalOptions } from './DataBlockInternal';
|
6
|
+
import type { MaterialInternal, MaterialInternalOptions } from './MaterialInternal';
|
7
|
+
import type { MeshInternal, MeshInternalOptions } from './MeshInternal';
|
8
|
+
import type { RenderPassInternal, RenderPassOptionsInternal } from './RenderPassInternal';
|
9
|
+
import type { RenderFrameInternal, RenderFrameInternalOptions } from './RenderFrameInternal';
|
10
|
+
import type { GPUCapability } from '../GPUCapability';
|
11
|
+
import type { TextureInternal, TextureInternalConstructOptions } from './TextureInternal';
|
12
|
+
import type { ImageBitmapCallback, ImageBitmapConstructor } from './ImageBitmapInternal';
|
13
|
+
|
14
|
+
/**
|
15
|
+
* renderer 内部创建的对象,用来统计信息,排查资源泄漏的问题
|
16
|
+
*/
|
17
|
+
export interface InternalResInfo {
|
18
|
+
buffer: number,
|
19
|
+
geometry: number,
|
20
|
+
material: number,
|
21
|
+
texture: number,
|
22
|
+
dataBlock: number,
|
23
|
+
mesh: number,
|
24
|
+
renderPass: number,
|
25
|
+
frame: number,
|
26
|
+
}
|
27
|
+
|
28
|
+
export abstract class RendererInternal implements ResourceInternal {
|
29
|
+
readonly isDestroyed: boolean;
|
30
|
+
readonly platform: ResourcePlatform;
|
31
|
+
readonly gpu: GPUCapability;
|
32
|
+
readonly shaderLibrary: ShaderLibraryInternal;
|
33
|
+
readonly width: number;
|
34
|
+
readonly height: number;
|
35
|
+
|
36
|
+
abstract destroy (): void;
|
37
|
+
|
38
|
+
abstract createBuffer (options: GPUBufferInternalOptions): GPUBufferInternal;
|
39
|
+
|
40
|
+
abstract createGeometry (options: GeometryInternalOptions): GeometryInternal;
|
41
|
+
|
42
|
+
abstract createDataBlock (options: DataBlockInternalOptions): DataBlockInternal;
|
43
|
+
|
44
|
+
abstract createMaterial (options: MaterialInternalOptions): MaterialInternal;
|
45
|
+
|
46
|
+
abstract createMesh (options: MeshInternalOptions): MeshInternal;
|
47
|
+
|
48
|
+
abstract createRenderPass (options: RenderPassOptionsInternal): RenderPassInternal;
|
49
|
+
|
50
|
+
abstract createRenderFrame (options: RenderFrameInternalOptions): RenderFrameInternal;
|
51
|
+
|
52
|
+
abstract createTexture (options: TextureInternalConstructOptions): TextureInternal;
|
53
|
+
|
54
|
+
abstract getResourceInfo (): InternalResInfo;
|
55
|
+
|
56
|
+
abstract requestAnimationFrame (callback: (timestamp: number) => void): number;
|
57
|
+
|
58
|
+
abstract cancelAnimationFrame (id: number): void;
|
59
|
+
|
60
|
+
abstract createImageBitmap (
|
61
|
+
data: ArrayBuffer | string, //图片文件的数据
|
62
|
+
options: ImageBitmapConstructor,
|
63
|
+
callback: ImageBitmapCallback
|
64
|
+
): void;
|
65
|
+
}
|
66
|
+
|