@@ -10,6 +10,7 @@ import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
1010import WebGLExtensions from './utils/WebGLExtensions.js' ;
1111import WebGLCapabilities from './utils/WebGLCapabilities.js' ;
1212import { GLFeatureName } from './utils/WebGLConstants.js' ;
13+
1314//
1415
1516class WebGLBackend extends Backend {
@@ -115,6 +116,24 @@ class WebGLBackend extends Backend {
115116 const renderContextData = this . get ( renderContext ) ;
116117 const previousContext = renderContextData . previousContext ;
117118
119+ const textures = renderContext . textures ;
120+
121+ if ( textures !== null ) {
122+
123+ for ( let i = 0 ; i < textures . length ; i ++ ) {
124+
125+ const texture = textures [ i ] ;
126+
127+ if ( texture . generateMipmaps ) {
128+
129+ this . generateMipmaps ( texture ) ;
130+
131+ }
132+
133+ }
134+
135+ }
136+
118137 this . _currentContext = previousContext ;
119138
120139
@@ -809,9 +828,9 @@ class WebGLBackend extends Backend {
809828
810829 }
811830
812- destroyAttribute ( /* attribute*/ ) {
831+ destroyAttribute ( attribute ) {
813832
814- console . warn ( 'Abstract class.' ) ;
833+ this . attributeUtils . destroyAttribute ( attribute ) ;
815834
816835 }
817836
@@ -855,18 +874,36 @@ class WebGLBackend extends Backend {
855874
856875 const { gl, state } = this ;
857876
858- let fb = null ;
859877 let currentFrameBuffer = null ;
860878
861879 if ( renderContext . textures !== null ) {
862880
863- const renderTargetContextData = this . get ( renderContext . renderTarget ) ;
864- const { samples } = renderContext . renderTarget ;
881+ const renderTarget = renderContext . renderTarget ;
882+ const renderTargetContextData = this . get ( renderTarget ) ;
883+ const { samples } = renderTarget ;
884+ const cubeFace = this . renderer . _activeCubeFace ;
885+ const isCube = renderTarget . isWebGLCubeRenderTarget === true ;
865886
866- fb = renderTargetContextData . framebuffer ;
867887 let msaaFb = renderTargetContextData . msaaFrameBuffer ;
868888 let depthRenderbuffer = renderTargetContextData . depthRenderbuffer ;
869889
890+ let fb ;
891+
892+ if ( isCube ) {
893+
894+ if ( renderTargetContextData . cubeFramebuffers === undefined ) {
895+
896+ renderTargetContextData . cubeFramebuffers = [ ] ;
897+
898+ }
899+
900+ fb = renderTargetContextData . cubeFramebuffers [ cubeFace ] ;
901+
902+ } else {
903+
904+ fb = renderTargetContextData . framebuffer ;
905+
906+ }
870907
871908 if ( fb === undefined ) {
872909
@@ -876,16 +913,30 @@ class WebGLBackend extends Backend {
876913
877914 const textures = renderContext . textures ;
878915
879- for ( let i = 0 ; i < textures . length ; i ++ ) {
916+ if ( isCube ) {
880917
881- const texture = textures [ i ] ;
882- const textureData = this . get ( texture ) ;
883- textureData . renderTarget = renderContext . renderTarget ;
918+ renderTargetContextData . cubeFramebuffers [ cubeFace ] = fb ;
919+ const { textureGPU } = this . get ( textures [ 0 ] ) ;
884920
885- const attachment = gl . COLOR_ATTACHMENT0 + i ;
921+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace , textureGPU , 0 ) ;
922+
923+ } else {
886924
925+ for ( let i = 0 ; i < textures . length ; i ++ ) {
887926
888- gl . framebufferTexture2D ( gl . FRAMEBUFFER , attachment , gl . TEXTURE_2D , textureData . textureGPU , 0 ) ;
927+ const texture = textures [ i ] ;
928+ const textureData = this . get ( texture ) ;
929+ textureData . renderTarget = renderContext . renderTarget ;
930+
931+ const attachment = gl . COLOR_ATTACHMENT0 + i ;
932+
933+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , attachment , gl . TEXTURE_2D , textureData . textureGPU , 0 ) ;
934+
935+ }
936+
937+ renderTargetContextData . framebuffer = fb ;
938+
939+ state . drawBuffers ( renderContext , fb ) ;
889940
890941 }
891942
@@ -897,11 +948,6 @@ class WebGLBackend extends Backend {
897948
898949 }
899950
900-
901- renderTargetContextData . framebuffer = fb ;
902-
903- state . drawBuffers ( renderContext , fb ) ;
904-
905951 }
906952
907953 if ( samples > 0 ) {
0 commit comments