UNPKG

7.24 kBTypeScriptView Raw
1import { Component, ComponentManager } from './ComponentManager';
2import { gl } from './components/renderer/gl';
3export type { IAttribute, IAttributeInitializationOptions, } from './components/renderer/IAttribute';
4export type { IBuffer, IBufferInitializationOptions, } from './components/renderer/IBuffer';
5export type { IComputeModel } from './components/renderer/IComputeModel';
6export type { IElements, IElementsInitializationOptions, } from './components/renderer/IElements';
7export type { IFramebuffer, IFramebufferInitializationOptions, } from './components/renderer/IFramebuffer';
8export type { IModel, IModelDrawOptions, IModelInitializationOptions, } from './components/renderer/IModel';
9export type { IRenderbuffer, IRenderbufferInitializationOptions, } from './components/renderer/IRenderbuffer';
10export type { BufferData, IClearOptions, IReadPixelsOptions, IRendererConfig, IRendererService, IViewport, } from './components/renderer/IRendererService';
11export type { ITexture2D, ITexture2DInitializationOptions, } from './components/renderer/ITexture2D';
12export type { IUniform } from './components/renderer/IUniform';
13import { createEntity } from './Entity';
14import { ConfigService } from './services/config/ConfigService';
15export type { IConfig, IConfigService } from './services/config/IConfigService';
16export type { IShaderModuleService } from './services/shader-module/IShaderModuleService';
17import { isSafari } from './utils/isSafari';
18declare type Entity = number;
19declare enum AST_TOKEN_TYPES {
20 Void = "Void",
21 Boolean = "Boolean",
22 Float = "Float",
23 Uint32 = "Uint32",
24 Int32 = "Int32",
25 Vector = "Vector",
26 Vector2Float = "vec2<f32>",
27 Vector3Float = "vec3<f32>",
28 Vector4Float = "vec4<f32>",
29 Vector2Boolean = "vec2<bool>",
30 Vector3Boolean = "vec3<bool>",
31 Vector4Boolean = "vec4<bool>",
32 Vector2Uint = "vec2<u32>",
33 Vector3Uint = "vec3<u32>",
34 Vector4Uint = "vec4<u32>",
35 Vector2Int = "vec2<i32>",
36 Vector3Int = "vec3<i32>",
37 Vector4Int = "vec4<i32>",
38 Matrix = "Matrix",
39 Matrix3x3Float = "mat3x3<f32>",
40 Matrix4x4Float = "mat4x4<i32>",
41 Struct = "Struct",
42 FloatArray = "Float[]",
43 Vector4FloatArray = "vec4<f32>[]"
44}
45declare enum AST_NODE_TYPES {
46 Program = "Program",
47 Identifier = "Identifier",
48 VariableDeclaration = "VariableDeclaration",
49 BlockStatement = "BlockStatement",
50 ReturnStatement = "ReturnStatement",
51 FunctionDeclaration = "FunctionDeclaration",
52 VariableDeclarator = "VariableDeclarator",
53 AssignmentExpression = "AssignmentExpression",
54 LogicalExpression = "LogicalExpression",
55 BinaryExpression = "BinaryExpression",
56 ArrayExpression = "ArrayExpression",
57 UnaryExpression = "UnaryExpression",
58 UpdateExpression = "UpdateExpression",
59 FunctionExpression = "FunctionExpression",
60 MemberExpression = "MemberExpression",
61 ConditionalExpression = "ConditionalExpression",
62 ExpressionStatement = "ExpressionStatement",
63 CallExpression = "CallExpression",
64 NumThreadStatement = "NumThreadStatement",
65 StorageStatement = "StorageStatement",
66 DoWhileStatement = "DoWhileStatement",
67 WhileStatement = "WhileStatement",
68 ForStatement = "ForStatement",
69 BreakStatement = "BreakStatement",
70 ContinueStatement = "ContinueStatement",
71 IfStatement = "IfStatement",
72 ImportedFunctionStatement = "ImportedFunctionStatement"
73}
74declare enum STORAGE_CLASS {
75 Input = "Input",
76 Output = "Output",
77 Uniform = "Uniform",
78 Workgroup = "Workgroup",
79 UniformConstant = "UniformConstant",
80 Image = "Image",
81 StorageBuffer = "StorageBuffer",
82 Private = "Private",
83 Function = "Function"
84}
85declare type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
86declare type DataType = AST_TOKEN_TYPES.Uint32 | AST_TOKEN_TYPES.Int32 | AST_TOKEN_TYPES.Boolean | AST_TOKEN_TYPES.Float | AST_TOKEN_TYPES.Vector2Float | AST_TOKEN_TYPES.Vector3Float | AST_TOKEN_TYPES.Vector4Float | AST_TOKEN_TYPES.Vector2Int | AST_TOKEN_TYPES.Vector3Int | AST_TOKEN_TYPES.Vector4Int | AST_TOKEN_TYPES.Vector2Uint | AST_TOKEN_TYPES.Vector3Uint | AST_TOKEN_TYPES.Vector4Uint | AST_TOKEN_TYPES.Vector2Boolean | AST_TOKEN_TYPES.Vector3Boolean | AST_TOKEN_TYPES.Vector4Boolean | AST_TOKEN_TYPES.Matrix3x3Float | AST_TOKEN_TYPES.Matrix4x4Float | AST_TOKEN_TYPES.FloatArray | AST_TOKEN_TYPES.Vector4FloatArray | AST_TOKEN_TYPES.Void;
87interface GLSLContext {
88 /**
89 * 程序名
90 */
91 name: string;
92 shader?: string;
93 /**
94 * size of thread grid
95 * 即 WebGL 2 Compute 中的 dispatchCompute
96 * 或者 WebGPU 中的 dispatch
97 */
98 dispatch: [number, number, number];
99 /**
100 * size of each thread group
101 * Compute Shader 中的 local_size_x/y/z
102 */
103 threadGroupSize: [number, number, number];
104 /**
105 * 迭代次数,例如布局运算中需要迭代很多次才能到达稳定
106 */
107 maxIteration: number;
108 /**
109 * 是否需要 pingpong,如果存在输入和输出为同一个的情况
110 */
111 needPingpong: boolean;
112 /**
113 * 目前仅支持单一输出,受限于 WebGL 实现
114 */
115 output: {
116 name: string;
117 size?: [number, number];
118 textureSize?: [number, number];
119 length?: number;
120 typedArrayConstructor?: TypedArrayConstructor;
121 gpuBuffer?: any;
122 outputElementsPerTexel?: number;
123 };
124 /**
125 * 常量,可分成编译时和运行时两类:
126 * 1. 编译时即可确定值
127 * 2. 运行时:例如循环长度需要为常量,但在编译时又无法确定
128 * TODO 支持定义函数,例如 tensorflow 中的 DIV_CEIL
129 */
130 defines: Array<{
131 name: string;
132 type: DataType;
133 value: number;
134 runtime: boolean;
135 }>;
136 globalDeclarations: Array<{
137 name: string;
138 type: DataType;
139 value: string;
140 shared: boolean;
141 }>;
142 uniforms: Array<{
143 name: string;
144 type: DataType;
145 data?: number | number[] | Float32Array | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array;
146 size?: [number, number];
147 storageClass: STORAGE_CLASS;
148 readonly: boolean;
149 writeonly: boolean;
150 isReferer?: boolean;
151 }>;
152}
153/**
154 * 根据目标平台生成 Shader 代码
155 * * WebGL GLSL 1.0
156 * * WebGPU Chrome/Edge GLSL 4.5 & WGSL @see https://gpuweb.github.io/gpuweb/wgsl.html
157 * * Safari WHLSL (maybe deprecated)
158 */
159declare enum Target {
160 GLSL100 = "GLSL100",
161 GLSL450 = "GLSL450",
162 WGSL = "WGSL"
163}
164declare const DefineValuePlaceholder = "__DefineValuePlaceholder__";
165interface KernelBundle {
166 shaders: {
167 [Target.WGSL]: string;
168 [Target.GLSL450]: string;
169 [Target.GLSL100]: string;
170 };
171 context?: GLSLContext;
172 toString(): string;
173}
174export { createEntity, Component, ComponentManager, Entity, isSafari, gl, ConfigService, AST_TOKEN_TYPES, AST_NODE_TYPES, STORAGE_CLASS, GLSLContext, DataType, Target, DefineValuePlaceholder, KernelBundle, };