import { gl , IModelInitializationOptions } from '@antv/g-webgpu-core' ; import * as WebGPUConstants from '@webgpu/types/dist/constants' ; export const primitiveMap = { [ gl . POINTS ] : WebGPUConstants . PrimitiveTopology . PointList , [ gl . LINES ] : WebGPUConstants . PrimitiveTopology . LineList , [ gl . LINE_LOOP ] : WebGPUConstants . PrimitiveTopology . LineList , [ gl . LINE_STRIP ] : WebGPUConstants . PrimitiveTopology . LineStrip , [ gl . TRIANGLES ] : WebGPUConstants . PrimitiveTopology . TriangleList , [ gl . TRIANGLE_FAN ] : WebGPUConstants . PrimitiveTopology . TriangleList , [ gl . TRIANGLE_STRIP ] : WebGPUConstants . PrimitiveTopology . TriangleStrip , } ; export const depthFuncMap = { [ gl . NEVER ] : WebGPUConstants . CompareFunction . Never , [ gl . ALWAYS ] : WebGPUConstants . CompareFunction . Always , [ gl . LESS ] : WebGPUConstants . CompareFunction . Less , [ gl . LEQUAL ] : WebGPUConstants . CompareFunction . LessEqual , [ gl . GREATER ] : WebGPUConstants . CompareFunction . Greater , [ gl . GEQUAL ] : WebGPUConstants . CompareFunction . GreaterEqual , [ gl . EQUAL ] : WebGPUConstants . CompareFunction . Equal , [ gl . NOTEQUAL ] : WebGPUConstants . CompareFunction . NotEqual , } ; export const blendEquationMap = { [ gl . FUNC_ADD ] : WebGPUConstants . BlendOperation . Add , [ gl . MIN_EXT ] : WebGPUConstants . BlendOperation . Min , [ gl . MAX_EXT ] : WebGPUConstants . BlendOperation . Max , [ gl . FUNC_SUBTRACT ] : WebGPUConstants . BlendOperation . Subtract , [ gl . FUNC_REVERSE_SUBTRACT ] : WebGPUConstants . BlendOperation . ReverseSubtract , } ; export const blendFuncMap = { [ gl . ZERO ] : WebGPUConstants . BlendFactor . Zero , [ gl . ONE ] : WebGPUConstants . BlendFactor . One , [ gl . SRC_COLOR ] : WebGPUConstants . BlendFactor . SrcColor , [ gl . ONE_MINUS_SRC_COLOR ] : WebGPUConstants . BlendFactor . OneMinusSrcColor , [ gl . SRC_ALPHA ] : WebGPUConstants . BlendFactor . SrcAlpha , [ gl . ONE_MINUS_SRC_ALPHA ] : WebGPUConstants . BlendFactor . OneMinusSrcAlpha , [ gl . DST_COLOR ] : WebGPUConstants . BlendFactor . DstColor , [ gl . ONE_MINUS_DST_COLOR ] : WebGPUConstants . BlendFactor . OneMinusDstColor , [ gl . DST_ALPHA ] : WebGPUConstants . BlendFactor . DstAlpha , [ gl . ONE_MINUS_DST_ALPHA ] : WebGPUConstants . BlendFactor . OneMinusDstAlpha , [ gl . CONSTANT_COLOR ] : WebGPUConstants . BlendFactor . BlendColor , [ gl . ONE_MINUS_CONSTANT_COLOR ] : WebGPUConstants . BlendFactor . OneMinusBlendColor , [ gl . SRC_ALPHA_SATURATE ] : WebGPUConstants . BlendFactor . SrcAlphaSaturated , } ; export const formatMap = { [ gl . ALPHA ] : 'r8unorm' , [ gl . RGBA ] : 'rgba8unorm' , [ gl . DEPTH_COMPONENT ] : 'depth32float' , [ gl . DEPTH_STENCIL ] : 'depth24plus-stencil8' , } ; export const filterMap = { [ gl . NEAREST ] : 'nearest' , [ gl . LINEAR ] : 'linear' , } ; export const wrapModeMap = { [ gl . REPEAT ] : 'repeat' , [ gl . CLAMP_TO_EDGE ] : 'clamp-to-edge' , [ gl . MIRRORED_REPEAT ] : 'mirror-repeat' , } ; export function getCullMode ( { cull , } ) { if ( ! cull || ! cull . enable ) { return WebGPUConstants . CullMode . None ; } if ( cull . face ) { return cull . face === gl . FRONT ? WebGPUConstants . CullMode . Front : WebGPUConstants . CullMode . Back ; } } export function getDepthStencilStateDescriptor ( { depth , stencil , } ) { const stencilFrontBack = { compare : WebGPUConstants . CompareFunction . Always , depthFailOp : WebGPUConstants . StencilOperation . Keep , failOp : WebGPUConstants . StencilOperation . Keep , passOp : WebGPUConstants . StencilOperation . Keep , } ; return { depthWriteEnabled : depth && depth . enable , depthCompare : depthFuncMap [ depth ?. func || gl . ALWAYS ] , format : WebGPUConstants . TextureFormat . Depth24PlusStencil8 , stencilFront : stencilFrontBack , stencilBack : stencilFrontBack , stencilReadMask : 0xffffffff , stencilWriteMask : 0xffffffff , } ; } see https export function getColorStateDescriptors ( { blend } , swapChainFormat ) { return [ { format : swapChainFormat , alphaBlend : { srcFactor : blendFuncMap [ ( blend && blend . func && blend . func . srcAlpha ) || gl . ONE ] , dstFactor : blendFuncMap [ ( blend && blend . func && blend . func . dstAlpha ) || gl . ZERO ] , operation : blendEquationMap [ ( blend && blend . equation && blend . equation . alpha ) || gl . FUNC_ADD ] , } , colorBlend : { srcFactor : blendFuncMap [ ( blend && blend . func && blend . func . srcRGB ) || gl . ONE ] , dstFactor : blendFuncMap [ ( blend && blend . func && blend . func . dstRGB ) || gl . ZERO ] , operation : blendEquationMap [ ( blend && blend . equation && blend . equation . rgb ) || gl . FUNC_ADD ] , } , writeMask : WebGPUConstants . ColorWrite . All , } , ] ; }