ris-framework 0.1.0 → 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 (383) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +27 -4
  3. package/dist/Framework.d.ts +34 -10
  4. package/dist/Framework.d.ts.map +1 -1
  5. package/dist/api/IFramework.d.ts +50 -6
  6. package/dist/api/IFramework.d.ts.map +1 -1
  7. package/dist/api/_export.d.ts +3 -1
  8. package/dist/api/_export.d.ts.map +1 -1
  9. package/dist/api/camera/CameraFactory.d.ts +3 -2
  10. package/dist/api/camera/CameraFactory.d.ts.map +1 -1
  11. package/dist/api/camera/ICamera.d.ts +5 -0
  12. package/dist/api/camera/ICamera.d.ts.map +1 -1
  13. package/dist/api/camera/ICameraFactory.d.ts +5 -6
  14. package/dist/api/camera/ICameraFactory.d.ts.map +1 -1
  15. package/dist/api/camera/OrthographicCamera.d.ts +7 -0
  16. package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
  17. package/dist/api/camera/PerspectiveCamera.d.ts +30 -6
  18. package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
  19. package/dist/api/content/ContentManager.d.ts +15 -2
  20. package/dist/api/content/ContentManager.d.ts.map +1 -1
  21. package/dist/api/content/IContentManager.d.ts +35 -1
  22. package/dist/api/content/IContentManager.d.ts.map +1 -1
  23. package/dist/api/content/ShaderModuleContent.d.ts.map +1 -1
  24. package/dist/api/data/Color.d.ts +5 -0
  25. package/dist/api/data/Color.d.ts.map +1 -1
  26. package/dist/api/geometry/BaseGeometry.d.ts +9 -0
  27. package/dist/api/geometry/BaseGeometry.d.ts.map +1 -1
  28. package/dist/api/geometry/GeometryBuilder.d.ts +3 -1
  29. package/dist/api/geometry/GeometryBuilder.d.ts.map +1 -1
  30. package/dist/api/geometry/IGeometryBuilder.d.ts +24 -0
  31. package/dist/api/geometry/IGeometryBuilder.d.ts.map +1 -1
  32. package/dist/api/geometry/_export-geometry.d.ts +1 -0
  33. package/dist/api/geometry/_export-geometry.d.ts.map +1 -1
  34. package/dist/api/input/InputManager.d.ts +4 -0
  35. package/dist/api/input/InputManager.d.ts.map +1 -1
  36. package/dist/api/lights/AmbientLight.d.ts +35 -0
  37. package/dist/api/lights/AmbientLight.d.ts.map +1 -0
  38. package/dist/api/lights/DirectionalLight.d.ts +40 -0
  39. package/dist/api/lights/DirectionalLight.d.ts.map +1 -0
  40. package/dist/api/lights/LightFactory.d.ts +18 -0
  41. package/dist/api/lights/LightFactory.d.ts.map +1 -0
  42. package/dist/api/lights/LightId.d.ts +6 -0
  43. package/dist/api/lights/LightId.d.ts.map +1 -0
  44. package/dist/api/lights/LightsBuffer.d.ts +77 -0
  45. package/dist/api/lights/LightsBuffer.d.ts.map +1 -0
  46. package/dist/api/lights/PointLight.d.ts +59 -0
  47. package/dist/api/lights/PointLight.d.ts.map +1 -0
  48. package/dist/api/lights/_export.d.ts +6 -0
  49. package/dist/api/lights/_export.d.ts.map +1 -0
  50. package/dist/api/loaders/ObjGeometryMapper.d.ts +19 -0
  51. package/dist/api/loaders/ObjGeometryMapper.d.ts.map +1 -0
  52. package/dist/api/loaders/ObjLoader.d.ts +61 -0
  53. package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
  54. package/dist/api/loaders/_export.d.ts +2 -0
  55. package/dist/api/loaders/_export.d.ts.map +1 -1
  56. package/dist/api/loaders/obj/ObjParser.d.ts +44 -0
  57. package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
  58. package/dist/api/loaders/obj/ObjTypes.d.ts +119 -0
  59. package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -0
  60. package/dist/api/loaders/obj/index.d.ts +3 -0
  61. package/dist/api/loaders/obj/index.d.ts.map +1 -0
  62. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +138 -0
  63. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -0
  64. package/dist/api/material/ICameraMaterial.d.ts +18 -0
  65. package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
  66. package/dist/api/material/ILightsMaterial.d.ts +26 -0
  67. package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
  68. package/dist/api/material/IMaterial.d.ts +13 -10
  69. package/dist/api/material/IMaterial.d.ts.map +1 -1
  70. package/dist/api/material/IMaterialFactory.d.ts +17 -2
  71. package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
  72. package/dist/api/material/InspectTextureMipsMaterial.d.ts +18 -9
  73. package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
  74. package/dist/api/material/MaterialFactory.d.ts +6 -0
  75. package/dist/api/material/MaterialFactory.d.ts.map +1 -1
  76. package/dist/api/material/SpriteMaterial.d.ts +51 -0
  77. package/dist/api/material/SpriteMaterial.d.ts.map +1 -0
  78. package/dist/api/material/UnlitMaterial.d.ts +32 -13
  79. package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
  80. package/dist/api/material/_export.d.ts +4 -0
  81. package/dist/api/material/_export.d.ts.map +1 -1
  82. package/dist/api/meshes/IMesh.d.ts +31 -6
  83. package/dist/api/meshes/IMesh.d.ts.map +1 -1
  84. package/dist/api/meshes/IMeshFactory.d.ts +30 -4
  85. package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
  86. package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
  87. package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
  88. package/dist/api/meshes/Mesh.d.ts +14 -8
  89. package/dist/api/meshes/Mesh.d.ts.map +1 -1
  90. package/dist/api/meshes/MeshFactory.d.ts +10 -3
  91. package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
  92. package/dist/api/meshes/QuadMesh.d.ts +5 -3
  93. package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
  94. package/dist/api/meshes/RenderableMesh.d.ts +95 -0
  95. package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
  96. package/dist/api/meshes/_export.d.ts +2 -0
  97. package/dist/api/meshes/_export.d.ts.map +1 -1
  98. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
  99. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
  100. package/dist/api/rendering/IRenderer.d.ts +28 -1
  101. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  102. package/dist/api/rendering/enums.d.ts +7 -0
  103. package/dist/api/rendering/enums.d.ts.map +1 -1
  104. package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts +56 -0
  105. package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts.map +1 -0
  106. package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts +3 -0
  107. package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts.map +1 -1
  108. package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts +29 -0
  109. package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts.map +1 -1
  110. package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts +1 -0
  111. package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts.map +1 -1
  112. package/dist/api/rendering/renderer-interface.d.ts +1 -31
  113. package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
  114. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
  115. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
  116. package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
  117. package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
  118. package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
  119. package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
  120. package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
  121. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  122. package/dist/api/scene/Scene.d.ts +113 -0
  123. package/dist/api/scene/Scene.d.ts.map +1 -0
  124. package/dist/api/scene/SceneMesh.d.ts +27 -0
  125. package/dist/api/scene/SceneMesh.d.ts.map +1 -0
  126. package/dist/api/shader/IShaderModuleLoader.d.ts +4 -1
  127. package/dist/api/shader/IShaderModuleLoader.d.ts.map +1 -1
  128. package/dist/api/shader/{shader-loader.d.ts → ShaderLoader.d.ts} +1 -1
  129. package/dist/api/shader/ShaderLoader.d.ts.map +1 -0
  130. package/dist/api/sprites/SpriteBatchDrawable.d.ts +1 -1
  131. package/dist/api/sprites/SpriteBatchDrawable.d.ts.map +1 -1
  132. package/dist/api/sprites/SpriteBatchMesh.d.ts +14 -1
  133. package/dist/api/sprites/SpriteBatchMesh.d.ts.map +1 -1
  134. package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
  135. package/dist/api/utilities/GeometryUtilities.d.ts.map +1 -1
  136. package/dist/api/window/WindowManager.d.ts +4 -0
  137. package/dist/api/window/WindowManager.d.ts.map +1 -1
  138. package/dist/core/rendering/ARenderer.d.ts +5 -5
  139. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  140. package/dist/core/rendering/vertex-buffer-layout.d.ts +1 -0
  141. package/dist/core/rendering/vertex-buffer-layout.d.ts.map +1 -1
  142. package/dist/index.d.ts +0 -1
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +9238 -4595
  145. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
  146. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
  147. package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
  148. package/dist/webgl/WebGlRenderer.d.ts +1 -3
  149. package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
  150. package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts +17 -0
  151. package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts.map +1 -0
  152. package/dist/webgl/lights/WebGlLightsBuffer.d.ts +59 -0
  153. package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -0
  154. package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts +3 -1
  155. package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts.map +1 -1
  156. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +5 -0
  157. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
  158. package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts +3 -1
  159. package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts.map +1 -1
  160. package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts +3 -1
  161. package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts.map +1 -1
  162. package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts +88 -0
  163. package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts.map +1 -0
  164. package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts +3 -1
  165. package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts.map +1 -1
  166. package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts +3 -1
  167. package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts.map +1 -1
  168. package/dist/webgl/shader/WebGlShaderModule.d.ts +4 -1
  169. package/dist/webgl/shader/WebGlShaderModule.d.ts.map +1 -1
  170. package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts +16 -5
  171. package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts.map +1 -1
  172. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
  173. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
  174. package/dist/webgl/texture/WebGlTexture2D.d.ts +8 -1
  175. package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
  176. package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
  177. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  178. package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
  179. package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
  180. package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
  181. package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
  182. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
  183. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
  184. package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
  185. package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
  186. package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
  187. package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts +0 -1
  188. package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts.map +1 -1
  189. package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
  190. package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
  191. package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
  192. package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
  193. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
  194. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
  195. package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
  196. package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
  197. package/dist/webgpu/WebGpuTypes.d.ts +355 -0
  198. package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
  199. package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
  200. package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
  201. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
  202. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
  203. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
  204. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
  205. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
  206. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
  207. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
  208. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
  209. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
  210. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
  211. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
  212. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
  213. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
  214. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
  215. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
  216. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
  217. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
  218. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
  219. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
  220. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
  221. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
  222. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
  223. package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
  224. package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
  225. package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
  226. package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
  227. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
  228. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
  229. package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
  230. package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
  231. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
  232. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
  233. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
  234. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
  235. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
  236. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
  237. package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
  238. package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
  239. package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
  240. package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
  241. package/package.json +4 -4
  242. package/shaders/glsl/forward_blinn_phong_material_fs.glsl +110 -0
  243. package/shaders/glsl/forward_blinn_phong_material_vs.glsl +32 -0
  244. package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
  245. package/shaders/glsl/sprite_fs.glsl +1 -1
  246. package/shaders/glsl/unlit_material_fs.glsl +1 -1
  247. package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
  248. package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
  249. package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
  250. package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
  251. package/shaders/wgsl/sprite.wgsl +40 -0
  252. package/shaders/wgsl/unlit_material.wgsl +49 -0
  253. package/src/Framework.ts +156 -48
  254. package/src/api/IFramework.ts +63 -6
  255. package/src/api/_export.ts +3 -1
  256. package/src/api/camera/CameraFactory.ts +6 -6
  257. package/src/api/camera/ICamera.ts +6 -0
  258. package/src/api/camera/ICameraFactory.ts +5 -10
  259. package/src/api/camera/OrthographicCamera.ts +23 -1
  260. package/src/api/camera/PerspectiveCamera.ts +60 -15
  261. package/src/api/content/ContentManager.ts +78 -16
  262. package/src/api/content/IContentManager.ts +37 -1
  263. package/src/api/content/ShaderModuleContent.ts +9 -0
  264. package/src/api/data/Color.ts +7 -1
  265. package/src/api/geometry/BaseGeometry.ts +23 -0
  266. package/src/api/geometry/GeometryBuilder.ts +14 -2
  267. package/src/api/geometry/IGeometryBuilder.ts +31 -1
  268. package/src/api/geometry/_export-geometry.ts +2 -1
  269. package/src/api/input/InputManager.ts +14 -5
  270. package/src/api/lights/AmbientLight.ts +53 -0
  271. package/src/api/lights/DirectionalLight.ts +60 -0
  272. package/src/api/lights/LightFactory.ts +21 -0
  273. package/src/api/lights/LightId.ts +9 -0
  274. package/src/api/lights/LightsBuffer.ts +94 -0
  275. package/src/api/lights/PointLight.ts +91 -0
  276. package/src/api/lights/_export.ts +5 -0
  277. package/src/api/loaders/ObjGeometryMapper.ts +28 -0
  278. package/src/api/loaders/ObjLoader.ts +126 -0
  279. package/src/api/loaders/_export.ts +3 -1
  280. package/src/api/loaders/obj/ObjParser.ts +301 -0
  281. package/src/api/loaders/obj/ObjTypes.ts +142 -0
  282. package/src/api/loaders/obj/index.ts +5 -0
  283. package/src/api/material/ForwardBlinnPhongMaterial.ts +328 -0
  284. package/src/api/material/ICameraMaterial.ts +22 -0
  285. package/src/api/material/ILightsMaterial.ts +32 -0
  286. package/src/api/material/IMaterial.ts +13 -10
  287. package/src/api/material/IMaterialFactory.ts +19 -2
  288. package/src/api/material/InspectTextureMipsMaterial.ts +65 -26
  289. package/src/api/material/MaterialFactory.ts +12 -0
  290. package/src/api/material/SpriteMaterial.ts +83 -0
  291. package/src/api/material/UnlitMaterial.ts +105 -32
  292. package/src/api/material/_export.ts +5 -1
  293. package/src/api/meshes/IMesh.ts +40 -6
  294. package/src/api/meshes/IMeshFactory.ts +33 -4
  295. package/src/api/meshes/IRenderableMesh.ts +58 -0
  296. package/src/api/meshes/Mesh.ts +50 -43
  297. package/src/api/meshes/MeshFactory.ts +37 -4
  298. package/src/api/meshes/QuadMesh.ts +6 -4
  299. package/src/api/meshes/RenderableMesh.ts +207 -0
  300. package/src/api/meshes/_export.ts +6 -4
  301. package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
  302. package/src/api/rendering/IRenderer.ts +34 -1
  303. package/src/api/rendering/enums.ts +10 -0
  304. package/src/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts +66 -0
  305. package/src/api/rendering/render-pipelines/IRenderPipeline.ts +4 -0
  306. package/src/api/rendering/render-pipelines/IRenderPipelineFactory.ts +39 -0
  307. package/src/api/rendering/render-pipelines/_export-render-pipelines.ts +2 -1
  308. package/src/api/rendering/renderer-interface.ts +1 -36
  309. package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
  310. package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
  311. package/src/api/rendering/texture/TextureFormat.ts +128 -14
  312. package/src/api/rendering/texture/TextureUtilities.ts +225 -10
  313. package/src/api/scene/Scene.ts +297 -0
  314. package/src/api/scene/SceneMesh.ts +61 -0
  315. package/src/api/shader/IShaderModuleLoader.ts +2 -1
  316. package/src/api/sprites/SpriteBatchDrawable.ts +12 -16
  317. package/src/api/sprites/SpriteBatchMesh.ts +22 -3
  318. package/src/api/utilities/AlignUtilities.ts +2 -1
  319. package/src/api/utilities/GeometryUtilities.ts +2 -0
  320. package/src/api/window/WindowManager.ts +23 -3
  321. package/src/core/rendering/ARenderer.ts +24 -15
  322. package/src/core/rendering/vertex-buffer-layout.ts +32 -1
  323. package/src/index.ts +0 -1
  324. package/src/main.ts +2 -4
  325. package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
  326. package/src/webgl/WebGlGpuInfo.ts +1 -1
  327. package/src/webgl/WebGlGraphicsDevice.ts +0 -1
  328. package/src/webgl/WebGlRenderer.ts +2 -5
  329. package/src/webgl/lights/WebGlAmbientLightFactory.ts +35 -0
  330. package/src/webgl/lights/WebGlLightsBuffer.ts +225 -0
  331. package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +7 -1
  332. package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +21 -1
  333. package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +24 -2
  334. package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +16 -6
  335. package/src/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.ts +300 -0
  336. package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +16 -6
  337. package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +11 -7
  338. package/src/webgl/shader/WebGlShaderModule.ts +11 -4
  339. package/src/webgl/shader/WebGlShaderModuleLoader.ts +29 -10
  340. package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
  341. package/src/webgl/texture/WebGlTexture2D.ts +19 -5
  342. package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
  343. package/src/webgl/utilities/WebGlConstants.ts +136 -0
  344. package/src/webgl/utilities/WebGlConverter.ts +91 -22
  345. package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
  346. package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
  347. package/src/webgl/utilities/WebGlUtilities.ts +4 -0
  348. package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +9 -6
  349. package/src/webgpu/WebGpuGpuInfo.ts +61 -0
  350. package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
  351. package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
  352. package/src/webgpu/WebGpuRenderer.ts +49 -0
  353. package/src/webgpu/WebGpuTypes.ts +288 -0
  354. package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
  355. package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
  356. package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
  357. package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
  358. package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
  359. package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
  360. package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
  361. package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
  362. package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
  363. package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
  364. package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
  365. package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
  366. package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
  367. package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
  368. package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
  369. package/src/webgpu/shader/WgslShaderContent.ts +20 -0
  370. package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
  371. package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
  372. package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
  373. package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
  374. package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
  375. package/src/wgsl-raw.d.ts +4 -0
  376. package/dist/api/FrameworkConfiguration.d.ts +0 -23
  377. package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
  378. package/dist/api/IFrameworkConfiguration.d.ts +0 -25
  379. package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
  380. package/dist/api/shader/shader-loader.d.ts.map +0 -1
  381. package/src/api/FrameworkConfiguration.ts +0 -29
  382. package/src/api/IFrameworkConfiguration.ts +0 -30
  383. /package/src/api/shader/{shader-loader.ts → ShaderLoader.ts} +0 -0
@@ -8,36 +8,199 @@ import {AlignUtilities} from "../../utilities/AlignUtilities.ts";
8
8
  export class TextureUtilities {
9
9
 
10
10
  private static readonly _compressedTextureFormats = [
11
- TextureFormat.ASTC_4X4_RGBA,
11
+
12
+ // ASTC
13
+ TextureFormat.ASTC_4X4_RGBA_UNORM,
14
+ TextureFormat.ASTC_4X4_RGBA_SRGB,
15
+ TextureFormat.ASTC_5X4_RGBA_UNORM,
16
+ TextureFormat.ASTC_5X4_RGBA_SRGB,
17
+ TextureFormat.ASTC_5X5_RGBA_UNORM,
18
+ TextureFormat.ASTC_5X5_RGBA_SRGB,
19
+ TextureFormat.ASTC_6X5_RGBA_UNORM,
20
+ TextureFormat.ASTC_6X5_RGBA_SRGB,
21
+ TextureFormat.ASTC_6X6_RGBA_UNORM,
22
+ TextureFormat.ASTC_6X6_RGBA_SRGB,
23
+ TextureFormat.ASTC_8X5_RGBA_UNORM,
24
+ TextureFormat.ASTC_8X5_RGBA_SRGB,
25
+ TextureFormat.ASTC_8X6_RGBA_UNORM,
26
+ TextureFormat.ASTC_8X6_RGBA_SRGB,
27
+ TextureFormat.ASTC_8X8_RGBA_UNORM,
28
+ TextureFormat.ASTC_8X8_RGBA_SRGB,
29
+ TextureFormat.ASTC_10X5_RGBA_UNORM,
30
+ TextureFormat.ASTC_10X5_RGBA_SRGB,
31
+ TextureFormat.ASTC_10X6_RGBA_UNORM,
32
+ TextureFormat.ASTC_10X6_RGBA_SRGB,
33
+ TextureFormat.ASTC_10X8_RGBA_UNORM,
34
+ TextureFormat.ASTC_10X8_RGBA_SRGB,
35
+ TextureFormat.ASTC_10X10_RGBA_UNORM,
36
+ TextureFormat.ASTC_10X10_RGBA_SRGB,
37
+ TextureFormat.ASTC_12X10_RGBA_UNORM,
38
+ TextureFormat.ASTC_12X10_RGBA_SRGB,
39
+ TextureFormat.ASTC_12X12_RGBA_UNORM,
40
+ TextureFormat.ASTC_12X12_RGBA_SRGB,
41
+
42
+ // PVRTC
43
+ TextureFormat.PVRTC_4BPPV1_RGBA,
44
+ TextureFormat.PVRTC_4BPPV1_RGB,
45
+ TextureFormat.PVRTC_2BPPV1_RGBA,
46
+ TextureFormat.PVRTC_2BPPV1_RGB,
47
+
12
48
  TextureFormat.BC3_RGBA_UNORM,
13
49
  TextureFormat.BC7_RGBA_UNORM,
14
- TextureFormat.ETC2_RGBA8_UNORM
50
+ TextureFormat.ETC2_RGBA8_UNORM,
51
+
52
+ // sRGB and RGB variants
53
+ TextureFormat.BC7_RGBA_SRGB,
54
+ TextureFormat.BC3_RGBA_SRGB,
55
+ TextureFormat.BC1_RGB_UNORM,
56
+ TextureFormat.BC1_RGB_SRGB,
57
+ TextureFormat.ETC2_RGBA8_SRGB,
58
+ TextureFormat.ETC2_RGB8_UNORM,
59
+ TextureFormat.ETC2_RGB8_SRGB,
15
60
  ];
16
- private static readonly _vkFormatTextureFormat: { [key: number]: number } = {
61
+
62
+ /** Linear compressed format → its sRGB variant. */
63
+ private static readonly _srgbVariant: { [key: string]: TextureFormat } = {
64
+ [TextureFormat.RGBA_8_UNORM]: TextureFormat.RGBA_8_UNORM_SRGB,
65
+ [TextureFormat.BC7_RGBA_UNORM]: TextureFormat.BC7_RGBA_SRGB,
66
+ [TextureFormat.BC3_RGBA_UNORM]: TextureFormat.BC3_RGBA_SRGB,
67
+ [TextureFormat.BC1_RGB_UNORM]: TextureFormat.BC1_RGB_SRGB,
68
+ [TextureFormat.ETC2_RGBA8_UNORM]: TextureFormat.ETC2_RGBA8_SRGB,
69
+ [TextureFormat.ETC2_RGB8_UNORM]: TextureFormat.ETC2_RGB8_SRGB,
70
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: TextureFormat.ASTC_4X4_RGBA_SRGB,
71
+ [TextureFormat.ASTC_5X4_RGBA_UNORM]: TextureFormat.ASTC_5X4_RGBA_SRGB,
72
+ [TextureFormat.ASTC_5X5_RGBA_UNORM]: TextureFormat.ASTC_5X5_RGBA_SRGB,
73
+ [TextureFormat.ASTC_6X5_RGBA_UNORM]: TextureFormat.ASTC_6X5_RGBA_SRGB,
74
+ [TextureFormat.ASTC_6X6_RGBA_UNORM]: TextureFormat.ASTC_6X6_RGBA_SRGB,
75
+ [TextureFormat.ASTC_8X5_RGBA_UNORM]: TextureFormat.ASTC_8X5_RGBA_SRGB,
76
+ [TextureFormat.ASTC_8X6_RGBA_UNORM]: TextureFormat.ASTC_8X6_RGBA_SRGB,
77
+ [TextureFormat.ASTC_8X8_RGBA_UNORM]: TextureFormat.ASTC_8X8_RGBA_SRGB,
78
+ [TextureFormat.ASTC_10X5_RGBA_UNORM]: TextureFormat.ASTC_10X5_RGBA_SRGB,
79
+ [TextureFormat.ASTC_10X6_RGBA_UNORM]: TextureFormat.ASTC_10X6_RGBA_SRGB,
80
+ [TextureFormat.ASTC_10X8_RGBA_UNORM]: TextureFormat.ASTC_10X8_RGBA_SRGB,
81
+ [TextureFormat.ASTC_10X10_RGBA_UNORM]: TextureFormat.ASTC_10X10_RGBA_SRGB,
82
+ [TextureFormat.ASTC_12X10_RGBA_UNORM]: TextureFormat.ASTC_12X10_RGBA_SRGB,
83
+ [TextureFormat.ASTC_12X12_RGBA_UNORM]: TextureFormat.ASTC_12X12_RGBA_SRGB,
84
+ };
85
+ private static readonly _vkFormatTextureFormat: { [key: number]: TextureFormat } = {
17
86
  [VkFormat.R8G8B8A8_UNORM]: TextureFormat.RGBA_8_UNORM,
18
87
  [VkFormat.R8G8B8A8_SRGB]: TextureFormat.RGBA_8_UNORM_SRGB,
19
88
  [VkFormat.BC7_UNORM_BLOCK]: TextureFormat.BC7_RGBA_UNORM,
20
- [VkFormat.ASTC_4X4_UNORM_BLOCK]: TextureFormat.ASTC_4X4_RGBA,
89
+
90
+ // ASTC
91
+ [VkFormat.ASTC_4X4_UNORM_BLOCK]: TextureFormat.ASTC_4X4_RGBA_UNORM,
92
+ [VkFormat.ASTC_4X4_SRGB_BLOCK]: TextureFormat.ASTC_4X4_RGBA_SRGB,
93
+ [VkFormat.ASTC_5X4_UNORM_BLOCK]: TextureFormat.ASTC_5X4_RGBA_UNORM,
94
+ [VkFormat.ASTC_5X4_SRGB_BLOCK]: TextureFormat.ASTC_5X4_RGBA_SRGB,
95
+ [VkFormat.ASTC_5X5_UNORM_BLOCK]: TextureFormat.ASTC_5X5_RGBA_UNORM,
96
+ [VkFormat.ASTC_5X5_SRGB_BLOCK]: TextureFormat.ASTC_5X5_RGBA_SRGB,
97
+ [VkFormat.ASTC_6X5_UNORM_BLOCK]: TextureFormat.ASTC_6X5_RGBA_UNORM,
98
+ [VkFormat.ASTC_6X5_SRGB_BLOCK]: TextureFormat.ASTC_6X5_RGBA_SRGB,
99
+ [VkFormat.ASTC_6X6_UNORM_BLOCK]: TextureFormat.ASTC_6X6_RGBA_UNORM,
100
+ [VkFormat.ASTC_6X6_SRGB_BLOCK]: TextureFormat.ASTC_6X6_RGBA_SRGB,
101
+ [VkFormat.ASTC_8X5_UNORM_BLOCK]: TextureFormat.ASTC_8X5_RGBA_UNORM,
102
+ [VkFormat.ASTC_8X5_SRGB_BLOCK]: TextureFormat.ASTC_8X5_RGBA_SRGB,
103
+ [VkFormat.ASTC_8X6_UNORM_BLOCK]: TextureFormat.ASTC_8X6_RGBA_UNORM,
104
+ [VkFormat.ASTC_8X6_SRGB_BLOCK]: TextureFormat.ASTC_8X6_RGBA_SRGB,
105
+ [VkFormat.ASTC_8X8_UNORM_BLOCK]: TextureFormat.ASTC_8X8_RGBA_UNORM,
106
+ [VkFormat.ASTC_8X8_SRGB_BLOCK]: TextureFormat.ASTC_8X8_RGBA_SRGB,
107
+ [VkFormat.ASTC_10X5_UNORM_BLOCK]: TextureFormat.ASTC_10X5_RGBA_UNORM,
108
+ [VkFormat.ASTC_10X5_SRGB_BLOCK]: TextureFormat.ASTC_10X5_RGBA_SRGB,
109
+ [VkFormat.ASTC_10X6_UNORM_BLOCK]: TextureFormat.ASTC_10X6_RGBA_UNORM,
110
+ [VkFormat.ASTC_10X6_SRGB_BLOCK]: TextureFormat.ASTC_10X6_RGBA_SRGB,
111
+ [VkFormat.ASTC_10X8_UNORM_BLOCK]: TextureFormat.ASTC_10X8_RGBA_UNORM,
112
+ [VkFormat.ASTC_10X8_SRGB_BLOCK]: TextureFormat.ASTC_10X8_RGBA_SRGB,
113
+ [VkFormat.ASTC_10X10_UNORM_BLOCK]: TextureFormat.ASTC_10X10_RGBA_UNORM,
114
+ [VkFormat.ASTC_10X10_SRGB_BLOCK]: TextureFormat.ASTC_10X10_RGBA_SRGB,
115
+ [VkFormat.ASTC_12X10_UNORM_BLOCK]: TextureFormat.ASTC_12X10_RGBA_UNORM,
116
+ [VkFormat.ASTC_12X10_SRGB_BLOCK]: TextureFormat.ASTC_12X10_RGBA_SRGB,
117
+ [VkFormat.ASTC_12X12_UNORM_BLOCK]: TextureFormat.ASTC_12X12_RGBA_UNORM,
118
+ [VkFormat.ASTC_12X12_SRGB_BLOCK]: TextureFormat.ASTC_12X12_RGBA_SRGB,
119
+
21
120
  [VkFormat.BC3_UNORM_BLOCK]: TextureFormat.BC3_RGBA_UNORM,
22
121
  [VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK]: TextureFormat.ETC2_RGBA8_UNORM,
122
+ [VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG]: TextureFormat.PVRTC_4BPPV1_RGBA,
123
+
124
+ // sRGB and RGB variants
125
+ [VkFormat.BC7_SRGB_BLOCK]: TextureFormat.BC7_RGBA_SRGB,
126
+ [VkFormat.BC3_SRGB_BLOCK]: TextureFormat.BC3_RGBA_SRGB,
127
+ [VkFormat.BC1_RGB_UNORM_BLOCK]: TextureFormat.BC1_RGB_UNORM,
128
+ [VkFormat.BC1_RGB_SRGB_BLOCK]: TextureFormat.BC1_RGB_SRGB,
129
+ [VkFormat.ETC2_R8G8B8A8_SRGB_BLOCK]: TextureFormat.ETC2_RGBA8_SRGB,
130
+ [VkFormat.ETC2_R8G8B8_UNORM_BLOCK]: TextureFormat.ETC2_RGB8_UNORM,
131
+ [VkFormat.ETC2_R8G8B8_SRGB_BLOCK]: TextureFormat.ETC2_RGB8_SRGB,
132
+
23
133
  }
24
134
 
25
- private static readonly _textureFormatVkFormat: { [key: number]: number } = {
135
+ private static readonly _textureFormatVkFormat: { [key: string]: number } = {
26
136
  [TextureFormat.RGBA_8_UNORM]: VkFormat.R8G8B8A8_UNORM,
27
137
  [TextureFormat.RGBA_8_UNORM_SRGB]: VkFormat.R8G8B8A8_SRGB,
28
138
  [TextureFormat.DEPTH_24_STENCIL_8]: VkFormat.D24_UNORM_S8_UINT,
29
139
  [TextureFormat.BC3_RGBA_UNORM]: VkFormat.BC3_UNORM_BLOCK,
30
140
  [TextureFormat.BC7_RGBA_UNORM]: VkFormat.BC7_UNORM_BLOCK,
31
- [TextureFormat.ASTC_4X4_RGBA]: VkFormat.ASTC_4X4_UNORM_BLOCK,
141
+
142
+ // ASTC
143
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: VkFormat.ASTC_4X4_UNORM_BLOCK,
144
+ [TextureFormat.ASTC_4X4_RGBA_SRGB]: VkFormat.ASTC_4X4_SRGB_BLOCK,
145
+ [TextureFormat.ASTC_5X4_RGBA_UNORM]: VkFormat.ASTC_5X4_UNORM_BLOCK,
146
+ [TextureFormat.ASTC_5X4_RGBA_SRGB]: VkFormat.ASTC_5X4_SRGB_BLOCK,
147
+ [TextureFormat.ASTC_5X5_RGBA_UNORM]: VkFormat.ASTC_5X5_UNORM_BLOCK,
148
+ [TextureFormat.ASTC_5X5_RGBA_SRGB]: VkFormat.ASTC_5X5_SRGB_BLOCK,
149
+ [TextureFormat.ASTC_6X5_RGBA_UNORM]: VkFormat.ASTC_6X5_UNORM_BLOCK,
150
+ [TextureFormat.ASTC_6X5_RGBA_SRGB]: VkFormat.ASTC_6X5_SRGB_BLOCK,
151
+ [TextureFormat.ASTC_6X6_RGBA_UNORM]: VkFormat.ASTC_6X6_UNORM_BLOCK,
152
+ [TextureFormat.ASTC_6X6_RGBA_SRGB]: VkFormat.ASTC_6X6_SRGB_BLOCK,
153
+ [TextureFormat.ASTC_8X5_RGBA_UNORM]: VkFormat.ASTC_8X5_UNORM_BLOCK,
154
+ [TextureFormat.ASTC_8X5_RGBA_SRGB]: VkFormat.ASTC_8X5_SRGB_BLOCK,
155
+ [TextureFormat.ASTC_8X6_RGBA_UNORM]: VkFormat.ASTC_8X6_UNORM_BLOCK,
156
+ [TextureFormat.ASTC_8X6_RGBA_SRGB]: VkFormat.ASTC_8X6_SRGB_BLOCK,
157
+ [TextureFormat.ASTC_8X8_RGBA_UNORM]: VkFormat.ASTC_8X8_UNORM_BLOCK,
158
+ [TextureFormat.ASTC_8X8_RGBA_SRGB]: VkFormat.ASTC_8X8_SRGB_BLOCK,
159
+ [TextureFormat.ASTC_10X5_RGBA_UNORM]: VkFormat.ASTC_10X5_UNORM_BLOCK,
160
+ [TextureFormat.ASTC_10X5_RGBA_SRGB]: VkFormat.ASTC_10X5_SRGB_BLOCK,
161
+ [TextureFormat.ASTC_10X6_RGBA_UNORM]: VkFormat.ASTC_10X6_UNORM_BLOCK,
162
+ [TextureFormat.ASTC_10X6_RGBA_SRGB]: VkFormat.ASTC_10X6_SRGB_BLOCK,
163
+ [TextureFormat.ASTC_10X8_RGBA_UNORM]: VkFormat.ASTC_10X8_UNORM_BLOCK,
164
+ [TextureFormat.ASTC_10X8_RGBA_SRGB]: VkFormat.ASTC_10X8_SRGB_BLOCK,
165
+ [TextureFormat.ASTC_10X10_RGBA_UNORM]: VkFormat.ASTC_10X10_UNORM_BLOCK,
166
+ [TextureFormat.ASTC_10X10_RGBA_SRGB]: VkFormat.ASTC_10X10_SRGB_BLOCK,
167
+ [TextureFormat.ASTC_12X10_RGBA_UNORM]: VkFormat.ASTC_12X10_UNORM_BLOCK,
168
+ [TextureFormat.ASTC_12X10_RGBA_SRGB]: VkFormat.ASTC_12X10_SRGB_BLOCK,
169
+ [TextureFormat.ASTC_12X12_RGBA_UNORM]: VkFormat.ASTC_12X12_UNORM_BLOCK,
170
+ [TextureFormat.ASTC_12X12_RGBA_SRGB]: VkFormat.ASTC_12X12_SRGB_BLOCK,
171
+
172
+ // PVRTC
173
+ [TextureFormat.PVRTC_4BPPV1_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
174
+ [TextureFormat.PVRTC_4BPPV1_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
175
+ [TextureFormat.PVRTC_2BPPV1_RGBA]: VkFormat.PVRTC1_2BPP_UNORM_BLOCK_IMG,
176
+ [TextureFormat.PVRTC_2BPPV1_RGB]: VkFormat.PVRTC1_2BPP_UNORM_BLOCK_IMG,
177
+
178
+
32
179
  [TextureFormat.ETC2_RGBA8_UNORM] : VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK,
180
+
181
+ // sRGB and RGB variants
182
+ [TextureFormat.BC7_RGBA_SRGB]: VkFormat.BC7_SRGB_BLOCK,
183
+ [TextureFormat.BC3_RGBA_SRGB]: VkFormat.BC3_SRGB_BLOCK,
184
+ [TextureFormat.BC1_RGB_UNORM]: VkFormat.BC1_RGB_UNORM_BLOCK,
185
+ [TextureFormat.BC1_RGB_SRGB]: VkFormat.BC1_RGB_SRGB_BLOCK,
186
+ [TextureFormat.ETC2_RGBA8_SRGB]: VkFormat.ETC2_R8G8B8A8_SRGB_BLOCK,
187
+ [TextureFormat.ETC2_RGB8_UNORM]: VkFormat.ETC2_R8G8B8_UNORM_BLOCK,
188
+ [TextureFormat.ETC2_RGB8_SRGB]: VkFormat.ETC2_R8G8B8_SRGB_BLOCK,
33
189
  };
34
190
 
35
- private static readonly _mapTextureFormatKtxTranscodeFormat: { [key: number]: number } = {
191
+ private static readonly _mapTextureFormatKtxTranscodeFormat: { [key: string]: number } = {
36
192
  [TextureFormat.RGBA_8_UNORM]: KtxTranscodeFormat.RGBA32,
37
- [TextureFormat.ASTC_4X4_RGBA]: KtxTranscodeFormat.ASTC_4X4_RGBA,
193
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: KtxTranscodeFormat.ASTC_4X4_RGBA,
38
194
  [TextureFormat.BC3_RGBA_UNORM]: KtxTranscodeFormat.BC3_RGBA,
39
195
  [TextureFormat.BC7_RGBA_UNORM]: KtxTranscodeFormat.BC7_RGBA,
40
196
  [TextureFormat.ETC2_RGBA8_UNORM]: KtxTranscodeFormat.ETC2_RGBA,
197
+ [TextureFormat.PVRTC_4BPPV1_RGBA] : KtxTranscodeFormat.PVRTC1_4_RGBA,
198
+ // Basis transcodes to the same blocks for sRGB; only the GPU format differs.
199
+ [TextureFormat.RGBA_8_UNORM_SRGB]: KtxTranscodeFormat.RGBA32,
200
+ [TextureFormat.ASTC_4X4_RGBA_SRGB]: KtxTranscodeFormat.ASTC_4X4_RGBA,
201
+ [TextureFormat.BC3_RGBA_SRGB]: KtxTranscodeFormat.BC3_RGBA,
202
+ [TextureFormat.BC7_RGBA_SRGB]: KtxTranscodeFormat.BC7_RGBA,
203
+ [TextureFormat.ETC2_RGBA8_SRGB]: KtxTranscodeFormat.ETC2_RGBA,
41
204
  };
42
205
 
43
206
  private static readonly _mapKtxTranscodeFormatVkFormat: { [key: number]: number } = {
@@ -49,18 +212,70 @@ export class TextureUtilities {
49
212
  [KtxTranscodeFormat.KTX_TTF_BC5_RG]: VkFormat.BC5_UNORM_BLOCK,
50
213
  [KtxTranscodeFormat.BC7_RGBA]: VkFormat.BC7_UNORM_BLOCK,
51
214
  [KtxTranscodeFormat.KTX_TTF_PVRTC1_4_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
52
- [KtxTranscodeFormat.KTX_TTF_PVRTC1_4_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
215
+ [KtxTranscodeFormat.PVRTC1_4_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
53
216
  [KtxTranscodeFormat.ASTC_4X4_RGBA]: VkFormat.ASTC_4X4_UNORM_BLOCK,
54
217
  [KtxTranscodeFormat.RGBA32]: VkFormat.R8G8B8A8_UNORM,
55
218
  [KtxTranscodeFormat.KTX_TTF_RGB565]: VkFormat.R5G6B5_UNORM_PACK16,
56
219
  [KtxTranscodeFormat.KTX_TTF_BGR565]: VkFormat.B5G6R5_UNORM_PACK16,
57
220
  [KtxTranscodeFormat.KTX_TTF_RGBA4444]: VkFormat.R4G4B4A4_UNORM_PACK16,
58
221
  [KtxTranscodeFormat.KTX_TTF_PVRTC2_4_RGB]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
59
- [KtxTranscodeFormat.KTX_TTF_PVRTC2_4_RGBA]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
222
+ [KtxTranscodeFormat.PVRTC2_4_RGBA]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
60
223
  [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_R11]: VkFormat.EAC_R11_UNORM_BLOCK,
61
224
  [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_RG11]: VkFormat.EAC_R11G11_UNORM_BLOCK,
62
225
  };
63
226
 
227
+ /**
228
+ * Whether the format stores sRGB-encoded colour (sampled as linear by the GPU).
229
+ * @param format The texture format.
230
+ */
231
+ public static isSrgbFormat(format: TextureFormat): boolean {
232
+ return format.endsWith("_SRGB");
233
+ }
234
+
235
+ /**
236
+ * Gets the sRGB variant of a linear format, or the format itself if it has none or is already sRGB.
237
+ * @param format The texture format.
238
+ */
239
+ public static toSrgbFormat(format: TextureFormat): TextureFormat {
240
+ return this._srgbVariant[format] ?? format;
241
+ }
242
+
243
+ /**
244
+ * Gets the linear variant of an sRGB format, or the format itself.
245
+ * @param format The texture format.
246
+ */
247
+ public static toLinearFormat(format: TextureFormat): TextureFormat {
248
+ for (const linear in this._srgbVariant) {
249
+ if (this._srgbVariant[linear] === format) return linear as TextureFormat;
250
+ }
251
+ return format;
252
+ }
253
+
254
+ /**
255
+ * Gets the block size (width, height) of a format: 1x1 for uncompressed, 4x4 for BC/ETC2, and the ASTC block.
256
+ * Returns null for formats it does not know.
257
+ * @param format The texture format.
258
+ */
259
+ public static getBlockSize(format: TextureFormat): [number, number] | null {
260
+ if (!this.isCompressedTextureFormat(format)) {
261
+ return [1, 1];
262
+ }
263
+ const astc = /^ASTC_(\d+)X(\d+)_/.exec(format);
264
+ if (astc) {
265
+ return [Number(astc[1]), Number(astc[2])];
266
+ }
267
+ if (format.startsWith("BC") || format.startsWith("ETC2")) {
268
+ return [4, 4];
269
+ }
270
+ if (format.startsWith("PVRTC_2BPP")) {
271
+ return [8, 4];
272
+ }
273
+ if (format.startsWith("PVRTC_4BPP")) {
274
+ return [4, 4];
275
+ }
276
+ return null;
277
+ }
278
+
64
279
  /**
65
280
  * Checks if the given texture format is a compressed texture format.
66
281
  * @param format - The texture format to check.
@@ -0,0 +1,297 @@
1
+ import {AmbientLight} from "../lights/AmbientLight.ts";
2
+ import {DirectionalLight} from "../lights/DirectionalLight.ts";
3
+ import {PointLight} from "../lights/PointLight.ts";
4
+ import type {IDisposable} from "../core/IDisposable.ts";
5
+ import type {IFramework} from "../IFramework.ts";
6
+ import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
7
+ import {SceneMesh} from "./SceneMesh.ts";
8
+ import {isCameraMaterial} from "../material/ICameraMaterial.ts";
9
+ import {isLightsMaterial} from "../material/ILightsMaterial.ts";
10
+ import type {GameTime} from "../time/GameTime.ts";
11
+ import type {ICamera} from "../camera/ICamera.ts";
12
+
13
+ /** Anything a scene can hold: a mesh, a light (ambient, directional, point) or a camera. */
14
+ export type SceneItem = IRenderableMesh | SceneMesh | AmbientLight | DirectionalLight | PointLight | ICamera;
15
+
16
+ /**
17
+ * The scene. Lights and cameras given a scene in their constructor add themselves through {@link add};
18
+ * meshes are added with `scene.add(mesh)` (wrapped in a {@link SceneMesh}, which owns the mesh's materials).
19
+ * Like C#, the scene keeps the light lists and hands its active ambient light and the lists themselves (not copies)
20
+ * to every lights material in {@link update}; each material owns and uploads its own lights buffer. Call {@link update} once per frame and {@link render} in the render listener.
21
+ */
22
+ export class Scene implements IDisposable {
23
+
24
+ private readonly _sceneMeshes: SceneMesh[] = [];
25
+ private readonly _directionalLights: DirectionalLight[] = [];
26
+ private readonly _pointLights: PointLight[] = [];
27
+
28
+ /** The directional light slots (matches the Blinn-Phong material). */
29
+ public static readonly MAX_DIRECTIONAL_LIGHTS = 3;
30
+
31
+ /** The point light slots (matches the Blinn-Phong material). */
32
+ public static readonly MAX_POINT_LIGHTS = 5;
33
+ private _activeAmbientLight: AmbientLight;
34
+ private _disposed = false;
35
+ private _activeCamera?: ICamera;
36
+
37
+ /**
38
+ * The camera the scene renders with; undefined until one is set or added.
39
+ * Setting it assigns it to the materials of every mesh (and submesh) whose camera differs;
40
+ * {@link update} also assigns it to meshes and submeshes added later.
41
+ */
42
+ public get camera(): ICamera | undefined {
43
+ return this._activeCamera;
44
+ }
45
+
46
+ public set camera(value: ICamera | undefined) {
47
+ this._activeCamera = value;
48
+ if (!value) {
49
+ return;
50
+ }
51
+ for (const sceneMesh of this._sceneMeshes) {
52
+ Scene._assignCamera(sceneMesh, value);
53
+ }
54
+ }
55
+
56
+ /** The ambient lights registered with this scene. */
57
+ public readonly ambientLights: AmbientLight[] = [];
58
+
59
+ /**
60
+ * The constructor.
61
+ * @param framework The framework.
62
+ */
63
+ public constructor(framework: IFramework) {
64
+
65
+ // Assigned through add() by the ambient light constructor; set here for the type checker.
66
+ this._activeAmbientLight = framework.lightsFactory.createAmbientLight(undefined, this);
67
+ }
68
+
69
+ /** The scene meshes, in the order they were added. */
70
+ public get sceneMeshes(): readonly SceneMesh[] {
71
+ return this._sceneMeshes;
72
+ }
73
+
74
+ /** The root meshes in this scene, in the order they were added. */
75
+ public get meshes(): readonly IRenderableMesh[] {
76
+ return this._sceneMeshes.map(s => s.mesh);
77
+ }
78
+
79
+ /** The directional lights in this scene. */
80
+ public get directionalLights(): readonly DirectionalLight[] {
81
+ return this._directionalLights;
82
+ }
83
+
84
+ /** The point lights in this scene. */
85
+ public get pointLights(): readonly PointLight[] {
86
+ return this._pointLights;
87
+ }
88
+
89
+ /**
90
+ * Gets the active ambient light.
91
+ */
92
+ public get activeAmbientLight(): AmbientLight {
93
+ return this._activeAmbientLight;
94
+ }
95
+
96
+ /** Sets the active ambient light; it is added to {@link ambientLights} if needed. */
97
+ public set activeAmbientLight(value: AmbientLight) {
98
+ this._addAmbientLight(value);
99
+ this._activeAmbientLight = value;
100
+ }
101
+
102
+ /**
103
+ * Adds a mesh, a light or a camera. Adding an item that is already in the scene does nothing.
104
+ * - Renderable mesh or {@link SceneMesh}: drawn by {@link render}; its materials get the scene camera and lights.
105
+ * A mesh is wrapped in a `SceneMesh`, so {@link dispose} also disposes its materials.
106
+ * - Ambient light: added to {@link ambientLights} (use {@link activeAmbientLight} to make it the lit one).
107
+ * - Directional / point light: added to {@link directionalLights} / {@link pointLights}.
108
+ * - Camera: becomes the scene {@link camera}.
109
+ * Constructors given a scene (lights, the perspective camera) call this themselves.
110
+ * @param item The item to add.
111
+ * @throws Error when all slots for a light kind are in use (3 directional, 5 point), or for an unsupported item.
112
+ */
113
+ public add(item: SceneItem): void {
114
+ if (item instanceof AmbientLight) {
115
+ this._addAmbientLight(item);
116
+ } else if (item instanceof DirectionalLight || item instanceof PointLight) {
117
+ this._addLight(item);
118
+ } else if (Scene._isCamera(item)) {
119
+ this.camera = item;
120
+ } else if (item instanceof SceneMesh || Scene._isMesh(item)) {
121
+ const mesh = item instanceof SceneMesh ? item.mesh : item;
122
+ if (!this._sceneMeshes.some(s => s.mesh === mesh)) {
123
+ const sceneMesh = item instanceof SceneMesh ? item : new SceneMesh(item);
124
+ this._sceneMeshes.push(sceneMesh);
125
+ this._bind(sceneMesh);
126
+ }
127
+ } else {
128
+ throw new Error("Scene.add: expected a mesh, an AmbientLight, DirectionalLight, PointLight or a camera.");
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Removes a mesh (or scene mesh), a light or a camera. The mesh and its materials are not disposed.
134
+ * Removing the active camera clears {@link camera}.
135
+ * @param item The item to remove.
136
+ * @returns True when the item was in the scene (for a camera: was the active camera).
137
+ * @throws Error when removing the active ambient light (set another {@link activeAmbientLight} first), or for an unsupported item.
138
+ */
139
+ public remove(item: SceneItem): boolean {
140
+ if (item instanceof AmbientLight) {
141
+ if (item === this._activeAmbientLight) {
142
+ throw new Error("Scene.remove: cannot remove the active ambient light; set scene.activeAmbientLight to another light first.");
143
+ }
144
+ return Scene._removeFrom(this.ambientLights, item);
145
+ }
146
+ if (item instanceof DirectionalLight || item instanceof PointLight) {
147
+ return item instanceof DirectionalLight
148
+ ? Scene._removeFrom(this._directionalLights, item)
149
+ : Scene._removeFrom(this._pointLights, item);
150
+ }
151
+ if (Scene._isCamera(item)) {
152
+ if (item !== this._activeCamera) {
153
+ return false;
154
+ }
155
+ this._activeCamera = undefined;
156
+ return true;
157
+ }
158
+ if (item instanceof SceneMesh || Scene._isMesh(item)) {
159
+ const mesh = item instanceof SceneMesh ? item.mesh : item;
160
+ const index = this._sceneMeshes.findIndex(s => s.mesh === mesh);
161
+ if (index < 0) {
162
+ return false;
163
+ }
164
+ this._sceneMeshes.splice(index, 1);
165
+ return true;
166
+ }
167
+ throw new Error("Scene.remove: expected a mesh, an AmbientLight, DirectionalLight, PointLight or a camera.");
168
+ }
169
+
170
+ /**
171
+ * Adds a directional or point light.
172
+ * @deprecated Use {@link add}.
173
+ * @throws Error when all slots for that kind are in use (3 directional, 5 point).
174
+ */
175
+ public addLight(light: DirectionalLight | PointLight): void {
176
+ this.add(light);
177
+ }
178
+
179
+ /**
180
+ * Removes a directional or point light.
181
+ * @deprecated Use {@link remove}.
182
+ * @returns True when the light was in the scene.
183
+ */
184
+ public removeLight(light: DirectionalLight | PointLight): boolean {
185
+ return this.remove(light);
186
+ }
187
+
188
+ private _addLight(light: DirectionalLight | PointLight): void {
189
+ const [list, max, kind] = light instanceof DirectionalLight
190
+ ? [this._directionalLights as (DirectionalLight | PointLight)[], Scene.MAX_DIRECTIONAL_LIGHTS, "directional"]
191
+ : [this._pointLights as (DirectionalLight | PointLight)[], Scene.MAX_POINT_LIGHTS, "point"];
192
+ if (list.includes(light)) {
193
+ return;
194
+ }
195
+ if (list.length >= max) {
196
+ throw new Error(`Scene: cannot add ${kind} light ${light.id}; all ${max} ${kind} light slots are in use.`);
197
+ }
198
+ list.push(light);
199
+ }
200
+
201
+ private _addAmbientLight(ambientLight: AmbientLight): void {
202
+ if (!this.ambientLights.includes(ambientLight)) {
203
+ this.ambientLights.push(ambientLight);
204
+ }
205
+ }
206
+
207
+ private static _removeFrom<T>(list: T[], item: T): boolean {
208
+ const index = list.indexOf(item);
209
+ if (index < 0) {
210
+ return false;
211
+ }
212
+ list.splice(index, 1);
213
+ return true;
214
+ }
215
+
216
+ /** Cameras have the camera buffers and updateBuffers(); meshes and lights do not. */
217
+ private static _isCamera(item: unknown): item is ICamera {
218
+ const camera = item as Partial<ICamera> | null;
219
+ return typeof camera === "object" && camera !== null
220
+ && "projectionViewBuffer" in camera && "viewMatrix" in camera && typeof camera.updateBuffers === "function";
221
+ }
222
+
223
+ /** Renderable meshes have render() and sub meshes. */
224
+ private static _isMesh(item: unknown): item is IRenderableMesh {
225
+ const mesh = item as Partial<IRenderableMesh> | null;
226
+ return typeof mesh === "object" && mesh !== null && typeof mesh.render === "function" && "subMeshes" in mesh;
227
+ }
228
+
229
+ /**
230
+ * Updates the scene: assigns {@link camera}, the active ambient light and the light lists to the mesh materials.
231
+ * Each lights material uploads its lights buffer when drawn, only if the lights changed.
232
+ * @param _time The game time.
233
+ * @public
234
+ */
235
+ update(_time: GameTime): void {
236
+ for (const sceneMesh of this._sceneMeshes) {
237
+ this._bind(sceneMesh);
238
+ }
239
+ }
240
+
241
+ /** Assigns the camera (when set) and the lights to the scene mesh's materials. */
242
+ private _bind(sceneMesh: SceneMesh): void {
243
+ if (this._activeCamera) {
244
+ Scene._assignCamera(sceneMesh, this._activeCamera);
245
+ }
246
+ for (const material of sceneMesh.materials) {
247
+ if (isLightsMaterial(material)) {
248
+ if (material.ambientLight !== this._activeAmbientLight) {
249
+ material.ambientLight = this._activeAmbientLight;
250
+ }
251
+ if (material.directionalLights !== this._directionalLights) {
252
+ material.directionalLights = this._directionalLights;
253
+ }
254
+ if (material.pointLights !== this._pointLights) {
255
+ material.pointLights = this._pointLights;
256
+ }
257
+ }
258
+ }
259
+ }
260
+
261
+ private static _assignCamera(sceneMesh: SceneMesh, camera: ICamera): void {
262
+ // A camera that is not initialized yet (e.g. added from its constructor) has no buffers;
263
+ // it is assigned by the next update() once initialize() created them.
264
+ if (!camera.projectionViewBuffer || !camera.positionBuffer) {
265
+ return;
266
+ }
267
+ for (const material of sceneMesh.materials) {
268
+ // The setter rebinds buffers, so skip when unchanged.
269
+ if (isCameraMaterial(material) && material.camera !== camera) {
270
+ material.camera = camera;
271
+ }
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Renders the meshes.
277
+ */
278
+ render(): void {
279
+
280
+ for (const sceneMesh of this._sceneMeshes) {
281
+ sceneMesh.render();
282
+ }
283
+
284
+ }
285
+
286
+ /** Disposes the scene meshes still in the scene: their meshes and materials. Calling it twice does nothing. */
287
+ public dispose(): void {
288
+ if (this._disposed) {
289
+ return;
290
+ }
291
+ this._disposed = true;
292
+ for (const sceneMesh of this._sceneMeshes) {
293
+ sceneMesh.dispose();
294
+ }
295
+ this._sceneMeshes.length = 0;
296
+ }
297
+ }
@@ -0,0 +1,61 @@
1
+ import type {IDisposable} from "../core/IDisposable.ts";
2
+ import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
3
+ import type {IMaterial} from "../material/IMaterial.ts";
4
+
5
+ /**
6
+ * A renderable mesh held by a scene (C# `SceneMesh`): `new SceneMesh(renderableMesh)`.
7
+ * It covers the mesh and all its sub meshes, and owns their materials:
8
+ * disposing it disposes the mesh (buffers once) and each distinct material once.
9
+ * @public
10
+ */
11
+ export class SceneMesh implements IDisposable {
12
+
13
+ private _disposed = false;
14
+
15
+ /**
16
+ * The constructor.
17
+ * @param mesh The root renderable mesh.
18
+ */
19
+ public constructor(public readonly mesh: IRenderableMesh) {
20
+ }
21
+
22
+ /** The mesh and all its sub meshes, depth first. */
23
+ public get meshes(): IRenderableMesh[] {
24
+ const result: IRenderableMesh[] = [];
25
+ const visit = (m: IRenderableMesh) => {
26
+ result.push(m);
27
+ m.subMeshes.forEach(visit);
28
+ };
29
+ visit(this.mesh);
30
+ return result;
31
+ }
32
+
33
+ /** The distinct materials of the mesh and its sub meshes. */
34
+ public get materials(): IMaterial[] {
35
+ const result: IMaterial[] = [];
36
+ for (const m of this.meshes) {
37
+ if (m.material && !result.includes(m.material)) {
38
+ result.push(m.material);
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+
44
+ /** Draws the mesh and its sub meshes. */
45
+ public render(): void {
46
+ this.mesh.render();
47
+ }
48
+
49
+ /** Disposes the mesh and its materials. Calling it twice does nothing. */
50
+ public dispose(): void {
51
+ if (this._disposed) {
52
+ return;
53
+ }
54
+ this._disposed = true;
55
+ const materials = this.materials;
56
+ this.mesh.dispose();
57
+ for (const material of materials) {
58
+ material.dispose();
59
+ }
60
+ }
61
+ }
@@ -8,8 +8,9 @@ export interface IShaderModuleLoader {
8
8
  /**
9
9
  * Loads a shader module.
10
10
  * @param shaderModuleId - The shader module id.
11
+ * @param keyValueDictionary - If present, tries to find key in shader such that it replaced ##DIRECTIONAL_LIGHT_COUNT## by given value for key DIRECTIONAL_LIGHST_COUNT.
11
12
  * @returns The shader module.
12
13
  */
13
- load(shaderModuleId: string): IShaderModule;
14
+ load(shaderModuleId: string, keyValueDictionary?: {[id:string]: number}): IShaderModule;
14
15
 
15
16
  }