@@ -13,6 +13,7 @@ export interface ITextureRecorderData {
13
13
format ?: number ;
14
14
type ?: number ;
15
15
depth ?: number ;
16
+ isCompressed : boolean ;
16
17
}
17
18
18
19
export class Texture2DRecorder extends BaseRecorder < WebGLTexture > {
@@ -71,24 +72,35 @@ export class Texture2DRecorder extends BaseRecorder<WebGLTexture> {
71
72
}
72
73
73
74
const previousLength = ( instance as any ) . __SPECTOR_Object_CustomData ? ( instance as any ) . __SPECTOR_Object_CustomData . length : 0 ;
74
- const cubeMapMultiplier = target === "TEXTURE_2D" ? 1 : 6 ;
75
- let internalFormat = customData . internalFormat ;
76
-
77
- // @ivanpopelyshev : this hack is made according to tests on PixiJS applications
78
- // Float textures is not a rare case
79
- // WebGL1 does not have RGBA32F, RGBA16F, we need to look in `type` field
80
- if ( internalFormat === WebGlConstants . RGBA . value ) {
81
- if ( customData . type === WebGlConstants . FLOAT . value ) {
82
- internalFormat = WebGlConstants . RGBA32F . value ;
75
+ if ( customData . isCompressed ) {
76
+ // Compressed textures are worth the size of their data.
77
+ if ( functionInformation . arguments . length >= 7 ) {
78
+ const viewOrSize = functionInformation . arguments [ 6 ] ;
79
+ customData . length = ( typeof viewOrSize === "number" ) ? viewOrSize : viewOrSize ?. byteLength ;
83
80
}
84
- if ( customData . type === WebGlConstants . HALF_FLOAT_OES . value ) {
85
- internalFormat = WebGlConstants . RGBA16F . value ;
81
+ }
82
+ else {
83
+ const cubeMapMultiplier = target === "TEXTURE_2D" ? 1 : 6 ;
84
+ let internalFormat = customData . internalFormat ;
85
+
86
+ // @ivanpopelyshev : this hack is made according to tests on PixiJS applications
87
+ // Float textures is not a rare case
88
+ // WebGL1 does not have RGBA32F, RGBA16F, we need to look in `type` field
89
+ if ( internalFormat === WebGlConstants . RGBA . value ) {
90
+ if ( customData . type === WebGlConstants . FLOAT . value ) {
91
+ internalFormat = WebGlConstants . RGBA32F . value ;
92
+ }
93
+ if ( customData . type === WebGlConstants . HALF_FLOAT_OES . value ) {
94
+ internalFormat = WebGlConstants . RGBA16F . value ;
95
+ }
86
96
}
97
+
98
+ // @ivanpopelyshev : This calculation should be fine for most cases, but not if we start counting mips
99
+ // TODO: move width/height inside and make pluggable functions based on compressed textures extensions
100
+ customData . length = ( customData . width * customData . height * cubeMapMultiplier * this . getByteSizeForInternalFormat ( internalFormat ) ) ;
87
101
}
88
102
89
- // @ivanpopelyshev : This calculation should be fine for most cases, but not if we start counting mips
90
- // TODO: move width/height inside and make pluggable functions based on compressed textures extensions
91
- customData . length = ( customData . width * customData . height * cubeMapMultiplier * this . getByteSizeForInternalFormat ( internalFormat ) ) | 0 ;
103
+ customData . length = customData . length | 0 ;
92
104
( instance as any ) . __SPECTOR_Object_CustomData = customData ;
93
105
return customData . length - previousLength ;
94
106
}
@@ -117,6 +129,7 @@ export class Texture2DRecorder extends BaseRecorder<WebGLTexture> {
117
129
width : functionInformation . arguments [ 3 ] ,
118
130
height : functionInformation . arguments [ 4 ] ,
119
131
length : 0 ,
132
+ isCompressed : false ,
120
133
} ;
121
134
}
122
135
@@ -140,6 +153,7 @@ export class Texture2DRecorder extends BaseRecorder<WebGLTexture> {
140
153
width : functionInformation . arguments [ 3 ] ,
141
154
height : functionInformation . arguments [ 4 ] ,
142
155
length : 0 ,
156
+ isCompressed : true ,
143
157
} ;
144
158
}
145
159
@@ -165,6 +179,7 @@ export class Texture2DRecorder extends BaseRecorder<WebGLTexture> {
165
179
format : functionInformation . arguments [ 6 ] ,
166
180
type : functionInformation . arguments [ 7 ] ,
167
181
length : 0 ,
182
+ isCompressed : false ,
168
183
} ;
169
184
}
170
185
else if ( functionInformation . arguments . length === 6 ) {
@@ -178,6 +193,7 @@ export class Texture2DRecorder extends BaseRecorder<WebGLTexture> {
178
193
format : functionInformation . arguments [ 3 ] ,
179
194
type : functionInformation . arguments [ 4 ] ,
180
195
length : 0 ,
196
+ isCompressed : false ,
181
197
} ;
182
198
}
183
199
0 commit comments