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
@@ -1,9 +1,10 @@
1
- import type {
2
- IFramework, IPrimitiveState,
3
- ISampler,
4
- ITexture2D,
5
- IUniformBuffer, IUnlitRenderPipeline,
6
- IVertexBuffer
1
+ import {
2
+ GeometryFormat,
3
+ type IFramework, type IPrimitiveState,
4
+ type ISampler,
5
+ type ITexture2D,
6
+ type IUniformBuffer, type IUnlitRenderPipeline,
7
+ type IVertexBuffer
7
8
  } from "../../../api/index.ts";
8
9
  import {VertexBufferLayout} from "../../../core/rendering/vertex-buffer-layout";
9
10
  import type {WebGlUniformBuffer} from "../../buffers/WebGlUniformBuffer.ts";
@@ -50,12 +51,18 @@ export class WebGlUnlitRenderPipeline extends AWebGlRenderPipeline implements IU
50
51
  materialBuffer: IUniformBuffer,
51
52
  primitiveState?: IPrimitiveState,
52
53
  ) {
54
+ // Validated before super(), which touches WebGL.
55
+ if (!modelBuffer) {
56
+ throw new Error("WebGlUnlitRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
57
+ }
53
58
  super(framework, primitiveState);
54
59
  this._projectionViewBuffer = projectionViewBuffer as WebGlUniformBuffer;
55
60
  this._modelBuffer = modelBuffer as WebGlUniformBuffer;
56
61
  this._materialBuffer = materialBuffer as WebGlUniformBuffer;
57
62
  }
58
63
 
64
+ /** @inheritDoc */
65
+ public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2;
59
66
 
60
67
  /** @inheritdoc */
61
68
  public get projectionViewBuffer(): IUniformBuffer {
@@ -74,6 +81,9 @@ export class WebGlUnlitRenderPipeline extends AWebGlRenderPipeline implements IU
74
81
 
75
82
  /** @inheritdoc */
76
83
  public set modelBuffer(value: IUniformBuffer) {
84
+ if (!value) {
85
+ throw new Error("WebGlUnlitRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
86
+ }
77
87
  this._modelBuffer = asWebGLUniformBuffer(value);
78
88
  }
79
89
 
@@ -1,10 +1,11 @@
1
- import type {
2
- IFramework,
3
- ISampler,
4
- ISpriteRenderPipeline,
5
- ITexture2D,
6
- IUniformBuffer,
7
- IVertexBuffer
1
+ import {
2
+ GeometryFormat,
3
+ type IFramework,
4
+ type ISampler,
5
+ type ISpriteRenderPipeline,
6
+ type ITexture2D,
7
+ type IUniformBuffer,
8
+ type IVertexBuffer
8
9
  } from "../../../api/index.ts";
9
10
  import {VertexBufferLayout} from "../../../core/rendering/vertex-buffer-layout";
10
11
  import type {WebGlUniformBuffer} from "../../buffers/WebGlUniformBuffer.ts";
@@ -41,6 +42,9 @@ export class WebGlSpriteRenderPipeline extends AWebGlRenderPipeline implements I
41
42
  this._projectionViewBuffer = asWebGLUniformBuffer(projectionViewBuffer);
42
43
  }
43
44
 
45
+ /** @inheritDoc */
46
+ public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2;
47
+
44
48
  /** @inheritdoc */
45
49
  public get projectionViewBuffer(): IUniformBuffer {
46
50
  return this._projectionViewBuffer;
@@ -22,12 +22,12 @@ export class WebGlShaderModule implements IShaderModule {
22
22
  * The constructor of the WebGL shader module.
23
23
  * @param framework The framework.
24
24
  * @param shaderFilePath
25
+ * @param @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.
25
26
  */
26
- public constructor(framework: IFramework, shaderFilePath: string) {
27
+ public constructor(framework: IFramework, shaderFilePath: string, keyValueDictionary?: {[id:string]: number} ) {
27
28
  this._graphicsDevice = framework.renderer.graphicsDevice as WebGlGraphicsDevice;
28
29
  this._gl = this._graphicsDevice.gl;
29
- this._program = this._loadShaders(shaderFilePath);
30
-
30
+ this._program = this._loadShaders(shaderFilePath, keyValueDictionary);
31
31
  }
32
32
 
33
33
  /** @inheritDoc */
@@ -63,7 +63,7 @@ export class WebGlShaderModule implements IShaderModule {
63
63
  return this._program;
64
64
  }
65
65
 
66
- private _loadShaders(shaderFilePath: string): WebGLProgram {
66
+ private _loadShaders(shaderFilePath: string, keyValueDictionary?: {[id:string]: number} ): WebGLProgram {
67
67
 
68
68
  const internalShader = this._tryResolveFrameworkShader(shaderFilePath);
69
69
 
@@ -72,6 +72,7 @@ export class WebGlShaderModule implements IShaderModule {
72
72
  if (internalShader) {
73
73
  vertexShaderSource = internalShader.vertex;
74
74
  fragmentShaderSource = internalShader.fragment;
75
+
75
76
  } else {
76
77
 
77
78
  throw new Error("Not implemented");
@@ -84,6 +85,12 @@ export class WebGlShaderModule implements IShaderModule {
84
85
  // fragmentShaderSource = await this._shaderLoader.load(shaderFilePath, RenderingBackend.WEB_GL, [ShaderStage.FRAGMENT]);
85
86
  }
86
87
 
88
+ if(keyValueDictionary) {
89
+ for(const key in keyValueDictionary) {
90
+ vertexShaderSource = vertexShaderSource.replace(`##${key}##`, String(keyValueDictionary[key]));
91
+ fragmentShaderSource = fragmentShaderSource.replace(`##${key}##`, String(keyValueDictionary[key]));
92
+ }
93
+ }
87
94
 
88
95
  const vertexShader = WebGlUtilities.shader.createVertexShader(this._gl, vertexShaderSource);
89
96
  const fragmentShader = WebGlUtilities.shader.createFragmentShader(this._gl, fragmentShaderSource);
@@ -2,6 +2,21 @@ import WebGlShaderModule from "./WebGlShaderModule.ts";
2
2
  import type {IFramework, IShaderModule} from "../../api/index.ts";
3
3
 
4
4
 
5
+ /**
6
+ * Builds the cache key of a shader module: the id plus the sorted replacement values,
7
+ * so the same shader with different `##KEY##` values (e.g. light counts) is compiled separately.
8
+ * @param id The shader module id.
9
+ * @param keyValueDictionary The optional replacement values.
10
+ * @internal
11
+ */
12
+ export function shaderModuleCacheKey(id: string, keyValueDictionary?: {[id: string]: number}): string {
13
+ if (!keyValueDictionary) {
14
+ return id;
15
+ }
16
+ const entries = Object.keys(keyValueDictionary).sort().map(key => `${key}=${keyValueDictionary[key]}`);
17
+ return entries.length === 0 ? id : `${id}?${entries.join("&")}`;
18
+ }
19
+
5
20
  /**
6
21
  * The content WebGL implementation of ShaderContentModule.
7
22
  */
@@ -17,24 +32,28 @@ export class WebGlShaderModuleLoader {
17
32
  this._framework = framework;
18
33
  }
19
34
 
20
- /**
21
- * The content types provided by this content module.
22
- * @param assetFilePathOrIdentifier The asset file path or identifier of the content to load.
23
- */
24
- public load(assetFilePathOrIdentifier: string): IShaderModule {
35
+ /** @inheritDoc */
36
+ public load(assetFilePathOrIdentifier: string, keyValueDictionary?: {[id:string]: number} ): IShaderModule {
25
37
 
26
38
  // Here something like 'sprite' is provided, we must resolve it.
27
39
 
28
40
  // Is it already cached?
29
- let shaderModule = this._shaderModules.get(assetFilePathOrIdentifier);
41
+ const cacheKey = shaderModuleCacheKey(assetFilePathOrIdentifier, keyValueDictionary);
42
+ let shaderModule = this._shaderModules.get(cacheKey);
30
43
  if (!shaderModule) {
31
44
 
32
45
  // If it does not exist create one and set it.
33
- shaderModule = new WebGlShaderModule(this._framework, assetFilePathOrIdentifier);
34
- this._shaderModules.set(assetFilePathOrIdentifier, shaderModule);
46
+ shaderModule = new WebGlShaderModule(this._framework, assetFilePathOrIdentifier, keyValueDictionary);
47
+ this._shaderModules.set(cacheKey, shaderModule);
35
48
  }
36
49
  return shaderModule;
37
50
  }
38
51
 
39
-
40
- }
52
+ /** Deletes every cached shader program and clears the cache. */
53
+ public dispose(): void {
54
+ for (const shaderModule of this._shaderModules.values()) {
55
+ shaderModule.dispose();
56
+ }
57
+ this._shaderModules.clear();
58
+ }
59
+ }
@@ -1,4 +1,4 @@
1
- import { vec2 } from "gl-matrix";
1
+ import {vec2} from "gl-matrix";
2
2
  import {type IGraphicsDevice, type ISwapChain, TextureFormat} from "../../api/index.ts";
3
3
  import type {WebGlGraphicsDevice} from "../WebGlGraphicsDevice.ts";
4
4
 
@@ -16,8 +16,9 @@ export class WebGlSwapChain implements ISwapChain {
16
16
  * The WebGLSwapChain constructor.
17
17
  * @param canvas The HTML canvas element that the swap chain will use for rendering.
18
18
  * @param graphicsDevice The graphics device.
19
+ * @param srgb Prefer use of
19
20
  */
20
- public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice) {
21
+ public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice, srgb = true) {
21
22
  this._canvas = canvas;
22
23
  this._graphicsDevice = graphicsDevice as WebGlGraphicsDevice;
23
24
  this._backBufferSize = vec2.fromValues(this._canvas.width, this._canvas.height);
@@ -25,13 +26,13 @@ export class WebGlSwapChain implements ISwapChain {
25
26
  this._backBufferSize[0] = this._canvas.width;
26
27
  this._backBufferSize[1] = this._canvas.height;
27
28
  });
28
- }
29
29
 
30
+ // Nothing else to do. Typically, framebuffer should be srgb, but that is already handled through canvas.
31
+ this.textureFormat = srgb ? TextureFormat.RGBA_8_UNORM_SRGB : TextureFormat.RGBA_8_UNORM;
32
+ }
30
33
 
31
34
  /** @inheritdoc */
32
- public get textureFormat(): TextureFormat {
33
- return TextureFormat.RGBA_8_UNORM;
34
- }
35
+ public readonly textureFormat: TextureFormat;
35
36
 
36
37
  /** @inheritdoc */
37
38
  public get backBufferSize(): vec2 {
@@ -107,16 +107,19 @@ export class WebGlTexture2D extends ATexture2D {
107
107
  }
108
108
  }
109
109
 
110
- private static _defaultFilled: WebGlTexture2D | null = null;
110
+ /** One default texture per framework, so a new framework (and GL context) never gets a texture of an old one. */
111
+ private static readonly _defaultFilled = new WeakMap<IFramework, WebGlTexture2D>();
111
112
 
112
113
  /**
113
114
  * Creates a default 1x1 white texture if it doesn't already exist and returns it.
114
115
  * This can be used as a placeholder texture when a texture is expected but not available.
115
116
  * @param framework The framework instance.
117
+ * The texture belongs to that framework's GL context; each framework gets its own.
116
118
  * @returns The default 1x1 white texture.
117
119
  */
118
120
  public static getOrCreateDefault(framework: IFramework): WebGlTexture2D {
119
- if (this._defaultFilled === null || this._defaultFilled.state === State.DISPOSED) {
121
+ let texture = WebGlTexture2D._defaultFilled.get(framework);
122
+ if (!texture || texture.state === State.DISPOSED) {
120
123
 
121
124
  const desc = new TextureDescriptor();
122
125
  desc.width = 1;
@@ -125,11 +128,22 @@ export class WebGlTexture2D extends ATexture2D {
125
128
  desc.textureFormat = framework.renderer.preferredTextureFormat;
126
129
  desc.label = "RisDefaultFilledTexture";
127
130
 
128
- this._defaultFilled = new WebGlTexture2D(framework, desc);
129
- this._defaultFilled.initialize();
131
+ texture = new WebGlTexture2D(framework, desc);
132
+ texture.initialize();
133
+ WebGlTexture2D._defaultFilled.set(framework, texture);
130
134
  }
131
135
 
132
- return this._defaultFilled;
136
+ return texture;
137
+ }
138
+
139
+ /**
140
+ * Disposes and forgets the default texture of a framework. Called from `Framework.dispose()`.
141
+ * @param framework The framework instance.
142
+ */
143
+ public static disposeDefault(framework: IFramework): void {
144
+ const texture = WebGlTexture2D._defaultFilled.get(framework);
145
+ WebGlTexture2D._defaultFilled.delete(framework);
146
+ texture?.dispose();
133
147
  }
134
148
 
135
149
  }
@@ -9,7 +9,7 @@ import {
9
9
  TextureUtilities
10
10
  } from "../../api/index.ts"
11
11
  import {WebGlTexture2D} from "./WebGlTexture2D.ts";
12
- import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, TextureFormatInfo, VkFormat} from "ris-ktx2";
12
+ import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, VkFormat} from "ris-ktx2";
13
13
  import {vec2} from "gl-matrix";
14
14
 
15
15
  export class WebGlTextureFactory implements ITextureFactory {
@@ -31,13 +31,13 @@ export class WebGlTextureFactory implements ITextureFactory {
31
31
  let transcodeFormat = KtxTranscodeFormat.NO_SELECTION;
32
32
  let textureFormat = descriptor.textureFormat;
33
33
  const gpuFeatures = this._framework.graphicsDevice.features;
34
- let texFormatInfo: TextureFormatInfo | null = null;
35
34
 
36
35
  if (ktxTexture.needsTranscoding && vkFormat == VkFormat.UNDEFINED)
37
36
  {
38
37
  // If descriptor format is UNDEFINED, we will use format according to the GPU features.
39
38
  if(descriptor.textureFormat == TextureFormat.UNDEFINED)
40
39
  {
40
+ // BC7 needs BPTC (supportsTextureCompressionBC), BC3 needs S3TC.
41
41
  if(gpuFeatures.supportsTextureCompressionBC)
42
42
  {
43
43
  transcodeFormat = KtxTranscodeFormat.BC7_RGBA;
@@ -46,7 +46,7 @@ export class WebGlTextureFactory implements ITextureFactory {
46
46
  else if(gpuFeatures.supportsTextureCompressionASTC)
47
47
  {
48
48
  transcodeFormat = KtxTranscodeFormat.ASTC_4X4_RGBA;
49
- textureFormat = TextureFormat.ASTC_4X4_RGBA
49
+ textureFormat = TextureFormat.ASTC_4X4_RGBA_UNORM
50
50
  }
51
51
  else if(gpuFeatures.supportsTextureCompressionS3TC)
52
52
  {
@@ -58,6 +58,16 @@ export class WebGlTextureFactory implements ITextureFactory {
58
58
  transcodeFormat = KtxTranscodeFormat.ETC2_RGBA;
59
59
  textureFormat = TextureFormat.ETC2_RGBA8_UNORM;
60
60
  }
61
+ else if(gpuFeatures.supportsTextureCompressionPVRTC)
62
+ {
63
+ transcodeFormat = KtxTranscodeFormat.PVRTC1_4_RGBA;
64
+ textureFormat = TextureFormat.PVRTC_4BPPV1_RGBA;
65
+ }
66
+ else
67
+ {
68
+ transcodeFormat = KtxTranscodeFormat.RGBA32;
69
+ textureFormat = TextureFormat.RGBA_8_UNORM;
70
+ }
61
71
  }
62
72
  else
63
73
  {
@@ -65,12 +75,23 @@ export class WebGlTextureFactory implements ITextureFactory {
65
75
  }
66
76
 
67
77
  ktxTexture.transcodeBasis(transcodeFormat, KtxTranscodeFlags.HIGH_QUALITY);
68
- texFormatInfo = ktxTexture.getTextureFormatInfo(TextureUtilities.convertKtxTranscodeFormatToVkFormat(transcodeFormat));
78
+
79
+ // After transcoding, libktx reports the sRGB vkFormat when the file's DFD transfer function is sRGB.
80
+ if (descriptor.textureFormat == TextureFormat.UNDEFINED && WebGlTextureFactory._isSrgbVkFormat(ktxTexture.vkFormat))
81
+ {
82
+ textureFormat = TextureUtilities.toSrgbFormat(textureFormat);
83
+ }
69
84
  }
70
85
  else {
71
- // No transcoding path, but still get info about the texture format.
86
+ // No transcoding path, the vkFormat already says linear or sRGB.
72
87
  textureFormat = TextureUtilities.convertVkFormatToTextureFormat(vkFormat);
73
- texFormatInfo = ktxTexture.getTextureFormatInfo(vkFormat);
88
+ }
89
+
90
+ textureFormat = this._ensureSrgbSupported(textureFormat, ktxTexture.filePath);
91
+
92
+ const blockSize = TextureUtilities.getBlockSize(textureFormat);
93
+ if (!blockSize) {
94
+ throw new Error(`Unknown block size for texture format ${textureFormat}.`);
74
95
  }
75
96
 
76
97
  const data: Uint8Array[] = [];
@@ -85,13 +106,34 @@ export class WebGlTextureFactory implements ITextureFactory {
85
106
  textureDescriptor.data = data;
86
107
  textureDescriptor.textureFormat = textureFormat;
87
108
  textureDescriptor.generateMipmaps = descriptor.generateMipmaps;
88
- textureDescriptor.blockSize = vec2.fromValues(texFormatInfo.blockWidth, texFormatInfo.blockHeight);
109
+ textureDescriptor.blockSize = vec2.fromValues(blockSize[0], blockSize[1]);
89
110
 
90
111
  const texture = new WebGlTexture2D(this._framework, textureDescriptor);
91
112
  texture.initialize();
92
113
  return texture;
93
114
  }
94
115
 
116
+ /** Whether the Vulkan format is an sRGB format. */
117
+ private static _isSrgbVkFormat(vkFormat: VkFormat): boolean {
118
+ const name = (VkFormat as unknown as Record<number, string>)[vkFormat];
119
+ return typeof name === "string" && name.includes("_SRGB");
120
+ }
121
+
122
+ /**
123
+ * Falls back to the linear variant (with a warning) when the GPU cannot sample the sRGB format.
124
+ * Only S3TC sRGB (BC1/BC3) has its own WebGL extension; BC7, ETC2 and ASTC sRGB ship with their base extension.
125
+ */
126
+ private _ensureSrgbSupported(textureFormat: TextureFormat, source?: string): TextureFormat {
127
+ const isS3tcSrgb = textureFormat === TextureFormat.BC3_RGBA_SRGB || textureFormat === TextureFormat.BC1_RGB_SRGB;
128
+ if (isS3tcSrgb && !this._framework.graphicsDevice.features.supportsTextureCompressionS3TCSrgb) {
129
+ const linear = TextureUtilities.toLinearFormat(textureFormat);
130
+ console.warn(`sRGB S3TC is not supported (WEBGL_compressed_texture_s3tc_srgb missing); ` +
131
+ `loading ${source ?? "texture"} as ${linear}. Colours will look washed out.`);
132
+ return linear;
133
+ }
134
+ return textureFormat;
135
+ }
136
+
95
137
  /** @inheritdoc */
96
138
  public create(
97
139
  width: number, height: number,
@@ -0,0 +1,136 @@
1
+ /**
2
+ * WebGL extension constants that WebGL2RenderingContext does not expose.
3
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
4
+ */
5
+ export class WebGlConstants {
6
+
7
+ /** BC1 RGB */
8
+ public static readonly GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
9
+
10
+ /** BC1 RGB sRGB (WEBGL_compressed_texture_s3tc_srgb) */
11
+ public static readonly GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
12
+
13
+ /** BC3 sRGB (WEBGL_compressed_texture_s3tc_srgb) */
14
+ public static readonly GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
15
+
16
+ /** BC7 sRGB (EXT_texture_compression_bptc) */
17
+ public static readonly GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D;
18
+
19
+ /** ETC2 RGB8 */
20
+ public static readonly GL_COMPRESSED_RGB8_ETC2 = 0x9274;
21
+
22
+ /** ETC2 RGB8 sRGB */
23
+ public static readonly GL_COMPRESSED_SRGB8_ETC2 = 0x9275;
24
+
25
+ /** ETC2 RGBA8 sRGB */
26
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
27
+
28
+ /** BC3 */
29
+ public static readonly GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
30
+
31
+ /** BC7 */
32
+ public static readonly GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
33
+
34
+ /** ETC2 */
35
+ public static readonly GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
36
+
37
+ // ASTC (WEBGL_compressed_texture_astc).
38
+
39
+ /** ASTC 4x4 */
40
+ public static readonly GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
41
+
42
+ /** ASTC 4x4 sRGB */
43
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
44
+
45
+ /** ASTC 5x4 */
46
+ public static readonly GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
47
+
48
+ /** ASTC 5x4 sRGB */
49
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
50
+
51
+ /** ASTC 5x5 */
52
+ public static readonly GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
53
+
54
+ /** ASTC 5x5 sRGB */
55
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
56
+
57
+ /** ASTC 6x5 */
58
+ public static readonly GL_COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
59
+
60
+ /** ASTC 6x5 sRGB */
61
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
62
+
63
+ /** ASTC 6x6 */
64
+ public static readonly GL_COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
65
+
66
+ /** ASTC 6x6 sRGB */
67
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
68
+
69
+ /** ASTC 8x5 */
70
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
71
+
72
+ /** ASTC 8x5 sRGB */
73
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
74
+
75
+ /** ASTC 8x6 */
76
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
77
+
78
+ /** ASTC 8x6 sRGB */
79
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
80
+
81
+ /** ASTC 8x8 */
82
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
83
+
84
+ /** ASTC 8x8 sRGB */
85
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
86
+
87
+ /** ASTC 10x5 */
88
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
89
+
90
+ /** ASTC 10x5 sRGB */
91
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
92
+
93
+ /** ASTC 10x6 */
94
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
95
+
96
+ /** ASTC 10x6 sRGB */
97
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
98
+
99
+ /** ASTC 10x8 */
100
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
101
+
102
+ /** ASTC 10x8 sRGB */
103
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
104
+
105
+ /** ASTC 10x10 */
106
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
107
+
108
+ /** ASTC 10x10 sRGB */
109
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
110
+
111
+ /** ASTC 12x10 */
112
+ public static readonly GL_COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
113
+
114
+ /** ASTC 12x10 sRGB */
115
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
116
+
117
+ /** ASTC 12x12 */
118
+ public static readonly GL_COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
119
+
120
+ /** ASTC 12x12 sRGB */
121
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
122
+
123
+ // PVRTC (WEBGL_compressed_texture_pvrtc).
124
+
125
+ /** PVRTC 4 bits per pixel, RGB */
126
+ public static readonly GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
127
+
128
+ /** PVRTC 2 bits per pixel, RGB */
129
+ public static readonly GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
130
+
131
+ /** PVRTC 4 bits per pixel, RGBA */
132
+ public static readonly GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
133
+
134
+ /** PVRTC 2 bits per pixel, RGBA */
135
+ public static readonly GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
136
+ }
@@ -1,3 +1,4 @@
1
+ import {WebGlConstants} from "./WebGlConstants.ts";
1
2
  import {Culling} from "../../api/rendering/enums.ts";
2
3
  import {BlendFactor, BlendOperation} from "../../core/rendering/blending/enums";
3
4
  import {VertexFormat} from "../../api/geometry/VertexFormat.ts";
@@ -14,20 +15,6 @@ import {
14
15
 
15
16
  export class WebGlConverter {
16
17
 
17
- // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
18
-
19
- /** BC3 */
20
- private static GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
21
-
22
- /** BC7 */
23
- private static GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
24
-
25
-
26
- /** ETC2 */
27
- private static GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
28
-
29
- private static GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
30
-
31
18
  /**
32
19
  * Converts PrimitiveTopology to WebGL enum.
33
20
  * @param topology The PrimitiveTopology.
@@ -65,7 +52,8 @@ export class WebGlConverter {
65
52
  return WebGL2RenderingContext.BACK;
66
53
  case CullMode.FRONT:
67
54
  return WebGL2RenderingContext.FRONT;
68
- default: throw new Error("Method not implemented.");
55
+ default:
56
+ throw new Error("Method not implemented.");
69
57
  }
70
58
 
71
59
  }
@@ -95,13 +83,13 @@ export class WebGlConverter {
95
83
 
96
84
  let bufferUsage: number = WebGL2RenderingContext.STATIC_DRAW;
97
85
 
98
- if((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST)
99
- {
86
+ if ((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST) {
100
87
  bufferUsage = WebGL2RenderingContext.DYNAMIC_DRAW;
101
88
  }
102
89
 
103
90
  return bufferUsage;
104
91
  }
92
+
105
93
  /**
106
94
  * Converts BlendOperation to WebGL enum.
107
95
  * @param gl The WebGL2RenderingContext.
@@ -195,13 +183,94 @@ export class WebGlConverter {
195
183
  case TextureFormat.DEPTH_24_STENCIL_8:
196
184
  return gl.DEPTH24_STENCIL8;
197
185
  case TextureFormat.BC3_RGBA_UNORM:
198
- return WebGlConverter.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
186
+ return WebGlConstants.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
199
187
  case TextureFormat.ETC2_RGBA8_UNORM:
200
- return WebGlConverter.GL_COMPRESSED_RGBA8_ETC2_EAC;
188
+ return WebGlConstants.GL_COMPRESSED_RGBA8_ETC2_EAC;
201
189
  case TextureFormat.BC7_RGBA_UNORM:
202
- return WebGlConverter.GL_COMPRESSED_RGBA_BPTC_UNORM;
203
- case TextureFormat.ASTC_4X4_RGBA:
204
- return WebGlConverter.GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
190
+ return WebGlConstants.GL_COMPRESSED_RGBA_BPTC_UNORM;
191
+ case TextureFormat.BC7_RGBA_SRGB:
192
+ return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
193
+ case TextureFormat.BC3_RGBA_SRGB:
194
+ return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
195
+ case TextureFormat.BC1_RGB_UNORM:
196
+ return WebGlConstants.GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
197
+ case TextureFormat.BC1_RGB_SRGB:
198
+ return WebGlConstants.GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
199
+ case TextureFormat.ETC2_RGBA8_SRGB:
200
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
201
+ case TextureFormat.ETC2_RGB8_UNORM:
202
+ return WebGlConstants.GL_COMPRESSED_RGB8_ETC2;
203
+ case TextureFormat.ETC2_RGB8_SRGB:
204
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ETC2;
205
+
206
+ // ASTC
207
+ case TextureFormat.ASTC_4X4_RGBA_UNORM:
208
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
209
+ case TextureFormat.ASTC_4X4_RGBA_SRGB:
210
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
211
+ case TextureFormat.ASTC_5X4_RGBA_UNORM:
212
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
213
+ case TextureFormat.ASTC_5X4_RGBA_SRGB:
214
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
215
+ case TextureFormat.ASTC_5X5_RGBA_UNORM:
216
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
217
+ case TextureFormat.ASTC_5X5_RGBA_SRGB:
218
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
219
+ case TextureFormat.ASTC_6X5_RGBA_UNORM:
220
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
221
+ case TextureFormat.ASTC_6X5_RGBA_SRGB:
222
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
223
+ case TextureFormat.ASTC_6X6_RGBA_UNORM:
224
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
225
+ case TextureFormat.ASTC_6X6_RGBA_SRGB:
226
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
227
+ case TextureFormat.ASTC_8X5_RGBA_UNORM:
228
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
229
+ case TextureFormat.ASTC_8X5_RGBA_SRGB:
230
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
231
+ case TextureFormat.ASTC_8X6_RGBA_UNORM:
232
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
233
+ case TextureFormat.ASTC_8X6_RGBA_SRGB:
234
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
235
+ case TextureFormat.ASTC_8X8_RGBA_UNORM:
236
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
237
+ case TextureFormat.ASTC_8X8_RGBA_SRGB:
238
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
239
+ case TextureFormat.ASTC_10X5_RGBA_UNORM:
240
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
241
+ case TextureFormat.ASTC_10X5_RGBA_SRGB:
242
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
243
+ case TextureFormat.ASTC_10X6_RGBA_UNORM:
244
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
245
+ case TextureFormat.ASTC_10X6_RGBA_SRGB:
246
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
247
+ case TextureFormat.ASTC_10X8_RGBA_UNORM:
248
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
249
+ case TextureFormat.ASTC_10X8_RGBA_SRGB:
250
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
251
+ case TextureFormat.ASTC_10X10_RGBA_UNORM:
252
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
253
+ case TextureFormat.ASTC_10X10_RGBA_SRGB:
254
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
255
+ case TextureFormat.ASTC_12X10_RGBA_UNORM:
256
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
257
+ case TextureFormat.ASTC_12X10_RGBA_SRGB:
258
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
259
+ case TextureFormat.ASTC_12X12_RGBA_UNORM:
260
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
261
+ case TextureFormat.ASTC_12X12_RGBA_SRGB:
262
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
263
+
264
+ // PVRTC
265
+ case TextureFormat.PVRTC_4BPPV1_RGBA:
266
+ return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
267
+ case TextureFormat.PVRTC_4BPPV1_RGB:
268
+ return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
269
+
270
+ case TextureFormat.PVRTC_2BPPV1_RGBA:
271
+ return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
272
+ case TextureFormat.PVRTC_2BPPV1_RGB:
273
+ return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
205
274
 
206
275
  default:
207
276
  throw new Error("NotImplementedException");