11import {
2- type CanvasRenderer ,
2+ Application ,
33 ColorLayer ,
4- game ,
54 loader ,
65 Renderable ,
76 Sprite ,
8- state ,
97 Text ,
108 video ,
119 type WebGLRenderer ,
@@ -40,10 +38,16 @@ const textureAssets = [
4038 src : "assets/compressedTextures/format_bc7_unorm.ktx" ,
4139 } ,
4240 {
43- name : "ktx-astc" ,
44- label : "KTX (ASTC)" ,
45- ext : "astc" ,
46- src : "assets/compressedTextures/format_astc_4x4_srgb.ktx" ,
41+ name : "pvr-pvrtc4" ,
42+ label : "PVR (PVRTC 4bpp)" ,
43+ ext : "pvrtc" ,
44+ src : "assets/compressedTextures/shannon-pvrtc-4bpp-rgba.pvr" ,
45+ } ,
46+ {
47+ name : "ktx-pvrtc" ,
48+ label : "KTX (PVRTC)" ,
49+ ext : "pvrtc" ,
50+ src : "assets/compressedTextures/format_pvrtc1_4bpp_unorm.ktx" ,
4751 } ,
4852 {
4953 name : "ktx-etc2" ,
@@ -52,10 +56,10 @@ const textureAssets = [
5256 src : "assets/compressedTextures/format_etc2_r8g8b8_srgb.ktx" ,
5357 } ,
5458 {
55- name : "ktx2-bc1 " ,
56- label : "KTX2 (BC1 )" ,
57- ext : "s3tc " ,
58- src : "assets/compressedTextures/synthetic_bc1.ktx2 " ,
59+ name : "ktx-astc4 " ,
60+ label : "KTX (ASTC 4x4 )" ,
61+ ext : "astc " ,
62+ src : "assets/compressedTextures/format_astc_4x4_srgb.ktx " ,
5963 } ,
6064 {
6165 name : "pkm-etc1" ,
@@ -70,33 +74,38 @@ const textureAssets = [
7074 src : "assets/compressedTextures/synthetic_etc2.pkm" ,
7175 } ,
7276 {
73- name : "pvr-4bpp " ,
74- label : "PVR (PVRTC )" ,
75- ext : "pvrtc " ,
76- src : "assets/compressedTextures/shannon-pvrtc-4bpp-rgba.pvr " ,
77+ name : "ktx2-bc1 " ,
78+ label : "KTX2 (BC1 )" ,
79+ ext : "s3tc " ,
80+ src : "assets/compressedTextures/synthetic_bc1.ktx2 " ,
7781 } ,
7882] ;
7983
84+ /**
85+ * A display renderable that shows compressed texture support info and loaded textures.
86+ */
8087class CompressedTextureDisplay extends Renderable {
88+ formats : ReturnType < WebGLRenderer [ "getSupportedCompressedTextureFormats" ] > ;
89+ sprites : { sprite : Sprite ; label : string ; x : number ; y : number } [ ] = [ ] ;
8190 titleFont : Text ;
8291 font : Text ;
8392 smallFont : Text ;
84- formats : Record < string , unknown > ;
85- loadedAssets : typeof textureAssets ;
86- sprites : { sprite : Sprite ; label : string ; x : number ; y : number } [ ] = [ ] ;
8793
8894 constructor (
89- formats : Record < string , unknown > ,
90- loadedAssets : typeof textureAssets ,
95+ app : Application ,
96+ formats : ReturnType < WebGLRenderer [ "getSupportedCompressedTextureFormats" ] > ,
97+ loadedAssets : ( typeof textureAssets ) [ number ] [ ] ,
9198 ) {
92- super ( 0 , 0 , game . viewport . width , game . viewport . height ) ;
99+ super ( 0 , 0 , app . viewport . width , app . viewport . height ) ;
100+
93101 this . formats = formats ;
94- this . loadedAssets = loadedAssets ;
95102 this . anchorPoint . set ( 0 , 0 ) ;
103+ this . floating = true ;
104+ this . isPersistent = true ;
96105
97106 this . titleFont = new Text ( 0 , 0 , {
98107 font : "Arial" ,
99- size : "20px " ,
108+ size : "24px " ,
100109 fillStyle : "#FFFFFF" ,
101110 } ) ;
102111 this . font = new Text ( 0 , 0 , {
@@ -114,7 +123,7 @@ class CompressedTextureDisplay extends Renderable {
114123 // create sprites for each loaded compressed texture
115124 const cols = Math . min ( Math . max ( loadedAssets . length , 1 ) , 4 ) ;
116125 const spacing = 160 ;
117- const startX = game . viewport . width / 2 - ( ( cols - 1 ) * spacing ) / 2 ;
126+ const startX = app . viewport . width / 2 - ( ( cols - 1 ) * spacing ) / 2 ;
118127 const startY = 200 ;
119128
120129 for ( let i = 0 ; i < loadedAssets . length ; i ++ ) {
@@ -143,7 +152,7 @@ class CompressedTextureDisplay extends Renderable {
143152
144153 /** @ignore */
145154 drawText (
146- renderer : WebGLRenderer | CanvasRenderer ,
155+ renderer : WebGLRenderer ,
147156 font : Text ,
148157 text : string ,
149158 x : number ,
@@ -156,7 +165,7 @@ class CompressedTextureDisplay extends Renderable {
156165 font . postDraw ( renderer ) ;
157166 }
158167
159- override draw ( renderer : WebGLRenderer | CanvasRenderer ) {
168+ override draw ( renderer : WebGLRenderer ) {
160169 let y = 10 ;
161170 const x = 10 ;
162171
@@ -182,7 +191,8 @@ class CompressedTextureDisplay extends Renderable {
182191
183192 for ( const [ key , label ] of extensions ) {
184193 const supported =
185- this . formats [ key ] !== null && this . formats [ key ] !== undefined ;
194+ ( this . formats as Record < string , unknown > ) [ key ] !== null &&
195+ ( this . formats as Record < string , unknown > ) [ key ] !== undefined ;
186196 this . font . fillStyle . parseCSS ( supported ? "#4ade80" : "#f87171" ) ;
187197 this . drawText (
188198 renderer ,
@@ -211,7 +221,7 @@ class CompressedTextureDisplay extends Renderable {
211221 }
212222
213223 // Footer info
214- const footerY = game . viewport . height - 40 ;
224+ const footerY = this . height - 40 ;
215225 this . font . fillStyle . parseCSS ( "#64748b" ) ;
216226 this . drawText (
217227 renderer ,
@@ -224,18 +234,13 @@ class CompressedTextureDisplay extends Renderable {
224234}
225235
226236const createGame = ( ) => {
227- if (
228- ! video . init ( 800 , 600 , {
229- parent : "screen" ,
230- scaleMethod : "flex" ,
231- renderer : video . WEBGL ,
232- } )
233- ) {
234- alert ( "Your browser does not support WebGL." ) ;
235- return ;
236- }
237+ const app = new Application ( 800 , 600 , {
238+ parent : "screen" ,
239+ scaleMethod : "flex" ,
240+ renderer : video . WEBGL ,
241+ } ) ;
237242
238- const renderer = video . renderer as WebGLRenderer ;
243+ const renderer = app . renderer as WebGLRenderer ;
239244 const formats = renderer . getSupportedCompressedTextureFormats ( ) ;
240245
241246 // Filter texture assets to only those whose extension is supported
@@ -252,11 +257,9 @@ const createGame = () => {
252257 } ) ) ;
253258
254259 const showScene = ( ) => {
255- state . change ( state . DEFAULT , true ) ;
256- game . world . reset ( ) ;
257- game . world . addChild ( new ColorLayer ( "background" , "#0f172a" ) , 0 ) ;
258- game . world . addChild (
259- new CompressedTextureDisplay ( formats , supportedAssets ) ,
260+ app . world . addChild ( new ColorLayer ( "background" , "#0f172a" ) , 0 ) ;
261+ app . world . addChild (
262+ new CompressedTextureDisplay ( app , formats , supportedAssets ) ,
260263 1 ,
261264 ) ;
262265 } ;
0 commit comments