UNPKG

14.1 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/webgpu/constants.ts"],"names":["gl","WebGPUConstants","primitiveMap","POINTS","PrimitiveTopology","PointList","LINES","LineList","LINE_LOOP","LINE_STRIP","LineStrip","TRIANGLES","TriangleList","TRIANGLE_FAN","TRIANGLE_STRIP","TriangleStrip","depthFuncMap","NEVER","CompareFunction","Never","ALWAYS","Always","LESS","Less","LEQUAL","LessEqual","GREATER","Greater","GEQUAL","GreaterEqual","EQUAL","Equal","NOTEQUAL","NotEqual","blendEquationMap","FUNC_ADD","BlendOperation","Add","MIN_EXT","Min","MAX_EXT","Max","FUNC_SUBTRACT","Subtract","FUNC_REVERSE_SUBTRACT","ReverseSubtract","blendFuncMap","ZERO","BlendFactor","Zero","ONE","One","SRC_COLOR","SrcColor","ONE_MINUS_SRC_COLOR","OneMinusSrcColor","SRC_ALPHA","SrcAlpha","ONE_MINUS_SRC_ALPHA","OneMinusSrcAlpha","DST_COLOR","DstColor","ONE_MINUS_DST_COLOR","OneMinusDstColor","DST_ALPHA","DstAlpha","ONE_MINUS_DST_ALPHA","OneMinusDstAlpha","CONSTANT_COLOR","BlendColor","ONE_MINUS_CONSTANT_COLOR","OneMinusBlendColor","SRC_ALPHA_SATURATE","SrcAlphaSaturated","formatMap","ALPHA","RGBA","DEPTH_COMPONENT","DEPTH_STENCIL","filterMap","NEAREST","LINEAR","wrapModeMap","REPEAT","CLAMP_TO_EDGE","MIRRORED_REPEAT","getCullMode","cull","enable","CullMode","None","face","FRONT","Front","Back","getDepthStencilStateDescriptor","depth","stencil","stencilFrontBack","compare","depthFailOp","StencilOperation","Keep","failOp","passOp","depthWriteEnabled","depthCompare","func","format","TextureFormat","Depth24PlusStencil8","stencilFront","stencilBack","stencilReadMask","stencilWriteMask","getColorStateDescriptors","swapChainFormat","blend","alphaBlend","srcFactor","srcAlpha","dstFactor","dstAlpha","operation","equation","alpha","colorBlend","srcRGB","dstRGB","rgb","writeMask","ColorWrite","All"],"mapp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P,KAAK,CAACO,QAAN,CAAeC,KAA3C,IAAqD7H,EAAE,CAACmC,QAD1C;AANR,KAHd;AAaE2F,IAAAA,UAAU,EAAE;AACVP,MAAAA,SAAS,EACPzE,YAAY,CAAEuE,KAAK,IAAIA,KAAK,CAACV,IAAf,IAAuBU,KAAK,CAACV,IAAN,CAAWoB,MAAnC,IAA8C/H,EAAE,CAACkD,GAAlD,CAFJ;AAGVuE,MAAAA,SAAS,EACP3E,YAAY,CAAEuE,KAAK,IAAIA,KAAK,CAACV,IAAf,IAAuBU,KAAK,CAACV,IAAN,CAAWqB,MAAnC,IAA8ChI,EAAE,CAAC+C,IAAlD,CAJJ;AAKV4E,MAAAA,SAAS,EACPzF,gBAAgB,CACbmF,KAAK,IAAIA,KAAK,CAACO,QAAf,IAA2BP,KAAK,CAACO,QAAN,CAAeK,GAA3C,IAAmDjI,EAAE,CAACmC,QADxC;AANR,KAbd;AAuBE+F,IAAAA,SAAS,EAAEjI,eAAe,CAACkI,UAAhB,CAA2BC;AAvBxC,GADK,CAAP;AA2BD","sourcesContent":["import { gl, IModelInitializationOptions } from '@antv/g-webgpu-core';\nimport * as WebGPUConstants from '@webgpu/types/dist/constants';\n\n// WebGPU 不支持 LINE_LOOP & TRIANGLE_FAN\nexport const primitiveMap: {\n [key: string]:\n | WebGPUConstants.PrimitiveTopology.PointList\n | WebGPUConstants.PrimitiveTopology.LineList\n | WebGPUConstants.PrimitiveTopology.LineStrip\n | WebGPUConstants.PrimitiveTopology.TriangleList\n | WebGPUConstants.PrimitiveTopology.TriangleStrip;\n} = {\n [gl.POINTS]: WebGPUConstants.PrimitiveTopology.PointList,\n [gl.LINES]: WebGPUConstants.PrimitiveTopology.LineList,\n [gl.LINE_LOOP]: WebGPUConstants.PrimitiveTopology.LineList,\n [gl.LINE_STRIP]: WebGPUConstants.PrimitiveTopology.LineStrip,\n [gl.TRIANGLES]: WebGPUConstants.PrimitiveTopology.TriangleList,\n [gl.TRIANGLE_FAN]: WebGPUConstants.PrimitiveTopology.TriangleList,\n [gl.TRIANGLE_STRIP]: WebGPUConstants.PrimitiveTopology.TriangleStrip,\n};\n\nexport const depthFuncMap: {\n [key: string]:\n | WebGPUConstants.CompareFunction.Never\n | WebGPUConstants.CompareFunction.Always\n | WebGPUConstants.CompareFunction.Less\n | WebGPUConstants.CompareFunction.LessEqual\n | WebGPUConstants.CompareFunction.Greater\n | WebGPUConstants.CompareFunction.GreaterEqual\n | WebGPUConstants.CompareFunction.Equal\n | WebGPUConstants.CompareFunction.NotEqual;\n} = {\n [gl.NEVER]: WebGPUConstants.CompareFunction.Never,\n [gl.ALWAYS]: WebGPUConstants.CompareFunction.Always,\n [gl.LESS]: WebGPUConstants.CompareFunction.Less,\n [gl.LEQUAL]: WebGPUConstants.CompareFunction.LessEqual,\n [gl.GREATER]: WebGPUConstants.CompareFunction.Greater,\n [gl.GEQUAL]: WebGPUConstants.CompareFunction.GreaterEqual,\n [gl.EQUAL]: WebGPUConstants.CompareFunction.Equal,\n [gl.NOTEQUAL]: WebGPUConstants.CompareFunction.NotEqual,\n};\n\nexport const blendEquationMap: {\n [key: string]:\n | WebGPUConstants.BlendOperation.Add\n | WebGPUConstants.BlendOperation.Min\n | WebGPUConstants.BlendOperation.Max\n | WebGPUConstants.BlendOperation.Subtract\n | WebGPUConstants.BlendOperation.ReverseSubtract;\n} = {\n [gl.FUNC_ADD]: WebGPUConstants.BlendOperation.Add,\n [gl.MIN_EXT]: WebGPUConstants.BlendOperation.Min,\n [gl.MAX_EXT]: WebGPUConstants.BlendOperation.Max,\n [gl.FUNC_SUBTRACT]: WebGPUConstants.BlendOperation.Subtract,\n [gl.FUNC_REVERSE_SUBTRACT]: WebGPUConstants.BlendOperation.ReverseSubtract,\n};\n\n// @see https://gpuweb.github.io/gpuweb/#blend-state\n// 不支持 'constant alpha' 和 'one minus constant alpha'\nexport const blendFuncMap: {\n [key: string]:\n | WebGPUConstants.BlendFactor.Zero\n | WebGPUConstants.BlendFactor.One\n | WebGPUConstants.BlendFactor.SrcColor\n | WebGPUConstants.BlendFactor.OneMinusSrcColor\n | WebGPUConstants.BlendFactor.SrcAlpha\n | WebGPUConstants.BlendFactor.OneMinusSrcAlpha\n | WebGPUConstants.BlendFactor.DstColor\n | WebGPUConstants.BlendFactor.OneMinusDstColor\n | WebGPUConstants.BlendFactor.DstAlpha\n | WebGPUConstants.BlendFactor.OneMinusDstAlpha\n | WebGPUConstants.BlendFactor.BlendColor\n | WebGPUConstants.BlendFactor.OneMinusBlendColor\n | WebGPUConstants.BlendFactor.SrcAlphaSaturated;\n} = {\n [gl.ZERO]: WebGPUConstants.BlendFactor.Zero,\n [gl.ONE]: WebGPUConstants.BlendFactor.One,\n [gl.SRC_COLOR]: WebGPUConstants.BlendFactor.SrcColor,\n [gl.ONE_MINUS_SRC_COLOR]: WebGPUConstants.BlendFactor.OneMinusSrcColor,\n [gl.SRC_ALPHA]: WebGPUConstants.BlendFactor.SrcAlpha,\n [gl.ONE_MINUS_SRC_ALPHA]: WebGPUConstants.BlendFactor.OneMinusSrcAlpha,\n [gl.DST_COLOR]: WebGPUConstants.BlendFactor.DstColor,\n [gl.ONE_MINUS_DST_COLOR]: WebGPUConstants.BlendFactor.OneMinusDstColor,\n [gl.DST_ALPHA]: WebGPUConstants.BlendFactor.DstAlpha,\n [gl.ONE_MINUS_DST_ALPHA]: WebGPUConstants.BlendFactor.OneMinusDstAlpha,\n [gl.CONSTANT_COLOR]: WebGPUConstants.BlendFactor.BlendColor,\n [gl.ONE_MINUS_CONSTANT_COLOR]: WebGPUConstants.BlendFactor.OneMinusBlendColor,\n // [gl.CONSTANT_ALPHA]: WebGPUConstants.BlendFactor.'constant alpha',\n // [gl.ONE_MINUS_CONSTANT_ALPHA]: WebGPUConstants.BlendFactor.'one minus constant alpha',\n [gl.SRC_ALPHA_SATURATE]: WebGPUConstants.BlendFactor.SrcAlphaSaturated,\n};\n\n// @see https://gpuweb.github.io/gpuweb/#texture-formats\nexport const formatMap: {\n [key: string]:\n | 'r8unorm'\n | 'rgba8unorm'\n | 'depth32float'\n | 'depth24plus-stencil8';\n} = {\n [gl.ALPHA]: 'r8unorm',\n [gl.RGBA]: 'rgba8unorm',\n [gl.DEPTH_COMPONENT]: 'depth32float',\n [gl.DEPTH_STENCIL]: 'depth24plus-stencil8',\n};\n\n// @see https://gpuweb.github.io/gpuweb/#enumdef-gpufiltermode\nexport const filterMap: {\n [key: string]: 'nearest' | 'linear';\n} = {\n [gl.NEAREST]: 'nearest',\n [gl.LINEAR]: 'linear',\n};\n\n// @see https://gpuweb.github.io/gpuweb/#enumdef-gpuaddressmode\nexport const wrapModeMap: {\n [key: string]: 'repeat' | 'clamp-to-edge' | 'mirror-repeat';\n} = {\n [gl.REPEAT]: 'repeat',\n [gl.CLAMP_TO_EDGE]: 'clamp-to-edge',\n [gl.MIRRORED_REPEAT]: 'mirror-repeat',\n};\n\nexport function getCullMode({\n cull,\n}: Pick<IModelInitializationOptions, 'cull'>):\n | 'none'\n | 'front'\n | 'back'\n | undefined {\n if (!cull || !cull.enable) {\n return WebGPUConstants.CullMode.None;\n }\n\n if (cull.face) {\n return cull.face === gl.FRONT\n ? WebGPUConstants.CullMode.Front\n : WebGPUConstants.CullMode.Back;\n }\n}\n\nexport function getDepthStencilStateDescriptor({\n depth,\n stencil,\n}: Pick<IModelInitializationOptions, 'depth' | 'stencil'>):\n | GPUDepthStencilStateDescriptor\n | undefined {\n // TODO: stencil\n\n const stencilFrontBack: GPUStencilStateFaceDescriptor = {\n compare: WebGPUConstants.CompareFunction.Always,\n depthFailOp: WebGPUConstants.StencilOperation.Keep,\n failOp: WebGPUConstants.StencilOperation.Keep,\n passOp: WebGPUConstants.StencilOperation.Keep,\n };\n\n return {\n depthWriteEnabled: depth && depth.enable,\n depthCompare: depthFuncMap[depth?.func || gl.ALWAYS],\n format: WebGPUConstants.TextureFormat.Depth24PlusStencil8,\n stencilFront: stencilFrontBack,\n stencilBack: stencilFrontBack,\n stencilReadMask: 0xffffffff,\n stencilWriteMask: 0xffffffff,\n };\n}\n\n/**\n * @see https://gpuweb.github.io/gpuweb/#color-state\n */\nexport function getColorStateDescriptors(\n { blend }: Pick<IModelInitializationOptions, 'blend'>,\n swapChainFormat: GPUTextureFormat,\n): GPUColorStateDescriptor[] {\n return [\n {\n format: swapChainFormat,\n // https://gpuweb.github.io/gpuweb/#blend-state\n alphaBlend: {\n srcFactor:\n blendFuncMap[(blend && blend.func && blend.func.srcAlpha) || gl.ONE],\n dstFactor:\n blendFuncMap[(blend && blend.func && blend.func.dstAlpha) || gl.ZERO],\n operation:\n blendEquationMap[\n (blend && blend.equation && blend.equation.alpha) || gl.FUNC_ADD\n ],\n },\n colorBlend: {\n srcFactor:\n blendFuncMap[(blend && blend.func && blend.func.srcRGB) || gl.ONE],\n dstFactor:\n blendFuncMap[(blend && blend.func && blend.func.dstRGB) || gl.ZERO],\n operation:\n blendEquationMap[\n (blend && blend.equation && blend.equation.rgb) || gl.FUNC_ADD\n ],\n },\n writeMask: WebGPUConstants.ColorWrite.All,\n },\n ];\n}\n"],"file":"constants.js"}
\No newline at end of file