@predy-js/render-interface 0.1.25-beta.20 → 0.1.25-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/statistic.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.1.25-beta.20
5
+ * Version: v0.1.25-beta.22
6
6
  */
7
7
 
8
8
  // https://github.com/greggman/webgl-memory/blob/main/src/texture-utils.js
@@ -67,12 +67,8 @@ export interface GeometryOptions {
67
67
  mode?: GeometryDrawMode;
68
68
  drawCount?: number;
69
69
  drawStart?: number;
70
- TransformFeedbackTarget?: TransformFeedbackTarget;
71
70
  bufferUsage?: GLenum;
72
71
  }
73
- type TransformFeedbackTarget = {
74
- [key: string]: number;
75
- };
76
72
  export declare class Geometry implements IGPUResource {
77
73
  readonly renderer?: IGPURenderer;
78
74
  /**
@@ -106,7 +102,6 @@ export declare class Geometry implements IGPUResource {
106
102
  * 获取Attribute的数据内存长度
107
103
  * 如果此Attribute设置了其他dataSource则返回 0
108
104
  * 无论是否设置了attribute releasable,此函数总是返回实际数据长度
109
- * //todo liyaohui.lyh@antgroup.com
110
105
  * @param name
111
106
  */
112
107
  getAttributeDataLength(name: string): number;
@@ -140,4 +135,3 @@ export declare class SharedGeometry extends Geometry {
140
135
  */
141
136
  constructor(options: SharedGeometryOptions, renderer?: IGPURenderer);
142
137
  }
143
- export {};
@@ -45,8 +45,7 @@ export interface MaterialRenderStates {
45
45
  polygonOffsetFill?: boolean;
46
46
  }
47
47
  export declare const enum MaterialRenderType {
48
- normal = 0,
49
- transformFeedback = 1
48
+ normal = 0
50
49
  }
51
50
  export interface MaterialOptions {
52
51
  states: MaterialRenderStates;
@@ -56,14 +55,9 @@ export interface MaterialOptions {
56
55
  uniformSemantics?: {
57
56
  [key: string]: UniformSemantic;
58
57
  };
59
- renderType?: MaterialRenderType;
60
58
  uniformValues?: {
61
59
  [key: string]: UniformValue;
62
60
  };
63
- transformFeedbackOutput?: {
64
- mode: WebGL2RenderingContext['INTERLEAVED_ATTRIBS'] | WebGL2RenderingContext['SEPARATE_ATTRIBS'];
65
- varyings: string[];
66
- };
67
61
  }
68
62
  /**
69
63
  * @example
@@ -108,7 +102,6 @@ export declare class Material implements IGPUResource {
108
102
  readonly options: Immutable<MaterialOptions>;
109
103
  readonly shaderCacheId: string;
110
104
  readonly states: Immutable<MaterialRenderStates>;
111
- readonly renderType: MaterialRenderType;
112
105
  readonly isDestroyed: boolean;
113
106
  constructor(options: MaterialOptions);
114
107
  addDataBlock(b: MaterialDataBlock): void;
@@ -48,7 +48,7 @@ export interface RenderPassColorAttachmentOptions {
48
48
  storage?: RenderPassStorageObject;
49
49
  }
50
50
  export interface RenderPassColorAttachment {
51
- readonly storageType: RenderPassAttachmentStorageType;
51
+ readonly storageType: RenderPassAttachmentStorageType.color;
52
52
  readonly texture: Texture;
53
53
  readonly isDestroyed: boolean;
54
54
  }
@@ -86,7 +86,6 @@ export type SemanticGetter = UniformValue | SemanticFunc | GPUBuffer;
86
86
  export interface RenderPassOptions extends RenderPassAttachmentOptions {
87
87
  name?: string;
88
88
  meshes?: Mesh[];
89
- camera?: Camera;
90
89
  priority?: number;
91
90
  meshOrder?: RenderPassMeshOrder;
92
91
  clearAction?: RenderPassClearAction;
@@ -1,21 +1,24 @@
1
1
  export type Shader = ShaderWithSource | ShaderUseCacheId;
2
2
  export type ShaderWithSource = InstancedShaderWithSource | SharedShaderWithSource;
3
- export interface InstancedShaderWithSource {
4
- fragment: string;
5
- vertex: string;
6
- name?: string;
7
- marcos?: ShaderMarcos;
8
- shared?: false;
9
- downgrade?: boolean;
3
+ export interface MetaShaderSpec {
4
+ mtlSource?: string;
5
+ mtlVertex?: string;
6
+ mtlFragment?: string;
7
+ mtlBinary?: ArrayBuffer;
10
8
  }
11
- export interface SharedShaderWithSource {
9
+ export interface ShaderSourceBase extends MetaShaderSpec {
12
10
  fragment: string;
13
11
  vertex: string;
14
12
  name?: string;
15
13
  downgrade?: boolean;
16
14
  marcos?: ShaderMarcos;
15
+ }
16
+ export interface InstancedShaderWithSource extends ShaderSourceBase {
17
+ shared?: false;
18
+ }
19
+ export interface SharedShaderWithSource extends ShaderSourceBase {
17
20
  cacheId?: string;
18
- shared?: true;
21
+ shared: true;
19
22
  }
20
23
  export interface ShaderUseCacheId {
21
24
  cacheId: string;
@@ -50,19 +53,19 @@ export interface ShaderLibrary {
50
53
  };
51
54
  addShader(shader: Shader): string;
52
55
  /**
53
- * @param cacheId
54
- */
56
+ * @param cacheId
57
+ */
55
58
  deleteShader(cacheId: string): void;
56
59
  /**
57
- * 编译shader
58
- * @param shaderCacheId
59
- * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
60
- */
60
+ * 编译shader
61
+ * @param shaderCacheId
62
+ * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
63
+ */
61
64
  compileShader(shaderCacheId: string, asyncCallback?: (result: ShaderCompileResult) => void): ShaderCompileResult;
62
65
  /***
63
- * 编译现有的所有shader
64
- * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
65
- */
66
+ * 编译现有的所有shader
67
+ * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
68
+ */
66
69
  compileAllShaders(asyncCallback?: (results: ShaderCompileResult[]) => void): void;
67
70
  destroy(): void;
68
71
  }
@@ -0,0 +1,18 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { TypedArray } from '../type';
3
+ import type { TextureInternal } from './TextureInternal';
4
+ export type UniformValueInternal = TypedArray | number | number[];
5
+ export interface DataBlockInternalOptions {
6
+ name: string;
7
+ }
8
+ export declare abstract class DataBlockInternal implements ResourceInternal {
9
+ readonly isDestroyed: boolean;
10
+ readonly platform: ResourcePlatform;
11
+ readonly name: string;
12
+ protected constructor(options: DataBlockInternalOptions);
13
+ abstract destroy(): void;
14
+ abstract setUniformValue(name: string, value: UniformValueInternal): void;
15
+ abstract setUniformTexture(name: string, value: TextureInternal): void;
16
+ abstract getUniformValue(name: string): UniformValueInternal | void;
17
+ abstract getUniformTexture(name: string): TextureInternal;
18
+ }
@@ -0,0 +1,37 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { TypedArray } from '../type';
3
+ export declare const GPUBufferOptionsMemoryShared: number;
4
+ export interface GPUBufferInternalOptions {
5
+ data?: TypedArray;
6
+ options?: typeof GPUBufferOptionsMemoryShared;
7
+ }
8
+ /**
9
+ * 内存写入GPU的具体时机由框架自行决定,只要保证在渲染前输入GPU即可
10
+ */
11
+ export declare abstract class GPUBufferInternal implements ResourceInternal {
12
+ readonly isDestroyed: boolean;
13
+ readonly platform: ResourcePlatform;
14
+ readonly byteLength: number;
15
+ protected constructor(options: GPUBufferInternalOptions);
16
+ abstract destroy(): void;
17
+ /**
18
+ * 整段替换数据,替换后byteLength会发生改变
19
+ * 内存写入GPU的具体时机由框架自行决定,只要保证在渲染前输入GPU即可
20
+ * 数据输入GPU后,可以丢弃内存端的数据
21
+ * @param typedArray
22
+ */
23
+ abstract bufferData(typedArray: TypedArray): void;
24
+ /**
25
+ * 部分替换数据,如果offset+data的长度大于目前的byteLength,需要重新申请新的内存,整段替换
26
+ * @param byteOffset 指针的offset,无类型区分
27
+ * @param data
28
+ */
29
+ abstract bufferSubData(byteOffset: number, data: TypedArray): void;
30
+ /**
31
+ * 读取GPU数据,当创建参数有 GPUBufferOptionsMemoryShared 时,必须能读取到数据
32
+ * 当框架没有读取到数据时,返回false
33
+ * @param typedArray 将数据写入的arrayBuffer
34
+ * @param offset 写入的指针偏移
35
+ */
36
+ abstract readSubData(typedArray: TypedArray, offset?: number): boolean;
37
+ }
@@ -0,0 +1,30 @@
1
+ import type { AttributeWithType, GeometryOptions } from '../Geometry';
2
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
3
+ import type { AttributeBase } from '../Geometry';
4
+ import type { GPUBufferInternal } from './GPUBufferInternal';
5
+ interface AttributeWithBuffer extends AttributeBase {
6
+ buffer: GPUBufferInternal;
7
+ }
8
+ export interface GeometryInternalOptions extends Omit<GeometryOptions, 'attributes'> {
9
+ attributes: {
10
+ attr: AttributeWithBuffer | AttributeWithType;
11
+ name: string;
12
+ }[];
13
+ }
14
+ export type IndexBufferType = WebGLRenderingContext['UNSIGNED_SHORT'] | WebGLRenderingContext['UNSIGNED_INT'];
15
+ /**
16
+ * geometry中的数据都以buffer形式保存
17
+ */
18
+ export declare abstract class GeometryInternal implements ResourceInternal {
19
+ readonly isDestroyed: boolean;
20
+ readonly platform: ResourcePlatform;
21
+ drawStart: number;
22
+ drawCount: number;
23
+ mode: GLenum;
24
+ protected constructor(options: GeometryInternalOptions);
25
+ abstract setAttributeBuffer(name: string, buffer: GPUBufferInternal | undefined): void;
26
+ abstract getAttributeBuffer(name: string): GPUBufferInternal | undefined;
27
+ abstract setIndexBuffer(buffer: GPUBufferInternal | undefined, bufferType: IndexBufferType): void;
28
+ abstract destroy(): void;
29
+ }
30
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { MaterialRenderStates } from '../Material';
3
+ import type { DataBlockInternal } from './DataBlockInternal';
4
+ export interface MaterialInternalOptions {
5
+ states: MaterialRenderStates;
6
+ shaderCacheId: string;
7
+ dataBlocks: DataBlockInternal[];
8
+ name?: string;
9
+ }
10
+ export declare abstract class MaterialInternal implements ResourceInternal {
11
+ readonly isDestroyed: boolean;
12
+ readonly platform: ResourcePlatform;
13
+ readonly name: string;
14
+ dataBlocks: DataBlockInternal[];
15
+ protected constructor(options: MaterialInternalOptions);
16
+ abstract destroy(): void;
17
+ }
@@ -0,0 +1,20 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { GeometryInternal } from './GeometryInternal';
3
+ import type { MaterialInternal } from './MaterialInternal';
4
+ export interface MeshInternalOptions {
5
+ name?: string;
6
+ geometries: GeometryInternal[];
7
+ material: MaterialInternal;
8
+ priority?: number;
9
+ }
10
+ export declare abstract class MeshInternal implements ResourceInternal {
11
+ readonly isDestroyed: boolean;
12
+ readonly platform: ResourcePlatform;
13
+ readonly name: string;
14
+ geometries: GeometryInternal[];
15
+ material: MaterialInternal;
16
+ priority: number;
17
+ hide: boolean;
18
+ protected constructor(options: MeshInternalOptions);
19
+ abstract destroy(): void;
20
+ }
@@ -0,0 +1,26 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { RenderPassInternal } from './RenderPassInternal';
3
+ import type { RenderPassClearAction } from '../RenderPass';
4
+ export interface RenderFrameInternalOptions {
5
+ renderPasses: RenderPassInternal[];
6
+ clearAction: RenderPassClearAction;
7
+ name: string;
8
+ }
9
+ export declare abstract class RenderFrameInternal implements ResourceInternal {
10
+ readonly isDestroyed: boolean;
11
+ readonly platform: ResourcePlatform;
12
+ readonly clearAction: RenderPassClearAction;
13
+ readonly name: string;
14
+ /**
15
+ * 增删改查的操作,在warp层对renderPassInternals进行后,得到的数据全部覆盖当前数据
16
+ */
17
+ renderPasses: RenderPassInternal[];
18
+ protected constructor(options: RenderFrameInternalOptions);
19
+ abstract destroy(): void;
20
+ /**
21
+ * warp层完成所有数据传输后,通知客户端,可以进行实际渲染,
22
+ * 实际渲染根据客户端时机进行
23
+ */
24
+ abstract flush(): void;
25
+ abstract updateClearAction(action: RenderPassClearAction): void;
26
+ }
@@ -0,0 +1,56 @@
1
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
2
+ import type { MeshInternal } from './MeshInternal';
3
+ import type { RenderPassClearAction, RenderPassStoreAction } from '../RenderPass';
4
+ import type { TextureInternal } from './TextureInternal';
5
+ import type { RenderPassStorageObject } from '../RenderPass';
6
+ import type { RenderPassAttachmentStorageType } from '../RenderPass';
7
+ import type { Mesh } from '../Mesh';
8
+ export interface RenderPassColorAttachmentInternal {
9
+ readonly storageType: RenderPassAttachmentStorageType.color;
10
+ readonly texture: TextureInternal;
11
+ }
12
+ export interface RenderPassDepthStencilAttachmentInternal {
13
+ readonly storageType: RenderPassAttachmentStorageType;
14
+ readonly texture?: TextureInternal;
15
+ readonly storage?: RenderPassStorageObjectInternal;
16
+ }
17
+ /**
18
+ * 在Metal里面,所有的RenderPassAttachment都以Texture存储
19
+ * 在GL中,可以使用RenderTarget/Texture作为fbo的attachment
20
+ */
21
+ export interface RenderPassStorageObjectInternal extends RenderPassStorageObject {
22
+ _mtlTexture?: TextureInternal;
23
+ _glRenderBuffer?: WebGLRenderbuffer;
24
+ }
25
+ export interface RenderPassDepthStencilAttachmentOptionsInternal {
26
+ storageType: RenderPassAttachmentStorageType;
27
+ texture?: TextureInternal;
28
+ storage?: RenderPassStorageObjectInternal;
29
+ }
30
+ export interface RenderPassOptionsInternal {
31
+ clearAction: RenderPassClearAction;
32
+ storeAction: RenderPassStoreAction;
33
+ attachments: RenderPassColorAttachmentInternal[];
34
+ depthStencilAttachment: RenderPassDepthStencilAttachmentOptionsInternal;
35
+ name: string;
36
+ meshes: Mesh[];
37
+ multiSample: number;
38
+ viewport?: [x: number, y: number, width: number, height: number];
39
+ }
40
+ export declare abstract class RenderPassInternal implements ResourceInternal {
41
+ readonly isDestroyed: boolean;
42
+ readonly platform: ResourcePlatform;
43
+ readonly name: string;
44
+ readonly storeAction: RenderPassStoreAction;
45
+ readonly clearAction: RenderPassClearAction;
46
+ readonly multisample: number;
47
+ readonly depthStencilAttachment: RenderPassDepthStencilAttachmentInternal;
48
+ readonly attachments: RenderPassColorAttachmentInternal[];
49
+ /**
50
+ * 增删改查的操作,在warp层对Mesh进行后,得到的数据全部覆盖当前数据
51
+ */
52
+ meshes: MeshInternal[];
53
+ priority: number;
54
+ protected constructor(options: RenderPassOptionsInternal);
55
+ abstract destroy(): void;
56
+ }
@@ -0,0 +1,32 @@
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
+ /**
12
+ * renderer 内部创建的对象,用来统计信息,排查资源泄漏的问题
13
+ */
14
+ export interface InternalResInfo {
15
+ buffer: number;
16
+ geometry: number;
17
+ }
18
+ export declare abstract class RendererInternal implements ResourceInternal {
19
+ readonly isDestroyed: boolean;
20
+ readonly platform: ResourcePlatform;
21
+ readonly gpu: GPUCapability;
22
+ readonly shaderLibrary: ShaderLibraryInternal;
23
+ abstract destroy(): void;
24
+ abstract createBuffer(options: GPUBufferInternalOptions): GPUBufferInternal;
25
+ abstract createGeometry(options: GeometryInternalOptions): GeometryInternal;
26
+ abstract createDataBlock(options: DataBlockInternalOptions): DataBlockInternal;
27
+ abstract createMaterial(options: MaterialInternalOptions): MaterialInternal;
28
+ abstract createMesh(options: MeshInternalOptions): MeshInternal;
29
+ abstract createRenderPass(options: RenderPassOptionsInternal): RenderPassInternal;
30
+ abstract createRenderFrame(options: RenderFrameInternalOptions): RenderFrameInternal;
31
+ abstract getResourceInfo(): InternalResInfo;
32
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 客户端创建对象,iOS和android
3
+ */
4
+ export declare enum ResourcePlatform {
5
+ iOS = 1,
6
+ android = 2
7
+ }
8
+ export interface ResourceInternal {
9
+ readonly platform: ResourcePlatform;
10
+ readonly isDestroyed: boolean;
11
+ destroy(): void;
12
+ }
@@ -0,0 +1,11 @@
1
+ import type { ShaderLibrary, Shader, ShaderCompileResult } from '../ShaderLibrary';
2
+ export declare abstract class ShaderLibraryInternal implements ShaderLibrary {
3
+ readonly shaderResults: {
4
+ [p: string]: ShaderCompileResult;
5
+ };
6
+ abstract addShader(shader: Shader): string;
7
+ abstract compileAllShaders(asyncCallback?: (results: ShaderCompileResult[]) => void): void;
8
+ abstract compileShader(shaderCacheId: string, asyncCallback?: (result: ShaderCompileResult) => void): ShaderCompileResult;
9
+ abstract deleteShader(cacheId: string): void;
10
+ abstract destroy(): void;
11
+ }
@@ -0,0 +1,25 @@
1
+ import type { TextureFormatOptions, TextureConfigOptionsBase } from '../Texture';
2
+ import type { ResourceInternal, ResourcePlatform } from './ResourceInternal';
3
+ export interface TextureImageLike {
4
+ data: Uint8Array;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export interface TextureInternalOptions extends TextureFormatOptions, Omit<TextureConfigOptionsBase, 'keepImageSource'> {
9
+ target: WebGLRenderingContext['TEXTURE_CUBE_MAP'] | WebGLRenderingContext['TEXTURE_2D'];
10
+ image?: TextureImageLike;
11
+ cube?: TextureImageLike[];
12
+ }
13
+ export declare abstract class TextureInternal implements ResourceInternal {
14
+ readonly isDestroyed: boolean;
15
+ readonly platform: ResourcePlatform;
16
+ readonly width: number;
17
+ readonly height: number;
18
+ readonly name: string;
19
+ readonly options: Omit<TextureInternalOptions, 'cube' | 'image'>;
20
+ protected constructor(options: TextureInternalOptions);
21
+ abstract reset(options: TextureInternalOptions): void;
22
+ abstract destroy(): void;
23
+ abstract update2DData(image: TextureImageLike): void;
24
+ abstract updateCubeData(face: GLenum, image: TextureImageLike): void;
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@predy-js/render-interface",
3
- "version": "0.1.25-beta.20",
3
+ "version": "0.1.25-beta.22",
4
4
  "license": "MIT",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",