From 55e013fbfc2dfe1ad9f6bd0d25f90e38c12e5543 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 14 May 2025 21:42:19 +0800 Subject: [PATCH 01/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Ble?= =?UTF-8?q?ndState=20=E5=92=8C=20RenderPassColorAttachment=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BlendState 中添加对 constantColor 的处理逻辑 - 修改 RenderPassColorAttachment 中 Color 类型为只读数组 --- src/data/BlendState.ts | 8 +++++++- src/data/RenderPassColorAttachment.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/data/BlendState.ts b/src/data/BlendState.ts index 5b68384..b027dad 100644 --- a/src/data/BlendState.ts +++ b/src/data/BlendState.ts @@ -47,7 +47,7 @@ export class BlendState { if (!blendState) return undefined; - const { color, alpha, constantColor } = blendState; + const { color, alpha } = blendState; // 当混合系数用到了混合常量值时设置混合常量值。 if (0 @@ -61,6 +61,12 @@ export class BlendState || alpha?.dstFactor === "one-minus-constant" ) { + const constantColor = blendState.constantColor; + if (constantColor) + { + return [constantColor[0], constantColor[1], constantColor[2], constantColor[3]]; + } + return constantColor ?? [0, 0, 0, 0]; } diff --git a/src/data/RenderPassColorAttachment.ts b/src/data/RenderPassColorAttachment.ts index c708709..e27add2 100644 --- a/src/data/RenderPassColorAttachment.ts +++ b/src/data/RenderPassColorAttachment.ts @@ -57,6 +57,6 @@ export interface RenderPassColorAttachment readonly loadOp?: LoadOp; } -export type Color = [red: number, green: number, blue: number, alpha: number]; +export type Color = readonly [red: number, green: number, blue: number, alpha: number]; export type LoadOp = "load" | "clear"; From f999563a8a6095b13a198a867ad50f4a3f711d72 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 14 May 2025 23:06:36 +0800 Subject: [PATCH 02/73] =?UTF-8?q?refactor(src):=20=E4=BC=98=E5=8C=96=20Cha?= =?UTF-8?q?inMap.ts=20=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了 ChainMap.ts 中的代码缩进和空格问题 - 确保函数 wrapKey 的返回值格式一致 --- src/utils/ChainMap.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 8aa1d65..56bdf3b 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -33,7 +33,7 @@ export class ChainMap, V> key = wrapKey(keys[keysLength - 1]); -return map.get(key); + return map.get(key); } /** @@ -128,5 +128,5 @@ function wrapKey(key: any) // 存储原始值和包装对象的映射 keyMap.set(key, wrapper); -return wrapper; + return wrapper; } \ No newline at end of file From 61426894bc2d5f36e15e1a0a83f8d3feba5d96b8 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 15 May 2025 22:42:44 +0800 Subject: [PATCH 03/73] =?UTF-8?q?build(package.json):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20@feng3d/reactivity=20=E4=BE=9D=E8=B5=96=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=87=B3=203.5.14-0.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48b79b8..219063e 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ "vitest": "^0.32.2" }, "dependencies": { - "@feng3d/reactivity": "^1.0.4" + "@feng3d/reactivity": "^3.5.14-0.0.1" } } From dc81c88a681c807cb34294842fe05907aed33298 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 16 May 2025 01:35:02 +0800 Subject: [PATCH 04/73] =?UTF-8?q?build(package.json):=20=E5=B0=86=20@feng3?= =?UTF-8?q?d/reactivity=20=E4=BE=9D=E8=B5=96=E7=89=88=E6=9C=AC=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=E8=87=B3=201.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 219063e..14418bf 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ "vitest": "^0.32.2" }, "dependencies": { - "@feng3d/reactivity": "^3.5.14-0.0.1" + "@feng3d/reactivity": "^1.0.5" } } From 46dcfb267e581d0a5e1ff9bdc73ea48a2c173e67 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 17 May 2025 11:09:29 +0800 Subject: [PATCH 05/73] =?UTF-8?q?build(package.json):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BE=9D=E8=B5=96=E5=92=8C=20@feng3d/reactiv?= =?UTF-8?q?ity=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 @typescript-eslint/eslint-plugin 和 @typescript-eslint/parser 更新至 8.32.1 - 更新 @vitest/ui 至 3.1.3 - 更新 eslint 至 9.27.0 - 更新 rimraf 至 6.0.1 - 更新 tslib 至 2.8.1 - 更新 typedoc 至 0.28.4 - 更新 typescript 至 5.8.3 - 更新 vite 至 6.3.5 - 将 @feng3d/reactivity 版本更新至 1.0.6 --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 14418bf..2d5b7aa 100644 --- a/package.json +++ b/package.json @@ -43,19 +43,19 @@ "tsconfig.json" ], "devDependencies": { - "@typescript-eslint/eslint-plugin": "5.17.0", - "@typescript-eslint/parser": "5.17.0", - "@vitest/ui": "^0.32.2", + "@typescript-eslint/eslint-plugin": "8.32.1", + "@typescript-eslint/parser": "8.32.1", + "@vitest/ui": "^3.1.3", "cross-env": "7.0.3", - "eslint": "8.12.0", - "rimraf": "3.0.2", - "tslib": "^2.4.0", - "typedoc": "^0.24.8", - "typescript": "5.1.3", - "vite": "^4.3.9", - "vitest": "^0.32.2" + "eslint": "9.27.0", + "rimraf": "6.0.1", + "tslib": "^2.8.1", + "typedoc": "^0.28.4", + "typescript": "5.8.3", + "vite": "^6.3.5", + "vitest": "^3.1.3" }, "dependencies": { - "@feng3d/reactivity": "^1.0.5" + "@feng3d/reactivity": "^1.0.6" } } From 71f96dc71cc18098ad0b7b5c8b5a831530eaeecf Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 19 May 2025 22:19:20 +0800 Subject: [PATCH 06/73] =?UTF-8?q?=E5=88=A0=E9=99=A4=20ESLint=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=92=8C=E5=BF=BD=E7=95=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=20package.json=20=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=20lint=20=E5=91=BD=E4=BB=A4=E5=92=8C=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E4=BE=9D=E8=B5=96=E9=A1=B9=EF=BC=8C=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E4=B8=BA=E5=8D=95=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 6 - .eslintrc.json | 473 ------------------- eslint.config.js | 159 +++++++ package.json | 18 +- scripts/postpublish.js | 13 +- scripts/prepublish.js | 13 +- src/consts/vertexFormatMap.ts | 106 ++--- src/data/BindingResources.ts | 2 +- src/data/BlendComponent.ts | 28 +- src/data/BlendState.ts | 21 +- src/data/Buffer.ts | 4 +- src/data/BufferBinding.ts | 2 +- src/data/CanvasTexture.ts | 2 +- src/data/ColorTargetState.ts | 2 +- src/data/CommandEncoder.ts | 6 +- src/data/CopyBufferToBuffer.ts | 4 +- src/data/CopyTextureToTexture.ts | 6 +- src/data/DepthStencilState.ts | 2 +- src/data/DrawIndexed.ts | 2 +- src/data/DrawVertex.ts | 2 +- src/data/FragmentState.ts | 2 +- src/data/ImageCopyTexture.ts | 4 +- src/data/OcclusionQuery.ts | 4 +- src/data/PrimitiveState.ts | 18 +- src/data/ReadPixels.ts | 2 +- src/data/RenderObject.ts | 26 +- src/data/RenderPass.ts | 8 +- src/data/RenderPassColorAttachment.ts | 4 +- src/data/RenderPassDepthStencilAttachment.ts | 6 +- src/data/RenderPassDescriptor.ts | 4 +- src/data/RenderPipeline.ts | 8 +- src/data/Sampler.ts | 8 +- src/data/StencilFaceState.ts | 4 +- src/data/Submit.ts | 2 +- src/data/Texture.ts | 312 ++++++------ src/data/TextureDataSource.ts | 4 +- src/data/TextureImageSource.ts | 5 +- src/data/TextureView.ts | 2 +- src/data/VertexAttributes.ts | 66 +-- src/data/WriteBuffer.ts | 2 +- src/index.ts | 86 ++-- src/utils/ChainMap.ts | 6 +- test/index.spec.ts | 8 +- vite.config.js | 20 +- 44 files changed, 586 insertions(+), 896 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 5cea5ae..0000000 --- a/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -node_modules - -dist -build -lib - diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 254a952..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,473 +0,0 @@ -{ - "env": { - "es6": true, - "browser": true, - "node": true, - "mocha": true - }, - "globals": { - "global": false - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 8, - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint" - ], - "rules": { - // Possible Errors - "comma-dangle": [ - 1, - "only-multiline" - ], - "no-cond-assign": [ - 1, - "except-parens" - ], - "no-constant-condition": 1, - "no-control-regex": 1, - "no-debugger": 0, - "no-dupe-args": 1, - "no-dupe-keys": 1, - "no-duplicate-case": 1, - "no-empty": 1, - "no-empty-character-class": 1, - "no-ex-assign": 1, - "no-extra-boolean-cast": 1, - "no-extra-parens": 0, - "no-extra-semi": 1, - "no-func-assign": 1, - "no-inner-declarations": 1, - "no-invalid-regexp": 1, - "no-irregular-whitespace": 1, - "no-negated-in-lhs": 1, - "no-obj-calls": 1, - "no-regex-spaces": 1, - "no-sparse-arrays": 1, - "no-unexpected-multiline": 1, - "no-unreachable": 1, - "no-unsafe-finally": 1, - "use-isnan": 1, - "valid-jsdoc": [ - 0, - { - "requireReturn": false, - "requireReturnType": true, - "requireParamDescription": true, - "requireReturnDescription": true - } - ], - "valid-typeof": 1, - // Best Practices - "accessor-pairs": 1, - "array-callback-return": 1, - "block-scoped-var": 1, - "complexity": 0, - "curly": [ - 1, - "multi-line" - ], - "default-case": 0, - "dot-location": [ - 1, - "property" - ], - "dot-notation": 0, - "eqeqeq": 1, - "guard-for-in": 0, - "no-alert": 0, - "no-caller": 1, - "no-case-declarations": 0, - "no-div-regex": 1, - "no-else-return": 1, - "no-empty-function": 0, - "no-empty-pattern": 1, - "no-eq-null": 1, - "no-eval": 1, - "no-extend-native": 1, - "no-extra-bind": 1, - "no-extra-label": 1, - "no-fallthrough": 1, - "no-floating-decimal": 1, - "no-implicit-coercion": [ - 1, - { - "boolean": false, - "number": true, - "string": true, - "allow": [] - } - ], - "no-implicit-globals": 1, - "no-implied-eval": 1, - "no-invalid-this": 0, - "no-iterator": 1, - "no-labels": 1, - "no-lone-blocks": 1, - "no-loop-func": 1, - "no-magic-numbers": [ - 0 - ], - "no-multi-spaces": [ - 1, - { - "exceptions": { - "VariableDeclarator": true, - "ImportDeclaration": true, - "Property": true - } - } - ], - "no-multi-str": 1, - "no-native-reassign": 1, - "no-new": 0, - "no-new-func": 1, - "no-new-wrappers": 1, - "no-octal": 1, - "no-octal-escape": 1, - "no-param-reassign": 0, - "no-redeclare": 1, - "no-return-assign": 0, - "no-script-url": 1, - "no-self-assign": 1, - "no-self-compare": 1, - "no-sequences": 1, - "no-unmodified-loop-condition": 1, - "no-unused-expressions": "off", - "no-unused-labels": 1, - "no-useless-call": 1, - "no-useless-concat": 1, - "no-useless-escape": 0, - "no-void": 1, - "no-warning-comments": 0, - "no-with": 1, - "radix": 0, - "vars-on-top": 0, - "wrap-iife": [ - 1, - "inside" - ], - "yoda": 0, - // Strict Mode - "strict": [ - 1, - "global" - ], - // Variables - "init-declarations": 0, - "no-catch-shadow": 1, - "no-delete-var": 1, - "no-label-var": 1, - "no-restricted-globals": [ - "error", - "event", - "fdescribe" - ], - "no-shadow": 0, - "no-shadow-restricted-names": 1, - "no-undef": 1, - "no-undef-init": 1, - "no-undefined": 0, - "no-unused-vars": "off", - // Node.js and CommonJS - "callback-return": 0, - "global-require": 1, - "handle-callback-err": 1, - "no-mixed-requires": 1, - "no-new-require": 1, - "no-path-concat": 1, - "no-process-env": 0, - "no-process-exit": 0, - "no-restricted-modules": 0, - "no-sync": 0, - // Stylistic Issues - "array-bracket-spacing": [ - 1, - "never" - ], - "block-spacing": [ - 1, - "always" - ], - "brace-style": [ - 1, - "allman", - { - "allowSingleLine": true - } - ], - "camelcase": [ - 0, - { - "properties": "never" - } - ], - "comma-spacing": [ - 1, - { - "before": false, - "after": true - } - ], - "comma-style": [ - 1, - "last" - ], - "computed-property-spacing": [ - 1, - "never" - ], - "consistent-this": 0, - "func-style": [ - 1, - "declaration", - { - "allowArrowFunctions": true - } - ], - "id-blacklist": 0, - "id-length": 0, - "id-match": 0, - "jsx-quotes": [ - 1, - "prefer-double" - ], - "key-spacing": [ - 1, - { - "beforeColon": false, - "afterColon": true, - "mode": "minimum" - } - ], - "keyword-spacing": [ - 1, - { - "before": true, - "after": true - } - ], - "lines-around-comment": 0, - "max-depth": [ - 1, - 6 - ], - "max-lines": 0, - "max-nested-callbacks": [ - 1, - { - "max": 5 - } - ], - "max-params": [ - 1, - { - "max": 10 - } - ], - "max-statements": 0, - "new-cap": [ - 1, - { - "newIsCap": true, - "capIsNew": false, - "properties": false - } - ], - "new-parens": 1, - "newline-before-return": 1, - "newline-per-chained-call": [ - 1, - { - "ignoreChainWithDepth": 4 - } - ], - "no-array-constructor": 1, - "no-bitwise": 0, - "no-continue": 0, - "no-inline-comments": 0, - "no-lonely-if": 0, - "no-mixed-spaces-and-tabs": 1, - "no-multiple-empty-lines": [ - 1, - { - "max": 1, - "maxEOF": 1, - "maxBOF": 0 - } - ], - "no-negated-condition": 0, - "no-new-object": 1, - "no-plusplus": 0, - "no-restricted-syntax": 0, - "no-spaced-func": 1, - "no-ternary": 0, - "no-trailing-spaces": 1, - "no-underscore-dangle": 0, - "no-unneeded-ternary": 1, - "no-whitespace-before-property": 1, - "object-curly-newline": 0, - "object-curly-spacing": [ - 1, - "always" - ], - "object-property-newline": 0, - "one-var": [ - 1, - "never" - ], - "one-var-declaration-per-line": [ - 1, - "always" - ], - "operator-assignment": 0, - "operator-linebreak": [ - 1, - "before" - ], - "padded-blocks": [ - 1, - "never" - ], - "quote-props": [ - 1, - "as-needed" - ], - "quotes": [ - 1, - "double", - { - "allowTemplateLiterals": true - } - ], - "require-jsdoc": [ - 0, - { - "require": { - "FunctionDeclaration": false, - "ClassDeclaration": true, - "MethodDefinition": true - } - } - ], - "semi": [ - 1, - "always" - ], - "semi-spacing": [ - 1, - { - "before": false, - "after": true - } - ], - "sort-vars": 0, - "space-before-blocks": [ - 1, - "always" - ], - "space-in-parens": [ - 1, - "never" - ], - "space-infix-ops": 1, - "space-unary-ops": [ - 1, - { - "words": true, - "nonwords": false - } - ], - "unicode-bom": [ - 1, - "never" - ], - "wrap-regex": 1, - // ECMAScript 6 - "arrow-body-style": [ - 1, - "as-needed" - ], - "arrow-parens": 1, - "arrow-spacing": [ - 1, - { - "before": true, - "after": true - } - ], - "constructor-super": 1, - "generator-star-spacing": [ - 1, - { - "before": true, - "after": false - } - ], - "no-class-assign": 1, - "no-confusing-arrow": [ - 1, - { - "allowParens": true - } - ], - "no-const-assign": 1, - "no-dupe-class-members": 0, - "no-duplicate-imports": 0, - "no-new-symbol": 1, - "no-restricted-imports": 0, - "no-this-before-super": 1, - "no-useless-computed-key": 1, - "no-useless-constructor": 0, - "@typescript-eslint/no-useless-constructor": 0, - "no-useless-rename": 1, - "no-var": 1, - "object-shorthand": 1, - "prefer-arrow-callback": 0, - "prefer-const": 1, - "prefer-reflect": 0, - "prefer-rest-params": 0, - "prefer-spread": 0, - "prefer-template": 1, - "require-yield": 1, - "rest-spread-spacing": [ - 1, - "never" - ], - "sort-imports": 0, - "template-curly-spacing": [ - 1, - "never" - ], - "yield-star-spacing": [ - 1, - "before" - ] - }, - "overrides": [ - { - "files": [ - "*.ts" - ], - "extends": [ - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/ban-types": 0, - "@typescript-eslint/semi": 1, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/interface-name-prefix": 0, - "@typescript-eslint/no-unused-vars": 0, - "@typescript-eslint/no-empty-interface": 0, - "@typescript-eslint/explicit-module-boundary-types": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-this-alias": 0, - "@typescript-eslint/no-empty-function": 0, - "prefer-spread": 0, - "@typescript-eslint/no-non-null-assertion": 0 - } - } - ] -} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..4310b9b --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,159 @@ +// 导入 ESLint 核心模块 +import eslint from '@eslint/js'; +// 导入 TypeScript ESLint 配置 +import tseslint from 'typescript-eslint'; +// 导入全局变量定义 +import globals from 'globals'; + +// 导出 ESLint 配置 +export default [ + // 忽略检查的文件和目录 + { + ignores: [ + '**/node_modules/**', // 忽略所有 node_modules 目录 + '**/dist/**', // 忽略所有 dist 目录 + '**/lib/**', // 忽略所有 lib 目录 + '**/public/**', // 忽略所有 public 目录 + '**/coverage/**', // 忽略所有 coverage 目录 + '**/.git/**', // 忽略所有 .git 目录 + '**/packages/**', // 忽略所有 packages 目录 + ], + }, + // 使用 ESLint 推荐配置 + eslint.configs.recommended, + // 使用 TypeScript ESLint 推荐配置 + ...tseslint.configs.recommended, + { + // 语言选项配置 + languageOptions: { + // 全局变量配置 + globals: { + ...globals.browser, // 浏览器环境全局变量 + ...globals.node, // Node.js 环境全局变量 + ...globals.es2021, // ES2021 全局变量 + global: false, // 禁用 global 全局变量 + }, + // 解析器选项 + parserOptions: { + ecmaVersion: 2021, // 使用 ES2021 语法 + sourceType: 'module', // 使用 ES 模块 + }, + }, + rules: { + '@typescript-eslint/no-unused-vars': 'off', // 允许未使用的变量 + '@typescript-eslint/no-explicit-any': 'off', // 允许使用 any 类型 + 'no-prototype-builtins': 'off', // 允许直接使用 Object.prototype 方法 + '@typescript-eslint/ban-ts-comment': 'off', // 允许使用 @ts 注释 + '@typescript-eslint/no-unused-expressions': 'off', // 允许未使用的表达式 + '@typescript-eslint/no-empty-object-type': 'off', // 允许空对象类型 + '@typescript-eslint/no-unsafe-declaration-merging': 'off', // 允许不安全的声明合并 + '@typescript-eslint/no-unsafe-function-type': 'off', // 允许不安全的函数类型 + '@typescript-eslint/no-this-alias': 'off', // 允许 this 别名 + 'prefer-const': 'off', // 不强制使用 const + 'no-fallthrough': 'off', // 允许 fallthrough + 'no-constant-binary-expression': 'off', // 允许常量二进制表达式 + + // 注释格式规则 + 'spaced-comment': ['warn', 'always', { + 'line': { + 'markers': ['/'], // 以 / 开头的注释需要空格 + 'exceptions': ['-', '+'], // 允许以 - 和 + 开头的注释不需要空格 + }, + 'block': { + 'markers': ['!'], // 以 ! 开头的块级注释需要空格 + 'exceptions': ['*'], // 允许以 * 开头的块级注释不需要空格 + 'balanced': true, // 要求块级注释的 * 对齐 + }, + }], + + // 空格和换行规则 + 'no-trailing-spaces': ['warn', { // 禁止行尾空格 + 'skipBlankLines': false, // 不跳过空行 + 'ignoreComments': false, // 不忽略注释 + }], + 'no-multiple-empty-lines': ['warn', { // 限制空行数量 + 'max': 1, // 最多允许 1 个空行 + 'maxEOF': 1, // 文件末尾最多 1 个空行 + 'maxBOF': 0, // 文件开头不允许空行 + }], + 'lines-between-class-members': ['warn', 'always', { // 类成员之间需要空行 + 'exceptAfterSingleLine': true, // 单行成员后可以没有空行 + }], + 'padding-line-between-statements': [ // 语句之间的空行规则 + 'warn', + { 'blankLine': 'always', 'prev': '*', 'next': 'return' }, // return 前需要空行 + { 'blankLine': 'always', 'prev': ['const', 'let', 'var'], 'next': '*' }, // 变量声明后需要空行 + { 'blankLine': 'any', 'prev': ['const', 'let', 'var'], 'next': ['const', 'let', 'var'] }, // 变量声明之间可以没有空行 + ], + + // 缩进规则 + 'indent': ['warn', 4, { // 使用 4 空格缩进 + 'SwitchCase': 1, // switch case 缩进 1 级 + 'VariableDeclarator': 'first', // 变量声明对齐到第一个变量 + 'outerIIFEBody': 1, // 外层 IIFE 缩进 1 级 + 'MemberExpression': 1, // 成员表达式缩进 1 级 + 'FunctionDeclaration': { // 函数声明缩进规则 + 'parameters': 1, // 参数缩进 1 级 + 'body': 1, // 函数体缩进 1 级 + }, + 'FunctionExpression': { // 函数表达式缩进规则 + 'parameters': 1, // 参数缩进 1 级 + 'body': 1, // 函数体缩进 1 级 + }, + 'CallExpression': { // 函数调用缩进规则 + 'arguments': 1, // 参数缩进 1 级 + }, + 'ArrayExpression': 1, // 数组表达式缩进 1 级 + 'ObjectExpression': 1, // 对象表达式缩进 1 级 + 'ImportDeclaration': 1, // import 声明缩进 1 级 + 'flatTernaryExpressions': false, // 不扁平化三元表达式 + 'ignoreComments': false, // 不忽略注释 + }], + + // 引号规则 + 'quotes': ['warn', 'single', { // 使用单引号 + 'avoidEscape': true, // 允许使用转义字符 + 'allowTemplateLiterals': true, // 允许使用模板字符串 + }], + + // 其他格式规则 + 'semi': ['off'], // 要求使用分号 + 'comma-dangle': ['warn', 'always-multiline'], // 多行时要求尾随逗号 + 'object-curly-spacing': ['warn', 'always'], // 对象括号内要求空格 + 'array-bracket-spacing': ['warn', 'never'], // 数组括号内不允许空格 + 'arrow-spacing': ['warn', { // 箭头函数空格规则 + 'before': true, // 箭头前需要空格 + 'after': true, // 箭头后需要空格 + }], + 'block-spacing': ['warn', 'always'], // 块级代码需要空格 + 'brace-style': ['warn', 'allman', { // 大括号风格 + 'allowSingleLine': false, // 不允许单行大括号 + }], + 'comma-spacing': ['warn', { // 逗号空格规则 + 'before': false, // 逗号前不允许空格 + 'after': true, // 逗号后需要空格 + }], + 'comma-style': ['warn', 'last'], // 逗号放在行尾 + 'key-spacing': ['warn', { // 对象键值对空格规则 + 'beforeColon': false, // 冒号前不允许空格 + 'afterColon': true, // 冒号后需要空格 + }], + 'keyword-spacing': ['warn', { // 关键字空格规则 + 'before': true, // 关键字前需要空格 + 'after': true, // 关键字后需要空格 + }], + 'space-before-blocks': ['warn', 'always'], // 块级代码前需要空格 + 'space-before-function-paren': ['warn', { // 函数括号前空格规则 + 'anonymous': 'always', // 匿名函数括号前需要空格 + 'named': 'never', // 命名函数括号前不允许空格 + 'asyncArrow': 'always', // 异步箭头函数括号前需要空格 + }], + 'space-in-parens': ['warn', 'never'], // 括号内不允许空格 + 'space-infix-ops': ['warn'], // 操作符前后需要空格 + 'space-unary-ops': ['warn', { // 一元操作符空格规则 + 'words': true, // 单词类操作符需要空格 + 'nonwords': false, // 非单词类操作符不需要空格 + }], + }, + }, +]; \ No newline at end of file diff --git a/package.json b/package.json index 2d5b7aa..aefe82f 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,15 @@ "name": "@feng3d/render-api", "version": "0.0.4", "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", + "homepage": "https://feng3d.com/render-api/", "author": "feng", - "license": "MIT", "type": "module", "main": "./src/index.ts", "types": "./src/index.ts", "module": "./src/index.ts", "exports": { ".": { + "types": "./src/index.ts", "import": "./src/index.ts", "require": "./src/index.ts" } @@ -18,13 +19,13 @@ "clean": "rimraf \"{lib,dist,public}\"", "build": "vite build", "test": "vitest", - "test:ui": "vitest --ui", "types": "tsc", "watch": "tsc -w", - "lint": "eslint --ext .js --ext .ts src --ignore-path .gitignore --max-warnings 0", + "lint": "eslint . --ext .js,.ts --max-warnings 0", "lintfix": "npm run lint -- --fix", "docs": "typedoc", - "release": "npm run clean && npm run lint && npm run build && npm run types && npm publish", + "upload_oss": "npm run docs && feng3d-cli oss_upload_dir", + "release": "npm run clean && npm run lint && npm run build && npm run docs && npm run types && npm publish", "prepublishOnly": "node scripts/prepublish.js", "postpublish": "node scripts/postpublish.js" }, @@ -43,11 +44,14 @@ "tsconfig.json" ], "devDependencies": { + "@eslint/js": "^9.0.0", + "@feng3d/cli": "^0.0.19", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", - "@vitest/ui": "^3.1.3", + "typescript-eslint": "^8.32.1", "cross-env": "7.0.3", - "eslint": "9.27.0", + "eslint": "9.26.0", + "globals": "^14.0.0", "rimraf": "6.0.1", "tslib": "^2.8.1", "typedoc": "^0.28.4", @@ -58,4 +62,4 @@ "dependencies": { "@feng3d/reactivity": "^1.0.6" } -} +} \ No newline at end of file diff --git a/scripts/postpublish.js b/scripts/postpublish.js index 01321a4..7296278 100644 --- a/scripts/postpublish.js +++ b/scripts/postpublish.js @@ -1,9 +1,10 @@ -import * as fs from "fs"; -import * as path from "path"; +import * as fs from 'fs'; +import * as path from 'path'; -const pkgpath = path.resolve("package.json"); +const pkgpath = path.resolve('package.json'); + +let pkg = fs.readFileSync(pkgpath, 'utf8'); -let pkg = fs.readFileSync(pkgpath, "utf8"); pkg = pkg .replace(`"types": "./lib/index.d.ts"`, `"types": "./src/index.ts"`) // @@ -12,6 +13,6 @@ pkg = pkg // .replace(`"import": "./dist/index.js"`, `"import": "./src/index.ts"`) .replace(`"require": "./dist/index.umd.cjs"`, `"require": "./src/index.ts"`) - ; +; -fs.writeFileSync(pkgpath, pkg, "utf8"); +fs.writeFileSync(pkgpath, pkg, 'utf8'); diff --git a/scripts/prepublish.js b/scripts/prepublish.js index db681a8..043f4c8 100644 --- a/scripts/prepublish.js +++ b/scripts/prepublish.js @@ -1,9 +1,10 @@ -import * as fs from "fs"; -import * as path from "path"; +import * as fs from 'fs'; +import * as path from 'path'; -const pkgpath = path.resolve("package.json"); +const pkgpath = path.resolve('package.json'); + +let pkg = fs.readFileSync(pkgpath, 'utf8'); -let pkg = fs.readFileSync(pkgpath, "utf8"); pkg = pkg .replace(`"types": "./src/index.ts"`, `"types": "./lib/index.d.ts"`) // @@ -12,6 +13,6 @@ pkg = pkg // .replace(`"import": "./src/index.ts"`, `"import": "./dist/index.js"`) .replace(`"require": "./src/index.ts"`, `"require": "./dist/index.umd.cjs"`) - ; +; -fs.writeFileSync(pkgpath, pkg, "utf8"); +fs.writeFileSync(pkgpath, pkg, 'utf8'); diff --git a/src/consts/vertexFormatMap.ts b/src/consts/vertexFormatMap.ts index 4ccfd06..7631ea9 100644 --- a/src/consts/vertexFormatMap.ts +++ b/src/consts/vertexFormatMap.ts @@ -1,40 +1,40 @@ -import { VertexFormat } from "../data/VertexAttributes"; +import { VertexFormat } from '../data/VertexAttributes'; /** * 顶点属性格式信息映射。 */ export const vertexFormatMap: Record = { - uint8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Uint8Array }, - uint8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Uint8Array }, - sint8x2: { numComponents: 2, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Int8Array }, - sint8x4: { numComponents: 4, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int8Array }, - unorm8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Uint8Array }, - unorm8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Uint8Array }, - snorm8x2: { numComponents: 2, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Int8Array }, - snorm8x4: { numComponents: 4, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int8Array }, - uint16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Uint16Array }, - uint16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Uint16Array }, - sint16x2: { numComponents: 2, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Int16Array }, - sint16x4: { numComponents: 4, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Int16Array }, - unorm16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Uint16Array }, - unorm16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Uint16Array }, - snorm16x2: { numComponents: 2, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Int16Array }, - snorm16x4: { numComponents: 4, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Int16Array }, - float16x2: { numComponents: 2, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "vec2", typedArrayConstructor: undefined }, - float16x4: { numComponents: 4, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec4", typedArrayConstructor: undefined }, - float32: { numComponents: 1, type: "FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "f32", typedArrayConstructor: Float32Array }, - float32x2: { numComponents: 2, type: "FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Float32Array }, - float32x3: { numComponents: 3, type: "FLOAT", normalized: false, dataType: "float", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Float32Array }, - float32x4: { numComponents: 4, type: "FLOAT", normalized: false, dataType: "float", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Float32Array }, - uint32: { numComponents: 1, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "u32", typedArrayConstructor: Uint32Array }, - uint32x2: { numComponents: 2, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Uint32Array }, - uint32x3: { numComponents: 3, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Uint32Array }, - uint32x4: { numComponents: 4, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Uint32Array }, - sint32: { numComponents: 1, type: "INT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "i32", typedArrayConstructor: Int32Array }, - sint32x2: { numComponents: 2, type: "INT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Int32Array }, - sint32x3: { numComponents: 3, type: "INT", normalized: false, dataType: "signed int", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Int32Array }, - sint32x4: { numComponents: 4, type: "INT", normalized: false, dataType: "signed int", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Int32Array }, - "unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int32Array } + uint8x2: { numComponents: 2, type: 'UNSIGNED_BYTE', normalized: false, dataType: 'unsigned int', byteSize: 2, wgslType: 'vec2', typedArrayConstructor: Uint8Array }, + uint8x4: { numComponents: 4, type: 'UNSIGNED_BYTE', normalized: false, dataType: 'unsigned int', byteSize: 4, wgslType: 'vec4', typedArrayConstructor: Uint8Array }, + sint8x2: { numComponents: 2, type: 'BYTE', normalized: false, dataType: 'signed int', byteSize: 2, wgslType: 'vec2', typedArrayConstructor: Int8Array }, + sint8x4: { numComponents: 4, type: 'BYTE', normalized: false, dataType: 'signed int', byteSize: 4, wgslType: 'vec4', typedArrayConstructor: Int8Array }, + unorm8x2: { numComponents: 2, type: 'UNSIGNED_BYTE', normalized: true, dataType: 'unsigned normalized', byteSize: 2, wgslType: 'vec2', typedArrayConstructor: Uint8Array }, + unorm8x4: { numComponents: 4, type: 'UNSIGNED_BYTE', normalized: true, dataType: 'unsigned normalized', byteSize: 4, wgslType: 'vec4', typedArrayConstructor: Uint8Array }, + snorm8x2: { numComponents: 2, type: 'BYTE', normalized: true, dataType: 'signed normalized', byteSize: 2, wgslType: 'vec2', typedArrayConstructor: Int8Array }, + snorm8x4: { numComponents: 4, type: 'BYTE', normalized: true, dataType: 'signed normalized', byteSize: 4, wgslType: 'vec4', typedArrayConstructor: Int8Array }, + uint16x2: { numComponents: 2, type: 'UNSIGNED_SHORT', normalized: false, dataType: 'unsigned int', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Uint16Array }, + uint16x4: { numComponents: 4, type: 'UNSIGNED_SHORT', normalized: false, dataType: 'unsigned int', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Uint16Array }, + sint16x2: { numComponents: 2, type: 'SHORT', normalized: false, dataType: 'signed int', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Int16Array }, + sint16x4: { numComponents: 4, type: 'SHORT', normalized: false, dataType: 'signed int', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Int16Array }, + unorm16x2: { numComponents: 2, type: 'UNSIGNED_SHORT', normalized: true, dataType: 'unsigned normalized', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Uint16Array }, + unorm16x4: { numComponents: 4, type: 'UNSIGNED_SHORT', normalized: true, dataType: 'unsigned normalized', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Uint16Array }, + snorm16x2: { numComponents: 2, type: 'SHORT', normalized: true, dataType: 'signed normalized', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Int16Array }, + snorm16x4: { numComponents: 4, type: 'SHORT', normalized: true, dataType: 'signed normalized', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Int16Array }, + float16x2: { numComponents: 2, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: undefined }, + float16x4: { numComponents: 4, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: undefined }, + float32: { numComponents: 1, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 4, wgslType: 'f32', typedArrayConstructor: Float32Array }, + float32x2: { numComponents: 2, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 8, wgslType: 'vec2', typedArrayConstructor: Float32Array }, + float32x3: { numComponents: 3, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 12, wgslType: 'vec3', typedArrayConstructor: Float32Array }, + float32x4: { numComponents: 4, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 16, wgslType: 'vec4', typedArrayConstructor: Float32Array }, + uint32: { numComponents: 1, type: 'UNSIGNED_INT', normalized: false, dataType: 'unsigned int', byteSize: 4, wgslType: 'u32', typedArrayConstructor: Uint32Array }, + uint32x2: { numComponents: 2, type: 'UNSIGNED_INT', normalized: false, dataType: 'unsigned int', byteSize: 8, wgslType: 'vec2', typedArrayConstructor: Uint32Array }, + uint32x3: { numComponents: 3, type: 'UNSIGNED_INT', normalized: false, dataType: 'unsigned int', byteSize: 12, wgslType: 'vec3', typedArrayConstructor: Uint32Array }, + uint32x4: { numComponents: 4, type: 'UNSIGNED_INT', normalized: false, dataType: 'unsigned int', byteSize: 16, wgslType: 'vec4', typedArrayConstructor: Uint32Array }, + sint32: { numComponents: 1, type: 'INT', normalized: false, dataType: 'signed int', byteSize: 4, wgslType: 'i32', typedArrayConstructor: Int32Array }, + sint32x2: { numComponents: 2, type: 'INT', normalized: false, dataType: 'signed int', byteSize: 8, wgslType: 'vec2', typedArrayConstructor: Int32Array }, + sint32x3: { numComponents: 3, type: 'INT', normalized: false, dataType: 'signed int', byteSize: 12, wgslType: 'vec3', typedArrayConstructor: Int32Array }, + sint32x4: { numComponents: 4, type: 'INT', normalized: false, dataType: 'signed int', byteSize: 16, wgslType: 'vec4', typedArrayConstructor: Int32Array }, + 'unorm10-10-10-2': { numComponents: 4, type: 'UNSIGNED_INT_2_10_10_10_REV', normalized: true, dataType: 'unsigned normalized', byteSize: 4, wgslType: 'vec4', typedArrayConstructor: Int32Array }, }; /** @@ -46,31 +46,31 @@ export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor * GPU顶点数据类型 */ export type VertexDataType = - | "unsigned int" - | "signed int" - | "unsigned normalized" - | "signed normalized" - | "float" + | 'unsigned int' + | 'signed int' + | 'unsigned normalized' + | 'signed normalized' + | 'float' ; /** * 顶点数据在WGSL中的类型。 */ export type WGSLVertexType = - | "vec2" - | "vec4" - | "vec2" - | "vec4" - | "vec2" - | "vec4" - | "vec2" - | "vec4" - | "f32" - | "vec3" - | "u32" - | "vec3" - | "i32" - | "vec3" + | 'vec2' + | 'vec4' + | 'vec2' + | 'vec4' + | 'vec2' + | 'vec4' + | 'vec2' + | 'vec4' + | 'f32' + | 'vec3' + | 'u32' + | 'vec3' + | 'i32' + | 'vec3' ; /** @@ -94,8 +94,8 @@ export type WGSLVertexType = * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer */ -export type GLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1 - | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2 +export type GLVertexAttributeTypes = 'FLOAT' | 'BYTE' | 'SHORT' | 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' // WebGL1 + | 'HALF_FLOAT' | 'INT' | 'UNSIGNED_INT' | 'INT_2_10_10_10_REV' | 'UNSIGNED_INT_2_10_10_10_REV'; // WebGL2 /** * 顶点属性格式信息 diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index 350b964..a98b22b 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -1,4 +1,4 @@ -import { BufferBinding, BufferBindingItem } from "./BufferBinding"; +import { BufferBinding, BufferBindingItem } from './BufferBinding'; /** * 绑定资源。 diff --git a/src/data/BlendComponent.ts b/src/data/BlendComponent.ts index b9e906b..ee496ec 100644 --- a/src/data/BlendComponent.ts +++ b/src/data/BlendComponent.ts @@ -42,7 +42,7 @@ export interface BlendComponent readonly dstFactor?: IBlendFactor; } -export type IBlendOperation = "add" | "subtract" | "reverse-subtract" | "min" | "max"; +export type IBlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max'; /** * @see https://gpuweb.github.io/gpuweb/#enumdef-gpublendfactor @@ -51,17 +51,17 @@ export type IBlendFactor = IBlendFactorMap[keyof IBlendFactorMap]; export interface IBlendFactorMap { - "zero": "zero"; - "one": "one"; - "src": "src"; - "one-minus-src": "one-minus-src"; - "src-alpha": "src-alpha"; - "one-minus-src-alpha": "one-minus-src-alpha"; - "dst": "dst"; - "one-minus-dst": "one-minus-dst"; - "dst-alpha": "dst-alpha"; - "one-minus-dst-alpha": "one-minus-dst-alpha"; - "src-alpha-saturated": "src-alpha-saturated"; - "constant": "constant"; - "one-minus-constant": "one-minus-constant"; + 'zero': 'zero'; + 'one': 'one'; + 'src': 'src'; + 'one-minus-src': 'one-minus-src'; + 'src-alpha': 'src-alpha'; + 'one-minus-src-alpha': 'one-minus-src-alpha'; + 'dst': 'dst'; + 'one-minus-dst': 'one-minus-dst'; + 'dst-alpha': 'dst-alpha'; + 'one-minus-dst-alpha': 'one-minus-dst-alpha'; + 'src-alpha-saturated': 'src-alpha-saturated'; + 'constant': 'constant'; + 'one-minus-constant': 'one-minus-constant'; } diff --git a/src/data/BlendState.ts b/src/data/BlendState.ts index b027dad..1d98929 100644 --- a/src/data/BlendState.ts +++ b/src/data/BlendState.ts @@ -1,5 +1,5 @@ -import { BlendComponent } from "./BlendComponent"; -import { Color } from "./RenderPassColorAttachment"; +import { BlendComponent } from './BlendComponent'; +import { Color } from './RenderPassColorAttachment'; /** * 混合状态。 @@ -51,17 +51,18 @@ export class BlendState // 当混合系数用到了混合常量值时设置混合常量值。 if (0 - || color?.srcFactor === "constant" - || color?.srcFactor === "one-minus-constant" - || color?.dstFactor === "constant" - || color?.dstFactor === "one-minus-constant" - || alpha?.srcFactor === "constant" - || alpha?.srcFactor === "one-minus-constant" - || alpha?.dstFactor === "constant" - || alpha?.dstFactor === "one-minus-constant" + || color?.srcFactor === 'constant' + || color?.srcFactor === 'one-minus-constant' + || color?.dstFactor === 'constant' + || color?.dstFactor === 'one-minus-constant' + || alpha?.srcFactor === 'constant' + || alpha?.srcFactor === 'one-minus-constant' + || alpha?.dstFactor === 'constant' + || alpha?.dstFactor === 'one-minus-constant' ) { const constantColor = blendState.constantColor; + if (constantColor) { return [constantColor[0], constantColor[1], constantColor[2], constantColor[3]]; diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 620ab87..c3a6091 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -1,5 +1,5 @@ -import { TypedArray } from "../types/TypedArray"; -import { WriteBuffer } from "./WriteBuffer"; +import { TypedArray } from '../types/TypedArray'; +import { WriteBuffer } from './WriteBuffer'; /** * 缓冲区 diff --git a/src/data/BufferBinding.ts b/src/data/BufferBinding.ts index 5c37ab7..d115e0d 100644 --- a/src/data/BufferBinding.ts +++ b/src/data/BufferBinding.ts @@ -1,4 +1,4 @@ -import { TypedArray } from "../types/TypedArray"; +import { TypedArray } from '../types/TypedArray'; /** * 缓冲区绑定。 diff --git a/src/data/CanvasTexture.ts b/src/data/CanvasTexture.ts index de3b617..7ebcde5 100644 --- a/src/data/CanvasTexture.ts +++ b/src/data/CanvasTexture.ts @@ -1,4 +1,4 @@ -import { CanvasContext } from "./CanvasContext"; +import { CanvasContext } from './CanvasContext'; /** * 画布纹理,从画布的上下文获取纹理 diff --git a/src/data/ColorTargetState.ts b/src/data/ColorTargetState.ts index e421f6e..db977ea 100644 --- a/src/data/ColorTargetState.ts +++ b/src/data/ColorTargetState.ts @@ -1,4 +1,4 @@ -import { BlendState } from "./BlendState"; +import { BlendState } from './BlendState'; /** * 属性 `format` 将由渲染通道中附件给出。 diff --git a/src/data/CommandEncoder.ts b/src/data/CommandEncoder.ts index b311f3e..09639ea 100644 --- a/src/data/CommandEncoder.ts +++ b/src/data/CommandEncoder.ts @@ -1,6 +1,6 @@ -import { CopyBufferToBuffer } from "./CopyBufferToBuffer"; -import { CopyTextureToTexture } from "./CopyTextureToTexture"; -import { RenderPass } from "./RenderPass"; +import { CopyBufferToBuffer } from './CopyBufferToBuffer'; +import { CopyTextureToTexture } from './CopyTextureToTexture'; +import { RenderPass } from './RenderPass'; /** * 命令编码器。 diff --git a/src/data/CopyBufferToBuffer.ts b/src/data/CopyBufferToBuffer.ts index 264cfde..36febdb 100644 --- a/src/data/CopyBufferToBuffer.ts +++ b/src/data/CopyBufferToBuffer.ts @@ -1,4 +1,4 @@ -import { Buffer } from "./Buffer"; +import { Buffer } from './Buffer'; /** * GPU缓冲区之间拷贝。 @@ -11,7 +11,7 @@ export interface CopyBufferToBuffer /** * 数据类型。 */ - readonly __type__: "CopyBufferToBuffer"; + readonly __type__: 'CopyBufferToBuffer'; /** * 源缓冲区。 diff --git a/src/data/CopyTextureToTexture.ts b/src/data/CopyTextureToTexture.ts index c55126a..6b18aad 100644 --- a/src/data/CopyTextureToTexture.ts +++ b/src/data/CopyTextureToTexture.ts @@ -1,5 +1,5 @@ -import { ImageCopyTexture } from "./ImageCopyTexture"; -import { TextureSize } from "./Texture"; +import { ImageCopyTexture } from './ImageCopyTexture'; +import { TextureSize } from './Texture'; /** * GPU纹理间拷贝。 @@ -11,7 +11,7 @@ export interface CopyTextureToTexture /** * 数据类型。 */ - readonly __type__: "CopyTextureToTexture"; + readonly __type__: 'CopyTextureToTexture'; /** * Combined with `copySize`, defines the region of the source texture subresources. diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index a79a051..b127598 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -1,4 +1,4 @@ -import { CompareFunction, StencilFaceState } from "./StencilFaceState"; +import { CompareFunction, StencilFaceState } from './StencilFaceState'; /** * 深度模板阶段描述。 diff --git a/src/data/DrawIndexed.ts b/src/data/DrawIndexed.ts index 8d5614c..8491e65 100644 --- a/src/data/DrawIndexed.ts +++ b/src/data/DrawIndexed.ts @@ -9,7 +9,7 @@ export interface DrawIndexed /** * 数据类型。 */ - readonly __type__: "DrawIndexed"; + readonly __type__: 'DrawIndexed'; /** * The number of indices to draw. diff --git a/src/data/DrawVertex.ts b/src/data/DrawVertex.ts index aa2cfdb..146e8a9 100644 --- a/src/data/DrawVertex.ts +++ b/src/data/DrawVertex.ts @@ -11,7 +11,7 @@ export interface DrawVertex /** * 数据类型。 */ - readonly __type__: "DrawVertex"; + readonly __type__: 'DrawVertex'; /** * The number of vertices to draw. diff --git a/src/data/FragmentState.ts b/src/data/FragmentState.ts index e21ada0..0c9da18 100644 --- a/src/data/FragmentState.ts +++ b/src/data/FragmentState.ts @@ -1,4 +1,4 @@ -import { ColorTargetState } from "./ColorTargetState"; +import { ColorTargetState } from './ColorTargetState'; /** * 片段着色器阶段描述。 diff --git a/src/data/ImageCopyTexture.ts b/src/data/ImageCopyTexture.ts index 4f62594..0ff9e7b 100644 --- a/src/data/ImageCopyTexture.ts +++ b/src/data/ImageCopyTexture.ts @@ -1,4 +1,4 @@ -import { TextureLike, TextureOrigin } from "./Texture"; +import { TextureLike, TextureOrigin } from './Texture'; /** * 被操作的纹理相关信息。 @@ -30,4 +30,4 @@ export interface ImageCopyTexture aspect?: ITextureAspect; } -export type ITextureAspect = "all" | "stencil-only" | "depth-only"; \ No newline at end of file +export type ITextureAspect = 'all' | 'stencil-only' | 'depth-only'; \ No newline at end of file diff --git a/src/data/OcclusionQuery.ts b/src/data/OcclusionQuery.ts index 6129ec6..4c11805 100644 --- a/src/data/OcclusionQuery.ts +++ b/src/data/OcclusionQuery.ts @@ -1,4 +1,4 @@ -import { RenderObject } from "./RenderObject"; +import { RenderObject } from './RenderObject'; /** * 遮挡查询 @@ -8,7 +8,7 @@ export interface OcclusionQuery /** * 数据类型。 */ - readonly __type__: "OcclusionQuery"; + readonly __type__: 'OcclusionQuery'; /** * GPU渲染对象列表。 diff --git a/src/data/PrimitiveState.ts b/src/data/PrimitiveState.ts index c5048cd..e1350bd 100644 --- a/src/data/PrimitiveState.ts +++ b/src/data/PrimitiveState.ts @@ -54,11 +54,11 @@ export type PrimitiveTopology = PrimitiveTopologyMap[keyof PrimitiveTopologyMap] export interface PrimitiveTopologyMap { - "point-list": "point-list", - "line-list": "line-list", - "line-strip": "line-strip", - "triangle-list": "triangle-list", - "triangle-strip": "triangle-strip", + 'point-list': 'point-list', + 'line-list': 'line-list', + 'line-strip': 'line-strip', + 'triangle-list': 'triangle-list', + 'triangle-strip': 'triangle-strip', } /** @@ -70,12 +70,12 @@ export type CullFace = CullFaceMap[keyof CullFaceMap]; export interface CullFaceMap { - "none": "none", - "front": "front", - "back": "back", + 'none': 'none', + 'front': 'front', + 'back': 'back', } /** * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace */ -export type FrontFace = "ccw" | "cw"; \ No newline at end of file +export type FrontFace = 'ccw' | 'cw'; \ No newline at end of file diff --git a/src/data/ReadPixels.ts b/src/data/ReadPixels.ts index 516980a..0a74316 100644 --- a/src/data/ReadPixels.ts +++ b/src/data/ReadPixels.ts @@ -1,4 +1,4 @@ -import { TextureView } from "./TextureView"; +import { TextureView } from './TextureView'; /** * 读取渲染缓冲区或者纹理视图中的像素值。 diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index cd4a0eb..2193787 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -1,10 +1,10 @@ -import { BindingResources } from "./BindingResources"; -import { DrawIndexed } from "./DrawIndexed"; -import { DrawVertex } from "./DrawVertex"; -import { RenderPipeline } from "./RenderPipeline"; -import { ScissorRect } from "./ScissorRect"; -import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; -import { Viewport } from "./Viewport"; +import { BindingResources } from './BindingResources'; +import { DrawIndexed } from './DrawIndexed'; +import { DrawVertex } from './DrawVertex'; +import { RenderPipeline } from './RenderPipeline'; +import { ScissorRect } from './ScissorRect'; +import { VertexAttribute, VertexAttributes } from './VertexAttributes'; +import { Viewport } from './Viewport'; /** * 渲染对象,包含一次渲染时包含的所有数据。 @@ -14,7 +14,7 @@ export interface RenderObject /** * 数据类型。 */ - __type__?: "RenderObject"; + __type__?: 'RenderObject'; /** * 视窗。 @@ -66,7 +66,7 @@ export class RenderObject static getNumVertex(geometry: RenderObject) { const attributes = geometry.vertices; - const vertexList = Object.keys(attributes).map((v) => attributes[v]).filter((v) => (v.data && v.stepMode !== "instance")); + const vertexList = Object.keys(attributes).map((v) => attributes[v]).filter((v) => (v.data && v.stepMode !== 'instance')); const count = vertexList.length > 0 ? VertexAttribute.getVertexCount(vertexList[0]) : 0; @@ -87,7 +87,7 @@ export class RenderObject static getInstanceCount(geometry: RenderObject) { const attributes = geometry.vertices; - const vertexList = Object.keys(attributes).map((v) => attributes[v]).filter((v) => (v.data && v.stepMode === "instance")); + const vertexList = Object.keys(attributes).map((v) => attributes[v]).filter((v) => (v.data && v.stepMode === 'instance')); const count = vertexList.length > 0 ? VertexAttribute.getVertexCount(vertexList[0]) : 1; @@ -102,14 +102,14 @@ export class RenderObject static getDraw(geometry: RenderObject): DrawIndexed | DrawVertex { - if (geometry["_draw"]) return geometry["_draw"]; + if (geometry['_draw']) return geometry['_draw']; const instanceCount = RenderObject.getInstanceCount(geometry); if (geometry.indices) { return { - __type__: "DrawIndexed", + __type__: 'DrawIndexed', indexCount: geometry.indices.length, firstIndex: 0, instanceCount, @@ -117,7 +117,7 @@ export class RenderObject } return { - __type__: "DrawVertex", + __type__: 'DrawVertex', vertexCount: RenderObject.getNumVertex(geometry), instanceCount, }; diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index e7632e8..a9ff9b8 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -1,6 +1,6 @@ -import { OcclusionQuery } from "./OcclusionQuery"; -import { RenderObject } from "./RenderObject"; -import { RenderPassDescriptor } from "./RenderPassDescriptor"; +import { OcclusionQuery } from './OcclusionQuery'; +import { RenderObject } from './RenderObject'; +import { RenderPassDescriptor } from './RenderPassDescriptor'; /** * WebGL渲染通道 @@ -12,7 +12,7 @@ export interface RenderPass /** * 数据类型。 */ - readonly __type__?: "RenderPass"; + readonly __type__?: 'RenderPass'; /** * 渲染通道描述 diff --git a/src/data/RenderPassColorAttachment.ts b/src/data/RenderPassColorAttachment.ts index e27add2..f56c3fa 100644 --- a/src/data/RenderPassColorAttachment.ts +++ b/src/data/RenderPassColorAttachment.ts @@ -1,4 +1,4 @@ -import { TextureView } from "./TextureView"; +import { TextureView } from './TextureView'; /** * 渲染通道颜色附件。 @@ -59,4 +59,4 @@ export interface RenderPassColorAttachment export type Color = readonly [red: number, green: number, blue: number, alpha: number]; -export type LoadOp = "load" | "clear"; +export type LoadOp = 'load' | 'clear'; diff --git a/src/data/RenderPassDepthStencilAttachment.ts b/src/data/RenderPassDepthStencilAttachment.ts index 3341033..368f3f7 100644 --- a/src/data/RenderPassDepthStencilAttachment.ts +++ b/src/data/RenderPassDepthStencilAttachment.ts @@ -1,4 +1,4 @@ -import { TextureView } from "./TextureView"; +import { TextureView } from './TextureView'; /** * 深度模板附件。 @@ -31,7 +31,7 @@ export interface RenderPassDepthStencilAttachment * * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear */ - readonly depthLoadOp?: "load" | "clear"; + readonly depthLoadOp?: 'load' | 'clear'; /** * 清除后填充模板值。 @@ -49,5 +49,5 @@ export interface RenderPassDepthStencilAttachment * * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear */ - readonly stencilLoadOp?: "load" | "clear"; + readonly stencilLoadOp?: 'load' | 'clear'; } \ No newline at end of file diff --git a/src/data/RenderPassDescriptor.ts b/src/data/RenderPassDescriptor.ts index 3f44a05..d76d69d 100644 --- a/src/data/RenderPassDescriptor.ts +++ b/src/data/RenderPassDescriptor.ts @@ -1,5 +1,5 @@ -import { RenderPassColorAttachment } from "./RenderPassColorAttachment"; -import { RenderPassDepthStencilAttachment } from "./RenderPassDepthStencilAttachment"; +import { RenderPassColorAttachment } from './RenderPassColorAttachment'; +import { RenderPassDepthStencilAttachment } from './RenderPassDepthStencilAttachment'; /** * 渲染通道描述 diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index 9fa17b4..aaca08b 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -1,7 +1,7 @@ -import { DepthStencilState } from "./DepthStencilState"; -import { FragmentState } from "./FragmentState"; -import { PrimitiveState } from "./PrimitiveState"; -import { VertexState } from "./VertexState"; +import { DepthStencilState } from './DepthStencilState'; +import { FragmentState } from './FragmentState'; +import { PrimitiveState } from './PrimitiveState'; +import { VertexState } from './VertexState'; /** * 渲染管线。 diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index a29f06d..6b50b77 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -1,4 +1,4 @@ -import { CompareFunction } from "./StencilFaceState"; +import { CompareFunction } from './StencilFaceState'; /** * 纹理采样器。 @@ -123,14 +123,14 @@ export interface Sampler /** * 纹理坐标寻址模式。 */ -export type IAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat"; +export type IAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat'; /** * 描述采样器在采样足迹与一个纹素不完全匹配时的行为。 */ -export type IFilterMode = "nearest" | "linear"; +export type IFilterMode = 'nearest' | 'linear'; /** * 描述采样器在采样足迹与mipmap层级不完全匹配时的行为。 */ -export type IMipmapFilterMode = "nearest" | "linear"; +export type IMipmapFilterMode = 'nearest' | 'linear'; diff --git a/src/data/StencilFaceState.ts b/src/data/StencilFaceState.ts index fa45bfd..e12d0f4 100644 --- a/src/data/StencilFaceState.ts +++ b/src/data/StencilFaceState.ts @@ -34,6 +34,6 @@ export interface StencilFaceState readonly passOp?: StencilOperation; } -export type CompareFunction = "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always"; +export type CompareFunction = 'never' | 'less' | 'equal' | 'less-equal' | 'greater' | 'not-equal' | 'greater-equal' | 'always'; -export type StencilOperation = "keep" | "zero" | "replace" | "invert" | "increment-clamp" | "decrement-clamp" | "increment-wrap" | "decrement-wrap"; \ No newline at end of file +export type StencilOperation = 'keep' | 'zero' | 'replace' | 'invert' | 'increment-clamp' | 'decrement-clamp' | 'increment-wrap' | 'decrement-wrap'; \ No newline at end of file diff --git a/src/data/Submit.ts b/src/data/Submit.ts index 20628a1..936dc75 100644 --- a/src/data/Submit.ts +++ b/src/data/Submit.ts @@ -1,4 +1,4 @@ -import { CommandEncoder } from "./CommandEncoder"; +import { CommandEncoder } from './CommandEncoder'; /** * 一次 GPU 提交。 diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 78f6bf4..3ac4ca7 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -1,5 +1,5 @@ -import { TextureDataSource } from "./TextureDataSource"; -import { TextureImageSource } from "./TextureImageSource"; +import { TextureDataSource } from './TextureDataSource'; +import { TextureImageSource } from './TextureImageSource'; /** * 类似纹理,包含画布纹理以及正常纹理。 @@ -96,7 +96,7 @@ export class Texture * * @param format 纹理格式。 */ - static getTextureBytesPerPixel(format: TextureFormat = "rgba8unorm") + static getTextureBytesPerPixel(format: TextureFormat = 'rgba8unorm') { const bytesPerPixel = formatMap[format]?.bytesPerPixel; @@ -111,7 +111,7 @@ export class Texture * @param format 纹理格式。 * @returns */ - static getTextureDataConstructor(format: TextureFormat = "rgba8unorm") + static getTextureDataConstructor(format: TextureFormat = 'rgba8unorm') { const bytesPerPixel = formatMap[format]?.dataConstructor; @@ -189,108 +189,108 @@ export type TextureOrigin = readonly [x: number, y: number, depthOrArrayLayers?: /** * 纹理规格维度。 */ -export type TextureDimension = "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d"; +export type TextureDimension = '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d'; /** * 参考 GPUTextureFormat */ export type TextureFormat = - | "r8unorm" - | "r8snorm" - | "r8uint" - | "r8sint" - | "r16uint" - | "r16sint" - | "r16float" - | "rg8unorm" - | "rg8snorm" - | "rg8uint" - | "rg8sint" - | "r32uint" - | "r32sint" - | "r32float" - | "rg16uint" - | "rg16sint" - | "rg16float" - | "rgba8unorm" - | "rgba8unorm-srgb" - | "rgba8snorm" - | "rgba8uint" - | "rgba8sint" - | "bgra8unorm" - | "bgra8unorm-srgb" - | "rgb9e5ufloat" - | "rgb10a2uint" - | "rgb10a2unorm" - | "rg11b10ufloat" - | "rg32uint" - | "rg32sint" - | "rg32float" - | "rgba16uint" - | "rgba16sint" - | "rgba16float" - | "rgba32uint" - | "rgba32sint" - | "rgba32float" - | "stencil8" - | "depth16unorm" - | "depth24plus" - | "depth24plus-stencil8" - | "depth32float" - | "depth32float-stencil8" - | "bc1-rgba-unorm" - | "bc1-rgba-unorm-srgb" - | "bc2-rgba-unorm" - | "bc2-rgba-unorm-srgb" - | "bc3-rgba-unorm" - | "bc3-rgba-unorm-srgb" - | "bc4-r-unorm" - | "bc4-r-snorm" - | "bc5-rg-unorm" - | "bc5-rg-snorm" - | "bc6h-rgb-ufloat" - | "bc6h-rgb-float" - | "bc7-rgba-unorm" - | "bc7-rgba-unorm-srgb" - | "etc2-rgb8unorm" - | "etc2-rgb8unorm-srgb" - | "etc2-rgb8a1unorm" - | "etc2-rgb8a1unorm-srgb" - | "etc2-rgba8unorm" - | "etc2-rgba8unorm-srgb" - | "eac-r11unorm" - | "eac-r11snorm" - | "eac-rg11unorm" - | "eac-rg11snorm" - | "astc-4x4-unorm" - | "astc-4x4-unorm-srgb" - | "astc-5x4-unorm" - | "astc-5x4-unorm-srgb" - | "astc-5x5-unorm" - | "astc-5x5-unorm-srgb" - | "astc-6x5-unorm" - | "astc-6x5-unorm-srgb" - | "astc-6x6-unorm" - | "astc-6x6-unorm-srgb" - | "astc-8x5-unorm" - | "astc-8x5-unorm-srgb" - | "astc-8x6-unorm" - | "astc-8x6-unorm-srgb" - | "astc-8x8-unorm" - | "astc-8x8-unorm-srgb" - | "astc-10x5-unorm" - | "astc-10x5-unorm-srgb" - | "astc-10x6-unorm" - | "astc-10x6-unorm-srgb" - | "astc-10x8-unorm" - | "astc-10x8-unorm-srgb" - | "astc-10x10-unorm" - | "astc-10x10-unorm-srgb" - | "astc-12x10-unorm" - | "astc-12x10-unorm-srgb" - | "astc-12x12-unorm" - | "astc-12x12-unorm-srgb"; + | 'r8unorm' + | 'r8snorm' + | 'r8uint' + | 'r8sint' + | 'r16uint' + | 'r16sint' + | 'r16float' + | 'rg8unorm' + | 'rg8snorm' + | 'rg8uint' + | 'rg8sint' + | 'r32uint' + | 'r32sint' + | 'r32float' + | 'rg16uint' + | 'rg16sint' + | 'rg16float' + | 'rgba8unorm' + | 'rgba8unorm-srgb' + | 'rgba8snorm' + | 'rgba8uint' + | 'rgba8sint' + | 'bgra8unorm' + | 'bgra8unorm-srgb' + | 'rgb9e5ufloat' + | 'rgb10a2uint' + | 'rgb10a2unorm' + | 'rg11b10ufloat' + | 'rg32uint' + | 'rg32sint' + | 'rg32float' + | 'rgba16uint' + | 'rgba16sint' + | 'rgba16float' + | 'rgba32uint' + | 'rgba32sint' + | 'rgba32float' + | 'stencil8' + | 'depth16unorm' + | 'depth24plus' + | 'depth24plus-stencil8' + | 'depth32float' + | 'depth32float-stencil8' + | 'bc1-rgba-unorm' + | 'bc1-rgba-unorm-srgb' + | 'bc2-rgba-unorm' + | 'bc2-rgba-unorm-srgb' + | 'bc3-rgba-unorm' + | 'bc3-rgba-unorm-srgb' + | 'bc4-r-unorm' + | 'bc4-r-snorm' + | 'bc5-rg-unorm' + | 'bc5-rg-snorm' + | 'bc6h-rgb-ufloat' + | 'bc6h-rgb-float' + | 'bc7-rgba-unorm' + | 'bc7-rgba-unorm-srgb' + | 'etc2-rgb8unorm' + | 'etc2-rgb8unorm-srgb' + | 'etc2-rgb8a1unorm' + | 'etc2-rgb8a1unorm-srgb' + | 'etc2-rgba8unorm' + | 'etc2-rgba8unorm-srgb' + | 'eac-r11unorm' + | 'eac-r11snorm' + | 'eac-rg11unorm' + | 'eac-rg11snorm' + | 'astc-4x4-unorm' + | 'astc-4x4-unorm-srgb' + | 'astc-5x4-unorm' + | 'astc-5x4-unorm-srgb' + | 'astc-5x5-unorm' + | 'astc-5x5-unorm-srgb' + | 'astc-6x5-unorm' + | 'astc-6x5-unorm-srgb' + | 'astc-6x6-unorm' + | 'astc-6x6-unorm-srgb' + | 'astc-8x5-unorm' + | 'astc-8x5-unorm-srgb' + | 'astc-8x6-unorm' + | 'astc-8x6-unorm-srgb' + | 'astc-8x8-unorm' + | 'astc-8x8-unorm-srgb' + | 'astc-10x5-unorm' + | 'astc-10x5-unorm-srgb' + | 'astc-10x6-unorm' + | 'astc-10x6-unorm-srgb' + | 'astc-10x8-unorm' + | 'astc-10x8-unorm-srgb' + | 'astc-10x10-unorm' + | 'astc-10x10-unorm-srgb' + | 'astc-12x10-unorm' + | 'astc-12x10-unorm-srgb' + | 'astc-12x12-unorm' + | 'astc-12x12-unorm-srgb'; const formatMap: { [key: string]: { @@ -326,12 +326,12 @@ const formatMap: { rg16sint: { bytesPerPixel: 4, dataConstructor: Int16Array }, rg16float: { bytesPerPixel: 4, dataConstructor: Uint16Array }, rgba8unorm: { bytesPerPixel: 4, dataConstructor: Uint8Array }, - "rgba8unorm-srgb": { bytesPerPixel: 4, dataConstructor: Uint8Array }, + 'rgba8unorm-srgb': { bytesPerPixel: 4, dataConstructor: Uint8Array }, rgba8snorm: { bytesPerPixel: 4, dataConstructor: Int8Array }, rgba8uint: { bytesPerPixel: 4, dataConstructor: Uint8Array }, rgba8sint: { bytesPerPixel: 4, dataConstructor: Int8Array }, bgra8unorm: { bytesPerPixel: 4, dataConstructor: Uint8Array }, - "bgra8unorm-srgb": { bytesPerPixel: 4, dataConstructor: Uint8Array }, + 'bgra8unorm-srgb': { bytesPerPixel: 4, dataConstructor: Uint8Array }, rgb9e5ufloat: { bytesPerPixel: 4, dataConstructor: Uint32Array }, rgb10a2uint: { bytesPerPixel: 4, dataConstructor: Uint32Array }, rgb10a2unorm: { bytesPerPixel: 4, dataConstructor: Uint32Array }, @@ -348,59 +348,59 @@ const formatMap: { stencil8: { bytesPerPixel: 1, dataConstructor: Uint8Array }, depth16unorm: { bytesPerPixel: 2, dataConstructor: Uint16Array }, depth24plus: { bytesPerPixel: 3, dataConstructor: Uint8Array }, - "depth24plus-stencil8": { bytesPerPixel: 4 }, + 'depth24plus-stencil8': { bytesPerPixel: 4 }, depth32float: { bytesPerPixel: 4 }, - "depth32float-stencil8": { bytesPerPixel: 5 }, - "bc1-rgba-unorm": undefined, - "bc1-rgba-unorm-srgb": undefined, - "bc2-rgba-unorm": undefined, - "bc2-rgba-unorm-srgb": undefined, - "bc3-rgba-unorm": undefined, - "bc3-rgba-unorm-srgb": undefined, - "bc4-r-unorm": undefined, - "bc4-r-snorm": undefined, - "bc5-rg-unorm": undefined, - "bc5-rg-snorm": undefined, - "bc6h-rgb-ufloat": undefined, - "bc6h-rgb-float": undefined, - "bc7-rgba-unorm": undefined, - "bc7-rgba-unorm-srgb": undefined, - "etc2-rgb8unorm": undefined, - "etc2-rgb8unorm-srgb": undefined, - "etc2-rgb8a1unorm": undefined, - "etc2-rgb8a1unorm-srgb": undefined, - "etc2-rgba8unorm": undefined, - "etc2-rgba8unorm-srgb": undefined, - "eac-r11unorm": undefined, - "eac-r11snorm": undefined, - "eac-rg11unorm": undefined, - "eac-rg11snorm": undefined, - "astc-4x4-unorm": undefined, - "astc-4x4-unorm-srgb": undefined, - "astc-5x4-unorm": undefined, - "astc-5x4-unorm-srgb": undefined, - "astc-5x5-unorm": undefined, - "astc-5x5-unorm-srgb": undefined, - "astc-6x5-unorm": undefined, - "astc-6x5-unorm-srgb": undefined, - "astc-6x6-unorm": undefined, - "astc-6x6-unorm-srgb": undefined, - "astc-8x5-unorm": undefined, - "astc-8x5-unorm-srgb": undefined, - "astc-8x6-unorm": undefined, - "astc-8x6-unorm-srgb": undefined, - "astc-8x8-unorm": undefined, - "astc-8x8-unorm-srgb": undefined, - "astc-10x5-unorm": undefined, - "astc-10x5-unorm-srgb": undefined, - "astc-10x6-unorm": undefined, - "astc-10x6-unorm-srgb": undefined, - "astc-10x8-unorm": undefined, - "astc-10x8-unorm-srgb": undefined, - "astc-10x10-unorm": undefined, - "astc-10x10-unorm-srgb": undefined, - "astc-12x10-unorm": undefined, - "astc-12x10-unorm-srgb": undefined, - "astc-12x12-unorm": undefined, - "astc-12x12-unorm-srgb": undefined, + 'depth32float-stencil8': { bytesPerPixel: 5 }, + 'bc1-rgba-unorm': undefined, + 'bc1-rgba-unorm-srgb': undefined, + 'bc2-rgba-unorm': undefined, + 'bc2-rgba-unorm-srgb': undefined, + 'bc3-rgba-unorm': undefined, + 'bc3-rgba-unorm-srgb': undefined, + 'bc4-r-unorm': undefined, + 'bc4-r-snorm': undefined, + 'bc5-rg-unorm': undefined, + 'bc5-rg-snorm': undefined, + 'bc6h-rgb-ufloat': undefined, + 'bc6h-rgb-float': undefined, + 'bc7-rgba-unorm': undefined, + 'bc7-rgba-unorm-srgb': undefined, + 'etc2-rgb8unorm': undefined, + 'etc2-rgb8unorm-srgb': undefined, + 'etc2-rgb8a1unorm': undefined, + 'etc2-rgb8a1unorm-srgb': undefined, + 'etc2-rgba8unorm': undefined, + 'etc2-rgba8unorm-srgb': undefined, + 'eac-r11unorm': undefined, + 'eac-r11snorm': undefined, + 'eac-rg11unorm': undefined, + 'eac-rg11snorm': undefined, + 'astc-4x4-unorm': undefined, + 'astc-4x4-unorm-srgb': undefined, + 'astc-5x4-unorm': undefined, + 'astc-5x4-unorm-srgb': undefined, + 'astc-5x5-unorm': undefined, + 'astc-5x5-unorm-srgb': undefined, + 'astc-6x5-unorm': undefined, + 'astc-6x5-unorm-srgb': undefined, + 'astc-6x6-unorm': undefined, + 'astc-6x6-unorm-srgb': undefined, + 'astc-8x5-unorm': undefined, + 'astc-8x5-unorm-srgb': undefined, + 'astc-8x6-unorm': undefined, + 'astc-8x6-unorm-srgb': undefined, + 'astc-8x8-unorm': undefined, + 'astc-8x8-unorm-srgb': undefined, + 'astc-10x5-unorm': undefined, + 'astc-10x5-unorm-srgb': undefined, + 'astc-10x6-unorm': undefined, + 'astc-10x6-unorm-srgb': undefined, + 'astc-10x8-unorm': undefined, + 'astc-10x8-unorm-srgb': undefined, + 'astc-10x10-unorm': undefined, + 'astc-10x10-unorm-srgb': undefined, + 'astc-12x10-unorm': undefined, + 'astc-12x10-unorm-srgb': undefined, + 'astc-12x12-unorm': undefined, + 'astc-12x12-unorm-srgb': undefined, }; \ No newline at end of file diff --git a/src/data/TextureDataSource.ts b/src/data/TextureDataSource.ts index 1cf65de..7e1c939 100644 --- a/src/data/TextureDataSource.ts +++ b/src/data/TextureDataSource.ts @@ -1,4 +1,4 @@ -import { TextureDataLayout, DataImageOrigin, TextureOrigin, TextureSize } from "./Texture"; +import { TextureDataLayout, DataImageOrigin, TextureOrigin, TextureSize } from './Texture'; /** * 纹理的数据资源。 @@ -15,7 +15,7 @@ export interface TextureDataSource /** * 数据类型。 */ - readonly __type__: "TextureDataSource"; + readonly __type__: 'TextureDataSource'; /** * 纹理数据。 diff --git a/src/data/TextureImageSource.ts b/src/data/TextureImageSource.ts index f6e3d1f..70fdedc 100644 --- a/src/data/TextureImageSource.ts +++ b/src/data/TextureImageSource.ts @@ -1,4 +1,4 @@ -import { ImageOrigin, ImageSize, TextureOrigin, TextureSize } from "./Texture"; +import { ImageOrigin, ImageSize, TextureOrigin, TextureSize } from './Texture'; /** * 纹理的图片资源。 @@ -17,7 +17,7 @@ export interface TextureImageSource /** * 数据类型。 */ - readonly __type__?: "TextureImageSource"; + readonly __type__?: 'TextureImageSource'; /** * 图片资源。 @@ -74,6 +74,7 @@ export class TextureImageSource { let width: number; let height: number; + if (image instanceof VideoFrame) { width = image.codedWidth; diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index da6fd2c..fbc0971 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -1,4 +1,4 @@ -import { TextureLike } from "./Texture"; +import { TextureLike } from './Texture'; /** * 纹理视图。 diff --git a/src/data/VertexAttributes.ts b/src/data/VertexAttributes.ts index e5c99f4..b3a29e3 100644 --- a/src/data/VertexAttributes.ts +++ b/src/data/VertexAttributes.ts @@ -1,4 +1,4 @@ -import { vertexFormatMap } from "../consts/vertexFormatMap"; +import { vertexFormatMap } from '../consts/vertexFormatMap'; /** * 顶点属性数据映射。 @@ -81,7 +81,7 @@ export class VertexAttribute } } -export type VertexStepMode = "vertex" | "instance"; +export type VertexStepMode = 'vertex' | 'instance'; export type VertexDataTypes = | Float32Array | Uint32Array @@ -96,34 +96,34 @@ export type VertexDataTypes = | Float32Array * 顶点数据格式。 */ export type VertexFormat = - | "uint8x2" - | "uint8x4" - | "sint8x2" - | "sint8x4" - | "unorm8x2" - | "unorm8x4" - | "snorm8x2" - | "snorm8x4" - | "uint16x2" - | "uint16x4" - | "sint16x2" - | "sint16x4" - | "unorm16x2" - | "unorm16x4" - | "snorm16x2" - | "snorm16x4" - | "float16x2" - | "float16x4" - | "float32" - | "float32x2" - | "float32x3" - | "float32x4" - | "uint32" - | "uint32x2" - | "uint32x3" - | "uint32x4" - | "sint32" - | "sint32x2" - | "sint32x3" - | "sint32x4" - | "unorm10-10-10-2"; \ No newline at end of file + | 'uint8x2' + | 'uint8x4' + | 'sint8x2' + | 'sint8x4' + | 'unorm8x2' + | 'unorm8x4' + | 'snorm8x2' + | 'snorm8x4' + | 'uint16x2' + | 'uint16x4' + | 'sint16x2' + | 'sint16x4' + | 'unorm16x2' + | 'unorm16x4' + | 'snorm16x2' + | 'snorm16x4' + | 'float16x2' + | 'float16x4' + | 'float32' + | 'float32x2' + | 'float32x3' + | 'float32x4' + | 'uint32' + | 'uint32x2' + | 'uint32x3' + | 'uint32x4' + | 'sint32' + | 'sint32x2' + | 'sint32x3' + | 'sint32x4' + | 'unorm10-10-10-2'; \ No newline at end of file diff --git a/src/data/WriteBuffer.ts b/src/data/WriteBuffer.ts index 98bdb5d..dfc4b70 100644 --- a/src/data/WriteBuffer.ts +++ b/src/data/WriteBuffer.ts @@ -1,4 +1,4 @@ -import { TypedArray } from "../types/TypedArray"; +import { TypedArray } from '../types/TypedArray'; export interface WriteBuffer { diff --git a/src/index.ts b/src/index.ts index 74cc531..42c2440 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,48 +1,48 @@ -export * from "./consts/vertexFormatMap"; +export * from './consts/vertexFormatMap'; -export * from "./data/BindingResources"; -export * from "./data/BlendComponent"; -export * from "./data/BlendState"; -export * from "./data/Buffer"; -export * from "./data/BufferBinding"; -export * from "./data/CanvasContext"; -export * from "./data/CanvasTexture"; -export * from "./data/ColorTargetState"; -export * from "./data/CommandEncoder"; -export * from "./data/CopyBufferToBuffer"; -export * from "./data/CopyTextureToTexture"; -export * from "./data/DepthStencilState"; -export * from "./data/DrawIndexed"; -export * from "./data/DrawVertex"; -export * from "./data/FragmentState"; -export * from "./data/ImageCopyTexture"; -export * from "./data/OcclusionQuery"; -export * from "./data/PrimitiveState"; -export * from "./data/ReadPixels"; -export * from "./data/RenderObject"; -export * from "./data/RenderPass"; -export * from "./data/RenderPassColorAttachment"; -export * from "./data/RenderPassDepthStencilAttachment"; -export * from "./data/RenderPassDescriptor"; -export * from "./data/RenderPipeline"; -export * from "./data/Sampler"; -export * from "./data/ScissorRect"; -export * from "./data/StencilFaceState"; -export * from "./data/Submit"; -export * from "./data/Texture"; -export * from "./data/TextureDataSource"; -export * from "./data/TextureImageSource"; -export * from "./data/TextureView"; -export * from "./data/VertexAttributes"; -export * from "./data/VertexState"; -export * from "./data/Viewport"; -export * from "./data/WriteBuffer"; +export * from './data/BindingResources'; +export * from './data/BlendComponent'; +export * from './data/BlendState'; +export * from './data/Buffer'; +export * from './data/BufferBinding'; +export * from './data/CanvasContext'; +export * from './data/CanvasTexture'; +export * from './data/ColorTargetState'; +export * from './data/CommandEncoder'; +export * from './data/CopyBufferToBuffer'; +export * from './data/CopyTextureToTexture'; +export * from './data/DepthStencilState'; +export * from './data/DrawIndexed'; +export * from './data/DrawVertex'; +export * from './data/FragmentState'; +export * from './data/ImageCopyTexture'; +export * from './data/OcclusionQuery'; +export * from './data/PrimitiveState'; +export * from './data/ReadPixels'; +export * from './data/RenderObject'; +export * from './data/RenderPass'; +export * from './data/RenderPassColorAttachment'; +export * from './data/RenderPassDepthStencilAttachment'; +export * from './data/RenderPassDescriptor'; +export * from './data/RenderPipeline'; +export * from './data/Sampler'; +export * from './data/ScissorRect'; +export * from './data/StencilFaceState'; +export * from './data/Submit'; +export * from './data/Texture'; +export * from './data/TextureDataSource'; +export * from './data/TextureImageSource'; +export * from './data/TextureView'; +export * from './data/VertexAttributes'; +export * from './data/VertexState'; +export * from './data/Viewport'; +export * from './data/WriteBuffer'; -export * from "./internal/BufferBindingInfo"; +export * from './internal/BufferBindingInfo'; -export * from "./types/TypedArray"; -export * from "./types/UnReadonly"; +export * from './types/TypedArray'; +export * from './types/UnReadonly'; -export * from "./utils/ChainMap"; +export * from './utils/ChainMap'; -import "./global"; \ No newline at end of file +import './global'; \ No newline at end of file diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 56bdf3b..14e9173 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -94,6 +94,7 @@ export class ChainMap, V> key = wrapKey(keys[keysLength - 1]); const result = map.delete(key); + if (result) this._数量--; return result; @@ -108,7 +109,7 @@ let idCounter = 0; // 包装函数,将非对象值包装成对象 function wrapKey(key: any) { - if (typeof key === "object" && key !== null) + if (typeof key === 'object' && key !== null) { // 如果 key 已经是对象,则直接返回 return key; @@ -123,8 +124,9 @@ function wrapKey(key: any) // 创建一个包装对象 const wrapper = { __id: id, - __value: key + __value: key, }; + // 存储原始值和包装对象的映射 keyMap.set(key, wrapper); diff --git a/test/index.spec.ts b/test/index.spec.ts index 9dcf08b..00252bf 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,9 +1,9 @@ -import { TextureImageSource } from "@feng3d/render-api"; -import { assert, describe, it } from "vitest"; +import { TextureImageSource } from '@feng3d/render-api'; +import { assert, describe, it } from 'vitest'; -describe("test", () => +describe('test', () => { - it("test", () => + it('test', () => { assert.equal(true, true); }); diff --git a/vite.config.js b/vite.config.js index f056904..d06a7e0 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,10 +1,10 @@ // @see https://cn.vitejs.dev/guide/build.html#library-mode -import { resolve } from "path"; -import { defineConfig } from "vite"; -import pkg from "./package.json"; +import { resolve } from 'path'; +import { defineConfig } from 'vite'; +import pkg from './package.json'; -const namespace = "feng3d"; +const namespace = 'feng3d'; const external = pkg.standalone ? [] : Object.keys(pkg.dependencies || []); const globals = () => namespace; @@ -12,10 +12,10 @@ export default defineConfig({ build: { lib: { // Could also be a dictionary or array of multiple entry points - entry: resolve(__dirname, "src/index.ts"), + entry: resolve(__dirname, 'src/index.ts'), name: namespace, // the proper extensions will be added - fileName: "index", + fileName: 'index', }, minify: false, sourcemap: true, @@ -30,20 +30,20 @@ export default defineConfig({ }, plugins: [ shaderToString(), - ] + ], }); function shaderToString() { return { - name: "vite-plugin-string", + name: 'vite-plugin-string', async transform(source, id) { - if (!["glsl", "wgsl", "vert", "frag", "vs", "fs"].includes(id.split(".").pop())) return; + if (!['glsl', 'wgsl', 'vert', 'frag', 'vs', 'fs'].includes(id.split('.').pop())) return; const esm = `export default \`${source}\`;`; - return { code: esm, map: { mappings: "" } }; + return { code: esm, map: { mappings: '' } }; }, }; } From 2bd312e50fd8b70a27d849e573685382b5381a25 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 19 May 2025 22:21:18 +0800 Subject: [PATCH 07/73] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20GitHub=20Actions=20?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E9=85=8D=E7=BD=AE=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E4=B8=BA=20Master=20Branch=20CI=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Node.js=20=E7=89=88=E6=9C=AC=E4=B8=BA=2020?= =?UTF-8?q?.x=EF=BC=8C=E5=8D=87=E7=BA=A7=20checkout=20=E5=92=8C=20setup-no?= =?UTF-8?q?de=20=E7=9A=84=E7=89=88=E6=9C=AC=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=96=B9=E5=BC=8F=E4=BB=A5=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=9A=84=20GitHub=20Actions=20=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/master.yml | 22 ++++++++-------------- .github/workflows/pull-request.yml | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index b1f3913..746cb82 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -1,26 +1,20 @@ -name: Node.js CI +name: Master Branch CI on: push: branches: [ master ] - pull_request: - branches: [ master ] jobs: - test: + deploy: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x] - steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} + node-version: '20.x' - name: Install dependencies run: npm install @@ -46,9 +40,9 @@ jobs: CURRENT_VERSION=$(node -p "require('./package.json').version") PUBLISHED_VERSION=$(npm view . version 2>/dev/null || echo "0.0.0") if [ "$CURRENT_VERSION" != "$PUBLISHED_VERSION" ]; then - echo "::set-output name=publish::true" + echo "publish=true" >> $GITHUB_OUTPUT else - echo "::set-output name=publish::false" + echo "publish=false" >> $GITHUB_OUTPUT fi - name: Publish to npm diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..bbeceb7 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,26 @@ +name: Pull Request CI + +on: + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: Install dependencies + run: npm install + + - name: Run unit tests + run: npm test + + - name: Build project + run: npm run build \ No newline at end of file From 8a62b2494e77e50c6cd9b0dca43ed89c8e852654 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 27 May 2025 21:13:37 +0800 Subject: [PATCH 08/73] =?UTF-8?q?=E5=88=A0=E9=99=A4=20UnReadonly=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=8F=8A=E5=85=B6=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 1 - src/types/UnReadonly.ts | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 src/types/UnReadonly.ts diff --git a/src/index.ts b/src/index.ts index 42c2440..68a0c2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,6 @@ export * from './data/WriteBuffer'; export * from './internal/BufferBindingInfo'; export * from './types/TypedArray'; -export * from './types/UnReadonly'; export * from './utils/ChainMap'; diff --git a/src/types/UnReadonly.ts b/src/types/UnReadonly.ts deleted file mode 100644 index ad8f1b1..0000000 --- a/src/types/UnReadonly.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 移除对象属性中的 readonly 关键字。 - */ -export type UnReadonly = { - -readonly [P in keyof T]: T[P]; -}; From 9c129fb1ef075930e1279f2c2292e4a5bee5ec6a Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 2 Jul 2025 21:41:42 +0800 Subject: [PATCH 09/73] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=93=BE=E6=8E=A5=E4=BB=8EGitHub=E5=88=B0Gitee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改package.json和typedoc.json中的仓库URL,将GitHub链接替换为Gitee链接 --- package.json | 2 +- typedoc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aefe82f..5a33fec 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/feng3d-labs/render-api.git" + "url": "https://gitee.com/feng3d/render-api.git" }, "publishConfig": { "access": "public" diff --git a/typedoc.json b/typedoc.json index e88a1a8..c40445a 100644 --- a/typedoc.json +++ b/typedoc.json @@ -4,6 +4,6 @@ "entryPoints": [ "src/index.ts" ], - "sourceLinkTemplate": "https://github.com/feng3d-labs/render-api/tree/master/{path}#L{line}", + "sourceLinkTemplate": "https://gitee.com/feng3d/render-api/tree/master/{path}#L{line}", "out": "public" } \ No newline at end of file From 2008d80f9073aa8bd298bd5a3cde368e6b1f99cb Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 4 Jul 2025 08:10:44 +0800 Subject: [PATCH 10/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Ble?= =?UTF-8?q?ndComponent=20=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 IBlendOperation 和 IBlendFactor 类型重命名为 BlendOperation 和 BlendFactor,以提高一致性和可读性。 --- src/data/BlendComponent.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data/BlendComponent.ts b/src/data/BlendComponent.ts index ee496ec..8cabe59 100644 --- a/src/data/BlendComponent.ts +++ b/src/data/BlendComponent.ts @@ -21,7 +21,7 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation */ - readonly operation?: IBlendOperation; + readonly operation?: BlendOperation; /** * 源混合因子。 @@ -30,7 +30,7 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ - readonly srcFactor?: IBlendFactor; + readonly srcFactor?: BlendFactor; /** * 目标混合因子。 @@ -39,15 +39,15 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ - readonly dstFactor?: IBlendFactor; + readonly dstFactor?: BlendFactor; } -export type IBlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max'; +export type BlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max'; /** * @see https://gpuweb.github.io/gpuweb/#enumdef-gpublendfactor */ -export type IBlendFactor = IBlendFactorMap[keyof IBlendFactorMap]; +export type BlendFactor = IBlendFactorMap[keyof IBlendFactorMap]; export interface IBlendFactorMap { From 9d04277ca2e616bb5ab7df89686d60a0581b72d3 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 4 Jul 2025 09:26:38 +0800 Subject: [PATCH 11/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Ima?= =?UTF-8?q?geCopyTexture=20=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 ITextureAspect 类型重命名为 TextureAspect,以提高一致性和可读性。 --- src/data/ImageCopyTexture.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/ImageCopyTexture.ts b/src/data/ImageCopyTexture.ts index 0ff9e7b..fdeb554 100644 --- a/src/data/ImageCopyTexture.ts +++ b/src/data/ImageCopyTexture.ts @@ -27,7 +27,7 @@ export interface ImageCopyTexture /** * Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */ - aspect?: ITextureAspect; + aspect?: TextureAspect; } -export type ITextureAspect = 'all' | 'stencil-only' | 'depth-only'; \ No newline at end of file +export type TextureAspect = 'all' | 'stencil-only' | 'depth-only'; \ No newline at end of file From 6e2258e72d7ba4ecd05ef319ecd3e005138a2577 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 5 Jul 2025 11:42:14 +0800 Subject: [PATCH 12/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Tex?= =?UTF-8?q?ture=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 generateMipmap 属性的注释,简化描述并明确其仅在纹理创建时执行。 --- src/data/Texture.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 3ac4ca7..44c827c 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -54,7 +54,9 @@ export interface Texture readonly sources?: readonly TextureSource[]; /** - * 初始化纹理后是否生成mipmap + * 是否生成mipmap + * + * 仅在纹理创建时执行。 */ readonly generateMipmap?: boolean; From 7048ce102771ef90e254238d2ad330a41fb94797 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 9 Jul 2025 09:18:43 +0800 Subject: [PATCH 13/73] Texture.descriptor --- src/data/Texture.ts | 63 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 44c827c..c9ccfaf 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -20,9 +20,9 @@ export interface TextureLikeMap } /** - * 纹理 + * 纹理描述。 */ -export interface Texture +export interface TextureDescriptor { /** * 标签。 @@ -40,6 +40,41 @@ export interface Texture */ readonly size: TextureSize; + /** + * 纹理维度,默认为 "2d" 。 + * + * WebGL中不支持 "1d" "cube-array"。 + */ + readonly dimension?: TextureDimension; + + /** + * 纹理格式。 默认为 "rgba8unorm", + */ + readonly format?: TextureFormat; + + /** + * The number of mip levels the texture will contain. + */ + readonly mipLevelCount?: number; + + /** + * 是否生成mipmap + * + * 仅在纹理创建时执行。 + */ + readonly generateMipmap?: boolean; +} + +/** + * 纹理 + */ +export interface Texture +{ + /** + * 纹理描述。 + */ + readonly descriptor: TextureDescriptor; + /** * 初始化纹理资源。 * @@ -53,13 +88,6 @@ export interface Texture */ readonly sources?: readonly TextureSource[]; - /** - * 是否生成mipmap - * - * 仅在纹理创建时执行。 - */ - readonly generateMipmap?: boolean; - /** * 写入纹理资源。 * @@ -72,23 +100,6 @@ export interface Texture * @see GPUQueue.writeTexture */ readonly writeTextures?: readonly TextureSource[]; - - /** - * 纹理维度,默认为 "2d" 。 - * - * WebGL中不支持 "1d" "cube-array"。 - */ - readonly dimension?: TextureDimension; - - /** - * 纹理格式。 默认为 "rgba8unorm", - */ - readonly format?: TextureFormat; - - /** - * The number of mip levels the texture will contain. - */ - readonly mipLevelCount?: number; } export class Texture From 7c4980d83dd7ae0135e0721b77f2870f49b2971d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 9 Jul 2025 23:43:34 +0800 Subject: [PATCH 14/73] TextureDescriptor.sampleCount --- src/data/Texture.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index c9ccfaf..6998b15 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -63,6 +63,14 @@ export interface TextureDescriptor * 仅在纹理创建时执行。 */ readonly generateMipmap?: boolean; + + /** + * The sample count of the texture. A {@link GPUTextureDescriptor#sampleCount} > `1` indicates + * a multisampled texture. + * + * WebGPU只支持4重采样。 + */ + readonly sampleCount?: 4; } /** From fcb9a42dfb25bde1bff5c722909464519bb6efc3 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 29 Jul 2025 23:44:26 +0800 Subject: [PATCH 15/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Can?= =?UTF-8?q?vasContext=20=E5=92=8C=20CanvasTexture=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CanvasContext 中添加可选的宽度和高度属性。 - 从 CanvasTexture 中移除不再使用的 _canvasSizeVersion 属性。 --- src/data/CanvasContext.ts | 10 ++++++++++ src/data/CanvasTexture.ts | 9 --------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index b4d47d3..974a950 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -9,4 +9,14 @@ export interface CanvasContext * 可能是画布的编号,也可能是画布元素或者离屏画布。 */ readonly canvasId: string | HTMLCanvasElement | OffscreenCanvas; + + /** + * 画布宽度。 + */ + readonly width?: number; + + /** + * 画布高度。 + */ + readonly height?: number; } diff --git a/src/data/CanvasTexture.ts b/src/data/CanvasTexture.ts index 7ebcde5..b2b5753 100644 --- a/src/data/CanvasTexture.ts +++ b/src/data/CanvasTexture.ts @@ -9,13 +9,4 @@ export interface CanvasTexture * 画布上下文。 */ context: CanvasContext; - - /** - * 画布尺寸发生变化后引擎自动递增。 - * - * 引擎内部监听这个值,在画布尺寸发生变化后重新获取纹理。 - * - * @private - */ - _canvasSizeVersion?: number; } From 5de0b02b9ffe756e061842a1f72b2800e72e6180 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 4 Sep 2025 00:20:41 +0800 Subject: [PATCH 16/73] @feng3d/render-api@0.0.6 --- package.json | 5 ++- src/consts/vertexFormatMap.ts | 65 +++++++++++++++++----------------- src/data/CanvasContext.ts | 2 +- src/data/Geometry.ts | 7 ++-- src/data/PrimitiveState.ts | 2 +- src/data/RenderPipeline.ts | 2 +- src/data/ScissorRect.ts | 2 +- src/data/StencilFaceState.ts | 2 +- src/data/Submit.ts | 2 +- src/data/Texture.ts | 6 ++-- src/data/TextureImageSource.ts | 2 +- src/data/VertexAttributes.ts | 6 ++-- src/data/Viewport.ts | 1 - 13 files changed, 50 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index d871a44..df76e41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@feng3d/render-api", - "version": "0.0.2", + "version": "0.0.6", "description": "渲染接口", "author": "feng", "license": "MIT", @@ -55,6 +55,5 @@ "vite": "^4.3.9", "vitest": "^0.32.2" }, - "dependencies": { - } + "dependencies": {} } \ No newline at end of file diff --git a/src/consts/vertexFormatMap.ts b/src/consts/vertexFormatMap.ts index 01c7489..4ccfd06 100644 --- a/src/consts/vertexFormatMap.ts +++ b/src/consts/vertexFormatMap.ts @@ -4,38 +4,38 @@ import { VertexFormat } from "../data/VertexAttributes"; * 顶点属性格式信息映射。 */ export const vertexFormatMap: Record = { - "uint8x2": { "numComponents": 2, "type": "UNSIGNED_BYTE", "normalized": false, "dataType": "unsigned int", "byteSize": 2, "wgslType": "vec2", "typedArrayConstructor": Uint8Array }, - "uint8x4": { "numComponents": 4, "type": "UNSIGNED_BYTE", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "vec4", "typedArrayConstructor": Uint8Array }, - "sint8x2": { "numComponents": 2, "type": "BYTE", "normalized": false, "dataType": "signed int", "byteSize": 2, "wgslType": "vec2", "typedArrayConstructor": Int8Array }, - "sint8x4": { "numComponents": 4, "type": "BYTE", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "vec4", "typedArrayConstructor": Int8Array }, - "unorm8x2": { "numComponents": 2, "type": "UNSIGNED_BYTE", "normalized": true, "dataType": "unsigned normalized", "byteSize": 2, "wgslType": "vec2", "typedArrayConstructor": Uint8Array }, - "unorm8x4": { "numComponents": 4, "type": "UNSIGNED_BYTE", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec4", "typedArrayConstructor": Uint8Array }, - "snorm8x2": { "numComponents": 2, "type": "BYTE", "normalized": true, "dataType": "signed normalized", "byteSize": 2, "wgslType": "vec2", "typedArrayConstructor": Int8Array }, - "snorm8x4": { "numComponents": 4, "type": "BYTE", "normalized": true, "dataType": "signed normalized", "byteSize": 4, "wgslType": "vec4", "typedArrayConstructor": Int8Array }, - "uint16x2": { "numComponents": 2, "type": "UNSIGNED_SHORT", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "vec2", "typedArrayConstructor": Uint16Array }, - "uint16x4": { "numComponents": 4, "type": "UNSIGNED_SHORT", "normalized": false, "dataType": "unsigned int", "byteSize": 8, "wgslType": "vec4", "typedArrayConstructor": Uint16Array }, - "sint16x2": { "numComponents": 2, "type": "SHORT", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "vec2", "typedArrayConstructor": Int16Array }, - "sint16x4": { "numComponents": 4, "type": "SHORT", "normalized": false, "dataType": "signed int", "byteSize": 8, "wgslType": "vec4", "typedArrayConstructor": Int16Array }, - "unorm16x2": { "numComponents": 2, "type": "UNSIGNED_SHORT", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec2", "typedArrayConstructor": Uint16Array }, - "unorm16x4": { "numComponents": 4, "type": "UNSIGNED_SHORT", "normalized": true, "dataType": "unsigned normalized", "byteSize": 8, "wgslType": "vec4", "typedArrayConstructor": Uint16Array }, - "snorm16x2": { "numComponents": 2, "type": "SHORT", "normalized": true, "dataType": "signed normalized", "byteSize": 4, "wgslType": "vec2", "typedArrayConstructor": Int16Array }, - "snorm16x4": { "numComponents": 4, "type": "SHORT", "normalized": true, "dataType": "signed normalized", "byteSize": 8, "wgslType": "vec4", "typedArrayConstructor": Int16Array }, - "float16x2": { "numComponents": 2, "type": "HALF_FLOAT", "normalized": false, "dataType": "float", "byteSize": 4, "wgslType": "vec2", "typedArrayConstructor": undefined, }, - "float16x4": { "numComponents": 4, "type": "HALF_FLOAT", "normalized": false, "dataType": "float", "byteSize": 8, "wgslType": "vec4", "typedArrayConstructor": undefined, }, - "float32": { "numComponents": 1, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 4, "wgslType": "f32", "typedArrayConstructor": Float32Array }, - "float32x2": { "numComponents": 2, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 8, "wgslType": "vec2", "typedArrayConstructor": Float32Array }, - "float32x3": { "numComponents": 3, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 12, "wgslType": "vec3", "typedArrayConstructor": Float32Array }, - "float32x4": { "numComponents": 4, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 16, "wgslType": "vec4", "typedArrayConstructor": Float32Array }, - "uint32": { "numComponents": 1, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "u32", "typedArrayConstructor": Uint32Array }, - "uint32x2": { "numComponents": 2, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 8, "wgslType": "vec2", "typedArrayConstructor": Uint32Array }, - "uint32x3": { "numComponents": 3, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 12, "wgslType": "vec3", "typedArrayConstructor": Uint32Array }, - "uint32x4": { "numComponents": 4, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 16, "wgslType": "vec4", "typedArrayConstructor": Uint32Array }, - "sint32": { "numComponents": 1, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "i32", "typedArrayConstructor": Int32Array }, - "sint32x2": { "numComponents": 2, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 8, "wgslType": "vec2", "typedArrayConstructor": Int32Array }, - "sint32x3": { "numComponents": 3, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 12, "wgslType": "vec3", "typedArrayConstructor": Int32Array }, - "sint32x4": { "numComponents": 4, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 16, "wgslType": "vec4", "typedArrayConstructor": Int32Array }, - "unorm10-10-10-2": { "numComponents": 4, "type": "UNSIGNED_INT_2_10_10_10_REV", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec4", "typedArrayConstructor": Int32Array } -} + uint8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Uint8Array }, + uint8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Uint8Array }, + sint8x2: { numComponents: 2, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Int8Array }, + sint8x4: { numComponents: 4, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int8Array }, + unorm8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Uint8Array }, + unorm8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Uint8Array }, + snorm8x2: { numComponents: 2, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 2, wgslType: "vec2", typedArrayConstructor: Int8Array }, + snorm8x4: { numComponents: 4, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int8Array }, + uint16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Uint16Array }, + uint16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Uint16Array }, + sint16x2: { numComponents: 2, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Int16Array }, + sint16x4: { numComponents: 4, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Int16Array }, + unorm16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Uint16Array }, + unorm16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Uint16Array }, + snorm16x2: { numComponents: 2, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec2", typedArrayConstructor: Int16Array }, + snorm16x4: { numComponents: 4, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 8, wgslType: "vec4", typedArrayConstructor: Int16Array }, + float16x2: { numComponents: 2, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "vec2", typedArrayConstructor: undefined }, + float16x4: { numComponents: 4, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec4", typedArrayConstructor: undefined }, + float32: { numComponents: 1, type: "FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "f32", typedArrayConstructor: Float32Array }, + float32x2: { numComponents: 2, type: "FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Float32Array }, + float32x3: { numComponents: 3, type: "FLOAT", normalized: false, dataType: "float", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Float32Array }, + float32x4: { numComponents: 4, type: "FLOAT", normalized: false, dataType: "float", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Float32Array }, + uint32: { numComponents: 1, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "u32", typedArrayConstructor: Uint32Array }, + uint32x2: { numComponents: 2, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Uint32Array }, + uint32x3: { numComponents: 3, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Uint32Array }, + uint32x4: { numComponents: 4, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Uint32Array }, + sint32: { numComponents: 1, type: "INT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "i32", typedArrayConstructor: Int32Array }, + sint32x2: { numComponents: 2, type: "INT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec2", typedArrayConstructor: Int32Array }, + sint32x3: { numComponents: 3, type: "INT", normalized: false, dataType: "signed int", byteSize: 12, wgslType: "vec3", typedArrayConstructor: Int32Array }, + sint32x4: { numComponents: 4, type: "INT", normalized: false, dataType: "signed int", byteSize: 16, wgslType: "vec4", typedArrayConstructor: Int32Array }, + "unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4", typedArrayConstructor: Int32Array } +}; /** * 有类型数组构造器。 @@ -97,7 +97,6 @@ export type WGSLVertexType = export type GLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1 | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2 - /** * 顶点属性格式信息 */ diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index 486eb08..daf9910 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -1,7 +1,7 @@ /** * 画布上下文 */ -export interface CanvasContext +export interface CanvasContext { __type__?: "CanvasContext"; diff --git a/src/data/Geometry.ts b/src/data/Geometry.ts index a4d905c..6e82cdf 100644 --- a/src/data/Geometry.ts +++ b/src/data/Geometry.ts @@ -5,7 +5,7 @@ import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; /** * 几何数据。 - * + * * 包含以下数据: * - 顶点属性数据 * - 顶点索引数据 @@ -41,11 +41,10 @@ export interface Geometry export class Geometry { - /** * 获取顶点数量。 * - * @returns 顶点数量。 + * @returns 顶点数量。 */ static getNumVertex(geometry: Geometry) { @@ -86,7 +85,7 @@ export class Geometry static getDraw(geometry: Geometry): DrawIndexed | DrawVertex { - if (geometry['_draw']) return geometry['_draw']; + if (geometry["_draw"]) return geometry["_draw"]; const instanceCount = Geometry.getInstanceCount(geometry); diff --git a/src/data/PrimitiveState.ts b/src/data/PrimitiveState.ts index 19ee77a..edcd0ce 100644 --- a/src/data/PrimitiveState.ts +++ b/src/data/PrimitiveState.ts @@ -19,7 +19,7 @@ export interface PrimitiveState * * `triangle-strip` 绘制三角形条带。 * * 默认 `triangle-list` ,默认每三个顶点绘制一个三角形。 - * + * * 图形拓扑结构。 * * 以下仅在WebGL生效 diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index 188054c..448d83e 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -4,7 +4,7 @@ import { VertexState } from "./VertexState"; /** * 渲染管线。 - * + * * 对应WebGPU的Pipeline。 */ export interface RenderPipeline diff --git a/src/data/ScissorRect.ts b/src/data/ScissorRect.ts index 5ddc496..7ac5157 100644 --- a/src/data/ScissorRect.ts +++ b/src/data/ScissorRect.ts @@ -18,7 +18,7 @@ export interface ScissorRect { __type__?: "ScissorRect"; - + /** * 是否为Y轴朝上。 * diff --git a/src/data/StencilFaceState.ts b/src/data/StencilFaceState.ts index 9706ee5..defeef3 100644 --- a/src/data/StencilFaceState.ts +++ b/src/data/StencilFaceState.ts @@ -3,7 +3,7 @@ * * @see https://www.orillusion.com/zh/webgpu.html#dictdef-gpustencilfacestate */ -export interface StencilFaceState +export interface StencilFaceState { __type__?: "StencilFaceState"; diff --git a/src/data/Submit.ts b/src/data/Submit.ts index ba3390f..fba33cb 100644 --- a/src/data/Submit.ts +++ b/src/data/Submit.ts @@ -5,7 +5,7 @@ import { CommandEncoder } from "./CommandEncoder"; * * @see https://developer.mozilla.org/en-US/docs/Web/API/GPUQueue/submit */ -export interface Submit +export interface Submit { __type__?: "Submit"; diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 010615e..c08d571 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -4,7 +4,7 @@ import { TextureImageSource } from "./TextureImageSource"; /** * 纹理 */ -export interface Texture +export interface Texture { __type__?: "Texture"; @@ -91,9 +91,9 @@ export class Texture /** * 获取纹理数据构造函数。 - + * @param format 纹理格式。 - * @returns + * @returns */ static getTextureDataConstructor(format: TextureFormat = "rgba8unorm") { diff --git a/src/data/TextureImageSource.ts b/src/data/TextureImageSource.ts index dc9a823..f6e3d1f 100644 --- a/src/data/TextureImageSource.ts +++ b/src/data/TextureImageSource.ts @@ -12,7 +12,7 @@ import { ImageOrigin, ImageSize, TextureOrigin, TextureSize } from "./Texture"; * * @see GPUQueue.copyExternalImageToTexture */ -export interface TextureImageSource +export interface TextureImageSource { /** * 数据类型。 diff --git a/src/data/VertexAttributes.ts b/src/data/VertexAttributes.ts index e2e44cd..cbf53ec 100644 --- a/src/data/VertexAttributes.ts +++ b/src/data/VertexAttributes.ts @@ -52,10 +52,10 @@ export interface VertexAttribute export class VertexAttribute { /** - * 获取顶点属性数据的顶点数量。 - * + * 获取顶点属性数据的顶点数量。 + * * @param attribute 顶点属性数据。 - * @returns + * @returns */ static getVertexCount(attribute: VertexAttribute) { diff --git a/src/data/Viewport.ts b/src/data/Viewport.ts index a149698..f7e6031 100644 --- a/src/data/Viewport.ts +++ b/src/data/Viewport.ts @@ -1,4 +1,3 @@ - /** * 视窗。 * From d46d4eb7d80bf2a0ff6a80b6883a90d35bc80109 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 5 Sep 2025 22:07:31 +0800 Subject: [PATCH 17/73] =?UTF-8?q?refactor(data):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8DUniforms=E4=B8=BABindingResources=E4=BB=A5=E6=9B=B4?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E6=8F=8F=E8=BF=B0=E7=94=A8=E9=80=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将Uniforms接口重命名为BindingResources,使其更准确地反映其作为着色器绑定资源的通用性,而不仅限于uniform变量。同时更新了相关引用和导出。 --- src/data/BindingResources.ts | 25 +++++++++++++++++++++++++ src/data/RenderObject.ts | 4 ++-- src/data/Uniforms.ts | 25 ------------------------- src/index.ts | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 src/data/BindingResources.ts delete mode 100644 src/data/Uniforms.ts diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts new file mode 100644 index 0000000..350b964 --- /dev/null +++ b/src/data/BindingResources.ts @@ -0,0 +1,25 @@ +import { BufferBinding, BufferBindingItem } from "./BufferBinding"; + +/** + * 绑定资源。 + * + * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 + */ +export interface BindingResources +{ + readonly [key: string]: BindingResource; +} + +/** + * 绑定资源 类型 + */ +export type BindingResource = BindingResourceTypeMap[keyof BindingResourceTypeMap]; + +export interface BindingResourceTypeMap +{ + /** + * 缓冲区绑定。 + */ + BufferBinding: BufferBinding; + BufferBindingItem: BufferBindingItem; +} diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 09d2dd3..46a5606 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -1,7 +1,7 @@ import { Geometry } from "./Geometry"; import { RenderPipeline } from "./RenderPipeline"; import { ScissorRect } from "./ScissorRect"; -import { Uniforms } from "./Uniforms"; +import { BindingResources } from "./BindingResources"; import { Viewport } from "./Viewport"; /** @@ -39,7 +39,7 @@ export interface RenderObject /** * Uniform变量数据 */ - uniforms?: Uniforms; + uniforms?: BindingResources; _version?: number; } diff --git a/src/data/Uniforms.ts b/src/data/Uniforms.ts deleted file mode 100644 index 30104f0..0000000 --- a/src/data/Uniforms.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BufferBinding, BufferBindingItem } from "./BufferBinding"; - -/** - * Uniform 数据 - */ -export interface Uniforms -{ - __type__?: any; - - [key: string]: UniformType; -} - -/** - * Uniform 类型 - */ -export type UniformType = UniformTypeMap[keyof UniformTypeMap]; - -export interface UniformTypeMap -{ - /** - * 缓冲区绑定。 - */ - IBufferBinding: BufferBinding; - IBufferBindingItem: BufferBindingItem; -} diff --git a/src/index.ts b/src/index.ts index e2ff293..db3c056 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,7 @@ export * from "./data/Texture"; export * from "./data/TextureDataSource"; export * from "./data/TextureImageSource"; export * from "./data/TextureView"; -export * from "./data/Uniforms"; +export * from "./data/BindingResources"; export * from "./data/VertexAttributes"; export * from "./data/VertexState"; export * from "./data/Viewport"; From 811d92dca93ae633ad30db6209d922f4e1f161b1 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 5 Sep 2025 22:27:34 +0800 Subject: [PATCH 18/73] =?UTF-8?q?refactor(data):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8D=95=E5=BC=95=E5=8F=B7=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除接口中多余的__type__标记 优化BlendState中常量颜色的处理逻辑 统一BufferBindingItem和UniformDataItem的类型定义 --- src/data/BindingResources.ts | 4 ++-- src/data/BlendComponent.ts | 38 +++++++++++++++++------------------- src/data/BlendState.ts | 31 +++++++++++++++++------------ src/data/Buffer.ts | 8 ++++---- src/data/BufferBinding.ts | 10 +++++----- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index 350b964..bc81821 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -1,4 +1,4 @@ -import { BufferBinding, BufferBindingItem } from "./BufferBinding"; +import { BufferBinding, BufferBindingItem } from './BufferBinding'; /** * 绑定资源。 @@ -7,7 +7,7 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; */ export interface BindingResources { - readonly [key: string]: BindingResource; + [key: string]: BindingResource; } /** diff --git a/src/data/BlendComponent.ts b/src/data/BlendComponent.ts index b17a6e5..8cabe59 100644 --- a/src/data/BlendComponent.ts +++ b/src/data/BlendComponent.ts @@ -12,8 +12,6 @@ */ export interface BlendComponent { - __type__?: "BlendComponent"; - /** * 混合方式。 * @@ -23,7 +21,7 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation */ - readonly operation?: IBlendOperation; + readonly operation?: BlendOperation; /** * 源混合因子。 @@ -32,7 +30,7 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ - readonly srcFactor?: IBlendFactor; + readonly srcFactor?: BlendFactor; /** * 目标混合因子。 @@ -41,29 +39,29 @@ export interface BlendComponent * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ - readonly dstFactor?: IBlendFactor; + readonly dstFactor?: BlendFactor; } -export type IBlendOperation = "add" | "subtract" | "reverse-subtract" | "min" | "max"; +export type BlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max'; /** * @see https://gpuweb.github.io/gpuweb/#enumdef-gpublendfactor */ -export type IBlendFactor = IBlendFactorMap[keyof IBlendFactorMap]; +export type BlendFactor = IBlendFactorMap[keyof IBlendFactorMap]; export interface IBlendFactorMap { - "zero": "zero"; - "one": "one"; - "src": "src"; - "one-minus-src": "one-minus-src"; - "src-alpha": "src-alpha"; - "one-minus-src-alpha": "one-minus-src-alpha"; - "dst": "dst"; - "one-minus-dst": "one-minus-dst"; - "dst-alpha": "dst-alpha"; - "one-minus-dst-alpha": "one-minus-dst-alpha"; - "src-alpha-saturated": "src-alpha-saturated"; - "constant": "constant"; - "one-minus-constant": "one-minus-constant"; + 'zero': 'zero'; + 'one': 'one'; + 'src': 'src'; + 'one-minus-src': 'one-minus-src'; + 'src-alpha': 'src-alpha'; + 'one-minus-src-alpha': 'one-minus-src-alpha'; + 'dst': 'dst'; + 'one-minus-dst': 'one-minus-dst'; + 'dst-alpha': 'dst-alpha'; + 'one-minus-dst-alpha': 'one-minus-dst-alpha'; + 'src-alpha-saturated': 'src-alpha-saturated'; + 'constant': 'constant'; + 'one-minus-constant': 'one-minus-constant'; } diff --git a/src/data/BlendState.ts b/src/data/BlendState.ts index 7e131bf..1d98929 100644 --- a/src/data/BlendState.ts +++ b/src/data/BlendState.ts @@ -1,5 +1,5 @@ -import { BlendComponent } from "./BlendComponent"; -import { Color } from "./RenderPassColorAttachment"; +import { BlendComponent } from './BlendComponent'; +import { Color } from './RenderPassColorAttachment'; /** * 混合状态。 @@ -12,8 +12,6 @@ import { Color } from "./RenderPassColorAttachment"; */ export interface BlendState { - __type__?: "BlendState"; - /** * 混合时使用的常量值,默认为 [0,0,0,0]。 * @@ -49,20 +47,27 @@ export class BlendState { if (!blendState) return undefined; - const { color, alpha, constantColor } = blendState; + const { color, alpha } = blendState; // 当混合系数用到了混合常量值时设置混合常量值。 if (0 - || color?.srcFactor === "constant" - || color?.srcFactor === "one-minus-constant" - || color?.dstFactor === "constant" - || color?.dstFactor === "one-minus-constant" - || alpha?.srcFactor === "constant" - || alpha?.srcFactor === "one-minus-constant" - || alpha?.dstFactor === "constant" - || alpha?.dstFactor === "one-minus-constant" + || color?.srcFactor === 'constant' + || color?.srcFactor === 'one-minus-constant' + || color?.dstFactor === 'constant' + || color?.dstFactor === 'one-minus-constant' + || alpha?.srcFactor === 'constant' + || alpha?.srcFactor === 'one-minus-constant' + || alpha?.dstFactor === 'constant' + || alpha?.dstFactor === 'one-minus-constant' ) { + const constantColor = blendState.constantColor; + + if (constantColor) + { + return [constantColor[0], constantColor[1], constantColor[2], constantColor[3]]; + } + return constantColor ?? [0, 0, 0, 0]; } diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 8c601b9..de7689a 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -1,5 +1,5 @@ -import { TypedArray } from "../types/TypedArray"; -import { WriteBuffer } from "./WriteBuffer"; +import { TypedArray } from '../types/TypedArray'; +import { WriteBuffer } from './WriteBuffer'; /** * 缓冲区 @@ -12,8 +12,6 @@ import { WriteBuffer } from "./WriteBuffer"; */ export interface Buffer { - __type__?: "Buffer"; - /** * 标签。 * @@ -25,6 +23,8 @@ export interface Buffer * 缓冲区尺寸,单位为字节。 * * 尺寸必须为4的倍数。 + * + * 注:修改尺寸时,会重新创建缓冲区。 */ readonly size: number; diff --git a/src/data/BufferBinding.ts b/src/data/BufferBinding.ts index e1063e1..c5fdea7 100644 --- a/src/data/BufferBinding.ts +++ b/src/data/BufferBinding.ts @@ -1,4 +1,4 @@ -import { TypedArray } from "../types/TypedArray"; +import { TypedArray } from '../types/TypedArray'; /** * 缓冲区绑定。 @@ -18,8 +18,8 @@ export interface BufferBinding readonly bufferView?: TypedArray; } -export type UniformDataItem = number | number[] | number[][] | TypedArray | TypedArray[] - | { toArray(): number[] | Float32Array } - | { toArray(): number[] | Float32Array }[] +export type UniformDataItem = number | readonly number[] | readonly number[][] | TypedArray | readonly TypedArray[] + | { toArray(): number[] | TypedArray } + | readonly { toArray(): number[] | TypedArray }[] ; -export type BufferBindingItem = UniformDataItem | { [key: string]: BufferBindingItem }; +export type BufferBindingItem = UniformDataItem | { readonly [key: string]: BufferBindingItem }; From f96688f7a6dcd77ab093af152d4e252d120d5e90 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 25 Sep 2025 16:13:39 +0800 Subject: [PATCH 19/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Buf?= =?UTF-8?q?fer=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Buffer 接口中添加关于初始化后无法修改 GPUBuffer 的注释。 - 更新数据属性的注释,明确只能通过 writeBuffers 修改数据。 --- src/data/Buffer.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index c3a6091..dce0e63 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -16,6 +16,8 @@ export interface Buffer * 标签。 * * 用于调试。 + * + * 注:初始化GPUBuffer后将无法修改。 */ readonly label?: string; @@ -24,12 +26,14 @@ export interface Buffer * * 尺寸必须为4的倍数。 * - * 注:修改尺寸时,会重新创建缓冲区。 + * 注:初始化GPUBuffer后将无法修改。 */ readonly size: number; /** * 缓冲区数据。 + * + * 注:初始化GPUBuffer后将无法直接修改数据,只能通过 {@link writeBuffers} 修改。 */ readonly data?: TypedArray; From a4cbcca5f7b0bb0b724925d39ceee6cd6d2fef21 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 25 Sep 2025 16:42:57 +0800 Subject: [PATCH 20/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Buf?= =?UTF-8?q?fer=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改关于 GPUBuffer 的注释,明确修改后将重新创建 GPUBuffer 的说明。 - 更新数据属性的注释,强调初始化后无法直接修改数据。 --- src/data/Buffer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index dce0e63..98be002 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -17,7 +17,7 @@ export interface Buffer * * 用于调试。 * - * 注:初始化GPUBuffer后将无法修改。 + * 注:修改后将重新创建GPUBuffer。 */ readonly label?: string; @@ -26,14 +26,14 @@ export interface Buffer * * 尺寸必须为4的倍数。 * - * 注:初始化GPUBuffer后将无法修改。 + * 注:修改后将重新创建GPUBuffer。 */ readonly size: number; /** * 缓冲区数据。 * - * 注:初始化GPUBuffer后将无法直接修改数据,只能通过 {@link writeBuffers} 修改。 + * 注:修改后将重新创建GPUBuffer。 */ readonly data?: TypedArray; From 27e249dc6df4ffd6c1fe9f5fb4c83069b2fb2a6d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 26 Sep 2025 14:15:06 +0800 Subject: [PATCH 21/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Buf?= =?UTF-8?q?fer=20=E6=8E=A5=E5=8F=A3=E5=92=8C=20tsconfig=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Buffer 接口中的 data 属性类型从 TypedArray 修改为 ArrayBuffer。 - 添加 Buffer 类的静态方法 fromArrayBuffer,用于从 ArrayBuffer 创建缓冲区配置并处理大小对齐。 - 更新 tsconfig.json,添加 skipLibCheck、esModuleInterop 和 downlevelIteration 配置,并修改 lib 版本为 ES2015、ES2017 和 ES2020。 --- src/data/Buffer.ts | 32 ++++++++++++++++++++++++++++++-- tsconfig.json | 7 ++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 98be002..a5f3078 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -1,4 +1,3 @@ -import { TypedArray } from '../types/TypedArray'; import { WriteBuffer } from './WriteBuffer'; /** @@ -35,7 +34,7 @@ export interface Buffer * * 注:修改后将重新创建GPUBuffer。 */ - readonly data?: TypedArray; + readonly data?: ArrayBuffer; /** * 写缓冲区。 @@ -44,3 +43,32 @@ export interface Buffer */ readonly writeBuffers?: WriteBuffer[]; } + +export class Buffer +{ + /** + * 从TypedArray创建或获取缓冲区配置 + * 自动处理缓冲区大小对齐(4字节对齐) + * @param arrayBuffer 源数据数组 + * @returns 缓冲区配置对象 + */ + static fromArrayBuffer(arrayBuffer: ArrayBuffer) + { + // 检查是否已存在对应的缓冲区配置 + let buffer = this.bufferMap.get(arrayBuffer); + + if (buffer) return buffer; + + // 创建新的缓冲区配置,确保大小为4的倍数 + buffer = { + size: Math.ceil(arrayBuffer.byteLength / 4) * 4, + data: arrayBuffer, + }; + this.bufferMap.set(arrayBuffer, buffer); + + return buffer; + } + + /** 缓冲区配置缓存映射表 */ + private static readonly bufferMap = new WeakMap(); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a737ab8..34a176d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,8 +8,13 @@ "declaration": true, "experimentalDecorators": true, "emitDeclarationOnly": true, + "skipLibCheck": true, + "esModuleInterop": true, + "downlevelIteration": true, "lib": [ - "ESNext", + "ES2015", + "ES2017", + "ES2020", "DOM", ], "outDir": "lib" From 2fa0b7e153ad16de9b27baba73b13d6cc77b2d7d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 26 Sep 2025 17:00:53 +0800 Subject: [PATCH 22/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Tex?= =?UTF-8?q?ture=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TextureDescriptor 中添加注释,明确修改后将重新创建纹理的说明。 - 更新多个属性的注释,以提高文档的清晰度和一致性。 --- src/data/Texture.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 6998b15..d6b0d8f 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -28,6 +28,8 @@ export interface TextureDescriptor * 标签。 * * 用于调试。 + * + * 注:修改后将重新创建纹理。 */ readonly label?: string; @@ -44,16 +46,22 @@ export interface TextureDescriptor * 纹理维度,默认为 "2d" 。 * * WebGL中不支持 "1d" "cube-array"。 + * + * 注:修改后将重新创建纹理。 */ readonly dimension?: TextureDimension; /** * 纹理格式。 默认为 "rgba8unorm", + * + * 注:修改后将重新创建纹理。 */ readonly format?: TextureFormat; /** * The number of mip levels the texture will contain. + * + * 注:修改后将重新创建纹理。 */ readonly mipLevelCount?: number; @@ -61,6 +69,8 @@ export interface TextureDescriptor * 是否生成mipmap * * 仅在纹理创建时执行。 + * + * 注:修改后将重新创建纹理。 */ readonly generateMipmap?: boolean; @@ -69,6 +79,8 @@ export interface TextureDescriptor * a multisampled texture. * * WebGPU只支持4重采样。 + * + * 注:修改后将重新创建纹理。 */ readonly sampleCount?: 4; } @@ -80,6 +92,8 @@ export interface Texture { /** * 纹理描述。 + * + * 注:修改后将重新创建纹理。 */ readonly descriptor: TextureDescriptor; @@ -93,6 +107,8 @@ export interface Texture * * @see GPUQueue.copyExternalImageToTexture * @see GPUQueue.writeTexture + * + * 注:修改后将重新创建纹理。 */ readonly sources?: readonly TextureSource[]; From e7798a2c1c74b56566b8e827e60850c394fd81e5 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 26 Sep 2025 17:30:13 +0800 Subject: [PATCH 23/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Tex?= =?UTF-8?q?tureView=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TextureView 接口中为多个属性添加注释,明确修改后将重新创建视图的说明。 - 提高文档的清晰度和一致性。 --- src/data/TextureView.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index fbc0971..31aab1a 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -9,11 +9,15 @@ export interface TextureView * 标签。 * * 用于调试。 + * + * 注:修改后将重新创建视图。 */ readonly label?: string; /** * 产生视图的纹理。 + * + * 注:修改后将重新创建视图。 */ readonly texture: TextureLike; @@ -21,6 +25,8 @@ export interface TextureView * mipmap级别。 * * 默认为 0。 + * + * 注:修改后将重新创建视图。 */ readonly baseMipLevel?: number; @@ -28,6 +34,8 @@ export interface TextureView * 3d纹理的深度索引、纹理数组中的层次、立方体纹理的面索引。 * * 默认为 0。 + * + * 注:修改后将重新创建视图。 */ readonly baseArrayLayer?: number; } From 3857086e15a9e8a142d04ad3834c10a4e2ee494a Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 4 Oct 2025 10:57:04 +0800 Subject: [PATCH 24/73] =?UTF-8?q?fix(eslint):=20=E6=B7=BB=E5=8A=A0=20tscon?= =?UTF-8?q?fig=20=E6=A0=B9=E7=9B=AE=E5=BD=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 明确指定 tsconfig 根目录路径,确保 ESLint 能够正确解析 TypeScript 配置文件, 避免因路径问题导致的解析错误。 --- eslint.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eslint.config.js b/eslint.config.js index 4310b9b..26e30c7 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -37,6 +37,7 @@ export default [ parserOptions: { ecmaVersion: 2021, // 使用 ES2021 语法 sourceType: 'module', // 使用 ES 模块 + tsconfigRootDir: import.meta.dirname, // 明确指定 tsconfig 根目录 }, }, rules: { From 02dff6b79afef4d94d7f9b09befbe3c4abeacec9 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 23 Oct 2025 16:19:52 +0800 Subject: [PATCH 25/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Buf?= =?UTF-8?q?fer=20=E6=8E=A5=E5=8F=A3=E5=92=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Buffer 接口中的 data 属性类型从 ArrayBuffer 修改为 ArrayBufferLike,以支持更广泛的数据类型。 - 重命名 Buffer 类的静态方法 fromArrayBuffer 为 getBuffer,并更新其参数类型为 TypedArray | ArrayBufferLike,以增强灵活性和兼容性。 --- src/data/Buffer.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index a5f3078..0a33275 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -1,3 +1,4 @@ +import { TypedArray } from '../types/TypedArray'; import { WriteBuffer } from './WriteBuffer'; /** @@ -34,7 +35,7 @@ export interface Buffer * * 注:修改后将重新创建GPUBuffer。 */ - readonly data?: ArrayBuffer; + readonly data?: ArrayBufferLike; /** * 写缓冲区。 @@ -52,8 +53,15 @@ export class Buffer * @param arrayBuffer 源数据数组 * @returns 缓冲区配置对象 */ - static fromArrayBuffer(arrayBuffer: ArrayBuffer) + static getBuffer(data: TypedArray | ArrayBufferLike) { + let arrayBuffer = data as ArrayBuffer; + + if ((data as ArrayBufferView).buffer) + { + arrayBuffer = (data as ArrayBufferView).buffer as ArrayBuffer; + } + // 检查是否已存在对应的缓冲区配置 let buffer = this.bufferMap.get(arrayBuffer); From 153b78d0acd7d69d249c4f2638afd6c5045b1c31 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 23 Oct 2025 17:37:22 +0800 Subject: [PATCH 26/73] =?UTF-8?q?feat(src):=20=E6=B7=BB=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=B8=B2=E6=9F=93=E9=80=9A=E9=81=93=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 defaultRenderPassColorAttachment 常量,提供默认的渲染通道颜色附件配置。 - 包含视图、清除值和加载操作的默认设置。 --- src/data/RenderPassColorAttachment.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/data/RenderPassColorAttachment.ts b/src/data/RenderPassColorAttachment.ts index f56c3fa..9e8e79e 100644 --- a/src/data/RenderPassColorAttachment.ts +++ b/src/data/RenderPassColorAttachment.ts @@ -60,3 +60,12 @@ export interface RenderPassColorAttachment export type Color = readonly [red: number, green: number, blue: number, alpha: number]; export type LoadOp = 'load' | 'clear'; + +/** + * 默认渲染通道颜色附件。 + */ +export const defaultRenderPassColorAttachment: RenderPassColorAttachment = { + view: undefined, + clearValue: [0, 0, 0, 0], + loadOp: 'clear', +} \ No newline at end of file From 89d5f14b0ebee9c8e2da8a9ae001c9c6e4294102 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 27 Oct 2025 14:55:49 +0800 Subject: [PATCH 27/73] =?UTF-8?q?refactor(src):=20=E6=9B=B4=E6=96=B0=20Ver?= =?UTF-8?q?texAttributes=20=E6=8E=A5=E5=8F=A3=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 VertexAttribute 接口中的 data 属性类型从 VertexDataTypes 修改为 VertexData,以提高类型的清晰度和一致性。 - 更新 VertexData 类型定义,确保支持更多数据类型。 --- src/data/VertexAttributes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/VertexAttributes.ts b/src/data/VertexAttributes.ts index b3a29e3..1cec2e7 100644 --- a/src/data/VertexAttributes.ts +++ b/src/data/VertexAttributes.ts @@ -16,7 +16,7 @@ export interface VertexAttribute /** * 顶点数据。 */ - data: VertexDataTypes; + data: VertexData; /** * 顶点数据格式。 @@ -83,7 +83,7 @@ export class VertexAttribute export type VertexStepMode = 'vertex' | 'instance'; -export type VertexDataTypes = | Float32Array +export type VertexData = | Float32Array | Uint32Array | Int32Array | Uint16Array From 6ef1e518e5bc2f4a14d29914e44b99e5ff840e1f Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 4 Nov 2025 16:02:45 +0800 Subject: [PATCH 28/73] =?UTF-8?q?refactor(src):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=A0=B9=E5=AD=97=E5=85=B8=E5=8F=98=E9=87=8F=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=A7=E5=B0=8F=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将根字典变量名从 _根字典 修改为 _map,以提高代码可读性。 - 将数量属性重命名为 _size,并更新相关逻辑以保持一致性。 --- src/utils/ChainMap.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 14e9173..f9c1015 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -8,8 +8,9 @@ export class ChainMap, V> /** * 根字典。 */ - private _根字典 = new WeakMap(); - private _数量 = 0; + private _map = new WeakMap(); + get size() { return this._size; } + private _size = 0; /** * 获取键对应的值。 @@ -20,7 +21,7 @@ export class ChainMap, V> get(keys: K): V { const keysLength = keys.length; - let map = this._根字典; + let map = this._map; let key: any; for (let i = 0, n = keysLength - 1; i < n; i++) @@ -47,7 +48,7 @@ export class ChainMap, V> set(keys: K, value: V) { const keysLength = keys.length; - let map = this._根字典; + let map = this._map; let key: any; for (let i = 0; i < keysLength - 1; i++) @@ -66,7 +67,7 @@ export class ChainMap, V> if (!map.has(key)) { map.set(key, value); - this._数量++; + this._size++; } return value; @@ -81,7 +82,7 @@ export class ChainMap, V> delete(keys: K): boolean { const keysLength = keys.length; - let map = this._根字典; + let map = this._map; let key: any; for (let i = 0; i < keysLength - 1; i++) @@ -95,7 +96,7 @@ export class ChainMap, V> key = wrapKey(keys[keysLength - 1]); const result = map.delete(key); - if (result) this._数量--; + if (result) this._size--; return result; } From ae3e64feec3a93a6b9b44090e33e81ec63d011a1 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 4 Nov 2025 20:08:50 +0800 Subject: [PATCH 29/73] =?UTF-8?q?refactor(src):=20=E7=A7=BB=E9=99=A4=20Can?= =?UTF-8?q?vasContext=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=E5=AE=BD?= =?UTF-8?q?=E9=AB=98=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 CanvasContext 接口中移除可选的 width 和 height 属性,以简化接口结构。 - 该变更旨在提高代码的清晰度和可维护性。 --- src/data/CanvasContext.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index 974a950..b4d47d3 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -9,14 +9,4 @@ export interface CanvasContext * 可能是画布的编号,也可能是画布元素或者离屏画布。 */ readonly canvasId: string | HTMLCanvasElement | OffscreenCanvas; - - /** - * 画布宽度。 - */ - readonly width?: number; - - /** - * 画布高度。 - */ - readonly height?: number; } From 56fd5cb26a9d3c0ade5d1bcd5c42eef21eb9da28 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 5 Nov 2025 14:53:09 +0800 Subject: [PATCH 30/73] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=B8=B2=E6=9F=93=E9=80=9A=E9=81=93=E6=B7=B1=E5=BA=A6?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 defaultRenderPassDepthStencilAttachment 常量,提供默认的渲染通道深度模板附件配置。 - 包含视图、深度清除值、深度加载操作、模板清除值和模板加载操作的默认设置。 --- src/data/RenderPassDepthStencilAttachment.ts | 10 +++++++++- src/data/RenderPassDescriptor.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/data/RenderPassDepthStencilAttachment.ts b/src/data/RenderPassDepthStencilAttachment.ts index 368f3f7..4b6bd4b 100644 --- a/src/data/RenderPassDepthStencilAttachment.ts +++ b/src/data/RenderPassDepthStencilAttachment.ts @@ -50,4 +50,12 @@ export interface RenderPassDepthStencilAttachment * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear */ readonly stencilLoadOp?: 'load' | 'clear'; -} \ No newline at end of file +} + +export const defaultRenderPassDepthStencilAttachment: RenderPassDepthStencilAttachment = { + view: undefined, + depthClearValue: 1, + depthLoadOp: 'load', + stencilClearValue: 0, + stencilLoadOp: 'load', +}; \ No newline at end of file diff --git a/src/data/RenderPassDescriptor.ts b/src/data/RenderPassDescriptor.ts index d76d69d..731c7f1 100644 --- a/src/data/RenderPassDescriptor.ts +++ b/src/data/RenderPassDescriptor.ts @@ -38,4 +38,4 @@ export interface RenderPassDescriptor * 是否开启多重采样。WebGPU貌似只支持4重采样。如果在颜色附件中没有给出支持多重采样的纹理时则引擎将会自动为其添加。 */ readonly sampleCount?: 4; -} \ No newline at end of file +} From a034560cfda95918a4afd69a702d20f3b555b58d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 5 Nov 2025 16:27:27 +0800 Subject: [PATCH 31/73] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=B8=B2=E6=9F=93=E9=80=9A=E9=81=93=E6=B7=B1=E5=BA=A6?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=99=84=E4=BB=B6=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 defaultRenderPassDepthStencilAttachment 常量,简化代码结构。 - 该变更旨在提高代码的清晰度和可维护性。 --- src/data/RenderPassDepthStencilAttachment.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/data/RenderPassDepthStencilAttachment.ts b/src/data/RenderPassDepthStencilAttachment.ts index 4b6bd4b..4df34ff 100644 --- a/src/data/RenderPassDepthStencilAttachment.ts +++ b/src/data/RenderPassDepthStencilAttachment.ts @@ -51,11 +51,3 @@ export interface RenderPassDepthStencilAttachment */ readonly stencilLoadOp?: 'load' | 'clear'; } - -export const defaultRenderPassDepthStencilAttachment: RenderPassDepthStencilAttachment = { - view: undefined, - depthClearValue: 1, - depthLoadOp: 'load', - stencilClearValue: 0, - stencilLoadOp: 'load', -}; \ No newline at end of file From b502281971294fd48311292efd6dcad3bfa44faa Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 6 Nov 2025 20:03:48 +0800 Subject: [PATCH 32/73] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=A8=A1=E6=9D=BF=E5=8F=82=E8=80=83=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 getStencilReference 函数,用于在模板测试中获取 stencilReference 值。 - 该函数根据 depthStencilState 中的模板操作类型判断是否需要设置 stencilReference,增强了模板测试的灵活性。 --- src/data/DepthStencilState.ts | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index b127598..6bf0a62 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -87,3 +87,40 @@ export interface DepthStencilState */ readonly depthBiasSlopeScale?: number; } + +/** + * 如果任意模板测试结果使用了 "replace" 运算,则需要再渲染前设置 `stencilReference` 值。 + * + * @param depthStencil + * @returns + */ +export function getStencilReference(depthStencil?: DepthStencilState) +{ + if (!depthStencil) return undefined; + + const { stencilFront, stencilBack } = depthStencil; + + // 如果开启了模板测试,则需要设置模板索引值 + let stencilReference: number; + + if (stencilFront) + { + const { failOp, depthFailOp, passOp } = stencilFront; + + if (failOp === 'replace' || depthFailOp === 'replace' || passOp === 'replace') + { + stencilReference = depthStencil?.stencilReference ?? 0; + } + } + if (stencilBack) + { + const { failOp, depthFailOp, passOp } = stencilBack; + + if (failOp === 'replace' || depthFailOp === 'replace' || passOp === 'replace') + { + stencilReference = depthStencil?.stencilReference ?? 0; + } + } + + return stencilReference; +} \ No newline at end of file From 40277b4e2641faccc27bc309e239028020c69a4f Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 7 Nov 2025 12:06:21 +0800 Subject: [PATCH 33/73] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=20getBlend?= =?UTF-8?q?ConstantColor=20=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 getBlendConstantColor 方法的返回类型,支持返回 undefined,以处理无效的 blendState 情况。 - 优化返回逻辑,直接返回 constantColor,提升代码简洁性。 --- src/data/BlendState.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/BlendState.ts b/src/data/BlendState.ts index 1d98929..ea95aa1 100644 --- a/src/data/BlendState.ts +++ b/src/data/BlendState.ts @@ -43,7 +43,7 @@ export class BlendState * @param blend * @returns */ - static getBlendConstantColor(blendState: BlendState): Color + static getBlendConstantColor(blendState: BlendState): Color | undefined { if (!blendState) return undefined; @@ -65,7 +65,7 @@ export class BlendState if (constantColor) { - return [constantColor[0], constantColor[1], constantColor[2], constantColor[3]]; + return constantColor; } return constantColor ?? [0, 0, 0, 0]; From 5188283de38fb62ee813c0c75c085d1aa9499cad Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 7 Nov 2025 14:09:59 +0800 Subject: [PATCH 34/73] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=20getStenc?= =?UTF-8?q?ilReference=20=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 getStencilReference 方法的返回类型,支持返回 number 或 undefined,以处理无效的 depthStencil 情况。 - 提升代码的类型安全性和可读性。 --- src/data/DepthStencilState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index 6bf0a62..756721d 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -94,7 +94,7 @@ export interface DepthStencilState * @param depthStencil * @returns */ -export function getStencilReference(depthStencil?: DepthStencilState) +export function getStencilReference(depthStencil?: DepthStencilState): number | undefined { if (!depthStencil) return undefined; From 317a79ed788994a45476f9192abb9a393dc4f6d9 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 10 Nov 2025 20:43:52 +0800 Subject: [PATCH 35/73] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20BufferBi?= =?UTF-8?q?nding=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 BufferBinding 接口中移除 BufferBindingItem 属性,简化接口结构。 - 将属性更改为可选的 value,以提高灵活性和可维护性。 --- src/data/BindingResources.ts | 3 +-- src/data/BufferBinding.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index a98b22b..0d07a87 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -1,4 +1,4 @@ -import { BufferBinding, BufferBindingItem } from './BufferBinding'; +import { BufferBinding } from './BufferBinding'; /** * 绑定资源。 @@ -21,5 +21,4 @@ export interface BindingResourceTypeMap * 缓冲区绑定。 */ BufferBinding: BufferBinding; - BufferBindingItem: BufferBindingItem; } diff --git a/src/data/BufferBinding.ts b/src/data/BufferBinding.ts index d115e0d..49f60bc 100644 --- a/src/data/BufferBinding.ts +++ b/src/data/BufferBinding.ts @@ -10,7 +10,7 @@ import { TypedArray } from '../types/TypedArray'; */ export interface BufferBinding { - readonly [name: string]: BufferBindingItem; + readonly value?: BufferBindingItem; /** * 如果未设置引擎将自动生成。 From b5344b49f75f0378a021bced91f186bad3070a87 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 12 Nov 2025 17:00:38 +0800 Subject: [PATCH 36/73] @feng3d/render-api@0.0.7 --- package.json | 2 +- src/data/Texture.ts | 16 ++++++++-------- src/data/TextureView.ts | 8 ++++---- src/utils/ChainMap.ts | 6 +++++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 5a33fec..553b2b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@feng3d/render-api", - "version": "0.0.4", + "version": "0.0.7", "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", "homepage": "https://feng3d.com/render-api/", "author": "feng", diff --git a/src/data/Texture.ts b/src/data/Texture.ts index d6b0d8f..6769ce2 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -28,7 +28,7 @@ export interface TextureDescriptor * 标签。 * * 用于调试。 - * + * * 注:修改后将重新创建纹理。 */ readonly label?: string; @@ -46,21 +46,21 @@ export interface TextureDescriptor * 纹理维度,默认为 "2d" 。 * * WebGL中不支持 "1d" "cube-array"。 - * + * * 注:修改后将重新创建纹理。 */ readonly dimension?: TextureDimension; /** * 纹理格式。 默认为 "rgba8unorm", - * + * * 注:修改后将重新创建纹理。 */ readonly format?: TextureFormat; /** * The number of mip levels the texture will contain. - * + * * 注:修改后将重新创建纹理。 */ readonly mipLevelCount?: number; @@ -69,7 +69,7 @@ export interface TextureDescriptor * 是否生成mipmap * * 仅在纹理创建时执行。 - * + * * 注:修改后将重新创建纹理。 */ readonly generateMipmap?: boolean; @@ -79,7 +79,7 @@ export interface TextureDescriptor * a multisampled texture. * * WebGPU只支持4重采样。 - * + * * 注:修改后将重新创建纹理。 */ readonly sampleCount?: 4; @@ -92,7 +92,7 @@ export interface Texture { /** * 纹理描述。 - * + * * 注:修改后将重新创建纹理。 */ readonly descriptor: TextureDescriptor; @@ -107,7 +107,7 @@ export interface Texture * * @see GPUQueue.copyExternalImageToTexture * @see GPUQueue.writeTexture - * + * * 注:修改后将重新创建纹理。 */ readonly sources?: readonly TextureSource[]; diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index 31aab1a..439e374 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -9,14 +9,14 @@ export interface TextureView * 标签。 * * 用于调试。 - * + * * 注:修改后将重新创建视图。 */ readonly label?: string; /** * 产生视图的纹理。 - * + * * 注:修改后将重新创建视图。 */ readonly texture: TextureLike; @@ -25,7 +25,7 @@ export interface TextureView * mipmap级别。 * * 默认为 0。 - * + * * 注:修改后将重新创建视图。 */ readonly baseMipLevel?: number; @@ -34,7 +34,7 @@ export interface TextureView * 3d纹理的深度索引、纹理数组中的层次、立方体纹理的面索引。 * * 默认为 0。 - * + * * 注:修改后将重新创建视图。 */ readonly baseArrayLayer?: number; diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index f9c1015..346ecdf 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -9,7 +9,11 @@ export class ChainMap, V> * 根字典。 */ private _map = new WeakMap(); - get size() { return this._size; } + get size() + { + return this._size; + } + private _size = 0; /** From 99007d5636046384fd3c55c7fa8432dbca584650 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Nov 2025 11:35:48 +0800 Subject: [PATCH 37/73] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=20CopyBuff?= =?UTF-8?q?erToBuffer=20=E6=8E=A5=E5=8F=A3=E4=BB=A5=E4=BD=BF=E7=94=A8=20Ty?= =?UTF-8?q?pedArray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 source 和 destination 属性类型从 Buffer 更改为 TypedArray,以支持更广泛的数据类型。 - 更新注释以更清晰地描述源数据和目标数据的含义及其对应关系。 --- src/data/CopyBufferToBuffer.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/data/CopyBufferToBuffer.ts b/src/data/CopyBufferToBuffer.ts index 36febdb..d894f72 100644 --- a/src/data/CopyBufferToBuffer.ts +++ b/src/data/CopyBufferToBuffer.ts @@ -1,4 +1,4 @@ -import { Buffer } from './Buffer'; +import { TypedArray } from '../types/TypedArray'; /** * GPU缓冲区之间拷贝。 @@ -14,27 +14,23 @@ export interface CopyBufferToBuffer readonly __type__: 'CopyBufferToBuffer'; /** - * 源缓冲区。 + * 源数据。 + * + * source.buffer 对应 GPUBuffer,source.byteOffset 对应 sourceOffset,source.byteLength 对应 size。 */ - source: Buffer; - - /** - * 默认为0。 - */ - sourceOffset?: number; + source: TypedArray; /** * 目标缓冲区。 + * + * {@link destination.buffer} 对应 GPUBuffer,{@link destination.byteOffset} 对应 destinationOffset,{@link destination.byteLength} 对应 size。 */ - destination: Buffer; - - /** - * 默认为0。 - */ - destinationOffset?: number; + destination: TypedArray; /** - * 默认为源缓冲区尺寸。 + * 拷贝的尺寸。 + * + * 默认为源数据与目标数据字节长度的最小值({@link Math.min} ({@link source.byteLength}, {@link destination.byteLength}))。 */ size?: number; } From 838127100fcf36607bf93b2308ac735c472e19b1 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Nov 2025 14:25:38 +0800 Subject: [PATCH 38/73] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20Buffer?= =?UTF-8?q?=20=E7=B1=BB=E7=9A=84=20getBuffer=20=E6=96=B9=E6=B3=95=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 getBuffer 方法的参数类型从 TypedArray | ArrayBufferLike 更改为 ArrayBufferLike,以简化类型处理。 - 更新缓冲区配置缓存映射表的类型为 WeakMap,增强类型安全性。 - 添加 ArrayBuffer 和 SharedArrayBuffer 的类型声明,以便于类型区分。 --- src/data/Buffer.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 0a33275..486e5e5 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -1,4 +1,3 @@ -import { TypedArray } from '../types/TypedArray'; import { WriteBuffer } from './WriteBuffer'; /** @@ -53,15 +52,8 @@ export class Buffer * @param arrayBuffer 源数据数组 * @returns 缓冲区配置对象 */ - static getBuffer(data: TypedArray | ArrayBufferLike) + static getBuffer(arrayBuffer: ArrayBufferLike) { - let arrayBuffer = data as ArrayBuffer; - - if ((data as ArrayBufferView).buffer) - { - arrayBuffer = (data as ArrayBufferView).buffer as ArrayBuffer; - } - // 检查是否已存在对应的缓冲区配置 let buffer = this.bufferMap.get(arrayBuffer); @@ -78,5 +70,19 @@ export class Buffer } /** 缓冲区配置缓存映射表 */ - private static readonly bufferMap = new WeakMap(); + private static readonly bufferMap = new WeakMap(); +} + +declare global +{ + interface ArrayBuffer + { + // 并不会实际赋值, 只是用于 ArrayBuffer 与 TypedArray 在类型上做区分。 + __type__: 'ArrayBuffer'; + } + interface SharedArrayBuffer + { + // 并不会实际赋值, 只是用于 SharedArrayBuffer 与 TypedArray 在类型上做区分。 + __type__: 'SharedArrayBuffer'; + } } \ No newline at end of file From 4382b71ae361dff1fc3d0f6891521fa817fa003a Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Nov 2025 20:21:51 +0800 Subject: [PATCH 39/73] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=20WriteBuf?= =?UTF-8?q?fer=20=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 data 属性的类型从 ArrayBufferLike 更改为 TypedArray,以简化数据处理。 - 移除 dataOffset 属性,更新 size 属性的描述以更清晰地说明其默认值。 --- src/data/WriteBuffer.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/data/WriteBuffer.ts b/src/data/WriteBuffer.ts index dfc4b70..b2d6bfc 100644 --- a/src/data/WriteBuffer.ts +++ b/src/data/WriteBuffer.ts @@ -10,21 +10,12 @@ export interface WriteBuffer /** * 写入缓冲区数据。 */ - data: ArrayBufferLike | TypedArray; + data: TypedArray; /** - * 读取数据的起始位置。 + * 写入数据数量。 * - * 默认为 0 。 - * - * 当写入的数据类型为 {@link ArrayBufferLike} 时单位为字节,当数据类型为 {@link TypedArray} 时单位为元素。 - */ - dataOffset?: number; - - /** - * 写入数据尺寸。 - * - * 当写入的数据类型为 {@link ArrayBufferLike} 时单位为字节,当数据类型为 {@link TypedArray} 时单位为元素。 + * 默认为 {@link data.length} 。 */ size?: number; } From c5b7cce0d34541343a0fcfb49e2309b3959029e0 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Nov 2025 23:00:06 +0800 Subject: [PATCH 40/73] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=20Fragment?= =?UTF-8?q?State=20=E5=92=8C=20VertexState=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 code 属性更改为可选,以提高灵活性。 - 新增 glsl 和 wgsl 属性,分别用于支持 WebGL 和 WebGPU 的着色器代码。 --- src/data/FragmentState.ts | 12 +++++++++++- src/data/VertexState.ts | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/data/FragmentState.ts b/src/data/FragmentState.ts index 0c9da18..e727828 100644 --- a/src/data/FragmentState.ts +++ b/src/data/FragmentState.ts @@ -10,7 +10,17 @@ export interface FragmentState /** * 着色器代码。 */ - readonly code: string; + readonly code?: string; + + /** + * GLSL着色器代码。适用于WebGL。 + */ + readonly glsl?: string; + + /** + * WGSL着色器代码。适用于WebGPU。 + */ + readonly wgsl?: string; /** * A list of {@link GPUColorTargetState} defining the formats and behaviors of the color targets diff --git a/src/data/VertexState.ts b/src/data/VertexState.ts index ec5a64c..2a7b430 100644 --- a/src/data/VertexState.ts +++ b/src/data/VertexState.ts @@ -6,5 +6,15 @@ export interface VertexState /** * 着色器代码。 */ - readonly code: string; + readonly code?: string; + + /** + * GLSL着色器代码。适用于WebGL。 + */ + readonly glsl?: string; + + /** + * WGSL着色器代码。适用于WebGPU。 + */ + readonly wgsl?: string; } \ No newline at end of file From 83f8724e77dde59747fbf00a830597b9b22b825d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Nov 2025 01:02:58 +0800 Subject: [PATCH 41/73] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20CanvasRender?= =?UTF-8?q?PassDescriptor=20=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 index.ts 中新增对 CanvasRenderPassDescriptor 的导出,以支持画布渲染通道描述符的使用。 --- src/data/CanvasRenderPassDescriptor.ts | 94 ++++++++++++++++++++++++++ src/index.ts | 3 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/data/CanvasRenderPassDescriptor.ts diff --git a/src/data/CanvasRenderPassDescriptor.ts b/src/data/CanvasRenderPassDescriptor.ts new file mode 100644 index 0000000..6a3b3b1 --- /dev/null +++ b/src/data/CanvasRenderPassDescriptor.ts @@ -0,0 +1,94 @@ +import { CanvasContext } from './CanvasContext'; +import { Color, LoadOp } from './RenderPassColorAttachment'; + +/** + * 画布渲染通道描述。 + */ +export interface CanvasRenderPassDescriptor +{ + /** + * 清除后填充值。 + * + * 默认为 [0,0,0,0]。 + * + * ### WebGL + * + * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clearColor + * + * ### WebGPU: + * Indicates the value to clear {@link GPURenderPassColorAttachment#view} to prior to executing the + * render pass. If not map/exist|provided, defaults to `{r: 0, g: 0, b: 0, a: 0}`. Ignored + * if {@link GPURenderPassColorAttachment#loadOp} is not {@link GPULoadOp#"clear"}. + * The components of {@link GPURenderPassColorAttachment#clearValue} are all double values. + * They are converted [$to a texel value of texture format$] matching the render attachment. + * If conversion fails, a validation error is generated. + */ + readonly clearColorValue?: Color; + + /** + * 是否清除颜色附件。 + * + * 默认 `"clear"` 。 + * + * ### WebGL + * + * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear + * + * ### WebGPU + * + * Indicates the load operation to perform on {@link GPURenderPassColorAttachment#view} prior to + * executing the render pass. + * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details. + */ + readonly loadColorOp?: LoadOp; + + /** + * 清除后填充深度值。 + * + * 默认为 1。 + * + * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clearDepth + */ + readonly depthClearValue?: number; + + /** + * 是否清除深度值。 + * + * 默认为 "load"。 + * + * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear + */ + readonly depthLoadOp?: 'load' | 'clear'; + + /** + * 清除后填充模板值。 + * + * 默认为 0。 + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clearStencil + */ + readonly stencilClearValue?: number; + + /** + * 是否清除模板值。 + * + * 默认为 "load"。 + * + * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear + */ + readonly stencilLoadOp?: 'load' | 'clear'; + + /** + * 采用次数。 + * + * 注意: WebGL2 支持。 + * + * 当值存在时,引擎将会自动创建支持`multisample`的`IGLRenderbuffer`用于接收颜色附件的结果。在渲染通道执行结束后在由`IGLRenderbuffer`拷贝到对应纹理上。 + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/renderbufferStorageMultisample + * + * WebGPU: + * 是否开启多重采样。WebGPU貌似只支持4重采样。如果在颜色附件中没有给出支持多重采样的纹理时则引擎将会自动为其添加。 + */ + readonly sampleCount?: 4; +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 68a0c2c..321aef8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ export * from './data/BlendState'; export * from './data/Buffer'; export * from './data/BufferBinding'; export * from './data/CanvasContext'; +export * from './data/CanvasRenderPassDescriptor'; export * from './data/CanvasTexture'; export * from './data/ColorTargetState'; export * from './data/CommandEncoder'; @@ -44,4 +45,4 @@ export * from './types/TypedArray'; export * from './utils/ChainMap'; -import './global'; \ No newline at end of file +import './global'; From 127e56b4c1246aba039fd8985badfd4d12ea53fa Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Nov 2025 01:17:49 +0800 Subject: [PATCH 42/73] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20unreadonly?= =?UTF-8?q?=20=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 index.ts 中新增对 unreadonly 工具函数的导出,以支持更灵活的类型处理。 --- src/index.ts | 1 + src/utils/unreadonly.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/utils/unreadonly.ts diff --git a/src/index.ts b/src/index.ts index 321aef8..ddf0b87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,5 +44,6 @@ export * from './internal/BufferBindingInfo'; export * from './types/TypedArray'; export * from './utils/ChainMap'; +export * from './utils/unreadonly'; import './global'; diff --git a/src/utils/unreadonly.ts b/src/utils/unreadonly.ts new file mode 100644 index 0000000..05082f7 --- /dev/null +++ b/src/utils/unreadonly.ts @@ -0,0 +1,12 @@ +import { UnReadonly } from '@feng3d/reactivity'; + +/** + * 取消只读 + * @param value + * @returns + */ +export function unreadonly(value: T): UnReadonly +{ + return value; +} + From c07f619e50bd91fc4bc051923fc71da8d72bbb74 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Nov 2025 19:55:08 +0800 Subject: [PATCH 43/73] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20@we?= =?UTF-8?q?bgpu/types=20=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 package.json 中新增 @webgpu/types 依赖。 - 在 tsconfig.json 中添加类型声明以支持 @webgpu/types。 - 在 CanvasRenderPassDescriptor.ts 中新增 depthStoreOp、depthReadOnly、stencilStoreOp 和 stencilReadOnly 属性,增强渲染通道描述符的功能。 --- package.json | 1 + src/data/CanvasRenderPassDescriptor.ts | 33 +++++++++++++++++++++++++- tsconfig.json | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 553b2b0..0c13114 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "vitest": "^3.1.3" }, "dependencies": { + "@webgpu/types": "0.1.60", "@feng3d/reactivity": "^1.0.6" } } \ No newline at end of file diff --git a/src/data/CanvasRenderPassDescriptor.ts b/src/data/CanvasRenderPassDescriptor.ts index 6a3b3b1..b2ffcf7 100644 --- a/src/data/CanvasRenderPassDescriptor.ts +++ b/src/data/CanvasRenderPassDescriptor.ts @@ -1,4 +1,3 @@ -import { CanvasContext } from './CanvasContext'; import { Color, LoadOp } from './RenderPassColorAttachment'; /** @@ -60,6 +59,22 @@ export interface CanvasRenderPassDescriptor */ readonly depthLoadOp?: 'load' | 'clear'; + /** + * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s + * depth component after executing the render pass. + * + * 默认 `"store"` 。 + */ + readonly depthStoreOp?: GPUStoreOp; + + /** + * Indicates that the depth component of {@link GPURenderPassDepthStencilAttachment#view} + * is read only. + * + * 默认 `false` 。 + */ + readonly depthReadOnly?: boolean; + /** * 清除后填充模板值。 * @@ -78,6 +93,22 @@ export interface CanvasRenderPassDescriptor */ readonly stencilLoadOp?: 'load' | 'clear'; + /** + * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s + * stencil component after executing the render pass. + * + * 默认 `"store"` 。 + */ + readonly stencilStoreOp?: GPUStoreOp; + + /** + * Indicates that the stencil component of {@link GPURenderPassDepthStencilAttachment#view} + * is read only. + * + * 默认 `false` 。 + */ + readonly stencilReadOnly?: boolean; + /** * 采用次数。 * diff --git a/tsconfig.json b/tsconfig.json index 34a176d..5c0528f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,9 @@ "skipLibCheck": true, "esModuleInterop": true, "downlevelIteration": true, + "types": [ + "@webgpu/types" + ], "lib": [ "ES2015", "ES2017", From 444aa8f5646eb8a8194665f92acc48ef8e9374b4 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 25 Nov 2025 22:19:35 +0800 Subject: [PATCH 44/73] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20global.t?= =?UTF-8?q?s=20=E6=96=87=E4=BB=B6=E5=B9=B6=E6=9B=B4=E6=96=B0=20tsconfig.js?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除不再使用的 global.ts 文件。 - 在 tsconfig.json 中移除 @webgpu/types 的类型声明,改为在 index.ts 中通过引用引入。 --- src/{global.ts => debug.d.ts} | 1 - src/index.ts | 7 ++-- src/shader.d.ts | 65 +++++++++++++++++++++++++++++++++++ tsconfig.json | 3 -- 4 files changed, 70 insertions(+), 6 deletions(-) rename src/{global.ts => debug.d.ts} (91%) create mode 100644 src/shader.d.ts diff --git a/src/global.ts b/src/debug.d.ts similarity index 91% rename from src/global.ts rename to src/debug.d.ts index 2e59812..6a38a69 100644 --- a/src/global.ts +++ b/src/debug.d.ts @@ -1,4 +1,3 @@ -export { }; declare global { /** diff --git a/src/index.ts b/src/index.ts index ddf0b87..ed6c885 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,8 @@ +/// + +/// +/// + export * from './consts/vertexFormatMap'; export * from './data/BindingResources'; @@ -45,5 +50,3 @@ export * from './types/TypedArray'; export * from './utils/ChainMap'; export * from './utils/unreadonly'; - -import './global'; diff --git a/src/shader.d.ts b/src/shader.d.ts new file mode 100644 index 0000000..193d734 --- /dev/null +++ b/src/shader.d.ts @@ -0,0 +1,65 @@ +/** + * @const + * @readonly + * @kind module + * @description Generic shaders + */ +declare module '*.glsl' { + const shader: string; + export default shader; +} + +/** + * @const + * @readonly + * @kind module + * @description WebGPU shaders + */ +declare module '*.wgsl' { + const shader: string; + export default shader; +} + +/** + * @const + * @readonly + * @kind module + * @description Vertex shaders + */ +declare module '*.vert' { + const shader: string; + export default shader; +} + +/** + * @const + * @readonly + * @kind module + * @description Fragment shaders + */ +declare module '*.frag' { + const shader: string; + export default shader; +} + +/** + * @const + * @readonly + * @kind module + * @description Vertex shaders + */ +declare module '*.vs' { + const shader: string; + export default shader; +} + +/** + * @const + * @readonly + * @kind module + * @description Fragment shaders + */ +declare module '*.fs' { + const shader: string; + export default shader; +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 5c0528f..34a176d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,9 +11,6 @@ "skipLibCheck": true, "esModuleInterop": true, "downlevelIteration": true, - "types": [ - "@webgpu/types" - ], "lib": [ "ES2015", "ES2017", From 405558dfc336001819569061d93dc5cd8d970f49 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 25 Nov 2025 22:29:42 +0800 Subject: [PATCH 45/73] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=20RenderPass?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E6=8F=8F=E8=BF=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 RenderPass 接口的 descriptor 属性注释中添加详细说明,解释缺省值和提供 descriptor 时的渲染行为。 --- src/data/RenderPass.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index a9ff9b8..b38d5c1 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -16,6 +16,9 @@ export interface RenderPass /** * 渲染通道描述 + * + * 如果缺省(undefined),将会使用 WebGL/WebGPU 构造函数中的 `canvasRenderPassDescriptor` 参数来绘制到画布上。 + * 如果提供了 `descriptor`,则使用该 `descriptor` 进行渲染。 */ readonly descriptor?: RenderPassDescriptor; From 43ca721315e4873dc27fc54284cd34a496f0cc43 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 26 Nov 2025 00:26:21 +0800 Subject: [PATCH 46/73] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20CanvasRe?= =?UTF-8?q?nderPassDescriptor=20=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 CanvasRenderPassDescriptor.ts 文件,移除不再使用的接口定义。 - 更新 index.ts,移除对 CanvasRenderPassDescriptor 的导出,保持代码整洁。 --- src/data/CanvasRenderPassDescriptor.ts | 125 ------------------------- src/data/RenderPass.ts | 5 +- src/index.ts | 1 - 3 files changed, 2 insertions(+), 129 deletions(-) delete mode 100644 src/data/CanvasRenderPassDescriptor.ts diff --git a/src/data/CanvasRenderPassDescriptor.ts b/src/data/CanvasRenderPassDescriptor.ts deleted file mode 100644 index b2ffcf7..0000000 --- a/src/data/CanvasRenderPassDescriptor.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { Color, LoadOp } from './RenderPassColorAttachment'; - -/** - * 画布渲染通道描述。 - */ -export interface CanvasRenderPassDescriptor -{ - /** - * 清除后填充值。 - * - * 默认为 [0,0,0,0]。 - * - * ### WebGL - * - * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clearColor - * - * ### WebGPU: - * Indicates the value to clear {@link GPURenderPassColorAttachment#view} to prior to executing the - * render pass. If not map/exist|provided, defaults to `{r: 0, g: 0, b: 0, a: 0}`. Ignored - * if {@link GPURenderPassColorAttachment#loadOp} is not {@link GPULoadOp#"clear"}. - * The components of {@link GPURenderPassColorAttachment#clearValue} are all double values. - * They are converted [$to a texel value of texture format$] matching the render attachment. - * If conversion fails, a validation error is generated. - */ - readonly clearColorValue?: Color; - - /** - * 是否清除颜色附件。 - * - * 默认 `"clear"` 。 - * - * ### WebGL - * - * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear - * - * ### WebGPU - * - * Indicates the load operation to perform on {@link GPURenderPassColorAttachment#view} prior to - * executing the render pass. - * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details. - */ - readonly loadColorOp?: LoadOp; - - /** - * 清除后填充深度值。 - * - * 默认为 1。 - * - * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clearDepth - */ - readonly depthClearValue?: number; - - /** - * 是否清除深度值。 - * - * 默认为 "load"。 - * - * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear - */ - readonly depthLoadOp?: 'load' | 'clear'; - - /** - * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s - * depth component after executing the render pass. - * - * 默认 `"store"` 。 - */ - readonly depthStoreOp?: GPUStoreOp; - - /** - * Indicates that the depth component of {@link GPURenderPassDepthStencilAttachment#view} - * is read only. - * - * 默认 `false` 。 - */ - readonly depthReadOnly?: boolean; - - /** - * 清除后填充模板值。 - * - * 默认为 0。 - * - * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clearStencil - */ - readonly stencilClearValue?: number; - - /** - * 是否清除模板值。 - * - * 默认为 "load"。 - * - * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear - */ - readonly stencilLoadOp?: 'load' | 'clear'; - - /** - * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s - * stencil component after executing the render pass. - * - * 默认 `"store"` 。 - */ - readonly stencilStoreOp?: GPUStoreOp; - - /** - * Indicates that the stencil component of {@link GPURenderPassDepthStencilAttachment#view} - * is read only. - * - * 默认 `false` 。 - */ - readonly stencilReadOnly?: boolean; - - /** - * 采用次数。 - * - * 注意: WebGL2 支持。 - * - * 当值存在时,引擎将会自动创建支持`multisample`的`IGLRenderbuffer`用于接收颜色附件的结果。在渲染通道执行结束后在由`IGLRenderbuffer`拷贝到对应纹理上。 - * - * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/renderbufferStorageMultisample - * - * WebGPU: - * 是否开启多重采样。WebGPU貌似只支持4重采样。如果在颜色附件中没有给出支持多重采样的纹理时则引擎将会自动为其添加。 - */ - readonly sampleCount?: 4; -} \ No newline at end of file diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index b38d5c1..865ae26 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -17,10 +17,9 @@ export interface RenderPass /** * 渲染通道描述 * - * 如果缺省(undefined),将会使用 WebGL/WebGPU 构造函数中的 `canvasRenderPassDescriptor` 参数来绘制到画布上。 - * 如果提供了 `descriptor`,则使用该 `descriptor` 进行渲染。 + * 必须提供。第一个颜色附件中的纹理视图可以缺省,当缺省时使用 WebGL/WebGPU 构造函数中传递的 canvasContext。 */ - readonly descriptor?: RenderPassDescriptor; + readonly descriptor: RenderPassDescriptor; /** * 渲染对象列表 diff --git a/src/index.ts b/src/index.ts index ed6c885..b0607da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,6 @@ export * from './data/BlendState'; export * from './data/Buffer'; export * from './data/BufferBinding'; export * from './data/CanvasContext'; -export * from './data/CanvasRenderPassDescriptor'; export * from './data/CanvasTexture'; export * from './data/ColorTargetState'; export * from './data/CommandEncoder'; From 3cc2bf62376cdec051617fb705639fb4f0ac06ea Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 28 Nov 2025 00:47:42 +0800 Subject: [PATCH 47/73] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20arrayLayerCo?= =?UTF-8?q?unt=20=E5=B1=9E=E6=80=A7=E5=8F=8A=E5=85=B6=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TextureView 接口中新增 arrayLayerCount 属性,描述其默认值及 WebGPU 和 WebGL 的差异。 - 更新注释以提供更清晰的使用指导,确保用户理解该属性的作用和限制。 --- src/data/TextureView.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index 439e374..5ba4016 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -38,4 +38,18 @@ export interface TextureView * 注:修改后将重新创建视图。 */ readonly baseArrayLayer?: number; + + /** + * 数组层数。 + * + * 默认为 1。 + * + * **WebGPU 与 WebGL 的差异:** + * - **WebGPU**:当纹理视图用作渲染通道的颜色附件时,`arrayLayerCount` 必须为 1。 + * 如果未指定,默认值为 1,以确保每个颜色附件只绑定一个纹理层。 + * - **WebGL**:WebGL 不支持纹理数组作为渲染目标,此属性在 WebGL 中无效。 + * + * 注:修改后将重新创建视图。 + */ + readonly arrayLayerCount?: number; } From 99494c741bf18a31f74056dc6007158f1b3554fb Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 28 Nov 2025 01:24:30 +0800 Subject: [PATCH 48/73] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20isUsedAsColo?= =?UTF-8?q?rAttachment=20=E5=B1=9E=E6=80=A7=E5=8F=8A=E5=85=B6=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TextureView 接口中新增 isUsedAsColorAttachment 属性,描述其用途及自动设置机制。 - 更新 arrayLayerCount 属性的注释,明确其在不同情况下的默认值和要求。 --- src/data/TextureView.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index 5ba4016..25eb303 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -44,12 +44,16 @@ export interface TextureView * * 默认为 1。 * - * **WebGPU 与 WebGL 的差异:** - * - **WebGPU**:当纹理视图用作渲染通道的颜色附件时,`arrayLayerCount` 必须为 1。 - * 如果未指定,默认值为 1,以确保每个颜色附件只绑定一个纹理层。 - * - **WebGL**:WebGL 不支持纹理数组作为渲染目标,此属性在 WebGL 中无效。 + * 被用作颜色附件时,必须为 1。而其他情况默认为 undefined(使用所有剩余层)。 * * 注:修改后将重新创建视图。 */ readonly arrayLayerCount?: number; + + /** + * 是否被用作颜色附件。 + * + * 注:由 WebGPU 渲染通道颜色附件自动设置。 + */ + readonly isUsedAsColorAttachment?: boolean; } From 8dd62adbf23b412e99aa1d456d4346af673ea4ec Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 4 Dec 2025 01:39:22 +0800 Subject: [PATCH 49/73] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20CanvasTextur?= =?UTF-8?q?e=20=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TextureLikeMap 接口中新增 CanvasTexture 属性,描述其用途。 - 引入 CanvasTexture 模块以支持画布纹理的使用。 --- src/data/Texture.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 6769ce2..da1af69 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -1,3 +1,4 @@ +import { CanvasTexture } from './CanvasTexture'; import { TextureDataSource } from './TextureDataSource'; import { TextureImageSource } from './TextureImageSource'; @@ -17,6 +18,11 @@ export interface TextureLikeMap * 正常纹理。 */ Texture: Texture; + + /** + * 画布纹理。 + */ + CanvasTexture: CanvasTexture; } /** From e9d6eb7579c1877bf71e5c4d5e421a3ba0fa10ba Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 4 Dec 2025 21:58:52 +0800 Subject: [PATCH 50/73] =?UTF-8?q?feat:=20=E5=9C=A8=20ReadPixels=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E6=96=B0=E5=A2=9E=20format=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8F=8A=E5=85=B6=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 format 属性,表示纹理数据格式,帮助调用者正确处理颜色通道顺序。 - 更新注释以提供更清晰的使用指导。 --- src/data/ReadPixels.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/data/ReadPixels.ts b/src/data/ReadPixels.ts index 0a74316..5a64b6a 100644 --- a/src/data/ReadPixels.ts +++ b/src/data/ReadPixels.ts @@ -1,3 +1,4 @@ +import { TextureFormat } from './Texture'; import { TextureView } from './TextureView'; /** @@ -26,4 +27,12 @@ export interface ReadPixels * 用于保存最后结果。 */ result?: ArrayBufferView; + + /** + * 纹理数据格式。 + * + * 由 readPixels 方法设置,表示返回数据的格式(例如 'rgba8unorm' 或 'bgra8unorm')。 + * 调用者可以根据此格式正确处理颜色通道顺序。 + */ + format?: TextureFormat; } \ No newline at end of file From 79c400017d42ab0236106d31804c26053e796483 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 5 Dec 2025 01:34:33 +0800 Subject: [PATCH 51/73] =?UTF-8?q?feat(ReadPixels):=20=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?texture=20=E5=B1=9E=E6=80=A7=E5=8F=8A=E5=85=B6=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 textureView 属性更名为 texture,并更新为可选属性,表示从当前画布纹理读取。 - 添加详细注释,说明当 texture 为 undefined 时的行为,提升接口的可用性和清晰度。 --- src/data/ReadPixels.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/data/ReadPixels.ts b/src/data/ReadPixels.ts index 5a64b6a..44bd8d0 100644 --- a/src/data/ReadPixels.ts +++ b/src/data/ReadPixels.ts @@ -1,5 +1,4 @@ -import { TextureFormat } from './Texture'; -import { TextureView } from './TextureView'; +import { TextureFormat, TextureLike } from './Texture'; /** * 读取渲染缓冲区或者纹理视图中的像素值。 @@ -9,9 +8,13 @@ import { TextureView } from './TextureView'; export interface ReadPixels { /** - * 读取的纹理视图。 + * GPU纹理 + * + * 当 texture 为 undefined 时,表示从当前画布纹理读取。 + * + * @default undefined */ - textureView: TextureView; + texture?: TextureLike, /** * 读取位置。 From f4baab8810f99d1a42289669b05e19ec4035462b Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 8 Dec 2025 23:16:33 +0800 Subject: [PATCH 52/73] =?UTF-8?q?chore(package):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E8=87=B3=200.0.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c13114..e79cc20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@feng3d/render-api", - "version": "0.0.7", + "version": "0.0.8", "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", "homepage": "https://feng3d.com/render-api/", "author": "feng", From 8473779240ccf942ed37f9079d5749397fe7b627 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 13 Dec 2025 13:49:19 +0800 Subject: [PATCH 53/73] =?UTF-8?q?docs(Buffer):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=B3=E4=BA=8EGPUBuffer=E9=87=8D=E6=96=B0=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这些注释不再准确,因为修改label和data属性不再触发GPUBuffer的重新创建 --- src/data/Buffer.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 486e5e5..0bb441b 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -15,8 +15,6 @@ export interface Buffer * 标签。 * * 用于调试。 - * - * 注:修改后将重新创建GPUBuffer。 */ readonly label?: string; @@ -31,8 +29,6 @@ export interface Buffer /** * 缓冲区数据。 - * - * 注:修改后将重新创建GPUBuffer。 */ readonly data?: ArrayBufferLike; From 736e91c7415d9d6589270378dd3c6f6a4f18bbc6 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 20 Dec 2025 00:44:10 +0800 Subject: [PATCH 54/73] =?UTF-8?q?feat(ReadPixels):=20=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?texture=20=E5=B1=9E=E6=80=A7=E4=B8=BA=20textureView=20=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 texture 属性更名为 textureView,表示纹理视图。 - 更新注释,说明当 textureView 为 undefined 时的行为,并支持从纹理数组的特定层读取。 --- src/data/ReadPixels.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/data/ReadPixels.ts b/src/data/ReadPixels.ts index 44bd8d0..8bce9da 100644 --- a/src/data/ReadPixels.ts +++ b/src/data/ReadPixels.ts @@ -1,4 +1,5 @@ -import { TextureFormat, TextureLike } from './Texture'; +import { TextureFormat } from './Texture'; +import { TextureView } from './TextureView'; /** * 读取渲染缓冲区或者纹理视图中的像素值。 @@ -8,13 +9,15 @@ import { TextureFormat, TextureLike } from './Texture'; export interface ReadPixels { /** - * GPU纹理 + * 纹理视图 * - * 当 texture 为 undefined 时,表示从当前画布纹理读取。 + * 当 textureView 为 undefined 时,表示从当前画布纹理读取。 + * + * 支持从纹理数组的特定层读取,通过设置 textureView.baseArrayLayer 指定层索引。 * * @default undefined */ - texture?: TextureLike, + textureView?: TextureView, /** * 读取位置。 From bf1f2e4627b1f5b67f3134680b0dc0f4bff315a2 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 21 Dec 2025 11:44:53 +0800 Subject: [PATCH 55/73] =?UTF-8?q?feat(BlendComponent):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=B7=B7=E5=90=88=E5=9B=A0=E5=AD=90=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 BlendComponent 接口的注释,明确 alpha 通道的设置继承关系。 - 添加 defaultBlendComponent 常量,提供默认混合组件配置,确保 WebGL 和 WebGPU 渲染效果一致。 --- src/data/BlendComponent.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/data/BlendComponent.ts b/src/data/BlendComponent.ts index 8cabe59..ca22de9 100644 --- a/src/data/BlendComponent.ts +++ b/src/data/BlendComponent.ts @@ -19,6 +19,8 @@ export interface BlendComponent * * 当 `operation` 值为 "min" 或 "max" 时, `srcFactor` 与 `dstFactor` 将会被引擎自动使用 "one"。 * + * 对于 alpha 通道,未设置时会继承 color 通道的设置。 + * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation */ readonly operation?: BlendOperation; @@ -26,7 +28,9 @@ export interface BlendComponent /** * 源混合因子。 * - * 默认为 "one"。 + * 默认为 "src-alpha"。 + * + * 对于 alpha 通道,未设置时会继承 color 通道的设置。 * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ @@ -35,7 +39,9 @@ export interface BlendComponent /** * 目标混合因子。 * - * 默认为 "zero"。 + * 默认为 "one-minus-src-alpha"。 + * + * 对于 alpha 通道,未设置时会继承 color 通道的设置。 * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc */ @@ -65,3 +71,14 @@ export interface IBlendFactorMap 'constant': 'constant'; 'one-minus-constant': 'one-minus-constant'; } + +/** + * 默认混合组件配置。 + * + * 用于 WebGL 和 WebGPU 在未指定混合组件时使用相同的默认值,确保渲染效果一致。 + */ +export const defaultBlendComponent: BlendComponent = { + operation: 'add', + srcFactor: 'src-alpha', + dstFactor: 'one-minus-src-alpha', +}; \ No newline at end of file From fee00216ddc812746ea2e97ee4b1cf5d5ed9cde9 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 21 Dec 2025 15:11:18 +0800 Subject: [PATCH 56/73] =?UTF-8?q?feat(Sampler):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=87=87=E6=A0=B7=E5=99=A8=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 defaultSampler 常量,提供默认的采样器配置,确保一致的采样行为。 - 更新 lodMaxClamp 注释,明确未设置 mipmapFilter 时的默认值,以保持与 WebGL 行为一致。 --- src/data/Sampler.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index 6b50b77..d9512cf 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -106,7 +106,7 @@ export interface Sampler /** * 采样时使用的最大Lod等级。 * - * 默认 16 。 + * 默认 16。当未设置 {@link mipmapFilter} 时默认为 0(不使用 mipmap),以保持与 WebGL 行为一致。 */ readonly lodMaxClamp?: number; @@ -134,3 +134,19 @@ export type IFilterMode = 'nearest' | 'linear'; * 描述采样器在采样足迹与mipmap层级不完全匹配时的行为。 */ export type IMipmapFilterMode = 'nearest' | 'linear'; + +/** + * 采样器默认值。 + */ +export const defaultSampler: Sampler = { + addressModeU: 'repeat', + addressModeV: 'repeat', + addressModeW: 'repeat', + magFilter: 'nearest', + minFilter: 'nearest', + mipmapFilter: 'nearest', + lodMinClamp: 0, + lodMaxClamp: 16, + compare: undefined, + maxAnisotropy: 1, +}; From 9ef202521f3374c6ac436334a66de3432178555e Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 21 Dec 2025 18:47:07 +0800 Subject: [PATCH 57/73] =?UTF-8?q?feat(BufferBindingInfo):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20typeName=20=E5=B1=9E=E6=80=A7=E5=8F=8A=E5=85=B6?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BufferBindingInfo 接口中新增 typeName 可选属性,用于判断是否需要对齐转换,专为 WebGPU 设计。 - 添加详细注释,提升接口的可用性和清晰度。 --- src/internal/BufferBindingInfo.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/internal/BufferBindingInfo.ts b/src/internal/BufferBindingInfo.ts index 764a0d5..f13a8a1 100644 --- a/src/internal/BufferBindingInfo.ts +++ b/src/internal/BufferBindingInfo.ts @@ -9,5 +9,9 @@ export interface BufferBindingInfo offset: number; size: number; Cls: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Int16ArrayConstructor; + /** + * 类型名称(用于判断是否需要对齐转换,WebGPU 专用) + */ + typeName?: string; }[] } From e1b6b8ea461bc929d97be34ffc92fbbb660b6e17 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 23 Dec 2025 00:26:52 +0800 Subject: [PATCH 58/73] =?UTF-8?q?feat(index):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=85=B1=E4=BA=AB=E9=85=8D=E7=BD=AE=E5=AF=B9=E8=B1=A1=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=B8=B2=E6=9F=93=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 shared 对象,包含 isRunWebGPU 和 isRunWebGL 属性,用于指示当前渲染模式。 - 该配置将有助于后续功能的扩展和渲染逻辑的管理。 --- src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.ts b/src/index.ts index b0607da..5291e7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,3 +49,8 @@ export * from './types/TypedArray'; export * from './utils/ChainMap'; export * from './utils/unreadonly'; + +export const shared = { + isRunWebGPU: false, + isRunWebGL: false, +} \ No newline at end of file From d3db9175b6baa39c0ae9cf777653abaf228cff23 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 23 Dec 2025 00:29:15 +0800 Subject: [PATCH 59/73] =?UTF-8?q?refactor(index):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E5=85=B1=E4=BA=AB=E9=85=8D=E7=BD=AE=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E4=B8=BA=20renderState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将原有的 shared 对象重命名为 renderState,以更清晰地表达其用途。 - 该对象仍包含 isRunWebGPU 和 isRunWebGL 属性,用于指示当前渲染模式。 --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5291e7f..281e4ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ export * from './types/TypedArray'; export * from './utils/ChainMap'; export * from './utils/unreadonly'; -export const shared = { +export const renderState = { isRunWebGPU: false, isRunWebGL: false, } \ No newline at end of file From 4772d7267ea0dbf991276166c08b8709678981b4 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 25 Dec 2025 12:05:36 +0800 Subject: [PATCH 60/73] =?UTF-8?q?fix(vertexFormatMap):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20float16=20=E7=B1=BB=E5=9E=8B=E7=9A=84=20typedArrayC?= =?UTF-8?q?onstructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 float16x2 和 float16x4 的 typedArrayConstructor 从 undefined 更新为 Int16Array,以确保正确的数据类型使用。 - 该更改提高了类型安全性,避免潜在的运行时错误。 --- src/consts/vertexFormatMap.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/consts/vertexFormatMap.ts b/src/consts/vertexFormatMap.ts index 7631ea9..6666eca 100644 --- a/src/consts/vertexFormatMap.ts +++ b/src/consts/vertexFormatMap.ts @@ -20,8 +20,8 @@ export const vertexFormatMap: Record = unorm16x4: { numComponents: 4, type: 'UNSIGNED_SHORT', normalized: true, dataType: 'unsigned normalized', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Uint16Array }, snorm16x2: { numComponents: 2, type: 'SHORT', normalized: true, dataType: 'signed normalized', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Int16Array }, snorm16x4: { numComponents: 4, type: 'SHORT', normalized: true, dataType: 'signed normalized', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Int16Array }, - float16x2: { numComponents: 2, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: undefined }, - float16x4: { numComponents: 4, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: undefined }, + float16x2: { numComponents: 2, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 4, wgslType: 'vec2', typedArrayConstructor: Int16Array }, + float16x4: { numComponents: 4, type: 'HALF_FLOAT', normalized: false, dataType: 'float', byteSize: 8, wgslType: 'vec4', typedArrayConstructor: Int16Array }, float32: { numComponents: 1, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 4, wgslType: 'f32', typedArrayConstructor: Float32Array }, float32x2: { numComponents: 2, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 8, wgslType: 'vec2', typedArrayConstructor: Float32Array }, float32x3: { numComponents: 3, type: 'FLOAT', normalized: false, dataType: 'float', byteSize: 12, wgslType: 'vec3', typedArrayConstructor: Float32Array }, From b16d4571c9130142c8328e3e9aeb88bf41b6f211 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 25 Dec 2025 16:54:31 +0800 Subject: [PATCH 61/73] =?UTF-8?q?feat(TransformFeedbackPass):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20TransformFeedbackPass=20=E6=8E=A5=E5=8F=A3=E5=8F=8A?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 TransformFeedbackPass 接口及其相关类型,支持 WebGL2 的变换反馈功能。 - 更新 CommandEncoder 接口以包含 TransformFeedbackPass,增强类型定义的完整性。 - 该更改为后续渲染功能提供了基础支持。 --- src/data/CommandEncoder.ts | 6 ++ src/data/TransformFeedbackPass.ts | 96 +++++++++++++++++++++++++++++++ src/index.ts | 1 + 3 files changed, 103 insertions(+) create mode 100644 src/data/TransformFeedbackPass.ts diff --git a/src/data/CommandEncoder.ts b/src/data/CommandEncoder.ts index 09639ea..2b8a616 100644 --- a/src/data/CommandEncoder.ts +++ b/src/data/CommandEncoder.ts @@ -1,6 +1,7 @@ import { CopyBufferToBuffer } from './CopyBufferToBuffer'; import { CopyTextureToTexture } from './CopyTextureToTexture'; import { RenderPass } from './RenderPass'; +import { TransformFeedbackPass } from './TransformFeedbackPass'; /** * 命令编码器。 @@ -40,5 +41,10 @@ export interface PassEncoderMap CopyTextureToTexture: CopyTextureToTexture; CopyBufferToBuffer: CopyBufferToBuffer; + + /** + * Transform Feedback 通道(WebGL2 特有,WebGPU 使用计算着色器模拟)。 + */ + TransformFeedbackPass: TransformFeedbackPass; } diff --git a/src/data/TransformFeedbackPass.ts b/src/data/TransformFeedbackPass.ts new file mode 100644 index 0000000..6f13ec2 --- /dev/null +++ b/src/data/TransformFeedbackPass.ts @@ -0,0 +1,96 @@ +import { BindingResources } from './BindingResources'; +import { DrawVertex } from './DrawVertex'; +import { VertexAttributes, VertexData } from './VertexAttributes'; +import { VertexState } from './VertexState'; + +export interface TransformFeedbackPass +{ + /** + * 数据类型。 + */ + readonly __type__: 'TransformFeedbackPass'; + + /** + * 变换反馈对象列表。 + */ + transformFeedbackObjects: TransformFeedbackObject[]; +} + +export interface TransformFeedbackObject +{ + /** + * 渲染管线描述。 + */ + readonly pipeline: TransformFeedbackPipeline; + + /** + * 顶点属性数据映射。 + */ + vertices: VertexAttributes; + + /** + * 根据顶点数据绘制图元。 + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex + */ + readonly draw: DrawVertex; + + /** + * Uniform渲染数据 + */ + uniforms?: BindingResources; + + /** + * 回写顶点着色器中输出到缓冲区。 + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/bindTransformFeedback + */ + transformFeedback: TransformFeedback; +} + +export interface TransformFeedbackPipeline +{ + /** + * 顶点着色器阶段描述(用于 WebGL Transform Feedback)。 + */ + readonly vertex: VertexState; + + /** + * 回写变量。 + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings + */ + transformFeedbackVaryings: TransformFeedbackVaryings; +} + +export interface TransformFeedbackVaryings +{ + /** + * 回写变量列表。 + */ + varyings: string[]; + + /** + * 交叉或者分离。 + */ + bufferMode: 'INTERLEAVED_ATTRIBS' | 'SEPARATE_ATTRIBS'; +} + +/** + * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/createTransformFeedback + */ +export interface TransformFeedback +{ + /** + * 绑定缓冲区列表。 + */ + bindBuffers: TransformFeedbacBindBuffer[]; +} + +export interface TransformFeedbacBindBuffer +{ + index: number; + + data: VertexData; +} + diff --git a/src/index.ts b/src/index.ts index 281e4ae..d9311e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,6 +38,7 @@ export * from './data/Texture'; export * from './data/TextureDataSource'; export * from './data/TextureImageSource'; export * from './data/TextureView'; +export * from './data/TransformFeedbackPass'; export * from './data/VertexAttributes'; export * from './data/VertexState'; export * from './data/Viewport'; From 95f019f4204f798c88fdf1b4c268aabbe6345490 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 15:22:57 +0800 Subject: [PATCH 62/73] =?UTF-8?q?chore(package):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=9C=B0=E5=9D=80=E5=92=8C=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 package.json 中的仓库地址更新为 GitHub,并指定目录为 packages/render-api。 - 更新 typedoc.json 中的源链接模板,以指向新的 GitHub 仓库地址,确保文档链接的准确性。 --- package.json | 3 ++- typedoc.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e79cc20..3cb8bc1 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ }, "repository": { "type": "git", - "url": "https://gitee.com/feng3d/render-api.git" + "url": "https://github.com/feng3d-labs/webgl.git", + "directory": "packages/render-api" }, "publishConfig": { "access": "public" diff --git a/typedoc.json b/typedoc.json index c40445a..9dcaad4 100644 --- a/typedoc.json +++ b/typedoc.json @@ -4,6 +4,6 @@ "entryPoints": [ "src/index.ts" ], - "sourceLinkTemplate": "https://gitee.com/feng3d/render-api/tree/master/{path}#L{line}", + "sourceLinkTemplate": "https://github.com/feng3d-labs/webgl/tree/master/packages/render-api/{path}#L{line}", "out": "public" } \ No newline at end of file From 56ce2d7fa6e3afc55e1094f6444162d17f351493 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 15:25:10 +0800 Subject: [PATCH 63/73] =?UTF-8?q?chore(package):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=9C=B0=E5=9D=80=E5=92=8C=E6=BA=90=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 package.json 中的仓库地址更新为新的 GitHub 仓库地址。 - 更新 typedoc.json 中的源链接模板,以指向新的仓库地址,确保文档链接的准确性。 --- package.json | 3 +-- typedoc.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3cb8bc1..a4610ff 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/feng3d-labs/webgl.git", - "directory": "packages/render-api" + "url": "https://github.com/feng3d-labs/render-api.git" }, "publishConfig": { "access": "public" diff --git a/typedoc.json b/typedoc.json index 9dcaad4..e88a1a8 100644 --- a/typedoc.json +++ b/typedoc.json @@ -4,6 +4,6 @@ "entryPoints": [ "src/index.ts" ], - "sourceLinkTemplate": "https://github.com/feng3d-labs/webgl/tree/master/packages/render-api/{path}#L{line}", + "sourceLinkTemplate": "https://github.com/feng3d-labs/render-api/tree/master/{path}#L{line}", "out": "public" } \ No newline at end of file From 7cbc8a7ab586a9501bf46d01944256f8ab3dfcaf Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 18:24:36 +0800 Subject: [PATCH 64/73] =?UTF-8?q?chore(package):=20=E6=9B=B4=E6=96=B0=20fe?= =?UTF-8?q?ng3d-cli=20=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 package.json 中的 @feng3d/cli 更新为 feng3d-cli,版本号调整为 ^0.0.3,以保持依赖项的最新状态。 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4610ff..b1c044e 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ ], "devDependencies": { "@eslint/js": "^9.0.0", - "@feng3d/cli": "^0.0.19", + "feng3d-cli": "^0.0.3", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", "typescript-eslint": "^8.32.1", From ce09e8ed7075548a6c1b3d8d826aa86bdb503cdd Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 19:54:02 +0800 Subject: [PATCH 65/73] =?UTF-8?q?chore(.gitignore):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 feng3d-cli 自动生成的文件到 .gitignore,避免不必要的提交。 - 移除 eslint.config.js 中对 packages 目录的忽略规则,以便于后续管理。 --- .gitignore | 7 +++ eslint.config.js | 3 +- package.json | 129 ++++++++++++++++++++++++----------------------- 3 files changed, 73 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index a48ec03..e73b65a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,10 @@ public out package-lock.json pnpm-lock.yaml + +# 以下文件可由 feng3d-cli 自动生成,无需提交 +# 运行 `feng3d-cli update` 可重新生成 +.github/workflows/publish.yml +feng3d.json +.cursorrules +eslint.config.js diff --git a/eslint.config.js b/eslint.config.js index 26e30c7..432003e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -16,7 +16,6 @@ export default [ '**/public/**', // 忽略所有 public 目录 '**/coverage/**', // 忽略所有 coverage 目录 '**/.git/**', // 忽略所有 .git 目录 - '**/packages/**', // 忽略所有 packages 目录 ], }, // 使用 ESLint 推荐配置 @@ -157,4 +156,4 @@ export default [ }], }, }, -]; \ No newline at end of file +]; diff --git a/package.json b/package.json index b1c044e..95f51b3 100644 --- a/package.json +++ b/package.json @@ -1,66 +1,67 @@ { - "name": "@feng3d/render-api", - "version": "0.0.8", - "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", - "homepage": "https://feng3d.com/render-api/", - "author": "feng", - "type": "module", - "main": "./src/index.ts", - "types": "./src/index.ts", - "module": "./src/index.ts", - "exports": { - ".": { - "types": "./src/index.ts", - "import": "./src/index.ts", - "require": "./src/index.ts" + "name": "@feng3d/render-api", + "version": "0.0.8", + "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", + "homepage": "https://feng3d.com/render-api/", + "author": "feng", + "type": "module", + "main": "./src/index.ts", + "types": "./src/index.ts", + "module": "./src/index.ts", + "exports": { + ".": { + "types": "./src/index.ts", + "import": "./src/index.ts", + "require": "./src/index.ts" + } + }, + "scripts": { + "clean": "rimraf \"{lib,dist,public}\"", + "build": "vite build", + "test": "vitest", + "types": "tsc", + "watch": "tsc -w", + "lint": "eslint . --ext .js,.ts --max-warnings 0", + "lintfix": "npm run lint -- --fix", + "docs": "typedoc", + "upload_oss": "npm run docs && feng3d-cli oss_upload_dir", + "update": "feng3d-cli update", + "release": "npm run clean && npm run lint && npm run build && npm run docs && npm run types && npm publish", + "prepublishOnly": "node scripts/prepublish.js", + "postpublish": "node scripts/postpublish.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/feng3d-labs/render-api.git" + }, + "publishConfig": { + "access": "public" + }, + "files": [ + "dist/", + "lib", + "src", + "readme", + "tsconfig.json" + ], + "devDependencies": { + "@eslint/js": "^9.0.0", + "feng3d-cli": "^0.0.3", + "@typescript-eslint/eslint-plugin": "8.32.1", + "@typescript-eslint/parser": "8.32.1", + "typescript-eslint": "^8.32.1", + "cross-env": "7.0.3", + "eslint": "9.26.0", + "globals": "^14.0.0", + "rimraf": "6.0.1", + "tslib": "^2.8.1", + "typedoc": "^0.28.4", + "typescript": "5.8.3", + "vite": "^6.3.5", + "vitest": "^3.1.3" + }, + "dependencies": { + "@webgpu/types": "0.1.60", + "@feng3d/reactivity": "^1.0.6" } - }, - "scripts": { - "clean": "rimraf \"{lib,dist,public}\"", - "build": "vite build", - "test": "vitest", - "types": "tsc", - "watch": "tsc -w", - "lint": "eslint . --ext .js,.ts --max-warnings 0", - "lintfix": "npm run lint -- --fix", - "docs": "typedoc", - "upload_oss": "npm run docs && feng3d-cli oss_upload_dir", - "release": "npm run clean && npm run lint && npm run build && npm run docs && npm run types && npm publish", - "prepublishOnly": "node scripts/prepublish.js", - "postpublish": "node scripts/postpublish.js" - }, - "repository": { - "type": "git", - "url": "https://github.com/feng3d-labs/render-api.git" - }, - "publishConfig": { - "access": "public" - }, - "files": [ - "dist/", - "lib", - "src", - "readme", - "tsconfig.json" - ], - "devDependencies": { - "@eslint/js": "^9.0.0", - "feng3d-cli": "^0.0.3", - "@typescript-eslint/eslint-plugin": "8.32.1", - "@typescript-eslint/parser": "8.32.1", - "typescript-eslint": "^8.32.1", - "cross-env": "7.0.3", - "eslint": "9.26.0", - "globals": "^14.0.0", - "rimraf": "6.0.1", - "tslib": "^2.8.1", - "typedoc": "^0.28.4", - "typescript": "5.8.3", - "vite": "^6.3.5", - "vitest": "^3.1.3" - }, - "dependencies": { - "@webgpu/types": "0.1.60", - "@feng3d/reactivity": "^1.0.6" - } -} \ No newline at end of file +} From f2881c7fcd42ac89af9745bc94fa2534370c830d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 20:35:19 +0800 Subject: [PATCH 66/73] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E9=9C=80=E8=A6=81=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=92=8C=E6=9B=B4=E6=96=B0=E5=BF=BD=E7=95=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 eslint.config.js 和 typedoc.json 文件,简化项目结构。 - 更新 .gitignore,移除对已删除文件的忽略规则,保持文件管理的整洁性。 --- .gitignore | 1 - eslint.config.js | 159 ----------------------------------------------- typedoc.json | 9 --- 3 files changed, 169 deletions(-) delete mode 100644 eslint.config.js delete mode 100644 typedoc.json diff --git a/.gitignore b/.gitignore index e73b65a..e6f11da 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ pnpm-lock.yaml # 以下文件可由 feng3d-cli 自动生成,无需提交 # 运行 `feng3d-cli update` 可重新生成 -.github/workflows/publish.yml feng3d.json .cursorrules eslint.config.js diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index 432003e..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,159 +0,0 @@ -// 导入 ESLint 核心模块 -import eslint from '@eslint/js'; -// 导入 TypeScript ESLint 配置 -import tseslint from 'typescript-eslint'; -// 导入全局变量定义 -import globals from 'globals'; - -// 导出 ESLint 配置 -export default [ - // 忽略检查的文件和目录 - { - ignores: [ - '**/node_modules/**', // 忽略所有 node_modules 目录 - '**/dist/**', // 忽略所有 dist 目录 - '**/lib/**', // 忽略所有 lib 目录 - '**/public/**', // 忽略所有 public 目录 - '**/coverage/**', // 忽略所有 coverage 目录 - '**/.git/**', // 忽略所有 .git 目录 - ], - }, - // 使用 ESLint 推荐配置 - eslint.configs.recommended, - // 使用 TypeScript ESLint 推荐配置 - ...tseslint.configs.recommended, - { - // 语言选项配置 - languageOptions: { - // 全局变量配置 - globals: { - ...globals.browser, // 浏览器环境全局变量 - ...globals.node, // Node.js 环境全局变量 - ...globals.es2021, // ES2021 全局变量 - global: false, // 禁用 global 全局变量 - }, - // 解析器选项 - parserOptions: { - ecmaVersion: 2021, // 使用 ES2021 语法 - sourceType: 'module', // 使用 ES 模块 - tsconfigRootDir: import.meta.dirname, // 明确指定 tsconfig 根目录 - }, - }, - rules: { - '@typescript-eslint/no-unused-vars': 'off', // 允许未使用的变量 - '@typescript-eslint/no-explicit-any': 'off', // 允许使用 any 类型 - 'no-prototype-builtins': 'off', // 允许直接使用 Object.prototype 方法 - '@typescript-eslint/ban-ts-comment': 'off', // 允许使用 @ts 注释 - '@typescript-eslint/no-unused-expressions': 'off', // 允许未使用的表达式 - '@typescript-eslint/no-empty-object-type': 'off', // 允许空对象类型 - '@typescript-eslint/no-unsafe-declaration-merging': 'off', // 允许不安全的声明合并 - '@typescript-eslint/no-unsafe-function-type': 'off', // 允许不安全的函数类型 - '@typescript-eslint/no-this-alias': 'off', // 允许 this 别名 - 'prefer-const': 'off', // 不强制使用 const - 'no-fallthrough': 'off', // 允许 fallthrough - 'no-constant-binary-expression': 'off', // 允许常量二进制表达式 - - // 注释格式规则 - 'spaced-comment': ['warn', 'always', { - 'line': { - 'markers': ['/'], // 以 / 开头的注释需要空格 - 'exceptions': ['-', '+'], // 允许以 - 和 + 开头的注释不需要空格 - }, - 'block': { - 'markers': ['!'], // 以 ! 开头的块级注释需要空格 - 'exceptions': ['*'], // 允许以 * 开头的块级注释不需要空格 - 'balanced': true, // 要求块级注释的 * 对齐 - }, - }], - - // 空格和换行规则 - 'no-trailing-spaces': ['warn', { // 禁止行尾空格 - 'skipBlankLines': false, // 不跳过空行 - 'ignoreComments': false, // 不忽略注释 - }], - 'no-multiple-empty-lines': ['warn', { // 限制空行数量 - 'max': 1, // 最多允许 1 个空行 - 'maxEOF': 1, // 文件末尾最多 1 个空行 - 'maxBOF': 0, // 文件开头不允许空行 - }], - 'lines-between-class-members': ['warn', 'always', { // 类成员之间需要空行 - 'exceptAfterSingleLine': true, // 单行成员后可以没有空行 - }], - 'padding-line-between-statements': [ // 语句之间的空行规则 - 'warn', - { 'blankLine': 'always', 'prev': '*', 'next': 'return' }, // return 前需要空行 - { 'blankLine': 'always', 'prev': ['const', 'let', 'var'], 'next': '*' }, // 变量声明后需要空行 - { 'blankLine': 'any', 'prev': ['const', 'let', 'var'], 'next': ['const', 'let', 'var'] }, // 变量声明之间可以没有空行 - ], - - // 缩进规则 - 'indent': ['warn', 4, { // 使用 4 空格缩进 - 'SwitchCase': 1, // switch case 缩进 1 级 - 'VariableDeclarator': 'first', // 变量声明对齐到第一个变量 - 'outerIIFEBody': 1, // 外层 IIFE 缩进 1 级 - 'MemberExpression': 1, // 成员表达式缩进 1 级 - 'FunctionDeclaration': { // 函数声明缩进规则 - 'parameters': 1, // 参数缩进 1 级 - 'body': 1, // 函数体缩进 1 级 - }, - 'FunctionExpression': { // 函数表达式缩进规则 - 'parameters': 1, // 参数缩进 1 级 - 'body': 1, // 函数体缩进 1 级 - }, - 'CallExpression': { // 函数调用缩进规则 - 'arguments': 1, // 参数缩进 1 级 - }, - 'ArrayExpression': 1, // 数组表达式缩进 1 级 - 'ObjectExpression': 1, // 对象表达式缩进 1 级 - 'ImportDeclaration': 1, // import 声明缩进 1 级 - 'flatTernaryExpressions': false, // 不扁平化三元表达式 - 'ignoreComments': false, // 不忽略注释 - }], - - // 引号规则 - 'quotes': ['warn', 'single', { // 使用单引号 - 'avoidEscape': true, // 允许使用转义字符 - 'allowTemplateLiterals': true, // 允许使用模板字符串 - }], - - // 其他格式规则 - 'semi': ['off'], // 要求使用分号 - 'comma-dangle': ['warn', 'always-multiline'], // 多行时要求尾随逗号 - 'object-curly-spacing': ['warn', 'always'], // 对象括号内要求空格 - 'array-bracket-spacing': ['warn', 'never'], // 数组括号内不允许空格 - 'arrow-spacing': ['warn', { // 箭头函数空格规则 - 'before': true, // 箭头前需要空格 - 'after': true, // 箭头后需要空格 - }], - 'block-spacing': ['warn', 'always'], // 块级代码需要空格 - 'brace-style': ['warn', 'allman', { // 大括号风格 - 'allowSingleLine': false, // 不允许单行大括号 - }], - 'comma-spacing': ['warn', { // 逗号空格规则 - 'before': false, // 逗号前不允许空格 - 'after': true, // 逗号后需要空格 - }], - 'comma-style': ['warn', 'last'], // 逗号放在行尾 - 'key-spacing': ['warn', { // 对象键值对空格规则 - 'beforeColon': false, // 冒号前不允许空格 - 'afterColon': true, // 冒号后需要空格 - }], - 'keyword-spacing': ['warn', { // 关键字空格规则 - 'before': true, // 关键字前需要空格 - 'after': true, // 关键字后需要空格 - }], - 'space-before-blocks': ['warn', 'always'], // 块级代码前需要空格 - 'space-before-function-paren': ['warn', { // 函数括号前空格规则 - 'anonymous': 'always', // 匿名函数括号前需要空格 - 'named': 'never', // 命名函数括号前不允许空格 - 'asyncArrow': 'always', // 异步箭头函数括号前需要空格 - }], - 'space-in-parens': ['warn', 'never'], // 括号内不允许空格 - 'space-infix-ops': ['warn'], // 操作符前后需要空格 - 'space-unary-ops': ['warn', { // 一元操作符空格规则 - 'words': true, // 单词类操作符需要空格 - 'nonwords': false, // 非单词类操作符不需要空格 - }], - }, - }, -]; diff --git a/typedoc.json b/typedoc.json deleted file mode 100644 index e88a1a8..0000000 --- a/typedoc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@feng3d/render-api", - "$schema": "https://typedoc.org/schema.json", - "entryPoints": [ - "src/index.ts" - ], - "sourceLinkTemplate": "https://github.com/feng3d-labs/render-api/tree/master/{path}#L{line}", - "out": "public" -} \ No newline at end of file From e0caeaf100defba5f2b2d1135957bcce5be8ffc2 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 20:43:07 +0800 Subject: [PATCH 67/73] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=20GitHub=20Ac?= =?UTF-8?q?tions=20=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=8F=91=E5=B8=83=E5=92=8C=20NPM=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 pages.yml 工作流,用于将文档发布到 GitHub Pages。 - 新增 publish.yml 工作流,实现当版本在 NPM 不存在时自动发布。 - 更新 .gitignore,添加 typedoc.json 和测试文件的忽略规则。 --- .github/workflows/pages.yml | 58 +++++++++++++++ .github/workflows/publish.yml | 128 ++++++++++++++++++++++++++++++++++ .gitignore | 2 + 3 files changed, 188 insertions(+) create mode 100644 .github/workflows/pages.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..91593a9 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,58 @@ +# 将文档发布到 GitHub Pages +name: Deploy to GitHub Pages + +on: + push: + branches: + - master + - main + workflow_dispatch: # 支持手动触发 + +# 设置 GITHUB_TOKEN 的权限 +permissions: + contents: read + pages: write + id-token: write + +# 只允许一个并发部署 +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm ci + + - name: Build docs + run: npm run docs + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: './public' + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bc63cd7 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,128 @@ +# 当 package.json 中的版本在 npm 不存在时自动发布 +name: Publish to NPM + +on: + push: + branches: + - master + - main + workflow_dispatch: # 支持手动触发 + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + should_publish: ${{ steps.check.outputs.should_publish }} + version: ${{ steps.check.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check if version exists on npm + id: check + run: | + # 获取包名和当前版本 + PACKAGE_NAME=$(node -p "require('./package.json').name") + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "Package: $PACKAGE_NAME" + echo "Current version: $CURRENT_VERSION" + + # 检查该版本是否已在 npm 上存在 + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/$PACKAGE_NAME/$CURRENT_VERSION") + + if [ "$HTTP_STATUS" = "404" ]; then + echo "Version $CURRENT_VERSION not found on npm, will publish" + echo "should_publish=true" >> $GITHUB_OUTPUT + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + else + echo "Version $CURRENT_VERSION already exists on npm (HTTP $HTTP_STATUS)" + echo "should_publish=false" >> $GITHUB_OUTPUT + fi + + publish: + needs: check-version + if: needs.check-version.outputs.should_publish == 'true' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # 获取完整历史以生成更新日志 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Run lint + run: npm run lint + + - name: Run tests + run: npm test + + - name: Publish to NPM + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create Git Tag + run: | + VERSION=${{ needs.check-version.outputs.version }} + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v$VERSION" -m "Release v$VERSION" + git push origin "v$VERSION" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate Release Notes + id: release_notes + run: | + VERSION=${{ needs.check-version.outputs.version }} + + # 获取上一个版本的 tag + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") + + echo "Previous tag: $PREVIOUS_TAG" + + # 生成更新日志 + if [ -n "$PREVIOUS_TAG" ]; then + echo "## 更新内容" > release_notes.md + echo "" >> release_notes.md + echo "与 $PREVIOUS_TAG 相比的变更:" >> release_notes.md + echo "" >> release_notes.md + + # 获取提交日志 + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> release_notes.md + else + echo "## 更新内容" > release_notes.md + echo "" >> release_notes.md + echo "首次发布" >> release_notes.md + echo "" >> release_notes.md + + # 获取所有提交日志 + git log --pretty=format:"- %s (%h)" >> release_notes.md + fi + + echo "" >> release_notes.md + + # 输出生成的内容 + echo "Generated release notes:" + cat release_notes.md + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ needs.check-version.outputs.version }} + name: Release v${{ needs.check-version.outputs.version }} + body_path: release_notes.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.gitignore b/.gitignore index e6f11da..49bb2a8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ pnpm-lock.yaml feng3d.json .cursorrules eslint.config.js +typedoc.json +test/index.test.ts From d5952b299102b3df14bf2da2f611e62ab0c7d013 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 20:55:20 +0800 Subject: [PATCH 68/73] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20.gitignore?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E5=92=8C=E5=88=A0=E9=99=A4=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 .gitignore 中添加 test/_.test.ts 文件以避免不必要的提交。 - 删除不再需要的 test/index.spec.ts 测试文件,简化项目结构。 --- .gitignore | 1 + test/index.spec.ts | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 test/index.spec.ts diff --git a/.gitignore b/.gitignore index 49bb2a8..a76fca1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ feng3d.json eslint.config.js typedoc.json test/index.test.ts +test/_.test.ts diff --git a/test/index.spec.ts b/test/index.spec.ts deleted file mode 100644 index 00252bf..0000000 --- a/test/index.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TextureImageSource } from '@feng3d/render-api'; -import { assert, describe, it } from 'vitest'; - -describe('test', () => -{ - it('test', () => - { - assert.equal(true, true); - }); -}); From 9d09ba5e660ce997d5ebb0397462967ae590916b Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 22:13:22 +0800 Subject: [PATCH 69/73] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E9=85=8D=E7=BD=AE=E5=92=8C=E4=BE=9D=E8=B5=96=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 .gitignore 中添加 .husky/pre-commit 文件以避免不必要的提交。 - 更新 package.json,修改 update 脚本以使用 npx,并添加 prepare 脚本以支持 husky。 - 添加 lint-staged 配置以在提交时自动修复代码格式问题。 - 更新 GitHub Actions 工作流,新增 release 触发条件以支持新版本发布。 --- .github/workflows/pages.yml | 2 ++ .gitignore | 1 + package.json | 14 +++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 91593a9..8809bb1 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -6,6 +6,8 @@ on: branches: - master - main + release: + types: [published] # 发布新版本时触发 workflow_dispatch: # 支持手动触发 # 设置 GITHUB_TOKEN 的权限 diff --git a/.gitignore b/.gitignore index a76fca1..596df3f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ eslint.config.js typedoc.json test/index.test.ts test/_.test.ts +.husky/pre-commit diff --git a/package.json b/package.json index 95f51b3..bf4af54 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,11 @@ "lintfix": "npm run lint -- --fix", "docs": "typedoc", "upload_oss": "npm run docs && feng3d-cli oss_upload_dir", - "update": "feng3d-cli update", + "update": "npx feng3d-cli update && npm install", "release": "npm run clean && npm run lint && npm run build && npm run docs && npm run types && npm publish", "prepublishOnly": "node scripts/prepublish.js", - "postpublish": "node scripts/postpublish.js" + "postpublish": "node scripts/postpublish.js", + "prepare": "husky" }, "repository": { "type": "git", @@ -58,10 +59,17 @@ "typedoc": "^0.28.4", "typescript": "5.8.3", "vite": "^6.3.5", - "vitest": "^3.1.3" + "vitest": "^3.1.3", + "husky": "^9.1.7", + "lint-staged": "^15.2.10" }, "dependencies": { "@webgpu/types": "0.1.60", "@feng3d/reactivity": "^1.0.6" + }, + "lint-staged": { + "*.{js,ts}": [ + "eslint --fix --max-warnings 0" + ] } } From a545e56ebf020cd0ebd299b4ededfa4c3da943b0 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 22:50:34 +0800 Subject: [PATCH 70/73] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=20master=20?= =?UTF-8?q?=E5=88=86=E6=94=AF=20CI=20=E9=85=8D=E7=BD=AE=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=90=88=E5=B9=B6=E8=AF=B7=E6=B1=82=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 master.yml 文件,移除不再需要的 CI 配置。 - 更新 pull-request.yml,支持同时在 master 和 main 分支上触发 CI。 - 修改步骤名称以提高可读性,并将依赖安装命令改为 npm ci,确保一致性。 --- .github/workflows/master.yml | 61 ------------------------------ .github/workflows/pull-request.yml | 29 ++++++++------ 2 files changed, 17 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/master.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml deleted file mode 100644 index 746cb82..0000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Master Branch CI - -on: - push: - branches: [ master ] - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: '20.x' - - - name: Install dependencies - run: npm install - - - name: Run unit tests - run: npm test - - - name: Build project - run: npm run build - - - name: docs - run: npm run docs - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public - - - name: Check npm version - id: check-npm-version - run: | - CURRENT_VERSION=$(node -p "require('./package.json').version") - PUBLISHED_VERSION=$(npm view . version 2>/dev/null || echo "0.0.0") - if [ "$CURRENT_VERSION" != "$PUBLISHED_VERSION" ]; then - echo "publish=true" >> $GITHUB_OUTPUT - else - echo "publish=false" >> $GITHUB_OUTPUT - fi - - - name: Publish to npm - if: steps.check-npm-version.outputs.publish == 'true' - run: | - echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc - npm run release - - - name: Create git tag - if: steps.check-npm-version.outputs.publish == 'true' - run: | - VERSION=$(node -p "require('./package.json').version") - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git tag -a v$VERSION -m "Release v$VERSION" - git push origin v$VERSION diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index bbeceb7..b5bf979 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,26 +1,31 @@ +# 合并请求 CI - 运行单元测试 name: Pull Request CI on: pull_request: - branches: [ master ] + branches: + - master + - main jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: '20.x' + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' - - name: Install dependencies - run: npm install + - name: Install dependencies + run: npm ci - - name: Run unit tests - run: npm test + - name: Run lint + run: npm run lint + + - name: Run unit tests + run: npm test - - name: Build project - run: npm run build \ No newline at end of file From 8432aeb4a03e4055996b5263926befb7463ceb55 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 23:03:08 +0800 Subject: [PATCH 71/73] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E8=AE=B8?= =?UTF-8?q?=E5=8F=AF=E8=AF=81=E6=96=87=E4=BB=B6=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 LICENSE 文件内容更新为 MIT 许可证的中文版本,确保版权信息的准确性。 - 在 .gitignore 中添加 .vscode/settings.json 文件以避免不必要的提交。 --- .gitignore | 1 + .vscode/settings.json | 9 --------- LICENSE | 28 +++++++++++----------------- 3 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 596df3f..cffe4d8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ typedoc.json test/index.test.ts test/_.test.ts .husky/pre-commit +.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4745c7f..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -// 将设置放入此文件中以覆盖默认值和用户设置。 -{ - // 定义函数的左大括号是否放置在新的一行。 - "typescript.format.placeOpenBraceOnNewLineForFunctions": true, - // 定义控制块的左括号是否放置在新的一行。 - "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, - "javascript.format.placeOpenBraceOnNewLineForFunctions": true, - "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true, -} \ No newline at end of file diff --git a/LICENSE b/LICENSE index 3ece308..af18e8f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,15 @@ -MIT License +MIT 许可证 -Copyright (c) 2019 feng +版权所有 (c) 2025 feng -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +特此授予任何获得本软件及相关文档文件("软件")副本的人免费许可, +可以不受限制地处理本软件,包括但不限于使用、复制、修改、合并、 +发布、分发、再许可和/或销售本软件的副本,并允许向其提供本软件的 +人这样做,但须符合以下条件: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +本软件按"原样"提供,不提供任何明示或暗示的保证,包括但不限于对 +适销性、特定用途适用性和非侵权性的保证。在任何情况下,作者或版权 +持有人均不对因本软件或本软件的使用或其他交易而产生的任何索赔、 +损害或其他责任负责,无论是在合同诉讼、侵权诉讼还是其他诉讼中。 From e356267dafb569d8a17f23ad07e0b2bdecd0c20b Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 28 Dec 2025 23:30:05 +0800 Subject: [PATCH 72/73] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=20tsconfig.js?= =?UTF-8?q?on=20=E6=96=87=E4=BB=B6=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除不再需要的 tsconfig.json 文件,简化项目结构。 - 在 .gitignore 中添加 tsconfig.json,以避免不必要的提交。 --- .gitignore | 1 + tsconfig.json | 25 ------------------------- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index cffe4d8..2429b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ test/index.test.ts test/_.test.ts .husky/pre-commit .vscode/settings.json +tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 34a176d..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "ES5", - "module": "CommonJS", - "noImplicitAny": false, - "sourceMap": true, - "declarationMap": true, - "declaration": true, - "experimentalDecorators": true, - "emitDeclarationOnly": true, - "skipLibCheck": true, - "esModuleInterop": true, - "downlevelIteration": true, - "lib": [ - "ES2015", - "ES2017", - "ES2020", - "DOM", - ], - "outDir": "lib" - }, - "include": [ - "src/**/*.ts" - ] -} \ No newline at end of file From 063f106afd1c50153556c4da944e9a70bd202916 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 29 Dec 2025 00:14:09 +0800 Subject: [PATCH 73/73] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20GitHub=20Ac?= =?UTF-8?q?tions=20=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=92=8C=20package.json=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 package.json 中添加 postinstall 脚本以支持 feng3d-cli 更新。 - 修改 GitHub Actions 工作流,仅在 package.json 变化时触发部署。 - 增加版本检查步骤,确保仅在版本号变化时构建和发布。 --- .github/workflows/pages.yml | 39 +++++++++++++++++++++++++++--- .github/workflows/publish.yml | 2 +- .github/workflows/pull-request.yml | 11 ++++++--- package.json | 3 ++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 8809bb1..9f5d7e6 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -1,4 +1,5 @@ # 将文档发布到 GitHub Pages +# 仅在主分支版本号发生变化时触发部署 name: Deploy to GitHub Pages on: @@ -6,8 +7,8 @@ on: branches: - master - main - release: - types: [published] # 发布新版本时触发 + paths: + - 'package.json' # 仅在 package.json 变化时触发 workflow_dispatch: # 支持手动触发 # 设置 GITHUB_TOKEN 的权限 @@ -22,8 +23,40 @@ concurrency: cancel-in-progress: true jobs: + # 检查版本号是否变化 + check-version: + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 # 获取最近两次提交以比较版本 + + - name: Check if version changed + id: check + run: | + # 获取当前版本 + CURRENT_VERSION=$(node -p "require('./package.json').version") + # 获取上一次提交的版本 + git checkout HEAD~1 -- package.json 2>/dev/null || echo "First commit" + PREVIOUS_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0") + git checkout HEAD -- package.json + + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then + echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" + echo "changed=true" >> $GITHUB_OUTPUT + else + echo "Version unchanged: $CURRENT_VERSION" + echo "changed=false" >> $GITHUB_OUTPUT + fi + build: runs-on: ubuntu-latest + needs: check-version + # 仅在版本号变化或手动触发时构建 + if: needs.check-version.outputs.version_changed == 'true' || github.event_name == 'workflow_dispatch' steps: - name: Checkout uses: actions/checkout@v4 @@ -34,7 +67,7 @@ jobs: node-version: '20' - name: Install dependencies - run: npm ci + run: npm install - name: Build docs run: npm run docs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bc63cd7..6235e79 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,7 +56,7 @@ jobs: registry-url: 'https://registry.npmjs.org' - name: Install dependencies - run: npm ci + run: npm install - name: Build run: npm run build diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b5bf979..c039144 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,7 +1,12 @@ -# 合并请求 CI - 运行单元测试 -name: Pull Request CI +# CI - 运行单元测试 +# 在合并到主分支或在主分支提交代码时执行 +name: CI on: + push: + branches: + - master + - main pull_request: branches: - master @@ -21,7 +26,7 @@ jobs: node-version: '20' - name: Install dependencies - run: npm ci + run: npm install - name: Run lint run: npm run lint diff --git a/package.json b/package.json index bf4af54..ce36146 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "release": "npm run clean && npm run lint && npm run build && npm run docs && npm run types && npm publish", "prepublishOnly": "node scripts/prepublish.js", "postpublish": "node scripts/postpublish.js", - "prepare": "husky" + "prepare": "husky", + "postinstall": "npx feng3d-cli update || exit 0" }, "repository": { "type": "git",