@predy-js/render-interface 0.1.61-beta.2 → 0.1.61-beta.22
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 +231 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +231 -137
- package/dist/index.mjs.map +1 -1
- package/dist/src/render/MarsGeometry.d.ts +4 -3
- package/dist/src/render/MarsMaterial.d.ts +2 -3
- package/dist/src/render/MarsMaterialDataBlock.d.ts +12 -3
- package/dist/src/render/MarsRenderer.d.ts +3 -0
- package/dist/src/webgl/GLGPUBuffer.d.ts +2 -4
- package/dist/src/webgl/GLGPURenderer.d.ts +2 -0
- package/dist/src/webgl/GLGeometry.d.ts +6 -2
- package/dist/src/webgl/GLProgram.d.ts +2 -0
- package/dist/statistic.js +1 -1
- package/dist/types/GPUBuffer.d.ts +14 -14
- package/dist/types/Geometry.d.ts +9 -4
- package/dist/types/Material.d.ts +27 -24
- package/dist/types/RenderFrame.d.ts +3 -5
- package/dist/types/RenderPass.d.ts +2 -2
- package/dist/types/Renderer.d.ts +21 -12
- package/dist/types/ShaderLibrary.d.ts +4 -4
- package/dist/types/native/DataBlockInternal.d.ts +3 -0
- package/dist/types/native/GPUBufferInternal.d.ts +1 -1
- package/dist/types/native/ImageBitmapInternal.d.ts +0 -2
- package/dist/types/native/MaterialInternal.d.ts +0 -9
- package/dist/types/native/RenderFrameInternal.d.ts +3 -7
- package/dist/types/native/RendererInternal.d.ts +10 -0
- package/dist/types/native/TextureInternal.d.ts +1 -0
- package/package.json +1 -1
- package/types/GPUBuffer.ts +16 -19
- package/types/Geometry.ts +11 -4
- package/types/Material.ts +37 -31
- package/types/RenderFrame.ts +3 -5
- package/types/RenderPass.ts +2 -2
- package/types/Renderer.ts +24 -13
- package/types/ShaderLibrary.ts +4 -4
- package/types/native/DataBlockInternal.ts +5 -0
- package/types/native/GPUBufferInternal.ts +1 -2
- package/types/native/ImageBitmapInternal.ts +0 -2
- package/types/native/MaterialInternal.ts +0 -11
- package/types/native/RenderFrameInternal.ts +3 -7
- package/types/native/RendererInternal.ts +13 -0
- package/types/native/TextureInternal.ts +1 -0
@@ -26,7 +26,7 @@ export declare class MarsGeometry implements Geometry {
|
|
26
26
|
_dirtyFlags: {
|
27
27
|
[key: string]: BufferDirtyFlag;
|
28
28
|
};
|
29
|
-
_index?:
|
29
|
+
_index?: Uint16Array | Uint32Array;
|
30
30
|
_indexReleasable: boolean;
|
31
31
|
readonly internal: GLGeometry;
|
32
32
|
readonly options?: GeometryOptions;
|
@@ -35,6 +35,7 @@ export declare class MarsGeometry implements Geometry {
|
|
35
35
|
protected _drawStart: number;
|
36
36
|
protected _mode: number;
|
37
37
|
protected _isDestroyed: boolean;
|
38
|
+
indexDataType: number;
|
38
39
|
get isDestroyed(): boolean;
|
39
40
|
get mode(): number;
|
40
41
|
set mode(n: number);
|
@@ -52,8 +53,8 @@ export declare class MarsGeometry implements Geometry {
|
|
52
53
|
setAttributeData(name: string, data: TypedArray): void;
|
53
54
|
getAttributeData(name: string): TypedArray | undefined;
|
54
55
|
setAttributeSubData(name: string, offset: number, data: TypedArray): void;
|
55
|
-
getIndexData():
|
56
|
-
setIndexData(data:
|
56
|
+
getIndexData(): Uint16Array | Uint32Array | undefined;
|
57
|
+
setIndexData(data: Uint16Array | Uint32Array | undefined): void;
|
57
58
|
setIndexSubData(offset: number, data: TypedArray): void;
|
58
59
|
getAttributeStride(name: string): number;
|
59
60
|
getAttributeDataLength(name: string): number;
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { Material, MaterialDestroyOptions, MaterialOptions, MaterialRenderStates } from '../../types';
|
2
|
-
import type { UniformSemantic } from '../../types';
|
3
2
|
import { MaterialRenderType } from '../../types/Material';
|
4
3
|
import type { Immutable } from '../../types/type';
|
5
4
|
import { GLMaterial } from '../webgl/GLMaterial';
|
@@ -14,16 +13,16 @@ export declare class MarsMaterial implements Material {
|
|
14
13
|
readonly renderType: MaterialRenderType;
|
15
14
|
readonly states: Immutable<MaterialRenderStates>;
|
16
15
|
readonly renderer?: MarsRenderer;
|
16
|
+
private _dbMap;
|
17
17
|
private _isDestroyed;
|
18
|
-
readonly uniformSemantics: Record<string, UniformSemantic>;
|
19
18
|
get isDestroyed(): boolean;
|
20
19
|
get dataBlocks(): MarsMaterialDataBlock[];
|
21
20
|
get defaultDataBlock(): MarsMaterialDataBlock;
|
22
21
|
constructor(options: MaterialOptions);
|
23
22
|
createMaterialStates(states: MaterialRenderStates): Immutable<MaterialRenderStates>;
|
24
23
|
addDataBlock(b: MarsMaterialDataBlock): void;
|
24
|
+
getDataBlockByName(name: string): MarsMaterialDataBlock;
|
25
25
|
removeDataBlock(b: MarsMaterialDataBlock): void;
|
26
|
-
setUniformSemantic(uniformName: string, semantic: string | undefined): void;
|
27
26
|
assignRenderer(renderer: MarsRenderer): MarsMaterial;
|
28
27
|
destroy(options?: MaterialDestroyOptions): void;
|
29
28
|
}
|
@@ -1,24 +1,32 @@
|
|
1
|
-
import type { MaterialDataBlock, MaterialDataBlockDestroyOptions, MaterialDataBlockOptions, UniformValue, vec2 } from '../../types';
|
1
|
+
import type { MaterialDataBlock, MaterialDataBlockDestroyOptions, MaterialDataBlockOptions, UniformSemantic, UniformValue, vec2, Texture } from '../../types';
|
2
2
|
import type { MarsRenderer } from './MarsRenderer';
|
3
|
+
import { MarsTexture } from './MarsTexture';
|
3
4
|
import type { UniformBlockSpec } from '../webgl/GLUniformUtils';
|
4
5
|
import { UniformBlockBuffer } from '../webgl/GLUniformUtils';
|
5
6
|
export declare class MarsMaterialDataBlock implements MaterialDataBlock {
|
6
7
|
readonly _uniformValues: Record<string, UniformValue>;
|
8
|
+
readonly _uniformTextures: Record<string, MarsTexture | MarsTexture[]>;
|
7
9
|
readonly _uniformFlags: Record<string, boolean>;
|
8
10
|
readonly _uniformValueRanges: Record<string, vec2>;
|
9
11
|
readonly name: string;
|
12
|
+
readonly uniformSemantics: {
|
13
|
+
[key: string]: UniformSemantic;
|
14
|
+
};
|
10
15
|
readonly renderer?: MarsRenderer;
|
11
16
|
readonly uboBufferMap: Record<string, UniformBlockBuffer>;
|
12
17
|
protected _isDestroyed: boolean;
|
18
|
+
private _uniformPrivate;
|
13
19
|
private readonly _keepUboData;
|
14
20
|
constructor(props: MaterialDataBlockOptions & {
|
15
21
|
keepUboData?: boolean;
|
16
22
|
}, renderer?: MarsRenderer);
|
17
|
-
_assignUniformValueRenderer(value:
|
23
|
+
_assignUniformValueRenderer(value: MarsTexture | MarsTexture[], renderer?: MarsRenderer): void;
|
18
24
|
invalidAllFlags(): void;
|
19
25
|
clearFlags(): void;
|
20
26
|
isDirty(shaderCacheId: string, name: string): boolean;
|
21
27
|
get isDestroyed(): boolean;
|
28
|
+
setUniformTexture(uniformName: string, texture: MarsTexture | MarsTexture[] | undefined): void;
|
29
|
+
getUniformTexture<T extends (Texture | Texture[]) = MarsTexture>(uniformName: string): T | undefined;
|
22
30
|
assignRenderer(renderer: MarsRenderer): MaterialDataBlock;
|
23
31
|
createUboBuffer(spec: UniformBlockSpec): UniformBlockBuffer | undefined;
|
24
32
|
setUboBuffer(uboBuffer: UniformBlockBuffer): void;
|
@@ -29,9 +37,10 @@ export declare class MarsMaterialDataBlock implements MaterialDataBlock {
|
|
29
37
|
getUniformValues(): {
|
30
38
|
[p: string]: UniformValue;
|
31
39
|
};
|
32
|
-
setUniformValue(name: string, value: UniformValue | undefined): boolean;
|
40
|
+
setUniformValue(name: string, value: UniformValue | undefined, isSemantic?: boolean): boolean;
|
33
41
|
setUniformValues(map: {
|
34
42
|
[p: string]: UniformValue;
|
35
43
|
}): void;
|
44
|
+
setUniformSemantic(name: string, semantic: string | undefined): void;
|
36
45
|
clone(name: string): MarsMaterialDataBlock;
|
37
46
|
}
|
@@ -17,4 +17,7 @@ export declare class MarsRenderer implements GPURenderer {
|
|
17
17
|
createRenderFrame(options?: RenderFrameOptions): MarsRenderFrame;
|
18
18
|
destroy(haltGL?: boolean): void;
|
19
19
|
resize(width: number, height: number): void;
|
20
|
+
cancelAnimationFrame(id: number): void;
|
21
|
+
getErrors(): string[];
|
22
|
+
requestAnimationFrame(cb: FrameRequestCallback): number;
|
20
23
|
}
|
@@ -3,18 +3,15 @@ import type { GLGPURenderer } from './GLGPURenderer';
|
|
3
3
|
import type { TypedArray } from '../../types/type';
|
4
4
|
import type { MarsRenderer } from '../render/MarsRenderer';
|
5
5
|
export declare class GLGPUBuffer implements GPUBuffer {
|
6
|
-
readonly bytesPerElement: number;
|
7
|
-
readonly target: GPUBufferTarget;
|
8
|
-
readonly type: WebGLRenderingContext['FLOAT'] | WebGLRenderingContext['INT'] | WebGLRenderingContext['SHORT'];
|
9
6
|
readonly usage: WebGLRenderingContext['STATIC_DRAW'] | WebGLRenderingContext['DYNAMIC_DRAW'] | WebGLRenderingContext['STREAM_DRAW'];
|
10
7
|
readonly renderer?: GLGPURenderer;
|
11
8
|
readonly glBuffer: WebGLBuffer | null;
|
9
|
+
readonly target: GPUBufferTarget;
|
12
10
|
private _byteLength;
|
13
11
|
private _isDestroyed;
|
14
12
|
readonly name: string;
|
15
13
|
get byteLength(): number;
|
16
14
|
get isBuffer(): boolean;
|
17
|
-
get elementCount(): number;
|
18
15
|
get level(): number;
|
19
16
|
get isDestroyed(): boolean;
|
20
17
|
constructor(options: GPUBufferOptions, renderer: GLGPURenderer);
|
@@ -23,5 +20,6 @@ export declare class GLGPUBuffer implements GPUBuffer {
|
|
23
20
|
bufferSubData(elementOffset: number, typedArray: TypedArray): void;
|
24
21
|
destroy(): void;
|
25
22
|
readSubData(elementOffset: number, typedArray: TypedArray): boolean;
|
23
|
+
getElementCount(bytePerElement: number): number;
|
26
24
|
assignRenderer(renderer: MarsRenderer): GLGPUBuffer;
|
27
25
|
}
|
@@ -26,6 +26,8 @@ export declare class GLGPURenderer implements GPURenderer {
|
|
26
26
|
private _isDestroyed;
|
27
27
|
extension: RendererExtensions;
|
28
28
|
constructor(gl: WebGLRenderingContext | WebGL2RenderingContext);
|
29
|
+
requestAnimationFrame(cb: FrameRequestCallback): number;
|
30
|
+
cancelAnimationFrame(id: number): void;
|
29
31
|
get isDestroyed(): boolean;
|
30
32
|
onContextLose: (e: Event) => void;
|
31
33
|
copy2(source: GLTexture, target: GLTexture): void;
|
@@ -7,6 +7,9 @@ import type { GLVertexArrayObject } from './GLVertexArrayObject';
|
|
7
7
|
export declare const INDEX_TYPE_MAP: {
|
8
8
|
[x: number]: number;
|
9
9
|
};
|
10
|
+
export declare const TYPE_BYTE_MAP: {
|
11
|
+
[x: number]: number;
|
12
|
+
};
|
10
13
|
export type GLGeometryOptions = {
|
11
14
|
drawStart: number;
|
12
15
|
drawCount: number;
|
@@ -31,6 +34,7 @@ export declare class GLGeometry {
|
|
31
34
|
drawStart: number;
|
32
35
|
drawCount: number;
|
33
36
|
mode: GLenum;
|
37
|
+
indexBufferType: GLenum;
|
34
38
|
attributes: {
|
35
39
|
[key: string]: AttributeWithType;
|
36
40
|
};
|
@@ -42,8 +46,8 @@ export declare class GLGeometry {
|
|
42
46
|
constructor(option: GLGeometryOptions | GLGeometry, renderer: GLGPURenderer);
|
43
47
|
createVao(name: string): GLVertexArrayObject;
|
44
48
|
destroyVao(name: string): void;
|
45
|
-
setIndexBuffer(buffer: GLGPUBuffer): void;
|
46
|
-
createIndexBuffer(data: Uint16Array | Uint32Array | Uint8Array, renderer: GLGPURenderer): GLGPUBuffer;
|
49
|
+
setIndexBuffer(buffer: GLGPUBuffer, indexBufferType: GLenum): void;
|
50
|
+
createIndexBuffer(data: Uint16Array | Uint32Array | Uint8Array, renderer: GLGPURenderer): [buffer: GLGPUBuffer, type: GLenum];
|
47
51
|
getGPUBuffer(name: string | number): GLGPUBuffer | null;
|
48
52
|
destroy(): void;
|
49
53
|
setAttributeBuffer(name: string, buffer: GPUBuffer): void;
|
@@ -3,6 +3,7 @@ import type { GLGeometry } from './GLGeometry';
|
|
3
3
|
import type { RenderState } from '../../types/RenderFrame';
|
4
4
|
import type { GLVertexArrayObject } from './GLVertexArrayObject';
|
5
5
|
import type { UniformBlockSpec } from './GLUniformUtils';
|
6
|
+
import type { UniformValue } from '../../types';
|
6
7
|
export interface ProgramAttributeInfo {
|
7
8
|
readonly name: string;
|
8
9
|
readonly size: number;
|
@@ -35,6 +36,7 @@ export declare class GLProgram {
|
|
35
36
|
constructor(renderer: GLGPURenderer, program: WebGLProgram, shared: boolean, id: string);
|
36
37
|
init(renderer: GLGPURenderer, program: WebGLProgram): void;
|
37
38
|
bind(): void;
|
39
|
+
getSemanticValue(state: RenderState, semanticName: string): UniformValue | import("../../types").GPUBuffer | null | undefined;
|
38
40
|
setupUniforms(state: RenderState): void;
|
39
41
|
setGLUniformValue(name: string, value: any, info: ProgramUniformInfo, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
40
42
|
setupAttributes(geometry: GLGeometry): GLVertexArrayObject;
|
package/dist/statistic.js
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
import type { TypedArray } from './type';
|
2
2
|
import type { IGPUResource, IGPURenderer } from './IGPURenderer';
|
3
3
|
import type { GPURenderer } from './Renderer';
|
4
|
+
export declare const GPUBufferOptionsMemoryShared: number;
|
4
5
|
export type GPUBufferTarget = WebGLRenderingContext['ARRAY_BUFFER'] | WebGLRenderingContext['ELEMENT_ARRAY_BUFFER'] | WebGL2RenderingContext['COPY_READ_BUFFER'] | WebGL2RenderingContext['COPY_WRITE_BUFFER'] | WebGL2RenderingContext['TRANSFORM_FEEDBACK_BUFFER'] | WebGL2RenderingContext['UNIFORM_BUFFER'] | WebGL2RenderingContext['PIXEL_PACK_BUFFER'] | WebGL2RenderingContext['PIXEL_UNPACK_BUFFER'];
|
5
|
-
type GPUBufferType = WebGLRenderingContext['FLOAT'] | WebGLRenderingContext['INT'] | WebGLRenderingContext['SHORT'];
|
6
6
|
export interface GPUBufferOptions {
|
7
7
|
name?: string;
|
8
|
-
target?: GPUBufferTarget;
|
9
|
-
type?: GPUBufferType;
|
10
8
|
/**
|
11
|
-
*
|
9
|
+
* 数据长度,如果提供了data,忽略此参数
|
12
10
|
*/
|
13
|
-
|
11
|
+
byteLength?: number;
|
14
12
|
data?: TypedArray;
|
13
|
+
/**
|
14
|
+
* GL需要设置,Vulkan和Metal此属性忽略
|
15
|
+
*/
|
16
|
+
target?: GPUBufferTarget;
|
17
|
+
/**
|
18
|
+
* GL需要设置,Vulkan和Metal此属性忽略
|
19
|
+
*/
|
15
20
|
usage?: WebGLRenderingContext['STATIC_DRAW'] | WebGLRenderingContext['DYNAMIC_DRAW'];
|
16
21
|
}
|
17
22
|
/**
|
@@ -23,16 +28,11 @@ export declare class GPUBuffer implements IGPUResource {
|
|
23
28
|
readonly renderer?: IGPURenderer;
|
24
29
|
readonly isDestroyed: boolean;
|
25
30
|
readonly level: number;
|
26
|
-
readonly target: GPUBufferTarget;
|
27
|
-
readonly type: GPUBufferOptions['type'];
|
28
31
|
readonly byteLength: number;
|
29
|
-
readonly
|
30
|
-
|
32
|
+
readonly target: GPUBufferTarget;
|
33
|
+
readonly usage?: WebGLRenderingContext['STATIC_DRAW'] | WebGLRenderingContext['DYNAMIC_DRAW'];
|
31
34
|
constructor(options: GPUBufferOptions, renderer?: IGPURenderer);
|
32
|
-
|
33
|
-
* 数据元素的总量
|
34
|
-
*/
|
35
|
-
readonly elementCount: number;
|
35
|
+
getElementCount(bytePerElement: number): number;
|
36
36
|
/**
|
37
37
|
* 根据TypedArray容量,重新分配Buffer内存
|
38
38
|
* @param typedArray
|
@@ -52,5 +52,5 @@ export declare class GPUBuffer implements IGPUResource {
|
|
52
52
|
*/
|
53
53
|
readSubData(elementOffset: number, typedArray: TypedArray, elementCount?: number): boolean;
|
54
54
|
assignRenderer(renderer: GPURenderer): GPUBuffer;
|
55
|
+
destroy(): void;
|
55
56
|
}
|
56
|
-
export {};
|
package/dist/types/Geometry.d.ts
CHANGED
@@ -62,7 +62,7 @@ export interface GeometryOptions {
|
|
62
62
|
[key: string]: Attribute;
|
63
63
|
};
|
64
64
|
index?: {
|
65
|
-
data:
|
65
|
+
data: GeometryIndexData;
|
66
66
|
releasable?: boolean;
|
67
67
|
};
|
68
68
|
mode?: GeometryDrawMode;
|
@@ -70,6 +70,10 @@ export interface GeometryOptions {
|
|
70
70
|
drawStart?: number;
|
71
71
|
bufferUsage?: GLenum;
|
72
72
|
}
|
73
|
+
/**
|
74
|
+
* 不兼容Uint8的Index,只能使用Uin16和Uin32
|
75
|
+
*/
|
76
|
+
export type GeometryIndexData = Uint16Array | Uint32Array;
|
73
77
|
export declare class Geometry implements IGPUResource {
|
74
78
|
readonly renderer?: IGPURenderer;
|
75
79
|
/**
|
@@ -80,6 +84,7 @@ export declare class Geometry implements IGPUResource {
|
|
80
84
|
}>;
|
81
85
|
readonly isDestroyed: boolean;
|
82
86
|
readonly options?: Immutable<GeometryOptions>;
|
87
|
+
indexDataType?: WebGLRenderingContext['UNSIGNED_INT'] | WebGLRenderingContext['UNSIGNED_SHORT'];
|
83
88
|
drawStart: number;
|
84
89
|
drawCount: number;
|
85
90
|
mode: number;
|
@@ -96,8 +101,8 @@ export declare class Geometry implements IGPUResource {
|
|
96
101
|
setAttributeData(name: string, data: TypedArray): void;
|
97
102
|
getAttributeData(name: string): TypedArray | undefined;
|
98
103
|
setAttributeSubData(name: string, offset: number, data: TypedArray): void;
|
99
|
-
getIndexData():
|
100
|
-
setIndexData(data:
|
104
|
+
getIndexData(): GeometryIndexData | undefined;
|
105
|
+
setIndexData(data: GeometryIndexData | undefined): void;
|
101
106
|
setIndexSubData(offset: number, data: TypedArray): void;
|
102
107
|
/**
|
103
108
|
* 获取Attribute的数据内存长度
|
@@ -119,7 +124,7 @@ export interface SharedGeometryOptions {
|
|
119
124
|
drawCount?: number;
|
120
125
|
mode?: number;
|
121
126
|
index?: {
|
122
|
-
data:
|
127
|
+
data: GeometryIndexData;
|
123
128
|
releasable?: boolean;
|
124
129
|
};
|
125
130
|
geometry: Geometry;
|
package/dist/types/Material.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Texture } from './Texture';
|
2
1
|
import type { ShaderUseCacheId, ShaderWithSource } from './ShaderLibrary';
|
3
2
|
import type { IGPUResource, IGPURenderer } from './IGPURenderer';
|
4
3
|
import type { Immutable, TypedArray } from './type';
|
5
4
|
import type { GPURenderer } from './Renderer';
|
6
5
|
import type { DestroyOptions } from './constants';
|
6
|
+
import type { Texture } from './Texture';
|
7
7
|
export type UniformSemantic = 'VIEW' | 'MODEL' | 'MODELVIEW' | 'PROJECTION' | 'VIEWPROJECTION' | 'MODELVIEWPROJECTION' | string;
|
8
8
|
export interface MaterialRenderStates {
|
9
9
|
sampleAlphaToCoverage?: boolean;
|
@@ -15,13 +15,13 @@ export interface MaterialRenderStates {
|
|
15
15
|
blendSrc?: number;
|
16
16
|
blendDst?: number;
|
17
17
|
/**
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
* The blend color is a state value,
|
19
|
+
* like the blend equations and blend parameters. Therefore,
|
20
|
+
* it cannot change within a single draw call;
|
21
|
+
* fragment shaders cannot write to, modify,
|
22
|
+
* or even access the blend color.
|
23
|
+
* All buffers share the same blend color.
|
24
|
+
*/
|
25
25
|
blendColor?: [r: number, g: number, b: number, a: number];
|
26
26
|
colorMask?: [r: boolean, g: boolean, b: boolean, a: boolean];
|
27
27
|
depthTest?: boolean;
|
@@ -52,12 +52,6 @@ export interface MaterialOptions {
|
|
52
52
|
shader: ShaderWithSource | ShaderUseCacheId;
|
53
53
|
name?: string;
|
54
54
|
dataBlocks?: MaterialDataBlockOptions[];
|
55
|
-
uniformSemantics?: {
|
56
|
-
[key: string]: UniformSemantic;
|
57
|
-
};
|
58
|
-
uniformValues?: {
|
59
|
-
[key: string]: UniformValue;
|
60
|
-
};
|
61
55
|
}
|
62
56
|
/**
|
63
57
|
* @example
|
@@ -85,7 +79,7 @@ export interface MaterialOptions {
|
|
85
79
|
* });
|
86
80
|
* mtl2 use the same program with mtl0
|
87
81
|
*/
|
88
|
-
export type UniformValueDataType = TypedArray | number | number[] |
|
82
|
+
export type UniformValueDataType = TypedArray | number | number[] | number[][];
|
89
83
|
export type UniformValue = UniformValueDataType | UniformStruct | UniformStruct[];
|
90
84
|
export type UniformStruct = {
|
91
85
|
[key: string]: UniformValueDataType;
|
@@ -107,14 +101,17 @@ export declare class Material implements IGPUResource {
|
|
107
101
|
addDataBlock(b: MaterialDataBlock): void;
|
108
102
|
removeDataBlock(b: MaterialDataBlock): void;
|
109
103
|
destroy(options?: MaterialDestroyOptions): void;
|
110
|
-
setUniformSemantic(uniformName: string, semantic: string | undefined): void;
|
111
104
|
assignRenderer(renderer: GPURenderer): Material;
|
112
105
|
}
|
113
106
|
export interface MaterialDataBlockOptions {
|
114
107
|
uniformValues?: {
|
115
108
|
[key: string]: UniformValue;
|
116
109
|
};
|
110
|
+
uniformTextures?: Record<string, Texture | Texture[]>;
|
117
111
|
name?: string;
|
112
|
+
uniformSemantics?: {
|
113
|
+
[key: string]: UniformSemantic;
|
114
|
+
};
|
118
115
|
}
|
119
116
|
export interface MaterialDataBlockDestroyOptions {
|
120
117
|
textures?: DestroyOptions;
|
@@ -123,8 +120,12 @@ export declare class MaterialDataBlock implements IGPUResource {
|
|
123
120
|
readonly renderer?: IGPURenderer;
|
124
121
|
readonly isDestroyed: boolean;
|
125
122
|
readonly name: string;
|
123
|
+
readonly uniformSemantics?: {
|
124
|
+
[key: string]: UniformSemantic;
|
125
|
+
};
|
126
126
|
constructor(options: MaterialDataBlockOptions);
|
127
127
|
hasUniformValue(name: string): boolean;
|
128
|
+
setUniformSemantic(name: string, semantic: string | undefined): void;
|
128
129
|
setUniformValue(name: string, value: UniformValue): boolean;
|
129
130
|
getUniformValue(name: string): UniformValue;
|
130
131
|
getUniformValues(): {
|
@@ -133,15 +134,17 @@ export declare class MaterialDataBlock implements IGPUResource {
|
|
133
134
|
setUniformValues(map: {
|
134
135
|
[key: string]: UniformValue;
|
135
136
|
}): void;
|
137
|
+
setUniformTexture(uniformName: string, texture: Texture | Texture[] | undefined): void;
|
138
|
+
getUniformTexture<T extends Texture[] | Texture = Texture>(uniformName: string): T | undefined;
|
136
139
|
/**
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
140
|
+
* indicate uniform data should be resent to GPU, but not the full range,
|
141
|
+
* only works for ubo,if not an ubo, this method has no side effect
|
142
|
+
* offset and count are counted by typed entry, not the number elements
|
143
|
+
* entry means matrix or vector in shader
|
144
|
+
* @param name uniform name
|
145
|
+
* @param offset entry offset,first entry to send to gpu, default 0
|
146
|
+
* @param count entry count,entry count to send to gpu,default to end
|
147
|
+
*/
|
145
148
|
updateUniformSubData(name: string, offset: number, count: number): void;
|
146
149
|
destroy(options?: MaterialDataBlockDestroyOptions): void;
|
147
150
|
assignRenderer(renderer: GPURenderer): MaterialDataBlock;
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
import type { RenderPass, RenderPassLoadAction, RenderPassDestroyOptions, SemanticMap } from './RenderPass';
|
1
|
+
import type { RenderPass, RenderPassLoadAction, RenderPassDestroyOptions, SemanticMap, SemanticGetter } from './RenderPass';
|
3
2
|
import type { Mesh } from './Mesh';
|
4
|
-
import type { GPUBuffer } from './GPUBuffer';
|
5
3
|
import type { vec4 } from './type';
|
6
4
|
import type { GPURenderer } from './index';
|
7
5
|
import type { IGPURenderer, IGPUResource } from './IGPURenderer';
|
@@ -16,12 +14,12 @@ export interface RenderFrameOptions {
|
|
16
14
|
renderPasses?: RenderPass[];
|
17
15
|
viewport?: vec4;
|
18
16
|
semantics?: {
|
19
|
-
[key: string]:
|
17
|
+
[key: string]: SemanticGetter;
|
20
18
|
};
|
21
19
|
loadAction?: RenderPassLoadAction;
|
22
20
|
name?: string;
|
23
21
|
}
|
24
|
-
export type SemanticFunc = (state: RenderState) =>
|
22
|
+
export type SemanticFunc = (state: RenderState) => SemanticGetter | null | undefined;
|
25
23
|
export type RenderFrameDestroyOptions = {
|
26
24
|
passes?: RenderPassDestroyOptions | DestroyOptions.keep;
|
27
25
|
semantics?: DestroyOptions;
|
@@ -81,7 +81,7 @@ export interface RenderPassAttachmentOptions {
|
|
81
81
|
viewportScale?: number;
|
82
82
|
multiSample?: number;
|
83
83
|
}
|
84
|
-
export type SemanticGetter = UniformValue | SemanticFunc | GPUBuffer;
|
84
|
+
export type SemanticGetter = UniformValue | SemanticFunc | GPUBuffer | Texture | Texture[];
|
85
85
|
export interface RenderPassOptions extends RenderPassAttachmentOptions {
|
86
86
|
name?: string;
|
87
87
|
meshes?: Mesh[];
|
@@ -119,7 +119,7 @@ export interface RenderPassDelegate {
|
|
119
119
|
willBeginRenderPass?: (renderPass: RenderPass, state: RenderState) => void;
|
120
120
|
didEndRenderPass?: (renderPass: RenderPass, state: RenderState) => void;
|
121
121
|
willRenderMesh?: (mesh: Mesh, state: RenderState) => void;
|
122
|
-
|
122
|
+
didRenderMesh?: (mesh: Mesh, state: RenderState) => void;
|
123
123
|
}
|
124
124
|
export declare class RenderPass implements IGPUResource {
|
125
125
|
readonly isDestroyed: boolean;
|
package/dist/types/Renderer.d.ts
CHANGED
@@ -24,8 +24,8 @@ export declare class GPURenderer implements IGPURenderer {
|
|
24
24
|
readonly height: number;
|
25
25
|
readonly width: number;
|
26
26
|
/**
|
27
|
-
|
28
|
-
|
27
|
+
* if webgl not support, gpu.level will be 0
|
28
|
+
*/
|
29
29
|
readonly shaderLibrary: ShaderLibrary;
|
30
30
|
readonly gpu: GPUCapability;
|
31
31
|
readonly canvas: Canvas;
|
@@ -35,17 +35,26 @@ export declare class GPURenderer implements IGPURenderer {
|
|
35
35
|
createRenderFrame(options?: RenderFrameOptions): RenderFrame;
|
36
36
|
createBuffer(options: GPUBufferOptions): GPUBuffer;
|
37
37
|
/**
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
* 根据不同平台封装实现 requestAnimationFrame,
|
39
|
+
* FrameRequestCallback函数回调中进行渲染数据更新,
|
40
|
+
* OpenGL/WebGL在绘制开始之前(传递此帧数据)
|
41
|
+
* Metal在commandBuffer提交后(传递下一帧数据)
|
42
|
+
* @param cb
|
43
|
+
*/
|
44
|
+
requestAnimationFrame(cb: FrameRequestCallback): number;
|
45
|
+
cancelAnimationFrame(id: number): void;
|
46
|
+
/**
|
47
|
+
* only resize when width or height is different from now,
|
48
|
+
* when resized,all full-screen renderPasses attached to this renderer should be resized as well
|
49
|
+
* 只有当宽高不同的时候,才实际进行函数
|
50
|
+
* 当重新调整宽高后,这个renderer创建的renderPasses,如果没有被指定 viewport(全屏),那么需要resize 所有的renderPass
|
51
|
+
* @param width
|
52
|
+
* @param height
|
53
|
+
*/
|
45
54
|
resize(width: number, height: number): void;
|
46
55
|
/**
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
* destroy all resources created by this renderer
|
57
|
+
* @param haltGL if true, this method will call webgl lose context extension which leads webgl absolutely halt
|
58
|
+
*/
|
50
59
|
destroy(haltGL?: boolean): void;
|
51
60
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export type Shader = ShaderWithSource | ShaderUseCacheId;
|
2
2
|
export type ShaderWithSource = InstancedShaderWithSource | SharedShaderWithSource;
|
3
3
|
export interface MetaShaderSpec {
|
4
|
-
mtlBinary?: ArrayBuffer;
|
4
|
+
mtlBinary?: ArrayBuffer | string;
|
5
5
|
mtlSource?: string;
|
6
6
|
mtlVertex?: string;
|
7
7
|
mtlFragment?: string;
|
@@ -51,9 +51,9 @@ export interface ShaderLibrary {
|
|
51
51
|
readonly cacheIds: string[];
|
52
52
|
getShaderResult(cacheId: string): ShaderCompileResult | undefined;
|
53
53
|
/**
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
* 添加shader
|
55
|
+
* @param shader
|
56
|
+
*/
|
57
57
|
addShader(shader: Shader): string;
|
58
58
|
/**
|
59
59
|
* @param cacheId
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { ResourceInternal } from './ResourceInternal';
|
2
2
|
import type { TypedArray } from '../type';
|
3
|
+
import type { TextureInternal } from './TextureInternal';
|
3
4
|
export interface DataBlockInternalOptions {
|
4
5
|
name: string;
|
5
6
|
}
|
@@ -26,4 +27,6 @@ export declare abstract class DataBlockInternal implements ResourceInternal {
|
|
26
27
|
* @param value
|
27
28
|
*/
|
28
29
|
abstract getUniformValue(name: string, value: TypedArray): boolean;
|
30
|
+
abstract setUniformTextures(uniformName: string, texture: TextureInternal[] | undefined): void;
|
31
|
+
abstract getUniformTextures(uniformName: string): TextureInternal[] | undefined;
|
29
32
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ResourceInternal } from './ResourceInternal';
|
2
2
|
import type { TypedArray } from '../type';
|
3
|
-
|
3
|
+
import type { GPUBufferOptionsMemoryShared } from '../GPUBuffer';
|
4
4
|
export interface GPUBufferInternalOptions {
|
5
5
|
data?: TypedArray;
|
6
6
|
options?: typeof GPUBufferOptionsMemoryShared;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { ResourceInternal } from './ResourceInternal';
|
2
2
|
import type { MaterialRenderStates } from '../Material';
|
3
3
|
import type { DataBlockInternal } from './DataBlockInternal';
|
4
|
-
import type { TextureInternal } from './TextureInternal';
|
5
4
|
export interface MaterialInternalOptions {
|
6
5
|
states: MaterialRenderStates;
|
7
6
|
dataBlocks: DataBlockInternal[];
|
@@ -15,12 +14,4 @@ export declare abstract class MaterialInternal implements ResourceInternal {
|
|
15
14
|
dataBlocks: DataBlockInternal[];
|
16
15
|
protected constructor(options: MaterialInternalOptions);
|
17
16
|
abstract destroy(): void;
|
18
|
-
/**
|
19
|
-
* 对于 uniform sampler2D uTex
|
20
|
-
* 和 uniform sampler2D uTextures[4] 都使用此函数
|
21
|
-
* @param name
|
22
|
-
* @param value
|
23
|
-
*/
|
24
|
-
abstract setUniformTextures(name: string, value: TextureInternal[]): void;
|
25
|
-
abstract getUniformTextures(name: string): TextureInternal[];
|
26
17
|
}
|
@@ -17,13 +17,9 @@ export declare abstract class RenderFrameInternal implements ResourceInternal {
|
|
17
17
|
protected constructor(options: RenderFrameInternalOptions);
|
18
18
|
abstract destroy(): void;
|
19
19
|
/**
|
20
|
-
*
|
21
|
-
*
|
20
|
+
* 代表此帧会在渲染队列的下一帧被渲染,调用此函数,也会调用renderer.invalid方法
|
21
|
+
* 由于渲染是异步的,此函数在Metal/Vulkan实现中,并不会直接绘制
|
22
22
|
*/
|
23
|
-
abstract
|
24
|
-
/**
|
25
|
-
* 将RenderFrame移除渲染队列
|
26
|
-
*/
|
27
|
-
abstract end(): void;
|
23
|
+
abstract render(): void;
|
28
24
|
abstract updateLoadAction(action: RenderPassLoadAction): void;
|
29
25
|
}
|
@@ -31,6 +31,10 @@ export declare abstract class RendererInternal implements ResourceInternal {
|
|
31
31
|
readonly width: number;
|
32
32
|
readonly height: number;
|
33
33
|
abstract destroy(): void;
|
34
|
+
/**
|
35
|
+
* 需要进行重新渲染
|
36
|
+
*/
|
37
|
+
abstract invalid(): void;
|
34
38
|
abstract createBuffer(options: GPUBufferInternalOptions): GPUBufferInternal;
|
35
39
|
abstract createGeometry(options: GeometryInternalOptions): GeometryInternal;
|
36
40
|
abstract createDataBlock(options: DataBlockInternalOptions): DataBlockInternal;
|
@@ -42,6 +46,12 @@ export declare abstract class RendererInternal implements ResourceInternal {
|
|
42
46
|
abstract getResourceInfo(): InternalResInfo;
|
43
47
|
abstract requestAnimationFrame(callback: (timestamp: number) => void): number;
|
44
48
|
abstract cancelAnimationFrame(id: number): void;
|
49
|
+
/**
|
50
|
+
* 获取错误信息,目前支持最大获取5条,
|
51
|
+
* 每次调用此函数后,清空错误队列
|
52
|
+
*/
|
53
|
+
abstract getErrors(): string[];
|
54
|
+
abstract resize(width: number, height: number): void;
|
45
55
|
abstract createImageBitmap(data: ArrayBuffer | string, //图片文件的数据
|
46
56
|
options: ImageBitmapConstructor, callback: ImageBitmapCallback): void;
|
47
57
|
}
|
@@ -4,6 +4,7 @@ import type { TypedArray } from '../type';
|
|
4
4
|
import type { ImageBitmapInternal } from './ImageBitmapInternal';
|
5
5
|
export interface TextureInternalOptions extends TextureFormatOptions, Omit<TextureConfigOptionsBase, 'keepImageSource'> {
|
6
6
|
target: WebGLRenderingContext['TEXTURE_CUBE_MAP'] | WebGLRenderingContext['TEXTURE_2D'];
|
7
|
+
generateMipmap?: boolean;
|
7
8
|
}
|
8
9
|
export interface TextureInternalConstructOptions extends TextureInternalOptions {
|
9
10
|
width: number;
|