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.
Files changed (256) hide show
  1. package/.configs/tsconfig.lib.json +43 -0
  2. package/.configs/tsconfig.website.json +34 -0
  3. package/.github/workflows/static.yml +88 -0
  4. package/.vscode/launch.json +29 -0
  5. package/.vscode/tasks.json +19 -0
  6. package/README.md +127 -0
  7. package/assets/images/disappointed.jpg +0 -0
  8. package/assets/images/skybox/grimmnight_back.png +0 -0
  9. package/assets/images/skybox/grimmnight_bottom.png +0 -0
  10. package/assets/images/skybox/grimmnight_front.png +0 -0
  11. package/assets/images/skybox/grimmnight_left.png +0 -0
  12. package/assets/images/skybox/grimmnight_right.png +0 -0
  13. package/assets/images/skybox/grimmnight_top.png +0 -0
  14. package/assets/images/skybox/miramar_back.png +0 -0
  15. package/assets/images/skybox/miramar_bottom.png +0 -0
  16. package/assets/images/skybox/miramar_front.png +0 -0
  17. package/assets/images/skybox/miramar_left.png +0 -0
  18. package/assets/images/skybox/miramar_right.png +0 -0
  19. package/assets/images/skybox/miramar_top.png +0 -0
  20. package/assets/images/uv.jpg +0 -0
  21. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
  22. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
  23. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
  24. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
  25. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
  26. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
  27. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
  28. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
  29. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
  30. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
  31. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
  32. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
  33. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
  34. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
  35. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
  36. package/assets/models/gltf/flight_helmet/index.bin +0 -0
  37. package/assets/models/gltf/flight_helmet/index.gltf +705 -0
  38. package/assets/models/gltf/object.gltf +23 -0
  39. package/assets/models/gltf/pirate_girl/index.bin +0 -0
  40. package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
  41. package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
  42. package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
  43. package/astro.config.mjs +45 -0
  44. package/content/guide/api-map.md +89 -0
  45. package/content/guide/camera-and-controls.md +98 -0
  46. package/content/guide/first-scene.md +176 -0
  47. package/content/guide/index.md +72 -0
  48. package/content/guide/installation.md +179 -0
  49. package/content/guide/materials-and-lighting.md +138 -0
  50. package/content/guide/plugins-and-render-pipeline.md +124 -0
  51. package/content/guide/render-targets-and-views.md +147 -0
  52. package/content/guide/scene-graph-and-transforms.md +113 -0
  53. package/content/guide/textures-and-assets.md +120 -0
  54. package/content/guide/troubleshooting.md +49 -0
  55. package/env.d.ts +19 -0
  56. package/examples/addons/rendergraph_gui.js +580 -0
  57. package/examples/camera/orthographic.js +120 -0
  58. package/examples/camera/perspective.js +138 -0
  59. package/examples/lights/directional.js +397 -0
  60. package/examples/lights/multiple_spot_lights.js +304 -0
  61. package/examples/lights/point.js +337 -0
  62. package/examples/lights/spot.js +366 -0
  63. package/examples/loader/gltf_material.js +111 -0
  64. package/examples/loader/gltfloader.js +78 -0
  65. package/examples/loader/objloader.js +95 -0
  66. package/examples/material/cullface.js +111 -0
  67. package/examples/material/materials.js +126 -0
  68. package/examples/material/standard/basic.js +164 -0
  69. package/examples/mesh/circle.js +117 -0
  70. package/examples/mesh/cuboid.js +151 -0
  71. package/examples/mesh/cylinder.js +139 -0
  72. package/examples/mesh/geometries.js +108 -0
  73. package/examples/mesh/meshTopology.js +103 -0
  74. package/examples/mesh/plane.js +117 -0
  75. package/examples/mesh/skinning.js +136 -0
  76. package/examples/mesh/uvsphere.js +113 -0
  77. package/examples/other/rotatingCube.js +93 -0
  78. package/examples/other/rotatingSphere.js +96 -0
  79. package/examples/rendertarget/basic_canvas.js +130 -0
  80. package/examples/rendertarget/depth_texture.js +130 -0
  81. package/examples/rendertarget/image_target.js +140 -0
  82. package/examples/rendertarget/multiple_views.js +158 -0
  83. package/examples/rendertarget/render_masks.js +173 -0
  84. package/examples/rendertarget/split_screen.js +123 -0
  85. package/examples/rendertarget/split_view.js +137 -0
  86. package/examples/skybox/skybox.js +111 -0
  87. package/examples/texture/arrays.js +156 -0
  88. package/examples/texture/textureWrap.js +118 -0
  89. package/examples/transform/propagation.js +92 -0
  90. package/package.json +55 -0
  91. package/rollup.config.js +66 -0
  92. package/scripts/stage-chorama.mjs +29 -0
  93. package/src/caches/cache.js +420 -0
  94. package/src/caches/index.js +2 -0
  95. package/src/caches/uniformbuffers.js +104 -0
  96. package/src/cameracontrols/index.js +258 -0
  97. package/src/constants/index.js +3 -0
  98. package/src/constants/mesh.js +197 -0
  99. package/src/constants/others.js +218 -0
  100. package/src/constants/texture.js +183 -0
  101. package/src/core/constants.js +14 -0
  102. package/src/core/extensions.js +42 -0
  103. package/src/core/index.js +7 -0
  104. package/src/core/layouts/index.js +4 -0
  105. package/src/core/layouts/meshvertex.js +60 -0
  106. package/src/core/layouts/uniform.js +21 -0
  107. package/src/core/layouts/uniformbuffer.js +15 -0
  108. package/src/core/layouts/vertexbuffer.js +43 -0
  109. package/src/core/limits.js +247 -0
  110. package/src/core/resources/blendparams.js +89 -0
  111. package/src/core/resources/framebuffer.js +127 -0
  112. package/src/core/resources/gpubuffer.js +32 -0
  113. package/src/core/resources/gpumesh.js +43 -0
  114. package/src/core/resources/gputexture.js +73 -0
  115. package/src/core/resources/index.js +5 -0
  116. package/src/core/shader.js +62 -0
  117. package/src/core/webgl/bindgroup.js +89 -0
  118. package/src/core/webgl/descriptors.js +104 -0
  119. package/src/core/webgl/index.js +5 -0
  120. package/src/core/webgl/renderpassencoder.js +96 -0
  121. package/src/core/webgl/renderpipeline.js +54 -0
  122. package/src/core/webgl/utils.js +371 -0
  123. package/src/core/webgl/webglrenderdevice.js +235 -0
  124. package/src/function.js +358 -0
  125. package/src/index.js +15 -0
  126. package/src/loader/gltf.js +2172 -0
  127. package/src/loader/index.js +3 -0
  128. package/src/loader/loader.js +174 -0
  129. package/src/loader/obj.js +188 -0
  130. package/src/loader/texture.js +85 -0
  131. package/src/loader/utils.js +16 -0
  132. package/src/material/basic.js +75 -0
  133. package/src/material/depth.js +73 -0
  134. package/src/material/index.js +8 -0
  135. package/src/material/lambert.js +73 -0
  136. package/src/material/material.js +106 -0
  137. package/src/material/normal.js +30 -0
  138. package/src/material/phong.js +86 -0
  139. package/src/material/raw.js +52 -0
  140. package/src/material/standard.js +221 -0
  141. package/src/math/index.js +3 -0
  142. package/src/math/transform.js +38 -0
  143. package/src/mesh/attribute/attribute.js +79 -0
  144. package/src/mesh/attribute/index.js +1 -0
  145. package/src/mesh/attributedata/index.js +1 -0
  146. package/src/mesh/attributedata/separate.js +180 -0
  147. package/src/mesh/builders/base.js +41 -0
  148. package/src/mesh/builders/circle.js +63 -0
  149. package/src/mesh/builders/cuboid.js +135 -0
  150. package/src/mesh/builders/cylinder.js +131 -0
  151. package/src/mesh/builders/index.js +7 -0
  152. package/src/mesh/builders/plane.js +73 -0
  153. package/src/mesh/builders/utils.js +20 -0
  154. package/src/mesh/builders/uvsphere.js +80 -0
  155. package/src/mesh/builders/wireframe.js +62 -0
  156. package/src/mesh/index.js +4 -0
  157. package/src/mesh/mesh.js +149 -0
  158. package/src/objects/bone.js +17 -0
  159. package/src/objects/camera/camera.js +56 -0
  160. package/src/objects/camera/index.js +2 -0
  161. package/src/objects/camera/projection.js +203 -0
  162. package/src/objects/debug/index.js +1 -0
  163. package/src/objects/debug/skeleton.js +28 -0
  164. package/src/objects/index.js +7 -0
  165. package/src/objects/light/ambient.js +20 -0
  166. package/src/objects/light/directional.js +29 -0
  167. package/src/objects/light/index.js +5 -0
  168. package/src/objects/light/point.js +32 -0
  169. package/src/objects/light/shadow/index.js +1 -0
  170. package/src/objects/light/shadow/shadow.js +67 -0
  171. package/src/objects/light/spot.js +56 -0
  172. package/src/objects/mesh.js +141 -0
  173. package/src/objects/object3d.js +167 -0
  174. package/src/objects/skybox.js +38 -0
  175. package/src/plugins/camera/camera.js +19 -0
  176. package/src/plugins/camera/index.js +2 -0
  177. package/src/plugins/camera/nodes/cameraview.js +46 -0
  178. package/src/plugins/camera/nodes/index.js +2 -0
  179. package/src/plugins/camera/nodes/opaquepass.js +79 -0
  180. package/src/plugins/index.js +6 -0
  181. package/src/plugins/light/index.js +2 -0
  182. package/src/plugins/light/light.js +23 -0
  183. package/src/plugins/light/nodes/index.js +1 -0
  184. package/src/plugins/light/nodes/light.js +127 -0
  185. package/src/plugins/meshmaterial/index.js +3 -0
  186. package/src/plugins/meshmaterial/meshmaterial.js +381 -0
  187. package/src/plugins/meshmaterial/nodes/index.js +1 -0
  188. package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
  189. package/src/plugins/meshmaterial/resources/index.js +1 -0
  190. package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
  191. package/src/plugins/shadow/index.js +3 -0
  192. package/src/plugins/shadow/nodes/index.js +3 -0
  193. package/src/plugins/shadow/nodes/shadow.js +272 -0
  194. package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
  195. package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
  196. package/src/plugins/shadow/resources/ShadowMap.js +99 -0
  197. package/src/plugins/shadow/resources/index.js +2 -0
  198. package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
  199. package/src/plugins/shadow/shadow.js +31 -0
  200. package/src/plugins/skeletonhelper/index.js +1 -0
  201. package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
  202. package/src/plugins/skybox/index.js +3 -0
  203. package/src/plugins/skybox/nodes/index.js +1 -0
  204. package/src/plugins/skybox/nodes/skybox.js +143 -0
  205. package/src/plugins/skybox/resources/index.js +2 -0
  206. package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
  207. package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
  208. package/src/plugins/skybox/skybox.js +137 -0
  209. package/src/renderer/core/index.js +179 -0
  210. package/src/renderer/graph/index.js +3 -0
  211. package/src/renderer/graph/nodes.js +34 -0
  212. package/src/renderer/graph/rendergraph.js +182 -0
  213. package/src/renderer/index.js +5 -0
  214. package/src/renderer/plugin.js +36 -0
  215. package/src/renderer/renderer.js +179 -0
  216. package/src/renderer/views.js +28 -0
  217. package/src/rendertarget/canvastarget.js +30 -0
  218. package/src/rendertarget/image.js +132 -0
  219. package/src/rendertarget/index.js +3 -0
  220. package/src/rendertarget/rendertarget.js +89 -0
  221. package/src/shader/basicFragment.glsl +30 -0
  222. package/src/shader/basicVertex.glsl +87 -0
  223. package/src/shader/common/color.glsl +7 -0
  224. package/src/shader/common/common.glsl +25 -0
  225. package/src/shader/common/index.js +4 -0
  226. package/src/shader/common/light.glsl +437 -0
  227. package/src/shader/common/math.glsl +12 -0
  228. package/src/shader/debug/index.js +2 -0
  229. package/src/shader/debug/skeletonFragment.glsl +8 -0
  230. package/src/shader/debug/skeletonVertex.glsl +27 -0
  231. package/src/shader/depthFragment.glsl +37 -0
  232. package/src/shader/index.js +11 -0
  233. package/src/shader/lambertFragment.glsl +126 -0
  234. package/src/shader/normalFragment.glsl +25 -0
  235. package/src/shader/phongFragment.glsl +140 -0
  236. package/src/shader/skyboxFragment.glsl +16 -0
  237. package/src/shader/skyboxVertex.glsl +20 -0
  238. package/src/shader/standardFragment.glsl +274 -0
  239. package/src/texture/index.js +2 -0
  240. package/src/texture/sampler.js +111 -0
  241. package/src/texture/texture.js +234 -0
  242. package/src/utils/index.js +115 -0
  243. package/tsconfig.json +11 -0
  244. package/website/config/index.ts +1 -0
  245. package/website/config/navigation.ts +53 -0
  246. package/website/content.config.ts +92 -0
  247. package/website/layouts/DocLayout.astro +501 -0
  248. package/website/layouts/Example.astro +91 -0
  249. package/website/pages/examples/[...slug].astro +77 -0
  250. package/website/pages/examples/index.astro +98 -0
  251. package/website/pages/examples/samples/[...slug].astro +17 -0
  252. package/website/pages/guide/[slug].astro +30 -0
  253. package/website/pages/guide/index.astro +21 -0
  254. package/website/pages/index.astro +9 -0
  255. package/website/plugins/remark-link-base.js +23 -0
  256. 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,7 @@
1
+ export * from "./layouts/index.js"
2
+ export * from "./shader.js"
3
+ export * from "./limits.js"
4
+ export * from "./extensions.js"
5
+ export * from "./resources/index.js"
6
+ export * from "./webgl/index.js"
7
+ export * from "./constants.js"
@@ -0,0 +1,4 @@
1
+ export * from './uniformbuffer.js'
2
+ export * from './uniform.js'
3
+ export * from './vertexbuffer.js'
4
+ export * from './meshvertex.js'
@@ -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
+ }