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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/CHANGELOG.md +21 -29
  2. package/README.md +99 -150
  3. package/dist/Framework.d.ts +26 -8
  4. package/dist/Framework.d.ts.map +1 -1
  5. package/dist/api/IFramework.d.ts +43 -0
  6. package/dist/api/IFramework.d.ts.map +1 -1
  7. package/dist/api/_export.d.ts +1 -1
  8. package/dist/api/_export.d.ts.map +1 -1
  9. package/dist/api/content/ContentManager.d.ts +5 -57
  10. package/dist/api/content/ContentManager.d.ts.map +1 -1
  11. package/dist/api/content/IContentManager.d.ts +24 -21
  12. package/dist/api/content/IContentManager.d.ts.map +1 -1
  13. package/dist/api/lights/LightsBuffer.d.ts +13 -6
  14. package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
  15. package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
  16. package/dist/api/loaders/ObjLoader.d.ts +61 -0
  17. package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
  18. package/dist/api/loaders/_export.d.ts +1 -0
  19. package/dist/api/loaders/_export.d.ts.map +1 -1
  20. package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
  21. package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
  22. package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
  23. package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
  24. package/dist/api/loaders/obj/index.d.ts +1 -1
  25. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
  26. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
  27. package/dist/api/material/ICameraMaterial.d.ts +18 -0
  28. package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
  29. package/dist/api/material/ILightsMaterial.d.ts +26 -0
  30. package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
  31. package/dist/api/material/IMaterial.d.ts +2 -8
  32. package/dist/api/material/IMaterial.d.ts.map +1 -1
  33. package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
  34. package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
  35. package/dist/api/material/SpriteMaterial.d.ts +2 -2
  36. package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
  37. package/dist/api/material/UnlitMaterial.d.ts +4 -3
  38. package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
  39. package/dist/api/material/_export.d.ts +2 -0
  40. package/dist/api/material/_export.d.ts.map +1 -1
  41. package/dist/api/meshes/IMesh.d.ts +29 -34
  42. package/dist/api/meshes/IMesh.d.ts.map +1 -1
  43. package/dist/api/meshes/IMeshFactory.d.ts +13 -8
  44. package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
  45. package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
  46. package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
  47. package/dist/api/meshes/Mesh.d.ts +11 -57
  48. package/dist/api/meshes/Mesh.d.ts.map +1 -1
  49. package/dist/api/meshes/MeshFactory.d.ts +6 -3
  50. package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
  51. package/dist/api/meshes/QuadMesh.d.ts +3 -5
  52. package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
  53. package/dist/api/meshes/RenderableMesh.d.ts +95 -0
  54. package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
  55. package/dist/api/meshes/_export.d.ts +2 -1
  56. package/dist/api/meshes/_export.d.ts.map +1 -1
  57. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
  58. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
  59. package/dist/api/rendering/IRenderer.d.ts +28 -1
  60. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  61. package/dist/api/rendering/enums.d.ts +7 -0
  62. package/dist/api/rendering/enums.d.ts.map +1 -1
  63. package/dist/api/rendering/renderer-interface.d.ts +1 -31
  64. package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
  65. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
  66. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
  67. package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
  68. package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
  69. package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
  70. package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
  71. package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
  72. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  73. package/dist/api/scene/Scene.d.ts +30 -21
  74. package/dist/api/scene/Scene.d.ts.map +1 -1
  75. package/dist/api/scene/SceneMesh.d.ts +27 -0
  76. package/dist/api/scene/SceneMesh.d.ts.map +1 -0
  77. package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
  78. package/dist/api/window/WindowManager.d.ts.map +1 -1
  79. package/dist/core/rendering/ARenderer.d.ts +5 -5
  80. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  81. package/dist/index.d.ts +0 -1
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +4006 -1355
  84. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
  85. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
  86. package/dist/webgl/WebGlRenderer.d.ts +1 -3
  87. package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
  88. package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
  89. package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
  90. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
  91. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
  92. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
  93. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
  94. package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
  95. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  96. package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
  97. package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
  98. package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
  99. package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
  100. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
  101. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
  102. package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
  103. package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
  104. package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
  105. package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
  106. package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
  107. package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
  108. package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
  109. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
  110. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
  111. package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
  112. package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
  113. package/dist/webgpu/WebGpuTypes.d.ts +355 -0
  114. package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
  115. package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
  116. package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
  117. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
  118. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
  119. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
  120. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
  121. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
  122. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
  123. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
  124. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
  125. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
  126. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
  127. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
  128. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
  129. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
  130. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
  131. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
  132. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
  133. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
  134. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
  135. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
  136. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
  137. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
  138. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
  139. package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
  140. package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
  141. package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
  142. package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
  143. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
  144. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
  145. package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
  146. package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
  147. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
  148. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
  149. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
  150. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
  151. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
  152. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
  153. package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
  154. package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
  155. package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
  156. package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
  157. package/package.json +2 -2
  158. package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
  159. package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
  160. package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
  161. package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
  162. package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
  163. package/shaders/wgsl/sprite.wgsl +40 -0
  164. package/shaders/wgsl/unlit_material.wgsl +49 -0
  165. package/src/Framework.ts +121 -37
  166. package/src/api/IFramework.ts +55 -0
  167. package/src/api/_export.ts +1 -1
  168. package/src/api/content/ContentManager.ts +46 -180
  169. package/src/api/content/IContentManager.ts +25 -21
  170. package/src/api/lights/LightsBuffer.ts +13 -6
  171. package/src/api/loaders/ObjGeometryMapper.ts +2 -2
  172. package/src/api/loaders/ObjLoader.ts +126 -0
  173. package/src/api/loaders/_export.ts +1 -0
  174. package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
  175. package/src/api/loaders/obj/ObjTypes.ts +19 -1
  176. package/src/api/loaders/obj/index.ts +1 -1
  177. package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
  178. package/src/api/material/ICameraMaterial.ts +22 -0
  179. package/src/api/material/ILightsMaterial.ts +32 -0
  180. package/src/api/material/IMaterial.ts +2 -9
  181. package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
  182. package/src/api/material/SpriteMaterial.ts +2 -2
  183. package/src/api/material/UnlitMaterial.ts +4 -3
  184. package/src/api/material/_export.ts +2 -0
  185. package/src/api/meshes/IMesh.ts +32 -37
  186. package/src/api/meshes/IMeshFactory.ts +14 -8
  187. package/src/api/meshes/IRenderableMesh.ts +58 -0
  188. package/src/api/meshes/Mesh.ts +17 -132
  189. package/src/api/meshes/MeshFactory.ts +14 -5
  190. package/src/api/meshes/QuadMesh.ts +4 -6
  191. package/src/api/meshes/RenderableMesh.ts +207 -0
  192. package/src/api/meshes/_export.ts +6 -5
  193. package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
  194. package/src/api/rendering/IRenderer.ts +34 -1
  195. package/src/api/rendering/enums.ts +10 -0
  196. package/src/api/rendering/renderer-interface.ts +1 -36
  197. package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
  198. package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
  199. package/src/api/rendering/texture/TextureFormat.ts +128 -14
  200. package/src/api/rendering/texture/TextureUtilities.ts +225 -10
  201. package/src/api/scene/Scene.ts +102 -69
  202. package/src/api/scene/SceneMesh.ts +61 -0
  203. package/src/api/sprites/SpriteBatchMesh.ts +1 -1
  204. package/src/api/utilities/AlignUtilities.ts +2 -1
  205. package/src/api/window/WindowManager.ts +1 -1
  206. package/src/core/rendering/ARenderer.ts +24 -15
  207. package/src/index.ts +0 -1
  208. package/src/main.ts +2 -3
  209. package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
  210. package/src/webgl/WebGlGpuInfo.ts +1 -1
  211. package/src/webgl/WebGlRenderer.ts +2 -5
  212. package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
  213. package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
  214. package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
  215. package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
  216. package/src/webgl/utilities/WebGlConstants.ts +136 -0
  217. package/src/webgl/utilities/WebGlConverter.ts +91 -22
  218. package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
  219. package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
  220. package/src/webgl/utilities/WebGlUtilities.ts +4 -0
  221. package/src/webgpu/WebGpuGpuInfo.ts +61 -0
  222. package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
  223. package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
  224. package/src/webgpu/WebGpuRenderer.ts +49 -0
  225. package/src/webgpu/WebGpuTypes.ts +288 -0
  226. package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
  227. package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
  228. package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
  229. package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
  230. package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
  231. package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
  232. package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
  233. package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
  234. package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
  235. package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
  236. package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
  237. package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
  238. package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
  239. package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
  240. package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
  241. package/src/webgpu/shader/WgslShaderContent.ts +20 -0
  242. package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
  243. package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
  244. package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
  245. package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
  246. package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
  247. package/src/wgsl-raw.d.ts +4 -0
  248. package/dist/api/FrameworkConfiguration.d.ts +0 -23
  249. package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
  250. package/dist/api/IFrameworkConfiguration.d.ts +0 -25
  251. package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
  252. package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
  253. package/dist/api/meshes/SubMesh.d.ts +0 -47
  254. package/dist/api/meshes/SubMesh.d.ts.map +0 -1
  255. package/src/api/FrameworkConfiguration.ts +0 -29
  256. package/src/api/IFrameworkConfiguration.ts +0 -30
  257. package/src/api/meshes/SubMesh.ts +0 -71
@@ -1,56 +1,21 @@
1
1
  import { vec2 } from "gl-matrix";
2
- import { TextureSamplerFilteringPreset } from "../../core/rendering/enums.ts";
3
2
  import type {RenderingLimits} from "./rendering-limits.ts";
4
- import type {Color, IGraphicsDevice, IRenderer} from "../index.ts";
3
+ import type { IRenderer} from "../index.ts";
5
4
  import type {TextureFormat} from "../index.ts";
6
- import {PowerPreferenceType} from "./PowerPreference.ts";
7
5
 
8
- export const RenderConfigurationSymbol = Symbol("RenderConfiguration");
9
6
 
10
- /**
11
- * The configuration for the renderer. This is used to initialize the renderer.
12
- * @internal
13
- */
14
- export interface IRendererConfiguration {
15
-
16
- /**The size of the main frame buffer. */
17
- backBufferSize: vec2;
18
7
 
19
- /** Should back buffer use alpha. */
20
- alpha: boolean;
21
-
22
- /** The preference when it comes to selecting GPU device. Only makes sense to set on multi-GPU devices. */
23
- powerPreference: PowerPreferenceType;
24
-
25
- /**
26
- * The preset for texture sampler filtering.
27
- * This is used to configure the default texture sampler in the graphics device.
28
- * The default texture sampler is used when a texture is sampled without a specific sampler being bound.
29
- */
30
- textureFiltering: TextureSamplerFilteringPreset;
31
- }
32
8
 
33
9
  /**
34
10
  * The interface for renderers.
35
11
  */
36
12
  export interface ITempRenderer extends IRenderer {
37
13
 
38
- /**
39
- * The clear color used by the renderer.
40
- */
41
- clearColor: Color
42
-
43
14
  /**
44
15
  * The rendering limits of the renderer.
45
16
  */
46
17
  limits: RenderingLimits | null;
47
18
 
48
- /**
49
- * The graphics device used by the renderer.
50
- * This is used to create resources and manage the rendering context.
51
- */
52
- readonly graphicsDevice: IGraphicsDevice;
53
-
54
19
  /**
55
20
  * The preferred texture format for the renderer.
56
21
  * @returns The preferred texture format for the renderer.
@@ -6,21 +6,17 @@ import {RenderPassColorAttachment} from "./RenderPassColorAttachment.ts";
6
6
  */
7
7
  export class RenderPassDescriptor {
8
8
 
9
- /**
10
- * The color attachments of the render pass.
11
- */
12
- public colorAttachments?: RenderPassColorAttachment[];
9
+ /** The color attachments of the render pass. */
10
+ public colorAttachments?: RenderPassColorAttachment[];
13
11
 
14
- /**
15
- * The depth-stencil attachment of the render pass.
16
- */
17
- public depthStencilAttachment?: RenderPassDepthStencilAttachment;
12
+ /** The depth-stencil attachment of the render pass. */
13
+ public depthStencilAttachment?: RenderPassDepthStencilAttachment;
18
14
 
19
- /**
20
- * The label of the render pass.
21
- * This is used for debugging purposes and can be set to any string that helps identify the render pass in graphics debuggers or profiling tools.
22
- * It does not affect the functionality of the render pass and can be left empty if not needed.
23
- */
24
- public label?: string;
15
+ /**
16
+ * The label of the render pass.
17
+ * This is used for debugging purposes and can be set to any string that helps identify the render pass in graphics debuggers or profiling tools.
18
+ * It does not affect the functionality of the render pass and can be left empty if not needed.
19
+ */
20
+ public label?: string;
25
21
 
26
22
  }
@@ -12,9 +12,7 @@ export interface ISwapChain extends IDisposable {
12
12
  */
13
13
  readonly backBufferSize: vec2;
14
14
 
15
- /**
16
- * The texture format of the back buffer.
17
- */
15
+ /** The texture format of the back buffer. */
18
16
  readonly textureFormat: TextureFormat;
19
17
 
20
18
  /**
@@ -6,53 +6,167 @@ export enum TextureFormat {
6
6
  * Default value.
7
7
  For unknown texture format.
8
8
  */
9
- UNDEFINED = 0,
9
+ UNDEFINED = "UNDEFINED",
10
10
 
11
11
  /**
12
12
  * Red, green, blue, and alpha channels.
13
13
  * 8-bit integer per channel.
14
14
  * [0, 255] converted to/from float [0, 1] in shader.
15
15
  * */
16
- RGBA_8_UNORM = 1,
16
+ RGBA_8_UNORM = "RGBA_8_UNORM",
17
17
 
18
18
  /**
19
19
  * Red, green, blue, and alpha channels.
20
20
  * 8-bit integer per channel.
21
21
  * Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
22
22
  */
23
- RGBA_8_UNORM_SRGB = 2,
23
+ RGBA_8_UNORM_SRGB = "RGBA_8_UNORM_SRGB",
24
24
 
25
25
  /**
26
26
  * Depth 24 and stencil 8.
27
27
  */
28
- DEPTH_24_STENCIL_8 = 3,
28
+ DEPTH_24_STENCIL_8 = "DEPTH_24_STENCIL_8",
29
29
 
30
30
  /**
31
31
  * The depth 32 float.
32
32
  */
33
- DEPTH_32_FLOAT = 4,
33
+ DEPTH_32_FLOAT = "DEPTH_32_FLOAT_8",
34
34
 
35
- RED_32_FLOAT = 5,
35
+ RED_32_FLOAT = "RED_32_FLOAT_8",
36
36
  /**
37
37
  * The 32-bit float format with one red component. It is typeless.
38
38
 
39
39
  Valid only for D3D11.
40
40
  */
41
- RED_32_TYPELESS = 6,
41
+ RED_32_TYPELESS = "RED_32_TYPELE_8",
42
42
  /**
43
43
  * The BC7 compressed format with four 8-bit normalized unsigned integer components in RGBA order.
44
44
  */
45
- BC7_RGBA_UNORM = 7,
45
+ BC7_RGBA_UNORM = "BC7_RGBA_UNORM",
46
46
  /**
47
47
  * The BC3 compressed format with four 8-bit normalized unsigned integer components in RGBA order.
48
48
  */
49
- BC3_RGBA_UNORM = 8,
49
+ BC3_RGBA_UNORM = "BC3_RGBA_UNORM",
50
50
  /**
51
51
  * The ETC2 compressed format with four 8-bit normalized unsigned integer components in RGBA order.
52
52
  */
53
- ETC2_RGBA8_UNORM = 9,
54
- /**
55
- * The ASTC 4x4 compressed format with four 8-bit normalized unsigned integer components in RGBA order.
56
- */
57
- ASTC_4X4_RGBA = 10
53
+ ETC2_RGBA8_UNORM = "ETC2_RGBA8_UNORM",
54
+
55
+ /** BC7 RGBA, sRGB. Requires EXT_texture_compression_bptc (WebGL) or texture-compression-bc (WebGPU). */
56
+ BC7_RGBA_SRGB = "BC7_RGBA_SRGB",
57
+
58
+ /** BC3 (DXT5) RGBA, sRGB. Requires WEBGL_compressed_texture_s3tc_srgb (WebGL) or texture-compression-bc (WebGPU). */
59
+ BC3_RGBA_SRGB = "BC3_RGBA_SRGB",
60
+
61
+ /** BC1 (DXT1) RGB. Requires WEBGL_compressed_texture_s3tc (WebGL) or texture-compression-bc (WebGPU). */
62
+ BC1_RGB_UNORM = "BC1_RGB_UNORM",
63
+
64
+ /** BC1 (DXT1) RGB, sRGB. Requires WEBGL_compressed_texture_s3tc_srgb (WebGL). WebGPU only has BC1 RGBA, which is used instead. */
65
+ BC1_RGB_SRGB = "BC1_RGB_SRGB",
66
+
67
+ /** ETC2 RGBA8 with EAC alpha, sRGB. Requires WEBGL_compressed_texture_etc (WebGL) or texture-compression-etc2 (WebGPU). */
68
+ ETC2_RGBA8_SRGB = "ETC2_RGBA8_SRGB",
69
+
70
+ /** ETC2 RGB8. Requires WEBGL_compressed_texture_etc (WebGL) or texture-compression-etc2 (WebGPU). */
71
+ ETC2_RGB8_UNORM = "ETC2_RGB8_UNORM",
72
+
73
+ /** ETC2 RGB8, sRGB. Requires WEBGL_compressed_texture_etc (WebGL) or texture-compression-etc2 (WebGPU). */
74
+ ETC2_RGB8_SRGB = "ETC2_RGB8_SRGB",
75
+
76
+
77
+ /** The ASTC 4x4 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
78
+ ASTC_4X4_RGBA_UNORM = "ASTC_4X4_RGBA_UNORM",
79
+
80
+ /** The ASTC 4x4 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
81
+ ASTC_4X4_RGBA_SRGB = "ASTC_4X4_RGBA_SRGB",
82
+
83
+ /** The ASTC 5x4 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
84
+ ASTC_5X4_RGBA_UNORM = "ASTC_5X4_RGBA_UNORM",
85
+
86
+ /** The ASTC 5x4 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
87
+ ASTC_5X4_RGBA_SRGB = "ASTC_5X4_RGBA_SRGB",
88
+
89
+ /** The ASTC 5x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
90
+ ASTC_5X5_RGBA_UNORM = "ASTC_5X5_RGBA_UNORM",
91
+
92
+ /** The ASTC 5x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
93
+ ASTC_5X5_RGBA_SRGB = "ASTC_5X5_RGBA_SRGB",
94
+
95
+ /** The ASTC 6x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
96
+ ASTC_6X5_RGBA_UNORM = "ASTC_6X5_RGBA_UNORM",
97
+
98
+ /** The ASTC 6x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
99
+ ASTC_6X5_RGBA_SRGB = "ASTC_6X5_RGBA_SRGB",
100
+
101
+ /** The ASTC 6x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
102
+ ASTC_6X6_RGBA_UNORM = "ASTC_6X6_RGBA_UNORM",
103
+
104
+ /** The ASTC 6x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
105
+ ASTC_6X6_RGBA_SRGB = "ASTC_6X6_RGBA_SRGB",
106
+
107
+ /** The ASTC 8x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
108
+ ASTC_8X5_RGBA_UNORM = "ASTC_8X5_RGBA_UNORM",
109
+
110
+ /** The ASTC 8x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
111
+ ASTC_8X5_RGBA_SRGB = "ASTC_8X5_RGBA_SRGB",
112
+
113
+ /** The ASTC 8x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
114
+ ASTC_8X6_RGBA_UNORM = "ASTC_8X6_RGBA_UNORM",
115
+
116
+ /** The ASTC 8x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
117
+ ASTC_8X6_RGBA_SRGB = "ASTC_8X6_RGBA_SRGB",
118
+
119
+ /** The ASTC 8x8 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
120
+ ASTC_8X8_RGBA_UNORM = "ASTC_8X8_RGBA_UNORM",
121
+
122
+ /** The ASTC 8x8 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
123
+ ASTC_8X8_RGBA_SRGB = "ASTC_8X8_RGBA_SRGB",
124
+
125
+ /** The ASTC 10x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
126
+ ASTC_10X5_RGBA_UNORM = "ASTC_10X5_RGBA_UNORM",
127
+
128
+ /** The ASTC 10x5 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
129
+ ASTC_10X5_RGBA_SRGB = "ASTC_10X5_RGBA_SRGB",
130
+
131
+ /** The ASTC 10x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
132
+ ASTC_10X6_RGBA_UNORM = "ASTC_10X6_RGBA_UNORM",
133
+
134
+ /** The ASTC 10x6 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
135
+ ASTC_10X6_RGBA_SRGB = "ASTC_10X6_RGBA_SRGB",
136
+
137
+ /** The ASTC 10x8 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
138
+ ASTC_10X8_RGBA_UNORM = "ASTC_10X8_RGBA_UNORM",
139
+
140
+ /** The ASTC 10x8 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
141
+ ASTC_10X8_RGBA_SRGB = "ASTC_10X8_RGBA_SRGB",
142
+
143
+ /** The ASTC 10x10 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
144
+ ASTC_10X10_RGBA_UNORM = "ASTC_10X10_RGBA_UNORM",
145
+
146
+ /** The ASTC 10x10 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
147
+ ASTC_10X10_RGBA_SRGB = "ASTC_10X10_RGBA_SRGB",
148
+
149
+ /** The ASTC 12x10 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
150
+ ASTC_12X10_RGBA_UNORM = "ASTC_12X10_RGBA_UNORM",
151
+
152
+ /** The ASTC 12x10 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
153
+ ASTC_12X10_RGBA_SRGB = "ASTC_12X10_RGBA_SRGB",
154
+
155
+ /** The ASTC 12x12 compressed format with four 8-bit normalized unsigned integer components in RGBA order. */
156
+ ASTC_12X12_RGBA_UNORM = "ASTC_12X12_RGBA_UNORM",
157
+
158
+ /** The ASTC 12x12 compressed format with four 8-bit normalized unsigned integer components in RGBA order, sRGB-encoded color. */
159
+ ASTC_12X12_RGBA_SRGB = "ASTC_12X12_RGBA_SRGB",
160
+
161
+ /** The PVRTC1 compressed format at 4 bits per pixel with RGBA components. Requires WEBGL_compressed_texture_pvrtc. */
162
+ PVRTC_4BPPV1_RGBA = "PVRTC_4BPPV1_RGBA",
163
+
164
+ /** The PVRTC1 compressed format at 4 bits per pixel with RGB components. Requires WEBGL_compressed_texture_pvrtc. */
165
+ PVRTC_4BPPV1_RGB = "PVRTC_4BPPV1_RGB",
166
+
167
+ /** The PVRTC1 compressed format at 2 bits per pixel with RGBA components. Requires WEBGL_compressed_texture_pvrtc. */
168
+ PVRTC_2BPPV1_RGBA = "PVRTC_2BPPV1_RGBA",
169
+
170
+ /** The PVRTC1 compressed format at 2 bits per pixel with RGB components. Requires WEBGL_compressed_texture_pvrtc. */
171
+ PVRTC_2BPPV1_RGB = "PVRTC_2BPPV1_RGB",
58
172
  }
@@ -8,36 +8,199 @@ import {AlignUtilities} from "../../utilities/AlignUtilities.ts";
8
8
  export class TextureUtilities {
9
9
 
10
10
  private static readonly _compressedTextureFormats = [
11
- TextureFormat.ASTC_4X4_RGBA,
11
+
12
+ // ASTC
13
+ TextureFormat.ASTC_4X4_RGBA_UNORM,
14
+ TextureFormat.ASTC_4X4_RGBA_SRGB,
15
+ TextureFormat.ASTC_5X4_RGBA_UNORM,
16
+ TextureFormat.ASTC_5X4_RGBA_SRGB,
17
+ TextureFormat.ASTC_5X5_RGBA_UNORM,
18
+ TextureFormat.ASTC_5X5_RGBA_SRGB,
19
+ TextureFormat.ASTC_6X5_RGBA_UNORM,
20
+ TextureFormat.ASTC_6X5_RGBA_SRGB,
21
+ TextureFormat.ASTC_6X6_RGBA_UNORM,
22
+ TextureFormat.ASTC_6X6_RGBA_SRGB,
23
+ TextureFormat.ASTC_8X5_RGBA_UNORM,
24
+ TextureFormat.ASTC_8X5_RGBA_SRGB,
25
+ TextureFormat.ASTC_8X6_RGBA_UNORM,
26
+ TextureFormat.ASTC_8X6_RGBA_SRGB,
27
+ TextureFormat.ASTC_8X8_RGBA_UNORM,
28
+ TextureFormat.ASTC_8X8_RGBA_SRGB,
29
+ TextureFormat.ASTC_10X5_RGBA_UNORM,
30
+ TextureFormat.ASTC_10X5_RGBA_SRGB,
31
+ TextureFormat.ASTC_10X6_RGBA_UNORM,
32
+ TextureFormat.ASTC_10X6_RGBA_SRGB,
33
+ TextureFormat.ASTC_10X8_RGBA_UNORM,
34
+ TextureFormat.ASTC_10X8_RGBA_SRGB,
35
+ TextureFormat.ASTC_10X10_RGBA_UNORM,
36
+ TextureFormat.ASTC_10X10_RGBA_SRGB,
37
+ TextureFormat.ASTC_12X10_RGBA_UNORM,
38
+ TextureFormat.ASTC_12X10_RGBA_SRGB,
39
+ TextureFormat.ASTC_12X12_RGBA_UNORM,
40
+ TextureFormat.ASTC_12X12_RGBA_SRGB,
41
+
42
+ // PVRTC
43
+ TextureFormat.PVRTC_4BPPV1_RGBA,
44
+ TextureFormat.PVRTC_4BPPV1_RGB,
45
+ TextureFormat.PVRTC_2BPPV1_RGBA,
46
+ TextureFormat.PVRTC_2BPPV1_RGB,
47
+
12
48
  TextureFormat.BC3_RGBA_UNORM,
13
49
  TextureFormat.BC7_RGBA_UNORM,
14
- TextureFormat.ETC2_RGBA8_UNORM
50
+ TextureFormat.ETC2_RGBA8_UNORM,
51
+
52
+ // sRGB and RGB variants
53
+ TextureFormat.BC7_RGBA_SRGB,
54
+ TextureFormat.BC3_RGBA_SRGB,
55
+ TextureFormat.BC1_RGB_UNORM,
56
+ TextureFormat.BC1_RGB_SRGB,
57
+ TextureFormat.ETC2_RGBA8_SRGB,
58
+ TextureFormat.ETC2_RGB8_UNORM,
59
+ TextureFormat.ETC2_RGB8_SRGB,
15
60
  ];
16
- private static readonly _vkFormatTextureFormat: { [key: number]: number } = {
61
+
62
+ /** Linear compressed format → its sRGB variant. */
63
+ private static readonly _srgbVariant: { [key: string]: TextureFormat } = {
64
+ [TextureFormat.RGBA_8_UNORM]: TextureFormat.RGBA_8_UNORM_SRGB,
65
+ [TextureFormat.BC7_RGBA_UNORM]: TextureFormat.BC7_RGBA_SRGB,
66
+ [TextureFormat.BC3_RGBA_UNORM]: TextureFormat.BC3_RGBA_SRGB,
67
+ [TextureFormat.BC1_RGB_UNORM]: TextureFormat.BC1_RGB_SRGB,
68
+ [TextureFormat.ETC2_RGBA8_UNORM]: TextureFormat.ETC2_RGBA8_SRGB,
69
+ [TextureFormat.ETC2_RGB8_UNORM]: TextureFormat.ETC2_RGB8_SRGB,
70
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: TextureFormat.ASTC_4X4_RGBA_SRGB,
71
+ [TextureFormat.ASTC_5X4_RGBA_UNORM]: TextureFormat.ASTC_5X4_RGBA_SRGB,
72
+ [TextureFormat.ASTC_5X5_RGBA_UNORM]: TextureFormat.ASTC_5X5_RGBA_SRGB,
73
+ [TextureFormat.ASTC_6X5_RGBA_UNORM]: TextureFormat.ASTC_6X5_RGBA_SRGB,
74
+ [TextureFormat.ASTC_6X6_RGBA_UNORM]: TextureFormat.ASTC_6X6_RGBA_SRGB,
75
+ [TextureFormat.ASTC_8X5_RGBA_UNORM]: TextureFormat.ASTC_8X5_RGBA_SRGB,
76
+ [TextureFormat.ASTC_8X6_RGBA_UNORM]: TextureFormat.ASTC_8X6_RGBA_SRGB,
77
+ [TextureFormat.ASTC_8X8_RGBA_UNORM]: TextureFormat.ASTC_8X8_RGBA_SRGB,
78
+ [TextureFormat.ASTC_10X5_RGBA_UNORM]: TextureFormat.ASTC_10X5_RGBA_SRGB,
79
+ [TextureFormat.ASTC_10X6_RGBA_UNORM]: TextureFormat.ASTC_10X6_RGBA_SRGB,
80
+ [TextureFormat.ASTC_10X8_RGBA_UNORM]: TextureFormat.ASTC_10X8_RGBA_SRGB,
81
+ [TextureFormat.ASTC_10X10_RGBA_UNORM]: TextureFormat.ASTC_10X10_RGBA_SRGB,
82
+ [TextureFormat.ASTC_12X10_RGBA_UNORM]: TextureFormat.ASTC_12X10_RGBA_SRGB,
83
+ [TextureFormat.ASTC_12X12_RGBA_UNORM]: TextureFormat.ASTC_12X12_RGBA_SRGB,
84
+ };
85
+ private static readonly _vkFormatTextureFormat: { [key: number]: TextureFormat } = {
17
86
  [VkFormat.R8G8B8A8_UNORM]: TextureFormat.RGBA_8_UNORM,
18
87
  [VkFormat.R8G8B8A8_SRGB]: TextureFormat.RGBA_8_UNORM_SRGB,
19
88
  [VkFormat.BC7_UNORM_BLOCK]: TextureFormat.BC7_RGBA_UNORM,
20
- [VkFormat.ASTC_4X4_UNORM_BLOCK]: TextureFormat.ASTC_4X4_RGBA,
89
+
90
+ // ASTC
91
+ [VkFormat.ASTC_4X4_UNORM_BLOCK]: TextureFormat.ASTC_4X4_RGBA_UNORM,
92
+ [VkFormat.ASTC_4X4_SRGB_BLOCK]: TextureFormat.ASTC_4X4_RGBA_SRGB,
93
+ [VkFormat.ASTC_5X4_UNORM_BLOCK]: TextureFormat.ASTC_5X4_RGBA_UNORM,
94
+ [VkFormat.ASTC_5X4_SRGB_BLOCK]: TextureFormat.ASTC_5X4_RGBA_SRGB,
95
+ [VkFormat.ASTC_5X5_UNORM_BLOCK]: TextureFormat.ASTC_5X5_RGBA_UNORM,
96
+ [VkFormat.ASTC_5X5_SRGB_BLOCK]: TextureFormat.ASTC_5X5_RGBA_SRGB,
97
+ [VkFormat.ASTC_6X5_UNORM_BLOCK]: TextureFormat.ASTC_6X5_RGBA_UNORM,
98
+ [VkFormat.ASTC_6X5_SRGB_BLOCK]: TextureFormat.ASTC_6X5_RGBA_SRGB,
99
+ [VkFormat.ASTC_6X6_UNORM_BLOCK]: TextureFormat.ASTC_6X6_RGBA_UNORM,
100
+ [VkFormat.ASTC_6X6_SRGB_BLOCK]: TextureFormat.ASTC_6X6_RGBA_SRGB,
101
+ [VkFormat.ASTC_8X5_UNORM_BLOCK]: TextureFormat.ASTC_8X5_RGBA_UNORM,
102
+ [VkFormat.ASTC_8X5_SRGB_BLOCK]: TextureFormat.ASTC_8X5_RGBA_SRGB,
103
+ [VkFormat.ASTC_8X6_UNORM_BLOCK]: TextureFormat.ASTC_8X6_RGBA_UNORM,
104
+ [VkFormat.ASTC_8X6_SRGB_BLOCK]: TextureFormat.ASTC_8X6_RGBA_SRGB,
105
+ [VkFormat.ASTC_8X8_UNORM_BLOCK]: TextureFormat.ASTC_8X8_RGBA_UNORM,
106
+ [VkFormat.ASTC_8X8_SRGB_BLOCK]: TextureFormat.ASTC_8X8_RGBA_SRGB,
107
+ [VkFormat.ASTC_10X5_UNORM_BLOCK]: TextureFormat.ASTC_10X5_RGBA_UNORM,
108
+ [VkFormat.ASTC_10X5_SRGB_BLOCK]: TextureFormat.ASTC_10X5_RGBA_SRGB,
109
+ [VkFormat.ASTC_10X6_UNORM_BLOCK]: TextureFormat.ASTC_10X6_RGBA_UNORM,
110
+ [VkFormat.ASTC_10X6_SRGB_BLOCK]: TextureFormat.ASTC_10X6_RGBA_SRGB,
111
+ [VkFormat.ASTC_10X8_UNORM_BLOCK]: TextureFormat.ASTC_10X8_RGBA_UNORM,
112
+ [VkFormat.ASTC_10X8_SRGB_BLOCK]: TextureFormat.ASTC_10X8_RGBA_SRGB,
113
+ [VkFormat.ASTC_10X10_UNORM_BLOCK]: TextureFormat.ASTC_10X10_RGBA_UNORM,
114
+ [VkFormat.ASTC_10X10_SRGB_BLOCK]: TextureFormat.ASTC_10X10_RGBA_SRGB,
115
+ [VkFormat.ASTC_12X10_UNORM_BLOCK]: TextureFormat.ASTC_12X10_RGBA_UNORM,
116
+ [VkFormat.ASTC_12X10_SRGB_BLOCK]: TextureFormat.ASTC_12X10_RGBA_SRGB,
117
+ [VkFormat.ASTC_12X12_UNORM_BLOCK]: TextureFormat.ASTC_12X12_RGBA_UNORM,
118
+ [VkFormat.ASTC_12X12_SRGB_BLOCK]: TextureFormat.ASTC_12X12_RGBA_SRGB,
119
+
21
120
  [VkFormat.BC3_UNORM_BLOCK]: TextureFormat.BC3_RGBA_UNORM,
22
121
  [VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK]: TextureFormat.ETC2_RGBA8_UNORM,
122
+ [VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG]: TextureFormat.PVRTC_4BPPV1_RGBA,
123
+
124
+ // sRGB and RGB variants
125
+ [VkFormat.BC7_SRGB_BLOCK]: TextureFormat.BC7_RGBA_SRGB,
126
+ [VkFormat.BC3_SRGB_BLOCK]: TextureFormat.BC3_RGBA_SRGB,
127
+ [VkFormat.BC1_RGB_UNORM_BLOCK]: TextureFormat.BC1_RGB_UNORM,
128
+ [VkFormat.BC1_RGB_SRGB_BLOCK]: TextureFormat.BC1_RGB_SRGB,
129
+ [VkFormat.ETC2_R8G8B8A8_SRGB_BLOCK]: TextureFormat.ETC2_RGBA8_SRGB,
130
+ [VkFormat.ETC2_R8G8B8_UNORM_BLOCK]: TextureFormat.ETC2_RGB8_UNORM,
131
+ [VkFormat.ETC2_R8G8B8_SRGB_BLOCK]: TextureFormat.ETC2_RGB8_SRGB,
132
+
23
133
  }
24
134
 
25
- private static readonly _textureFormatVkFormat: { [key: number]: number } = {
135
+ private static readonly _textureFormatVkFormat: { [key: string]: number } = {
26
136
  [TextureFormat.RGBA_8_UNORM]: VkFormat.R8G8B8A8_UNORM,
27
137
  [TextureFormat.RGBA_8_UNORM_SRGB]: VkFormat.R8G8B8A8_SRGB,
28
138
  [TextureFormat.DEPTH_24_STENCIL_8]: VkFormat.D24_UNORM_S8_UINT,
29
139
  [TextureFormat.BC3_RGBA_UNORM]: VkFormat.BC3_UNORM_BLOCK,
30
140
  [TextureFormat.BC7_RGBA_UNORM]: VkFormat.BC7_UNORM_BLOCK,
31
- [TextureFormat.ASTC_4X4_RGBA]: VkFormat.ASTC_4X4_UNORM_BLOCK,
141
+
142
+ // ASTC
143
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: VkFormat.ASTC_4X4_UNORM_BLOCK,
144
+ [TextureFormat.ASTC_4X4_RGBA_SRGB]: VkFormat.ASTC_4X4_SRGB_BLOCK,
145
+ [TextureFormat.ASTC_5X4_RGBA_UNORM]: VkFormat.ASTC_5X4_UNORM_BLOCK,
146
+ [TextureFormat.ASTC_5X4_RGBA_SRGB]: VkFormat.ASTC_5X4_SRGB_BLOCK,
147
+ [TextureFormat.ASTC_5X5_RGBA_UNORM]: VkFormat.ASTC_5X5_UNORM_BLOCK,
148
+ [TextureFormat.ASTC_5X5_RGBA_SRGB]: VkFormat.ASTC_5X5_SRGB_BLOCK,
149
+ [TextureFormat.ASTC_6X5_RGBA_UNORM]: VkFormat.ASTC_6X5_UNORM_BLOCK,
150
+ [TextureFormat.ASTC_6X5_RGBA_SRGB]: VkFormat.ASTC_6X5_SRGB_BLOCK,
151
+ [TextureFormat.ASTC_6X6_RGBA_UNORM]: VkFormat.ASTC_6X6_UNORM_BLOCK,
152
+ [TextureFormat.ASTC_6X6_RGBA_SRGB]: VkFormat.ASTC_6X6_SRGB_BLOCK,
153
+ [TextureFormat.ASTC_8X5_RGBA_UNORM]: VkFormat.ASTC_8X5_UNORM_BLOCK,
154
+ [TextureFormat.ASTC_8X5_RGBA_SRGB]: VkFormat.ASTC_8X5_SRGB_BLOCK,
155
+ [TextureFormat.ASTC_8X6_RGBA_UNORM]: VkFormat.ASTC_8X6_UNORM_BLOCK,
156
+ [TextureFormat.ASTC_8X6_RGBA_SRGB]: VkFormat.ASTC_8X6_SRGB_BLOCK,
157
+ [TextureFormat.ASTC_8X8_RGBA_UNORM]: VkFormat.ASTC_8X8_UNORM_BLOCK,
158
+ [TextureFormat.ASTC_8X8_RGBA_SRGB]: VkFormat.ASTC_8X8_SRGB_BLOCK,
159
+ [TextureFormat.ASTC_10X5_RGBA_UNORM]: VkFormat.ASTC_10X5_UNORM_BLOCK,
160
+ [TextureFormat.ASTC_10X5_RGBA_SRGB]: VkFormat.ASTC_10X5_SRGB_BLOCK,
161
+ [TextureFormat.ASTC_10X6_RGBA_UNORM]: VkFormat.ASTC_10X6_UNORM_BLOCK,
162
+ [TextureFormat.ASTC_10X6_RGBA_SRGB]: VkFormat.ASTC_10X6_SRGB_BLOCK,
163
+ [TextureFormat.ASTC_10X8_RGBA_UNORM]: VkFormat.ASTC_10X8_UNORM_BLOCK,
164
+ [TextureFormat.ASTC_10X8_RGBA_SRGB]: VkFormat.ASTC_10X8_SRGB_BLOCK,
165
+ [TextureFormat.ASTC_10X10_RGBA_UNORM]: VkFormat.ASTC_10X10_UNORM_BLOCK,
166
+ [TextureFormat.ASTC_10X10_RGBA_SRGB]: VkFormat.ASTC_10X10_SRGB_BLOCK,
167
+ [TextureFormat.ASTC_12X10_RGBA_UNORM]: VkFormat.ASTC_12X10_UNORM_BLOCK,
168
+ [TextureFormat.ASTC_12X10_RGBA_SRGB]: VkFormat.ASTC_12X10_SRGB_BLOCK,
169
+ [TextureFormat.ASTC_12X12_RGBA_UNORM]: VkFormat.ASTC_12X12_UNORM_BLOCK,
170
+ [TextureFormat.ASTC_12X12_RGBA_SRGB]: VkFormat.ASTC_12X12_SRGB_BLOCK,
171
+
172
+ // PVRTC
173
+ [TextureFormat.PVRTC_4BPPV1_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
174
+ [TextureFormat.PVRTC_4BPPV1_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
175
+ [TextureFormat.PVRTC_2BPPV1_RGBA]: VkFormat.PVRTC1_2BPP_UNORM_BLOCK_IMG,
176
+ [TextureFormat.PVRTC_2BPPV1_RGB]: VkFormat.PVRTC1_2BPP_UNORM_BLOCK_IMG,
177
+
178
+
32
179
  [TextureFormat.ETC2_RGBA8_UNORM] : VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK,
180
+
181
+ // sRGB and RGB variants
182
+ [TextureFormat.BC7_RGBA_SRGB]: VkFormat.BC7_SRGB_BLOCK,
183
+ [TextureFormat.BC3_RGBA_SRGB]: VkFormat.BC3_SRGB_BLOCK,
184
+ [TextureFormat.BC1_RGB_UNORM]: VkFormat.BC1_RGB_UNORM_BLOCK,
185
+ [TextureFormat.BC1_RGB_SRGB]: VkFormat.BC1_RGB_SRGB_BLOCK,
186
+ [TextureFormat.ETC2_RGBA8_SRGB]: VkFormat.ETC2_R8G8B8A8_SRGB_BLOCK,
187
+ [TextureFormat.ETC2_RGB8_UNORM]: VkFormat.ETC2_R8G8B8_UNORM_BLOCK,
188
+ [TextureFormat.ETC2_RGB8_SRGB]: VkFormat.ETC2_R8G8B8_SRGB_BLOCK,
33
189
  };
34
190
 
35
- private static readonly _mapTextureFormatKtxTranscodeFormat: { [key: number]: number } = {
191
+ private static readonly _mapTextureFormatKtxTranscodeFormat: { [key: string]: number } = {
36
192
  [TextureFormat.RGBA_8_UNORM]: KtxTranscodeFormat.RGBA32,
37
- [TextureFormat.ASTC_4X4_RGBA]: KtxTranscodeFormat.ASTC_4X4_RGBA,
193
+ [TextureFormat.ASTC_4X4_RGBA_UNORM]: KtxTranscodeFormat.ASTC_4X4_RGBA,
38
194
  [TextureFormat.BC3_RGBA_UNORM]: KtxTranscodeFormat.BC3_RGBA,
39
195
  [TextureFormat.BC7_RGBA_UNORM]: KtxTranscodeFormat.BC7_RGBA,
40
196
  [TextureFormat.ETC2_RGBA8_UNORM]: KtxTranscodeFormat.ETC2_RGBA,
197
+ [TextureFormat.PVRTC_4BPPV1_RGBA] : KtxTranscodeFormat.PVRTC1_4_RGBA,
198
+ // Basis transcodes to the same blocks for sRGB; only the GPU format differs.
199
+ [TextureFormat.RGBA_8_UNORM_SRGB]: KtxTranscodeFormat.RGBA32,
200
+ [TextureFormat.ASTC_4X4_RGBA_SRGB]: KtxTranscodeFormat.ASTC_4X4_RGBA,
201
+ [TextureFormat.BC3_RGBA_SRGB]: KtxTranscodeFormat.BC3_RGBA,
202
+ [TextureFormat.BC7_RGBA_SRGB]: KtxTranscodeFormat.BC7_RGBA,
203
+ [TextureFormat.ETC2_RGBA8_SRGB]: KtxTranscodeFormat.ETC2_RGBA,
41
204
  };
42
205
 
43
206
  private static readonly _mapKtxTranscodeFormatVkFormat: { [key: number]: number } = {
@@ -49,18 +212,70 @@ export class TextureUtilities {
49
212
  [KtxTranscodeFormat.KTX_TTF_BC5_RG]: VkFormat.BC5_UNORM_BLOCK,
50
213
  [KtxTranscodeFormat.BC7_RGBA]: VkFormat.BC7_UNORM_BLOCK,
51
214
  [KtxTranscodeFormat.KTX_TTF_PVRTC1_4_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
52
- [KtxTranscodeFormat.KTX_TTF_PVRTC1_4_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
215
+ [KtxTranscodeFormat.PVRTC1_4_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
53
216
  [KtxTranscodeFormat.ASTC_4X4_RGBA]: VkFormat.ASTC_4X4_UNORM_BLOCK,
54
217
  [KtxTranscodeFormat.RGBA32]: VkFormat.R8G8B8A8_UNORM,
55
218
  [KtxTranscodeFormat.KTX_TTF_RGB565]: VkFormat.R5G6B5_UNORM_PACK16,
56
219
  [KtxTranscodeFormat.KTX_TTF_BGR565]: VkFormat.B5G6R5_UNORM_PACK16,
57
220
  [KtxTranscodeFormat.KTX_TTF_RGBA4444]: VkFormat.R4G4B4A4_UNORM_PACK16,
58
221
  [KtxTranscodeFormat.KTX_TTF_PVRTC2_4_RGB]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
59
- [KtxTranscodeFormat.KTX_TTF_PVRTC2_4_RGBA]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
222
+ [KtxTranscodeFormat.PVRTC2_4_RGBA]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
60
223
  [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_R11]: VkFormat.EAC_R11_UNORM_BLOCK,
61
224
  [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_RG11]: VkFormat.EAC_R11G11_UNORM_BLOCK,
62
225
  };
63
226
 
227
+ /**
228
+ * Whether the format stores sRGB-encoded colour (sampled as linear by the GPU).
229
+ * @param format The texture format.
230
+ */
231
+ public static isSrgbFormat(format: TextureFormat): boolean {
232
+ return format.endsWith("_SRGB");
233
+ }
234
+
235
+ /**
236
+ * Gets the sRGB variant of a linear format, or the format itself if it has none or is already sRGB.
237
+ * @param format The texture format.
238
+ */
239
+ public static toSrgbFormat(format: TextureFormat): TextureFormat {
240
+ return this._srgbVariant[format] ?? format;
241
+ }
242
+
243
+ /**
244
+ * Gets the linear variant of an sRGB format, or the format itself.
245
+ * @param format The texture format.
246
+ */
247
+ public static toLinearFormat(format: TextureFormat): TextureFormat {
248
+ for (const linear in this._srgbVariant) {
249
+ if (this._srgbVariant[linear] === format) return linear as TextureFormat;
250
+ }
251
+ return format;
252
+ }
253
+
254
+ /**
255
+ * Gets the block size (width, height) of a format: 1x1 for uncompressed, 4x4 for BC/ETC2, and the ASTC block.
256
+ * Returns null for formats it does not know.
257
+ * @param format The texture format.
258
+ */
259
+ public static getBlockSize(format: TextureFormat): [number, number] | null {
260
+ if (!this.isCompressedTextureFormat(format)) {
261
+ return [1, 1];
262
+ }
263
+ const astc = /^ASTC_(\d+)X(\d+)_/.exec(format);
264
+ if (astc) {
265
+ return [Number(astc[1]), Number(astc[2])];
266
+ }
267
+ if (format.startsWith("BC") || format.startsWith("ETC2")) {
268
+ return [4, 4];
269
+ }
270
+ if (format.startsWith("PVRTC_2BPP")) {
271
+ return [8, 4];
272
+ }
273
+ if (format.startsWith("PVRTC_4BPP")) {
274
+ return [4, 4];
275
+ }
276
+ return null;
277
+ }
278
+
64
279
  /**
65
280
  * Checks if the given texture format is a compressed texture format.
66
281
  * @param format - The texture format to check.