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.
- package/CHANGELOG.md +5 -2
- package/README.md +101 -158
- package/dist/api/IFramework.d.ts +3 -3
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +2 -2
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +2 -2
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +11 -6
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +5 -5
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/texture/ITextureDescriptor.d.ts +49 -0
- package/dist/api/rendering/texture/ITextureDescriptor.d.ts.map +1 -0
- package/dist/api/rendering/texture/ITextureFactory.d.ts +2 -2
- package/dist/api/rendering/texture/ITextureFactory.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +22 -21
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/rendering/texture/_export-texture.d.ts +1 -1
- package/dist/api/rendering/texture/_export-texture.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +3 -0
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts +14 -0
- package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts.map +1 -0
- package/dist/core/rendering/texture/texture.d.ts +3 -2
- package/dist/core/rendering/texture/texture.d.ts.map +1 -1
- package/dist/index.js +277 -290
- package/dist/webgl/texture/WebGlTexture2D.d.ts +3 -2
- package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +2 -9
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -1
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +3 -2
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -1
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +2 -2
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Framework.ts +2 -2
- package/src/api/IFramework.ts +3 -3
- package/src/api/content/ContentManager.ts +9 -7
- package/src/api/content/IContentManager.ts +2 -2
- package/src/api/rendering/IRenderer.ts +12 -6
- package/src/api/rendering/enums.ts +5 -5
- package/src/api/rendering/texture/ITextureDescriptor.ts +57 -0
- package/src/api/rendering/texture/ITextureFactory.ts +2 -2
- package/src/api/rendering/texture/TextureUtilities.ts +43 -61
- package/src/api/rendering/texture/_export-texture.ts +1 -1
- package/src/core/rendering/ARenderer.ts +6 -2
- package/src/core/rendering/texture/TextureDescriptorUtilities.ts +27 -0
- package/src/core/rendering/texture/texture.ts +2 -2
- package/src/main.ts +5 -4
- package/src/webgl/texture/WebGlTexture2D.ts +9 -8
- package/src/webgl/texture/WebGlTextureFactory.ts +50 -64
- package/src/webgl/utilities/WebGlErrorUtilities.ts +3 -2
- package/src/webgpu/texture/WebGpuTexture2D.ts +10 -9
- package/src/webgpu/texture/WebGpuTextureFactory.ts +19 -16
- package/dist/api/rendering/texture/TextureDescriptor.d.ts +0 -42
- package/dist/api/rendering/texture/TextureDescriptor.d.ts.map +0 -1
- package/src/api/rendering/texture/TextureDescriptor.ts +0 -52
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {WebGlUtilities} from "../utilities/WebGlUtilities.ts";
|
|
2
2
|
import {
|
|
3
|
-
TextureDescriptor,
|
|
4
3
|
type IFramework, State,
|
|
5
4
|
type ITextureView,
|
|
6
5
|
type TextureViewDescriptor, TextureUtilities
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
import type {WebGlGraphicsDevice} from "../WebGlGraphicsDevice.ts";
|
|
9
8
|
import {ATexture2D} from "../../core/rendering/texture/texture.ts";
|
|
10
9
|
import {vec2} from "gl-matrix";
|
|
10
|
+
import {type ResolvedTextureDescriptor, resolveTextureDescriptor} from "../../core/rendering/texture/TextureDescriptorUtilities.ts";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The WebGL implementation of ITexture2D.
|
|
@@ -25,7 +25,7 @@ export class WebGlTexture2D extends ATexture2D {
|
|
|
25
25
|
*/
|
|
26
26
|
constructor(
|
|
27
27
|
private readonly _framework: IFramework,
|
|
28
|
-
textureDescriptor:
|
|
28
|
+
textureDescriptor: ResolvedTextureDescriptor
|
|
29
29
|
) {
|
|
30
30
|
super(textureDescriptor);
|
|
31
31
|
this._graphicsDevice = this._framework.renderer.graphicsDevice as WebGlGraphicsDevice;
|
|
@@ -121,12 +121,13 @@ export class WebGlTexture2D extends ATexture2D {
|
|
|
121
121
|
let texture = WebGlTexture2D._defaultFilled.get(framework);
|
|
122
122
|
if (!texture || texture.state === State.DISPOSED) {
|
|
123
123
|
|
|
124
|
-
const desc =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
const desc = resolveTextureDescriptor({
|
|
125
|
+
width: 1,
|
|
126
|
+
height: 1,
|
|
127
|
+
data: [new Uint8Array([255, 255, 255, 255])],
|
|
128
|
+
textureFormat: framework.renderer.preferredTextureFormat,
|
|
129
|
+
label: "RisDefaultFilledTexture",
|
|
130
|
+
});
|
|
130
131
|
|
|
131
132
|
texture = new WebGlTexture2D(framework, desc);
|
|
132
133
|
texture.initialize();
|
|
@@ -3,14 +3,16 @@ import {
|
|
|
3
3
|
type IFramework,
|
|
4
4
|
type ITexture2D,
|
|
5
5
|
type ITextureFactory,
|
|
6
|
-
|
|
6
|
+
type ITextureDescriptor,
|
|
7
7
|
TextureFormat,
|
|
8
8
|
TextureUsage,
|
|
9
9
|
TextureUtilities
|
|
10
10
|
} from "../../api/index.ts"
|
|
11
11
|
import {WebGlTexture2D} from "./WebGlTexture2D.ts";
|
|
12
|
-
import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, VkFormat} from "ris-ktx2";
|
|
12
|
+
import {type IKtx2Texture, KtxDFTransfer, KtxTranscodeFlags, KtxTranscodeFormat, VkFormat} from "ris-ktx2";
|
|
13
13
|
import {vec2} from "gl-matrix";
|
|
14
|
+
import {ColorSpace} from "../../api/rendering/enums.ts";
|
|
15
|
+
import {resolveTextureDescriptor} from "../../core/rendering/texture/TextureDescriptorUtilities.ts";
|
|
14
16
|
|
|
15
17
|
export class WebGlTextureFactory implements ITextureFactory {
|
|
16
18
|
|
|
@@ -22,51 +24,55 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/** @inheritDoc */
|
|
25
|
-
public createFromKtx2(ktxTexture: IKtx2Texture, descriptor?:
|
|
26
|
-
|
|
27
|
+
public createFromKtx2(ktxTexture: IKtx2Texture, descriptor?: ITextureDescriptor): ITexture2D {
|
|
28
|
+
const desc = resolveTextureDescriptor(descriptor);
|
|
27
29
|
const vkFormat = ktxTexture.vkFormat;
|
|
28
30
|
|
|
29
31
|
// Ktx2 will have different cases, for now we consider simple 2d case.
|
|
30
32
|
const numLevels = ktxTexture.numLevels;
|
|
31
33
|
let transcodeFormat = KtxTranscodeFormat.NO_SELECTION;
|
|
32
|
-
let textureFormat =
|
|
34
|
+
let textureFormat = desc.textureFormat;
|
|
33
35
|
const gpuFeatures = this._framework.graphicsDevice.features;
|
|
34
36
|
|
|
37
|
+
const srgb = ktxTexture.oetf == KtxDFTransfer.SRGB;
|
|
38
|
+
const preferSrgb = this._framework.renderer.preferredColorSpace == ColorSpace.SRGB;
|
|
39
|
+
|
|
35
40
|
if (ktxTexture.needsTranscoding && vkFormat == VkFormat.UNDEFINED)
|
|
36
41
|
{
|
|
37
42
|
// If descriptor format is UNDEFINED, we will use format according to the GPU features.
|
|
38
|
-
if(
|
|
43
|
+
if(desc.textureFormat == TextureFormat.UNDEFINED)
|
|
39
44
|
{
|
|
40
45
|
// BC7 needs BPTC (supportsTextureCompressionBC), BC3 needs S3TC.
|
|
41
46
|
if(gpuFeatures.supportsTextureCompressionBC)
|
|
42
47
|
{
|
|
43
48
|
transcodeFormat = KtxTranscodeFormat.BC7_RGBA;
|
|
44
|
-
textureFormat = TextureFormat.BC7_RGBA_UNORM;
|
|
49
|
+
textureFormat = srgb ? TextureFormat.BC7_RGBA_SRGB : TextureFormat.BC7_RGBA_UNORM;
|
|
45
50
|
}
|
|
46
51
|
else if(gpuFeatures.supportsTextureCompressionASTC)
|
|
47
52
|
{
|
|
48
53
|
transcodeFormat = KtxTranscodeFormat.ASTC_4X4_RGBA;
|
|
49
|
-
textureFormat = TextureFormat.ASTC_4X4_RGBA_UNORM
|
|
54
|
+
textureFormat = srgb ? TextureFormat.ASTC_4X4_RGBA_SRGB : TextureFormat.ASTC_4X4_RGBA_UNORM;
|
|
50
55
|
}
|
|
51
56
|
else if(gpuFeatures.supportsTextureCompressionS3TC)
|
|
52
57
|
{
|
|
53
58
|
transcodeFormat = KtxTranscodeFormat.BC3_RGBA;
|
|
54
|
-
textureFormat = TextureFormat.BC3_RGBA_UNORM;
|
|
59
|
+
textureFormat = srgb ? TextureFormat.BC3_RGBA_SRGB : TextureFormat.BC3_RGBA_UNORM;
|
|
55
60
|
}
|
|
56
61
|
else if(gpuFeatures.supportsTextureCompressionETC2)
|
|
57
62
|
{
|
|
58
63
|
transcodeFormat = KtxTranscodeFormat.ETC2_RGBA;
|
|
59
|
-
textureFormat = TextureFormat.ETC2_RGBA8_UNORM;
|
|
64
|
+
textureFormat = srgb ? TextureFormat.ETC2_RGBA8_SRGB : TextureFormat.ETC2_RGBA8_UNORM;
|
|
60
65
|
}
|
|
61
66
|
else if(gpuFeatures.supportsTextureCompressionPVRTC)
|
|
62
67
|
{
|
|
63
68
|
transcodeFormat = KtxTranscodeFormat.PVRTC1_4_RGBA;
|
|
69
|
+
// Does not have SRGB equivalent.
|
|
64
70
|
textureFormat = TextureFormat.PVRTC_4BPPV1_RGBA;
|
|
65
71
|
}
|
|
66
72
|
else
|
|
67
73
|
{
|
|
68
74
|
transcodeFormat = KtxTranscodeFormat.RGBA32;
|
|
69
|
-
textureFormat = TextureFormat.RGBA_8_UNORM;
|
|
75
|
+
textureFormat = srgb ? TextureFormat.RGBA_8_UNORM_SRGB : TextureFormat.RGBA_8_UNORM;
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
else
|
|
@@ -75,21 +81,19 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
ktxTexture.transcodeBasis(transcodeFormat, KtxTranscodeFlags.HIGH_QUALITY);
|
|
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
|
-
}
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
86
|
// No transcoding path, the vkFormat already says linear or sRGB.
|
|
87
87
|
textureFormat = TextureUtilities.convertVkFormatToTextureFormat(vkFormat);
|
|
88
|
+
if(!srgb && preferSrgb && !TextureUtilities.isSrgbFormat(textureFormat)){
|
|
89
|
+
textureFormat = TextureUtilities.convertToSrgbVariant(textureFormat);
|
|
90
|
+
}
|
|
91
|
+
else if(srgb && !preferSrgb && TextureUtilities.isSrgbFormat(textureFormat)){
|
|
92
|
+
textureFormat = TextureUtilities.convertToLinearVariant(textureFormat);
|
|
93
|
+
}
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const blockSize = TextureUtilities.getBlockSize(textureFormat);
|
|
96
|
+
const blockSize = ktxTexture.getTextureFormatInfo(ktxTexture.vkFormat);
|
|
93
97
|
if (!blockSize) {
|
|
94
98
|
throw new Error(`Unknown block size for texture format ${textureFormat}.`);
|
|
95
99
|
}
|
|
@@ -100,40 +104,20 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
100
104
|
data.push(ktxTexture.getImage(i));
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
const textureDescriptor =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const textureDescriptor = resolveTextureDescriptor({
|
|
108
|
+
...desc,
|
|
109
|
+
width: ktxTexture.width,
|
|
110
|
+
height: ktxTexture.height,
|
|
111
|
+
data,
|
|
112
|
+
textureFormat,
|
|
113
|
+
blockSize: vec2.fromValues(blockSize.blockWidth, blockSize.blockHeight),
|
|
114
|
+
});
|
|
110
115
|
|
|
111
116
|
const texture = new WebGlTexture2D(this._framework, textureDescriptor);
|
|
112
117
|
texture.initialize();
|
|
113
118
|
return texture;
|
|
114
119
|
}
|
|
115
120
|
|
|
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
|
-
|
|
137
121
|
/** @inheritdoc */
|
|
138
122
|
public create(
|
|
139
123
|
width: number, height: number,
|
|
@@ -155,15 +139,16 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
155
139
|
throw new Error("channels must be greater than 0.");
|
|
156
140
|
}
|
|
157
141
|
|
|
158
|
-
const desc =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
142
|
+
const desc = resolveTextureDescriptor({
|
|
143
|
+
width,
|
|
144
|
+
height,
|
|
145
|
+
// @ts-ignore HTMLImageElement is uploaded as-is by WebGlTexture2D.
|
|
146
|
+
data: [data],
|
|
147
|
+
textureFormat,
|
|
148
|
+
textureUsage,
|
|
149
|
+
generateMipmaps: useMipMaps,
|
|
150
|
+
label,
|
|
151
|
+
});
|
|
167
152
|
|
|
168
153
|
const texture = new WebGlTexture2D(
|
|
169
154
|
this._framework,
|
|
@@ -191,13 +176,14 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
191
176
|
textureFormat = this._framework.renderer.preferredTextureFormat;
|
|
192
177
|
}
|
|
193
178
|
|
|
194
|
-
const desc =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
179
|
+
const desc = resolveTextureDescriptor({
|
|
180
|
+
width,
|
|
181
|
+
height,
|
|
182
|
+
textureUsage,
|
|
183
|
+
textureFormat,
|
|
184
|
+
label,
|
|
185
|
+
generateMipmaps: useMipmap,
|
|
186
|
+
});
|
|
201
187
|
|
|
202
188
|
// Fast path: avoid generating & uploading a big CPU-side buffer when not needed.
|
|
203
189
|
if (!color || color.equals(Color.black())) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export class WebGlErrorUtilities {
|
|
2
2
|
|
|
3
3
|
private readonly _map: Record<number, string> = {
|
|
4
|
-
|
|
4
|
+
1281: "INVALID_VALUE",
|
|
5
|
+
1282: "INVALID_OPERATION",
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -9,7 +10,7 @@ export class WebGlErrorUtilities {
|
|
|
9
10
|
* @param error The error code.
|
|
10
11
|
* @return The string of error code.
|
|
11
12
|
*/
|
|
12
|
-
public errorToStr(error: number)
|
|
13
|
+
public errorToStr(error: number): string {
|
|
13
14
|
return this._map[error] ?? error.toString();
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type IFramework,
|
|
3
3
|
State,
|
|
4
|
-
TextureDescriptor,
|
|
5
4
|
TextureUsage,
|
|
6
5
|
TextureUtilities,
|
|
7
6
|
type ITextureView,
|
|
@@ -13,6 +12,7 @@ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
|
13
12
|
import {GpuTextureUsage, type GpuTexture, type GpuTextureView} from "../WebGpuTypes.ts";
|
|
14
13
|
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
15
14
|
import {WebGpuTextureView} from "./WebGpuTextureView.ts";
|
|
15
|
+
import {type ResolvedTextureDescriptor, resolveTextureDescriptor} from "../../core/rendering/texture/TextureDescriptorUtilities.ts";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The WebGPU 2D texture.
|
|
@@ -34,7 +34,7 @@ export class WebGpuTexture2D extends ATexture2D {
|
|
|
34
34
|
* @param descriptor The texture descriptor.
|
|
35
35
|
* @param image An optional image to upload instead of `descriptor.data`.
|
|
36
36
|
*/
|
|
37
|
-
public constructor(framework: IFramework, descriptor:
|
|
37
|
+
public constructor(framework: IFramework, descriptor: ResolvedTextureDescriptor, image?: HTMLImageElement) {
|
|
38
38
|
super(descriptor);
|
|
39
39
|
this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
|
|
40
40
|
this._image = image;
|
|
@@ -171,13 +171,14 @@ export class WebGpuTexture2D extends ATexture2D {
|
|
|
171
171
|
public static getOrCreateDefault(framework: IFramework): WebGpuTexture2D {
|
|
172
172
|
let texture = WebGpuTexture2D._defaultFilled.get(framework);
|
|
173
173
|
if (!texture || texture.state === State.DISPOSED) {
|
|
174
|
-
const desc =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
const desc = resolveTextureDescriptor({
|
|
175
|
+
width: 1,
|
|
176
|
+
height: 1,
|
|
177
|
+
data: [new Uint8Array([255, 255, 255, 255])],
|
|
178
|
+
textureFormat: framework.renderer.preferredTextureFormat,
|
|
179
|
+
textureUsage: TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_DST,
|
|
180
|
+
label: "RisDefaultFilledTexture",
|
|
181
|
+
});
|
|
181
182
|
texture = new WebGpuTexture2D(framework, desc);
|
|
182
183
|
texture.initialize();
|
|
183
184
|
WebGpuTexture2D._defaultFilled.set(framework, texture);
|
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
type IFramework,
|
|
4
4
|
type ITexture2D,
|
|
5
5
|
type ITextureFactory,
|
|
6
|
-
|
|
6
|
+
type ITextureDescriptor,
|
|
7
7
|
TextureFormat,
|
|
8
8
|
TextureUsage,
|
|
9
9
|
} from "../../api/index.ts";
|
|
10
10
|
import type {IKtx2Texture} from "ris-ktx2";
|
|
11
11
|
import {WebGpuTexture2D} from "./WebGpuTexture2D.ts";
|
|
12
|
+
import {resolveTextureDescriptor} from "../../core/rendering/texture/TextureDescriptorUtilities.ts";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* The WebGPU texture factory.
|
|
@@ -24,7 +25,7 @@ export class WebGpuTextureFactory implements ITextureFactory {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/** @inheritDoc */
|
|
27
|
-
public createFromKtx2(_ktxTexture: IKtx2Texture, _descriptor?:
|
|
28
|
+
public createFromKtx2(_ktxTexture: IKtx2Texture, _descriptor?: ITextureDescriptor): ITexture2D {
|
|
28
29
|
throw new Error("createFromKtx2 is not implemented for WebGPU.");
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -51,13 +52,14 @@ export class WebGpuTextureFactory implements ITextureFactory {
|
|
|
51
52
|
textureFormat = this._framework.renderer.preferredTextureFormat;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
const desc =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const desc = resolveTextureDescriptor({
|
|
56
|
+
width,
|
|
57
|
+
height,
|
|
58
|
+
textureFormat,
|
|
59
|
+
textureUsage,
|
|
60
|
+
generateMipmaps: useMipMaps,
|
|
61
|
+
label: label ?? null,
|
|
62
|
+
});
|
|
61
63
|
|
|
62
64
|
let image: HTMLImageElement | undefined;
|
|
63
65
|
if (typeof HTMLImageElement !== "undefined" && data instanceof HTMLImageElement) {
|
|
@@ -90,13 +92,14 @@ export class WebGpuTextureFactory implements ITextureFactory {
|
|
|
90
92
|
textureFormat = this._framework.renderer.preferredTextureFormat;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const desc =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
const desc = resolveTextureDescriptor({
|
|
96
|
+
width,
|
|
97
|
+
height,
|
|
98
|
+
textureUsage,
|
|
99
|
+
textureFormat,
|
|
100
|
+
label,
|
|
101
|
+
generateMipmaps: useMipmap,
|
|
102
|
+
});
|
|
100
103
|
|
|
101
104
|
// WebGPU zero-initializes textures, so transparent black needs no upload; neither do depth textures.
|
|
102
105
|
if (!color || (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 0)) {
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { TextureFormat } from "./TextureFormat.js";
|
|
2
|
-
import { vec2 } from "gl-matrix";
|
|
3
|
-
/**
|
|
4
|
-
* The texture descriptor.
|
|
5
|
-
*/
|
|
6
|
-
export declare class TextureDescriptor {
|
|
7
|
-
/**
|
|
8
|
-
* The texture width.
|
|
9
|
-
*/
|
|
10
|
-
width: number;
|
|
11
|
-
/**
|
|
12
|
-
* The texture height.
|
|
13
|
-
*/
|
|
14
|
-
height: number;
|
|
15
|
-
/**
|
|
16
|
-
* The texture format.
|
|
17
|
-
* By default, it is UNDEFINED.
|
|
18
|
-
*/
|
|
19
|
-
textureFormat: TextureFormat;
|
|
20
|
-
/**
|
|
21
|
-
* The texture usage.
|
|
22
|
-
* By default, it is TEXTURE_BINDING | COPY_DST.
|
|
23
|
-
*/
|
|
24
|
-
textureUsage: number;
|
|
25
|
-
/**
|
|
26
|
-
* The texture label.
|
|
27
|
-
*/
|
|
28
|
-
label: string | null;
|
|
29
|
-
/**
|
|
30
|
-
* The data per mip level.
|
|
31
|
-
*/
|
|
32
|
-
data?: Uint8Array[];
|
|
33
|
-
/**
|
|
34
|
-
* Should mipmaps be generated.
|
|
35
|
-
*/
|
|
36
|
-
generateMipmaps: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* The block size of a texture, which must be set for compressed textures.
|
|
39
|
-
*/
|
|
40
|
-
blockSize?: vec2;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=TextureDescriptor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextureDescriptor.d.ts","sourceRoot":"","sources":["../../../../src/api/rendering/texture/TextureDescriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/B;;GAEG;AACH,qBAAa,iBAAiB;IAE1B;;OAEG;IACI,KAAK,EAAE,MAAM,CAAK;IAEzB;;OAEG;IACI,MAAM,EAAE,MAAM,CAAK;IAE1B;;;OAGG;IACI,aAAa,gBAA2B;IAE/C;;;OAGG;IACI,YAAY,SAAwD;IAE3E;;OAEG;IACI,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEnC;;OAEG;IACI,IAAI,CAAC,EAAE,UAAU,EAAE,CAAa;IAEvC;;OAEG;IACI,eAAe,UAAS;IAE/B;;OAEG;IACI,SAAS,CAAC,EAAE,IAAI,CAAC;CAE3B"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {TextureFormat} from "./TextureFormat.ts";
|
|
2
|
-
import {TextureUsage} from "./TextureUsage.ts";
|
|
3
|
-
import {vec2} from "gl-matrix";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The texture descriptor.
|
|
7
|
-
*/
|
|
8
|
-
export class TextureDescriptor {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The texture width.
|
|
12
|
-
*/
|
|
13
|
-
public width: number = 0;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The texture height.
|
|
17
|
-
*/
|
|
18
|
-
public height: number = 0;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The texture format.
|
|
22
|
-
* By default, it is UNDEFINED.
|
|
23
|
-
*/
|
|
24
|
-
public textureFormat = TextureFormat.UNDEFINED;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The texture usage.
|
|
28
|
-
* By default, it is TEXTURE_BINDING | COPY_DST.
|
|
29
|
-
*/
|
|
30
|
-
public textureUsage = TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_DST;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The texture label.
|
|
34
|
-
*/
|
|
35
|
-
public label: string | null = null;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The data per mip level.
|
|
39
|
-
*/
|
|
40
|
-
public data?: Uint8Array[] = undefined;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Should mipmaps be generated.
|
|
44
|
-
*/
|
|
45
|
-
public generateMipmaps = false;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The block size of a texture, which must be set for compressed textures.
|
|
49
|
-
*/
|
|
50
|
-
public blockSize?: vec2;
|
|
51
|
-
|
|
52
|
-
}
|