Skip to content

Commit a992b4b

Browse files
authored
Feature(v2) texture compression (#668)
Reworked the texture compression feature. - fixed ktx loading when sizes are not perfectly divedable by format block sizes. - cleaned up pvr data loading / uploading to webgl. - added astc support (possibly not usable on most devices at this point in time). - compressed textures now properly fire `loaded` and `failed` events.
1 parent 01376c8 commit a992b4b

File tree

6 files changed

+483
-109
lines changed

6 files changed

+483
-109
lines changed

examples/tests/tx-compression.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,64 @@
2020
import type { ExampleSettings } from '../common/ExampleSettings.js';
2121

2222
export default async function ({ renderer, testRoot }: ExampleSettings) {
23-
renderer.createTextNode({
23+
const cn1Label = renderer.createTextNode({
2424
x: 100,
2525
y: 100,
2626
color: 0xffffffff,
2727
alpha: 1.0,
28-
text: 'etc1 compression in .pvr',
28+
text: 'w: 400',
2929
fontFamily: 'Ubuntu',
3030
fontSize: 30,
3131
parent: testRoot,
3232
});
3333

34-
renderer.createNode({
34+
const compressedNode1 = renderer.createNode({
3535
x: 100,
3636
y: 170,
3737
width: 550,
3838
height: 550,
3939
src: '../assets/test-etc1.pvr',
40+
imageType: 'compressed',
4041
parent: testRoot,
4142
});
4243

43-
renderer.createTextNode({
44+
compressedNode1.on('loaded', (node, data) => {
45+
const { width, height } = data.dimensions;
46+
node.width = width;
47+
node.height = height;
48+
49+
cn1Label.text = `w: ${width}, h: ${height}`;
50+
});
51+
52+
compressedNode1.on('failed', (node, error) => {
53+
console.error('compressed error', error);
54+
});
55+
56+
const cn2Label = renderer.createTextNode({
4457
x: 800,
4558
y: 100,
4659
color: 0xffffffff,
4760
alpha: 1.0,
48-
text: 's3tc compression in .ktx',
61+
text: 'w: 333',
4962
fontFamily: 'Ubuntu',
5063
fontSize: 30,
5164
parent: testRoot,
5265
});
5366

54-
renderer.createNode({
67+
const compressedNode2 = renderer.createNode({
5568
x: 800,
5669
y: 170,
5770
width: 400,
5871
height: 400,
5972
src: '../assets/test-s3tc.ktx',
73+
imageType: 'compressed',
6074
parent: testRoot,
6175
});
76+
77+
compressedNode2.on('loaded', (node, data) => {
78+
const { width, height } = data.dimensions;
79+
node.width = width;
80+
node.height = height;
81+
cn2Label.text = `w: ${width}, h: ${height}`;
82+
});
6283
}

src/core/lib/WebGlContextWrapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export class WebGlContextWrapper {
6767
public readonly TEXTURE_WRAP_S;
6868
public readonly TEXTURE_WRAP_T;
6969
public readonly LINEAR;
70+
public readonly LINEAR_MIPMAP_LINEAR;
7071
public readonly CLAMP_TO_EDGE;
7172
public readonly RGB;
7273
public readonly RGBA;
@@ -158,6 +159,7 @@ export class WebGlContextWrapper {
158159
this.TEXTURE_WRAP_S = gl.TEXTURE_WRAP_S;
159160
this.TEXTURE_WRAP_T = gl.TEXTURE_WRAP_T;
160161
this.LINEAR = gl.LINEAR;
162+
this.LINEAR_MIPMAP_LINEAR = gl.LINEAR_MIPMAP_LINEAR;
161163
this.CLAMP_TO_EDGE = gl.CLAMP_TO_EDGE;
162164
this.RGB = gl.RGB;
163165
this.RGBA = gl.RGBA;

0 commit comments

Comments
 (0)