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
@@ -0,0 +1,225 @@
1
+ import {
2
+ AmbientLight,
3
+ BufferUsage,
4
+ DirectionalLight,
5
+ PointLight,
6
+ type Color,
7
+ DEFAULT_POINT_LIGHTS_COUNT,
8
+ type IFramework,
9
+ type IUniformBuffer,
10
+ type LightsBuffer,
11
+ type LightsBufferDescriptor,
12
+ DEFAULT_DIRECTIONAL_LIGHTS_COUNT,
13
+ } from "../../api/index.ts";
14
+
15
+ /**
16
+ * The WebGL lights buffer. Owns a std140 uniform buffer for the `LightsBuffer` block.
17
+ * See {@link LightsBuffer} for the layout.
18
+ */
19
+ export class WebGlLightsBuffer implements LightsBuffer {
20
+
21
+ /** Floats for the ambient light: vec3 padded to 16 bytes. */
22
+ public static readonly AMBIENT_FLOAT_COUNT = 4;
23
+
24
+ /** Floats per directional light: two vec3, each padded to 16 bytes. */
25
+ public static readonly DIRECTIONAL_LIGHT_FLOAT_COUNT = 8;
26
+
27
+ /** Floats per point light: vec3 light + float constant, vec3 position + float linear, float quadratic, padded to 48 bytes. */
28
+ public static readonly POINT_LIGHT_FLOAT_COUNT = 12;
29
+
30
+ private _ambientLight!: AmbientLight;
31
+ private readonly _buffer: IUniformBuffer;
32
+ private readonly _data: number[];
33
+ private readonly _uploaded: number[];
34
+ private _directionalLights: DirectionalLight[] = [];
35
+ private _pointLights: PointLight[] = [];
36
+ private _disposed = false;
37
+
38
+ /**
39
+ * The constructor.
40
+ * @param framework The framework, used to create the uniform buffer.
41
+ * @param descriptor The optional initial lights and directional light count.
42
+ */
43
+ public constructor(framework: IFramework, descriptor?: LightsBufferDescriptor) {
44
+ this.ambientLight = descriptor?.ambientLight ?? new AmbientLight();
45
+ this.maxDirectionalLights = descriptor?.maxDirectionalLights ?? DEFAULT_DIRECTIONAL_LIGHTS_COUNT;
46
+ this.maxPointLights = descriptor?.maxPointLights ?? DEFAULT_POINT_LIGHTS_COUNT;
47
+ for (const light of descriptor?.directionalLights ?? []) {
48
+ this.add(light);
49
+ }
50
+ for (const light of descriptor?.pointLights ?? []) {
51
+ this.add(light);
52
+ }
53
+
54
+ const floatCount = WebGlLightsBuffer.AMBIENT_FLOAT_COUNT
55
+ + this.maxDirectionalLights * WebGlLightsBuffer.DIRECTIONAL_LIGHT_FLOAT_COUNT
56
+ + this.maxPointLights * WebGlLightsBuffer.POINT_LIGHT_FLOAT_COUNT;
57
+ this._data = new Array<number>(floatCount).fill(0);
58
+ this._writeData();
59
+ this._uploaded = [...this._data];
60
+ this._buffer = framework.bufferFactory.createUniformBuffer(this._data, BufferUsage.UNIFORM | BufferUsage.COPY_DST);
61
+ }
62
+
63
+ /** @inheritDoc */
64
+ public get ambientLight(): AmbientLight {
65
+ return this._ambientLight;
66
+ }
67
+
68
+ /** @inheritDoc */
69
+ public set ambientLight(ambientLight: AmbientLight) {
70
+ this._ambientLight = ambientLight;
71
+ }
72
+
73
+ /** @inheritDoc */
74
+ public get directionalLights(): DirectionalLight[] {
75
+ return this._directionalLights;
76
+ }
77
+
78
+ /** @inheritDoc */
79
+ public set directionalLights(lights: DirectionalLight[]) {
80
+ this._directionalLights = lights;
81
+ }
82
+
83
+ /** @inheritDoc */
84
+ public readonly maxDirectionalLights: number;
85
+
86
+ /** @inheritDoc */
87
+ public get pointLights(): PointLight[] {
88
+ return this._pointLights;
89
+ }
90
+
91
+ /** @inheritDoc */
92
+ public set pointLights(lights: PointLight[]) {
93
+ this._pointLights = lights;
94
+ }
95
+
96
+ /** @inheritDoc */
97
+ public add(light: DirectionalLight | PointLight): void {
98
+ const [list, max, kind] = this._listFor(light);
99
+ if (list.includes(light)) {
100
+ return;
101
+ }
102
+ if (list.length >= max) {
103
+ throw new Error(`LightsBuffer: cannot add ${kind} light ${light.id}; all ${max} ${kind} light slots are in use (max${kind === "directional" ? "Directional" : "Point"}Lights = ${max}).`);
104
+ }
105
+ list.push(light);
106
+ }
107
+
108
+ /** @inheritDoc */
109
+ public remove(light: DirectionalLight | PointLight): boolean {
110
+ const [list] = this._listFor(light);
111
+ const index = list.indexOf(light);
112
+ if (index < 0) {
113
+ return false;
114
+ }
115
+ list.splice(index, 1);
116
+ return true;
117
+ }
118
+
119
+ /** @inheritDoc */
120
+ public readonly maxPointLights: number;
121
+
122
+ /** @inheritDoc */
123
+ public get buffer(): IUniformBuffer {
124
+ return this._buffer;
125
+ }
126
+
127
+ /** @inheritDoc */
128
+ public update(): void {
129
+
130
+ // The ambient light (also a newly assigned one) is written with the rest; only changed data is uploaded.
131
+ this._writeData();
132
+ if (!this._hasChanged()) {
133
+ return;
134
+ }
135
+
136
+ this._buffer.update(this._data);
137
+ for (let i = 0; i < this._data.length; i++) {
138
+ this._uploaded[i] = this._data[i];
139
+ }
140
+ }
141
+
142
+ /** @inheritDoc */
143
+ public dispose(): void {
144
+ if (this._disposed) {
145
+ return;
146
+ }
147
+ this._disposed = true;
148
+ this._buffer.dispose();
149
+ }
150
+
151
+ private _writeAmbientLight() {
152
+ this._writeColor(0, this.ambientLight.color, this.ambientLight.intensity);
153
+ this._data[3] = 0; // std140 padding for vec3.
154
+ }
155
+
156
+ private _listFor(light: DirectionalLight | PointLight): [(DirectionalLight | PointLight)[], number, string] {
157
+ if (light instanceof DirectionalLight) {
158
+ return [this._directionalLights, this.maxDirectionalLights, "directional"];
159
+ }
160
+ if (light instanceof PointLight) {
161
+ return [this._pointLights, this.maxPointLights, "point"];
162
+ }
163
+ throw new Error("LightsBuffer: expected a DirectionalLight or PointLight instance.");
164
+ }
165
+
166
+ /** Writes color * intensity as vec3 at offset (the fourth float is left to the caller). */
167
+ private _writeColor(offset: number, color: Color | undefined, intensity: number): void {
168
+ this._data[offset] = color ? color.r * intensity : 0;
169
+ this._data[offset + 1] = color ? color.g * intensity : 0;
170
+ this._data[offset + 2] = color ? color.b * intensity : 0;
171
+ }
172
+
173
+ private _hasChanged(): boolean {
174
+ for (let i = 0; i < this._data.length; i++) {
175
+ if (this._data[i] !== this._uploaded[i]) {
176
+ return true;
177
+ }
178
+ }
179
+ return false;
180
+ }
181
+
182
+ private _writeData(): void {
183
+ // Written every time, so in-place colour and intensity edits are detected by _hasChanged().
184
+ this._writeAmbientLight();
185
+
186
+ for (let i = 0; i < this.maxDirectionalLights; i++) {
187
+ const offset = WebGlLightsBuffer.AMBIENT_FLOAT_COUNT + i * WebGlLightsBuffer.DIRECTIONAL_LIGHT_FLOAT_COUNT;
188
+ const light = this._directionalLights[i];
189
+
190
+ // vec3 light (colour * intensity)
191
+ this._writeColor(offset, light?.color, light?.intensity ?? 0);
192
+ this._data[offset + 3] = 0;
193
+
194
+ // vec3 direction
195
+ this._data[offset + 4] = light ? light.direction[0] : 0;
196
+ this._data[offset + 5] = light ? light.direction[1] : 0;
197
+ this._data[offset + 6] = light ? light.direction[2] : 0;
198
+ this._data[offset + 7] = 0;
199
+ }
200
+
201
+ const pointLightsStart = WebGlLightsBuffer.AMBIENT_FLOAT_COUNT
202
+ + this.maxDirectionalLights * WebGlLightsBuffer.DIRECTIONAL_LIGHT_FLOAT_COUNT;
203
+ for (let i = 0; i < this.maxPointLights; i++) {
204
+ const offset = pointLightsStart + i * WebGlLightsBuffer.POINT_LIGHT_FLOAT_COUNT;
205
+ const light = this._pointLights[i];
206
+
207
+ // vec3 light (colour * intensity), float constant
208
+ this._writeColor(offset, light?.color, light?.intensity ?? 0);
209
+ // An empty slot keeps constant at 1 so the shader never divides by zero.
210
+ this._data[offset + 3] = light ? light.constant : 1;
211
+
212
+ // vec3 position, float linear
213
+ this._data[offset + 4] = light ? light.position[0] : 0;
214
+ this._data[offset + 5] = light ? light.position[1] : 0;
215
+ this._data[offset + 6] = light ? light.position[2] : 0;
216
+ this._data[offset + 7] = light ? light.linear : 0;
217
+
218
+ // float quadratic, then padding to the 16-byte struct size
219
+ this._data[offset + 8] = light ? light.quadratic : 0;
220
+ this._data[offset + 9] = 0;
221
+ this._data[offset + 10] = 0;
222
+ this._data[offset + 11] = 0;
223
+ }
224
+ }
225
+ }
@@ -1,4 +1,7 @@
1
- import type {IBlendState, IFramework, IIndexBuffer, IPrimitiveState, IRenderPipeline, IVertexBuffer} from "../../api/index.ts";
1
+ import {
2
+ GeometryFormat,
3
+ type IBlendState, type IFramework, type IIndexBuffer, type IPrimitiveState, type IRenderPipeline, type IVertexBuffer
4
+ } from "../../api/index.ts";
2
5
  import type {VertexBufferLayout} from '../../core/rendering/vertex-buffer-layout';
3
6
  import type {WebGlBlendState} from '../blending/webgl-blend-state';
4
7
  import type {WebGlPrimitiveState} from '../primitive/WebGlPrimitiveState.ts';
@@ -35,6 +38,9 @@ export abstract class AWebGlRenderPipeline implements IRenderPipeline {
35
38
  this.primitiveState = (primitiveState ?? graphicsDevice.defaultPrimitiveState) as WebGlPrimitiveState;
36
39
  }
37
40
 
41
+ /** @inheritDoc */
42
+ public abstract readonly geometryFormat: GeometryFormat;
43
+
38
44
  /** @inheritDoc */
39
45
  public get blendState(): IBlendState {
40
46
  return this._blendState;
@@ -6,7 +6,13 @@ import {VertexBufferLayout} from "../../core/rendering/vertex-buffer-layout";
6
6
  import type {WebGlTexture2D} from "../texture/WebGlTexture2D.ts";
7
7
  import WebGlShaderModule from "../shader/WebGlShaderModule.ts";
8
8
  import {AWebGlRenderPipeline} from "./AWebGlRenderPipeline.ts";
9
- import {BufferUsage, type IFramework, type IMainRenderTargetRenderPipeline, type ITexture2D} from "../../api/index.ts";
9
+ import {
10
+ BufferUsage,
11
+ type IFramework,
12
+ type IMainRenderTargetRenderPipeline,
13
+ type ITexture2D,
14
+ TextureFormat
15
+ } from "../../api/index.ts";
10
16
 
11
17
  /**
12
18
  * The WebGL implementation of the main render target render pipeline.
@@ -17,6 +23,9 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
17
23
  private _indexBuffer: WebGLIndexBuffer = null!;
18
24
  private _mainRenderTarget: WebGlTexture2D = null!;
19
25
 
26
+ private _colorConversionUniformLocation: WebGLUniformLocation = null!;
27
+ private _colorSpaceValue = 0;
28
+
20
29
  /**
21
30
  * The constructor.
22
31
  * @param framework The framework.
@@ -25,8 +34,15 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
25
34
  public constructor(framework: IFramework, mainRenderTarget: ITexture2D) {
26
35
  super(framework);
27
36
  this._mainRenderTarget = mainRenderTarget as WebGlTexture2D;
37
+
38
+ if(framework.renderer.preferredTextureFormat == TextureFormat.RGBA_8_UNORM_SRGB) {
39
+ this._colorSpaceValue = 1;
40
+ }
28
41
  }
29
42
 
43
+ /** @inheritDoc */
44
+ public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2;
45
+
30
46
  /** @inheritdoc */
31
47
  protected _provideBuffers(): WebGLBuffer[] {
32
48
  return [this._vertexBuffer.buffer!];
@@ -52,6 +68,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
52
68
  this._createResources();
53
69
  this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float2Layout()];
54
70
  super.initialize();
71
+
72
+ this._colorConversionUniformLocation = this._gl.getUniformLocation(this._program, "u_colorConversion")!;
55
73
  }
56
74
 
57
75
  private _createResources(): void {
@@ -90,6 +108,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
90
108
  this._gl.bindTexture(this._gl.TEXTURE_2D, this._mainRenderTarget.glTexture);
91
109
  this._gl.bindSampler(0, this._defaultTextureSampler.glSampler);
92
110
 
111
+ this._gl.uniform1i(this._colorConversionUniformLocation, this._colorSpaceValue)
112
+
93
113
  this._gl.drawElements(this._gl.TRIANGLES, this._indexBuffer.indicesCount, this._gl.UNSIGNED_SHORT, 0);
94
114
  }
95
115
 
@@ -6,10 +6,13 @@ import type {
6
6
  IMainRenderTargetRenderPipeline, IPrimitiveState, IRenderPipelineFactory,
7
7
  ISpriteRenderPipeline, ITexture2D,
8
8
  IUniformBuffer,
9
- IUnlitRenderPipeline
10
- } from "../../api/index.ts";
9
+ IUnlitRenderPipeline,
10
+ IForwardBlinnPhongRenderPipeline,
11
+ ForwardBlinnPhongRenderPipelineDescriptor,
12
+ } from "../../api";
11
13
  import {WebGlInspectTextureMipsRenderPipeline} from "./inspect/WebGlInspectTextureMipsRenderPipeline.ts";
12
14
  import {WebGlUnlitRenderPipeline} from "./material/WebGlUnlitRenderPipeline.ts";
15
+ import {WebGlForwardBlinnPhongRenderPipeline} from "./material/WebGlBlinnPhongRenderPipeline.ts";
13
16
 
14
17
  /**
15
18
  * The WebGL implementation of the IRenderPipelineFactory interface.
@@ -37,6 +40,25 @@ export class WebGlRenderPipelineFactory implements IRenderPipelineFactory {
37
40
  return pipeline;
38
41
  }
39
42
 
43
+ /** @inheritDoc */
44
+ public createForwardBlinnPhongRenderPipeline(descriptor: ForwardBlinnPhongRenderPipelineDescriptor): IForwardBlinnPhongRenderPipeline {
45
+ const pipeline = new WebGlForwardBlinnPhongRenderPipeline(this._framework,
46
+ descriptor.projectionViewBuffer,
47
+ descriptor.modelBuffer,
48
+ descriptor.materialBuffer,
49
+ descriptor.lightsBuffer,
50
+ descriptor.cameraPositionBuffer,
51
+ descriptor.primitiveState
52
+ );
53
+ if (descriptor.maxDirectionalLights !== undefined || descriptor.maxPointLights !== undefined) {
54
+ pipeline.setLightCounts(
55
+ descriptor.maxDirectionalLights ?? pipeline.maxDirectionalLights,
56
+ descriptor.maxPointLights ?? pipeline.maxPointLights);
57
+ }
58
+ pipeline.initialize();
59
+ return pipeline;
60
+ }
61
+
40
62
  /** @inheritDoc */
41
63
  public createMainFrameBufferPipeline(mainFrameBuffer: ITexture2D): IMainRenderTargetRenderPipeline {
42
64
  const renderPipeline = new WebGlMainRenderTargetRenderPipeline(this._framework, mainFrameBuffer);
@@ -1,9 +1,10 @@
1
- import type {
2
- IFramework, IPrimitiveState,
3
- ISampler,
4
- ITexture2D,
5
- IUniformBuffer,
6
- IVertexBuffer
1
+ import {
2
+ GeometryFormat,
3
+ type IFramework, type IPrimitiveState,
4
+ type ISampler,
5
+ type ITexture2D,
6
+ type IUniformBuffer,
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";
@@ -52,12 +53,18 @@ export class WebGlInspectTextureMipsRenderPipeline extends AWebGlRenderPipeline
52
53
  textureConstantsBuffer: IUniformBuffer,
53
54
  primitiveState? : IPrimitiveState
54
55
  ) {
56
+ // Validated before super(), which touches WebGL.
57
+ if (!modelBuffer) {
58
+ throw new Error("WebGlInspectTextureMipsRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
59
+ }
55
60
  super(framework, primitiveState);
56
61
  this._projectionViewBuffer = projectionViewBuffer as WebGlUniformBuffer;
57
62
  this._modelBuffer = modelBuffer as WebGlUniformBuffer;
58
63
  this._textureConstantsBuffer = textureConstantsBuffer as WebGlUniformBuffer;
59
64
  }
60
65
 
66
+ /** @inheritDoc */
67
+ public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2;
61
68
 
62
69
  /** @inheritdoc */
63
70
  public get projectionViewBuffer(): IUniformBuffer {
@@ -76,6 +83,9 @@ export class WebGlInspectTextureMipsRenderPipeline extends AWebGlRenderPipeline
76
83
 
77
84
  /** @inheritdoc */
78
85
  public set modelBuffer(value: IUniformBuffer) {
86
+ if (!value) {
87
+ throw new Error("WebGlInspectTextureMipsRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
88
+ }
79
89
  this._modelBuffer = asWebGLUniformBuffer(value);
80
90
  }
81
91
 
@@ -0,0 +1,300 @@
1
+ import {
2
+ GeometryFormat,
3
+ type IFramework, type IPrimitiveState,
4
+ type ISampler,
5
+ type ITexture2D,
6
+ type IUniformBuffer,
7
+ type IVertexBuffer
8
+ } from "../../../api";
9
+ import {VertexBufferLayout} from "../../../core/rendering/vertex-buffer-layout";
10
+ import type {WebGlUniformBuffer} from "../../buffers/WebGlUniformBuffer.ts";
11
+ import {asWebGLUniformBuffer} from "../../cast/cast";
12
+ import WebGlShaderModule from "../../shader/WebGlShaderModule.ts";
13
+ import {WebGlTexture2D} from "../../texture/WebGlTexture2D.ts";
14
+ import {WebGlVertexBuffer} from '../../buffers/WebGlVertexBuffer.ts';
15
+ import {AWebGlRenderPipeline} from "../AWebGlRenderPipeline.ts";
16
+ import type {WebGLIndexBuffer} from "../../buffers/webgl-index-buffer";
17
+ import {
18
+ type IIndexBuffer,
19
+ IndexBufferType,
20
+ DEFAULT_DIRECTIONAL_LIGHTS_COUNT,
21
+ DEFAULT_POINT_LIGHTS_COUNT
22
+ } from "../../../api";
23
+ import type {WebGlSampler} from "../../sampler/webgl-sampler.ts";
24
+ import type {
25
+ IForwardBlinnPhongRenderPipeline
26
+ } from "../../../api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts";
27
+
28
+ /**
29
+ * The WebGL implementation of Blinn-Phong with forward calculated lighting.
30
+ * @internal
31
+ **/
32
+ export class WebGlForwardBlinnPhongRenderPipeline extends AWebGlRenderPipeline implements IForwardBlinnPhongRenderPipeline {
33
+
34
+ private static readonly CAMERA_BINDING_POINT = 0;
35
+ private static readonly MODEL_BINDING_POINT = 1;
36
+ private static readonly MATERIAL_BINDING_POINT = 2;
37
+ private static readonly LIGHTS_BINDING_POINT = 3;
38
+ private static readonly CAMERA_POSITION_BINDING_POINT = 4;
39
+
40
+ private _texture: WebGlTexture2D = null!;
41
+ private _sampler?: WebGlSampler;
42
+ private _projectionViewBuffer: WebGlUniformBuffer;
43
+ private _modelBuffer: WebGlUniformBuffer;
44
+ private _materialBuffer: WebGlUniformBuffer;
45
+ private _lightsBuffer: WebGlUniformBuffer;
46
+ private _cameraBlockIndex = -1;
47
+ private _modelBlockIndex = -1;
48
+ private _materialBlockIndex = -1;
49
+ private _lightsBlockIndex = -1;
50
+ private _cameraPositionBuffer: WebGlUniformBuffer;
51
+ private _cameraPositionBlockIndex = -1;
52
+ private _maxDirectionalLights = DEFAULT_DIRECTIONAL_LIGHTS_COUNT;
53
+ private _maxPointLights = DEFAULT_POINT_LIGHTS_COUNT;
54
+ private _initialized = false;
55
+ private _buffersArray: WebGLBuffer[] = [null!];
56
+ private _lastVertexBuffer: WebGlVertexBuffer | null = null;
57
+
58
+ /**
59
+ * The constructor.
60
+ * @param framework The framework.
61
+ * @param projectionViewBuffer The projection view buffer.
62
+ * @param modelBuffer The model buffer.
63
+ * @param materialBuffer The material buffer.
64
+ * @param lightsBuffer The lights buffer (`LightsBuffer.buffer`). May be set later.
65
+ * @param cameraPositionBuffer The camera position buffer (world-space eye).
66
+ * @param primitiveState The primitive state.
67
+ */
68
+ public constructor(framework: IFramework,
69
+ projectionViewBuffer: IUniformBuffer,
70
+ modelBuffer: IUniformBuffer,
71
+ materialBuffer: IUniformBuffer,
72
+ lightsBuffer: IUniformBuffer | undefined,
73
+ cameraPositionBuffer: IUniformBuffer,
74
+ primitiveState?: IPrimitiveState,
75
+ ) {
76
+ // Validated before super(), which touches WebGL.
77
+ if (!modelBuffer) {
78
+ throw new Error("WebGlForwardBlinnPhongRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
79
+ }
80
+ super(framework, primitiveState);
81
+ this._projectionViewBuffer = projectionViewBuffer as WebGlUniformBuffer;
82
+ this._modelBuffer = modelBuffer as WebGlUniformBuffer;
83
+ this._materialBuffer = materialBuffer as WebGlUniformBuffer;
84
+ this._lightsBuffer = lightsBuffer as WebGlUniformBuffer;
85
+ this._cameraPositionBuffer = cameraPositionBuffer as WebGlUniformBuffer;
86
+ }
87
+
88
+ /** @inheritDoc */
89
+ public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2_NORMAL3;
90
+
91
+ /** @inheritdoc */
92
+ public get projectionViewBuffer(): IUniformBuffer {
93
+ return this._projectionViewBuffer;
94
+ }
95
+
96
+ /** @inheritdoc */
97
+ public set projectionViewBuffer(value: IUniformBuffer) {
98
+ this._projectionViewBuffer = asWebGLUniformBuffer(value);
99
+ }
100
+
101
+ /** @inheritdoc */
102
+ public get modelBuffer(): IUniformBuffer {
103
+ return this._modelBuffer;
104
+ }
105
+
106
+ /** @inheritdoc */
107
+ public set modelBuffer(value: IUniformBuffer) {
108
+ if (!value) {
109
+ throw new Error("WebGlForwardBlinnPhongRenderPipeline: modelBuffer is required (the mesh's model buffer, std140 mat4).");
110
+ }
111
+ this._modelBuffer = asWebGLUniformBuffer(value);
112
+ }
113
+
114
+ /** @inheritdoc */
115
+ public get materialBuffer(): IUniformBuffer {
116
+ return this._materialBuffer;
117
+ }
118
+
119
+ /** @inheritdoc */
120
+ public set materialBuffer(value: IUniformBuffer) {
121
+ this._materialBuffer = asWebGLUniformBuffer(value);
122
+ }
123
+
124
+ /** @inheritdoc */
125
+ public get lightsBuffer(): IUniformBuffer {
126
+ return this._lightsBuffer;
127
+ }
128
+
129
+ /** @inheritdoc */
130
+ public set lightsBuffer(value: IUniformBuffer) {
131
+ this._lightsBuffer = asWebGLUniformBuffer(value);
132
+ }
133
+
134
+ /** @inheritdoc */
135
+ public get maxDirectionalLights(): number {
136
+ return this._maxDirectionalLights;
137
+ }
138
+
139
+ /** @inheritdoc */
140
+ public get maxPointLights(): number {
141
+ return this._maxPointLights;
142
+ }
143
+
144
+ /** @inheritdoc */
145
+ public setLightCounts(maxDirectionalLights: number, maxPointLights: number): void {
146
+ if (maxDirectionalLights === this._maxDirectionalLights && maxPointLights === this._maxPointLights) {
147
+ return;
148
+ }
149
+ this._maxDirectionalLights = maxDirectionalLights;
150
+ this._maxPointLights = maxPointLights;
151
+ if (this._initialized) {
152
+ // The vertex array object only depends on the vertex layout, so only the program and block bindings change.
153
+ this._loadProgram();
154
+ }
155
+ }
156
+
157
+ /** @inheritdoc */
158
+ public get cameraPositionBuffer(): IUniformBuffer {
159
+ return this._cameraPositionBuffer;
160
+ }
161
+
162
+ /** @inheritdoc */
163
+ public set cameraPositionBuffer(value: IUniformBuffer) {
164
+ this._cameraPositionBuffer = asWebGLUniformBuffer(value);
165
+ }
166
+
167
+ /** @inheritdoc */
168
+ public get diffuseTexture(): ITexture2D {
169
+ return this._texture;
170
+ }
171
+
172
+ /** @inheritdoc */
173
+ public set diffuseTexture(value: ITexture2D) {
174
+ this._texture = value as WebGlTexture2D;
175
+ }
176
+
177
+ /** @inheritdoc */
178
+ public get diffuseTextureSampler(): ISampler | undefined {
179
+ return this._sampler;
180
+ }
181
+
182
+ public set diffuseTextureSampler(value: ISampler | undefined) {
183
+ this._sampler = value as WebGlSampler | undefined;
184
+ }
185
+
186
+ /** @inheritdoc */
187
+ public override initialize(): void {
188
+
189
+ this._loadProgram();
190
+ this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float4Float2Float3Layout()];
191
+ super.initialize();
192
+ this._initialized = true;
193
+ }
194
+
195
+ /** Loads the shader variant for the current light counts (cached per counts by the shader loader). */
196
+ private _loadProgram(): void {
197
+ const module = this._framework.content.loadShaderModule("forward_blinn_phong_material", {
198
+ "DIRECTIONAL_LIGHTS_COUNT": this._maxDirectionalLights,
199
+ "POINT_LIGHTS_COUNT": this._maxPointLights,
200
+ }) as WebGlShaderModule;
201
+ this._program = module.program!;
202
+ this._createResources();
203
+ }
204
+
205
+ private _createResources(): void {
206
+ {
207
+ this._texture = WebGlTexture2D.getOrCreateDefault(this._framework);
208
+
209
+ this._cameraBlockIndex = this._gl.getUniformBlockIndex(this._program, "CameraBuffer");
210
+ this._gl.uniformBlockBinding(this._program, this._cameraBlockIndex, WebGlForwardBlinnPhongRenderPipeline.CAMERA_BINDING_POINT);
211
+
212
+ this._modelBlockIndex = this._gl.getUniformBlockIndex(this._program, "ModelBuffer");
213
+ this._gl.uniformBlockBinding(this._program, this._modelBlockIndex, WebGlForwardBlinnPhongRenderPipeline.MODEL_BINDING_POINT);
214
+
215
+ this._materialBlockIndex = this._gl.getUniformBlockIndex(this._program, "MaterialBuffer");
216
+ this._gl.uniformBlockBinding(this._program, this._materialBlockIndex, WebGlForwardBlinnPhongRenderPipeline.MATERIAL_BINDING_POINT);
217
+
218
+ this._lightsBlockIndex = this._gl.getUniformBlockIndex(this._program, "LightsBuffer");
219
+ this._gl.uniformBlockBinding(this._program, this._lightsBlockIndex, WebGlForwardBlinnPhongRenderPipeline.LIGHTS_BINDING_POINT);
220
+
221
+ this._cameraPositionBlockIndex = this._gl.getUniformBlockIndex(this._program, "CameraPositionBuffer");
222
+ this._gl.uniformBlockBinding(this._program, this._cameraPositionBlockIndex, WebGlForwardBlinnPhongRenderPipeline.CAMERA_POSITION_BINDING_POINT);
223
+ }
224
+ }
225
+
226
+
227
+ /** @inheritdoc */
228
+ protected _provideBuffers(): WebGLBuffer[] | undefined | null {
229
+ if (this._lastVertexBuffer === null) {
230
+ return null;
231
+ }
232
+
233
+ this._buffersArray[0] = this._lastVertexBuffer.buffer!;
234
+ return this._buffersArray;
235
+ }
236
+
237
+ /** @inheritdoc */
238
+ public render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount: number = -1, indicesOffset: number = 0): void {
239
+
240
+ if (indicesCount == 0) {
241
+ return;
242
+ }
243
+
244
+ const webGlVertexBuffer = vertexBuffer as WebGlVertexBuffer;
245
+ const webGlIndexBuffer = indexBuffer as WebGLIndexBuffer;
246
+ const webGlSampler = this._sampler ?? this._defaultTextureSampler;
247
+
248
+ this.primitiveState.apply(this._gl);
249
+ this._blendState.apply(this._gl);
250
+
251
+ // if it was changed, we need to create a new vao.
252
+ if (this._lastVertexBuffer != webGlVertexBuffer) {
253
+ // Create a new VAO. Internally deletes the old one.
254
+ this._lastVertexBuffer = webGlVertexBuffer;
255
+ this._createVertexArrayObject();
256
+ }
257
+
258
+ this._gl.useProgram(this._program);
259
+ // Bind the vao. It contains all the information about the vertex buffer layout ( vertices + instances)
260
+ this._gl.bindVertexArray(this._vertexArrayObject);
261
+ this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, webGlIndexBuffer.buffer);
262
+ this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,
263
+ WebGlForwardBlinnPhongRenderPipeline.CAMERA_BINDING_POINT,
264
+ this._projectionViewBuffer.glBuffer!);
265
+ this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,
266
+ WebGlForwardBlinnPhongRenderPipeline.MODEL_BINDING_POINT,
267
+ this._modelBuffer.glBuffer!);
268
+
269
+ if (this.materialBuffer) {
270
+ this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,
271
+ WebGlForwardBlinnPhongRenderPipeline.MATERIAL_BINDING_POINT,
272
+ this._materialBuffer.glBuffer!);
273
+ }
274
+ if (this._lightsBuffer) {
275
+ this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,
276
+ WebGlForwardBlinnPhongRenderPipeline.LIGHTS_BINDING_POINT,
277
+ this._lightsBuffer.glBuffer!);
278
+ }
279
+ this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,
280
+ WebGlForwardBlinnPhongRenderPipeline.CAMERA_POSITION_BINDING_POINT,
281
+ this._cameraPositionBuffer.glBuffer!);
282
+ this._gl.activeTexture(this._gl.TEXTURE0);
283
+ this._gl.bindTexture(this._gl.TEXTURE_2D, this._texture!.glTexture);
284
+ this._gl.bindSampler(0, webGlSampler.glSampler);
285
+
286
+ // We can only really use two types uint16 and uint32. Boolean check to see which one to use.
287
+ const type = indexBuffer.type == IndexBufferType.UINT_16
288
+ ? this._gl.UNSIGNED_SHORT
289
+ : this._gl.UNSIGNED_INT;
290
+
291
+ // api.PolygonMode(GLEnum.FrontAndBack, GLEnum.Line);
292
+
293
+ // Either draw all indices or a specific amount. If indicesCount is -1, draw all as defined by the index buffer.
294
+ const toIndices = indicesCount > 0 ? indicesCount : indexBuffer.indicesCount;
295
+ const fromIndices = indicesOffset * indexBuffer.elementByteSize;
296
+
297
+ this._gl.drawElements(this.primitiveState.glPrimitiveType, toIndices, type, fromIndices);
298
+ }
299
+
300
+ }