From 56788cbd7c7fa9754c0cd13285e4f7f80dac7ac1 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 13 Mar 2025 23:34:19 +0800 Subject: [PATCH 01/80] =?UTF-8?q?refactor(data):=20=E5=B0=86=20Buffer=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=20writeBuffers=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=A0=87=E8=AE=B0=E4=B8=BA=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Buffer 接口中,将 writeBuffers 属性添加 readonly 修饰符 - 此更改表示该属性在创建后不应被修改,提高了代码的可读性和安全性 --- src/data/Buffer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 8c601b9..4108b9f 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -38,5 +38,5 @@ export interface Buffer * * {@link GPUQueue.writeBuffer} */ - writeBuffers?: WriteBuffer[]; + readonly writeBuffers?: WriteBuffer[]; } -- Gitee From 0c8a9751d2baabf3f2e52b4f83568565b06ac197 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 18:01:27 +0800 Subject: [PATCH 02/80] =?UTF-8?q?refactor(data):=20=E9=87=8D=E6=9E=84=20Un?= =?UTF-8?q?iforms=20=E6=8E=A5=E5=8F=A3=E5=B9=B6=E6=94=B9=E5=90=8D=E4=B8=BA?= =?UTF-8?q?=20BindingResources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Uniforms 接口重命名为 BindingResources,以更好地反映其功能 - 更新了相关文件中的引用,以适应这一更改 - 删除了 Uniforms.ts 文件,因其内容已迁移到 BindingResources --- src/data/{Uniforms.ts => BindingResources.ts} | 14 ++++++++------ src/data/RenderObject.ts | 4 ++-- src/data/RenderPass.ts | 4 ++-- src/index.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) rename src/data/{Uniforms.ts => BindingResources.ts} (40%) diff --git a/src/data/Uniforms.ts b/src/data/BindingResources.ts similarity index 40% rename from src/data/Uniforms.ts rename to src/data/BindingResources.ts index 30104f0..50d4e12 100644 --- a/src/data/Uniforms.ts +++ b/src/data/BindingResources.ts @@ -1,21 +1,23 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; /** - * Uniform 数据 + * 绑定资源。 + * + * 与WGSL中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ -export interface Uniforms +export interface BindingResources { __type__?: any; - [key: string]: UniformType; + [key: string]: BindingResource; } /** - * Uniform 类型 + * 绑定资源 类型 */ -export type UniformType = UniformTypeMap[keyof UniformTypeMap]; +export type BindingResource = BindingResourceTypeMap[keyof BindingResourceTypeMap]; -export interface UniformTypeMap +export interface BindingResourceTypeMap { /** * 缓冲区绑定。 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/RenderPass.ts b/src/data/RenderPass.ts index 81d4a24..d34a58f 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -22,7 +22,7 @@ export interface RenderPass /** * 渲染对象列表 */ - readonly renderObjects?: readonly IRenderPassObject[]; + readonly renderObjects?: readonly RenderPassObject[]; /** * 渲染不被遮挡查询结果。具体数据保存在各子项的"result"属性中。 @@ -32,7 +32,7 @@ export interface RenderPass occlusionQueryResults?: OcclusionQuery[]; } -export type IRenderPassObject = RenderPassObjectMap[keyof RenderPassObjectMap]; +export type RenderPassObject = RenderPassObjectMap[keyof RenderPassObjectMap]; export interface RenderPassObjectMap { 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"; -- Gitee From 1b461fa2fcc9e00ed0514b6363044058d377cacb Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 18:12:56 +0800 Subject: [PATCH 03/80] =?UTF-8?q?build(dependencies):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20Vue=20=E5=8F=8D=E5=BA=94=E6=80=A7=E5=BA=93=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=AF=BC=E5=87=BA=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 package.json 中添加 @vue/reactivity 依赖,版本为 ^3.5.13 - 在 src/index.ts 中导入并导出 reactivity 模块 - 调整 BindingResources 的导出顺序,移到 VertexAttributes 之前 --- package.json | 1 + src/index.ts | 4 +++- src/reactivity.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/reactivity.ts diff --git a/package.json b/package.json index d871a44..a426988 100644 --- a/package.json +++ b/package.json @@ -56,5 +56,6 @@ "vitest": "^0.32.2" }, "dependencies": { + "@vue/reactivity": "^3.5.13" } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index db3c056..7930ed0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from "./consts/vertexFormatMap"; +export * from "./data/BindingResources"; export * from "./data/BlendComponent"; export * from "./data/BlendState"; export * from "./data/Buffer"; @@ -33,12 +34,13 @@ export * from "./data/Texture"; export * from "./data/TextureDataSource"; export * from "./data/TextureImageSource"; export * from "./data/TextureView"; -export * from "./data/BindingResources"; export * from "./data/VertexAttributes"; export * from "./data/VertexState"; export * from "./data/Viewport"; export * from "./data/WriteBuffer"; +export * from "./reactivity"; + export * from "./internal/BufferBindingInfo"; export * from "./types/TypedArray"; diff --git a/src/reactivity.ts b/src/reactivity.ts new file mode 100644 index 0000000..a6b45bc --- /dev/null +++ b/src/reactivity.ts @@ -0,0 +1,12 @@ +import { UnReadonly } from "@feng3d/render-api"; +import { reactive as vueReactive } from "@vue/reactivity"; + +export { computed, type ComputedRef, effect } from "@vue/reactivity"; + +/** + * Vue响应式。 + * + * 额外把只读属性去掉(引擎希望原始数据只用于访问,不直接修改,通过修改响应式数据来触发引擎更新逻辑并间接修改原始数据)。 + */ +export const reactive: (target: T) => UnReadonly = vueReactive as any; + -- Gitee From a8ae421d865589a1614391f3e5acf61064c34a50 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 18:17:32 +0800 Subject: [PATCH 04/80] =?UTF-8?q?refactor(data):=20=E5=B0=86=20Buffer=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA=20GBuffe?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 src/data/Buffer.ts 中将 Buffer 接口重命名为 GBuffer - 在 src/data/CopyBufferToBuffer.ts 中更新了相关的导入和类型引用 --- src/data/Buffer.ts | 2 +- src/data/CopyBufferToBuffer.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 4108b9f..23bdf1e 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -10,7 +10,7 @@ import { WriteBuffer } from "./WriteBuffer"; * * {@link GPUBuffer} */ -export interface Buffer +export interface GBuffer { __type__?: "Buffer"; diff --git a/src/data/CopyBufferToBuffer.ts b/src/data/CopyBufferToBuffer.ts index 264cfde..89cd239 100644 --- a/src/data/CopyBufferToBuffer.ts +++ b/src/data/CopyBufferToBuffer.ts @@ -1,4 +1,4 @@ -import { Buffer } from "./Buffer"; +import { GBuffer } from "./Buffer"; /** * GPU缓冲区之间拷贝。 @@ -16,7 +16,7 @@ export interface CopyBufferToBuffer /** * 源缓冲区。 */ - source: Buffer; + source: GBuffer; /** * 默认为0。 @@ -26,7 +26,7 @@ export interface CopyBufferToBuffer /** * 目标缓冲区。 */ - destination: Buffer; + destination: GBuffer; /** * 默认为0。 -- Gitee From 573d49d7d63493a501fd7c018efaa179e00743b2 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 18:23:00 +0800 Subject: [PATCH 05/80] =?UTF-8?q?refactor(data):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=B5=84=E6=BA=90=E5=92=8C=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 BindingResources 接口的注释,明确其与着色器中名称的对应关系 - 修改 RenderObject 接口中的 uniforms 属性名称为 bindingResources,以更准确地反映其内容 --- src/data/BindingResources.ts | 2 +- src/data/RenderObject.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index 50d4e12..cc71199 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -3,7 +3,7 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; /** * 绑定资源。 * - * 与WGSL中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 + * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ export interface BindingResources { diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 46a5606..9c95fc6 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -37,9 +37,11 @@ export interface RenderObject geometry: Geometry; /** - * Uniform变量数据 + * 绑定资源。 + * + * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ - uniforms?: BindingResources; + bindingResources?: BindingResources; _version?: number; } -- Gitee From 0530a659c5a4cd337cabbf16ec5879da63c4c742 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 20:58:25 +0800 Subject: [PATCH 06/80] =?UTF-8?q?refactor(data):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=20=5F=5Ftype=5F=5F=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了多个接口中不必要的 __type__ 属性,包括: - BindingResources - BlendComponent - BlendState - Buffer - CanvasContext - CanvasTexture - ColorTargetState - CommandEncoder - DepthStencilState - FragmentState - Geometry - ImageCopyTexture - PrimitiveState - RenderPassColorAttachment - RenderPassDepthStencilAttachment - RenderPassDescriptor - RenderPipeline - Sampler - ScissorRect - StencilFaceState - Submit - Texture - TextureView - VertexAttributes - VertexState - Viewport - WriteBuffer 这个改动简化了接口定义,并减少了冗余的类型信息。 --- src/data/BindingResources.ts | 2 -- src/data/BlendComponent.ts | 2 -- src/data/BlendState.ts | 2 -- src/data/Buffer.ts | 2 -- src/data/CanvasContext.ts | 2 -- src/data/CanvasTexture.ts | 2 -- src/data/ColorTargetState.ts | 2 -- src/data/CommandEncoder.ts | 2 -- src/data/DepthStencilState.ts | 2 -- src/data/FragmentState.ts | 2 -- src/data/Geometry.ts | 2 -- src/data/ImageCopyTexture.ts | 5 +---- src/data/PrimitiveState.ts | 2 -- src/data/RenderPassColorAttachment.ts | 2 -- src/data/RenderPassDepthStencilAttachment.ts | 2 -- src/data/RenderPassDescriptor.ts | 2 -- src/data/RenderPipeline.ts | 2 -- src/data/Sampler.ts | 2 -- src/data/ScissorRect.ts | 2 -- src/data/StencilFaceState.ts | 2 -- src/data/Submit.ts | 2 -- src/data/Texture.ts | 20 ++++++++++++++++-- src/data/TextureView.ts | 22 +------------------- src/data/VertexAttributes.ts | 2 -- src/data/VertexState.ts | 2 -- src/data/Viewport.ts | 2 -- src/data/WriteBuffer.ts | 2 -- 27 files changed, 20 insertions(+), 75 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index cc71199..2253ce6 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -7,8 +7,6 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; */ export interface BindingResources { - __type__?: any; - [key: string]: BindingResource; } diff --git a/src/data/BlendComponent.ts b/src/data/BlendComponent.ts index b17a6e5..b9e906b 100644 --- a/src/data/BlendComponent.ts +++ b/src/data/BlendComponent.ts @@ -12,8 +12,6 @@ */ export interface BlendComponent { - __type__?: "BlendComponent"; - /** * 混合方式。 * diff --git a/src/data/BlendState.ts b/src/data/BlendState.ts index 7e131bf..5b68384 100644 --- a/src/data/BlendState.ts +++ b/src/data/BlendState.ts @@ -12,8 +12,6 @@ import { Color } from "./RenderPassColorAttachment"; */ export interface BlendState { - __type__?: "BlendState"; - /** * 混合时使用的常量值,默认为 [0,0,0,0]。 * diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index 23bdf1e..f7563f3 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -12,8 +12,6 @@ import { WriteBuffer } from "./WriteBuffer"; */ export interface GBuffer { - __type__?: "Buffer"; - /** * 标签。 * diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index 486eb08..3f9a20c 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -3,8 +3,6 @@ */ export interface CanvasContext { - __type__?: "CanvasContext"; - /** * 画布id */ diff --git a/src/data/CanvasTexture.ts b/src/data/CanvasTexture.ts index 6737ac7..5ad3990 100644 --- a/src/data/CanvasTexture.ts +++ b/src/data/CanvasTexture.ts @@ -5,8 +5,6 @@ import { CanvasContext } from "./CanvasContext"; */ export interface CanvasTexture { - __type__?: "CanvasTexture"; - /** * 画布上下文。 */ diff --git a/src/data/ColorTargetState.ts b/src/data/ColorTargetState.ts index 49ac807..73d964d 100644 --- a/src/data/ColorTargetState.ts +++ b/src/data/ColorTargetState.ts @@ -7,8 +7,6 @@ import { BlendState } from "./BlendState"; */ export interface ColorTargetState { - __type__?: "ColorTargetState"; - /** * The blending behavior for this color target. If left undefined, disables blending for this * color target. diff --git a/src/data/CommandEncoder.ts b/src/data/CommandEncoder.ts index a1465ea..ea29b80 100644 --- a/src/data/CommandEncoder.ts +++ b/src/data/CommandEncoder.ts @@ -9,8 +9,6 @@ import { RenderPass } from "./RenderPass"; */ export interface CommandEncoder { - __type__?: "CommandEncoder"; - /** * 通道编码器列表。 * diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index 968cc07..9fff8ab 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -11,8 +11,6 @@ import { ICompareFunction, StencilFaceState } from "./StencilFaceState"; */ export interface DepthStencilState { - __type__?: "DepthStencilState"; - /** * 指示这个 GPURenderPipeline 是否可以修改 depthStencilAttachment 深度值。 * diff --git a/src/data/FragmentState.ts b/src/data/FragmentState.ts index be66cb0..db702d5 100644 --- a/src/data/FragmentState.ts +++ b/src/data/FragmentState.ts @@ -7,8 +7,6 @@ import { ColorTargetState } from "./ColorTargetState"; */ export interface FragmentState { - __type__?: "FragmentState"; - /** * 着色器代码。 */ diff --git a/src/data/Geometry.ts b/src/data/Geometry.ts index a4d905c..385166f 100644 --- a/src/data/Geometry.ts +++ b/src/data/Geometry.ts @@ -14,8 +14,6 @@ import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; */ export interface Geometry { - __type__?: "Geometry"; - /** * Describes the primitive-related properties of the pipeline. * diff --git a/src/data/ImageCopyTexture.ts b/src/data/ImageCopyTexture.ts index ff42f76..4f62594 100644 --- a/src/data/ImageCopyTexture.ts +++ b/src/data/ImageCopyTexture.ts @@ -1,5 +1,4 @@ -import { TextureOrigin, Texture } from "./Texture"; -import { TextureLike } from "./TextureView"; +import { TextureLike, TextureOrigin } from "./Texture"; /** * 被操作的纹理相关信息。 @@ -9,8 +8,6 @@ import { TextureLike } from "./TextureView"; */ export interface ImageCopyTexture { - __type__?: "ImageCopyTexture"; - /** * Texture to copy to/from. */ diff --git a/src/data/PrimitiveState.ts b/src/data/PrimitiveState.ts index 19ee77a..e4a03e0 100644 --- a/src/data/PrimitiveState.ts +++ b/src/data/PrimitiveState.ts @@ -7,8 +7,6 @@ */ export interface PrimitiveState { - __type__?: "PrimitiveState"; - /** * The type of primitive to be constructed from the vertex inputs. * diff --git a/src/data/RenderPassColorAttachment.ts b/src/data/RenderPassColorAttachment.ts index f7970f2..c708709 100644 --- a/src/data/RenderPassColorAttachment.ts +++ b/src/data/RenderPassColorAttachment.ts @@ -5,8 +5,6 @@ import { TextureView } from "./TextureView"; */ export interface RenderPassColorAttachment { - __type__?: "RenderPassColorAttachment"; - /** * 颜色附件视图。 * diff --git a/src/data/RenderPassDepthStencilAttachment.ts b/src/data/RenderPassDepthStencilAttachment.ts index 77573f9..3341033 100644 --- a/src/data/RenderPassDepthStencilAttachment.ts +++ b/src/data/RenderPassDepthStencilAttachment.ts @@ -5,8 +5,6 @@ import { TextureView } from "./TextureView"; */ export interface RenderPassDepthStencilAttachment { - __type__?: "RenderPassDepthStencilAttachment"; - /** * 深度附件视图。 * diff --git a/src/data/RenderPassDescriptor.ts b/src/data/RenderPassDescriptor.ts index f571aa2..3f44a05 100644 --- a/src/data/RenderPassDescriptor.ts +++ b/src/data/RenderPassDescriptor.ts @@ -6,8 +6,6 @@ import { RenderPassDepthStencilAttachment } from "./RenderPassDepthStencilAttach */ export interface RenderPassDescriptor { - __type__?: "RenderPassDescriptor"; - /** * 标签。 * diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index 188054c..601e5cc 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -9,8 +9,6 @@ import { VertexState } from "./VertexState"; */ export interface RenderPipeline { - __type__?: "RenderPipeline"; - /** * 标签。 * diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index c30d42d..d7ddee1 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -12,8 +12,6 @@ import { ICompareFunction } from "./StencilFaceState"; */ export interface Sampler { - __type__?: "Sampler"; - /** * 标签。 * diff --git a/src/data/ScissorRect.ts b/src/data/ScissorRect.ts index 5ddc496..f4d9996 100644 --- a/src/data/ScissorRect.ts +++ b/src/data/ScissorRect.ts @@ -17,8 +17,6 @@ */ export interface ScissorRect { - __type__?: "ScissorRect"; - /** * 是否为Y轴朝上。 * diff --git a/src/data/StencilFaceState.ts b/src/data/StencilFaceState.ts index 9706ee5..e82cc0e 100644 --- a/src/data/StencilFaceState.ts +++ b/src/data/StencilFaceState.ts @@ -5,8 +5,6 @@ */ export interface StencilFaceState { - __type__?: "StencilFaceState"; - /** * 在测试片元与 depthStencilAttachment 模板值时使用的 GPUCompareFunction。 * diff --git a/src/data/Submit.ts b/src/data/Submit.ts index ba3390f..9a05068 100644 --- a/src/data/Submit.ts +++ b/src/data/Submit.ts @@ -7,8 +7,6 @@ import { CommandEncoder } from "./CommandEncoder"; */ export interface Submit { - __type__?: "Submit"; - /** * 命令编码器列表。 */ diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 010615e..6cbb607 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -1,13 +1,29 @@ import { TextureDataSource } from "./TextureDataSource"; import { TextureImageSource } from "./TextureImageSource"; +/** + * 类似纹理,包含画布纹理以及正常纹理。 + * + * 如需扩展 ITextureLike,则需在 ITextureMap 中添加类型。 + */ +export type TextureLike = TextureLikeMap[keyof TextureLikeMap]; + +/** + * 如需扩展 ITextureLike,则需在 ITextureMap 中添加类型。 + */ +export interface TextureLikeMap +{ + /** + * 正常纹理。 + */ + Texture: Texture; +} + /** * 纹理 */ export interface Texture { - __type__?: "Texture"; - /** * 标签。 * diff --git a/src/data/TextureView.ts b/src/data/TextureView.ts index 158de4c..da6fd2c 100644 --- a/src/data/TextureView.ts +++ b/src/data/TextureView.ts @@ -1,12 +1,10 @@ -import { Texture } from "./Texture"; +import { TextureLike } from "./Texture"; /** * 纹理视图。 */ export interface TextureView { - __type__?: "TextureView"; - /** * 标签。 * @@ -33,21 +31,3 @@ export interface TextureView */ readonly baseArrayLayer?: number; } - -/** - * 类似纹理,包含画布纹理以及正常纹理。 - * - * 如需扩展 ITextureLike,则需在 ITextureMap 中添加类型。 - */ -export type TextureLike = TextureLikeMap[keyof TextureLikeMap]; - -/** - * 如需扩展 ITextureLike,则需在 ITextureMap 中添加类型。 - */ -export interface TextureLikeMap -{ - /** - * 正常纹理。 - */ - Texture: Texture; -} \ No newline at end of file diff --git a/src/data/VertexAttributes.ts b/src/data/VertexAttributes.ts index e2e44cd..fdd8fa9 100644 --- a/src/data/VertexAttributes.ts +++ b/src/data/VertexAttributes.ts @@ -5,8 +5,6 @@ import { vertexFormatMap } from "../consts/vertexFormatMap"; */ export interface VertexAttributes { - __type__?: any; - [name: string]: VertexAttribute; } diff --git a/src/data/VertexState.ts b/src/data/VertexState.ts index 21335b7..033479e 100644 --- a/src/data/VertexState.ts +++ b/src/data/VertexState.ts @@ -3,8 +3,6 @@ */ export interface VertexState { - __type__?: "VertexState"; - /** * 着色器代码。 */ diff --git a/src/data/Viewport.ts b/src/data/Viewport.ts index a149698..4676c45 100644 --- a/src/data/Viewport.ts +++ b/src/data/Viewport.ts @@ -20,8 +20,6 @@ */ export interface Viewport { - __type__?: "Viewport"; - /** * 是否为Y轴朝上。 * diff --git a/src/data/WriteBuffer.ts b/src/data/WriteBuffer.ts index 2b65666..98bdb5d 100644 --- a/src/data/WriteBuffer.ts +++ b/src/data/WriteBuffer.ts @@ -2,8 +2,6 @@ import { TypedArray } from "../types/TypedArray"; export interface WriteBuffer { - __type__?: "WriteBuffer"; - /** * GPU缓冲区写入起始位置。 */ -- Gitee From aea2ae05a717ea5937d06f5c32d4b0efd9463fc5 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 14 Mar 2025 23:09:53 +0800 Subject: [PATCH 07/80] =?UTF-8?q?refactor:=20=E5=9C=A8=20index.ts=20?= =?UTF-8?q?=E4=B8=AD=E5=AF=BC=E5=85=A5=20global=20=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global.ts | 8 ++++++++ src/index.ts | 1 + 2 files changed, 9 insertions(+) create mode 100644 src/global.ts diff --git a/src/global.ts b/src/global.ts new file mode 100644 index 0000000..0777368 --- /dev/null +++ b/src/global.ts @@ -0,0 +1,8 @@ +export { }; +declare global +{ + /** + * 是否为开发模式。 + */ + var __DEV__: boolean; +} diff --git a/src/index.ts b/src/index.ts index 7930ed0..802e8f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,3 +46,4 @@ export * from "./internal/BufferBindingInfo"; export * from "./types/TypedArray"; export * from "./types/UnReadonly"; +import "./global" \ No newline at end of file -- Gitee From 433a448b6e63360ca49ceda257f6e8cf480ce1b8 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Mar 2025 00:26:13 +0800 Subject: [PATCH 08/80] =?UTF-8?q?refactor(data):=20=E9=87=8D=E6=9E=84=20Oc?= =?UTF-8?q?clusionQuery=20=E5=92=8C=20RenderPass=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 OcclusionQuery 接口中添加了中文注释和 onQuery 回调方法 - 移除了 RenderPass 接口中的 occlusionQueryResults 属性 --- src/data/OcclusionQuery.ts | 14 +++++++------- src/data/RenderPass.ts | 7 ------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/data/OcclusionQuery.ts b/src/data/OcclusionQuery.ts index 2d9836e..4c8eac9 100644 --- a/src/data/OcclusionQuery.ts +++ b/src/data/OcclusionQuery.ts @@ -1,5 +1,8 @@ import { RenderObject } from "./RenderObject"; +/** + * 遮挡查询 + */ export interface OcclusionQuery { /** @@ -13,12 +16,9 @@ export interface OcclusionQuery renderObjects: RenderObject[]; /** - * 渲染完成后由引擎自动填充。 + * 查询结束回调。 + * + * @param result 是否被渲染。true表示被渲染,false表示未被渲染。 */ - result?: { - /** - * 查询结果。 - */ - result: number; - }; + onQuery?(result: boolean): void; } \ No newline at end of file diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index d34a58f..f3635da 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -23,13 +23,6 @@ export interface RenderPass * 渲染对象列表 */ readonly renderObjects?: readonly RenderPassObject[]; - - /** - * 渲染不被遮挡查询结果。具体数据保存在各子项的"result"属性中。 - * - * 当提交WebGL后自动获取结果后填充该属性。 - */ - occlusionQueryResults?: OcclusionQuery[]; } export type RenderPassObject = RenderPassObjectMap[keyof RenderPassObjectMap]; -- Gitee From fc8c0c601b6275a932a38039c91d0d542bb658ec Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Mar 2025 00:42:44 +0800 Subject: [PATCH 09/80] =?UTF-8?q?feat(data):=20=E4=BC=98=E5=8C=96=E9=81=AE?= =?UTF-8?q?=E6=8C=A1=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 OcclusionQuery 接口中的 onQuery 方法的参数类型从 boolean 改为 number - 在 RenderPass 接口中添加 onOcclusionQuery 方法,用于处理遮挡查询结果 --- src/data/OcclusionQuery.ts | 2 +- src/data/RenderPass.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/data/OcclusionQuery.ts b/src/data/OcclusionQuery.ts index 4c8eac9..a8f960d 100644 --- a/src/data/OcclusionQuery.ts +++ b/src/data/OcclusionQuery.ts @@ -20,5 +20,5 @@ export interface OcclusionQuery * * @param result 是否被渲染。true表示被渲染,false表示未被渲染。 */ - onQuery?(result: boolean): void; + onQuery?(result: number): void; } \ No newline at end of file diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index f3635da..10826ab 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -23,6 +23,14 @@ export interface RenderPass * 渲染对象列表 */ readonly renderObjects?: readonly RenderPassObject[]; + + /** + * 当渲染通道中存在遮挡查询时,在查询结束后调用该函数返回查询结果。 + * + * @param occlusionQuerys 遮挡查询列表 + * @param results 是否被渲染。true表示被渲染,false表示未被渲染。 + */ + onOcclusionQuery?(occlusionQuerys: OcclusionQuery[], results: number[]): void; } export type RenderPassObject = RenderPassObjectMap[keyof RenderPassObjectMap]; -- Gitee From 165d051acbd04655d73d6b9d43d0c4900124af46 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 15 Mar 2025 20:45:12 +0800 Subject: [PATCH 10/80] =?UTF-8?q?refactor(data):=20=E6=9B=B4=E6=96=B0=20Co?= =?UTF-8?q?mmandEncoder=20=E6=8E=A5=E5=8F=A3=E5=8F=8A=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 IPassEncoder 重命名为 PassEncoder - 更新 CommandEncoder 接口中的 passEncoders 类型 - 修改 PassEncoderMap 中的键值类型 --- src/data/CommandEncoder.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data/CommandEncoder.ts b/src/data/CommandEncoder.ts index ea29b80..b311f3e 100644 --- a/src/data/CommandEncoder.ts +++ b/src/data/CommandEncoder.ts @@ -14,7 +14,7 @@ export interface CommandEncoder * * 包括计算通道编码器、渲染通道编码器 以及 GPU中缓存与纹理之间拷贝。 */ - passEncoders: IPassEncoder[] + passEncoders: PassEncoder[] } /** @@ -22,7 +22,7 @@ export interface CommandEncoder * * 如需扩展 IPassEncoder ,请在 PassEncoderMap 中进行添加。 */ -export type IPassEncoder = PassEncoderMap[keyof PassEncoderMap]; +export type PassEncoder = PassEncoderMap[keyof PassEncoderMap]; /** * 如需扩展 IPassEncoder ,请在 PassEncoderMap 中进行添加。 @@ -32,13 +32,13 @@ export interface PassEncoderMap /** * 渲染通道。 */ - IRenderPass: RenderPass; + RenderPass: RenderPass; /** * 纹理之间拷贝。 */ - ICopyTextureToTexture: CopyTextureToTexture; + CopyTextureToTexture: CopyTextureToTexture; - ICopyBufferToBuffer: CopyBufferToBuffer; + CopyBufferToBuffer: CopyBufferToBuffer; } -- Gitee From a75cd0a0b2340bc0b112bf88cf6af987f87c1559 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 16 Mar 2025 13:23:50 +0800 Subject: [PATCH 11/80] =?UTF-8?q?refactor(data):=20=E6=89=A9=E5=B1=95=20Ca?= =?UTF-8?q?nvasContext=20=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 CanvasContext 接口中的 canvasId 属性类型 - 允许 canvasId 是字符串、HTMLCanvasElement 或 OffscreenCanvas 类型 - 添加属性注释以解释其可能的用途 --- src/data/CanvasContext.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index 3f9a20c..5722931 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -4,7 +4,9 @@ export interface CanvasContext { /** - * 画布id + * 画布。 + * + * 可能是画布的编号,也可能是画布元素或者离屏画布。 */ - readonly canvasId: string; + readonly canvasId: string | HTMLCanvasElement | OffscreenCanvas; } -- Gitee From b2794a34229b33a1f769b961feb7eb817d719f10 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 16 Mar 2025 17:26:15 +0800 Subject: [PATCH 12/80] =?UTF-8?q?feat(export):=20=E6=B7=BB=E5=8A=A0=20Chai?= =?UTF-8?q?nMap=20=E5=AE=9E=E7=94=A8=E5=B7=A5=E5=85=B7=E7=9A=84=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 src/index.ts 文件中添加了对 ChainMap 工具的导出,使得外部可以更方便地使用 ChainMap 功能。 --- src/index.ts | 2 ++ src/utils/ChainMap.ts | 79 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/utils/ChainMap.ts diff --git a/src/index.ts b/src/index.ts index 802e8f5..6c183f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,4 +46,6 @@ export * from "./internal/BufferBindingInfo"; export * from "./types/TypedArray"; export * from "./types/UnReadonly"; +export * from "./utils/ChainMap"; + import "./global" \ No newline at end of file diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts new file mode 100644 index 0000000..067a6f9 --- /dev/null +++ b/src/utils/ChainMap.ts @@ -0,0 +1,79 @@ +/** + * 链式Map。 + * + * 多个key数组对应一个值。 + * + * 由于键值可能是字面值也可能是对象,因此无法使用 {@link WeakMap} 来构建{@link ChainMap},只能使用 {@link Map}。 + */ +export class ChainMap, V> +{ + private _map: Map | WeakMap; + + /** + * 获取键对应的值。 + * + * @param keys 键。 + * @returns 值。 + */ + get(keys: K): V + { + if (!this._map) return undefined; + let map = this._map; + + for (let i = 0, n = keys.length - 1; i < n; i++) + { + map = map.get(keys[i]); + + if (map === undefined) return undefined; + } + + return map.get(keys[keys.length - 1]); + } + + /** + * 设置映射。 + * + * @param keys 键。 + * @param value 值。 + */ + set(keys: K, value: V) + { + let map = this._map = this._map || ((typeof keys[0] === "string") ? new Map() : new WeakMap()); + + for (let i = 0; i < keys.length - 1; i++) + { + const key = keys[i]; + + if (!map.has(key)) + { + map.set(key, typeof key === "string" ? new Map() : new WeakMap()); + } + + map = map.get(key); + } + + map.set(keys[keys.length - 1], value); + } + + /** + * 删除映射。 + * + * @param keys 键。 + * @returns 如果找到目标值且被删除返回 `true` ,否则返回 `false` 。 + */ + delete(keys: K): boolean + { + if (!this._map) return false; + let map = this._map; + + for (let i = 0; i < keys.length - 1; i++) + { + map = map.get(keys[i]); + + if (map === undefined) return false; + } + + return map.delete(keys[keys.length - 1]); + } +} + -- Gitee From ac772903d3ebe6264b3c0256efe2cc237b333773 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 16 Mar 2025 20:26:08 +0800 Subject: [PATCH 13/80] =?UTF-8?q?refactor(utils):=20=E4=BC=98=E5=8C=96=20C?= =?UTF-8?q?hainMap=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 初始化 _map 属性为新的 Map 实例,移除条件判断 - 在 set 方法中简化了 map 实例的创建逻辑,统一使用 Map - 删除了 get 和 delete 方法中对 _map 的空值检查,因为现在 _map 总是会被初始化 --- src/utils/ChainMap.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 067a6f9..798c14e 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -7,7 +7,7 @@ */ export class ChainMap, V> { - private _map: Map | WeakMap; + private _map = new Map(); /** * 获取键对应的值。 @@ -17,7 +17,6 @@ export class ChainMap, V> */ get(keys: K): V { - if (!this._map) return undefined; let map = this._map; for (let i = 0, n = keys.length - 1; i < n; i++) @@ -38,7 +37,7 @@ export class ChainMap, V> */ set(keys: K, value: V) { - let map = this._map = this._map || ((typeof keys[0] === "string") ? new Map() : new WeakMap()); + let map = this._map; for (let i = 0; i < keys.length - 1; i++) { @@ -46,7 +45,7 @@ export class ChainMap, V> if (!map.has(key)) { - map.set(key, typeof key === "string" ? new Map() : new WeakMap()); + map.set(key, new Map()); } map = map.get(key); @@ -63,7 +62,6 @@ export class ChainMap, V> */ delete(keys: K): boolean { - if (!this._map) return false; let map = this._map; for (let i = 0; i < keys.length - 1; i++) -- Gitee From 719f2ec47cc762703777da3c19b29159d4e8a91a Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 16 Mar 2025 23:43:51 +0800 Subject: [PATCH 14/80] =?UTF-8?q?refactor(data):=20=E5=B0=86=20FragmentSta?= =?UTF-8?q?te=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=20code=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=A0=87=E8=AE=B0=E4=B8=BA=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 FragmentState.ts 文件中,将 code 属性从 string 类型改为 readonly string 类型 - 这个改动确保了 FragmentState 实例的 code 属性在创建后不可修改,提高了代码的健壮性和可维护性 --- src/data/FragmentState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/FragmentState.ts b/src/data/FragmentState.ts index db702d5..e21ada0 100644 --- a/src/data/FragmentState.ts +++ b/src/data/FragmentState.ts @@ -10,7 +10,7 @@ export interface FragmentState /** * 着色器代码。 */ - code: string; + readonly code: string; /** * A list of {@link GPUColorTargetState} defining the formats and behaviors of the color targets -- Gitee From eb9611cba3eab0968128ac6b2d311726c116e2a8 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Mon, 17 Mar 2025 23:01:36 +0800 Subject: [PATCH 15/80] =?UTF-8?q?refactor(data):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=20IWriteMask=20=E4=B8=BA=20WriteMask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了 IWriteMask 接口名称中的 "I" 前缀 - 更新了 ColorTargetState 接口中的 writeMask 属性类型引用 --- src/data/ColorTargetState.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/ColorTargetState.ts b/src/data/ColorTargetState.ts index 73d964d..52fedb3 100644 --- a/src/data/ColorTargetState.ts +++ b/src/data/ColorTargetState.ts @@ -26,7 +26,7 @@ export interface ColorTargetState * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask */ - readonly writeMask?: IWriteMask; + readonly writeMask?: WriteMask; } -export type IWriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean]; +export type WriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean]; -- Gitee From dff052a94c07374c1b3779fc4fe7ae21d4222f1b Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 18 Mar 2025 12:13:47 +0800 Subject: [PATCH 16/80] =?UTF-8?q?refactor(data):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3=E5=B9=B6=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E5=87=BD=E6=95=B0=E5=92=8C=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 ICompareFunction 和 IStencilOperation 重命名为 CompareFunction 和 StencilOperation - 在 DepthStencilState、Geometry、RenderPipeline、Sampler 和 VertexState 中更新相关引用 - 从 StencilFaceState 中导出 CompareFunction 和 StencilOperation - 在 reactivity.ts 中添加 toRaw 函数引用 --- src/data/DepthStencilState.ts | 4 ++-- src/data/Geometry.ts | 7 ------- src/data/RenderPipeline.ts | 13 +++++++++++-- src/data/Sampler.ts | 4 ++-- src/data/StencilFaceState.ts | 12 ++++++------ src/data/VertexState.ts | 2 +- src/reactivity.ts | 7 ++++++- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index 9fff8ab..7d1fe47 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -1,4 +1,4 @@ -import { ICompareFunction, StencilFaceState } from "./StencilFaceState"; +import { CompareFunction as CompareFunction, StencilFaceState } from "./StencilFaceState"; /** * 深度模板阶段描述。 @@ -27,7 +27,7 @@ export interface DepthStencilState * * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc */ - readonly depthCompare?: ICompareFunction; + readonly depthCompare?: CompareFunction; /** * 定义了如何为朝前的图元执行模板比较和操作。 diff --git a/src/data/Geometry.ts b/src/data/Geometry.ts index 385166f..2f91a72 100644 --- a/src/data/Geometry.ts +++ b/src/data/Geometry.ts @@ -14,13 +14,6 @@ import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; */ export interface Geometry { - /** - * Describes the primitive-related properties of the pipeline. - * - * 图元拓扑结构。 - */ - primitive?: PrimitiveState; - /** * 顶点属性数据映射。 */ diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index 601e5cc..948c12d 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -1,5 +1,7 @@ +import { readonly } from "@vue/reactivity"; import { DepthStencilState } from "./DepthStencilState"; import { FragmentState } from "./FragmentState"; +import { PrimitiveState } from "./PrimitiveState"; import { VertexState } from "./VertexState"; /** @@ -19,12 +21,19 @@ export interface RenderPipeline /** * 顶点着色器阶段描述。 */ - vertex: VertexState; + readonly vertex: VertexState; /** * 片段着色器阶段描述。 */ - fragment?: FragmentState; + readonly fragment?: FragmentState; + + /** + * Describes the primitive-related properties of the pipeline. + * + * 图元拓扑结构。 + */ + readonly primitive?: PrimitiveState; /** * 深度模板阶段描述。 diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index d7ddee1..ed7627f 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -1,4 +1,4 @@ -import { ICompareFunction } from "./StencilFaceState"; +import { CompareFunction } from "./StencilFaceState"; /** * 纹理采样器。 @@ -115,7 +115,7 @@ export interface Sampler * * 注:比较采样器可能会使用过滤,但采样结果将是 依赖于实现并且可能不同于正常的过滤规则。 */ - compare?: ICompareFunction; + compare?: CompareFunction; } /** diff --git a/src/data/StencilFaceState.ts b/src/data/StencilFaceState.ts index e82cc0e..94cde7d 100644 --- a/src/data/StencilFaceState.ts +++ b/src/data/StencilFaceState.ts @@ -10,30 +10,30 @@ export interface StencilFaceState * * 默认为 "always"。 */ - readonly compare?: ICompareFunction; + readonly compare?: CompareFunction; /** * 如果片元模板比较测试(由 compare 描述)失败,则执行的 GPUStencilOperation。 * * 默认为 "keep"。 */ - readonly failOp?: IStencilOperation; + readonly failOp?: StencilOperation; /** * 如果由 depthCompare 描述的片元深度比较失败,则执行的 GPUStencilOperation。 * * 默认为 "keep"。 */ - readonly depthFailOp?: IStencilOperation; + readonly depthFailOp?: StencilOperation; /** * 如果片元模板比较测试通过,则执行由compare描述的GPUStencilOperation。 * * 默认为 "keep"。 */ - readonly passOp?: IStencilOperation; + readonly passOp?: StencilOperation; } -export type ICompareFunction = "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 IStencilOperation = "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/VertexState.ts b/src/data/VertexState.ts index 033479e..ec5a64c 100644 --- a/src/data/VertexState.ts +++ b/src/data/VertexState.ts @@ -6,5 +6,5 @@ export interface VertexState /** * 着色器代码。 */ - code: string; + readonly code: string; } \ No newline at end of file diff --git a/src/reactivity.ts b/src/reactivity.ts index a6b45bc..77016ed 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -1,5 +1,5 @@ import { UnReadonly } from "@feng3d/render-api"; -import { reactive as vueReactive } from "@vue/reactivity"; +import { toRaw as vueToRaw, reactive as vueReactive } from "@vue/reactivity"; export { computed, type ComputedRef, effect } from "@vue/reactivity"; @@ -10,3 +10,8 @@ export { computed, type ComputedRef, effect } from "@vue/reactivity"; */ export const reactive: (target: T) => UnReadonly = vueReactive as any; +/** + * Vue原始数据。 + * + */ +export const toRaw: (observed: T) => T = vueToRaw as any; -- Gitee From 92a12e81784646c9f1a18c27776713652cca2427 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Tue, 18 Mar 2025 16:29:47 +0800 Subject: [PATCH 17/80] =?UTF-8?q?refactor(data):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=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 - 在 ColorTargetState 和 PrimitiveState 接口中添加 readonly 修饰符,提高代码的不可变性和安全性 - 在 WriteMask 类型中添加 readonly 修饰符,确保数组类型的安全使用 - 移除未使用的 import 语句,清理无用代码 - 在 VertexState 接口中移除 readonly 修饰符,允许 code 属性的修改 --- src/data/ColorTargetState.ts | 4 ++-- src/data/PrimitiveState.ts | 6 +++--- src/data/RenderPipeline.ts | 1 - src/data/VertexState.ts | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/data/ColorTargetState.ts b/src/data/ColorTargetState.ts index 52fedb3..e421f6e 100644 --- a/src/data/ColorTargetState.ts +++ b/src/data/ColorTargetState.ts @@ -15,7 +15,7 @@ export interface ColorTargetState * * 默认 `undefined`,表示不进行混合。 */ - blend?: BlendState; + readonly blend?: BlendState; /** * 控制那些颜色分量是否可以被写入到颜色中。 @@ -29,4 +29,4 @@ export interface ColorTargetState readonly writeMask?: WriteMask; } -export type WriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean]; +export type WriteMask = readonly [red: boolean, green: boolean, blue: boolean, alpha: boolean]; diff --git a/src/data/PrimitiveState.ts b/src/data/PrimitiveState.ts index e4a03e0..b2f77d8 100644 --- a/src/data/PrimitiveState.ts +++ b/src/data/PrimitiveState.ts @@ -24,7 +24,7 @@ export interface PrimitiveState * * LINE_LOOP 绘制循环连线。 * * TRIANGLE_FAN 绘制三角扇形。 */ - topology?: PrimitiveTopology; + readonly topology?: PrimitiveTopology; /** * Defines which polygon orientation will be culled, if any. @@ -37,14 +37,14 @@ export interface PrimitiveState * * `front` 剔除正面 * * `back` 剔除背面 */ - cullFace?: CullFace; + readonly cullFace?: CullFace; /** * Defines which polygons are considered front-facing. * * 正向方向。默认 "ccw",表示三角形逆时针方向为正面。 */ - frontFace?: FrontFace; + readonly frontFace?: FrontFace; } /** diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index 948c12d..f68d53b 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -1,4 +1,3 @@ -import { readonly } from "@vue/reactivity"; import { DepthStencilState } from "./DepthStencilState"; import { FragmentState } from "./FragmentState"; import { PrimitiveState } from "./PrimitiveState"; diff --git a/src/data/VertexState.ts b/src/data/VertexState.ts index ec5a64c..033479e 100644 --- a/src/data/VertexState.ts +++ b/src/data/VertexState.ts @@ -6,5 +6,5 @@ export interface VertexState /** * 着色器代码。 */ - readonly code: string; + code: string; } \ No newline at end of file -- Gitee From 36cef6cac464bc9f4b66dfc66385a43a9da891f7 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 19 Mar 2025 10:17:56 +0800 Subject: [PATCH 18/80] =?UTF-8?q?refactor(data):=20=E4=BD=BF=20VertexState?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=20code=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=B8=BA=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/VertexState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/VertexState.ts b/src/data/VertexState.ts index 033479e..ec5a64c 100644 --- a/src/data/VertexState.ts +++ b/src/data/VertexState.ts @@ -6,5 +6,5 @@ export interface VertexState /** * 着色器代码。 */ - code: string; + readonly code: string; } \ No newline at end of file -- Gitee From 3eeb5e24145e9abe094ebff96ab204a34ad04835 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 19 Mar 2025 12:20:42 +0800 Subject: [PATCH 19/80] =?UTF-8?q?feat(ChainMap):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=94=AE=E9=95=BF=E5=BA=A6=E5=A4=84=E7=90=86=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 _keyLength 属性以存储键长度 - 在 set 和 delete 方法中添加对键长度的断言 - 优化 get、set 和 delete 方法中的循环逻辑 - 提高代码可读性和性能 --- src/utils/ChainMap.ts | 48 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 798c14e..6cc6e56 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -7,7 +7,14 @@ */ export class ChainMap, V> { + /** + * 根字典。 + */ private _map = new Map(); + /** + * 键长度。 + */ + private _keyLength: number; /** * 获取键对应的值。 @@ -17,16 +24,22 @@ export class ChainMap, V> */ get(keys: K): V { + __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); + + const keysLength = keys.length; let map = this._map; + let key: any; - for (let i = 0, n = keys.length - 1; i < n; i++) + for (let i = 0, n = keysLength - 1; i < n; i++) { - map = map.get(keys[i]); + key = keys[i]; + map = map.get(key); if (map === undefined) return undefined; } - return map.get(keys[keys.length - 1]); + key = keys[keysLength - 1]; + return map.get(key); } /** @@ -34,14 +47,21 @@ export class ChainMap, V> * * @param keys 键。 * @param value 值。 + * + * @returns 返回设置的值。 */ set(keys: K, value: V) { + this._keyLength ??= keys.length; + __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); + + const keysLength = keys.length; let map = this._map; + let key: any; - for (let i = 0; i < keys.length - 1; i++) + for (let i = 0; i < keysLength - 1; i++) { - const key = keys[i]; + key = keys[i]; if (!map.has(key)) { @@ -51,7 +71,10 @@ export class ChainMap, V> map = map.get(key); } - map.set(keys[keys.length - 1], value); + key = keys[keysLength - 1]; + map.set(key, value); + + return value; } /** @@ -62,16 +85,21 @@ export class ChainMap, V> */ delete(keys: K): boolean { + __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); + + const keysLength = keys.length; let map = this._map; + let key: any; - for (let i = 0; i < keys.length - 1; i++) + for (let i = 0; i < keysLength - 1; i++) { - map = map.get(keys[i]); + key = keys[i]; + map = map.get(key); if (map === undefined) return false; } - return map.delete(keys[keys.length - 1]); + key = keys[keysLength - 1]; + return map.delete(key); } } - -- Gitee From 4edb5c88bf0d9db4a58e6f993ec48a7d5f308d39 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 19 Mar 2025 15:47:07 +0800 Subject: [PATCH 20/80] =?UTF-8?q?fix(utils):=20=E4=BF=AE=E5=A4=8D=20ChainM?= =?UTF-8?q?ap=20=E5=9C=A8=E6=9C=AA=E8=AE=BE=E7=BD=AE=E9=94=AE=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 get 和 delete 方法中添加了对 _keyLength 为 0 的判断 - 避免在未设置键长度时执行后续操作,提高代码的健壮性 --- src/utils/ChainMap.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 6cc6e56..7915ba8 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -24,6 +24,7 @@ export class ChainMap, V> */ get(keys: K): V { + if (!this._keyLength) return undefined; __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); const keysLength = keys.length; @@ -85,6 +86,7 @@ export class ChainMap, V> */ delete(keys: K): boolean { + if (!this._keyLength) return false; __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); const keysLength = keys.length; -- Gitee From b6497393b91ee6d225621bc70c22f3cf533ee724 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 19 Mar 2025 16:07:15 +0800 Subject: [PATCH 21/80] =?UTF-8?q?refactor(utils):=20=E7=A7=BB=E9=99=A4=20C?= =?UTF-8?q?hainMap=20=E4=B8=AD=E7=9A=84=E9=94=AE=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了 ChainMap 类中用于限制键长度的代码,包括: - 删除了 _keyLength 属性 - 移除了 get、set 和 delete 方法中关于键长度的检查和断言 这些更改简化了代码结构,并消除了不必要的限制。 --- src/utils/ChainMap.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 7915ba8..99e9ad5 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -11,10 +11,6 @@ export class ChainMap, V> * 根字典。 */ private _map = new Map(); - /** - * 键长度。 - */ - private _keyLength: number; /** * 获取键对应的值。 @@ -24,9 +20,6 @@ export class ChainMap, V> */ get(keys: K): V { - if (!this._keyLength) return undefined; - __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); - const keysLength = keys.length; let map = this._map; let key: any; @@ -53,9 +46,6 @@ export class ChainMap, V> */ set(keys: K, value: V) { - this._keyLength ??= keys.length; - __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); - const keysLength = keys.length; let map = this._map; let key: any; @@ -86,9 +76,6 @@ export class ChainMap, V> */ delete(keys: K): boolean { - if (!this._keyLength) return false; - __DEV__ && console.assert(keys.length === this._keyLength, `键长度必须为${this._keyLength}。`); - const keysLength = keys.length; let map = this._map; let key: any; -- Gitee From 8e2041f35374c70d566f329738d90c1ee54dc609 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 00:27:09 +0800 Subject: [PATCH 22/80] =?UTF-8?q?refactor(data):=20=E4=B8=BA=20Texture=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20readonly=20=E4=BF=AE=E9=A5=B0=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Texture 接口中,将 size、sources 和 writeTextures 属性标记为 readonly - 这样做可以更好地表达这些属性的不可变性,提高代码的可读性和安全性 - 在文件顶部添加了对 @vue/reactivity 的 readonly 函数的导入 --- src/data/Texture.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 6cbb607..48e9a9b 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -1,3 +1,4 @@ +import { readonly } from "@vue/reactivity"; import { TextureDataSource } from "./TextureDataSource"; import { TextureImageSource } from "./TextureImageSource"; @@ -38,7 +39,7 @@ export interface Texture * * 修改尺寸将会引发纹理销毁,使用时重新创建新纹理。 */ - size: TextureSize; + readonly size: TextureSize; /** * 初始化纹理资源。 @@ -51,7 +52,7 @@ export interface Texture * @see GPUQueue.copyExternalImageToTexture * @see GPUQueue.writeTexture */ - sources?: readonly TextureSource[]; + readonly sources?: readonly TextureSource[]; /** * 初始化纹理后是否生成mipmap @@ -69,7 +70,7 @@ export interface Texture * @see GPUQueue.copyExternalImageToTexture * @see GPUQueue.writeTexture */ - writeTextures?: readonly TextureSource[]; + readonly writeTextures?: readonly TextureSource[]; /** * 纹理维度,默认为 "2d" 。 -- Gitee From c7977e9ea7cb833bdbfaaf4f41d096eebedd8a61 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 11:38:16 +0800 Subject: [PATCH 23/80] =?UTF-8?q?refactor(data):=20=E4=B8=BA=20Sampler=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20readonly=20=E4=BF=AE=E9=A5=B0=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Sampler.ts 文件中,为 Sampler 接口的所有属性添加了 readonly 修饰符 - 这个改动使得这些属性在创建后不可更改,提高了代码的健壮性和可维护性 - 受影响的属性包括 addressModeU、addressModeV、addressModeW、magFilter、minFilter、mipmapFilter、maxAnisotropy、lodMinClamp、lodMaxClamp 和 compare --- src/data/Sampler.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index ed7627f..aa84604 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -1,3 +1,4 @@ +import { readonly } from "@vue/reactivity"; import { CompareFunction } from "./StencilFaceState"; /** @@ -27,7 +28,7 @@ export interface Sampler * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_s * @see https://gpuweb.github.io/gpuweb/#dom-gpusamplerdescriptor-addressmodeu */ - addressModeU?: IAddressMode; + readonly addressModeU?: IAddressMode; /** * 用于指定纹理在垂直方向(即T或V坐标轴)上的寻址模式。 @@ -37,7 +38,7 @@ export interface Sampler * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_t * @see https://gpuweb.github.io/gpuweb/#dom-gpusamplerdescriptor-addressmodev */ - addressModeV?: IAddressMode; + readonly addressModeV?: IAddressMode; /** * 用于指定纹理在深度方向(即R或W坐标轴)上的寻址模式。用于3D纹理或者纹理数组。 @@ -47,7 +48,7 @@ export interface Sampler * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_r * @see https://gpuweb.github.io/gpuweb/#dom-gpusamplerdescriptor-addressmodew */ - addressModeW?: IAddressMode; + readonly addressModeW?: IAddressMode; /** * 指定样本足迹小于或等于一个纹素时的采样行为 @@ -57,7 +58,7 @@ export interface Sampler * @see https://www.orillusion.com/zh/webgpu.html#dom-gpusamplerdescriptor-magfilter * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_mag_filter */ - magFilter?: IFilterMode; + readonly magFilter?: IFilterMode; /** * 指定样本足迹大于一个纹素时的采样行为。 @@ -69,7 +70,7 @@ export interface Sampler * @see https://www.orillusion.com/zh/webgpu.html#dom-gpusamplerdescriptor-minfilter * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_min_filter */ - minFilter?: IFilterMode; + readonly minFilter?: IFilterMode; /** * 指定在 mipmap 级别之间进行采样的行为。 @@ -79,12 +80,14 @@ export interface Sampler * @see https://www.orillusion.com/zh/webgpu.html#dom-gpusamplerdescriptor-mipmapfilter * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_min_filter */ - mipmapFilter?: IMipmapFilterMode; + readonly mipmapFilter?: IMipmapFilterMode; /** * 指定采样器使用的最大各向异性值夹具。 * 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。 * + * 仅当 minFilter 、magFilter 或 mipmapFilter 为 "linear" 时才有效,否则取 1。 + * * 默认 1。 * * 注:大多数实现支持范围在1到16之间(包括1和16)的maxAnisotropy值。所使用的maxAnisotropy值将被限制在平台支持的最大值内 @@ -92,21 +95,21 @@ export interface Sampler * @see https://www.orillusion.com/zh/webgpu.html#dom-gpusamplerdescriptor-maxanisotropy * @see https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_filter_anisotropic */ - maxAnisotropy?: number; + readonly maxAnisotropy?: number; /** * 采样时使用的最小Lod等级。 * * 默认 0。 */ - lodMinClamp?: number; + readonly lodMinClamp?: number; /** * 采样时使用的最大Lod等级。 * * 默认 16 。 */ - lodMaxClamp?: number; + readonly lodMaxClamp?: number; /** * 涉及纹理比较操作时需提供,采样器将是具有指定 GPUCompareFunction 的比较采样器。 @@ -115,7 +118,7 @@ export interface Sampler * * 注:比较采样器可能会使用过滤,但采样结果将是 依赖于实现并且可能不同于正常的过滤规则。 */ - compare?: CompareFunction; + readonly compare?: CompareFunction; } /** -- Gitee From b5b25988aaf58867ec8170e9ba50f9c25dbd8e40 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 14:25:24 +0800 Subject: [PATCH 24/80] =?UTF-8?q?refactor(data):=20=E6=9B=B4=E6=96=B0=20Bi?= =?UTF-8?q?ndingResources=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 IBufferBinding 和 IBufferBindingItem 接口名称修改为 PascalCase 命名规范 - 重命名为 BufferBinding 和 BufferBindingItem,去掉前导的 "I" --- src/data/BindingResources.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index 2253ce6..3e76a8b 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -20,6 +20,6 @@ export interface BindingResourceTypeMap /** * 缓冲区绑定。 */ - IBufferBinding: BufferBinding; - IBufferBindingItem: BufferBindingItem; + BufferBinding: BufferBinding; + BufferBindingItem: BufferBindingItem; } -- Gitee From c6c43cabde8b9ab179eeeaca1f57c2fd59b1ff99 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 15:16:19 +0800 Subject: [PATCH 25/80] =?UTF-8?q?refactor(data):=20=E6=B7=BB=E5=8A=A0=20re?= =?UTF-8?q?adonly=20=E4=BF=AE=E9=A5=B0=E7=AC=A6=E4=BB=A5=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BindingResources 接口中为键值对添加 readonly 修饰符 - 在 BufferBinding 接口中为键值对添加 readonly 修饰符 - 更新 UniformDataItem 类型定义,添加 readonly 修饰符 - 更新 BufferBindingItem 类型定义,添加 readonly 修饰符 --- src/data/BindingResources.ts | 2 +- src/data/BufferBinding.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/data/BindingResources.ts b/src/data/BindingResources.ts index 3e76a8b..5a41490 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -7,7 +7,7 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; */ export interface BindingResources { - [key: string]: BindingResource; + readonly [key: string]: BindingResource; } /** diff --git a/src/data/BufferBinding.ts b/src/data/BufferBinding.ts index e1063e1..5c37ab7 100644 --- a/src/data/BufferBinding.ts +++ b/src/data/BufferBinding.ts @@ -10,7 +10,7 @@ import { TypedArray } from "../types/TypedArray"; */ export interface BufferBinding { - [name: string]: BufferBindingItem; + readonly [name: string]: BufferBindingItem; /** * 如果未设置引擎将自动生成。 @@ -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 }; -- Gitee From a03ac8f3cb6dbc6058d9f732ba7f8e236bf265a5 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 18:52:26 +0800 Subject: [PATCH 26/80] =?UTF-8?q?refactor(data):=20=E4=BF=AE=E6=94=B9=20Ge?= =?UTF-8?q?ometry=20=E7=B1=BB=E4=B8=AD=E9=A1=B6=E7=82=B9=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将接口 Geometry 中的 indices 属性类型从 IIndicesDataTypes 改为 IndicesDataTypes - 将类型定义 IIndicesDataTypes 改为 IndicesDataTypes,去掉前缀 I --- src/data/Geometry.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/Geometry.ts b/src/data/Geometry.ts index 2f91a72..92ab75d 100644 --- a/src/data/Geometry.ts +++ b/src/data/Geometry.ts @@ -22,7 +22,7 @@ export interface Geometry /** * 顶点索引数据。 */ - indices?: IIndicesDataTypes; + indices?: IndicesDataTypes; /** * 绘制。 @@ -102,7 +102,7 @@ export class Geometry /** * 顶点索引数据类型。 */ -export type IIndicesDataTypes = Uint16Array | Uint32Array; +export type IndicesDataTypes = Uint16Array | Uint32Array; /** * 绘制图形。 -- Gitee From a4dc0ef395e29631c5a712865031de2a99268e40 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 20 Mar 2025 19:05:55 +0800 Subject: [PATCH 27/80] =?UTF-8?q?refactor(data):=20=E7=A7=BB=E9=99=A4=20Ge?= =?UTF-8?q?ometry=20=E7=B1=BB=E5=B9=B6=E6=95=B4=E5=90=88=E5=85=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=88=B0=20RenderObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了 Geometry.ts 文件 - 将 Geometry 类的 getNumVertex、getInstanceCount 和 getDraw 方法移到 RenderObject 类 - 更新了 RenderObject 接口,添加了 vertices、indices 和 draw 属性 - 移除了 index.ts 中对 Geometry 的引用 --- src/data/Geometry.ts | 110 --------------------------------------- src/data/RenderObject.ts | 100 +++++++++++++++++++++++++++++++++-- src/index.ts | 1 - 3 files changed, 96 insertions(+), 115 deletions(-) delete mode 100644 src/data/Geometry.ts diff --git a/src/data/Geometry.ts b/src/data/Geometry.ts deleted file mode 100644 index 92ab75d..0000000 --- a/src/data/Geometry.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { DrawIndexed } from "./DrawIndexed"; -import { DrawVertex } from "./DrawVertex"; -import { PrimitiveState } from "./PrimitiveState"; -import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; - -/** - * 几何数据。 - * - * 包含以下数据: - * - 顶点属性数据 - * - 顶点索引数据 - * - 如何渲染 - * - 拓扑结构 - */ -export interface Geometry -{ - /** - * 顶点属性数据映射。 - */ - vertices?: VertexAttributes; - - /** - * 顶点索引数据。 - */ - indices?: IndicesDataTypes; - - /** - * 绘制。 - */ - draw?: IDraw; -} - -export class Geometry -{ - - /** - * 获取顶点数量。 - * - * @returns 顶点数量。 - */ - static getNumVertex(geometry: Geometry) - { - const attributes = geometry.vertices; - 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; - - // 验证所有顶点属性数据的顶点数量一致。 - if (vertexList.length > 0) - { - console.assert(vertexList.every((v) => count === VertexAttribute.getVertexCount(v))); - } - - return count; - } - - /** - * 获取实例数量。 - * - * @returns 实例数量。 - */ - static getInstanceCount(geometry: Geometry) - { - const attributes = geometry.vertices; - 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; - - // 验证所有顶点属性数据的顶点数量一致。 - if (vertexList.length > 0) - { - console.assert(vertexList.every((v) => count === VertexAttribute.getVertexCount(v))); - } - - return count; - } - - static getDraw(geometry: Geometry): DrawIndexed | DrawVertex - { - if (geometry['_draw']) return geometry['_draw']; - - const instanceCount = Geometry.getInstanceCount(geometry); - - if (geometry.indices) - { - return { - __type__: "DrawIndexed", - indexCount: geometry.indices.length, - firstIndex: 0, - instanceCount, - }; - } - - return { - __type__: "DrawVertex", - vertexCount: Geometry.getNumVertex(geometry), - instanceCount, - }; - } -} - -/** - * 顶点索引数据类型。 - */ -export type IndicesDataTypes = Uint16Array | Uint32Array; - -/** - * 绘制图形。 - */ -export type IDraw = DrawVertex | DrawIndexed; diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 9c95fc6..028ac12 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -1,7 +1,9 @@ -import { Geometry } from "./Geometry"; +import { BindingResources } from "./BindingResources"; +import { DrawIndexed } from "./DrawIndexed"; +import { DrawVertex } from "./DrawVertex"; import { RenderPipeline } from "./RenderPipeline"; import { ScissorRect } from "./ScissorRect"; -import { BindingResources } from "./BindingResources"; +import { VertexAttribute, VertexAttributes } from "./VertexAttributes"; import { Viewport } from "./Viewport"; /** @@ -32,9 +34,19 @@ export interface RenderObject pipeline: RenderPipeline; /** - * 渲染几何数据。 + * 顶点属性数据映射。 + */ + vertices?: VertexAttributes; + + /** + * 顶点索引数据。 */ - geometry: Geometry; + indices?: IndicesDataTypes; + + /** + * 绘制。 + */ + draw?: IDraw; /** * 绑定资源。 @@ -45,3 +57,83 @@ export interface RenderObject _version?: number; } + + +export class RenderObject +{ + + /** + * 获取顶点数量。 + * + * @returns 顶点数量。 + */ + 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 count = vertexList.length > 0 ? VertexAttribute.getVertexCount(vertexList[0]) : 0; + + // 验证所有顶点属性数据的顶点数量一致。 + if (vertexList.length > 0) + { + console.assert(vertexList.every((v) => count === VertexAttribute.getVertexCount(v))); + } + + return count; + } + + /** + * 获取实例数量。 + * + * @returns 实例数量。 + */ + 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 count = vertexList.length > 0 ? VertexAttribute.getVertexCount(vertexList[0]) : 1; + + // 验证所有顶点属性数据的顶点数量一致。 + if (vertexList.length > 0) + { + console.assert(vertexList.every((v) => count === VertexAttribute.getVertexCount(v))); + } + + return count; + } + + static getDraw(geometry: RenderObject): DrawIndexed | DrawVertex + { + if (geometry['_draw']) return geometry['_draw']; + + const instanceCount = RenderObject.getInstanceCount(geometry); + + if (geometry.indices) + { + return { + __type__: "DrawIndexed", + indexCount: geometry.indices.length, + firstIndex: 0, + instanceCount, + }; + } + + return { + __type__: "DrawVertex", + vertexCount: RenderObject.getNumVertex(geometry), + instanceCount, + }; + } +} + +/** + * 顶点索引数据类型。 + */ +export type IndicesDataTypes = Uint16Array | Uint32Array; + +/** + * 绘制图形。 + */ +export type IDraw = DrawVertex | DrawIndexed; diff --git a/src/index.ts b/src/index.ts index 6c183f4..4d890eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,6 @@ export * from "./data/DepthStencilState"; export * from "./data/DrawIndexed"; export * from "./data/DrawVertex"; export * from "./data/FragmentState"; -export * from "./data/Geometry"; export * from "./data/ImageCopyTexture"; export * from "./data/OcclusionQuery"; export * from "./data/PrimitiveState"; -- Gitee From 1a80b35e3ae156b070c7426a9db4dfc31b3e8e7e Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Mar 2025 10:43:21 +0800 Subject: [PATCH 28/80] =?UTF-8?q?refactor(data):=20=E9=87=8D=E6=9E=84=20Bu?= =?UTF-8?q?ffer=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 GBuffer 接口重命名为 Buffer - 为 CopyBufferToBuffer 接口中的 source 和 destination 属性重命名 - 在 Buffer 接口中添加关于 size 属性的注释说明 - 将 Buffer 接口中的 data 属性标记为 readonly --- src/data/Buffer.ts | 6 ++++-- src/data/CopyBufferToBuffer.ts | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index f7563f3..f39971b 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -10,7 +10,7 @@ import { WriteBuffer } from "./WriteBuffer"; * * {@link GPUBuffer} */ -export interface GBuffer +export interface Buffer { /** * 标签。 @@ -23,13 +23,15 @@ export interface GBuffer * 缓冲区尺寸,单位为字节。 * * 尺寸必须为4的倍数。 + * + * 注:修改尺寸时,会重新创建缓冲区。 */ readonly size: number; /** * 缓冲区数据。 */ - data?: TypedArray; + readonly data?: TypedArray; /** * 写缓冲区。 diff --git a/src/data/CopyBufferToBuffer.ts b/src/data/CopyBufferToBuffer.ts index 89cd239..264cfde 100644 --- a/src/data/CopyBufferToBuffer.ts +++ b/src/data/CopyBufferToBuffer.ts @@ -1,4 +1,4 @@ -import { GBuffer } from "./Buffer"; +import { Buffer } from "./Buffer"; /** * GPU缓冲区之间拷贝。 @@ -16,7 +16,7 @@ export interface CopyBufferToBuffer /** * 源缓冲区。 */ - source: GBuffer; + source: Buffer; /** * 默认为0。 @@ -26,7 +26,7 @@ export interface CopyBufferToBuffer /** * 目标缓冲区。 */ - destination: GBuffer; + destination: Buffer; /** * 默认为0。 -- Gitee From 07cb9a7b580bada7678ecb25619cb12b8dd7da24 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Mar 2025 13:17:25 +0800 Subject: [PATCH 29/80] =?UTF-8?q?feat(ChainMap):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ChainMap 类中添加 _数量 属性,用于记录键值对数量 - 重命名 _map 为 _根字典,提高代码可读性 - 在 set 方法中增加对新键值对的判断,更新 _数量 - 在 delete 方法中添加对删除成功的处理,更新 _数量 --- src/utils/ChainMap.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 99e9ad5..6622e07 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -10,7 +10,8 @@ export class ChainMap, V> /** * 根字典。 */ - private _map = new Map(); + private _根字典 = new Map(); + private _数量 = 0; /** * 获取键对应的值。 @@ -21,7 +22,7 @@ export class ChainMap, V> get(keys: K): V { const keysLength = keys.length; - let map = this._map; + let map = this._根字典; 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._map; + let map = this._根字典; let key: any; for (let i = 0; i < keysLength - 1; i++) @@ -63,7 +64,11 @@ export class ChainMap, V> } key = keys[keysLength - 1]; - map.set(key, value); + if (!map.has(key)) + { + map.set(key, value); + this._数量++; + } return value; } @@ -77,7 +82,7 @@ export class ChainMap, V> delete(keys: K): boolean { const keysLength = keys.length; - let map = this._map; + let map = this._根字典; let key: any; for (let i = 0; i < keysLength - 1; i++) @@ -89,6 +94,9 @@ export class ChainMap, V> } key = keys[keysLength - 1]; - return map.delete(key); + const result = map.delete(key); + if (result) this._数量--; + + return result; } } -- Gitee From 68b7004f622cd8c1af80c79f16b946f3ecc09849 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Mar 2025 13:45:10 +0800 Subject: [PATCH 30/80] =?UTF-8?q?refactor(utils):=20=E4=BC=98=E5=8C=96=20C?= =?UTF-8?q?hainMap=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将根字典从 Map 改为 WeakMap,以支持对象作为键 - 新增 wrapKey 函数,用于包装非对象键值 - 通过 keyMap 和 idCounter 实现键值的唯一包装 - 优化 get、set 和 delete 方法,以适应新的实现 --- src/utils/ChainMap.ts | 54 ++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/utils/ChainMap.ts b/src/utils/ChainMap.ts index 6622e07..2fc6348 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -1,16 +1,14 @@ /** - * 链式Map。 - * - * 多个key数组对应一个值。 - * - * 由于键值可能是字面值也可能是对象,因此无法使用 {@link WeakMap} 来构建{@link ChainMap},只能使用 {@link Map}。 + * 链式字典。 + * + * 使用WeakMap构建的,支持多个key数组对应一个值。 */ export class ChainMap, V> { /** * 根字典。 */ - private _根字典 = new Map(); + private _根字典 = new WeakMap(); private _数量 = 0; /** @@ -27,13 +25,13 @@ export class ChainMap, V> for (let i = 0, n = keysLength - 1; i < n; i++) { - key = keys[i]; + key = wrapKey(keys[i]); map = map.get(key); if (map === undefined) return undefined; } - key = keys[keysLength - 1]; + key = wrapKey(keys[keysLength - 1]); return map.get(key); } @@ -53,17 +51,17 @@ export class ChainMap, V> for (let i = 0; i < keysLength - 1; i++) { - key = keys[i]; + key = wrapKey(keys[i]); if (!map.has(key)) { - map.set(key, new Map()); + map.set(key, new WeakMap()); } map = map.get(key); } - key = keys[keysLength - 1]; + key = wrapKey(keys[keysLength - 1]); if (!map.has(key)) { map.set(key, value); @@ -87,16 +85,46 @@ export class ChainMap, V> for (let i = 0; i < keysLength - 1; i++) { - key = keys[i]; + key = wrapKey(keys[i]); map = map.get(key); if (map === undefined) return false; } - key = keys[keysLength - 1]; + key = wrapKey(keys[keysLength - 1]); const result = map.delete(key); if (result) this._数量--; return result; } } + +// 创建一个普通 Map 用于存储原始值和包装对象的映射 +const keyMap = new Map(); +// 用于生成唯一 ID 的计数器 +let idCounter = 0; + +// 包装函数,将非对象值包装成对象 +function wrapKey(key: any) +{ + if (typeof key === 'object' && key !== null) + { + // 如果 key 已经是对象,则直接返回 + return key; + } + if (keyMap.has(key)) + { + // 如果原始值已经有对应的包装对象,直接返回 + return keyMap.get(key); + } + // 为非对象 key 生成一个唯一 ID + const id = idCounter++; + // 创建一个包装对象 + const wrapper = { + __id: id, + __value: key + }; + // 存储原始值和包装对象的映射 + keyMap.set(key, wrapper); + return wrapper; +} \ No newline at end of file -- Gitee From 007df47ed699528007b3c00c49616272de44a650 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Mar 2025 17:14:56 +0800 Subject: [PATCH 31/80] =?UTF-8?q?refactor(data):=20=E4=BC=98=E5=8C=96=20Re?= =?UTF-8?q?nderObject=20=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 RenderObject 接口中的属性添加 readonly 修饰符,确保其不可变性 - 移除了未使用的 _version 属性 - 通过引入 readonly 依赖项,提高了代码的可维护性和可读性 --- src/data/RenderObject.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 028ac12..829f0cd 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -1,3 +1,4 @@ +import { readonly } from "@vue/reactivity"; import { BindingResources } from "./BindingResources"; import { DrawIndexed } from "./DrawIndexed"; import { DrawVertex } from "./DrawVertex"; @@ -21,41 +22,39 @@ export interface RenderObject * * 描述渲染在画布的哪个区域,默认整个画布。 */ - viewport?: Viewport; + readonly viewport?: Viewport; /** * 光栅化阶段中使用的剪刀矩形。 */ - scissorRect?: ScissorRect; + readonly scissorRect?: ScissorRect; /** * 渲染管线描述。 */ - pipeline: RenderPipeline; + readonly pipeline: RenderPipeline; /** * 顶点属性数据映射。 */ - vertices?: VertexAttributes; + readonly vertices?: VertexAttributes; /** * 顶点索引数据。 */ - indices?: IndicesDataTypes; + readonly indices?: IndicesDataTypes; /** * 绘制。 */ - draw?: IDraw; + readonly draw?: IDraw; /** * 绑定资源。 * * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ - bindingResources?: BindingResources; - - _version?: number; + readonly bindingResources?: BindingResources; } -- Gitee From 91a27d3b175624643ff66e751f7a16f1105308bb Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 21 Mar 2025 17:25:39 +0800 Subject: [PATCH 32/80] =?UTF-8?q?refactor(data):=20=E7=A7=BB=E9=99=A4=20Re?= =?UTF-8?q?nderObject=20=E4=B8=AD=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了 RenderObject.ts 文件中未使用的 readonly 导入语句。这个更改是为了清理无用的代码,提高代码的可读性和维护性。 --- src/data/RenderObject.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 829f0cd..740155a 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -1,4 +1,3 @@ -import { readonly } from "@vue/reactivity"; import { BindingResources } from "./BindingResources"; import { DrawIndexed } from "./DrawIndexed"; import { DrawVertex } from "./DrawVertex"; -- Gitee From c25575fb9c548b63e46b2f14a441984254c4d90f Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 22 Mar 2025 10:27:38 +0800 Subject: [PATCH 33/80] =?UTF-8?q?refactor(data):=20=E4=BF=AE=E6=94=B9=20Re?= =?UTF-8?q?nderPass=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 renderObjects 属性重命名为 renderPassObjects - 此修改提高了代码的清晰度和一致性 --- src/data/RenderPass.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index 10826ab..4c27a56 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -22,7 +22,7 @@ export interface RenderPass /** * 渲染对象列表 */ - readonly renderObjects?: readonly RenderPassObject[]; + readonly renderPassObjects?: readonly RenderPassObject[]; /** * 当渲染通道中存在遮挡查询时,在查询结束后调用该函数返回查询结果。 -- Gitee From 99ece3a055d6bfd3c7a844f493168e10f38d6b1d Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 29 Mar 2025 00:33:42 +0800 Subject: [PATCH 34/80] =?UTF-8?q?build(dependencies):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20reactivity=20=E4=BE=9D=E8=B5=96=E8=87=B3=20@feng3d/reactivit?= =?UTF-8?q?y@1.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 @vue/reactivity 替换为 @feng3d/reactivity - 更新相关导入语句 - 调整部分 API 使用,如 ComputedRef 改为 Computed --- package.json | 3 ++- src/data/Sampler.ts | 1 - src/data/Texture.ts | 1 - src/reactivity.ts | 8 ++++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a426988..1639e5a 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "vitest": "^0.32.2" }, "dependencies": { + "@feng3d/reactivity": "^1.0.2", "@vue/reactivity": "^3.5.13" } -} \ No newline at end of file +} diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index aa84604..5079cbd 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -1,4 +1,3 @@ -import { readonly } from "@vue/reactivity"; import { CompareFunction } from "./StencilFaceState"; /** diff --git a/src/data/Texture.ts b/src/data/Texture.ts index 48e9a9b..e29efe1 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -1,4 +1,3 @@ -import { readonly } from "@vue/reactivity"; import { TextureDataSource } from "./TextureDataSource"; import { TextureImageSource } from "./TextureImageSource"; diff --git a/src/reactivity.ts b/src/reactivity.ts index 77016ed..9618d3e 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -1,7 +1,11 @@ import { UnReadonly } from "@feng3d/render-api"; -import { toRaw as vueToRaw, reactive as vueReactive } from "@vue/reactivity"; -export { computed, type ComputedRef, effect } from "@vue/reactivity"; +// import { reactive as vueReactive, toRaw as vueToRaw } from "@feng3d/reactivity"; +// export { computed, type Computed, effect } from "@feng3d/reactivity"; + +import { reactive as vueReactive, toRaw as vueToRaw } from "@vue/reactivity"; +export { computed, effect, type ComputedRef as Computed } from "@vue/reactivity"; + /** * Vue响应式。 -- Gitee From 7418a0f46d7c7d64e8c58d7d55c2c52d67c49062 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 29 Mar 2025 04:31:11 +0800 Subject: [PATCH 35/80] =?UTF-8?q?refactor(reactivity):=20=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=8F=8D=E5=BA=94=E6=80=A7=E6=A8=A1=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启用 @feng3d/reactivity 的导入 - 禁用 @vue/reactivity 的导入 - 调整导入语句和导出内容 --- src/reactivity.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/reactivity.ts b/src/reactivity.ts index 9618d3e..7446edc 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -1,10 +1,10 @@ import { UnReadonly } from "@feng3d/render-api"; -// import { reactive as vueReactive, toRaw as vueToRaw } from "@feng3d/reactivity"; -// export { computed, type Computed, effect } from "@feng3d/reactivity"; +import { reactive as vueReactive, toRaw as vueToRaw } from "@feng3d/reactivity"; +export { computed, type Computed, effect } from "@feng3d/reactivity"; -import { reactive as vueReactive, toRaw as vueToRaw } from "@vue/reactivity"; -export { computed, effect, type ComputedRef as Computed } from "@vue/reactivity"; +// import { reactive as vueReactive, toRaw as vueToRaw } from "@vue/reactivity"; +// export { computed, effect, type ComputedRef as Computed } from "@vue/reactivity"; /** -- Gitee From d8e193e2c7f3d09ad1908f8c21045104748743dd Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 29 Mar 2025 15:34:20 +0800 Subject: [PATCH 36/80] =?UTF-8?q?refactor(data):=20=E5=9C=A8=20CanvasTextu?= =?UTF-8?q?re=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E6=B7=BB=E5=8A=A0=20=5FcanvasS?= =?UTF-8?q?izeVersion=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 画布尺寸发生变化后引擎自动递增的版本号 - 引擎内部监听这个值,在画布尺寸发生变化后重新获取纹理 --- src/data/CanvasTexture.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/data/CanvasTexture.ts b/src/data/CanvasTexture.ts index 5ad3990..fc72794 100644 --- a/src/data/CanvasTexture.ts +++ b/src/data/CanvasTexture.ts @@ -9,4 +9,13 @@ export interface CanvasTexture * 画布上下文。 */ context: CanvasContext; + + /** + * 画布尺寸发生变化后引擎自动递增。 + * + * 引擎内部监听这个值,在画布尺寸发生变化后重新获取纹理。 + * + * @private + */ + _canvasSizeVersion?: number; } -- Gitee From 36f08b1463b70b40a4db8f19f82fdae7407d69af Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Wed, 2 Apr 2025 10:08:10 +0800 Subject: [PATCH 37/80] build(dependencies): update @feng3d/reactivity and remove @vue/reactivity - Update @feng3d/reactivity from 1.0.2 to 1.0.4 - Remove @vue/reactivity dependency --- package.json | 3 +-- src/reactivity.ts | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/package.json b/package.json index 1639e5a..f3cbef9 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "vitest": "^0.32.2" }, "dependencies": { - "@feng3d/reactivity": "^1.0.2", - "@vue/reactivity": "^3.5.13" + "@feng3d/reactivity": "^1.0.4" } } diff --git a/src/reactivity.ts b/src/reactivity.ts index 7446edc..dbfb887 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -3,10 +3,6 @@ import { UnReadonly } from "@feng3d/render-api"; import { reactive as vueReactive, toRaw as vueToRaw } from "@feng3d/reactivity"; export { computed, type Computed, effect } from "@feng3d/reactivity"; -// import { reactive as vueReactive, toRaw as vueToRaw } from "@vue/reactivity"; -// export { computed, effect, type ComputedRef as Computed } from "@vue/reactivity"; - - /** * Vue响应式。 * -- Gitee From b73d1ff5e8516971dbeed933b00060ba078d3195 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sun, 20 Apr 2025 10:25:40 +0800 Subject: [PATCH 38/80] gitee.com/feng3d -> github.com/feng3d-labs --- package.json | 2 +- typedoc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f3cbef9..e2cdd6a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "repository": { "type": "git", - "url": "https://gitee.com/feng3d/render-api.git" + "url": "https://github.com/feng3d-labs/render-api.git" }, "publishConfig": { "access": "public" diff --git a/typedoc.json b/typedoc.json index c40445a..e88a1a8 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/render-api/tree/master/{path}#L{line}", "out": "public" } \ No newline at end of file -- Gitee From d60d7b987ebeb39a76e1bf7d72e4479ff114d3ee Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 22:43:07 +0800 Subject: [PATCH 39/80] =?UTF-8?q?build:=20=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=9E=84=E5=BB=BA=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 .gitlab-ci.yml 文件,停止使用 GitLab CI/CD - 删除 .gitpod.yml 文件,移除 Gitpod 配置 - 更新 package.json 版本号至 0.0.3 --- .github/workflows/master.yml | 67 ++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 33 ------------------ .gitpod.yml | 3 -- package.json | 2 +- 4 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/master.yml delete mode 100644 .gitlab-ci.yml delete mode 100644 .gitpod.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 0000000..b1f3913 --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,67 @@ +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - 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 "::set-output name=publish::true" + else + echo "::set-output name=publish::false" + 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/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 54bd9ee..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/npm.gitlab-ci.yml - -image: node:latest - -cache: - paths: - - node_modules/ - - examples/node_modules/ - -test: - stage: test - script: - - npm i -g pnpm - - pnpm i --no-frozen-lockfile - - npm run test - rules: - - if: $CI_MERGE_REQUEST_IID - - if: $CI_COMMIT_TAG - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - -pages: - stage: deploy - script: - - npm run docs - - npm run examples - artifacts: - paths: - - public - only: - - master diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index c165d7f..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,3 +0,0 @@ -tasks: - - init: npm i -g pnpm && pnpm i - command: npm run watch diff --git a/package.json b/package.json index e2cdd6a..4a217c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@feng3d/render-api", - "version": "0.0.2", + "version": "0.0.3", "description": "渲染接口", "author": "feng", "license": "MIT", -- Gitee From 2c60239aa49ed546b067460f3b0bfbbaed104ef6 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 22:51:39 +0800 Subject: [PATCH 40/80] =?UTF-8?q?refactor(src):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=20reactivity=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 src/index.ts 中移除了对 reactivity 模块的导出 - 删除了 src/reactivity.ts 文件 --- src/index.ts | 2 -- src/reactivity.ts | 17 ----------------- 2 files changed, 19 deletions(-) delete mode 100644 src/reactivity.ts diff --git a/src/index.ts b/src/index.ts index 4d890eb..6dac494 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,8 +38,6 @@ export * from "./data/VertexState"; export * from "./data/Viewport"; export * from "./data/WriteBuffer"; -export * from "./reactivity"; - export * from "./internal/BufferBindingInfo"; export * from "./types/TypedArray"; diff --git a/src/reactivity.ts b/src/reactivity.ts deleted file mode 100644 index dbfb887..0000000 --- a/src/reactivity.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { UnReadonly } from "@feng3d/render-api"; - -import { reactive as vueReactive, toRaw as vueToRaw } from "@feng3d/reactivity"; -export { computed, type Computed, effect } from "@feng3d/reactivity"; - -/** - * Vue响应式。 - * - * 额外把只读属性去掉(引擎希望原始数据只用于访问,不直接修改,通过修改响应式数据来触发引擎更新逻辑并间接修改原始数据)。 - */ -export const reactive: (target: T) => UnReadonly = vueReactive as any; - -/** - * Vue原始数据。 - * - */ -export const toRaw: (observed: T) => T = vueToRaw as any; -- Gitee From 5cd0b922ce0dedc1cecfc7d977a65dcc8c76cdb6 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 22:56:56 +0800 Subject: [PATCH 41/80] =?UTF-8?q?build:=20=E7=A7=BB=E9=99=A4=20tsconfig.js?= =?UTF-8?q?on=20=E4=B8=AD=E7=9A=84=20types=20=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了 tsconfig.json 中的 "types" 配置项,以解决可能导致构建失败的问题。这个更改不会影响项目的功能,但可能需要确保在其他地方正确引入所需的类型定义。 --- tsconfig.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index f20f562..a737ab8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,9 +8,6 @@ "declaration": true, "experimentalDecorators": true, "emitDeclarationOnly": true, - "types": [ - "@webgpu/types" - ], "lib": [ "ESNext", "DOM", -- Gitee From 791d9e4994ef6acccec135e3fc0ce24c54a531fc Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 23:04:47 +0800 Subject: [PATCH 42/80] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=92=8C=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除多余的空行和空格 - 统一代码风格 - 修复部分代码格式问题 --- src/consts/vertexFormatMap.ts | 65 +++++++++++++++++----------------- src/data/BindingResources.ts | 2 +- src/data/Buffer.ts | 2 +- src/data/CanvasContext.ts | 4 +-- src/data/CanvasTexture.ts | 4 +-- src/data/DepthStencilState.ts | 2 +- src/data/OcclusionQuery.ts | 2 +- src/data/PrimitiveState.ts | 2 +- src/data/RenderObject.ts | 8 ++--- src/data/RenderPass.ts | 2 +- src/data/RenderPipeline.ts | 2 +- src/data/Sampler.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 - src/global.ts | 2 +- src/index.ts | 2 +- src/utils/ChainMap.ts | 12 ++++--- 21 files changed, 65 insertions(+), 67 deletions(-) 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/BindingResources.ts b/src/data/BindingResources.ts index 5a41490..350b964 100644 --- a/src/data/BindingResources.ts +++ b/src/data/BindingResources.ts @@ -2,7 +2,7 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding"; /** * 绑定资源。 - * + * * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ export interface BindingResources diff --git a/src/data/Buffer.ts b/src/data/Buffer.ts index f39971b..620ab87 100644 --- a/src/data/Buffer.ts +++ b/src/data/Buffer.ts @@ -23,7 +23,7 @@ export interface Buffer * 缓冲区尺寸,单位为字节。 * * 尺寸必须为4的倍数。 - * + * * 注:修改尺寸时,会重新创建缓冲区。 */ readonly size: number; diff --git a/src/data/CanvasContext.ts b/src/data/CanvasContext.ts index 5722931..b4d47d3 100644 --- a/src/data/CanvasContext.ts +++ b/src/data/CanvasContext.ts @@ -1,11 +1,11 @@ /** * 画布上下文 */ -export interface CanvasContext +export interface CanvasContext { /** * 画布。 - * + * * 可能是画布的编号,也可能是画布元素或者离屏画布。 */ readonly canvasId: string | HTMLCanvasElement | OffscreenCanvas; diff --git a/src/data/CanvasTexture.ts b/src/data/CanvasTexture.ts index fc72794..de3b617 100644 --- a/src/data/CanvasTexture.ts +++ b/src/data/CanvasTexture.ts @@ -12,9 +12,9 @@ export interface CanvasTexture /** * 画布尺寸发生变化后引擎自动递增。 - * + * * 引擎内部监听这个值,在画布尺寸发生变化后重新获取纹理。 - * + * * @private */ _canvasSizeVersion?: number; diff --git a/src/data/DepthStencilState.ts b/src/data/DepthStencilState.ts index 7d1fe47..a79a051 100644 --- a/src/data/DepthStencilState.ts +++ b/src/data/DepthStencilState.ts @@ -1,4 +1,4 @@ -import { CompareFunction as CompareFunction, StencilFaceState } from "./StencilFaceState"; +import { CompareFunction, StencilFaceState } from "./StencilFaceState"; /** * 深度模板阶段描述。 diff --git a/src/data/OcclusionQuery.ts b/src/data/OcclusionQuery.ts index a8f960d..6129ec6 100644 --- a/src/data/OcclusionQuery.ts +++ b/src/data/OcclusionQuery.ts @@ -17,7 +17,7 @@ export interface OcclusionQuery /** * 查询结束回调。 - * + * * @param result 是否被渲染。true表示被渲染,false表示未被渲染。 */ onQuery?(result: number): void; diff --git a/src/data/PrimitiveState.ts b/src/data/PrimitiveState.ts index b2f77d8..c5048cd 100644 --- a/src/data/PrimitiveState.ts +++ b/src/data/PrimitiveState.ts @@ -17,7 +17,7 @@ export interface PrimitiveState * * `triangle-strip` 绘制三角形条带。 * * 默认 `triangle-list` ,默认每三个顶点绘制一个三角形。 - * + * * 图形拓扑结构。 * * 以下仅在WebGL生效 diff --git a/src/data/RenderObject.ts b/src/data/RenderObject.ts index 740155a..cd4a0eb 100644 --- a/src/data/RenderObject.ts +++ b/src/data/RenderObject.ts @@ -50,20 +50,18 @@ export interface RenderObject /** * 绑定资源。 - * + * * 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。 */ readonly bindingResources?: BindingResources; } - export class RenderObject { - /** * 获取顶点数量。 * - * @returns 顶点数量。 + * @returns 顶点数量。 */ static getNumVertex(geometry: RenderObject) { @@ -104,7 +102,7 @@ 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); diff --git a/src/data/RenderPass.ts b/src/data/RenderPass.ts index 4c27a56..e7632e8 100644 --- a/src/data/RenderPass.ts +++ b/src/data/RenderPass.ts @@ -26,7 +26,7 @@ export interface RenderPass /** * 当渲染通道中存在遮挡查询时,在查询结束后调用该函数返回查询结果。 - * + * * @param occlusionQuerys 遮挡查询列表 * @param results 是否被渲染。true表示被渲染,false表示未被渲染。 */ diff --git a/src/data/RenderPipeline.ts b/src/data/RenderPipeline.ts index f68d53b..9fa17b4 100644 --- a/src/data/RenderPipeline.ts +++ b/src/data/RenderPipeline.ts @@ -5,7 +5,7 @@ import { VertexState } from "./VertexState"; /** * 渲染管线。 - * + * * 对应WebGPU的Pipeline。 */ export interface RenderPipeline diff --git a/src/data/Sampler.ts b/src/data/Sampler.ts index 5079cbd..a29f06d 100644 --- a/src/data/Sampler.ts +++ b/src/data/Sampler.ts @@ -86,7 +86,7 @@ export interface Sampler * 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。 * * 仅当 minFilter 、magFilter 或 mipmapFilter 为 "linear" 时才有效,否则取 1。 - * + * * 默认 1。 * * 注:大多数实现支持范围在1到16之间(包括1和16)的maxAnisotropy值。所使用的maxAnisotropy值将被限制在平台支持的最大值内 diff --git a/src/data/StencilFaceState.ts b/src/data/StencilFaceState.ts index 94cde7d..fa45bfd 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 { /** * 在测试片元与 depthStencilAttachment 模板值时使用的 GPUCompareFunction。 diff --git a/src/data/Submit.ts b/src/data/Submit.ts index 9a05068..20628a1 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 { /** * 命令编码器列表。 diff --git a/src/data/Texture.ts b/src/data/Texture.ts index e29efe1..78f6bf4 100644 --- a/src/data/Texture.ts +++ b/src/data/Texture.ts @@ -22,7 +22,7 @@ export interface TextureLikeMap /** * 纹理 */ -export interface Texture +export interface Texture { /** * 标签。 @@ -107,9 +107,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 fdd8fa9..e5c99f4 100644 --- a/src/data/VertexAttributes.ts +++ b/src/data/VertexAttributes.ts @@ -50,10 +50,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 4676c45..be479cf 100644 --- a/src/data/Viewport.ts +++ b/src/data/Viewport.ts @@ -1,4 +1,3 @@ - /** * 视窗。 * diff --git a/src/global.ts b/src/global.ts index 0777368..b759ece 100644 --- a/src/global.ts +++ b/src/global.ts @@ -4,5 +4,5 @@ declare global /** * 是否为开发模式。 */ - var __DEV__: boolean; + let __DEV__: boolean; } diff --git a/src/index.ts b/src/index.ts index 6dac494..74cc531 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,4 +45,4 @@ export * from "./types/UnReadonly"; 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 2fc6348..8aa1d65 100644 --- a/src/utils/ChainMap.ts +++ b/src/utils/ChainMap.ts @@ -1,6 +1,6 @@ /** * 链式字典。 - * + * * 使用WeakMap构建的,支持多个key数组对应一个值。 */ export class ChainMap, V> @@ -32,7 +32,8 @@ export class ChainMap, V> } key = wrapKey(keys[keysLength - 1]); - return map.get(key); + +return map.get(key); } /** @@ -40,7 +41,7 @@ export class ChainMap, V> * * @param keys 键。 * @param value 值。 - * + * * @returns 返回设置的值。 */ set(keys: K, value: V) @@ -107,7 +108,7 @@ let idCounter = 0; // 包装函数,将非对象值包装成对象 function wrapKey(key: any) { - if (typeof key === 'object' && key !== null) + if (typeof key === "object" && key !== null) { // 如果 key 已经是对象,则直接返回 return key; @@ -126,5 +127,6 @@ function wrapKey(key: any) }; // 存储原始值和包装对象的映射 keyMap.set(key, wrapper); - return wrapper; + +return wrapper; } \ No newline at end of file -- Gitee From 9d055f8fb992c43f96d8ebd6756a3c615b062497 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 23:15:03 +0800 Subject: [PATCH 43/80] =?UTF-8?q?docs(readme):=20=E6=9B=B4=E6=96=B0=20@fen?= =?UTF-8?q?g3d/render-api=20=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加项目描述和功能特性 - 补充安装说明 - 移除示例部分 --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7dcf394..636ce95 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ -# @feng3d/renderer +# @feng3d/render-api +WebGL/WebGPU渲染API接口库,提供给@feng3d/webgl与@feng3d/webgpu使用。 -## 示例 +## 功能特性 -### WebGL2Samples -https://github.com/WebGLSamples/WebGL2Samples \ No newline at end of file +- 提供统一的WebGL/WebGPU渲染接口 +- 支持缓冲区(Buffer)、纹理(Texture)、采样器(Sampler)等资源管理 +- 支持渲染管线(RenderPipeline)配置 +- 支持渲染通道(RenderPass)设置 +- 类型安全的TypeScript实现 + +## 安装 + +```bash +npm install @feng3d/render-api +``` -- Gitee From dfa96655e796fb4d60d8d265e9b4ce8ae24d218f Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Thu, 8 May 2025 23:20:43 +0800 Subject: [PATCH 44/80] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0README.md?= =?UTF-8?q?=E5=92=8Cpackage.json=E4=B8=AD=E7=9A=84=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新README.md和package.json中的描述信息,使其更准确地反映库的功能和用途,即提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程。 --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 636ce95..69f9f93 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @feng3d/render-api -WebGL/WebGPU渲染API接口库,提供给@feng3d/webgl与@feng3d/webgpu使用。 +提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。 ## 功能特性 diff --git a/package.json b/package.json index 4a217c6..0d45a40 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@feng3d/render-api", "version": "0.0.3", - "description": "渲染接口", + "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", "author": "feng", "license": "MIT", "type": "module", -- Gitee From 724784ea9d2ab02508bbfc139f00c22a0b701789 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Fri, 9 May 2025 23:31:47 +0800 Subject: [PATCH 45/80] =?UTF-8?q?build:=20=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E8=87=B3=200.0.4=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=A8=A1=E5=BC=8F=E5=8F=98=E9=87=8F=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E4=B8=BA=20var?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/global.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0d45a40..48b79b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@feng3d/render-api", - "version": "0.0.3", + "version": "0.0.4", "description": "提供WebGL/WebGPU统一的渲染数据结构,描述渲染所需的所有数据以及流程,用于@feng3d/webgl与@feng3d/webgpu。", "author": "feng", "license": "MIT", diff --git a/src/global.ts b/src/global.ts index b759ece..0777368 100644 --- a/src/global.ts +++ b/src/global.ts @@ -4,5 +4,5 @@ declare global /** * 是否为开发模式。 */ - let __DEV__: boolean; + var __DEV__: boolean; } -- Gitee From 1aefd54111fe70a42d803c55f7ec6c0fffa24848 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 10 May 2025 01:17:52 +0800 Subject: [PATCH 46/80] refactor(global): change development mode variable declaration from var to const --- src/global.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global.ts b/src/global.ts index 0777368..d94471f 100644 --- a/src/global.ts +++ b/src/global.ts @@ -4,5 +4,5 @@ declare global /** * 是否为开发模式。 */ - var __DEV__: boolean; + const __DEV__: boolean; } -- Gitee From b6a6de20fc574b956f0efc5eed85f2e9e67f9136 Mon Sep 17 00:00:00 2001 From: feng <908087098@qq.com> Date: Sat, 10 May 2025 01:18:50 +0800 Subject: [PATCH 47/80] refactor(global): change development mode variable declaration back to var --- src/global.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/global.ts b/src/global.ts index d94471f..2e59812 100644 --- a/src/global.ts +++ b/src/global.ts @@ -4,5 +4,6 @@ declare global /** * 是否为开发模式。 */ - const __DEV__: boolean; + // eslint-disable-next-line no-var + var __DEV__: boolean; } -- Gitee 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 48/80] =?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"; -- Gitee 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 49/80] =?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 -- Gitee 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 50/80] =?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" } } -- Gitee 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 51/80] =?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" } } -- Gitee 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 52/80] =?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" } } -- Gitee 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 53/80] =?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: '' } }; }, }; } -- Gitee 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 54/80] =?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 -- Gitee 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 55/80] =?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]; -}; -- Gitee 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 56/80] =?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 -- Gitee 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 57/80] =?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 { -- Gitee 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 58/80] =?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 -- Gitee 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 59/80] =?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; -- Gitee 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 60/80] 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 -- Gitee 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 61/80] 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; } /** -- Gitee 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 62/80] =?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; } -- Gitee 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 63/80] =?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; -- Gitee 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 64/80] =?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; -- Gitee 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 65/80] =?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" -- Gitee 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 66/80] =?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[]; -- Gitee 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 67/80] =?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; } -- Gitee 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 68/80] =?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: { -- Gitee 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 69/80] =?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); -- Gitee 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 70/80] =?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 -- Gitee 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 71/80] =?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 -- Gitee 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 72/80] =?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; } -- Gitee 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 73/80] =?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; } -- Gitee 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 74/80] =?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 +} -- Gitee 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 75/80] =?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 -- Gitee 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 76/80] =?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 -- Gitee 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 77/80] =?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]; -- Gitee 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 78/80] =?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; -- Gitee 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 79/80] =?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; /** * 如果未设置引擎将自动生成。 -- Gitee 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 80/80] @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; /** -- Gitee