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
@@ -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,6 +34,10 @@ 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
 
30
43
  /** @inheritDoc */
@@ -55,6 +68,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
55
68
  this._createResources();
56
69
  this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float2Layout()];
57
70
  super.initialize();
71
+
72
+ this._colorConversionUniformLocation = this._gl.getUniformLocation(this._program, "u_colorConversion")!;
58
73
  }
59
74
 
60
75
  private _createResources(): void {
@@ -93,6 +108,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
93
108
  this._gl.bindTexture(this._gl.TEXTURE_2D, this._mainRenderTarget.glTexture);
94
109
  this._gl.bindSampler(0, this._defaultTextureSampler.glSampler);
95
110
 
111
+ this._gl.uniform1i(this._colorConversionUniformLocation, this._colorSpaceValue)
112
+
96
113
  this._gl.drawElements(this._gl.TRIANGLES, this._indexBuffer.indicesCount, this._gl.UNSIGNED_SHORT, 0);
97
114
  }
98
115
 
@@ -1,4 +1,4 @@
1
- import { vec2 } from "gl-matrix";
1
+ import {vec2} from "gl-matrix";
2
2
  import {type IGraphicsDevice, type ISwapChain, TextureFormat} from "../../api/index.ts";
3
3
  import type {WebGlGraphicsDevice} from "../WebGlGraphicsDevice.ts";
4
4
 
@@ -16,8 +16,9 @@ export class WebGlSwapChain implements ISwapChain {
16
16
  * The WebGLSwapChain constructor.
17
17
  * @param canvas The HTML canvas element that the swap chain will use for rendering.
18
18
  * @param graphicsDevice The graphics device.
19
+ * @param srgb Prefer use of
19
20
  */
20
- public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice) {
21
+ public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice, srgb = true) {
21
22
  this._canvas = canvas;
22
23
  this._graphicsDevice = graphicsDevice as WebGlGraphicsDevice;
23
24
  this._backBufferSize = vec2.fromValues(this._canvas.width, this._canvas.height);
@@ -25,13 +26,13 @@ export class WebGlSwapChain implements ISwapChain {
25
26
  this._backBufferSize[0] = this._canvas.width;
26
27
  this._backBufferSize[1] = this._canvas.height;
27
28
  });
28
- }
29
29
 
30
+ // Nothing else to do. Typically, framebuffer should be srgb, but that is already handled through canvas.
31
+ this.textureFormat = srgb ? TextureFormat.RGBA_8_UNORM_SRGB : TextureFormat.RGBA_8_UNORM;
32
+ }
30
33
 
31
34
  /** @inheritdoc */
32
- public get textureFormat(): TextureFormat {
33
- return TextureFormat.RGBA_8_UNORM;
34
- }
35
+ public readonly textureFormat: TextureFormat;
35
36
 
36
37
  /** @inheritdoc */
37
38
  public get backBufferSize(): vec2 {
@@ -9,7 +9,7 @@ import {
9
9
  TextureUtilities
10
10
  } from "../../api/index.ts"
11
11
  import {WebGlTexture2D} from "./WebGlTexture2D.ts";
12
- import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, TextureFormatInfo, VkFormat} from "ris-ktx2";
12
+ import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, VkFormat} from "ris-ktx2";
13
13
  import {vec2} from "gl-matrix";
14
14
 
15
15
  export class WebGlTextureFactory implements ITextureFactory {
@@ -31,13 +31,13 @@ export class WebGlTextureFactory implements ITextureFactory {
31
31
  let transcodeFormat = KtxTranscodeFormat.NO_SELECTION;
32
32
  let textureFormat = descriptor.textureFormat;
33
33
  const gpuFeatures = this._framework.graphicsDevice.features;
34
- let texFormatInfo: TextureFormatInfo | null = null;
35
34
 
36
35
  if (ktxTexture.needsTranscoding && vkFormat == VkFormat.UNDEFINED)
37
36
  {
38
37
  // If descriptor format is UNDEFINED, we will use format according to the GPU features.
39
38
  if(descriptor.textureFormat == TextureFormat.UNDEFINED)
40
39
  {
40
+ // BC7 needs BPTC (supportsTextureCompressionBC), BC3 needs S3TC.
41
41
  if(gpuFeatures.supportsTextureCompressionBC)
42
42
  {
43
43
  transcodeFormat = KtxTranscodeFormat.BC7_RGBA;
@@ -46,7 +46,7 @@ export class WebGlTextureFactory implements ITextureFactory {
46
46
  else if(gpuFeatures.supportsTextureCompressionASTC)
47
47
  {
48
48
  transcodeFormat = KtxTranscodeFormat.ASTC_4X4_RGBA;
49
- textureFormat = TextureFormat.ASTC_4X4_RGBA
49
+ textureFormat = TextureFormat.ASTC_4X4_RGBA_UNORM
50
50
  }
51
51
  else if(gpuFeatures.supportsTextureCompressionS3TC)
52
52
  {
@@ -58,6 +58,16 @@ export class WebGlTextureFactory implements ITextureFactory {
58
58
  transcodeFormat = KtxTranscodeFormat.ETC2_RGBA;
59
59
  textureFormat = TextureFormat.ETC2_RGBA8_UNORM;
60
60
  }
61
+ else if(gpuFeatures.supportsTextureCompressionPVRTC)
62
+ {
63
+ transcodeFormat = KtxTranscodeFormat.PVRTC1_4_RGBA;
64
+ textureFormat = TextureFormat.PVRTC_4BPPV1_RGBA;
65
+ }
66
+ else
67
+ {
68
+ transcodeFormat = KtxTranscodeFormat.RGBA32;
69
+ textureFormat = TextureFormat.RGBA_8_UNORM;
70
+ }
61
71
  }
62
72
  else
63
73
  {
@@ -65,12 +75,23 @@ export class WebGlTextureFactory implements ITextureFactory {
65
75
  }
66
76
 
67
77
  ktxTexture.transcodeBasis(transcodeFormat, KtxTranscodeFlags.HIGH_QUALITY);
68
- texFormatInfo = ktxTexture.getTextureFormatInfo(TextureUtilities.convertKtxTranscodeFormatToVkFormat(transcodeFormat));
78
+
79
+ // After transcoding, libktx reports the sRGB vkFormat when the file's DFD transfer function is sRGB.
80
+ if (descriptor.textureFormat == TextureFormat.UNDEFINED && WebGlTextureFactory._isSrgbVkFormat(ktxTexture.vkFormat))
81
+ {
82
+ textureFormat = TextureUtilities.toSrgbFormat(textureFormat);
83
+ }
69
84
  }
70
85
  else {
71
- // No transcoding path, but still get info about the texture format.
86
+ // No transcoding path, the vkFormat already says linear or sRGB.
72
87
  textureFormat = TextureUtilities.convertVkFormatToTextureFormat(vkFormat);
73
- texFormatInfo = ktxTexture.getTextureFormatInfo(vkFormat);
88
+ }
89
+
90
+ textureFormat = this._ensureSrgbSupported(textureFormat, ktxTexture.filePath);
91
+
92
+ const blockSize = TextureUtilities.getBlockSize(textureFormat);
93
+ if (!blockSize) {
94
+ throw new Error(`Unknown block size for texture format ${textureFormat}.`);
74
95
  }
75
96
 
76
97
  const data: Uint8Array[] = [];
@@ -85,13 +106,34 @@ export class WebGlTextureFactory implements ITextureFactory {
85
106
  textureDescriptor.data = data;
86
107
  textureDescriptor.textureFormat = textureFormat;
87
108
  textureDescriptor.generateMipmaps = descriptor.generateMipmaps;
88
- textureDescriptor.blockSize = vec2.fromValues(texFormatInfo.blockWidth, texFormatInfo.blockHeight);
109
+ textureDescriptor.blockSize = vec2.fromValues(blockSize[0], blockSize[1]);
89
110
 
90
111
  const texture = new WebGlTexture2D(this._framework, textureDescriptor);
91
112
  texture.initialize();
92
113
  return texture;
93
114
  }
94
115
 
116
+ /** Whether the Vulkan format is an sRGB format. */
117
+ private static _isSrgbVkFormat(vkFormat: VkFormat): boolean {
118
+ const name = (VkFormat as unknown as Record<number, string>)[vkFormat];
119
+ return typeof name === "string" && name.includes("_SRGB");
120
+ }
121
+
122
+ /**
123
+ * Falls back to the linear variant (with a warning) when the GPU cannot sample the sRGB format.
124
+ * Only S3TC sRGB (BC1/BC3) has its own WebGL extension; BC7, ETC2 and ASTC sRGB ship with their base extension.
125
+ */
126
+ private _ensureSrgbSupported(textureFormat: TextureFormat, source?: string): TextureFormat {
127
+ const isS3tcSrgb = textureFormat === TextureFormat.BC3_RGBA_SRGB || textureFormat === TextureFormat.BC1_RGB_SRGB;
128
+ if (isS3tcSrgb && !this._framework.graphicsDevice.features.supportsTextureCompressionS3TCSrgb) {
129
+ const linear = TextureUtilities.toLinearFormat(textureFormat);
130
+ console.warn(`sRGB S3TC is not supported (WEBGL_compressed_texture_s3tc_srgb missing); ` +
131
+ `loading ${source ?? "texture"} as ${linear}. Colours will look washed out.`);
132
+ return linear;
133
+ }
134
+ return textureFormat;
135
+ }
136
+
95
137
  /** @inheritdoc */
96
138
  public create(
97
139
  width: number, height: number,
@@ -0,0 +1,136 @@
1
+ /**
2
+ * WebGL extension constants that WebGL2RenderingContext does not expose.
3
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
4
+ */
5
+ export class WebGlConstants {
6
+
7
+ /** BC1 RGB */
8
+ public static readonly GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
9
+
10
+ /** BC1 RGB sRGB (WEBGL_compressed_texture_s3tc_srgb) */
11
+ public static readonly GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
12
+
13
+ /** BC3 sRGB (WEBGL_compressed_texture_s3tc_srgb) */
14
+ public static readonly GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
15
+
16
+ /** BC7 sRGB (EXT_texture_compression_bptc) */
17
+ public static readonly GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D;
18
+
19
+ /** ETC2 RGB8 */
20
+ public static readonly GL_COMPRESSED_RGB8_ETC2 = 0x9274;
21
+
22
+ /** ETC2 RGB8 sRGB */
23
+ public static readonly GL_COMPRESSED_SRGB8_ETC2 = 0x9275;
24
+
25
+ /** ETC2 RGBA8 sRGB */
26
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
27
+
28
+ /** BC3 */
29
+ public static readonly GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
30
+
31
+ /** BC7 */
32
+ public static readonly GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
33
+
34
+ /** ETC2 */
35
+ public static readonly GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
36
+
37
+ // ASTC (WEBGL_compressed_texture_astc).
38
+
39
+ /** ASTC 4x4 */
40
+ public static readonly GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
41
+
42
+ /** ASTC 4x4 sRGB */
43
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
44
+
45
+ /** ASTC 5x4 */
46
+ public static readonly GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
47
+
48
+ /** ASTC 5x4 sRGB */
49
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
50
+
51
+ /** ASTC 5x5 */
52
+ public static readonly GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
53
+
54
+ /** ASTC 5x5 sRGB */
55
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
56
+
57
+ /** ASTC 6x5 */
58
+ public static readonly GL_COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
59
+
60
+ /** ASTC 6x5 sRGB */
61
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
62
+
63
+ /** ASTC 6x6 */
64
+ public static readonly GL_COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
65
+
66
+ /** ASTC 6x6 sRGB */
67
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
68
+
69
+ /** ASTC 8x5 */
70
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
71
+
72
+ /** ASTC 8x5 sRGB */
73
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
74
+
75
+ /** ASTC 8x6 */
76
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
77
+
78
+ /** ASTC 8x6 sRGB */
79
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
80
+
81
+ /** ASTC 8x8 */
82
+ public static readonly GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
83
+
84
+ /** ASTC 8x8 sRGB */
85
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
86
+
87
+ /** ASTC 10x5 */
88
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
89
+
90
+ /** ASTC 10x5 sRGB */
91
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
92
+
93
+ /** ASTC 10x6 */
94
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
95
+
96
+ /** ASTC 10x6 sRGB */
97
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
98
+
99
+ /** ASTC 10x8 */
100
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
101
+
102
+ /** ASTC 10x8 sRGB */
103
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
104
+
105
+ /** ASTC 10x10 */
106
+ public static readonly GL_COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
107
+
108
+ /** ASTC 10x10 sRGB */
109
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
110
+
111
+ /** ASTC 12x10 */
112
+ public static readonly GL_COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
113
+
114
+ /** ASTC 12x10 sRGB */
115
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
116
+
117
+ /** ASTC 12x12 */
118
+ public static readonly GL_COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
119
+
120
+ /** ASTC 12x12 sRGB */
121
+ public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
122
+
123
+ // PVRTC (WEBGL_compressed_texture_pvrtc).
124
+
125
+ /** PVRTC 4 bits per pixel, RGB */
126
+ public static readonly GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
127
+
128
+ /** PVRTC 2 bits per pixel, RGB */
129
+ public static readonly GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
130
+
131
+ /** PVRTC 4 bits per pixel, RGBA */
132
+ public static readonly GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
133
+
134
+ /** PVRTC 2 bits per pixel, RGBA */
135
+ public static readonly GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
136
+ }
@@ -1,3 +1,4 @@
1
+ import {WebGlConstants} from "./WebGlConstants.ts";
1
2
  import {Culling} from "../../api/rendering/enums.ts";
2
3
  import {BlendFactor, BlendOperation} from "../../core/rendering/blending/enums";
3
4
  import {VertexFormat} from "../../api/geometry/VertexFormat.ts";
@@ -14,20 +15,6 @@ import {
14
15
 
15
16
  export class WebGlConverter {
16
17
 
17
- // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
18
-
19
- /** BC3 */
20
- private static GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
21
-
22
- /** BC7 */
23
- private static GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
24
-
25
-
26
- /** ETC2 */
27
- private static GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
28
-
29
- private static GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
30
-
31
18
  /**
32
19
  * Converts PrimitiveTopology to WebGL enum.
33
20
  * @param topology The PrimitiveTopology.
@@ -65,7 +52,8 @@ export class WebGlConverter {
65
52
  return WebGL2RenderingContext.BACK;
66
53
  case CullMode.FRONT:
67
54
  return WebGL2RenderingContext.FRONT;
68
- default: throw new Error("Method not implemented.");
55
+ default:
56
+ throw new Error("Method not implemented.");
69
57
  }
70
58
 
71
59
  }
@@ -95,13 +83,13 @@ export class WebGlConverter {
95
83
 
96
84
  let bufferUsage: number = WebGL2RenderingContext.STATIC_DRAW;
97
85
 
98
- if((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST)
99
- {
86
+ if ((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST) {
100
87
  bufferUsage = WebGL2RenderingContext.DYNAMIC_DRAW;
101
88
  }
102
89
 
103
90
  return bufferUsage;
104
91
  }
92
+
105
93
  /**
106
94
  * Converts BlendOperation to WebGL enum.
107
95
  * @param gl The WebGL2RenderingContext.
@@ -195,13 +183,94 @@ export class WebGlConverter {
195
183
  case TextureFormat.DEPTH_24_STENCIL_8:
196
184
  return gl.DEPTH24_STENCIL8;
197
185
  case TextureFormat.BC3_RGBA_UNORM:
198
- return WebGlConverter.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
186
+ return WebGlConstants.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
199
187
  case TextureFormat.ETC2_RGBA8_UNORM:
200
- return WebGlConverter.GL_COMPRESSED_RGBA8_ETC2_EAC;
188
+ return WebGlConstants.GL_COMPRESSED_RGBA8_ETC2_EAC;
201
189
  case TextureFormat.BC7_RGBA_UNORM:
202
- return WebGlConverter.GL_COMPRESSED_RGBA_BPTC_UNORM;
203
- case TextureFormat.ASTC_4X4_RGBA:
204
- return WebGlConverter.GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
190
+ return WebGlConstants.GL_COMPRESSED_RGBA_BPTC_UNORM;
191
+ case TextureFormat.BC7_RGBA_SRGB:
192
+ return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
193
+ case TextureFormat.BC3_RGBA_SRGB:
194
+ return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
195
+ case TextureFormat.BC1_RGB_UNORM:
196
+ return WebGlConstants.GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
197
+ case TextureFormat.BC1_RGB_SRGB:
198
+ return WebGlConstants.GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
199
+ case TextureFormat.ETC2_RGBA8_SRGB:
200
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
201
+ case TextureFormat.ETC2_RGB8_UNORM:
202
+ return WebGlConstants.GL_COMPRESSED_RGB8_ETC2;
203
+ case TextureFormat.ETC2_RGB8_SRGB:
204
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ETC2;
205
+
206
+ // ASTC
207
+ case TextureFormat.ASTC_4X4_RGBA_UNORM:
208
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
209
+ case TextureFormat.ASTC_4X4_RGBA_SRGB:
210
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
211
+ case TextureFormat.ASTC_5X4_RGBA_UNORM:
212
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
213
+ case TextureFormat.ASTC_5X4_RGBA_SRGB:
214
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
215
+ case TextureFormat.ASTC_5X5_RGBA_UNORM:
216
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
217
+ case TextureFormat.ASTC_5X5_RGBA_SRGB:
218
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
219
+ case TextureFormat.ASTC_6X5_RGBA_UNORM:
220
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
221
+ case TextureFormat.ASTC_6X5_RGBA_SRGB:
222
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
223
+ case TextureFormat.ASTC_6X6_RGBA_UNORM:
224
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
225
+ case TextureFormat.ASTC_6X6_RGBA_SRGB:
226
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
227
+ case TextureFormat.ASTC_8X5_RGBA_UNORM:
228
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
229
+ case TextureFormat.ASTC_8X5_RGBA_SRGB:
230
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
231
+ case TextureFormat.ASTC_8X6_RGBA_UNORM:
232
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
233
+ case TextureFormat.ASTC_8X6_RGBA_SRGB:
234
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
235
+ case TextureFormat.ASTC_8X8_RGBA_UNORM:
236
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
237
+ case TextureFormat.ASTC_8X8_RGBA_SRGB:
238
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
239
+ case TextureFormat.ASTC_10X5_RGBA_UNORM:
240
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
241
+ case TextureFormat.ASTC_10X5_RGBA_SRGB:
242
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
243
+ case TextureFormat.ASTC_10X6_RGBA_UNORM:
244
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
245
+ case TextureFormat.ASTC_10X6_RGBA_SRGB:
246
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
247
+ case TextureFormat.ASTC_10X8_RGBA_UNORM:
248
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
249
+ case TextureFormat.ASTC_10X8_RGBA_SRGB:
250
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
251
+ case TextureFormat.ASTC_10X10_RGBA_UNORM:
252
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
253
+ case TextureFormat.ASTC_10X10_RGBA_SRGB:
254
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
255
+ case TextureFormat.ASTC_12X10_RGBA_UNORM:
256
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
257
+ case TextureFormat.ASTC_12X10_RGBA_SRGB:
258
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
259
+ case TextureFormat.ASTC_12X12_RGBA_UNORM:
260
+ return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
261
+ case TextureFormat.ASTC_12X12_RGBA_SRGB:
262
+ return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
263
+
264
+ // PVRTC
265
+ case TextureFormat.PVRTC_4BPPV1_RGBA:
266
+ return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
267
+ case TextureFormat.PVRTC_4BPPV1_RGB:
268
+ return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
269
+
270
+ case TextureFormat.PVRTC_2BPPV1_RGBA:
271
+ return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
272
+ case TextureFormat.PVRTC_2BPPV1_RGB:
273
+ return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
205
274
 
206
275
  default:
207
276
  throw new Error("NotImplementedException");
@@ -0,0 +1,15 @@
1
+ export class WebGlErrorUtilities {
2
+
3
+ private readonly _map: Record<number, string> = {
4
+ 1282: "INVALID_OPERATION"
5
+ }
6
+
7
+ /**
8
+ * Maps the WebGL2 error code to string.
9
+ * @param error The error code.
10
+ * @return The string of error code.
11
+ */
12
+ public errorToStr(error: number) : string {
13
+ return this._map[error] ?? error.toString();
14
+ }
15
+ }
@@ -1,6 +1,7 @@
1
1
  import {WebGlConverter} from "./WebGlConverter.ts";
2
2
  import {AlignUtilities, TextureFormat} from "../../api/index.ts";
3
3
  import {vec2} from "gl-matrix";
4
+ import {WebGlUtilities} from "./WebGlUtilities.ts";
4
5
 
5
6
  /**
6
7
  * The utilities for working with WebGL textures.
@@ -120,8 +121,8 @@ export class WebGlTextureUtilities {
120
121
  gl.bindTexture(gl.TEXTURE_2D, texture);
121
122
 
122
123
  const internalFormat = WebGlConverter.convertInternalFormat(gl, textureFormat);
123
-
124
124
  const useTexStorage = baseWidth % blockSize[0] == 0 && baseHeight % blockSize[1] == 0;
125
+
125
126
  if (useTexStorage) {
126
127
  gl.texStorage2D(gl.TEXTURE_2D, mipLevels, internalFormat, baseWidth, baseHeight);
127
128
  }
@@ -163,7 +164,9 @@ export class WebGlTextureUtilities {
163
164
 
164
165
  const error = gl.getError();
165
166
  if (error != gl.NO_ERROR) {
166
- throw new Error("WebGlTextureUtilities error " + error.toString());
167
+ const errorStr ="WebGlTextureUtilities error " + WebGlUtilities.error.errorToStr(error);
168
+ console.error(errorStr);
169
+ throw new Error(errorStr);
167
170
  }
168
171
 
169
172
  return texture;
@@ -8,6 +8,7 @@ import { WebGLRenderbufferUtilities } from "./webgl-renderbuffer-utilities";
8
8
  import { WebGlSamplerUtilities } from "./WebGlSamplerUtilities.ts";
9
9
  import { WebGlShaderUtilities } from "./WebGlShaderUtilities.ts";
10
10
  import { WebGlTextureUtilities } from "./WebGlTextureUtilities.ts";
11
+ import {WebGlErrorUtilities} from "./WebGlErrorUtilities.ts";
11
12
 
12
13
  /**
13
14
  * The utility class for WebGL operations.
@@ -68,4 +69,7 @@ export class WebGlUtilities {
68
69
  * The WebGL program utilities.
69
70
  */
70
71
  public static readonly program = new WebGLProgramUtilities();
72
+
73
+ /** The WebGL error utilities. Helper class for working with errors. */
74
+ public static readonly error = new WebGlErrorUtilities();
71
75
  }
@@ -0,0 +1,61 @@
1
+ import {type IGPUInfo, RenderingBackend, TextureFormat} from "../api/index.ts";
2
+ import type {GpuAdapter} from "./WebGpuTypes.ts";
3
+ import type {WebGpuGraphicsDeviceFeatures} from "./WebGpuGraphicsDeviceFeatures.ts";
4
+
5
+ /**
6
+ * The WebGPU GPU info, read from the adapter info.
7
+ * @internal
8
+ */
9
+ export class WebGpuGpuInfo implements IGPUInfo {
10
+
11
+ /**
12
+ * The constructor.
13
+ * @param adapter The adapter.
14
+ * @param features The device features.
15
+ */
16
+ public constructor(adapter: GpuAdapter, features: WebGpuGraphicsDeviceFeatures) {
17
+ const info = adapter.info;
18
+ this.name = info?.description || info?.device || info?.architecture || "Unknown";
19
+ this.vendor = info?.vendor || "Unknown";
20
+ this.apiVersion = "WebGPU";
21
+ this.api = RenderingBackend.WEB_GPU;
22
+ // The native API behind WebGPU (Vulkan, Metal, D3D12) is hidden from the page.
23
+ this.underlyingBackend = RenderingBackend.DEFAULT;
24
+
25
+ // Features are read from the device (only requested features are enabled), so this lists what can be created.
26
+ const formats: TextureFormat[] = [];
27
+ if (features.supportsTextureCompressionASTC) {
28
+ formats.push(TextureFormat.ASTC_4X4_RGBA_UNORM, TextureFormat.ASTC_4X4_RGBA_SRGB);
29
+ }
30
+ if (features.supportsTextureCompressionS3TC) {
31
+ formats.push(TextureFormat.BC1_RGB_UNORM, TextureFormat.BC1_RGB_SRGB,
32
+ TextureFormat.BC3_RGBA_UNORM, TextureFormat.BC3_RGBA_SRGB);
33
+ }
34
+ if (features.supportsTextureCompressionETC2) {
35
+ formats.push(TextureFormat.ETC2_RGB8_UNORM, TextureFormat.ETC2_RGB8_SRGB,
36
+ TextureFormat.ETC2_RGBA8_UNORM, TextureFormat.ETC2_RGBA8_SRGB);
37
+ }
38
+ if (features.supportsTextureCompressionBC) {
39
+ formats.push(TextureFormat.BC7_RGBA_UNORM, TextureFormat.BC7_RGBA_SRGB);
40
+ }
41
+ this.supportedCompressedTextureFormats = formats;
42
+ }
43
+
44
+ /** @inheritDoc */
45
+ public readonly name: string;
46
+
47
+ /** @inheritDoc */
48
+ public readonly vendor: string;
49
+
50
+ /** @inheritDoc */
51
+ public readonly apiVersion: string;
52
+
53
+ /** @inheritDoc */
54
+ public readonly api: RenderingBackend;
55
+
56
+ /** @inheritDoc */
57
+ public readonly underlyingBackend: RenderingBackend;
58
+
59
+ /** @inheritDoc */
60
+ public readonly supportedCompressedTextureFormats: TextureFormat[];
61
+ }