@predy-js/render-interface 0.1.61-beta.1 → 0.1.61-beta.3

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.
@@ -1,70 +0,0 @@
1
- import type { UniformValue } from './Material';
2
- import type {
3
- RenderPass,
4
- RenderPassLoadAction,
5
- RenderPassDestroyOptions, SemanticMap,
6
- } from './RenderPass';
7
- import type { Mesh } from './Mesh';
8
- import type { GPUBuffer } from './GPUBuffer';
9
- import type { vec4 } from './type';
10
- import type { GPURenderer } from './index';
11
- import type { IGPURenderer, IGPUResource } from './IGPURenderer';
12
- import type { DestroyOptions } from './constants';
13
- import type { InstancedMesh } from './Mesh';
14
-
15
- export interface RenderState {
16
- currentMesh: Mesh | InstancedMesh,
17
- currentFrame: RenderFrame,
18
- currentPass: RenderPass,
19
- }
20
-
21
- export interface RenderFrameOptions {
22
- renderPasses?: RenderPass[],
23
- viewport?: vec4,
24
- semantics?: { [key: string]: UniformValue | SemanticFunc | GPUBuffer },
25
- loadAction?: RenderPassLoadAction,
26
- name?: string,
27
- }
28
-
29
- export type SemanticFunc = (state: RenderState) => UniformValue | GPUBuffer | null | undefined;
30
-
31
- export type RenderFrameDestroyOptions = {
32
- passes?: RenderPassDestroyOptions | DestroyOptions.keep,
33
- semantics?: DestroyOptions,
34
- };
35
-
36
- export declare class RenderFrame implements IGPUResource {
37
-
38
- public loadAction: RenderPassLoadAction;
39
-
40
- constructor (options: RenderFrameOptions, renderer?: GPURenderer);
41
-
42
- readonly renderPasses: RenderPass[];
43
-
44
- readonly viewport?: vec4;
45
-
46
- readonly semantics: SemanticMap;
47
-
48
- readonly renderer?: IGPURenderer;
49
-
50
- readonly isDestroyed: boolean;
51
-
52
- setRenderPasses (passes: RenderPass[]): void;
53
-
54
- addRenderPass (pass: RenderPass): void;
55
-
56
- removeRenderPass (pass: RenderPass): void;
57
-
58
- render (): void;
59
-
60
- destroy (options?: RenderFrameDestroyOptions): void;
61
-
62
- assignRenderer (renderer: IGPURenderer): RenderFrame ;
63
- }
64
-
65
- /**
66
- * RenderFrame 渲染顺序如下:
67
- * 1. renderFrame 按照priority由底到高渲染renderPass,renderPass如果有设置attachments,则会创建frameBuffer对象
68
- * 2. 每个renderPass渲染时,按照meshes数组顺序进行渲染,renderPass可以制定meshes数组的排序方式,对每个mesh的priority进行排序
69
- * 3. 遍历Mesh时会将其Material中的Shader添加至shaderLibrary,再调用render之前,将所有shader进行编译
70
- */
@@ -1,222 +0,0 @@
1
- import type {
2
- Texture, TextureConfigOptions, TextureFormatOptions,
3
- } from './Texture';
4
- import type { Mesh, MeshDestroyOptions } from './Mesh';
5
- import type { vec4 } from './type';
6
- import type { IGPURenderer, IGPUResource } from './IGPURenderer';
7
- import type { GPURenderer } from './Renderer';
8
- import type { UniformValue } from './Material';
9
- import type { GPUBuffer } from './GPUBuffer';
10
- import type { RenderState, SemanticFunc } from './RenderFrame';
11
- import type { DestroyOptions } from './constants';
12
-
13
- export enum RenderPassDestroyAttachmentType {
14
- force = 0,
15
- keep = 1,
16
- keepExternal = 2,
17
- destroy = force
18
- }
19
-
20
- export const RenderPassPriorityPrepare = 0;
21
- export const RenderPassPriorityNormal = 1000;
22
- export const RenderPassPriorityPostprocess = 3000;
23
-
24
- export enum TextureLoadAction {
25
- whatever = 0,
26
- //preserve previous attachment
27
- //load = 1,
28
- //clear attachment
29
- clear = 2,
30
- }
31
-
32
- export enum TextureStoreAction {
33
- store = 1,
34
- clear = 0
35
- }
36
-
37
- export enum RenderPassAttachmentStorageType {
38
- none = 0,
39
- color = 1,
40
- //stencil 8 render buffer
41
- stencil_8_opaque = 2,
42
- //stencil 16 render buffer
43
- depth_16_opaque = 3,
44
- //depth 16 & stencil 8 render buffer
45
- depth_stencil_opaque = 4,
46
- //depth 16 texture, need gpu.capability.readableDepthStencilTextures
47
- depth_16_texture = 5,
48
- //depth 24 texture, need gpu.capability.readableDepthStencilTextures
49
- depth_24_stencil_8_texture = 6,
50
-
51
- }
52
-
53
- export interface RenderPassStorageObject {
54
- readonly attachment: GLenum,
55
- readonly format: GLenum,
56
- readonly size: [width: number, height: number],
57
- readonly storageType: RenderPassAttachmentStorageType,
58
- readonly multiSample: number,
59
- }
60
-
61
- export interface RenderPassColorAttachmentTextureOptions extends TextureFormatOptions, TextureConfigOptions {
62
- }
63
-
64
- export interface RenderPassColorAttachmentOptions {
65
- // color storage must be texture or textureOptions
66
- texture?: Texture | RenderPassColorAttachmentTextureOptions,
67
- storage?: RenderPassStorageObject,
68
- }
69
-
70
- export interface RenderPassColorAttachment {
71
- readonly storageType: RenderPassAttachmentStorageType.color,
72
- readonly texture: Texture,
73
- readonly isDestroyed: boolean,
74
- }
75
-
76
- export interface RenderPassDepthStencilAttachment {
77
- readonly storageType: RenderPassAttachmentStorageType,
78
- readonly texture?: Texture,
79
- readonly storage: RenderPassStorageObject,
80
- }
81
-
82
- export interface RenderPassDepthStencilAttachmentOptions {
83
- storageType: RenderPassAttachmentStorageType,
84
- storage?: RenderPassStorageObject,
85
- texture?: Texture,
86
- }
87
-
88
- export interface RenderPassStoreAction {
89
- depthAction?: TextureStoreAction,
90
- stencilAction?: TextureStoreAction,
91
- colorAction?: TextureStoreAction,
92
- }
93
-
94
- export interface RenderPassLoadAction {
95
- clearColor?: vec4,
96
- colorAction?: TextureLoadAction,
97
- clearDepth?: number,
98
- depthAction?: TextureLoadAction,
99
- clearStencil?: number,
100
- stencilAction?: TextureLoadAction,
101
- }
102
-
103
- export interface RenderPassAttachmentOptions {
104
- attachments?: RenderPassColorAttachmentOptions[],
105
- depthStencilAttachment?: RenderPassDepthStencilAttachmentOptions,
106
- //if viewport not set,it will use viewportScale
107
- viewport?: [x: number, y: number, width: number, height: number],
108
- //default 1 , when renderer resize, this attachment will be resized to same scale
109
- //todo 增加测试:
110
- // 1.viewport 提供时,忽略此参数,renderPass的尺寸由viewport决定,无论renderer是否变化尺寸
111
- // 2.viewportScale 默认为1,renderPass的尺寸由renderer的尺寸决定,renderer尺寸变化时,renderPass的尺寸也会变化
112
- // 3.renderPass的color/depth_stencil attachment尺寸由
113
- viewportScale?: number,
114
- //in webgl2 use multisample renderbuffer
115
- //default is 0, means disabled
116
- //only enabled in webgl2
117
- multiSample?: number,
118
- }
119
-
120
- export type SemanticGetter = UniformValue | SemanticFunc | GPUBuffer;
121
-
122
- export interface RenderPassOptions extends RenderPassAttachmentOptions {
123
- name?: string,
124
- meshes?: Mesh[],
125
- priority?: number,
126
- meshOrder?: RenderPassMeshOrder,
127
- loadAction?: RenderPassLoadAction,
128
- storeAction?: RenderPassStoreAction,
129
- semantics?: { [key: string]: SemanticGetter },
130
- delegate?: RenderPassDelegate,
131
- }
132
-
133
- export enum RenderPassMeshOrder {
134
- none = 1,
135
- ascending = 2,
136
- descending = 3
137
- }
138
-
139
- export type RenderPassDestroyOptions = {
140
- meshes?: MeshDestroyOptions | DestroyOptions.keep,
141
- depthStencilAttachment?: RenderPassDestroyAttachmentType,
142
- colorAttachment?: RenderPassDestroyAttachmentType,
143
- semantics?: DestroyOptions,
144
- };
145
-
146
- export declare class SemanticMap {
147
-
148
- constructor (options?: { [key: string]: SemanticGetter });
149
-
150
- setSemantic (name: string, value: SemanticGetter | undefined): void;
151
-
152
- getSemanticValue (name: string, state: RenderState): UniformValue | GPUBuffer | null | undefined;
153
-
154
- hasSemanticValue (name: string): boolean;
155
-
156
- toObject (): Record<string, SemanticGetter>;
157
-
158
- destroy (): void;
159
-
160
- }
161
-
162
- export interface RenderPassDelegate {
163
- willBeginRenderPass?: (renderPass: RenderPass, state: RenderState) => void,
164
- didEndRenderPass?: (renderPass: RenderPass, state: RenderState) => void,
165
- willRenderMesh?: (mesh: Mesh, state: RenderState) => void,
166
- didiRenderMesh?: (mesh: Mesh, state: RenderState) => void,
167
- }
168
-
169
- export declare class RenderPass implements IGPUResource {
170
-
171
- readonly isDestroyed: boolean;
172
-
173
- readonly name: string;
174
-
175
- readonly priority: number;
176
-
177
- readonly attachments: RenderPassColorAttachment[];
178
-
179
- readonly depthAttachment?: RenderPassDepthStencilAttachment;
180
-
181
- readonly stencilAttachment?: RenderPassDepthStencilAttachment;
182
-
183
- readonly viewport: [x: number, y: number, width: number, height: number];
184
-
185
- readonly meshes: Mesh[];
186
-
187
- readonly renderer?: IGPURenderer;
188
-
189
- readonly semantics: SemanticMap;
190
-
191
- readonly storeAction: RenderPassStoreAction;
192
-
193
- readonly loadAction: RenderPassLoadAction;
194
-
195
- readonly multisample: number;
196
-
197
- delegate: RenderPassDelegate;
198
-
199
- meshOrder: RenderPassMeshOrder;
200
-
201
- constructor (options: RenderPassOptions, renderer?: IGPURenderer);
202
-
203
- /**
204
- * reset color/depth_stencil attachments,
205
- * if color/depth_stencil texture is external, this will not destroy textures
206
- * if color/depth_stencil texture is internal created, this will also delete those textures
207
- * this method will delete previous fbo if exists
208
- * returns previous options
209
- **/
210
- resetAttachments (options: RenderPassAttachmentOptions): RenderPassAttachmentOptions;
211
-
212
- setMeshes (meshes: Mesh[]): Mesh[];
213
-
214
- addMesh (mesh: Mesh): void;
215
-
216
- removeMesh (mesh: Mesh): void;
217
-
218
- destroy (options?: RenderPassDestroyOptions): void;
219
-
220
- assignRenderer (renderer: GPURenderer): RenderPass;
221
-
222
- }
package/types/Renderer.ts DELETED
@@ -1,62 +0,0 @@
1
- import type { RenderFrame, RenderFrameOptions } from './RenderFrame';
2
- import type { ShaderLibrary } from './ShaderLibrary';
3
- import type { GPUCapability } from './GPUCapability';
4
- import type { GPUBuffer, GPUBufferOptions } from './GPUBuffer';
5
- import type { IGPURenderer } from './IGPURenderer';
6
- import type { Canvas } from './Canvas';
7
- import type { Texture } from './Texture';
8
- import type { RenderPass } from './RenderPass';
9
-
10
- export interface RendererOptions {
11
- gl?: WebGLRenderingContext | WebGL2RenderingContext,
12
- canvas?: HTMLCanvasElement,
13
- // if use frameworks [ 'webgl2', 'webgl' ], renderer will choose webgl if webgl2 is not supported
14
- frameworks?: Array<'webgl' | 'webgl2'>,
15
- willCaptureImage?: boolean,
16
- premultiplyAlpha?: boolean,
17
- }
18
-
19
- /**
20
- * 常用的GPU方法,不是规范必须实现的
21
- */
22
- export interface RendererExtensions {
23
- copyTexture?: (source: Texture, tex: Texture) => void,
24
- resetColorAttachments?: (rp: RenderPass, colorAttachments: Texture[]) => void,
25
- }
26
-
27
- export declare class GPURenderer implements IGPURenderer {
28
- readonly height: number;
29
- readonly width: number;
30
- /**
31
- * if webgl not support, gpu.level will be 0
32
- */
33
- readonly shaderLibrary: ShaderLibrary;
34
- readonly gpu: GPUCapability;
35
- readonly canvas: Canvas;
36
-
37
- readonly extension: RendererExtensions;
38
- readonly isDestroyed: boolean;
39
-
40
- constructor (options: RendererOptions);
41
-
42
- createRenderFrame (options?: RenderFrameOptions): RenderFrame;
43
-
44
- createBuffer (options: GPUBufferOptions): GPUBuffer;
45
-
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
- */
54
- resize (width: number, height: number): void;
55
-
56
- /**
57
- * destroy all resources created by this renderer
58
- * @param haltGL if true, this method will call webgl lose context extension which leads webgl absolutely halt
59
- */
60
- destroy (haltGL?: boolean): void;
61
-
62
- }
@@ -1,128 +0,0 @@
1
- export type Shader = ShaderWithSource | ShaderUseCacheId;
2
- export type ShaderWithSource = InstancedShaderWithSource | SharedShaderWithSource;
3
-
4
- export interface MetaShaderSpec {
5
- mtlBinary?: ArrayBuffer | string,
6
- mtlSource?: string,
7
-
8
- mtlVertex?: string,
9
- mtlFragment?: string,
10
- }
11
-
12
- export interface ShaderSourceBase extends MetaShaderSpec {
13
- fragment: string,
14
- vertex: string,
15
- name?: string,
16
- //将es300的shader in/out关键字替换为attribute/varying
17
- downgrade?: boolean,
18
- marcos?: ShaderMarcos,
19
- }
20
-
21
- export interface InstancedShaderWithSource extends ShaderSourceBase {
22
- shared?: false,
23
- }
24
-
25
- export interface SharedShaderWithSource extends ShaderSourceBase {
26
- //相同cacheId的shader会使用同一个GLProgram
27
- //提供了cacheId就会认为是shared Shader
28
- cacheId?: string,
29
- //shared为true时,
30
- //如果没有提供cacheId,会根据字符串hash计算出 cacheId,
31
- //字符串相同的shader将会使用同一个GLProgram
32
- //如果提供了cacheId,cacheId相同的,都会使用同一个GLProgram
33
- shared: true,
34
- }
35
-
36
- export interface ShaderUseCacheId {
37
- cacheId: string,
38
- }
39
-
40
- export type ShaderMarcos = [key: string, value: string | number | boolean][];
41
-
42
- export enum ShaderCompileResultStatus {
43
- noShader = 0,
44
- success = 1,
45
- fail = 2,
46
- compiling = 3
47
- }
48
-
49
- export interface ShaderCompileResult {
50
- status: ShaderCompileResultStatus,
51
- cacheId?: string,
52
- error?: string | null,
53
- compileTime?: number,
54
- // deprecated
55
- shared?: boolean,
56
- }
57
-
58
- /**
59
- * @example
60
- * const lib:ShaderLibrary = ...;
61
- * const shaderCacheId = lib.addShader({fragment:'...',vertex:'...'});
62
- * lib.compileShader(shaderCacheId);
63
- * //pre-compiled program
64
- * const mtl = new Material({
65
- * shader:{ shaderCacheId }
66
- * })
67
- */
68
- export interface ShaderLibrary {
69
-
70
- readonly cacheIds: string[],
71
-
72
- getShaderResult(cacheId: string): ShaderCompileResult | undefined,
73
-
74
- /**
75
- * 添加shader
76
- * @param shader
77
- */
78
- addShader(shader: Shader): string,
79
-
80
- /**
81
- * @param cacheId
82
- */
83
- deleteShader(cacheId: string): void,
84
-
85
- /**
86
- * 编译shader
87
- * @param shaderCacheId
88
- * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
89
- */
90
- compileShader(shaderCacheId: string, asyncCallback?: (result: ShaderCompileResult) => void): ShaderCompileResult,
91
-
92
- /***
93
- * 编译现有的所有shader
94
- * @param asyncCallback 如果传入,则会启用异步编译,当所有编译完成后被回调
95
- */
96
- compileAllShaders(asyncCallback?: (results: ShaderCompileResult[]) => void): void,
97
-
98
- destroy(): void,
99
- }
100
-
101
- export class ShaderLibraryEmpty implements ShaderLibrary {
102
-
103
- get cacheIds () {
104
- return [];
105
- }
106
-
107
- getShaderResult (cacheId: string): ShaderCompileResult | undefined {
108
- return undefined;
109
- }
110
-
111
- addShader (shader: Shader, marcos?: ShaderMarcos) {
112
- return '';
113
- }
114
-
115
- compileAllShaders (asyncCallback?: (results: ShaderCompileResult[]) => void) {
116
- return [];
117
- }
118
-
119
- deleteShader (cacheId: string) {
120
- }
121
-
122
- compileShader (shaderCacheId: string): ShaderCompileResult {
123
- return { status: ShaderCompileResultStatus.fail };
124
- }
125
-
126
- destroy () {
127
- }
128
- }