UNPKG

6.49 kBJavaScriptView Raw
1import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3var _primitiveMap, _depthFuncMap, _blendEquationMap, _blendFuncMap, _formatMap, _filterMap, _wrapModeMap;
4
5import { gl } from '@antv/g-webgpu-core';
6import * as WebGPUConstants from '@webgpu/types/dist/constants'; // WebGPU 不支持 LINE_LOOP & TRIANGLE_FAN
7
8export var primitiveMap = (_primitiveMap = {}, _defineProperty(_primitiveMap, gl.POINTS, WebGPUConstants.PrimitiveTopology.PointList), _defineProperty(_primitiveMap, gl.LINES, WebGPUConstants.PrimitiveTopology.LineList), _defineProperty(_primitiveMap, gl.LINE_LOOP, WebGPUConstants.PrimitiveTopology.LineList), _defineProperty(_primitiveMap, gl.LINE_STRIP, WebGPUConstants.PrimitiveTopology.LineStrip), _defineProperty(_primitiveMap, gl.TRIANGLES, WebGPUConstants.PrimitiveTopology.TriangleList), _defineProperty(_primitiveMap, gl.TRIANGLE_FAN, WebGPUConstants.PrimitiveTopology.TriangleList), _defineProperty(_primitiveMap, gl.TRIANGLE_STRIP, WebGPUConstants.PrimitiveTopology.TriangleStrip), _primitiveMap);
9export var depthFuncMap = (_depthFuncMap = {}, _defineProperty(_depthFuncMap, gl.NEVER, WebGPUConstants.CompareFunction.Never), _defineProperty(_depthFuncMap, gl.ALWAYS, WebGPUConstants.CompareFunction.Always), _defineProperty(_depthFuncMap, gl.LESS, WebGPUConstants.CompareFunction.Less), _defineProperty(_depthFuncMap, gl.LEQUAL, WebGPUConstants.CompareFunction.LessEqual), _defineProperty(_depthFuncMap, gl.GREATER, WebGPUConstants.CompareFunction.Greater), _defineProperty(_depthFuncMap, gl.GEQUAL, WebGPUConstants.CompareFunction.GreaterEqual), _defineProperty(_depthFuncMap, gl.EQUAL, WebGPUConstants.CompareFunction.Equal), _defineProperty(_depthFuncMap, gl.NOTEQUAL, WebGPUConstants.CompareFunction.NotEqual), _depthFuncMap);
10export var blendEquationMap = (_blendEquationMap = {}, _defineProperty(_blendEquationMap, gl.FUNC_ADD, WebGPUConstants.BlendOperation.Add), _defineProperty(_blendEquationMap, gl.MIN_EXT, WebGPUConstants.BlendOperation.Min), _defineProperty(_blendEquationMap, gl.MAX_EXT, WebGPUConstants.BlendOperation.Max), _defineProperty(_blendEquationMap, gl.FUNC_SUBTRACT, WebGPUConstants.BlendOperation.Subtract), _defineProperty(_blendEquationMap, gl.FUNC_REVERSE_SUBTRACT, WebGPUConstants.BlendOperation.ReverseSubtract), _blendEquationMap); // @see https://gpuweb.github.io/gpuweb/#blend-state
11// 不支持 'constant alpha' 和 'one minus constant alpha'
12
13export var blendFuncMap = (_blendFuncMap = {}, _defineProperty(_blendFuncMap, gl.ZERO, WebGPUConstants.BlendFactor.Zero), _defineProperty(_blendFuncMap, gl.ONE, WebGPUConstants.BlendFactor.One), _defineProperty(_blendFuncMap, gl.SRC_COLOR, WebGPUConstants.BlendFactor.SrcColor), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_COLOR, WebGPUConstants.BlendFactor.OneMinusSrcColor), _defineProperty(_blendFuncMap, gl.SRC_ALPHA, WebGPUConstants.BlendFactor.SrcAlpha), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_ALPHA, WebGPUConstants.BlendFactor.OneMinusSrcAlpha), _defineProperty(_blendFuncMap, gl.DST_COLOR, WebGPUConstants.BlendFactor.DstColor), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_COLOR, WebGPUConstants.BlendFactor.OneMinusDstColor), _defineProperty(_blendFuncMap, gl.DST_ALPHA, WebGPUConstants.BlendFactor.DstAlpha), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_ALPHA, WebGPUConstants.BlendFactor.OneMinusDstAlpha), _defineProperty(_blendFuncMap, gl.CONSTANT_COLOR, WebGPUConstants.BlendFactor.BlendColor), _defineProperty(_blendFuncMap, gl.ONE_MINUS_CONSTANT_COLOR, WebGPUConstants.BlendFactor.OneMinusBlendColor), _defineProperty(_blendFuncMap, gl.SRC_ALPHA_SATURATE, WebGPUConstants.BlendFactor.SrcAlphaSaturated), _blendFuncMap); // @see https://gpuweb.github.io/gpuweb/#texture-formats
14
15export var formatMap = (_formatMap = {}, _defineProperty(_formatMap, gl.ALPHA, 'r8unorm'), _defineProperty(_formatMap, gl.RGBA, 'rgba8unorm'), _defineProperty(_formatMap, gl.DEPTH_COMPONENT, 'depth32float'), _defineProperty(_formatMap, gl.DEPTH_STENCIL, 'depth24plus-stencil8'), _formatMap); // @see https://gpuweb.github.io/gpuweb/#enumdef-gpufiltermode
16
17export var filterMap = (_filterMap = {}, _defineProperty(_filterMap, gl.NEAREST, 'nearest'), _defineProperty(_filterMap, gl.LINEAR, 'linear'), _filterMap); // @see https://gpuweb.github.io/gpuweb/#enumdef-gpuaddressmode
18
19export var wrapModeMap = (_wrapModeMap = {}, _defineProperty(_wrapModeMap, gl.REPEAT, 'repeat'), _defineProperty(_wrapModeMap, gl.CLAMP_TO_EDGE, 'clamp-to-edge'), _defineProperty(_wrapModeMap, gl.MIRRORED_REPEAT, 'mirror-repeat'), _wrapModeMap);
20export function getCullMode(_ref) {
21 var cull = _ref.cull;
22
23 if (!cull || !cull.enable) {
24 return WebGPUConstants.CullMode.None;
25 }
26
27 if (cull.face) {
28 return cull.face === gl.FRONT ? WebGPUConstants.CullMode.Front : WebGPUConstants.CullMode.Back;
29 }
30}
31export function getDepthStencilStateDescriptor(_ref2) {
32 var depth = _ref2.depth,
33 stencil = _ref2.stencil;
34 // TODO: stencil
35 var stencilFrontBack = {
36 compare: WebGPUConstants.CompareFunction.Always,
37 depthFailOp: WebGPUConstants.StencilOperation.Keep,
38 failOp: WebGPUConstants.StencilOperation.Keep,
39 passOp: WebGPUConstants.StencilOperation.Keep
40 };
41 return {
42 depthWriteEnabled: depth && depth.enable,
43 depthCompare: depthFuncMap[(depth === null || depth === void 0 ? void 0 : depth.func) || gl.ALWAYS],
44 format: WebGPUConstants.TextureFormat.Depth24PlusStencil8,
45 stencilFront: stencilFrontBack,
46 stencilBack: stencilFrontBack,
47 stencilReadMask: 0xffffffff,
48 stencilWriteMask: 0xffffffff
49 };
50}
51/**
52 * @see https://gpuweb.github.io/gpuweb/#color-state
53 */
54
55export function getColorStateDescriptors(_ref3, swapChainFormat) {
56 var blend = _ref3.blend;
57 return [{
58 format: swapChainFormat,
59 // https://gpuweb.github.io/gpuweb/#blend-state
60 alphaBlend: {
61 srcFactor: blendFuncMap[blend && blend.func && blend.func.srcAlpha || gl.ONE],
62 dstFactor: blendFuncMap[blend && blend.func && blend.func.dstAlpha || gl.ZERO],
63 operation: blendEquationMap[blend && blend.equation && blend.equation.alpha || gl.FUNC_ADD]
64 },
65 colorBlend: {
66 srcFactor: blendFuncMap[blend && blend.func && blend.func.srcRGB || gl.ONE],
67 dstFactor: blendFuncMap[blend && blend.func && blend.func.dstRGB || gl.ZERO],
68 operation: blendEquationMap[blend && blend.equation && blend.equation.rgb || gl.FUNC_ADD]
69 },
70 writeMask: WebGPUConstants.ColorWrite.All
71 }];
72}
73//# sourceMappingURL=constants.js.map
\No newline at end of file