ris-framework 0.2.0-dev.11 → 0.2.0-dev.12

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 (257) hide show
  1. package/CHANGELOG.md +22 -29
  2. package/README.md +13 -1
  3. package/dist/Framework.d.ts +26 -8
  4. package/dist/Framework.d.ts.map +1 -1
  5. package/dist/api/IFramework.d.ts +43 -0
  6. package/dist/api/IFramework.d.ts.map +1 -1
  7. package/dist/api/_export.d.ts +1 -1
  8. package/dist/api/_export.d.ts.map +1 -1
  9. package/dist/api/content/ContentManager.d.ts +5 -57
  10. package/dist/api/content/ContentManager.d.ts.map +1 -1
  11. package/dist/api/content/IContentManager.d.ts +24 -21
  12. package/dist/api/content/IContentManager.d.ts.map +1 -1
  13. package/dist/api/lights/LightsBuffer.d.ts +13 -6
  14. package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
  15. package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
  16. package/dist/api/loaders/ObjLoader.d.ts +61 -0
  17. package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
  18. package/dist/api/loaders/_export.d.ts +1 -0
  19. package/dist/api/loaders/_export.d.ts.map +1 -1
  20. package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
  21. package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
  22. package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
  23. package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
  24. package/dist/api/loaders/obj/index.d.ts +1 -1
  25. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
  26. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
  27. package/dist/api/material/ICameraMaterial.d.ts +18 -0
  28. package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
  29. package/dist/api/material/ILightsMaterial.d.ts +26 -0
  30. package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
  31. package/dist/api/material/IMaterial.d.ts +2 -8
  32. package/dist/api/material/IMaterial.d.ts.map +1 -1
  33. package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
  34. package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
  35. package/dist/api/material/SpriteMaterial.d.ts +2 -2
  36. package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
  37. package/dist/api/material/UnlitMaterial.d.ts +4 -3
  38. package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
  39. package/dist/api/material/_export.d.ts +2 -0
  40. package/dist/api/material/_export.d.ts.map +1 -1
  41. package/dist/api/meshes/IMesh.d.ts +29 -34
  42. package/dist/api/meshes/IMesh.d.ts.map +1 -1
  43. package/dist/api/meshes/IMeshFactory.d.ts +13 -8
  44. package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
  45. package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
  46. package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
  47. package/dist/api/meshes/Mesh.d.ts +11 -57
  48. package/dist/api/meshes/Mesh.d.ts.map +1 -1
  49. package/dist/api/meshes/MeshFactory.d.ts +6 -3
  50. package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
  51. package/dist/api/meshes/QuadMesh.d.ts +3 -5
  52. package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
  53. package/dist/api/meshes/RenderableMesh.d.ts +95 -0
  54. package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
  55. package/dist/api/meshes/_export.d.ts +2 -1
  56. package/dist/api/meshes/_export.d.ts.map +1 -1
  57. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
  58. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
  59. package/dist/api/rendering/IRenderer.d.ts +28 -1
  60. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  61. package/dist/api/rendering/enums.d.ts +7 -0
  62. package/dist/api/rendering/enums.d.ts.map +1 -1
  63. package/dist/api/rendering/renderer-interface.d.ts +1 -31
  64. package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
  65. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
  66. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
  67. package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
  68. package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
  69. package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
  70. package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
  71. package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
  72. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  73. package/dist/api/scene/Scene.d.ts +30 -21
  74. package/dist/api/scene/Scene.d.ts.map +1 -1
  75. package/dist/api/scene/SceneMesh.d.ts +27 -0
  76. package/dist/api/scene/SceneMesh.d.ts.map +1 -0
  77. package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
  78. package/dist/api/window/WindowManager.d.ts.map +1 -1
  79. package/dist/core/rendering/ARenderer.d.ts +5 -5
  80. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  81. package/dist/index.d.ts +0 -1
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +4006 -1355
  84. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
  85. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
  86. package/dist/webgl/WebGlRenderer.d.ts +1 -3
  87. package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
  88. package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
  89. package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
  90. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
  91. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
  92. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
  93. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
  94. package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
  95. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  96. package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
  97. package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
  98. package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
  99. package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
  100. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
  101. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
  102. package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
  103. package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
  104. package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
  105. package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
  106. package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
  107. package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
  108. package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
  109. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
  110. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
  111. package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
  112. package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
  113. package/dist/webgpu/WebGpuTypes.d.ts +355 -0
  114. package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
  115. package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
  116. package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
  117. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
  118. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
  119. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
  120. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
  121. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
  122. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
  123. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
  124. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
  125. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
  126. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
  127. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
  128. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
  129. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
  130. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
  131. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
  132. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
  133. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
  134. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
  135. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
  136. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
  137. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
  138. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
  139. package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
  140. package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
  141. package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
  142. package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
  143. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
  144. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
  145. package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
  146. package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
  147. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
  148. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
  149. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
  150. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
  151. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
  152. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
  153. package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
  154. package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
  155. package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
  156. package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
  157. package/package.json +2 -2
  158. package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
  159. package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
  160. package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
  161. package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
  162. package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
  163. package/shaders/wgsl/sprite.wgsl +40 -0
  164. package/shaders/wgsl/unlit_material.wgsl +49 -0
  165. package/src/Framework.ts +121 -37
  166. package/src/api/IFramework.ts +55 -0
  167. package/src/api/_export.ts +1 -1
  168. package/src/api/content/ContentManager.ts +46 -180
  169. package/src/api/content/IContentManager.ts +25 -21
  170. package/src/api/lights/LightsBuffer.ts +13 -6
  171. package/src/api/loaders/ObjGeometryMapper.ts +2 -2
  172. package/src/api/loaders/ObjLoader.ts +126 -0
  173. package/src/api/loaders/_export.ts +1 -0
  174. package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
  175. package/src/api/loaders/obj/ObjTypes.ts +19 -1
  176. package/src/api/loaders/obj/index.ts +1 -1
  177. package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
  178. package/src/api/material/ICameraMaterial.ts +22 -0
  179. package/src/api/material/ILightsMaterial.ts +32 -0
  180. package/src/api/material/IMaterial.ts +2 -9
  181. package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
  182. package/src/api/material/SpriteMaterial.ts +2 -2
  183. package/src/api/material/UnlitMaterial.ts +4 -3
  184. package/src/api/material/_export.ts +2 -0
  185. package/src/api/meshes/IMesh.ts +32 -37
  186. package/src/api/meshes/IMeshFactory.ts +14 -8
  187. package/src/api/meshes/IRenderableMesh.ts +58 -0
  188. package/src/api/meshes/Mesh.ts +17 -132
  189. package/src/api/meshes/MeshFactory.ts +14 -5
  190. package/src/api/meshes/QuadMesh.ts +4 -6
  191. package/src/api/meshes/RenderableMesh.ts +207 -0
  192. package/src/api/meshes/_export.ts +6 -5
  193. package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
  194. package/src/api/rendering/IRenderer.ts +34 -1
  195. package/src/api/rendering/enums.ts +10 -0
  196. package/src/api/rendering/renderer-interface.ts +1 -36
  197. package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
  198. package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
  199. package/src/api/rendering/texture/TextureFormat.ts +128 -14
  200. package/src/api/rendering/texture/TextureUtilities.ts +225 -10
  201. package/src/api/scene/Scene.ts +102 -69
  202. package/src/api/scene/SceneMesh.ts +61 -0
  203. package/src/api/sprites/SpriteBatchMesh.ts +1 -1
  204. package/src/api/utilities/AlignUtilities.ts +2 -1
  205. package/src/api/window/WindowManager.ts +1 -1
  206. package/src/core/rendering/ARenderer.ts +24 -15
  207. package/src/index.ts +0 -1
  208. package/src/main.ts +2 -3
  209. package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
  210. package/src/webgl/WebGlGpuInfo.ts +1 -1
  211. package/src/webgl/WebGlRenderer.ts +2 -5
  212. package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
  213. package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
  214. package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
  215. package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
  216. package/src/webgl/utilities/WebGlConstants.ts +136 -0
  217. package/src/webgl/utilities/WebGlConverter.ts +91 -22
  218. package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
  219. package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
  220. package/src/webgl/utilities/WebGlUtilities.ts +4 -0
  221. package/src/webgpu/WebGpuGpuInfo.ts +61 -0
  222. package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
  223. package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
  224. package/src/webgpu/WebGpuRenderer.ts +49 -0
  225. package/src/webgpu/WebGpuTypes.ts +288 -0
  226. package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
  227. package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
  228. package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
  229. package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
  230. package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
  231. package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
  232. package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
  233. package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
  234. package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
  235. package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
  236. package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
  237. package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
  238. package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
  239. package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
  240. package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
  241. package/src/webgpu/shader/WgslShaderContent.ts +20 -0
  242. package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
  243. package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
  244. package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
  245. package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
  246. package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
  247. package/src/wgsl-raw.d.ts +4 -0
  248. package/dist/api/FrameworkConfiguration.d.ts +0 -23
  249. package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
  250. package/dist/api/IFrameworkConfiguration.d.ts +0 -25
  251. package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
  252. package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
  253. package/dist/api/meshes/SubMesh.d.ts +0 -47
  254. package/dist/api/meshes/SubMesh.d.ts.map +0 -1
  255. package/src/api/FrameworkConfiguration.ts +0 -29
  256. package/src/api/IFrameworkConfiguration.ts +0 -30
  257. package/src/api/meshes/SubMesh.ts +0 -71
@@ -2,8 +2,42 @@
2
2
  precision highp float;
3
3
  in vec2 v_texCoord;
4
4
  out vec4 outColor;
5
+
5
6
  uniform sampler2D u_texture;
7
+ uniform int u_colorConversion;
8
+
9
+ float linearToSrgb(float c)
10
+ {
11
+ if (c <= 0.0)
12
+ return 0.0;
13
+
14
+ if (c < 0.0031308)
15
+ return 12.92 * c;
16
+
17
+ if (c < 1.0)
18
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
19
+
20
+ return 1.0;
21
+ }
22
+
23
+ // https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf
24
+ // Chapter 17.3.7
25
+ // Page 513
26
+ vec3 linearToSrgb(vec3 c)
27
+ {
28
+ return vec3(
29
+ linearToSrgb(c.r),
30
+ linearToSrgb(c.g),
31
+ linearToSrgb(c.b)
32
+ );
33
+ }
34
+
6
35
  void main()
7
36
  {
8
- outColor = texture(u_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y));
37
+ vec4 color = texture(u_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y));
38
+ outColor.rgb = color.rgb;
39
+ if(u_colorConversion == 1) {
40
+ outColor.rgb = linearToSrgb(color.rgb);
41
+ }
42
+ outColor.a = color.a;
9
43
  }
@@ -0,0 +1,150 @@
1
+ // Forward Blinn-Phong material shader (WebGPU): ambient + directional + point lights, per fragment in world space.
2
+ // Hand-maintained, mirrors slang/forward_blinn_phong_material.slang and glsl_300_es/forward_blinn_phong_material_*.glsl.
3
+ //
4
+ // The light counts must match LightsBuffer.DEFAULT_*_LIGHTS_COUNT (3 directional, 5 point lights;
5
+ // Lights = 4 + 3 * 8 + 5 * 12 = 88 floats = 352 bytes). Every member is a 16 byte aligned vec4.
6
+ // The counts are fixed here because the WebGPU pipeline does not pass a shader config.
7
+ //
8
+ // Bind groups (WebGPUForwardBlinnPhongRenderPipeline), WebGPU guarantees only 4 groups:
9
+ // group 0: binding 0 = projection view matrix, binding 1 = model matrix (vertex)
10
+ // group 1: binding 0 = diffuse texture, binding 1 = sampler (fragment)
11
+ // group 2: binding 2 = material (fragment)
12
+ // group 3: binding 3 = lights, binding 4 = camera position (fragment)
13
+
14
+ const DIRECTIONAL_LIGHTS_COUNT : u32 = 3u;
15
+ const POINT_LIGHTS_COUNT : u32 = 5u;
16
+
17
+ // Material colors (MTL Ka, Kd, Ks) and the specular exponent (MTL Ns).
18
+ struct BlinnPhongMaterial
19
+ {
20
+ ambientColor : vec4<f32>,
21
+ diffuseColor : vec4<f32>,
22
+ specularColorShininess : vec4<f32>, // xyz specular color, w shininess
23
+ };
24
+
25
+ struct DirectionalLight
26
+ {
27
+ light : vec4<f32>, // xyz color * intensity
28
+ direction : vec4<f32>, // xyz direction in which the light travels
29
+ };
30
+
31
+ struct PointLight
32
+ {
33
+ lightConstant : vec4<f32>, // xyz color * intensity, w constant attenuation
34
+ positionLinear : vec4<f32>, // xyz world position, w linear attenuation
35
+ quadratic : vec4<f32>, // x quadratic attenuation
36
+ };
37
+
38
+ struct Lights
39
+ {
40
+ ambientLight : vec4<f32>, // xyz color * intensity
41
+ directionalLights : array<DirectionalLight, DIRECTIONAL_LIGHTS_COUNT>,
42
+ pointLights : array<PointLight, POINT_LIGHTS_COUNT>,
43
+ };
44
+
45
+ struct CameraPosition
46
+ {
47
+ position : vec4<f32>, // xyz world-space eye
48
+ };
49
+
50
+ @group(0) @binding(0) var<uniform> projectionView : mat4x4<f32>;
51
+ @group(0) @binding(1) var<uniform> model : mat4x4<f32>;
52
+
53
+ @group(1) @binding(0) var diffuseTexture : texture_2d<f32>;
54
+ @group(1) @binding(1) var diffuseSampler : sampler;
55
+
56
+ @group(2) @binding(2) var<uniform> material : BlinnPhongMaterial;
57
+
58
+ @group(3) @binding(3) var<uniform> lights : Lights;
59
+ @group(3) @binding(4) var<uniform> cameraPosition : CameraPosition;
60
+
61
+ struct VertexInput
62
+ {
63
+ @location(0) position : vec3<f32>,
64
+ @location(1) color : vec4<f32>,
65
+ @location(2) texCoord : vec2<f32>,
66
+ @location(3) normal : vec3<f32>,
67
+ };
68
+
69
+ struct VertexOutput
70
+ {
71
+ @builtin(position) position : vec4<f32>,
72
+ @location(0) color : vec4<f32>,
73
+ @location(1) texCoord : vec2<f32>,
74
+ @location(2) normal : vec3<f32>,
75
+ @location(3) worldPosition : vec3<f32>,
76
+ };
77
+
78
+ @vertex
79
+ fn main_vs(input : VertexInput) -> VertexOutput
80
+ {
81
+ var output : VertexOutput;
82
+ let worldPosition = model * vec4<f32>(input.position, 1.0);
83
+ output.position = projectionView * worldPosition;
84
+ output.color = input.color;
85
+ output.texCoord = input.texCoord;
86
+ output.worldPosition = worldPosition.xyz;
87
+
88
+ // World-space normal through the normal matrix (inverse transpose of the upper 3x3 of the model matrix),
89
+ // correct for non-uniform scale. For M = [a b c] (columns) the cofactor matrix is [b x c, c x a, a x b];
90
+ // it equals the inverse transpose times det(M). The length is removed in the fragment shader, only the sign matters.
91
+ let a = model[0].xyz;
92
+ let b = model[1].xyz;
93
+ let c = model[2].xyz;
94
+ let cofactor = mat3x3<f32>(cross(b, c), cross(c, a), cross(a, b));
95
+ let determinantSign = select(1.0, -1.0, dot(a, cross(b, c)) < 0.0);
96
+ output.normal = determinantSign * (cofactor * input.normal);
97
+ return output;
98
+ }
99
+
100
+ fn blinnPhong(normal : vec3<f32>, lightDirection : vec3<f32>, viewDirection : vec3<f32>, lightColor : vec3<f32>,
101
+ diffuse : ptr<function, vec3<f32>>, specular : ptr<function, vec3<f32>>)
102
+ {
103
+ let NdotL = max(dot(normal, lightDirection), 0.0);
104
+ *diffuse += material.diffuseColor.xyz * lightColor * NdotL;
105
+
106
+ if (NdotL > 0.0)
107
+ {
108
+ let halfway = normalize(lightDirection + viewDirection);
109
+ let NdotH = max(dot(normal, halfway), 0.0);
110
+ *specular += material.specularColorShininess.xyz * lightColor * pow(NdotH, material.specularColorShininess.w);
111
+ }
112
+ }
113
+
114
+ @fragment
115
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
116
+ {
117
+ let normal = normalize(input.normal);
118
+
119
+ // Ambient lighting.
120
+ let ambient = material.ambientColor.xyz * lights.ambientLight.xyz;
121
+
122
+ let viewDirection = normalize(cameraPosition.position.xyz - input.worldPosition);
123
+
124
+ // Diffuse and Blinn-Phong specular lighting.
125
+ var diffuse = vec3<f32>(0.0);
126
+ var specular = vec3<f32>(0.0);
127
+
128
+ for (var i = 0u; i < DIRECTIONAL_LIGHTS_COUNT; i++)
129
+ {
130
+ let light = lights.directionalLights[i];
131
+ blinnPhong(normal, normalize(-light.direction.xyz), viewDirection, light.light.xyz, &diffuse, &specular);
132
+ }
133
+
134
+ // Point lights: same diffuse and specular, scaled by distance attenuation.
135
+ for (var i = 0u; i < POINT_LIGHTS_COUNT; i++)
136
+ {
137
+ let light = lights.pointLights[i];
138
+ let toLight = light.positionLinear.xyz - input.worldPosition;
139
+ let lightDistance = length(toLight);
140
+ let lightDirection = toLight / max(lightDistance, 0.0001);
141
+ let attenuation = 1.0 / (light.lightConstant.w
142
+ + light.positionLinear.w * lightDistance
143
+ + light.quadratic.x * lightDistance * lightDistance);
144
+ blinnPhong(normal, lightDirection, viewDirection, light.lightConstant.xyz * attenuation, &diffuse, &specular);
145
+ }
146
+
147
+ // Apply material lighting, texture and vertex color. Specular highlights are not tinted by the texture.
148
+ let texel = textureSample(diffuseTexture, diffuseSampler, input.texCoord) * input.color;
149
+ return vec4<f32>(texel.rgb * (ambient + diffuse) + specular, texel.a);
150
+ }
@@ -0,0 +1,51 @@
1
+ // Inspect texture mips shader (WebGPU): draws a texture at an explicit mip level.
2
+ // Hand-maintained, mirrors slang/inspect_texture_mips.slang and glsl_300_es/inspect_texture_mips_*.glsl.
3
+ // Note: there is no WebGPU inspect pipeline yet; the layout follows the mesh pipelines.
4
+ //
5
+ // Bind groups:
6
+ // group 0: binding 0 = projection view matrix, binding 1 = model matrix (vertex)
7
+ // group 1: binding 0 = texture, binding 1 = sampler (fragment)
8
+ // group 2: binding 2 = texture constants (fragment)
9
+
10
+ struct TextureConstants
11
+ {
12
+ mipLevel : f32,
13
+ };
14
+
15
+ @group(0) @binding(0) var<uniform> projectionView : mat4x4<f32>;
16
+ @group(0) @binding(1) var<uniform> model : mat4x4<f32>;
17
+
18
+ @group(1) @binding(0) var diffuseTexture : texture_2d<f32>;
19
+ @group(1) @binding(1) var diffuseSampler : sampler;
20
+
21
+ @group(2) @binding(2) var<uniform> textureConstants : TextureConstants;
22
+
23
+ struct VertexInput
24
+ {
25
+ @location(0) position : vec3<f32>,
26
+ @location(1) color : vec4<f32>,
27
+ @location(2) texCoord : vec2<f32>,
28
+ };
29
+
30
+ struct VertexOutput
31
+ {
32
+ @builtin(position) position : vec4<f32>,
33
+ @location(0) color : vec4<f32>,
34
+ @location(1) texCoord : vec2<f32>,
35
+ };
36
+
37
+ @vertex
38
+ fn main_vs(input : VertexInput) -> VertexOutput
39
+ {
40
+ var output : VertexOutput;
41
+ output.position = projectionView * model * vec4<f32>(input.position, 1.0);
42
+ output.color = input.color;
43
+ output.texCoord = input.texCoord;
44
+ return output;
45
+ }
46
+
47
+ @fragment
48
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
49
+ {
50
+ return textureSampleLevel(diffuseTexture, diffuseSampler, input.texCoord, textureConstants.mipLevel) * input.color;
51
+ }
@@ -0,0 +1,35 @@
1
+ // Draws the main render target texture to the screen. (WebGPU)
2
+ // Hand-maintained, mirrors slang/main_frame_buffer.slang.
3
+ //
4
+ // Bind groups (WebGPUMainFrameBufferRenderPipeline):
5
+ // group 0: binding 0 = texture, binding 1 = sampler (fragment)
6
+
7
+ @group(0) @binding(0) var diffuseTexture : texture_2d<f32>;
8
+ @group(0) @binding(1) var diffuseSampler : sampler;
9
+
10
+ struct VertexInput
11
+ {
12
+ @location(0) position : vec3<f32>,
13
+ @location(1) texCoord : vec2<f32>,
14
+ };
15
+
16
+ struct VertexOutput
17
+ {
18
+ @builtin(position) position : vec4<f32>,
19
+ @location(0) texCoord : vec2<f32>,
20
+ };
21
+
22
+ @vertex
23
+ fn main_vs(input : VertexInput) -> VertexOutput
24
+ {
25
+ var output : VertexOutput;
26
+ output.position = vec4<f32>(input.position, 1.0);
27
+ output.texCoord = input.texCoord;
28
+ return output;
29
+ }
30
+
31
+ @fragment
32
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
33
+ {
34
+ return textureSample(diffuseTexture, diffuseSampler, input.texCoord);
35
+ }
@@ -0,0 +1,35 @@
1
+ // Draws the main render target texture to the screen, flipped on Y. (WebGPU)
2
+ // Hand-maintained, mirrors slang/main_render_target_flip_y.slang.
3
+ //
4
+ // Bind groups (WebGPUMainFrameBufferRenderPipeline):
5
+ // group 0: binding 0 = texture, binding 1 = sampler (fragment)
6
+
7
+ @group(0) @binding(0) var diffuseTexture : texture_2d<f32>;
8
+ @group(0) @binding(1) var diffuseSampler : sampler;
9
+
10
+ struct VertexInput
11
+ {
12
+ @location(0) position : vec3<f32>,
13
+ @location(1) texCoord : vec2<f32>,
14
+ };
15
+
16
+ struct VertexOutput
17
+ {
18
+ @builtin(position) position : vec4<f32>,
19
+ @location(0) texCoord : vec2<f32>,
20
+ };
21
+
22
+ @vertex
23
+ fn main_vs(input : VertexInput) -> VertexOutput
24
+ {
25
+ var output : VertexOutput;
26
+ output.position = vec4<f32>(input.position, 1.0);
27
+ output.texCoord = input.texCoord;
28
+ return output;
29
+ }
30
+
31
+ @fragment
32
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
33
+ {
34
+ return textureSample(diffuseTexture, diffuseSampler, vec2<f32>(input.texCoord.x, 1.0 - input.texCoord.y));
35
+ }
@@ -0,0 +1,40 @@
1
+ // Sprite batch shader (WebGPU). Hand-maintained, mirrors slang/sprite.slang and glsl_300_es/sprite_*.glsl.
2
+ //
3
+ // Bind groups (WebGPUSpriteRenderPipeline):
4
+ // group 0: binding 0 = projection view matrix (vertex)
5
+ // group 1: binding 0 = sprite texture, binding 1 = sampler (fragment)
6
+
7
+ @group(0) @binding(0) var<uniform> projectionView : mat4x4<f32>;
8
+
9
+ @group(1) @binding(0) var diffuseTexture : texture_2d<f32>;
10
+ @group(1) @binding(1) var diffuseSampler : sampler;
11
+
12
+ struct VertexInput
13
+ {
14
+ @location(0) position : vec3<f32>,
15
+ @location(1) color : vec4<f32>,
16
+ @location(2) texCoord : vec2<f32>,
17
+ };
18
+
19
+ struct VertexOutput
20
+ {
21
+ @builtin(position) position : vec4<f32>,
22
+ @location(0) color : vec4<f32>,
23
+ @location(1) texCoord : vec2<f32>,
24
+ };
25
+
26
+ @vertex
27
+ fn main_vs(input : VertexInput) -> VertexOutput
28
+ {
29
+ var output : VertexOutput;
30
+ output.position = projectionView * vec4<f32>(input.position, 1.0);
31
+ output.color = input.color;
32
+ output.texCoord = input.texCoord;
33
+ return output;
34
+ }
35
+
36
+ @fragment
37
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
38
+ {
39
+ return textureSample(diffuseTexture, diffuseSampler, input.texCoord) * input.color;
40
+ }
@@ -0,0 +1,49 @@
1
+ // Unlit material shader (WebGPU). Hand-maintained, mirrors slang/unlit_material.slang and glsl_300_es/unlit_material_*.glsl.
2
+ //
3
+ // Bind groups (WebGPUUnlitRenderPipeline):
4
+ // group 0: binding 0 = projection view matrix, binding 1 = model matrix (vertex)
5
+ // group 1: binding 0 = diffuse texture, binding 1 = sampler (fragment)
6
+ // group 2: binding 2 = material (fragment)
7
+
8
+ struct Material
9
+ {
10
+ diffuseColor : vec4<f32>,
11
+ };
12
+
13
+ @group(0) @binding(0) var<uniform> projectionView : mat4x4<f32>;
14
+ @group(0) @binding(1) var<uniform> model : mat4x4<f32>;
15
+
16
+ @group(1) @binding(0) var diffuseTexture : texture_2d<f32>;
17
+ @group(1) @binding(1) var diffuseSampler : sampler;
18
+
19
+ @group(2) @binding(2) var<uniform> material : Material;
20
+
21
+ struct VertexInput
22
+ {
23
+ @location(0) position : vec3<f32>,
24
+ @location(1) color : vec4<f32>,
25
+ @location(2) texCoord : vec2<f32>,
26
+ };
27
+
28
+ struct VertexOutput
29
+ {
30
+ @builtin(position) position : vec4<f32>,
31
+ @location(0) color : vec4<f32>,
32
+ @location(1) texCoord : vec2<f32>,
33
+ };
34
+
35
+ @vertex
36
+ fn main_vs(input : VertexInput) -> VertexOutput
37
+ {
38
+ var output : VertexOutput;
39
+ output.position = projectionView * model * vec4<f32>(input.position, 1.0);
40
+ output.color = input.color;
41
+ output.texCoord = input.texCoord;
42
+ return output;
43
+ }
44
+
45
+ @fragment
46
+ fn main_fs(input : VertexOutput) -> @location(0) vec4<f32>
47
+ {
48
+ return textureSample(diffuseTexture, diffuseSampler, input.texCoord) * material.diffuseColor * input.color;
49
+ }
package/src/Framework.ts CHANGED
@@ -1,36 +1,35 @@
1
1
  import {WebGlAmbientLightFactory} from "./webgl/lights/WebGlAmbientLightFactory.ts";
2
2
  import {WindowManager} from "./api/window/WindowManager.ts";
3
- import {FrameworkConfiguration} from "./api/FrameworkConfiguration.ts";
4
- import {type IRendererConfiguration} from "./api/rendering/renderer-interface.ts";
5
3
  import {GeometryBuilder} from "./api/geometry/GeometryBuilder.ts";
6
4
  import {ContentManager} from "./api/content/ContentManager.ts";
5
+ import {ObjLoader} from "./api/loaders/ObjLoader.ts";
7
6
  import {WebGlRenderer} from "./webgl/WebGlRenderer.ts";
8
7
  import {WebGlBuffersFactory} from "./webgl/buffers/WebGlBuffersFactory.ts";
9
8
  import {
10
- type ICameraFactory,
11
- type IContentManager,
12
- type IFramework, IFrameworkConfiguration,
13
- type IImageLoader,
14
- type IRenderer,
15
- type IRenderPipelineFactory,
16
- type IWindowManager
17
- } from "./api/index.ts";
18
- import {
9
+ type AmbientLightFactory,
19
10
  CameraFactory,
20
11
  CpuImageProcessor,
21
12
  GameTime,
22
13
  type IBufferFactory,
14
+ type ICameraFactory,
15
+ type IContentManager,
16
+ type IFramework,
17
+ IFrameworkConfiguration,
23
18
  type IGeometryBuilder,
24
19
  type IGraphicsDevice,
20
+ type IImageLoader,
25
21
  type IImageProcessor,
26
22
  type IInputManager,
27
23
  ImageLoader,
28
24
  type IMaterialFactory,
29
- type AmbientLightFactory,
30
25
  type IMeshFactory,
26
+ type IRenderer,
27
+ type IRendererConfiguration,
28
+ type IRenderPipelineFactory,
31
29
  type ISpriteBatch,
32
30
  type ITextureFactory,
33
31
  type ITimeManager,
32
+ type IWindowManager,
34
33
  MaterialFactory,
35
34
  MeshFactory,
36
35
  RenderingBackend,
@@ -48,7 +47,16 @@ import type {IKtx2Factory} from "ris-ktx2";
48
47
  import {Ktx2Factory} from "ris-ktx2";
49
48
  import {PowerPreferenceType} from "./api/rendering/PowerPreference.ts";
50
49
  import {vec2} from "gl-matrix";
51
-
50
+ import {ARenderer} from "./core/rendering/ARenderer.ts";
51
+ import {WebGpuRenderer} from "./webgpu/WebGpuRenderer.ts";
52
+ import {WebGpuTextureFactory} from "./webgpu/texture/WebGpuTextureFactory.ts";
53
+ import {WebGpuRenderPipelineFactory} from "./webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts";
54
+ import {WebGpuShaderModuleLoader} from "./webgpu/shader/WebGpuShaderModuleLoader.ts";
55
+ import {WebGpuBuffersFactory} from "./webgpu/buffers/WebGpuBuffersFactory.ts";
56
+ import {WebGpuTexture2D} from "./webgpu/texture/WebGpuTexture2D.ts";
57
+ import {TextureColorSpace} from "./api/rendering/enums.ts";
58
+
59
+ /** The Ris framework */
52
60
  export class Framework implements IFramework {
53
61
 
54
62
  private readonly _onLoadContentListeners: (() => void)[] = [];
@@ -56,46 +64,63 @@ export class Framework implements IFramework {
56
64
  private readonly _onUpdateListeners: ((gameTime: GameTime) => void)[] = [];
57
65
  private readonly _onRenderListeners: (() => void)[] = [];
58
66
 
59
- private readonly _textureFactory: ITextureFactory;
60
- private readonly _buffersFactory: IBufferFactory;
61
- private readonly _contentManager: IContentManager;
67
+ private _configuration: IFrameworkConfiguration;
68
+ private _textureFactory: ITextureFactory = null!;
69
+ private _buffersFactory: IBufferFactory = null!;
70
+ private _contentManager: IContentManager = null!;
71
+ private readonly _rendererConfiguration: IRendererConfiguration = null!;
72
+ private _renderer: IRenderer = null!;
62
73
  private readonly _geometryBuilder: IGeometryBuilder;
63
74
  private readonly _meshFactory: IMeshFactory;
64
75
  private _disposed = false;
65
76
 
66
77
  /**
67
78
  * The constructor for the Framework class.
68
- * @param options The optional framework configuration. When omitted, a default `FrameworkConfiguration` is used.
79
+ * @param configuration The optional framework configuration. When omitted, a default `FrameworkConfiguration` is used.
69
80
  */
70
- constructor(options?: IFrameworkConfiguration) {
71
- options = options ?? new FrameworkConfiguration();
81
+ constructor(configuration?: IFrameworkConfiguration) {
82
+
83
+ this._configuration = configuration ?? {}
84
+
85
+ if(!this._configuration.backBufferSize){
86
+ this._configuration.backBufferSize = vec2.fromValues(800, 600);
87
+ }
72
88
 
73
89
  // Without a canvas, WindowManager creates one and appends it to document.body.
74
- if(!options.canvas){
90
+ if(!this._configuration.canvas){
75
91
  console.warn("Canvas not provided. Creating canvas and appending it to document.body.")
76
92
  }
77
- options.backBufferSize = options.backBufferSize ?? vec2.fromValues(800, 600);
93
+ this._configuration.backBufferSize = this._configuration.backBufferSize ?? vec2.fromValues(800, 600);
78
94
 
79
- this.windowManager = new WindowManager(options.canvas ?? null);
95
+ this.windowManager = new WindowManager(this._configuration.canvas ?? null);
80
96
 
81
97
  // Services are created here and get their dependencies through their constructors.
82
- const rendererConfig: IRendererConfiguration = {
83
- backBufferSize: options.backBufferSize,
84
- textureFiltering: options.textureFiltering ?? TextureSamplerFilteringPreset.BILINEAR,
85
- alpha: options.alpha ?? false,
86
- powerPreference: options.powerPreference ?? PowerPreferenceType.DEFAULT
98
+ this._rendererConfiguration = {
99
+ backBufferSize: this._configuration.backBufferSize,
100
+ textureFiltering: this._configuration.textureFiltering ?? TextureSamplerFilteringPreset.BILINEAR,
101
+ alpha: this._configuration.alpha ?? false,
102
+ powerPreference: this._configuration.powerPreference ?? PowerPreferenceType.DEFAULT,
103
+ textureColorSpace: this._configuration.textureColorSpace ?? TextureColorSpace.SRGB
87
104
  };
88
- this.renderer = new WebGlRenderer(this, rendererConfig);
89
- this.renderingBackend = RenderingBackend.WEB_GL;
90
- this._textureFactory = new WebGlTextureFactory(this);
105
+
106
+
107
+ // The renderer, texture, pipeline, shader and buffer services depend on the backend.
108
+ let backend = this._configuration.renderingBackend ?? RenderingBackend.WEB_GL;
109
+ if (backend === RenderingBackend.DEFAULT) {
110
+ backend = RenderingBackend.WEB_GL;
111
+ }
112
+ if (backend === RenderingBackend.WEB_GPU && !WebGpuRenderer.isSupported()) {
113
+ console.warn("WebGPU was requested, but navigator.gpu is missing. Falling back to WebGL.");
114
+ backend = RenderingBackend.WEB_GL;
115
+ }
116
+ this.renderingBackend = backend;
117
+ this._setupBackendServices(backend);
118
+
91
119
  this._geometryBuilder = new GeometryBuilder();
92
- this.renderPipelineFactory = new WebGlRenderPipelineFactory(this);
93
- this._contentManager = new ContentManager(this, new WebGlShaderModuleLoader(this));
94
120
  this._meshFactory = new MeshFactory(this);
95
121
  this.materialFactory = new MaterialFactory(this);
96
122
  this.lightsFactory = new WebGlAmbientLightFactory(this);
97
123
 
98
- this._buffersFactory = new WebGlBuffersFactory(this);
99
124
  this.spriteBatch = new SpriteBatch(this);
100
125
  this.cameraFactory = new CameraFactory(this);
101
126
  this.timeManager = new TimeManager();
@@ -103,7 +128,7 @@ export class Framework implements IFramework {
103
128
  this.imageProcessor = new CpuImageProcessor();
104
129
  this.imageLoader = new ImageLoader(this);
105
130
 
106
- if(options.useKtx2){
131
+ if(this._configuration.useKtx2){
107
132
  this.ktx2Factory = new Ktx2Factory();
108
133
  }
109
134
  }
@@ -117,7 +142,30 @@ export class Framework implements IFramework {
117
142
  public readonly imageProcessor :IImageProcessor;
118
143
 
119
144
  /** @inheritDoc */
120
- public readonly renderer : IRenderer;
145
+ public get renderer(): IRenderer {
146
+ return this._renderer;
147
+ }
148
+
149
+ /**
150
+ * Creates the backend-specific services: renderer, texture factory, pipeline factory, shader loader and buffers factory.
151
+ * @param backend WEB_GL or WEB_GPU.
152
+ */
153
+ private _setupBackendServices(backend: RenderingBackend): void {
154
+ this.renderingBackend = backend;
155
+ if (backend === RenderingBackend.WEB_GPU) {
156
+ this._renderer = new WebGpuRenderer(this, this._rendererConfiguration);
157
+ this._textureFactory = new WebGpuTextureFactory(this);
158
+ this.renderPipelineFactory = new WebGpuRenderPipelineFactory(this);
159
+ this._contentManager = new ContentManager(this, new WebGpuShaderModuleLoader(this));
160
+ this._buffersFactory = new WebGpuBuffersFactory(this);
161
+ } else {
162
+ this._renderer = new WebGlRenderer(this, this._rendererConfiguration);
163
+ this._textureFactory = new WebGlTextureFactory(this);
164
+ this.renderPipelineFactory = new WebGlRenderPipelineFactory(this);
165
+ this._contentManager = new ContentManager(this, new WebGlShaderModuleLoader(this));
166
+ this._buffersFactory = new WebGlBuffersFactory(this);
167
+ }
168
+ }
121
169
 
122
170
  /** @inheritDoc */
123
171
  public readonly spriteBatch: ISpriteBatch;
@@ -185,7 +233,7 @@ export class Framework implements IFramework {
185
233
  }
186
234
 
187
235
  /** @inheritdoc */
188
- public renderPipelineFactory: IRenderPipelineFactory;
236
+ public renderPipelineFactory: IRenderPipelineFactory = null!;
189
237
 
190
238
  /** @inheritdoc */
191
239
  get geometryBuilder(): IGeometryBuilder {
@@ -215,6 +263,9 @@ export class Framework implements IFramework {
215
263
  return this._meshFactory;
216
264
  }
217
265
 
266
+ /** @inheritDoc */
267
+ public readonly objLoader: ObjLoader = new ObjLoader(this);
268
+
218
269
  /** @inheritDoc */
219
270
  public readonly materialFactory: IMaterialFactory;
220
271
 
@@ -230,11 +281,43 @@ export class Framework implements IFramework {
230
281
  /** @inheritdoc */
231
282
  public initialize(): void {
232
283
 
284
+ // WebGPU needs an async device request; initialize() keeps the synchronous WebGL path.
285
+ if (this.renderingBackend === RenderingBackend.WEB_GPU) {
286
+ console.warn("WebGPU needs Framework.initializeAsync(). initialize() falls back to WebGL.");
287
+ this._setupBackendServices(RenderingBackend.WEB_GL);
288
+ }
289
+
233
290
  if(this.ktx2Factory) {
234
291
  this.ktx2Factory.initializeAsync();
235
292
  }
236
293
 
237
- (this.renderer as WebGlRenderer).initialize();
294
+ this._initializeCore();
295
+ }
296
+
297
+ /**
298
+ * Initializes the framework and starts the event loop. Required for WebGPU, which requests its adapter
299
+ * and device asynchronously; for WebGL it behaves like {@link initialize}.
300
+ * If the WebGPU device cannot be acquired, the framework falls back to WebGL with a warning.
301
+ */
302
+ public async initializeAsync(): Promise<void> {
303
+ if (this.renderingBackend === RenderingBackend.WEB_GPU) {
304
+ try {
305
+ await (this._renderer as WebGpuRenderer).acquireDeviceAsync();
306
+ } catch (error) {
307
+ console.warn(`WebGPU could not be initialized (${(error as Error)?.message ?? error}). Falling back to WebGL.`);
308
+ this._setupBackendServices(RenderingBackend.WEB_GL);
309
+ }
310
+ }
311
+
312
+ if (this.ktx2Factory) {
313
+ this.ktx2Factory.initializeAsync();
314
+ }
315
+
316
+ this._initializeCore();
317
+ }
318
+
319
+ private _initializeCore(): void {
320
+ (this._renderer as ARenderer).initialize();
238
321
  this.spriteBatch.initialize();
239
322
  this.input.initialize();
240
323
 
@@ -297,6 +380,7 @@ export class Framework implements IFramework {
297
380
  this._onRenderListeners.length = 0;
298
381
 
299
382
  WebGlTexture2D.disposeDefault(this);
383
+ WebGpuTexture2D.disposeDefault(this);
300
384
  (this._contentManager as Partial<IDisposable>).dispose?.();
301
385
  // Only exists after initialize(); it owns the default sampler and blend state.
302
386
  (this.renderer.graphicsDevice as IGraphicsDevice | undefined)?.dispose();