Skip to content

Commit 97cc79d

Browse files
Release (#108)
* Fix 102 (#106) * fix: use internal format in webgl2 #102 * chore: commit changeset * chore(release): bump version (#107) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 879028a commit 97cc79d

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @antv/g-device-api
22

3+
## 1.4.7
4+
5+
### Patch Changes
6+
7+
- 72ddd05: Use internal format in webgl2 when calling texImage2D.
8+
39
## 1.4.6
410

511
### Patch Changes

examples/demos/set-image-data.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,35 @@ export async function render(
1313
swapChain.configureSwapChain($canvas.width, $canvas.height);
1414
const device = swapChain.getDevice();
1515

16-
const dataTexture = device.createTexture({
17-
format: Format.U8_LUMINANCE,
16+
// const luminance = device.createTexture({
17+
// format: Format.U8_LUMINANCE,
18+
// width: 1,
19+
// height: 1,
20+
// usage: TextureUsage.SAMPLED,
21+
// pixelStore: {
22+
// unpackFlipY: false,
23+
// packAlignment: 1,
24+
// },
25+
// mipLevelCount: 0,
26+
// });
27+
// luminance.setImageData([new Uint8Array([10])]);
28+
29+
const floatRGB = device.createTexture({
30+
format: Format.F32_RGB,
1831
width: 1,
1932
height: 1,
2033
usage: TextureUsage.SAMPLED,
2134
pixelStore: {
2235
unpackFlipY: false,
23-
packAlignment: 1,
36+
packAlignment: 4,
2437
},
2538
mipLevelCount: 0,
2639
});
27-
dataTexture.setImageData([new Uint8Array([10])]);
40+
floatRGB.setImageData([new Float32Array([10, 20, 30])]);
2841

2942
return () => {
30-
dataTexture.destroy();
43+
// luminance.destroy();
44+
floatRGB.destroy();
3145
device.destroy();
3246

3347
// For debug.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g-device-api",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"description": "A Device API references WebGPU implementations",
55
"keywords": [
66
"antv",

src/webgl/Device.ts

+29
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,35 @@ export class Device_GL implements SwapChain, Device {
688688
}
689689
}
690690

691+
/**
692+
* Only works in WebGL2
693+
* @see https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html
694+
*/
695+
translateInternalTextureFormat(fmt: Format): GLenum {
696+
switch (fmt) {
697+
case Format.F32_R:
698+
return GL.R32F;
699+
case Format.F32_RG:
700+
return GL.RG32F;
701+
case Format.F32_RGB:
702+
return GL.RGB32F;
703+
case Format.F32_RGBA:
704+
return GL.RGBA32F;
705+
case Format.F16_R:
706+
return GL.R16F;
707+
case Format.F16_RG:
708+
return GL.RG16F;
709+
case Format.F16_RGB:
710+
return GL.RGB16F;
711+
case Format.F16_RGBA:
712+
return GL.RGBA16F;
713+
default:
714+
break;
715+
}
716+
717+
return this.translateTextureFormat(fmt);
718+
}
719+
691720
translateTextureFormat(fmt: Format): GLenum {
692721
if (
693722
isTextureFormatCompressed(fmt) ||

src/webgl/Texture.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ export class Texture_GL extends ResourceBase_GL implements Texture {
253253
gl.bindTexture(this.gl_target, this.gl_texture);
254254

255255
const gl_format = this.device.translateTextureFormat(this.format);
256+
// In WebGL 1, this must be the same as internalformat
257+
const gl_internal_format = isWebGL2(gl)
258+
? this.device.translateInternalTextureFormat(this.format)
259+
: gl_format;
256260
const gl_type = this.device.translateTextureType(this.format);
257261

258262
this.preprocessImage();
@@ -289,7 +293,7 @@ export class Texture_GL extends ResourceBase_GL implements Texture {
289293
gl.texImage3D(
290294
gl_target,
291295
lod,
292-
gl_format,
296+
gl_internal_format,
293297
width,
294298
height,
295299
this.depthOrArrayLayers,
@@ -303,7 +307,7 @@ export class Texture_GL extends ResourceBase_GL implements Texture {
303307
gl.texImage2D(
304308
gl_target,
305309
lod,
306-
gl_format,
310+
gl_internal_format,
307311
width,
308312
height,
309313
0, // border must be 0

0 commit comments

Comments
 (0)