@@ -88,9 +88,6 @@ class RenderTarget {
8888 this . _colorBuffer . _isRenderTarget = true ;
8989 }
9090
91- this . _glFrameBuffer = null ;
92- this . _glDepthBuffer = null ;
93-
9491 // Process optional arguments
9592 options = ( options !== undefined ) ? options : defaultOptions ;
9693 this . _depthBuffer = options . depthBuffer ;
@@ -120,9 +117,6 @@ class RenderTarget {
120117
121118 this . _samples = ( options . samples !== undefined ) ? Math . min ( options . samples , this . _device . maxSamples ) : 1 ;
122119 this . autoResolve = ( options . autoResolve !== undefined ) ? options . autoResolve : true ;
123- this . _glResolveFrameBuffer = null ;
124- this . _glMsaaColorBuffer = null ;
125- this . _glMsaaDepthBuffer = null ;
126120
127121 // use specified name, otherwise get one from color or depth buffer
128122 this . name = options . name ;
@@ -138,6 +132,9 @@ class RenderTarget {
138132
139133 // render image flipped in Y
140134 this . flipY = ! ! options . flipY ;
135+
136+ // device specific implementation
137+ this . impl = this . _device . createRenderTargetImpl ( this ) ;
141138 }
142139
143140 /**
@@ -157,39 +154,15 @@ class RenderTarget {
157154 }
158155
159156 /**
160- * Free WebGL resources associated with this render target.
157+ * Free device resources associated with this render target.
161158 *
162159 * @ignore
163160 */
164161 destroyFrameBuffers ( ) {
165162
166163 const device = this . _device ;
167164 if ( device ) {
168- const gl = device . gl ;
169- if ( this . _glFrameBuffer ) {
170- gl . deleteFramebuffer ( this . _glFrameBuffer ) ;
171- this . _glFrameBuffer = null ;
172- }
173-
174- if ( this . _glDepthBuffer ) {
175- gl . deleteRenderbuffer ( this . _glDepthBuffer ) ;
176- this . _glDepthBuffer = null ;
177- }
178-
179- if ( this . _glResolveFrameBuffer ) {
180- gl . deleteFramebuffer ( this . _glResolveFrameBuffer ) ;
181- this . _glResolveFrameBuffer = null ;
182- }
183-
184- if ( this . _glMsaaColorBuffer ) {
185- gl . deleteRenderbuffer ( this . _glMsaaColorBuffer ) ;
186- this . _glMsaaColorBuffer = null ;
187- }
188-
189- if ( this . _glMsaaDepthBuffer ) {
190- gl . deleteRenderbuffer ( this . _glMsaaDepthBuffer ) ;
191- this . _glMsaaDepthBuffer = null ;
192- }
165+ this . impl . destroy ( device ) ;
193166 }
194167 }
195168
@@ -212,16 +185,21 @@ class RenderTarget {
212185 }
213186
214187 /**
215- * Called when the WebGL context was lost. It releases all context related resources.
188+ * Initialises the resources associated with this render target.
189+ *
190+ * @ignore
191+ */
192+ init ( ) {
193+ this . impl . init ( this . _device , this ) ;
194+ }
195+
196+ /**
197+ * Called when the device context was lost. It releases all context related resources.
216198 *
217199 * @ignore
218200 */
219201 loseContext ( ) {
220- this . _glFrameBuffer = undefined ;
221- this . _glDepthBuffer = undefined ;
222- this . _glResolveFrameBuffer = undefined ;
223- this . _glMsaaColorBuffer = undefined ;
224- this . _glMsaaDepthBuffer = undefined ;
202+ this . impl . loseContext ( ) ;
225203 }
226204
227205 /**
@@ -239,17 +217,9 @@ class RenderTarget {
239217 * depth buffer.
240218 */
241219 resolve ( color = true , depth = ! ! this . _depthBuffer ) {
242- if ( ! this . _device ) return ;
243- if ( ! this . _device . webgl2 ) return ;
244-
245- const gl = this . _device . gl ;
246- gl . bindFramebuffer ( gl . READ_FRAMEBUFFER , this . _glFrameBuffer ) ;
247- gl . bindFramebuffer ( gl . DRAW_FRAMEBUFFER , this . _glResolveFrameBuffer ) ;
248- gl . blitFramebuffer ( 0 , 0 , this . width , this . height ,
249- 0 , 0 , this . width , this . height ,
250- ( color ? gl . COLOR_BUFFER_BIT : 0 ) | ( depth ? gl . DEPTH_BUFFER_BIT : 0 ) ,
251- gl . NEAREST ) ;
252- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . _glFrameBuffer ) ;
220+ if ( this . _device ) {
221+ this . impl . resolve ( this . _device , this , color , depth ) ;
222+ }
253223 }
254224
255225 /**
0 commit comments