UNPKG

8.94 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","names":["Component","ComponentManager","gl","createEntity","ConfigService","isSafari","AST_TOKEN_TYPES","AST_NODE_TYPES","STORAGE_CLASS","Target","DefineValuePlaceholder"],"sources":["../src/index.ts"],"sourcesContent":["import { Component, ComponentManager } from './ComponentManager';\nimport { gl } from './components/renderer/gl';\nexport type {\n IAttribute,\n IAttributeInitializationOptions,\n} from './components/renderer/IAttribute';\nexport type {\n IBuffer,\n IBufferInitializationOptions,\n} from './components/renderer/IBuffer';\nexport type { IComputeModel } from './components/renderer/IComputeModel';\nexport type {\n IElements,\n IElementsInitializationOptions,\n} from './components/renderer/IElements';\nexport type {\n IFramebuffer,\n IFramebufferInitializationOptions,\n} from './components/renderer/IFramebuffer';\nexport type {\n IModel,\n IModelDrawOptions,\n IModelInitializationOptions,\n} from './components/renderer/IModel';\nexport type {\n IRenderbuffer,\n IRenderbufferInitializationOptions,\n} from './components/renderer/IRenderbuffer';\nexport type {\n BufferData,\n IClearOptions,\n IReadPixelsOptions,\n IRendererConfig,\n IRendererService,\n IViewport,\n} from './components/renderer/IRendererService';\nexport type {\n ITexture2D,\n ITexture2DInitializationOptions,\n} from './components/renderer/ITexture2D';\nexport type { IUniform } from './components/renderer/IUniform';\n\nimport { createEntity } from './Entity';\nimport { ConfigService } from './services/config/ConfigService';\nexport type { IConfig, IConfigService } from './services/config/IConfigService';\nexport type { IShaderModuleService } from './services/shader-module/IShaderModuleService';\nimport { isSafari } from './utils/isSafari';\n\ntype Entity = number;\n\nenum AST_TOKEN_TYPES {\n Void = 'Void',\n Boolean = 'Boolean',\n Float = 'Float',\n Uint32 = 'Uint32',\n Int32 = 'Int32',\n Vector = 'Vector',\n Vector2Float = 'vec2<f32>',\n Vector3Float = 'vec3<f32>',\n Vector4Float = 'vec4<f32>',\n Vector2Boolean = 'vec2<bool>',\n Vector3Boolean = 'vec3<bool>',\n Vector4Boolean = 'vec4<bool>',\n Vector2Uint = 'vec2<u32>',\n Vector3Uint = 'vec3<u32>',\n Vector4Uint = 'vec4<u32>',\n Vector2Int = 'vec2<i32>',\n Vector3Int = 'vec3<i32>',\n Vector4Int = 'vec4<i32>',\n Matrix = 'Matrix',\n Matrix3x3Float = 'mat3x3<f32>',\n Matrix4x4Float = 'mat4x4<i32>',\n Struct = 'Struct',\n FloatArray = 'Float[]',\n Vector4FloatArray = 'vec4<f32>[]',\n}\n\nenum AST_NODE_TYPES {\n Program = 'Program',\n Identifier = 'Identifier',\n VariableDeclaration = 'VariableDeclaration',\n BlockStatement = 'BlockStatement',\n ReturnStatement = 'ReturnStatement',\n FunctionDeclaration = 'FunctionDeclaration',\n VariableDeclarator = 'VariableDeclarator',\n AssignmentExpression = 'AssignmentExpression',\n LogicalExpression = 'LogicalExpression',\n BinaryExpression = 'BinaryExpression',\n ArrayExpression = 'ArrayExpression',\n UnaryExpression = 'UnaryExpression',\n UpdateExpression = 'UpdateExpression',\n FunctionExpression = 'FunctionExpression',\n MemberExpression = 'MemberExpression',\n ConditionalExpression = 'ConditionalExpression',\n ExpressionStatement = 'ExpressionStatement',\n CallExpression = 'CallExpression',\n NumThreadStatement = 'NumThreadStatement',\n StorageStatement = 'StorageStatement',\n DoWhileStatement = 'DoWhileStatement',\n WhileStatement = 'WhileStatement',\n ForStatement = 'ForStatement',\n BreakStatement = 'BreakStatement',\n ContinueStatement = 'ContinueStatement',\n IfStatement = 'IfStatement',\n ImportedFunctionStatement = 'ImportedFunctionStatement',\n}\n\nenum STORAGE_CLASS {\n Input = 'Input',\n Output = 'Output',\n Uniform = 'Uniform',\n Workgroup = 'Workgroup',\n UniformConstant = 'UniformConstant',\n Image = 'Image',\n StorageBuffer = 'StorageBuffer',\n Private = 'Private',\n Function = 'Function',\n}\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Uint8ClampedArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\ntype DataType =\n | AST_TOKEN_TYPES.Uint32\n | AST_TOKEN_TYPES.Int32\n | AST_TOKEN_TYPES.Boolean\n | AST_TOKEN_TYPES.Float\n | AST_TOKEN_TYPES.Vector2Float\n | AST_TOKEN_TYPES.Vector3Float\n | AST_TOKEN_TYPES.Vector4Float\n | AST_TOKEN_TYPES.Vector2Int\n | AST_TOKEN_TYPES.Vector3Int\n | AST_TOKEN_TYPES.Vector4Int\n | AST_TOKEN_TYPES.Vector2Uint\n | AST_TOKEN_TYPES.Vector3Uint\n | AST_TOKEN_TYPES.Vector4Uint\n | AST_TOKEN_TYPES.Vector2Boolean\n | AST_TOKEN_TYPES.Vector3Boolean\n | AST_TOKEN_TYPES.Vector4Boolean\n | AST_TOKEN_TYPES.Matrix3x3Float\n | AST_TOKEN_TYPES.Matrix4x4Float\n | AST_TOKEN_TYPES.FloatArray\n | AST_TOKEN_TYPES.Vector4FloatArray\n | AST_TOKEN_TYPES.Void;\n\ninterface GLSLContext {\n /**\n * 程序名\n */\n name: string;\n\n shader?: string;\n /**\n * size of thread grid\n * 即 WebGL 2 Compute 中的 dispatchCompute\n * 或者 WebGPU 中的 dispatch\n */\n dispatch: [number, number, number];\n /**\n * size of each thread group\n * Compute Shader 中的 local_size_x/y/z\n */\n threadGroupSize: [number, number, number];\n /**\n * 迭代次数,例如布局运算中需要迭代很多次才能到达稳定\n */\n maxIteration: number;\n /**\n * 是否需要 pingpong,如果存在输入和输出为同一个的情况\n */\n needPingpong: boolean;\n /**\n * 目前仅支持单一输出,受限于 WebGL 实现\n */\n output: {\n name: string;\n size?: [number, number];\n textureSize?: [number, number];\n length?: number;\n typedArrayConstructor?: TypedArrayConstructor;\n gpuBuffer?: any;\n outputElementsPerTexel?: number;\n };\n /**\n * 常量,可分成编译时和运行时两类:\n * 1. 编译时即可确定值\n * 2. 运行时:例如循环长度需要为常量,但在编译时又无法确定\n * TODO 支持定义函数,例如 tensorflow 中的 DIV_CEIL\n */\n defines: Array<{\n name: string;\n type: DataType;\n value: number;\n runtime: boolean; // 是否是运行时生成\n }>;\n globalDeclarations: Array<{\n name: string;\n type: DataType;\n value: string;\n shared: boolean;\n }>;\n uniforms: Array<{\n name: string;\n type: DataType;\n data?:\n | number\n | number[]\n | Float32Array\n | Uint8Array\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array;\n size?: [number, number];\n storageClass: STORAGE_CLASS;\n readonly: boolean;\n writeonly: boolean;\n isReferer?: boolean;\n }>;\n}\n\n/**\n * 根据目标平台生成 Shader 代码\n * * WebGL GLSL 1.0\n * * WebGPU Chrome/Edge GLSL 4.5 & WGSL @see https://gpuweb.github.io/gpuweb/wgsl.html\n * * Safari WHLSL (maybe deprecated)\n */\nenum Target {\n GLSL100 = 'GLSL100',\n GLSL450 = 'GLSL450',\n WGSL = 'WGSL',\n}\n\nconst DefineValuePlaceholder = '__DefineValuePlaceholder__';\n\ninterface KernelBundle {\n shaders: {\n [Target.WGSL]: string;\n [Target.GLSL450]: string;\n [Target.GLSL100]: string;\n };\n context?: GLSLContext;\n toString(): string;\n}\n\nexport {\n createEntity,\n Component,\n ComponentManager,\n Entity,\n isSafari,\n // renderer service\n gl,\n ConfigService,\n AST_TOKEN_TYPES,\n AST_NODE_TYPES,\n STORAGE_CLASS,\n GLSLContext,\n DataType,\n Target,\n DefineValuePlaceholder,\n KernelBundle,\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,gBAAgB,QAAQ,oBAAoB;AAChE,SAASC,EAAE,QAAQ,0BAA0B;AAyC7C,SAASC,YAAY,QAAQ,UAAU;AACvC,SAASC,aAAa,QAAQ,iCAAiC;AAG/D,SAASC,QAAQ,QAAQ,kBAAkB;AAAC,IAIvCC,eAAe;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;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