ris-framework 0.2.0-dev.12 → 0.2.0-dev.14

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 (59) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/README.md +101 -158
  3. package/dist/api/IFramework.d.ts +3 -3
  4. package/dist/api/IFramework.d.ts.map +1 -1
  5. package/dist/api/content/ContentManager.d.ts +2 -2
  6. package/dist/api/content/ContentManager.d.ts.map +1 -1
  7. package/dist/api/content/IContentManager.d.ts +2 -2
  8. package/dist/api/content/IContentManager.d.ts.map +1 -1
  9. package/dist/api/rendering/IRenderer.d.ts +11 -6
  10. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  11. package/dist/api/rendering/enums.d.ts +5 -5
  12. package/dist/api/rendering/enums.d.ts.map +1 -1
  13. package/dist/api/rendering/texture/ITextureDescriptor.d.ts +49 -0
  14. package/dist/api/rendering/texture/ITextureDescriptor.d.ts.map +1 -0
  15. package/dist/api/rendering/texture/ITextureFactory.d.ts +2 -2
  16. package/dist/api/rendering/texture/ITextureFactory.d.ts.map +1 -1
  17. package/dist/api/rendering/texture/TextureUtilities.d.ts +22 -21
  18. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  19. package/dist/api/rendering/texture/_export-texture.d.ts +1 -1
  20. package/dist/api/rendering/texture/_export-texture.d.ts.map +1 -1
  21. package/dist/core/rendering/ARenderer.d.ts +3 -0
  22. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  23. package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts +14 -0
  24. package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts.map +1 -0
  25. package/dist/core/rendering/texture/texture.d.ts +3 -2
  26. package/dist/core/rendering/texture/texture.d.ts.map +1 -1
  27. package/dist/index.js +277 -290
  28. package/dist/webgl/texture/WebGlTexture2D.d.ts +3 -2
  29. package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
  30. package/dist/webgl/texture/WebGlTextureFactory.d.ts +2 -9
  31. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  32. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -1
  33. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +3 -2
  34. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -1
  35. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +2 -2
  36. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/Framework.ts +2 -2
  39. package/src/api/IFramework.ts +3 -3
  40. package/src/api/content/ContentManager.ts +9 -7
  41. package/src/api/content/IContentManager.ts +2 -2
  42. package/src/api/rendering/IRenderer.ts +12 -6
  43. package/src/api/rendering/enums.ts +5 -5
  44. package/src/api/rendering/texture/ITextureDescriptor.ts +57 -0
  45. package/src/api/rendering/texture/ITextureFactory.ts +2 -2
  46. package/src/api/rendering/texture/TextureUtilities.ts +43 -61
  47. package/src/api/rendering/texture/_export-texture.ts +1 -1
  48. package/src/core/rendering/ARenderer.ts +6 -2
  49. package/src/core/rendering/texture/TextureDescriptorUtilities.ts +27 -0
  50. package/src/core/rendering/texture/texture.ts +2 -2
  51. package/src/main.ts +5 -4
  52. package/src/webgl/texture/WebGlTexture2D.ts +9 -8
  53. package/src/webgl/texture/WebGlTextureFactory.ts +50 -64
  54. package/src/webgl/utilities/WebGlErrorUtilities.ts +3 -2
  55. package/src/webgpu/texture/WebGpuTexture2D.ts +10 -9
  56. package/src/webgpu/texture/WebGpuTextureFactory.ts +19 -16
  57. package/dist/api/rendering/texture/TextureDescriptor.d.ts +0 -42
  58. package/dist/api/rendering/texture/TextureDescriptor.d.ts.map +0 -1
  59. package/src/api/rendering/texture/TextureDescriptor.ts +0 -52
@@ -1,5 +1,6 @@
1
- import { TextureDescriptor, type IFramework, type ITextureView, type TextureViewDescriptor } from "../../api/index.js";
1
+ import { type IFramework, type ITextureView, type TextureViewDescriptor } from "../../api/index.js";
2
2
  import { ATexture2D } from "../../core/rendering/texture/texture.js";
3
+ import { type ResolvedTextureDescriptor } from "../../core/rendering/texture/TextureDescriptorUtilities.js";
3
4
  /**
4
5
  * The WebGL implementation of ITexture2D.
5
6
  */
@@ -13,7 +14,7 @@ export declare class WebGlTexture2D extends ATexture2D {
13
14
  * @param _framework The framework instance.
14
15
  * @param textureDescriptor The texture descriptor.
15
16
  */
16
- constructor(_framework: IFramework, textureDescriptor: TextureDescriptor);
17
+ constructor(_framework: IFramework, textureDescriptor: ResolvedTextureDescriptor);
17
18
  /**
18
19
  * Gets the underlying WebGL texture.
19
20
  * @returns The WebGL texture.
@@ -1 +1 @@
1
- {"version":3,"file":"WebGlTexture2D.d.ts","sourceRoot":"","sources":["../../../src/webgl/texture/WebGlTexture2D.ts"],"names":[],"mappings":"AACA,OAAO,EACH,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AAGnE;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAYtC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAV/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsB;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyB;IAC7C,OAAO,CAAC,UAAU,CAA6B;IAE/C;;;;OAIG;gBAEkB,UAAU,EAAE,UAAU,EACvC,iBAAiB,EAAE,iBAAiB;IAOxC;;;OAGG;IACH,IAAW,SAAS,IAAI,YAAY,CAEnC;IAED,kBAAkB;IACX,UAAU,IAAI,IAAI;IA2CzB,kBAAkB;IACX,UAAU,CAAC,WAAW,CAAC,EAAE,qBAAqB,GAAG,YAAY;IAKpE,kBAAkB;IACX,OAAO,IAAI,IAAI;IAgBtB,iHAAiH;IACjH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAA6C;IAEnF;;;;;;OAMG;WACW,kBAAkB,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc;IAmBvE;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;CAM5D"}
1
+ {"version":3,"file":"WebGlTexture2D.d.ts","sourceRoot":"","sources":["../../../src/webgl/texture/WebGlTexture2D.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AAEnE,OAAO,EAAC,KAAK,yBAAyB,EAA2B,MAAM,4DAA4D,CAAC;AAEpI;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAYtC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAV/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsB;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyB;IAC7C,OAAO,CAAC,UAAU,CAA6B;IAE/C;;;;OAIG;gBAEkB,UAAU,EAAE,UAAU,EACvC,iBAAiB,EAAE,yBAAyB;IAOhD;;;OAGG;IACH,IAAW,SAAS,IAAI,YAAY,CAEnC;IAED,kBAAkB;IACX,UAAU,IAAI,IAAI;IA2CzB,kBAAkB;IACX,UAAU,CAAC,WAAW,CAAC,EAAE,qBAAqB,GAAG,YAAY;IAKpE,kBAAkB;IACX,OAAO,IAAI,IAAI;IAgBtB,iHAAiH;IACjH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAA6C;IAEnF;;;;;;OAMG;WACW,kBAAkB,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc;IAoBvE;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;CAM5D"}
@@ -1,4 +1,4 @@
1
- import { Color, type IFramework, type ITexture2D, type ITextureFactory, TextureDescriptor, TextureFormat } from "../../api/index.js";
1
+ import { Color, type IFramework, type ITexture2D, type ITextureFactory, type ITextureDescriptor, TextureFormat } from "../../api/index.js";
2
2
  import { type IKtx2Texture } from "ris-ktx2";
3
3
  export declare class WebGlTextureFactory implements ITextureFactory {
4
4
  private readonly _framework;
@@ -8,14 +8,7 @@ export declare class WebGlTextureFactory implements ITextureFactory {
8
8
  */
9
9
  constructor(_framework: IFramework);
10
10
  /** @inheritDoc */
11
- createFromKtx2(ktxTexture: IKtx2Texture, descriptor?: TextureDescriptor): ITexture2D;
12
- /** Whether the Vulkan format is an sRGB format. */
13
- private static _isSrgbVkFormat;
14
- /**
15
- * Falls back to the linear variant (with a warning) when the GPU cannot sample the sRGB format.
16
- * Only S3TC sRGB (BC1/BC3) has its own WebGL extension; BC7, ETC2 and ASTC sRGB ship with their base extension.
17
- */
18
- private _ensureSrgbSupported;
11
+ createFromKtx2(ktxTexture: IKtx2Texture, descriptor?: ITextureDescriptor): ITexture2D;
19
12
  /** @inheritdoc */
20
13
  create(width: number, height: number, data?: Uint8Array | HTMLImageElement, channels?: number, label?: string | null | undefined, textureUsage?: number, textureFormat?: TextureFormat, useMipMaps?: boolean): ITexture2D;
21
14
  /** @inheritdoc */
@@ -1 +1 @@
1
- {"version":3,"file":"WebGlTextureFactory.d.ts","sourceRoot":"","sources":["../../../src/webgl/texture/WebGlTextureFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,iBAAiB,EACjB,aAAa,EAGhB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAC,KAAK,YAAY,EAAkD,MAAM,UAAU,CAAC;AAG5F,qBAAa,mBAAoB,YAAW,eAAe;IAM3C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJvC;;;OAGG;gBAC0B,UAAU,EAAE,UAAU;IAGnD,kBAAkB;IACX,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,iBAAiB,GAAG,UAAU;IA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EACpB,KAAK,GAAE,MAAM,GAAG,IAAI,GAAG,SAAgB,EACvC,YAAY,SAAuD,EACnE,aAAa,gBAA4B,EACzC,UAAU,UAAQ,GAAG,UAAU;IAiCnC,kBAAkB;IACX,WAAW,CACd,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAC7B,KAAK,GAAE,KAAK,GAAG,IAAW,EAC1B,YAAY,SAAuD,EACnE,aAAa,gBAA0B,EACvC,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,SAAS,UAAQ,GAAG,UAAU;CA2CrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"WebGlErrorUtilities.d.ts","sourceRoot":"","sources":["../../../src/webgl/utilities/WebGlErrorUtilities.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAEpB;IAED;;;;OAIG;IACI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAI,MAAM;CAG5C"}
1
+ {"version":3,"file":"WebGlErrorUtilities.d.ts","sourceRoot":"","sources":["../../../src/webgl/utilities/WebGlErrorUtilities.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAGpB;IAED;;;;OAIG;IACI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAG3C"}
@@ -1,6 +1,7 @@
1
- import { type IFramework, TextureDescriptor, type ITextureView, TextureViewDescriptor } from "../../api/index.js";
1
+ import { type IFramework, type ITextureView, TextureViewDescriptor } from "../../api/index.js";
2
2
  import { ATexture2D } from "../../core/rendering/texture/texture.js";
3
3
  import { type GpuTexture, type GpuTextureView } from "../WebGpuTypes.js";
4
+ import { type ResolvedTextureDescriptor } from "../../core/rendering/texture/TextureDescriptorUtilities.js";
4
5
  /**
5
6
  * The WebGPU 2D texture.
6
7
  *
@@ -19,7 +20,7 @@ export declare class WebGpuTexture2D extends ATexture2D {
19
20
  * @param descriptor The texture descriptor.
20
21
  * @param image An optional image to upload instead of `descriptor.data`.
21
22
  */
22
- constructor(framework: IFramework, descriptor: TextureDescriptor, image?: HTMLImageElement);
23
+ constructor(framework: IFramework, descriptor: ResolvedTextureDescriptor, image?: HTMLImageElement);
23
24
  /** The WebGPU texture. */
24
25
  get gpuTexture(): GpuTexture;
25
26
  /** The default WebGPU view of the whole texture. */
@@ -1 +1 @@
1
- {"version":3,"file":"WebGpuTexture2D.d.ts","sourceRoot":"","sources":["../../../src/webgpu/texture/WebGpuTexture2D.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,UAAU,EAEf,iBAAiB,EAGjB,KAAK,YAAY,EACjB,qBAAqB,EAExB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AAEnE,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAIxF;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAE3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAmB;IAC3C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,eAAe,CAA+B;IAEtD;;;;;OAKG;gBACgB,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,gBAAgB;IAMjG,0BAA0B;IAC1B,IAAW,UAAU,IAAI,UAAU,CAKlC;IAED,oDAAoD;IACpD,IAAW,cAAc,IAAI,cAAc,CAK1C;IAED,kBAAkB;IACX,UAAU,IAAI,IAAI;IAyEzB,kBAAkB;IACX,UAAU,CAAC,UAAU,CAAC,EAAE,qBAAqB,GAAG,YAAY;IAanE,kBAAkB;IACX,OAAO,IAAI,IAAI;IAetB,yCAAyC;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAA8C;IAEpF;;;;OAIG;WACW,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AAS,EAAE,UAAU,GAAG,IAAI;CAK5D"}
@@ -1,4 +1,4 @@
1
- import { Color, type IFramework, type ITexture2D, type ITextureFactory, TextureDescriptor, TextureFormat } from "../../api/index.js";
1
+ import { Color, type IFramework, type ITexture2D, type ITextureFactory, type ITextureDescriptor, TextureFormat } from "../../api/index.js";
2
2
  import type { IKtx2Texture } from "ris-ktx2";
3
3
  /**
4
4
  * The WebGPU texture factory.
@@ -12,7 +12,7 @@ export declare class WebGpuTextureFactory implements ITextureFactory {
12
12
  */
13
13
  constructor(_framework: IFramework);
14
14
  /** @inheritDoc */
15
- createFromKtx2(_ktxTexture: IKtx2Texture, _descriptor?: TextureDescriptor): ITexture2D;
15
+ createFromKtx2(_ktxTexture: IKtx2Texture, _descriptor?: ITextureDescriptor): ITexture2D;
16
16
  /** @inheritDoc */
17
17
  create(width: number, height: number, data?: number[] | HTMLImageElement | ArrayBufferView, channels?: number, label?: string | null | undefined, textureUsage?: number, textureFormat?: TextureFormat, useMipMaps?: boolean): ITexture2D;
18
18
  /** @inheritDoc */
@@ -1 +1 @@
1
- {"version":3,"file":"WebGpuTextureFactory.d.ts","sourceRoot":"","sources":["../../../src/webgpu/texture/WebGpuTextureFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,iBAAiB,EACjB,aAAa,EAEhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAG3C;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAMrC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ9C;;;OAGG;gBACiC,UAAU,EAAE,UAAU;IAG1D,kBAAkB;IACX,cAAc,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,iBAAiB,GAAG,UAAU;IAI7F,kBAAkB;IACX,MAAM,CACT,KAAK,EAAE,MAAM,EAAE,MA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AAU,UAAQ,GAAG,UAAU;IAuCnC,kBAAkB;IACX,WAAW,CACd,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAC7B,KAAK,GAAE,KAAK,GAAG,IAAW,EAC1B,YAAY,SAAuD,EACnE,aAAa,gBAA0B,EACvC,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,SAAS,UAAQ,GAAG,UAAU;CAmCrC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ris-framework",
3
- "version": "0.2.0-dev.12",
3
+ "version": "0.2.0-dev.14",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Framework.ts CHANGED
@@ -54,7 +54,7 @@ import {WebGpuRenderPipelineFactory} from "./webgpu/render-pipelines/WebGpuRende
54
54
  import {WebGpuShaderModuleLoader} from "./webgpu/shader/WebGpuShaderModuleLoader.ts";
55
55
  import {WebGpuBuffersFactory} from "./webgpu/buffers/WebGpuBuffersFactory.ts";
56
56
  import {WebGpuTexture2D} from "./webgpu/texture/WebGpuTexture2D.ts";
57
- import {TextureColorSpace} from "./api/rendering/enums.ts";
57
+ import {ColorSpace} from "./api/rendering/enums.ts";
58
58
 
59
59
  /** The Ris framework */
60
60
  export class Framework implements IFramework {
@@ -100,7 +100,7 @@ export class Framework implements IFramework {
100
100
  textureFiltering: this._configuration.textureFiltering ?? TextureSamplerFilteringPreset.BILINEAR,
101
101
  alpha: this._configuration.alpha ?? false,
102
102
  powerPreference: this._configuration.powerPreference ?? PowerPreferenceType.DEFAULT,
103
- textureColorSpace: this._configuration.textureColorSpace ?? TextureColorSpace.SRGB
103
+ textureColorSpace: this._configuration.textureColorSpace ?? ColorSpace.SRGB
104
104
  };
105
105
 
106
106
 
@@ -23,7 +23,7 @@ import type { IDisposable } from "./core/IDisposable.ts";
23
23
  import type {vec2} from "gl-matrix";
24
24
  import type {TextureSamplerFilteringPreset} from "../core/rendering/enums.ts";
25
25
  import type {PowerPreferenceType} from "./rendering/PowerPreference.ts";
26
- import type {TextureColorSpace} from "./rendering/enums.ts";
26
+ import type {ColorSpace} from "./rendering/enums.ts";
27
27
 
28
28
 
29
29
  /**
@@ -41,8 +41,8 @@ export class IFrameworkConfiguration {
41
41
  /** The texture filtering to configure */
42
42
  textureFiltering?: TextureSamplerFilteringPreset;
43
43
 
44
- /** The texture color space to use by default. By default, it is {@link TextureColorSpace.SRGB}. */
45
- textureColorSpace?: TextureColorSpace;
44
+ /** The texture color space to use by default. By default, it is {@link ColorSpace.SRGB}. */
45
+ textureColorSpace?: ColorSpace;
46
46
 
47
47
  /**
48
48
  * The HTMLCanvasElement to use for rendering.
@@ -4,7 +4,7 @@ import {
4
4
  type IShaderModuleLoader,
5
5
  type ITexture2D,
6
6
  type IFramework,
7
- TextureDescriptor,
7
+ type ITextureDescriptor,
8
8
  TextureFormat,
9
9
  ContentConfig,
10
10
  TextureUsage,
@@ -18,6 +18,7 @@ import {
18
18
  import {ObjGeometryMapper} from "../loaders/ObjGeometryMapper.ts";
19
19
  import {ObjLoader} from "../loaders/ObjLoader.ts";
20
20
  import {Ktx2Factory} from "ris-ktx2";
21
+ import {resolveTextureDescriptor} from "../../core/rendering/texture/TextureDescriptorUtilities.ts";
21
22
  import type {IKtx2Texture} from "ris-ktx2";
22
23
 
23
24
  const KTX2_EXTENSION = ".ktx2";
@@ -76,16 +77,17 @@ export class ContentManager implements IContentManager {
76
77
 
77
78
  /** @inheritDoc */
78
79
  public async loadTexture2DAsync(path: string,
79
- textureDescriptor?: TextureDescriptor,
80
+ textureDescriptor?: ITextureDescriptor,
80
81
  contentConfig?: ContentConfig,
81
82
  ): Promise<ITexture2D> {
82
83
 
84
+ const desc = resolveTextureDescriptor(textureDescriptor);
85
+
83
86
  // TODO: check texture cache
84
87
  if (path.endsWith(KTX2_EXTENSION)) {
85
88
 
86
89
  const ktx2Texture = await this.loadKtx2Async(path);
87
- textureDescriptor = textureDescriptor ?? new TextureDescriptor();
88
- const tex = this._framework.textureFactory.createFromKtx2(ktx2Texture, textureDescriptor);
90
+ const tex = this._framework.textureFactory.createFromKtx2(ktx2Texture, desc);
89
91
  if (contentConfig?.keepDataCached !== true) {
90
92
  ktx2Texture.delete();
91
93
  }
@@ -94,8 +96,8 @@ export class ContentManager implements IContentManager {
94
96
 
95
97
  let format = this._framework.renderer.preferredTextureFormat;
96
98
 
97
- if (textureDescriptor && textureDescriptor.textureFormat != TextureFormat.UNDEFINED) {
98
- format = textureDescriptor.textureFormat;
99
+ if (desc.textureFormat != TextureFormat.UNDEFINED) {
100
+ format = desc.textureFormat;
99
101
  }
100
102
 
101
103
  const imageLoader = this._framework.imageLoader;
@@ -109,7 +111,7 @@ export class ContentManager implements IContentManager {
109
111
  path,
110
112
  TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_SRC,
111
113
  format,
112
- textureDescriptor?.generateMipmaps
114
+ desc.generateMipmaps
113
115
  );
114
116
  }
115
117
 
@@ -4,7 +4,7 @@ import type { IRenderableMesh } from "../meshes/IRenderableMesh.ts";
4
4
  import type { IShaderModuleLoader } from "../shader/IShaderModuleLoader.ts";
5
5
  import type { IShaderModule } from "../shader/IShaderModule.ts";
6
6
  import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
7
- import {TextureDescriptor} from "../rendering/texture/TextureDescriptor.ts";
7
+ import type {ITextureDescriptor} from "../rendering/texture/ITextureDescriptor.ts";
8
8
  import {ContentConfig} from "./ContentConfig.ts";
9
9
  import type { IKtx2Texture } from "ris-ktx2";
10
10
  import type {IMesh} from "../meshes/IMesh.ts";
@@ -42,7 +42,7 @@ export interface IContentManager {
42
42
  * @param contentConfig - The content config.
43
43
  * @returns The Texture2D.
44
44
  */
45
- loadTexture2DAsync(path: string, desc?: TextureDescriptor, contentConfig?: ContentConfig): Promise<ITexture2D>;
45
+ loadTexture2DAsync(path: string, desc?: ITextureDescriptor, contentConfig?: ContentConfig): Promise<ITexture2D>;
46
46
 
47
47
  /**
48
48
  * Loads a plain mesh (geometry and buffers only, no material or transform) from an OBJ (Wavefront) file,
@@ -5,7 +5,7 @@ import {RenderingBackend} from "./RenderingBackend.ts";
5
5
  import {vec2} from "gl-matrix";
6
6
  import type {PowerPreferenceType} from "./PowerPreference.ts";
7
7
  import type {TextureSamplerFilteringPreset} from "../../core/rendering/enums.ts";
8
- import type {TextureColorSpace} from "./enums.ts";
8
+ import type {ColorSpace} from "./enums.ts";
9
9
 
10
10
 
11
11
  /**
@@ -31,7 +31,7 @@ export interface IRendererConfiguration {
31
31
  textureFiltering: TextureSamplerFilteringPreset;
32
32
 
33
33
  /** The desired texture color space. */
34
- textureColorSpace: TextureColorSpace;
34
+ textureColorSpace: ColorSpace;
35
35
  }
36
36
 
37
37
  /**
@@ -46,13 +46,19 @@ export interface IRenderer {
46
46
  readonly graphicsDevice: IGraphicsDevice;
47
47
 
48
48
  /**
49
- * The preferred texture format.
50
- * This will encode texture which do not specify texture format to:
51
- * - {@link TextureFormat.} // TODO: describe SRGB depending on TextureSurfaceFormat requested
52
- * - {@link TextureFormat.} // TODO: describe RGBA depending on TextureSurfaceFormat requested
49
+ * The preferred texture format, chosen from {@link IRendererConfiguration.textureColorSpace}.
50
+ * Textures that do not specify a texture format are created with it:
51
+ * - {@link TextureFormat.RGBA_8_UNORM_SRGB} when the color space is {@link ColorSpace.SRGB} (the default).
52
+ * - {@link TextureFormat.RGBA_8_UNORM} when the color space is {@link ColorSpace.LINEAR}.
53
53
  */
54
54
  readonly preferredTextureFormat: TextureFormat;
55
55
 
56
+ /**
57
+ * The preferred texture color space, taken from {@link IRendererConfiguration.textureColorSpace}.
58
+ * Textures that do not specify a format are treated as being in this color space.
59
+ */
60
+ readonly preferredColorSpace: ColorSpace;
61
+
56
62
  /**
57
63
  * The preferred depth stencil format.
58
64
  */
@@ -19,12 +19,12 @@ export enum Culling {
19
19
  Front
20
20
  }
21
21
 
22
- /** TODO: */
23
- export enum TextureColorSpace
22
+ /** The color space. */
23
+ export enum ColorSpace
24
24
  {
25
- /** TODO */
25
+ /** The linear color space. */
26
26
  LINEAR = "LINEAR",
27
27
 
28
- /** TODO */
29
- SRGB = "S_RGBA",
28
+ /** The sRGB color space. */
29
+ SRGB = "SRGB",
30
30
  }
@@ -0,0 +1,57 @@
1
+ import type {TextureFormat} from "./TextureFormat.ts";
2
+ import type {TextureUsage} from "./TextureUsage.ts";
3
+ import type {vec2} from "gl-matrix";
4
+
5
+ /**
6
+ * The texture descriptor. Every field is optional; factories fill in the defaults for missing fields.
7
+ */
8
+ export interface ITextureDescriptor {
9
+
10
+ /**
11
+ * The texture width.
12
+ * By default, it is 0.
13
+ */
14
+ width?: number;
15
+
16
+ /**
17
+ * The texture height.
18
+ * By default, it is 0.
19
+ */
20
+ height?: number;
21
+
22
+ /**
23
+ * The texture format.
24
+ * By default, it is UNDEFINED.
25
+ */
26
+ textureFormat?: TextureFormat;
27
+
28
+ /**
29
+ * The texture usage.
30
+ * By default, it is TEXTURE_BINDING | COPY_DST.
31
+ */
32
+ textureUsage?: TextureUsage;
33
+
34
+ /**
35
+ * The texture label.
36
+ * By default, it is null.
37
+ */
38
+ label?: string | null;
39
+
40
+ /**
41
+ * The data per mip level.
42
+ * By default, it is undefined.
43
+ */
44
+ data?: Uint8Array[];
45
+
46
+ /**
47
+ * Should mipmaps be generated.
48
+ * By default, it is false.
49
+ */
50
+ generateMipmaps?: boolean;
51
+
52
+ /**
53
+ * The block size of a texture, which must be set for compressed textures.
54
+ * By default, it is undefined.
55
+ */
56
+ blockSize?: vec2;
57
+ }
@@ -2,7 +2,7 @@ import {Color} from "../../data/Color.ts";
2
2
  import {TextureUsage} from "./TextureUsage.ts";
3
3
  import {TextureFormat} from "./TextureFormat.ts";
4
4
  import type { ITexture2D } from "./ITexture2D.ts";
5
- import {TextureDescriptor} from "./TextureDescriptor.ts";
5
+ import type {ITextureDescriptor} from "./ITextureDescriptor.ts";
6
6
  import type {IKtx2Texture} from "ris-ktx2";
7
7
 
8
8
  /**
@@ -52,5 +52,5 @@ export interface ITextureFactory {
52
52
  * @param descriptor - The optional texture descriptor.
53
53
  * @returns The 2D texture.
54
54
  */
55
- createFromKtx2(ktxTexture: IKtx2Texture, descriptor?: TextureDescriptor): ITexture2D;
55
+ createFromKtx2(ktxTexture: IKtx2Texture, descriptor?: ITextureDescriptor): ITexture2D;
56
56
  }
@@ -204,77 +204,33 @@ export class TextureUtilities {
204
204
  };
205
205
 
206
206
  private static readonly _mapKtxTranscodeFormatVkFormat: { [key: number]: number } = {
207
- [KtxTranscodeFormat.KTX_TTF_ETC1_RGB]: VkFormat.ETC2_R8G8B8_UNORM_BLOCK,
207
+ [KtxTranscodeFormat.ETC1_RGB]: VkFormat.ETC2_R8G8B8_UNORM_BLOCK,
208
208
  [KtxTranscodeFormat.ETC2_RGBA]: VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK,
209
- [KtxTranscodeFormat.KTX_TTF_BC1_RGB]: VkFormat.BC1_RGB_UNORM_BLOCK,
209
+ [KtxTranscodeFormat.BC1_RGB]: VkFormat.BC1_RGB_UNORM_BLOCK,
210
210
  [KtxTranscodeFormat.BC3_RGBA]: VkFormat.BC3_UNORM_BLOCK,
211
- [KtxTranscodeFormat.KTX_TTF_BC4_R]: VkFormat.BC4_UNORM_BLOCK,
212
- [KtxTranscodeFormat.KTX_TTF_BC5_RG]: VkFormat.BC5_UNORM_BLOCK,
211
+ [KtxTranscodeFormat.BC4_R]: VkFormat.BC4_UNORM_BLOCK,
212
+ [KtxTranscodeFormat.BC5_RG]: VkFormat.BC5_UNORM_BLOCK,
213
213
  [KtxTranscodeFormat.BC7_RGBA]: VkFormat.BC7_UNORM_BLOCK,
214
- [KtxTranscodeFormat.KTX_TTF_PVRTC1_4_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
214
+ [KtxTranscodeFormat.PVRTC1_4_RGB]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
215
215
  [KtxTranscodeFormat.PVRTC1_4_RGBA]: VkFormat.PVRTC1_4BPP_UNORM_BLOCK_IMG,
216
216
  [KtxTranscodeFormat.ASTC_4X4_RGBA]: VkFormat.ASTC_4X4_UNORM_BLOCK,
217
217
  [KtxTranscodeFormat.RGBA32]: VkFormat.R8G8B8A8_UNORM,
218
- [KtxTranscodeFormat.KTX_TTF_RGB565]: VkFormat.R5G6B5_UNORM_PACK16,
219
- [KtxTranscodeFormat.KTX_TTF_BGR565]: VkFormat.B5G6R5_UNORM_PACK16,
220
- [KtxTranscodeFormat.KTX_TTF_RGBA4444]: VkFormat.R4G4B4A4_UNORM_PACK16,
221
- [KtxTranscodeFormat.KTX_TTF_PVRTC2_4_RGB]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
218
+ [KtxTranscodeFormat.RGB565]: VkFormat.R5G6B5_UNORM_PACK16,
219
+ [KtxTranscodeFormat.BGR565]: VkFormat.B5G6R5_UNORM_PACK16,
220
+ [KtxTranscodeFormat.RGBA4444]: VkFormat.R4G4B4A4_UNORM_PACK16,
221
+ [KtxTranscodeFormat.PVRTC2_4_RGB]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
222
222
  [KtxTranscodeFormat.PVRTC2_4_RGBA]: VkFormat.PVRTC2_4BPP_UNORM_BLOCK_IMG,
223
- [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_R11]: VkFormat.EAC_R11_UNORM_BLOCK,
224
- [KtxTranscodeFormat.KTX_TTF_ETC2_EAC_RG11]: VkFormat.EAC_R11G11_UNORM_BLOCK,
223
+ [KtxTranscodeFormat.ETC2_EAC_R11]: VkFormat.EAC_R11_UNORM_BLOCK,
224
+ [KtxTranscodeFormat.ETC2_EAC_RG11]: VkFormat.EAC_R11G11_UNORM_BLOCK,
225
225
  };
226
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
- }
227
+ /** sRGB format → its linear variant. */
228
+ private static readonly _linearVariant: { [key: string]: TextureFormat } = Object.fromEntries(
229
+ Object.entries(TextureUtilities._srgbVariant).map(([linear, srgb]) => [srgb, linear as TextureFormat])
230
+ );
253
231
 
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
- }
232
+ /** Every sRGB format. */
233
+ private static readonly _srgbFormats: TextureFormat[] = Object.values(TextureUtilities._srgbVariant);
278
234
 
279
235
  /**
280
236
  * Checks if the given texture format is a compressed texture format.
@@ -361,4 +317,30 @@ export class TextureUtilities {
361
317
  return format;
362
318
  }
363
319
 
320
+ /**
321
+ * Maps the linear format to the srgb variant.
322
+ * @param textureFormat The linear format.
323
+ * @return The srgb variant, or the format itself if it is already sRGB or has no sRGB variant (e.g. PVRTC).
324
+ */
325
+ public static convertToSrgbVariant(textureFormat: TextureFormat) : TextureFormat {
326
+ return this._srgbVariant[textureFormat] ?? textureFormat;
327
+ }
328
+
329
+ /**
330
+ * Maps the srgb format to the linear variant.
331
+ * @param textureFormat The srgb format.
332
+ * @return The linear variant, or the format itself if it is already linear.
333
+ */
334
+ public static convertToLinearVariant(textureFormat: TextureFormat) : TextureFormat {
335
+ return this._linearVariant[textureFormat] ?? textureFormat;
336
+ }
337
+
338
+ /**
339
+ * Checks whether the texture format is an sRGB format.
340
+ * @param textureFormat The texture format to check.
341
+ * @return True if srgb texture format.
342
+ */
343
+ public static isSrgbFormat(textureFormat: TextureFormat) : boolean {
344
+ return this._srgbFormats.includes(textureFormat);
345
+ }
364
346
  }
@@ -5,5 +5,5 @@ export * from "./TextureViewDimension.ts";
5
5
  export * from "./TextureFormat.ts";
6
6
  export * from "./ITextureView.ts";
7
7
  export * from "./ITextureFactory.ts";
8
- export * from "./TextureDescriptor.ts";
8
+ export * from "./ITextureDescriptor.ts";
9
9
  export * from "./TextureUtilities.ts";
@@ -18,7 +18,7 @@ import {
18
18
  TextureFormat,
19
19
  TextureUsage
20
20
  } from "../../api/index.ts";
21
- import {TextureColorSpace} from "../../api/rendering/enums.ts";
21
+ import {ColorSpace} from "../../api/rendering/enums.ts";
22
22
 
23
23
  export abstract class ARenderer implements ITempRenderer {
24
24
 
@@ -69,6 +69,9 @@ export abstract class ARenderer implements ITempRenderer {
69
69
  /** @inheritdoc */
70
70
  public readonly preferredTextureFormat: TextureFormat;
71
71
 
72
+ /** @inheritDoc */
73
+ public readonly preferredColorSpace: ColorSpace;
74
+
72
75
  /** @inheritdoc */
73
76
  public get preferredDepthStencilFormat(): TextureFormat {
74
77
  return this._preferredDepthStencilFormat;
@@ -108,7 +111,8 @@ export abstract class ARenderer implements ITempRenderer {
108
111
  this._windowManager = framework.windowManager;
109
112
  this._currentBackBufferSize[0] = this._windowManager.canvas.width;
110
113
  this._currentBackBufferSize[1] = this._windowManager.canvas.height;
111
- this.preferredTextureFormat = configuration.textureColorSpace == TextureColorSpace.SRGB
114
+ this.preferredColorSpace = configuration.textureColorSpace;
115
+ this.preferredTextureFormat = configuration.textureColorSpace == ColorSpace.SRGB
112
116
  ? TextureFormat.RGBA_8_UNORM_SRGB : TextureFormat.RGBA_8_UNORM;
113
117
  }
114
118
 
@@ -0,0 +1,27 @@
1
+ import {type ITextureDescriptor, TextureFormat, TextureUsage} from "../../../api/index.ts";
2
+
3
+ /**
4
+ * A texture descriptor with all defaults applied. Only `data` and `blockSize` stay optional.
5
+ * @internal
6
+ */
7
+ export type ResolvedTextureDescriptor =
8
+ Required<Omit<ITextureDescriptor, "data" | "blockSize">> & Pick<ITextureDescriptor, "data" | "blockSize">;
9
+
10
+ /**
11
+ * Fills in the defaults for every missing field of a texture descriptor.
12
+ * @param desc The descriptor, possibly partial or missing.
13
+ * @returns A new descriptor with the defaults applied.
14
+ * @internal
15
+ */
16
+ export function resolveTextureDescriptor(desc?: ITextureDescriptor): ResolvedTextureDescriptor {
17
+ return {
18
+ width: desc?.width ?? 0,
19
+ height: desc?.height ?? 0,
20
+ textureFormat: desc?.textureFormat ?? TextureFormat.UNDEFINED,
21
+ textureUsage: desc?.textureUsage ?? (TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_DST),
22
+ label: desc?.label ?? null,
23
+ data: desc?.data,
24
+ generateMipmaps: desc?.generateMipmaps ?? false,
25
+ blockSize: desc?.blockSize,
26
+ };
27
+ }
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  type ITexture2D, type ITextureView,
3
3
  State,
4
- type TextureDescriptor,
5
4
  type TextureFormat,
6
5
  TextureUsage,
7
6
  TextureViewDescriptor
8
7
  } from "../../../api/index.ts";
9
8
  import {vec2} from "gl-matrix";
9
+ import type {ResolvedTextureDescriptor} from "./TextureDescriptorUtilities.ts";
10
10
 
11
11
  /**
12
12
  * The ATexture2D class is an abstract base class that implements the ITexture2D interface. It provides common properties and a constructor for initializing a 2D texture, but it does not implement the actual texture creation and management logic, which must be provided by subclasses that extend this base class.
@@ -30,7 +30,7 @@ export abstract class ATexture2D implements ITexture2D {
30
30
  * @param descriptor - The texture descriptor.
31
31
  */
32
32
  protected constructor(
33
- descriptor: TextureDescriptor,
33
+ descriptor: ResolvedTextureDescriptor,
34
34
  ) {
35
35
 
36
36
  if (!descriptor.textureFormat) {
package/src/main.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  type ITexture2D,
12
12
  Rect,
13
13
  SamplerDescriptor,
14
- SamplerFilter, TextureDescriptor, TextureFormat
14
+ SamplerFilter, type ITextureDescriptor, TextureFormat
15
15
  } from "./api/index.ts";
16
16
 
17
17
  document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
@@ -46,9 +46,10 @@ let sampler: ISampler;
46
46
  framework.addOnLoadContentListener(async () =>
47
47
  {
48
48
 
49
- const texDesc = new TextureDescriptor();
50
- texDesc.generateMipmaps = true;
51
- texDesc.textureFormat = TextureFormat.RGBA_8_UNORM;
49
+ const texDesc: ITextureDescriptor = {
50
+ generateMipmaps: true,
51
+ textureFormat: TextureFormat.RGBA_8_UNORM,
52
+ };
52
53
 
53
54
  tex = await framework.content.loadTexture2DAsync("/assets/test.png", texDesc);
54
55
  tex2 = await framework.content.loadTexture2DAsync("/assets/cat.jpg", texDesc);