Skip to content

Commit 791d9e4

Browse files
committed
refactor: 优化代码格式和结构
- 移除多余的空行和空格 - 统一代码风格 - 修复部分代码格式问题
1 parent 5cd0b92 commit 791d9e4

21 files changed

+65
-67
lines changed

src/consts/vertexFormatMap.ts

+32-33
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@ import { VertexFormat } from "../data/VertexAttributes";
44
* 顶点属性格式信息映射。
55
*/
66
export const vertexFormatMap: Record<VertexFormat, VertexAttributeFormatInfo> = {
7-
"uint8x2": { "numComponents": 2, "type": "UNSIGNED_BYTE", "normalized": false, "dataType": "unsigned int", "byteSize": 2, "wgslType": "vec2<u32>", "typedArrayConstructor": Uint8Array },
8-
"uint8x4": { "numComponents": 4, "type": "UNSIGNED_BYTE", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "vec4<u32>", "typedArrayConstructor": Uint8Array },
9-
"sint8x2": { "numComponents": 2, "type": "BYTE", "normalized": false, "dataType": "signed int", "byteSize": 2, "wgslType": "vec2<i32>", "typedArrayConstructor": Int8Array },
10-
"sint8x4": { "numComponents": 4, "type": "BYTE", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "vec4<i32>", "typedArrayConstructor": Int8Array },
11-
"unorm8x2": { "numComponents": 2, "type": "UNSIGNED_BYTE", "normalized": true, "dataType": "unsigned normalized", "byteSize": 2, "wgslType": "vec2<f32>", "typedArrayConstructor": Uint8Array },
12-
"unorm8x4": { "numComponents": 4, "type": "UNSIGNED_BYTE", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec4<f32>", "typedArrayConstructor": Uint8Array },
13-
"snorm8x2": { "numComponents": 2, "type": "BYTE", "normalized": true, "dataType": "signed normalized", "byteSize": 2, "wgslType": "vec2<f32>", "typedArrayConstructor": Int8Array },
14-
"snorm8x4": { "numComponents": 4, "type": "BYTE", "normalized": true, "dataType": "signed normalized", "byteSize": 4, "wgslType": "vec4<f32>", "typedArrayConstructor": Int8Array },
15-
"uint16x2": { "numComponents": 2, "type": "UNSIGNED_SHORT", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "vec2<u32>", "typedArrayConstructor": Uint16Array },
16-
"uint16x4": { "numComponents": 4, "type": "UNSIGNED_SHORT", "normalized": false, "dataType": "unsigned int", "byteSize": 8, "wgslType": "vec4<u32>", "typedArrayConstructor": Uint16Array },
17-
"sint16x2": { "numComponents": 2, "type": "SHORT", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "vec2<i32>", "typedArrayConstructor": Int16Array },
18-
"sint16x4": { "numComponents": 4, "type": "SHORT", "normalized": false, "dataType": "signed int", "byteSize": 8, "wgslType": "vec4<i32>", "typedArrayConstructor": Int16Array },
19-
"unorm16x2": { "numComponents": 2, "type": "UNSIGNED_SHORT", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec2<f32>", "typedArrayConstructor": Uint16Array },
20-
"unorm16x4": { "numComponents": 4, "type": "UNSIGNED_SHORT", "normalized": true, "dataType": "unsigned normalized", "byteSize": 8, "wgslType": "vec4<f32>", "typedArrayConstructor": Uint16Array },
21-
"snorm16x2": { "numComponents": 2, "type": "SHORT", "normalized": true, "dataType": "signed normalized", "byteSize": 4, "wgslType": "vec2<f32>", "typedArrayConstructor": Int16Array },
22-
"snorm16x4": { "numComponents": 4, "type": "SHORT", "normalized": true, "dataType": "signed normalized", "byteSize": 8, "wgslType": "vec4<f32>", "typedArrayConstructor": Int16Array },
23-
"float16x2": { "numComponents": 2, "type": "HALF_FLOAT", "normalized": false, "dataType": "float", "byteSize": 4, "wgslType": "vec2<f16>", "typedArrayConstructor": undefined, },
24-
"float16x4": { "numComponents": 4, "type": "HALF_FLOAT", "normalized": false, "dataType": "float", "byteSize": 8, "wgslType": "vec4<f16>", "typedArrayConstructor": undefined, },
25-
"float32": { "numComponents": 1, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 4, "wgslType": "f32", "typedArrayConstructor": Float32Array },
26-
"float32x2": { "numComponents": 2, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 8, "wgslType": "vec2<f32>", "typedArrayConstructor": Float32Array },
27-
"float32x3": { "numComponents": 3, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 12, "wgslType": "vec3<f32>", "typedArrayConstructor": Float32Array },
28-
"float32x4": { "numComponents": 4, "type": "FLOAT", "normalized": false, "dataType": "float", "byteSize": 16, "wgslType": "vec4<f32>", "typedArrayConstructor": Float32Array },
29-
"uint32": { "numComponents": 1, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 4, "wgslType": "u32", "typedArrayConstructor": Uint32Array },
30-
"uint32x2": { "numComponents": 2, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 8, "wgslType": "vec2<u32>", "typedArrayConstructor": Uint32Array },
31-
"uint32x3": { "numComponents": 3, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 12, "wgslType": "vec3<u32>", "typedArrayConstructor": Uint32Array },
32-
"uint32x4": { "numComponents": 4, "type": "UNSIGNED_INT", "normalized": false, "dataType": "unsigned int", "byteSize": 16, "wgslType": "vec4<u32>", "typedArrayConstructor": Uint32Array },
33-
"sint32": { "numComponents": 1, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 4, "wgslType": "i32", "typedArrayConstructor": Int32Array },
34-
"sint32x2": { "numComponents": 2, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 8, "wgslType": "vec2<i32>", "typedArrayConstructor": Int32Array },
35-
"sint32x3": { "numComponents": 3, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 12, "wgslType": "vec3<i32>", "typedArrayConstructor": Int32Array },
36-
"sint32x4": { "numComponents": 4, "type": "INT", "normalized": false, "dataType": "signed int", "byteSize": 16, "wgslType": "vec4<i32>", "typedArrayConstructor": Int32Array },
37-
"unorm10-10-10-2": { "numComponents": 4, "type": "UNSIGNED_INT_2_10_10_10_REV", "normalized": true, "dataType": "unsigned normalized", "byteSize": 4, "wgslType": "vec4<f32>", "typedArrayConstructor": Int32Array }
38-
}
7+
uint8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 2, wgslType: "vec2<u32>", typedArrayConstructor: Uint8Array },
8+
uint8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec4<u32>", typedArrayConstructor: Uint8Array },
9+
sint8x2: { numComponents: 2, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 2, wgslType: "vec2<i32>", typedArrayConstructor: Int8Array },
10+
sint8x4: { numComponents: 4, type: "BYTE", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec4<i32>", typedArrayConstructor: Int8Array },
11+
unorm8x2: { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 2, wgslType: "vec2<f32>", typedArrayConstructor: Uint8Array },
12+
unorm8x4: { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4<f32>", typedArrayConstructor: Uint8Array },
13+
snorm8x2: { numComponents: 2, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 2, wgslType: "vec2<f32>", typedArrayConstructor: Int8Array },
14+
snorm8x4: { numComponents: 4, type: "BYTE", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec4<f32>", typedArrayConstructor: Int8Array },
15+
uint16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "vec2<u32>", typedArrayConstructor: Uint16Array },
16+
uint16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec4<u32>", typedArrayConstructor: Uint16Array },
17+
sint16x2: { numComponents: 2, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "vec2<i32>", typedArrayConstructor: Int16Array },
18+
sint16x4: { numComponents: 4, type: "SHORT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec4<i32>", typedArrayConstructor: Int16Array },
19+
unorm16x2: { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec2<f32>", typedArrayConstructor: Uint16Array },
20+
unorm16x4: { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true, dataType: "unsigned normalized", byteSize: 8, wgslType: "vec4<f32>", typedArrayConstructor: Uint16Array },
21+
snorm16x2: { numComponents: 2, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 4, wgslType: "vec2<f32>", typedArrayConstructor: Int16Array },
22+
snorm16x4: { numComponents: 4, type: "SHORT", normalized: true, dataType: "signed normalized", byteSize: 8, wgslType: "vec4<f32>", typedArrayConstructor: Int16Array },
23+
float16x2: { numComponents: 2, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "vec2<f16>", typedArrayConstructor: undefined },
24+
float16x4: { numComponents: 4, type: "HALF_FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec4<f16>", typedArrayConstructor: undefined },
25+
float32: { numComponents: 1, type: "FLOAT", normalized: false, dataType: "float", byteSize: 4, wgslType: "f32", typedArrayConstructor: Float32Array },
26+
float32x2: { numComponents: 2, type: "FLOAT", normalized: false, dataType: "float", byteSize: 8, wgslType: "vec2<f32>", typedArrayConstructor: Float32Array },
27+
float32x3: { numComponents: 3, type: "FLOAT", normalized: false, dataType: "float", byteSize: 12, wgslType: "vec3<f32>", typedArrayConstructor: Float32Array },
28+
float32x4: { numComponents: 4, type: "FLOAT", normalized: false, dataType: "float", byteSize: 16, wgslType: "vec4<f32>", typedArrayConstructor: Float32Array },
29+
uint32: { numComponents: 1, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 4, wgslType: "u32", typedArrayConstructor: Uint32Array },
30+
uint32x2: { numComponents: 2, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 8, wgslType: "vec2<u32>", typedArrayConstructor: Uint32Array },
31+
uint32x3: { numComponents: 3, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 12, wgslType: "vec3<u32>", typedArrayConstructor: Uint32Array },
32+
uint32x4: { numComponents: 4, type: "UNSIGNED_INT", normalized: false, dataType: "unsigned int", byteSize: 16, wgslType: "vec4<u32>", typedArrayConstructor: Uint32Array },
33+
sint32: { numComponents: 1, type: "INT", normalized: false, dataType: "signed int", byteSize: 4, wgslType: "i32", typedArrayConstructor: Int32Array },
34+
sint32x2: { numComponents: 2, type: "INT", normalized: false, dataType: "signed int", byteSize: 8, wgslType: "vec2<i32>", typedArrayConstructor: Int32Array },
35+
sint32x3: { numComponents: 3, type: "INT", normalized: false, dataType: "signed int", byteSize: 12, wgslType: "vec3<i32>", typedArrayConstructor: Int32Array },
36+
sint32x4: { numComponents: 4, type: "INT", normalized: false, dataType: "signed int", byteSize: 16, wgslType: "vec4<i32>", typedArrayConstructor: Int32Array },
37+
"unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true, dataType: "unsigned normalized", byteSize: 4, wgslType: "vec4<f32>", typedArrayConstructor: Int32Array }
38+
};
3939

4040
/**
4141
* 有类型数组构造器。
@@ -97,7 +97,6 @@ export type WGSLVertexType =
9797
export type GLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1
9898
| "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2
9999

100-
101100
/**
102101
* 顶点属性格式信息
103102
*/

src/data/BindingResources.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BufferBinding, BufferBindingItem } from "./BufferBinding";
22

33
/**
44
* 绑定资源。
5-
*
5+
*
66
* 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。
77
*/
88
export interface BindingResources

src/data/Buffer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface Buffer
2323
* 缓冲区尺寸,单位为字节。
2424
*
2525
* 尺寸必须为4的倍数。
26-
*
26+
*
2727
* 注:修改尺寸时,会重新创建缓冲区。
2828
*/
2929
readonly size: number;

src/data/CanvasContext.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* 画布上下文
33
*/
4-
export interface CanvasContext
4+
export interface CanvasContext
55
{
66
/**
77
* 画布。
8-
*
8+
*
99
* 可能是画布的编号,也可能是画布元素或者离屏画布。
1010
*/
1111
readonly canvasId: string | HTMLCanvasElement | OffscreenCanvas;

src/data/CanvasTexture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export interface CanvasTexture
1212

1313
/**
1414
* 画布尺寸发生变化后引擎自动递增。
15-
*
15+
*
1616
* 引擎内部监听这个值,在画布尺寸发生变化后重新获取纹理。
17-
*
17+
*
1818
* @private
1919
*/
2020
_canvasSizeVersion?: number;

src/data/DepthStencilState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CompareFunction as CompareFunction, StencilFaceState } from "./StencilFaceState";
1+
import { CompareFunction, StencilFaceState } from "./StencilFaceState";
22

33
/**
44
* 深度模板阶段描述。

src/data/OcclusionQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface OcclusionQuery
1717

1818
/**
1919
* 查询结束回调。
20-
*
20+
*
2121
* @param result 是否被渲染。true表示被渲染,false表示未被渲染。
2222
*/
2323
onQuery?(result: number): void;

src/data/PrimitiveState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface PrimitiveState
1717
* * `triangle-strip` 绘制三角形条带。
1818
*
1919
* 默认 `triangle-list` ,默认每三个顶点绘制一个三角形。
20-
*
20+
*
2121
* 图形拓扑结构。
2222
*
2323
* 以下仅在WebGL生效

src/data/RenderObject.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,18 @@ export interface RenderObject
5050

5151
/**
5252
* 绑定资源。
53-
*
53+
*
5454
* 与着色器中名称对应的绑定资源(纹理、采样器、统一数据、存储数据等)。
5555
*/
5656
readonly bindingResources?: BindingResources;
5757
}
5858

59-
6059
export class RenderObject
6160
{
62-
6361
/**
6462
* 获取顶点数量。
6563
*
66-
* @returns 顶点数量。
64+
* @returns 顶点数量。
6765
*/
6866
static getNumVertex(geometry: RenderObject)
6967
{
@@ -104,7 +102,7 @@ export class RenderObject
104102

105103
static getDraw(geometry: RenderObject): DrawIndexed | DrawVertex
106104
{
107-
if (geometry['_draw']) return geometry['_draw'];
105+
if (geometry["_draw"]) return geometry["_draw"];
108106

109107
const instanceCount = RenderObject.getInstanceCount(geometry);
110108

src/data/RenderPass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface RenderPass
2626

2727
/**
2828
* 当渲染通道中存在遮挡查询时,在查询结束后调用该函数返回查询结果。
29-
*
29+
*
3030
* @param occlusionQuerys 遮挡查询列表
3131
* @param results 是否被渲染。true表示被渲染,false表示未被渲染。
3232
*/

src/data/RenderPipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { VertexState } from "./VertexState";
55

66
/**
77
* 渲染管线。
8-
*
8+
*
99
* 对应WebGPU的Pipeline。
1010
*/
1111
export interface RenderPipeline

src/data/Sampler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export interface Sampler
8686
* 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
8787
*
8888
* 仅当 minFilter 、magFilter 或 mipmapFilter 为 "linear" 时才有效,否则取 1。
89-
*
89+
*
9090
* 默认 1。
9191
*
9292
* 注:大多数实现支持范围在1到16之间(包括1和16)的maxAnisotropy值。所使用的maxAnisotropy值将被限制在平台支持的最大值内

src/data/StencilFaceState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @see https://www.orillusion.com/zh/webgpu.html#dictdef-gpustencilfacestate
55
*/
6-
export interface StencilFaceState
6+
export interface StencilFaceState
77
{
88
/**
99
* 在测试片元与 depthStencilAttachment 模板值时使用的 GPUCompareFunction。

src/data/Submit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommandEncoder } from "./CommandEncoder";
55
*
66
* @see https://developer.mozilla.org/en-US/docs/Web/API/GPUQueue/submit
77
*/
8-
export interface Submit
8+
export interface Submit
99
{
1010
/**
1111
* 命令编码器列表。

src/data/Texture.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface TextureLikeMap
2222
/**
2323
* 纹理
2424
*/
25-
export interface Texture
25+
export interface Texture
2626
{
2727
/**
2828
* 标签。
@@ -107,9 +107,9 @@ export class Texture
107107

108108
/**
109109
* 获取纹理数据构造函数。
110-
110+
111111
* @param format 纹理格式。
112-
* @returns
112+
* @returns
113113
*/
114114
static getTextureDataConstructor(format: TextureFormat = "rgba8unorm")
115115
{

src/data/TextureImageSource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ImageOrigin, ImageSize, TextureOrigin, TextureSize } from "./Texture";
1212
*
1313
* @see GPUQueue.copyExternalImageToTexture
1414
*/
15-
export interface TextureImageSource
15+
export interface TextureImageSource
1616
{
1717
/**
1818
* 数据类型。

src/data/VertexAttributes.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export interface VertexAttribute
5050
export class VertexAttribute
5151
{
5252
/**
53-
* 获取顶点属性数据的顶点数量。
54-
*
53+
* 获取顶点属性数据的顶点数量。
54+
*
5555
* @param attribute 顶点属性数据。
56-
* @returns
56+
* @returns
5757
*/
5858
static getVertexCount(attribute: VertexAttribute)
5959
{

src/data/Viewport.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* 视窗。
43
*

src/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ declare global
44
/**
55
* 是否为开发模式。
66
*/
7-
var __DEV__: boolean;
7+
let __DEV__: boolean;
88
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ export * from "./types/UnReadonly";
4545

4646
export * from "./utils/ChainMap";
4747

48-
import "./global"
48+
import "./global";

src/utils/ChainMap.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* 链式字典。
3-
*
3+
*
44
* 使用WeakMap构建的,支持多个key数组对应一个值。
55
*/
66
export class ChainMap<K extends Array<any>, V>
@@ -32,15 +32,16 @@ export class ChainMap<K extends Array<any>, V>
3232
}
3333

3434
key = wrapKey(keys[keysLength - 1]);
35-
return map.get(key);
35+
36+
return map.get(key);
3637
}
3738

3839
/**
3940
* 设置映射。
4041
*
4142
* @param keys 键。
4243
* @param value 值。
43-
*
44+
*
4445
* @returns 返回设置的值。
4546
*/
4647
set(keys: K, value: V)
@@ -107,7 +108,7 @@ let idCounter = 0;
107108
// 包装函数,将非对象值包装成对象
108109
function wrapKey(key: any)
109110
{
110-
if (typeof key === 'object' && key !== null)
111+
if (typeof key === "object" && key !== null)
111112
{
112113
// 如果 key 已经是对象,则直接返回
113114
return key;
@@ -126,5 +127,6 @@ function wrapKey(key: any)
126127
};
127128
// 存储原始值和包装对象的映射
128129
keyMap.set(key, wrapper);
129-
return wrapper;
130+
131+
return wrapper;
130132
}

0 commit comments

Comments
 (0)