chorama 0.0.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/.configs/tsconfig.lib.json +43 -0
- package/.configs/tsconfig.website.json +34 -0
- package/.github/workflows/static.yml +88 -0
- package/.vscode/launch.json +29 -0
- package/.vscode/tasks.json +19 -0
- package/README.md +127 -0
- package/assets/images/disappointed.jpg +0 -0
- package/assets/images/skybox/grimmnight_back.png +0 -0
- package/assets/images/skybox/grimmnight_bottom.png +0 -0
- package/assets/images/skybox/grimmnight_front.png +0 -0
- package/assets/images/skybox/grimmnight_left.png +0 -0
- package/assets/images/skybox/grimmnight_right.png +0 -0
- package/assets/images/skybox/grimmnight_top.png +0 -0
- package/assets/images/skybox/miramar_back.png +0 -0
- package/assets/images/skybox/miramar_bottom.png +0 -0
- package/assets/images/skybox/miramar_front.png +0 -0
- package/assets/images/skybox/miramar_left.png +0 -0
- package/assets/images/skybox/miramar_right.png +0 -0
- package/assets/images/skybox/miramar_top.png +0 -0
- package/assets/images/uv.jpg +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/index.bin +0 -0
- package/assets/models/gltf/flight_helmet/index.gltf +705 -0
- package/assets/models/gltf/object.gltf +23 -0
- package/assets/models/gltf/pirate_girl/index.bin +0 -0
- package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
- package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
- package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
- package/astro.config.mjs +45 -0
- package/content/guide/api-map.md +89 -0
- package/content/guide/camera-and-controls.md +98 -0
- package/content/guide/first-scene.md +176 -0
- package/content/guide/index.md +72 -0
- package/content/guide/installation.md +179 -0
- package/content/guide/materials-and-lighting.md +138 -0
- package/content/guide/plugins-and-render-pipeline.md +124 -0
- package/content/guide/render-targets-and-views.md +147 -0
- package/content/guide/scene-graph-and-transforms.md +113 -0
- package/content/guide/textures-and-assets.md +120 -0
- package/content/guide/troubleshooting.md +49 -0
- package/env.d.ts +19 -0
- package/examples/addons/rendergraph_gui.js +580 -0
- package/examples/camera/orthographic.js +120 -0
- package/examples/camera/perspective.js +138 -0
- package/examples/lights/directional.js +397 -0
- package/examples/lights/multiple_spot_lights.js +304 -0
- package/examples/lights/point.js +337 -0
- package/examples/lights/spot.js +366 -0
- package/examples/loader/gltf_material.js +111 -0
- package/examples/loader/gltfloader.js +78 -0
- package/examples/loader/objloader.js +95 -0
- package/examples/material/cullface.js +111 -0
- package/examples/material/materials.js +126 -0
- package/examples/material/standard/basic.js +164 -0
- package/examples/mesh/circle.js +117 -0
- package/examples/mesh/cuboid.js +151 -0
- package/examples/mesh/cylinder.js +139 -0
- package/examples/mesh/geometries.js +108 -0
- package/examples/mesh/meshTopology.js +103 -0
- package/examples/mesh/plane.js +117 -0
- package/examples/mesh/skinning.js +136 -0
- package/examples/mesh/uvsphere.js +113 -0
- package/examples/other/rotatingCube.js +93 -0
- package/examples/other/rotatingSphere.js +96 -0
- package/examples/rendertarget/basic_canvas.js +130 -0
- package/examples/rendertarget/depth_texture.js +130 -0
- package/examples/rendertarget/image_target.js +140 -0
- package/examples/rendertarget/multiple_views.js +158 -0
- package/examples/rendertarget/render_masks.js +173 -0
- package/examples/rendertarget/split_screen.js +123 -0
- package/examples/rendertarget/split_view.js +137 -0
- package/examples/skybox/skybox.js +111 -0
- package/examples/texture/arrays.js +156 -0
- package/examples/texture/textureWrap.js +118 -0
- package/examples/transform/propagation.js +92 -0
- package/package.json +55 -0
- package/rollup.config.js +66 -0
- package/scripts/stage-chorama.mjs +29 -0
- package/src/caches/cache.js +420 -0
- package/src/caches/index.js +2 -0
- package/src/caches/uniformbuffers.js +104 -0
- package/src/cameracontrols/index.js +258 -0
- package/src/constants/index.js +3 -0
- package/src/constants/mesh.js +197 -0
- package/src/constants/others.js +218 -0
- package/src/constants/texture.js +183 -0
- package/src/core/constants.js +14 -0
- package/src/core/extensions.js +42 -0
- package/src/core/index.js +7 -0
- package/src/core/layouts/index.js +4 -0
- package/src/core/layouts/meshvertex.js +60 -0
- package/src/core/layouts/uniform.js +21 -0
- package/src/core/layouts/uniformbuffer.js +15 -0
- package/src/core/layouts/vertexbuffer.js +43 -0
- package/src/core/limits.js +247 -0
- package/src/core/resources/blendparams.js +89 -0
- package/src/core/resources/framebuffer.js +127 -0
- package/src/core/resources/gpubuffer.js +32 -0
- package/src/core/resources/gpumesh.js +43 -0
- package/src/core/resources/gputexture.js +73 -0
- package/src/core/resources/index.js +5 -0
- package/src/core/shader.js +62 -0
- package/src/core/webgl/bindgroup.js +89 -0
- package/src/core/webgl/descriptors.js +104 -0
- package/src/core/webgl/index.js +5 -0
- package/src/core/webgl/renderpassencoder.js +96 -0
- package/src/core/webgl/renderpipeline.js +54 -0
- package/src/core/webgl/utils.js +371 -0
- package/src/core/webgl/webglrenderdevice.js +235 -0
- package/src/function.js +358 -0
- package/src/index.js +15 -0
- package/src/loader/gltf.js +2172 -0
- package/src/loader/index.js +3 -0
- package/src/loader/loader.js +174 -0
- package/src/loader/obj.js +188 -0
- package/src/loader/texture.js +85 -0
- package/src/loader/utils.js +16 -0
- package/src/material/basic.js +75 -0
- package/src/material/depth.js +73 -0
- package/src/material/index.js +8 -0
- package/src/material/lambert.js +73 -0
- package/src/material/material.js +106 -0
- package/src/material/normal.js +30 -0
- package/src/material/phong.js +86 -0
- package/src/material/raw.js +52 -0
- package/src/material/standard.js +221 -0
- package/src/math/index.js +3 -0
- package/src/math/transform.js +38 -0
- package/src/mesh/attribute/attribute.js +79 -0
- package/src/mesh/attribute/index.js +1 -0
- package/src/mesh/attributedata/index.js +1 -0
- package/src/mesh/attributedata/separate.js +180 -0
- package/src/mesh/builders/base.js +41 -0
- package/src/mesh/builders/circle.js +63 -0
- package/src/mesh/builders/cuboid.js +135 -0
- package/src/mesh/builders/cylinder.js +131 -0
- package/src/mesh/builders/index.js +7 -0
- package/src/mesh/builders/plane.js +73 -0
- package/src/mesh/builders/utils.js +20 -0
- package/src/mesh/builders/uvsphere.js +80 -0
- package/src/mesh/builders/wireframe.js +62 -0
- package/src/mesh/index.js +4 -0
- package/src/mesh/mesh.js +149 -0
- package/src/objects/bone.js +17 -0
- package/src/objects/camera/camera.js +56 -0
- package/src/objects/camera/index.js +2 -0
- package/src/objects/camera/projection.js +203 -0
- package/src/objects/debug/index.js +1 -0
- package/src/objects/debug/skeleton.js +28 -0
- package/src/objects/index.js +7 -0
- package/src/objects/light/ambient.js +20 -0
- package/src/objects/light/directional.js +29 -0
- package/src/objects/light/index.js +5 -0
- package/src/objects/light/point.js +32 -0
- package/src/objects/light/shadow/index.js +1 -0
- package/src/objects/light/shadow/shadow.js +67 -0
- package/src/objects/light/spot.js +56 -0
- package/src/objects/mesh.js +141 -0
- package/src/objects/object3d.js +167 -0
- package/src/objects/skybox.js +38 -0
- package/src/plugins/camera/camera.js +19 -0
- package/src/plugins/camera/index.js +2 -0
- package/src/plugins/camera/nodes/cameraview.js +46 -0
- package/src/plugins/camera/nodes/index.js +2 -0
- package/src/plugins/camera/nodes/opaquepass.js +79 -0
- package/src/plugins/index.js +6 -0
- package/src/plugins/light/index.js +2 -0
- package/src/plugins/light/light.js +23 -0
- package/src/plugins/light/nodes/index.js +1 -0
- package/src/plugins/light/nodes/light.js +127 -0
- package/src/plugins/meshmaterial/index.js +3 -0
- package/src/plugins/meshmaterial/meshmaterial.js +381 -0
- package/src/plugins/meshmaterial/nodes/index.js +1 -0
- package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
- package/src/plugins/meshmaterial/resources/index.js +1 -0
- package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
- package/src/plugins/shadow/index.js +3 -0
- package/src/plugins/shadow/nodes/index.js +3 -0
- package/src/plugins/shadow/nodes/shadow.js +272 -0
- package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
- package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
- package/src/plugins/shadow/resources/ShadowMap.js +99 -0
- package/src/plugins/shadow/resources/index.js +2 -0
- package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
- package/src/plugins/shadow/shadow.js +31 -0
- package/src/plugins/skeletonhelper/index.js +1 -0
- package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
- package/src/plugins/skybox/index.js +3 -0
- package/src/plugins/skybox/nodes/index.js +1 -0
- package/src/plugins/skybox/nodes/skybox.js +143 -0
- package/src/plugins/skybox/resources/index.js +2 -0
- package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
- package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
- package/src/plugins/skybox/skybox.js +137 -0
- package/src/renderer/core/index.js +179 -0
- package/src/renderer/graph/index.js +3 -0
- package/src/renderer/graph/nodes.js +34 -0
- package/src/renderer/graph/rendergraph.js +182 -0
- package/src/renderer/index.js +5 -0
- package/src/renderer/plugin.js +36 -0
- package/src/renderer/renderer.js +179 -0
- package/src/renderer/views.js +28 -0
- package/src/rendertarget/canvastarget.js +30 -0
- package/src/rendertarget/image.js +132 -0
- package/src/rendertarget/index.js +3 -0
- package/src/rendertarget/rendertarget.js +89 -0
- package/src/shader/basicFragment.glsl +30 -0
- package/src/shader/basicVertex.glsl +87 -0
- package/src/shader/common/color.glsl +7 -0
- package/src/shader/common/common.glsl +25 -0
- package/src/shader/common/index.js +4 -0
- package/src/shader/common/light.glsl +437 -0
- package/src/shader/common/math.glsl +12 -0
- package/src/shader/debug/index.js +2 -0
- package/src/shader/debug/skeletonFragment.glsl +8 -0
- package/src/shader/debug/skeletonVertex.glsl +27 -0
- package/src/shader/depthFragment.glsl +37 -0
- package/src/shader/index.js +11 -0
- package/src/shader/lambertFragment.glsl +126 -0
- package/src/shader/normalFragment.glsl +25 -0
- package/src/shader/phongFragment.glsl +140 -0
- package/src/shader/skyboxFragment.glsl +16 -0
- package/src/shader/skyboxVertex.glsl +20 -0
- package/src/shader/standardFragment.glsl +274 -0
- package/src/texture/index.js +2 -0
- package/src/texture/sampler.js +111 -0
- package/src/texture/texture.js +234 -0
- package/src/utils/index.js +115 -0
- package/tsconfig.json +11 -0
- package/website/config/index.ts +1 -0
- package/website/config/navigation.ts +53 -0
- package/website/content.config.ts +92 -0
- package/website/layouts/DocLayout.astro +501 -0
- package/website/layouts/Example.astro +91 -0
- package/website/pages/examples/[...slug].astro +77 -0
- package/website/pages/examples/index.astro +98 -0
- package/website/pages/examples/samples/[...slug].astro +17 -0
- package/website/pages/guide/[slug].astro +30 -0
- package/website/pages/guide/index.astro +21 -0
- package/website/pages/index.astro +9 -0
- package/website/plugins/remark-link-base.js +23 -0
- package/website/utils/url.ts +30 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {number}
|
|
3
|
+
*/
|
|
4
|
+
export const TextureFormat = /** @type {const} */({
|
|
5
|
+
// --- 8-bit ---
|
|
6
|
+
R8Unorm: 1,
|
|
7
|
+
R8Snorm: 2,
|
|
8
|
+
R8Uint: 3,
|
|
9
|
+
R8Sint: 4,
|
|
10
|
+
|
|
11
|
+
// --- 16-bit ---
|
|
12
|
+
R16Uint: 5,
|
|
13
|
+
R16Sint: 6,
|
|
14
|
+
R16Float: 7,
|
|
15
|
+
RG8Unorm: 8,
|
|
16
|
+
RG8Snorm: 9,
|
|
17
|
+
RG8Uint: 10,
|
|
18
|
+
RG8Sint: 11,
|
|
19
|
+
|
|
20
|
+
// --- 32-bit ---
|
|
21
|
+
R32Uint: 12,
|
|
22
|
+
R32Sint: 13,
|
|
23
|
+
R32Float: 14,
|
|
24
|
+
RG16Uint: 15,
|
|
25
|
+
RG16Sint: 16,
|
|
26
|
+
RG16Float: 17,
|
|
27
|
+
RGBA8Unorm: 18,
|
|
28
|
+
RGBA8UnormSRGB: 19,
|
|
29
|
+
RGBA8Snorm: 20,
|
|
30
|
+
RGBA8Uint: 21,
|
|
31
|
+
RGBA8Sint: 22,
|
|
32
|
+
|
|
33
|
+
// --- 64-bit ---
|
|
34
|
+
RG32Uint: 23,
|
|
35
|
+
RG32Sint: 24,
|
|
36
|
+
RG32Float: 25,
|
|
37
|
+
RGBA16Uint: 26,
|
|
38
|
+
RGBA16Sint: 27,
|
|
39
|
+
RGBA16Float: 28,
|
|
40
|
+
|
|
41
|
+
// --- 128-bit ---
|
|
42
|
+
RGBA32Uint: 29,
|
|
43
|
+
RGBA32Sint: 30,
|
|
44
|
+
RGBA32Float: 31,
|
|
45
|
+
|
|
46
|
+
// --- Depth / Stencil ---
|
|
47
|
+
Stencil8: 32,
|
|
48
|
+
Depth16Unorm: 33,
|
|
49
|
+
Depth24Plus: 34,
|
|
50
|
+
Depth24PlusStencil8: 35,
|
|
51
|
+
Depth32Float: 36,
|
|
52
|
+
Depth32FloatStencil8: 37,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @enum {number}
|
|
57
|
+
*/
|
|
58
|
+
export const TextureFilter = /** @type {const} */({
|
|
59
|
+
Nearest: 0x2600,
|
|
60
|
+
Linear: 0x2601
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @enum {number}
|
|
65
|
+
*/
|
|
66
|
+
export const TextureWrap = /** @type {const} */({
|
|
67
|
+
Repeat: 0x2901,
|
|
68
|
+
Clamp: 0x812F,
|
|
69
|
+
MirrorRepeat: 0x8370
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @enum {number}
|
|
74
|
+
* Texture binding targets
|
|
75
|
+
*/
|
|
76
|
+
export const TextureType = /** @type {const} */({
|
|
77
|
+
Texture2D: 0x0DE1, // gl.TEXTURE_2D
|
|
78
|
+
Texture2DArray: 0x8C1A, // gl.TEXTURE_2D_ARRAY
|
|
79
|
+
Texture3D: 0x806F, // gl.TEXTURE_3D
|
|
80
|
+
TextureCubeMap: 0x8513 // gl.TEXTURE_CUBE_MAP
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the size in bytes per texel for a given TextureFormat.
|
|
85
|
+
* @param {TextureFormat} format
|
|
86
|
+
* @returns {number}
|
|
87
|
+
*/
|
|
88
|
+
export function getTextureFormatSize(format) {
|
|
89
|
+
switch (format) {
|
|
90
|
+
// 8-bit = 1 byte
|
|
91
|
+
case TextureFormat.R8Unorm:
|
|
92
|
+
case TextureFormat.R8Snorm:
|
|
93
|
+
case TextureFormat.R8Uint:
|
|
94
|
+
case TextureFormat.R8Sint:
|
|
95
|
+
return 1;
|
|
96
|
+
|
|
97
|
+
// 16-bit = 2 bytes
|
|
98
|
+
case TextureFormat.R16Uint:
|
|
99
|
+
case TextureFormat.R16Sint:
|
|
100
|
+
case TextureFormat.R16Float:
|
|
101
|
+
case TextureFormat.RG8Unorm:
|
|
102
|
+
case TextureFormat.RG8Snorm:
|
|
103
|
+
case TextureFormat.RG8Uint:
|
|
104
|
+
case TextureFormat.RG8Sint:
|
|
105
|
+
return 2;
|
|
106
|
+
|
|
107
|
+
// 32-bit = 4 bytes
|
|
108
|
+
case TextureFormat.R32Uint:
|
|
109
|
+
case TextureFormat.R32Sint:
|
|
110
|
+
case TextureFormat.R32Float:
|
|
111
|
+
case TextureFormat.RG16Uint:
|
|
112
|
+
case TextureFormat.RG16Sint:
|
|
113
|
+
case TextureFormat.RG16Float:
|
|
114
|
+
case TextureFormat.RGBA8Unorm:
|
|
115
|
+
case TextureFormat.RGBA8UnormSRGB:
|
|
116
|
+
case TextureFormat.RGBA8Snorm:
|
|
117
|
+
case TextureFormat.RGBA8Uint:
|
|
118
|
+
case TextureFormat.RGBA8Sint:
|
|
119
|
+
return 4;
|
|
120
|
+
|
|
121
|
+
// 64-bit = 8 bytes
|
|
122
|
+
case TextureFormat.RG32Uint:
|
|
123
|
+
case TextureFormat.RG32Sint:
|
|
124
|
+
case TextureFormat.RG32Float:
|
|
125
|
+
case TextureFormat.RGBA16Uint:
|
|
126
|
+
case TextureFormat.RGBA16Sint:
|
|
127
|
+
case TextureFormat.RGBA16Float:
|
|
128
|
+
return 8;
|
|
129
|
+
|
|
130
|
+
// 128-bit = 16 bytes
|
|
131
|
+
case TextureFormat.RGBA32Uint:
|
|
132
|
+
case TextureFormat.RGBA32Sint:
|
|
133
|
+
case TextureFormat.RGBA32Float:
|
|
134
|
+
return 16;
|
|
135
|
+
|
|
136
|
+
// Depth/stencil formats — size varies and is implementation-specific
|
|
137
|
+
case TextureFormat.Stencil8:
|
|
138
|
+
return 1;
|
|
139
|
+
case TextureFormat.Depth16Unorm:
|
|
140
|
+
return 2;
|
|
141
|
+
case TextureFormat.Depth24Plus:
|
|
142
|
+
case TextureFormat.Depth24PlusStencil8:
|
|
143
|
+
return 4; // Typically 3 or 4 bytes — assume 4
|
|
144
|
+
case TextureFormat.Depth32Float:
|
|
145
|
+
return 4;
|
|
146
|
+
case TextureFormat.Depth32FloatStencil8:
|
|
147
|
+
return 5; // 4 (depth) + 1 (stencil) — approximate
|
|
148
|
+
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`Unknown or unsupported texture format: ${format}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {TextureFormat} format
|
|
156
|
+
*/
|
|
157
|
+
export function hasDepthComponent(format) {
|
|
158
|
+
switch (format) {
|
|
159
|
+
case TextureFormat.Depth16Unorm:
|
|
160
|
+
case TextureFormat.Depth24Plus:
|
|
161
|
+
case TextureFormat.Depth24PlusStencil8:
|
|
162
|
+
case TextureFormat.Depth32Float:
|
|
163
|
+
case TextureFormat.Depth32FloatStencil8:
|
|
164
|
+
return true;
|
|
165
|
+
default:
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Checks if a format has a stencil component
|
|
172
|
+
* @param {TextureFormat} format
|
|
173
|
+
*/
|
|
174
|
+
export function hasStencilComponent(format) {
|
|
175
|
+
switch (format) {
|
|
176
|
+
case TextureFormat.Stencil8:
|
|
177
|
+
case TextureFormat.Depth24PlusStencil8:
|
|
178
|
+
case TextureFormat.Depth32FloatStencil8:
|
|
179
|
+
return true;
|
|
180
|
+
default:
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {number}
|
|
3
|
+
* Comparison functions for depth, stencil, and sampler tests
|
|
4
|
+
*/
|
|
5
|
+
export const CompareFunction = /** @type {const} */({
|
|
6
|
+
Never: 0x0200, // gl.NEVER
|
|
7
|
+
Less: 0x0201, // gl.LESS
|
|
8
|
+
Equal: 0x0202, // gl.EQUAL
|
|
9
|
+
Lequal: 0x0203, // gl.LEQUAL
|
|
10
|
+
Greater: 0x0204, // gl.GREATER
|
|
11
|
+
NotEqual: 0x0205, // gl.NOTEQUAL
|
|
12
|
+
Gequal: 0x0206, // gl.GEQUAL
|
|
13
|
+
Always: 0x0207 // gl.ALWAYS
|
|
14
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class WebGLExtensions {
|
|
2
|
+
/**
|
|
3
|
+
* @param {WebGL2RenderingContext} gl
|
|
4
|
+
*/
|
|
5
|
+
constructor(gl) {
|
|
6
|
+
this.gl = gl;
|
|
7
|
+
this.supported = gl.getSupportedExtensions() || [];
|
|
8
|
+
this.cache = new Map();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if an extension is supported.
|
|
13
|
+
* @param {string} name
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
has(name) {
|
|
17
|
+
return this.supported.includes(name);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get (and cache) an extension object.
|
|
22
|
+
* @param {string} name
|
|
23
|
+
* @returns {object | undefined}
|
|
24
|
+
*/
|
|
25
|
+
get(name) {
|
|
26
|
+
if (this.cache.has(name))
|
|
27
|
+
return this.cache.get(name);
|
|
28
|
+
|
|
29
|
+
const ext = this.has(name) ? this.gl.getExtension(name) : undefined;
|
|
30
|
+
this.cache.set(name, ext);
|
|
31
|
+
return ext;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initialize all supported extensions at once
|
|
36
|
+
*/
|
|
37
|
+
initAll() {
|
|
38
|
+
for (const name of this.supported) {
|
|
39
|
+
this.get(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Mesh, Attribute } from "../../mesh/index.js"
|
|
2
|
+
import { VertexBufferLayout } from "./vertexbuffer.js"
|
|
3
|
+
|
|
4
|
+
export class MeshVertexLayout {
|
|
5
|
+
/**
|
|
6
|
+
* @type {readonly VertexBufferLayout[]}
|
|
7
|
+
*/
|
|
8
|
+
layouts = []
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {VertexBufferLayout[]} layouts
|
|
12
|
+
*/
|
|
13
|
+
constructor(layouts) {
|
|
14
|
+
this.layouts = layouts
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Mesh} mesh
|
|
19
|
+
*/
|
|
20
|
+
compatibleWithMesh(mesh) {
|
|
21
|
+
for (const attributeName of mesh.attributes.keys()) {
|
|
22
|
+
let found = false
|
|
23
|
+
for (const layout of this.layouts) {
|
|
24
|
+
found = layout.hasOnly([attributeName])
|
|
25
|
+
if (found) {
|
|
26
|
+
break
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!found) {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {Attribute} attribute
|
|
39
|
+
*/
|
|
40
|
+
hasAttribute(attribute){
|
|
41
|
+
return this.layouts.some((layout)=>layout.has(attribute))
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @param {Mesh} mesh
|
|
45
|
+
* @param {ReadonlyMap<string, Attribute>} attributes
|
|
46
|
+
* @returns {MeshVertexLayout}
|
|
47
|
+
*/
|
|
48
|
+
static fromMesh(mesh, attributes) {
|
|
49
|
+
const result = []
|
|
50
|
+
for (const name of mesh.attributes.keys()) {
|
|
51
|
+
const attribute = attributes.get(name)
|
|
52
|
+
if (!attribute) {
|
|
53
|
+
throw `The attribute "${name}" is not available in the attribute map`
|
|
54
|
+
}
|
|
55
|
+
result.push(new VertexBufferLayout([attribute]))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return new MeshVertexLayout(result)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UniformType } from "../../constants/index.js"
|
|
2
|
+
|
|
3
|
+
export class Uniform {
|
|
4
|
+
location
|
|
5
|
+
size
|
|
6
|
+
type
|
|
7
|
+
/**
|
|
8
|
+
* @type {number | undefined}
|
|
9
|
+
*/
|
|
10
|
+
texture_unit
|
|
11
|
+
/**
|
|
12
|
+
* @param {WebGLUniformLocation} location
|
|
13
|
+
* @param {number} size
|
|
14
|
+
* @param {UniformType} type
|
|
15
|
+
*/
|
|
16
|
+
constructor(location,type,size){
|
|
17
|
+
this.location = location
|
|
18
|
+
this.type = type
|
|
19
|
+
this.size = size
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class UniformBufferLayout {
|
|
2
|
+
name
|
|
3
|
+
fields
|
|
4
|
+
size
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} name
|
|
7
|
+
* @param {any} size
|
|
8
|
+
* @param {Map<string, {name:string,size:string}>} fields
|
|
9
|
+
*/
|
|
10
|
+
constructor(name, size, fields) {
|
|
11
|
+
this.name = name
|
|
12
|
+
this.size = size
|
|
13
|
+
this.fields = fields
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Attribute } from "../../mesh/index.js"
|
|
2
|
+
|
|
3
|
+
export class VertexBufferLayout {
|
|
4
|
+
/**
|
|
5
|
+
* @type {readonly Attribute[]}
|
|
6
|
+
*/
|
|
7
|
+
attributes = []
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Attribute[]} attributes
|
|
11
|
+
*/
|
|
12
|
+
constructor(attributes) {
|
|
13
|
+
this.attributes = attributes
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Attribute} attribute
|
|
18
|
+
*/
|
|
19
|
+
has(attribute){
|
|
20
|
+
for (let i = 0; i < this.attributes.length; i++) {
|
|
21
|
+
if(this.attributes[i]?.id === attribute.id){
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @param {string[]} attributeIds
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
hasOnly(attributeIds) {
|
|
33
|
+
if (attributeIds.length !== this.attributes.length) return false
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < attributeIds.length; i++) {
|
|
36
|
+
if (this.attributes.findIndex(value => value.name === attributeIds[i]) === -1) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queries and stores WebGL 2.0 GPU capability limits in organized groups.
|
|
3
|
+
*/
|
|
4
|
+
export class WebGLDeviceLimits {
|
|
5
|
+
/**
|
|
6
|
+
* @type {WebGLTextureLimits}
|
|
7
|
+
*/
|
|
8
|
+
textures
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @type {WebGLBufferLimits}
|
|
12
|
+
*/
|
|
13
|
+
buffers
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {WebGLAttributeLimits}
|
|
17
|
+
*/
|
|
18
|
+
attributes
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @type {WebGLUniformLimits}
|
|
22
|
+
*/
|
|
23
|
+
uniforms
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type {WebGLFramebufferLimits}
|
|
27
|
+
*/
|
|
28
|
+
framebuffer
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @type {WebGLTransformFeedbackLimits}
|
|
32
|
+
*/
|
|
33
|
+
transformFeedback
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @type {WebGLShaderPrecisionLimits}
|
|
37
|
+
*/
|
|
38
|
+
precision
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @type {WebGLExtensionLimits}
|
|
42
|
+
*/
|
|
43
|
+
extensions
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @type {WebGLDeviceInfo}
|
|
47
|
+
*/
|
|
48
|
+
info
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {WebGL2RenderingContext} gl
|
|
52
|
+
*/
|
|
53
|
+
constructor(gl) {
|
|
54
|
+
// === Texture limits ===
|
|
55
|
+
this.textures = queryTextureLimits(gl)
|
|
56
|
+
|
|
57
|
+
// === Buffer and memory-related limits ===
|
|
58
|
+
this.buffers = {
|
|
59
|
+
maxRenderbufferSize: gl.getParameter(gl.MAX_RENDERBUFFER_SIZE),
|
|
60
|
+
maxUniformBufferBindings: gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS),
|
|
61
|
+
maxUniformBlockSize: gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// === Attribute / Vertex Shader limits ===
|
|
65
|
+
this.attributes = {
|
|
66
|
+
maxVertexAttribs: gl.getParameter(gl.MAX_VERTEX_ATTRIBS),
|
|
67
|
+
maxVertexOutputComponents: gl.getParameter(gl.MAX_VERTEX_OUTPUT_COMPONENTS),
|
|
68
|
+
aliasedPointSizeRange: gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE),
|
|
69
|
+
aliasedLineWidthRange: gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE),
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// === Uniform / Shader limits ===
|
|
73
|
+
this.uniforms = {
|
|
74
|
+
maxVertexUniformVectors: gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS),
|
|
75
|
+
maxVertexUniformBlocks: gl.getParameter(gl.MAX_VERTEX_UNIFORM_BLOCKS),
|
|
76
|
+
maxFragmentUniformVectors: gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS),
|
|
77
|
+
maxFragmentUniformBlocks: gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_BLOCKS),
|
|
78
|
+
maxVaryingVectors: gl.getParameter(gl.MAX_VARYING_VECTORS),
|
|
79
|
+
maxFragmentInputComponents: gl.getParameter(gl.MAX_FRAGMENT_INPUT_COMPONENTS),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// === Framebuffer / Render Target limits ===
|
|
83
|
+
this.framebuffer = {
|
|
84
|
+
maxViewportDims: gl.getParameter(gl.MAX_VIEWPORT_DIMS),
|
|
85
|
+
maxDrawBuffers: gl.getParameter(gl.MAX_DRAW_BUFFERS),
|
|
86
|
+
maxColorAttachments: gl.getParameter(gl.MAX_COLOR_ATTACHMENTS),
|
|
87
|
+
maxSamples: gl.getParameter(gl.MAX_SAMPLES),
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// === Transform Feedback limits ===
|
|
91
|
+
this.transformFeedback = {
|
|
92
|
+
maxInterleavedComponents: gl.getParameter(gl.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS),
|
|
93
|
+
maxSeparateAttribs: gl.getParameter(gl.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS),
|
|
94
|
+
maxSeparateComponents: gl.getParameter(gl.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS),
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// === Precision limits ===
|
|
98
|
+
this.precision = {
|
|
99
|
+
vertex: {
|
|
100
|
+
highFloat: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT),
|
|
101
|
+
mediumFloat: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT),
|
|
102
|
+
lowFloat: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT),
|
|
103
|
+
highInt: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_INT),
|
|
104
|
+
mediumInt: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_INT),
|
|
105
|
+
lowInt: gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_INT),
|
|
106
|
+
},
|
|
107
|
+
fragment: {
|
|
108
|
+
highFloat: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT),
|
|
109
|
+
mediumFloat: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT),
|
|
110
|
+
lowFloat: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_FLOAT),
|
|
111
|
+
highInt: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_INT),
|
|
112
|
+
mediumInt: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_INT),
|
|
113
|
+
lowInt: gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_INT),
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// === Extensions and optional limits ===
|
|
118
|
+
const extAniso =
|
|
119
|
+
gl.getExtension("EXT_texture_filter_anisotropic") ||
|
|
120
|
+
gl.getExtension("MOZ_EXT_texture_filter_anisotropic") ||
|
|
121
|
+
gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")
|
|
122
|
+
|
|
123
|
+
this.extensions = {
|
|
124
|
+
anisotropy: extAniso
|
|
125
|
+
? gl.getParameter(extAniso.MAX_TEXTURE_MAX_ANISOTROPY_EXT)
|
|
126
|
+
: 1,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// === Debug info (vendor/renderer) ===
|
|
130
|
+
const dbgInfo = gl.getExtension("WEBGL_debug_renderer_info")
|
|
131
|
+
this.info = {
|
|
132
|
+
vendor: dbgInfo
|
|
133
|
+
? gl.getParameter(dbgInfo.UNMASKED_VENDOR_WEBGL)
|
|
134
|
+
: gl.getParameter(gl.VENDOR),
|
|
135
|
+
renderer: dbgInfo
|
|
136
|
+
? gl.getParameter(dbgInfo.UNMASKED_RENDERER_WEBGL)
|
|
137
|
+
: gl.getParameter(gl.RENDERER),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @typedef WebGLTextureLimits
|
|
144
|
+
* @property {number} maxTextureSize
|
|
145
|
+
* @property {number} maxCubeMapTextureSize
|
|
146
|
+
* @property {number} max3DTextureSize
|
|
147
|
+
* @property {number} maxArrayTextureLayers
|
|
148
|
+
* @property {number} maxCombinedTextureImageUnits
|
|
149
|
+
* @property {number} maxVertexTextureImageUnits
|
|
150
|
+
* @property {number} maxFragmentTextureImageUnits
|
|
151
|
+
* @property {number} maxTextureAnisotropy
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @typedef WebGLAttributeLimits
|
|
156
|
+
* @property {number} maxVertexAttribs
|
|
157
|
+
* @property {number} maxVertexOutputComponents
|
|
158
|
+
* @property {Float32Array} aliasedPointSizeRange
|
|
159
|
+
* @property {Float32Array} aliasedLineWidthRange
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @typedef WebGLUniformLimits
|
|
164
|
+
* @property {number} maxVertexUniformVectors
|
|
165
|
+
* @property {number} maxVertexUniformBlocks
|
|
166
|
+
* @property {number} maxFragmentUniformVectors
|
|
167
|
+
* @property {number} maxFragmentUniformBlocks
|
|
168
|
+
* @property {number} maxVaryingVectors
|
|
169
|
+
* @property {number} maxFragmentInputComponents
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @typedef WebGLBufferLimits
|
|
174
|
+
* @property {number} maxRenderbufferSize
|
|
175
|
+
* @property {number} maxUniformBufferBindings
|
|
176
|
+
* @property {number} maxUniformBlockSize
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @typedef WebGLFramebufferLimits
|
|
181
|
+
* @property {Int32Array} maxViewportDims
|
|
182
|
+
* @property {number} maxDrawBuffers
|
|
183
|
+
* @property {number} maxColorAttachments
|
|
184
|
+
* @property {number} maxSamples
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @typedef WebGLTransformFeedbackLimits
|
|
189
|
+
* @property {number} maxInterleavedComponents
|
|
190
|
+
* @property {number} maxSeparateAttribs
|
|
191
|
+
* @property {number} maxSeparateComponents
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @typedef WebGLDeviceInfo
|
|
196
|
+
* @property {string} vendor
|
|
197
|
+
* @property {string} renderer
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @typedef WebGLShaderPrecisionLimits
|
|
202
|
+
* @property {WebGLShaderPrecisionInfo} vertex
|
|
203
|
+
* @property {WebGLShaderPrecisionInfo} fragment
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @typedef WebGLShaderPrecisionInfo
|
|
208
|
+
* @property {WebGLShaderPrecisionFormat | null} highFloat
|
|
209
|
+
* @property {WebGLShaderPrecisionFormat | null} mediumFloat
|
|
210
|
+
* @property {WebGLShaderPrecisionFormat | null} lowFloat
|
|
211
|
+
* @property {WebGLShaderPrecisionFormat | null} highInt
|
|
212
|
+
* @property {WebGLShaderPrecisionFormat | null} mediumInt
|
|
213
|
+
* @property {WebGLShaderPrecisionFormat | null} lowInt
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @typedef WebGLExtensionLimits
|
|
218
|
+
* @property {number} anisotropy
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Query all texture-related limits and supported features.
|
|
223
|
+
* @param {WebGL2RenderingContext} gl
|
|
224
|
+
* @returns {WebGLTextureLimits}
|
|
225
|
+
*/
|
|
226
|
+
function queryTextureLimits(gl) {
|
|
227
|
+
const extAniso =
|
|
228
|
+
gl.getExtension("EXT_texture_filter_anisotropic") ||
|
|
229
|
+
gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic") ||
|
|
230
|
+
gl.getExtension("MOZ_EXT_texture_filter_anisotropic")
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
// === Core WebGL2 texture limits ===
|
|
234
|
+
maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
|
|
235
|
+
maxCubeMapTextureSize: gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE),
|
|
236
|
+
max3DTextureSize: gl.getParameter(gl.MAX_3D_TEXTURE_SIZE),
|
|
237
|
+
maxArrayTextureLayers: gl.getParameter(gl.MAX_ARRAY_TEXTURE_LAYERS),
|
|
238
|
+
maxCombinedTextureImageUnits: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
|
|
239
|
+
maxVertexTextureImageUnits: gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
|
|
240
|
+
maxFragmentTextureImageUnits: gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS),
|
|
241
|
+
|
|
242
|
+
// === Extension-based limits ===
|
|
243
|
+
maxTextureAnisotropy: extAniso
|
|
244
|
+
? gl.getParameter(extAniso.MAX_TEXTURE_MAX_ANISOTROPY_EXT)
|
|
245
|
+
: 1
|
|
246
|
+
}
|
|
247
|
+
}
|