@zephyr3d/device 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base_types.js +602 -0
- package/dist/base_types.js.map +1 -0
- package/dist/builder/ast.js +2135 -0
- package/dist/builder/ast.js.map +1 -0
- package/dist/builder/base.js +477 -0
- package/dist/builder/base.js.map +1 -0
- package/dist/builder/builtinfunc.js +4101 -0
- package/dist/builder/builtinfunc.js.map +1 -0
- package/dist/builder/constructors.js +173 -0
- package/dist/builder/constructors.js.map +1 -0
- package/dist/builder/errors.js +148 -0
- package/dist/builder/errors.js.map +1 -0
- package/dist/builder/programbuilder.js +2323 -0
- package/dist/builder/programbuilder.js.map +1 -0
- package/dist/builder/reflection.js +60 -0
- package/dist/builder/reflection.js.map +1 -0
- package/dist/builder/types.js +1563 -0
- package/dist/builder/types.js.map +1 -0
- package/dist/device.js +515 -0
- package/dist/device.js.map +1 -0
- package/dist/gpuobject.js +2047 -0
- package/dist/gpuobject.js.map +1 -0
- package/dist/helpers/drawtext.js +187 -0
- package/dist/helpers/drawtext.js.map +1 -0
- package/dist/helpers/font.js +189 -0
- package/dist/helpers/font.js.map +1 -0
- package/dist/helpers/glyphmanager.js +121 -0
- package/dist/helpers/glyphmanager.js.map +1 -0
- package/dist/helpers/textureatlas.js +170 -0
- package/dist/helpers/textureatlas.js.map +1 -0
- package/dist/index.d.ts +3873 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/timer.js +38 -0
- package/dist/timer.js.map +1 -0
- package/dist/uniformdata.js +147 -0
- package/dist/uniformdata.js.map +1 -0
- package/dist/vertexdata.js +135 -0
- package/dist/vertexdata.js.map +1 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceResizeEvent, DeviceRestoreEvent, ShaderType, encodePixel, encodePixelToArray, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB } from './base_types.js';
|
|
2
|
+
export { VertexData } from './vertexdata.js';
|
|
3
|
+
export { GPUResourceUsageFlags, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, genDefaultName, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatSize, makeVertexBufferType, semanticList, semanticToAttrib } from './gpuobject.js';
|
|
4
|
+
export { BaseDevice } from './device.js';
|
|
5
|
+
export { PBShaderExp, Proxiable, getCurrentProgramBuilder, makeConstructor, setCurrentProgramBuilder } from './builder/base.js';
|
|
6
|
+
export { ASTAddressOf, ASTArrayIndex, ASTAssignment, ASTBinaryFunc, ASTBreak, ASTCallFunction, ASTCast, ASTContinue, ASTDeclareVar, ASTDiscard, ASTDoWhile, ASTExpression, ASTFunction, ASTFunctionParameter, ASTGlobalScope, ASTHash, ASTIf, ASTLValue, ASTLValueArray, ASTLValueDeclare, ASTLValueHash, ASTLValueScalar, ASTNakedScope, ASTPrimitive, ASTRange, ASTReferenceOf, ASTReturn, ASTScalar, ASTScope, ASTSelect, ASTShaderExpConstructor, ASTStructDefine, ASTTouch, ASTUnaryFunc, ASTWhile, DeclareType, ShaderAST, ShaderPrecisionType, builtinVariables, genSamplerName, getBuiltinInputStructInstanceName, getBuiltinInputStructName, getBuiltinOutputStructInstanceName, getBuiltinOutputStructName, getTextureSampleType } from './builder/ast.js';
|
|
7
|
+
export { PBBuiltinScope, PBDoWhileScope, PBForScope, PBFunctionScope, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBScope, PBWhileScope, ProgramBuilder } from './builder/programbuilder.js';
|
|
8
|
+
export { PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBFunctionTypeInfo, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBSamplerAccessMode, PBSamplerTypeInfo, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, typeAny, typeAtomicI32, typeAtomicU32, typeBVec2, typeBVec3, typeBVec4, typeBool, typeF16, typeF16Vec2, typeF16Vec3, typeF16Vec4, typeF32, typeF32Vec2, typeF32Vec3, typeF32Vec4, typeFrexpResult, typeFrexpResultVec2, typeFrexpResultVec3, typeFrexpResultVec4, typeI16, typeI16Vec2, typeI16Vec2_Norm, typeI16Vec3, typeI16Vec3_Norm, typeI16Vec4, typeI16Vec4_Norm, typeI16_Norm, typeI32, typeI32Vec2, typeI32Vec2_Norm, typeI32Vec3, typeI32Vec3_Norm, typeI32Vec4, typeI32Vec4_Norm, typeI32_Norm, typeI8, typeI8Vec2, typeI8Vec2_Norm, typeI8Vec3, typeI8Vec3_Norm, typeI8Vec4, typeI8Vec4_Norm, typeI8_Norm, typeITex1D, typeITex2D, typeITex2DArray, typeITex3D, typeITexCube, typeITexCubeArray, typeITexMultisampled2D, typeMat2, typeMat2x3, typeMat2x4, typeMat3, typeMat3x2, typeMat3x4, typeMat4, typeMat4x2, typeMat4x3, typeSampler, typeSamplerComparison, typeTex1D, typeTex2D, typeTex2DArray, typeTex3D, typeTexCube, typeTexCubeArray, typeTexDepth2D, typeTexDepth2DArray, typeTexDepthCube, typeTexDepthCubeArray, typeTexDepthMultisampled2D, typeTexExternal, typeTexMultisampled2D, typeTexStorage1D_bgra8unorm, typeTexStorage1D_r32float, typeTexStorage1D_r32sint, typeTexStorage1D_r32uint, typeTexStorage1D_rg32float, typeTexStorage1D_rg32sint, typeTexStorage1D_rg32uint, typeTexStorage1D_rgba16float, typeTexStorage1D_rgba16sint, typeTexStorage1D_rgba16uint, typeTexStorage1D_rgba32float, typeTexStorage1D_rgba32sint, typeTexStorage1D_rgba32uint, typeTexStorage1D_rgba8sint, typeTexStorage1D_rgba8snorm, typeTexStorage1D_rgba8uint, typeTexStorage1D_rgba8unorm, typeTexStorage2DArray_bgra8unorm, typeTexStorage2DArray_r32float, typeTexStorage2DArray_r32sint, typeTexStorage2DArray_r32uint, typeTexStorage2DArray_rg32float, typeTexStorage2DArray_rg32sint, typeTexStorage2DArray_rg32uint, typeTexStorage2DArray_rgba16float, typeTexStorage2DArray_rgba16sint, typeTexStorage2DArray_rgba16uint, typeTexStorage2DArray_rgba32float, typeTexStorage2DArray_rgba32sint, typeTexStorage2DArray_rgba32uint, typeTexStorage2DArray_rgba8sint, typeTexStorage2DArray_rgba8snorm, typeTexStorage2DArray_rgba8uint, typeTexStorage2DArray_rgba8unorm, typeTexStorage2D_bgra8unorm, typeTexStorage2D_r32float, typeTexStorage2D_r32sint, typeTexStorage2D_r32uint, typeTexStorage2D_rg32float, typeTexStorage2D_rg32sint, typeTexStorage2D_rg32uint, typeTexStorage2D_rgba16float, typeTexStorage2D_rgba16sint, typeTexStorage2D_rgba16uint, typeTexStorage2D_rgba32float, typeTexStorage2D_rgba32sint, typeTexStorage2D_rgba32uint, typeTexStorage2D_rgba8sint, typeTexStorage2D_rgba8snorm, typeTexStorage2D_rgba8uint, typeTexStorage2D_rgba8unorm, typeTexStorage3D_bgra8unorm, typeTexStorage3D_r32float, typeTexStorage3D_r32sint, typeTexStorage3D_r32uint, typeTexStorage3D_rg32float, typeTexStorage3D_rg32sint, typeTexStorage3D_rg32uint, typeTexStorage3D_rgba16float, typeTexStorage3D_rgba16sint, typeTexStorage3D_rgba16uint, typeTexStorage3D_rgba32float, typeTexStorage3D_rgba32sint, typeTexStorage3D_rgba32uint, typeTexStorage3D_rgba8sint, typeTexStorage3D_rgba8snorm, typeTexStorage3D_rgba8uint, typeTexStorage3D_rgba8unorm, typeU16, typeU16Vec2, typeU16Vec2_Norm, typeU16Vec3, typeU16Vec3_Norm, typeU16Vec4, typeU16Vec4_Norm, typeU16_Norm, typeU32, typeU32Vec2, typeU32Vec2_Norm, typeU32Vec3, typeU32Vec3_Norm, typeU32Vec4, typeU32Vec4_Norm, typeU32_Norm, typeU8, typeU8Vec2, typeU8Vec2_Norm, typeU8Vec3, typeU8Vec3_Norm, typeU8Vec4, typeU8Vec4_Norm, typeU8_Norm, typeUTex1D, typeUTex2D, typeUTex2DArray, typeUTex3D, typeUTexCube, typeUTexCubeArray, typeUTexMultisampled2D, typeVoid } from './builder/types.js';
|
|
9
|
+
export { PBReflection } from './builder/reflection.js';
|
|
10
|
+
export { TextureAtlasManager } from './helpers/textureatlas.js';
|
|
11
|
+
export { Font, FontCanvas } from './helpers/font.js';
|
|
12
|
+
export { GlyphManager } from './helpers/glyphmanager.js';
|
|
13
|
+
export { DrawText } from './helpers/drawtext.js';
|
|
14
|
+
export { CPUTimer } from './timer.js';
|
|
15
|
+
export { StructuredBufferData } from './uniformdata.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/dist/timer.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract timer interface
|
|
3
|
+
* @public
|
|
4
|
+
*/ /**
|
|
5
|
+
* CPU timer class
|
|
6
|
+
* @public
|
|
7
|
+
*/ class CPUTimer {
|
|
8
|
+
/** @internal */ _cpuTimer;
|
|
9
|
+
/** @internal */ _cpuStart;
|
|
10
|
+
/** @internal */ _cpuTime;
|
|
11
|
+
/** @internal */ _ended;
|
|
12
|
+
constructor(){
|
|
13
|
+
this._cpuTimer = window.performance || window.Date;
|
|
14
|
+
this._cpuTime = null;
|
|
15
|
+
this._ended = false;
|
|
16
|
+
}
|
|
17
|
+
now() {
|
|
18
|
+
return this._cpuTimer.now();
|
|
19
|
+
}
|
|
20
|
+
begin() {
|
|
21
|
+
this._cpuStart = this.now();
|
|
22
|
+
this._cpuTime = null;
|
|
23
|
+
this._ended = false;
|
|
24
|
+
}
|
|
25
|
+
end() {
|
|
26
|
+
this._cpuTime = this.now() - this._cpuStart;
|
|
27
|
+
this._ended = true;
|
|
28
|
+
}
|
|
29
|
+
ended() {
|
|
30
|
+
return this._ended;
|
|
31
|
+
}
|
|
32
|
+
elapsed() {
|
|
33
|
+
return this._cpuTime;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { CPUTimer };
|
|
38
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { PBPrimitiveType } from './builder/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structured buffer data
|
|
5
|
+
* @public
|
|
6
|
+
*/ class StructuredBufferData {
|
|
7
|
+
/** @internal */ _cache;
|
|
8
|
+
/** @internal */ _buffer;
|
|
9
|
+
/** @internal */ _size;
|
|
10
|
+
/** @internal */ _uniformMap;
|
|
11
|
+
/** @internal */ _uniformPositions;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new structured buffer data
|
|
14
|
+
* @param layout - Layout of the structure
|
|
15
|
+
* @param buffer - Buffer that holds the data
|
|
16
|
+
*/ constructor(layout, buffer){
|
|
17
|
+
this._size = layout.byteSize + 15 & ~15;
|
|
18
|
+
if (this._size <= 0) {
|
|
19
|
+
throw new Error(`UniformBuffer(): invalid uniform buffer byte size: ${this._size}`);
|
|
20
|
+
}
|
|
21
|
+
// this._cache = new ArrayBuffer(size);
|
|
22
|
+
this._uniformMap = {};
|
|
23
|
+
this._uniformPositions = {};
|
|
24
|
+
this._cache = buffer instanceof ArrayBuffer ? buffer : null;
|
|
25
|
+
this._buffer = buffer instanceof ArrayBuffer ? null : buffer;
|
|
26
|
+
this.init(layout, 0, '');
|
|
27
|
+
}
|
|
28
|
+
/** The buffer size in bytes */ get byteLength() {
|
|
29
|
+
return this._size;
|
|
30
|
+
}
|
|
31
|
+
/** Get the data cache buffer */ get buffer() {
|
|
32
|
+
return this._cache;
|
|
33
|
+
}
|
|
34
|
+
/** Get all the uniform datas */ get uniforms() {
|
|
35
|
+
return this._uniformMap;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets the value of a structure member
|
|
39
|
+
* @param name - Name of the member
|
|
40
|
+
* @param value - Value to set
|
|
41
|
+
*/ set(name, value) {
|
|
42
|
+
if (value !== undefined) {
|
|
43
|
+
const view = this._uniformMap[name];
|
|
44
|
+
if (view) {
|
|
45
|
+
if (this._cache) {
|
|
46
|
+
if (typeof value === 'number') {
|
|
47
|
+
view[0] = value;
|
|
48
|
+
} else if (value?._v) {
|
|
49
|
+
view.set(value._v);
|
|
50
|
+
} else if (typeof value?.length === 'number') {
|
|
51
|
+
view.set(value);
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error('invalid uniform value');
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const size = this._uniformPositions[name][1];
|
|
57
|
+
if (typeof value === 'number') {
|
|
58
|
+
view[0] = value;
|
|
59
|
+
this._buffer.bufferSubData(this._uniformPositions[name][0], view);
|
|
60
|
+
} else if (value['BYTES_PER_ELEMENT'] && size <= value['byteLength']) {
|
|
61
|
+
const arr = value;
|
|
62
|
+
this._buffer.bufferSubData(this._uniformPositions[name][0], arr, 0, size / arr.BYTES_PER_ELEMENT >> 0);
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error('invalid uniform value');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const proto = Object.getPrototypeOf(value);
|
|
69
|
+
if (proto === Object.getPrototypeOf({})) {
|
|
70
|
+
this.setStruct(name, value);
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error('invalid uniform value');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** @internal */ setStruct(name, value) {
|
|
78
|
+
for(const k in value){
|
|
79
|
+
this.set(`${name}.${k}`, value[k]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** @internal */ init(layout, offset, prefix) {
|
|
83
|
+
for (const entry of layout.entries){
|
|
84
|
+
if (entry.subLayout) {
|
|
85
|
+
offset = this.init(entry.subLayout, offset, `${prefix}${entry.name}.`);
|
|
86
|
+
} else {
|
|
87
|
+
const name = `${prefix}${entry.name}`;
|
|
88
|
+
if (this._uniformPositions[name]) {
|
|
89
|
+
throw new Error(`UniformBuffer(): duplicate uniform name: ${name}`);
|
|
90
|
+
}
|
|
91
|
+
if (entry.offset < offset || entry.byteSize < 0) {
|
|
92
|
+
throw new Error('UniformBuffer(): invalid layout');
|
|
93
|
+
}
|
|
94
|
+
this._uniformPositions[name] = [
|
|
95
|
+
entry.offset,
|
|
96
|
+
entry.byteSize
|
|
97
|
+
];
|
|
98
|
+
let viewCtor = null;
|
|
99
|
+
switch(entry.type){
|
|
100
|
+
case PBPrimitiveType.F32:
|
|
101
|
+
viewCtor = Float32Array;
|
|
102
|
+
break;
|
|
103
|
+
case PBPrimitiveType.U32:
|
|
104
|
+
case PBPrimitiveType.BOOL:
|
|
105
|
+
viewCtor = Uint32Array;
|
|
106
|
+
break;
|
|
107
|
+
case PBPrimitiveType.I32:
|
|
108
|
+
viewCtor = Int32Array;
|
|
109
|
+
break;
|
|
110
|
+
case PBPrimitiveType.U16:
|
|
111
|
+
case PBPrimitiveType.U16_NORM:
|
|
112
|
+
case PBPrimitiveType.F16:
|
|
113
|
+
viewCtor = Uint16Array;
|
|
114
|
+
break;
|
|
115
|
+
case PBPrimitiveType.I16:
|
|
116
|
+
case PBPrimitiveType.I16_NORM:
|
|
117
|
+
viewCtor = Int16Array;
|
|
118
|
+
break;
|
|
119
|
+
case PBPrimitiveType.U8:
|
|
120
|
+
case PBPrimitiveType.U8_NORM:
|
|
121
|
+
viewCtor = Uint8Array;
|
|
122
|
+
break;
|
|
123
|
+
case PBPrimitiveType.I8:
|
|
124
|
+
case PBPrimitiveType.I8_NORM:
|
|
125
|
+
viewCtor = Int8Array;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (!viewCtor) {
|
|
129
|
+
throw new Error(`UniformBuffer(): invalid data type for uniform: ${name}`);
|
|
130
|
+
}
|
|
131
|
+
if (entry.byteSize % viewCtor.BYTES_PER_ELEMENT) {
|
|
132
|
+
throw new Error(`UniformBuffer(): invalid byte size for uniform: ${name}`);
|
|
133
|
+
}
|
|
134
|
+
if (this._cache) {
|
|
135
|
+
this._uniformMap[name] = new viewCtor(this._cache, entry.offset, entry.byteSize / viewCtor.BYTES_PER_ELEMENT);
|
|
136
|
+
} else {
|
|
137
|
+
this._uniformMap[name] = new viewCtor(1);
|
|
138
|
+
}
|
|
139
|
+
offset = entry.offset + entry.byteSize;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return offset;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { StructuredBufferData };
|
|
147
|
+
//# sourceMappingURL=uniformdata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniformdata.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { MAX_VERTEX_ATTRIBUTES, getVertexAttribByName, GPUResourceUsageFlags, getVertexBufferAttribType, getVertexBufferStride } from './gpuobject.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The vertex data class
|
|
5
|
+
* @public
|
|
6
|
+
*/ class VertexData {
|
|
7
|
+
/** @internal */ _vertexBuffers;
|
|
8
|
+
/** @internal */ _indexBuffer;
|
|
9
|
+
/** @internal */ _drawOffset;
|
|
10
|
+
constructor(){
|
|
11
|
+
this._vertexBuffers = [];
|
|
12
|
+
for(let i = 0; i < MAX_VERTEX_ATTRIBUTES; i++){
|
|
13
|
+
this._vertexBuffers.push(null);
|
|
14
|
+
}
|
|
15
|
+
this._indexBuffer = null;
|
|
16
|
+
this._drawOffset = 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new instance of VertexData by copying from this object
|
|
20
|
+
* @returns New instance of VertexData
|
|
21
|
+
*/ clone() {
|
|
22
|
+
const newVertexData = new VertexData();
|
|
23
|
+
newVertexData._vertexBuffers = this._vertexBuffers.slice();
|
|
24
|
+
newVertexData._indexBuffer = this._indexBuffer;
|
|
25
|
+
newVertexData._drawOffset = this._drawOffset;
|
|
26
|
+
return newVertexData;
|
|
27
|
+
}
|
|
28
|
+
/** Vertex buffer information list */ get vertexBuffers() {
|
|
29
|
+
return this._vertexBuffers;
|
|
30
|
+
}
|
|
31
|
+
/** Index buffer */ get indexBuffer() {
|
|
32
|
+
return this._indexBuffer;
|
|
33
|
+
}
|
|
34
|
+
/** Draw offset */ getDrawOffset() {
|
|
35
|
+
return this._drawOffset;
|
|
36
|
+
}
|
|
37
|
+
setDrawOffset(offset) {
|
|
38
|
+
if (offset !== this._drawOffset) {
|
|
39
|
+
this._drawOffset = offset;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets the vertex buffer by specific vertex semantic
|
|
44
|
+
* @param semantic - The vertex semantic
|
|
45
|
+
* @returns Vertex buffer of the given semantic
|
|
46
|
+
*/ getVertexBuffer(semantic) {
|
|
47
|
+
return this._vertexBuffers[getVertexAttribByName(semantic)]?.buffer ?? null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the vertex buffer information by specific vertex semantic
|
|
51
|
+
* @param semantic - The vertex semantic
|
|
52
|
+
* @returns Vertex buffer information of the given semantic
|
|
53
|
+
*/ getVertexBufferInfo(semantic) {
|
|
54
|
+
return this._vertexBuffers[getVertexAttribByName(semantic)] ?? null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets the index buffer
|
|
58
|
+
* @returns The index buffer
|
|
59
|
+
*/ getIndexBuffer() {
|
|
60
|
+
return this._indexBuffer || null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sets a vertex buffer
|
|
64
|
+
* @param buffer - The vertex buffer object
|
|
65
|
+
* @param stepMode - Step mode of the buffer
|
|
66
|
+
* @returns The buffer that was set
|
|
67
|
+
*/ setVertexBuffer(buffer, stepMode) {
|
|
68
|
+
if (!buffer || !(buffer.usage & GPUResourceUsageFlags.BF_VERTEX)) {
|
|
69
|
+
throw new Error('setVertexBuffer() failed: buffer is null or buffer has not Vertex usage flag');
|
|
70
|
+
}
|
|
71
|
+
stepMode = stepMode || 'vertex';
|
|
72
|
+
const vertexType = buffer.structure.structMembers[0].type.elementType;
|
|
73
|
+
if (vertexType.isStructType()) {
|
|
74
|
+
let offset = 0;
|
|
75
|
+
for (const attrib of vertexType.structMembers){
|
|
76
|
+
const loc = getVertexAttribByName(attrib.name);
|
|
77
|
+
this.internalSetVertexBuffer(loc, buffer, offset, stepMode);
|
|
78
|
+
offset += attrib.size;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
const loc = getVertexAttribByName(buffer.structure.structMembers[0].name);
|
|
82
|
+
this.internalSetVertexBuffer(loc, buffer, 0, stepMode);
|
|
83
|
+
}
|
|
84
|
+
return buffer;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Removes a vertex buffer
|
|
88
|
+
* @param buffer - Vertex buffer to be removed
|
|
89
|
+
* @returns true if the buffer was successfully removed, otherwise false
|
|
90
|
+
*/ removeVertexBuffer(buffer) {
|
|
91
|
+
let removed = false;
|
|
92
|
+
for(let loc = 0; loc < this._vertexBuffers.length; loc++){
|
|
93
|
+
const info = this._vertexBuffers[loc];
|
|
94
|
+
const remove = info?.buffer === buffer;
|
|
95
|
+
if (remove) {
|
|
96
|
+
this._vertexBuffers[loc] = null;
|
|
97
|
+
removed = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return removed;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets the index buffer
|
|
104
|
+
* @param buffer - Index buffer to be set
|
|
105
|
+
* @returns The index buffer that was set
|
|
106
|
+
*/ setIndexBuffer(buffer) {
|
|
107
|
+
if (buffer !== this._indexBuffer) {
|
|
108
|
+
this._indexBuffer = buffer || null;
|
|
109
|
+
}
|
|
110
|
+
return buffer;
|
|
111
|
+
}
|
|
112
|
+
/** @internal */ internalSetVertexBuffer(loc, buffer, offset, stepMode) {
|
|
113
|
+
if (loc < 0 || loc >= MAX_VERTEX_ATTRIBUTES) {
|
|
114
|
+
throw new Error(`setVertexBuffer() failed: location out of bounds: ${loc}`);
|
|
115
|
+
}
|
|
116
|
+
offset = Number(offset) || 0;
|
|
117
|
+
stepMode = stepMode || 'vertex';
|
|
118
|
+
const old = this._vertexBuffers[loc];
|
|
119
|
+
if (!old || old.buffer !== buffer || old.offset !== offset || old.stepMode !== stepMode) {
|
|
120
|
+
this._vertexBuffers[loc] = {
|
|
121
|
+
buffer: buffer,
|
|
122
|
+
offset: offset,
|
|
123
|
+
type: getVertexBufferAttribType(buffer.structure, loc),
|
|
124
|
+
stride: getVertexBufferStride(buffer.structure),
|
|
125
|
+
drawOffset: 0,
|
|
126
|
+
stepMode: stepMode
|
|
127
|
+
};
|
|
128
|
+
return buffer;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { VertexData };
|
|
135
|
+
//# sourceMappingURL=vertexdata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vertexdata.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zephyr3d/device",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "base system for zephyr3d library",
|
|
5
|
+
"homepage": "https://github.com/gavinyork/zephyr3d#readme",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"**/*.js",
|
|
12
|
+
"**/*.d.ts",
|
|
13
|
+
"**/*.js.map"
|
|
14
|
+
],
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/gavinyork/zephyr3d.git"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "shx rm -rf ./dist .tsbuildinfo",
|
|
22
|
+
"tsc": "tsc -p . --noEmit",
|
|
23
|
+
"build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 rollup -c --silent"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"javascript",
|
|
27
|
+
"3d",
|
|
28
|
+
"rendering",
|
|
29
|
+
"engine",
|
|
30
|
+
"webgl",
|
|
31
|
+
"webgpu",
|
|
32
|
+
"canvas",
|
|
33
|
+
"zephyr3d",
|
|
34
|
+
"device"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/gavinyork/zephyr3d/issues"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=16.18.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@babel/core": "^7.20.12",
|
|
45
|
+
"@babel/preset-env": "^7.20.2",
|
|
46
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
48
|
+
"@rollup/plugin-strip": "^3.0.2",
|
|
49
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
50
|
+
"@rollup/pluginutils": "^5.0.2",
|
|
51
|
+
"rollup": "^3.15.0",
|
|
52
|
+
"rollup-plugin-dts": "^5.2.0",
|
|
53
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
54
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
55
|
+
"@swc/core": "^1.3.62",
|
|
56
|
+
"rollup-plugin-swc3": "^0.8.2",
|
|
57
|
+
"shx": "^0.3.4",
|
|
58
|
+
"cross-env": "^7.0.3",
|
|
59
|
+
"typescript": "^5.1.3",
|
|
60
|
+
"@zephyr3d/base": "workspace:^0.1.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@zephyr3d/base": "workspace:^0.1.0"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@webgpu/types": "^0.1.31",
|
|
67
|
+
"@types/node": "^18.13.0"
|
|
68
|
+
}
|
|
69
|
+
}
|