11import DataMap from './DataMap.js' ;
2- import { DepthTexture , DepthStencilFormat , UnsignedInt248Type } from 'three' ;
2+ import { Vector2 , DepthTexture , DepthStencilFormat , UnsignedInt248Type } from 'three' ;
3+
4+ const _size = new Vector2 ( ) ;
35
46class Textures extends DataMap {
57
@@ -17,6 +19,7 @@ class Textures extends DataMap {
1719 const renderTargetData = this . get ( renderTarget ) ;
1820
1921 const texture = renderTarget . texture ;
22+ const size = this . getSize ( texture ) ;
2023
2124 let depthTexture = renderTarget . depthTexture || renderTargetData . depthTexture ;
2225
@@ -25,23 +28,23 @@ class Textures extends DataMap {
2528 depthTexture = new DepthTexture ( ) ;
2629 depthTexture . format = DepthStencilFormat ;
2730 depthTexture . type = UnsignedInt248Type ;
28- depthTexture . image . width = texture . image . width ;
29- depthTexture . image . height = texture . image . height ;
31+ depthTexture . image . width = size . width ;
32+ depthTexture . image . height = size . height ;
3033
3134 }
3235
33- if ( renderTargetData . width !== texture . image . width || texture . image . height !== renderTargetData . height ) {
36+ if ( renderTargetData . width !== size . width || size . height !== renderTargetData . height ) {
3437
3538 texture . needsUpdate = true ;
3639 depthTexture . needsUpdate = true ;
3740
38- depthTexture . image . width = texture . image . width ;
39- depthTexture . image . height = texture . image . height ;
41+ depthTexture . image . width = size . width ;
42+ depthTexture . image . height = size . height ;
4043
4144 }
4245
43- renderTargetData . width = texture . image . width ;
44- renderTargetData . height = texture . image . height ;
46+ renderTargetData . width = size . width ;
47+ renderTargetData . height = size . height ;
4548 renderTargetData . texture = texture ;
4649 renderTargetData . depthTexture = depthTexture ;
4750
@@ -171,6 +174,24 @@ class Textures extends DataMap {
171174
172175 }
173176
177+ getSize ( texture , target = _size ) {
178+
179+ if ( texture . isCubeTexture ) {
180+
181+ target . width = texture . image [ 0 ] . width ;
182+ target . height = texture . image [ 0 ] . height ;
183+
184+ } else {
185+
186+ target . width = texture . image . width ;
187+ target . height = texture . image . height ;
188+
189+ }
190+
191+ return target ;
192+
193+ }
194+
174195 _destroyTexture ( texture ) {
175196
176197 this . backend . destroySampler ( texture ) ;
0 commit comments