WebGLBackend.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. import { WebGLCoordinateSystem } from 'three';
  2. import GLSLNodeBuilder from './nodes/GLSLNodeBuilder.js';
  3. import Backend from '../common/Backend.js';
  4. import WebGLAttributeUtils from './utils/WebGLAttributeUtils.js';
  5. import WebGLState from './utils/WebGLState.js';
  6. import WebGLUtils from './utils/WebGLUtils.js';
  7. import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
  8. import WebGLExtensions from './utils/WebGLExtensions.js';
  9. //
  10. class WebGLBackend extends Backend {
  11. constructor( parameters = {} ) {
  12. super( parameters );
  13. }
  14. async init( renderer ) {
  15. await super.init( renderer );
  16. //
  17. const parameters = this.parameters;
  18. const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' );
  19. this.gl = glContext;
  20. this.extensions = new WebGLExtensions( this );
  21. this.attributeUtils = new WebGLAttributeUtils( this );
  22. this.textureUtils = new WebGLTextureUtils( this );
  23. this.state = new WebGLState( this );
  24. this.utils = new WebGLUtils( this );
  25. this.defaultTextures = {};
  26. this.extensions.get( 'EXT_color_buffer_float' );
  27. }
  28. get coordinateSystem() {
  29. return WebGLCoordinateSystem;
  30. }
  31. beginRender( renderContext ) {
  32. const { gl } = this;
  33. //
  34. this._setFramebuffer( renderContext );
  35. let clear = 0;
  36. if ( renderContext.clearColor ) clear |= gl.COLOR_BUFFER_BIT;
  37. if ( renderContext.clearDepth ) clear |= gl.DEPTH_BUFFER_BIT;
  38. if ( renderContext.clearStencil ) clear |= gl.STENCIL_BUFFER_BIT;
  39. const clearColor = renderContext.clearColorValue;
  40. if ( clear !== 0 ) {
  41. if ( renderContext.textures === null ) {
  42. gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
  43. gl.clear( clear );
  44. } else {
  45. for ( let i = 0; i < renderContext.textures.length; i ++ ) {
  46. gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );
  47. }
  48. gl.clearBufferfi( gl.DEPTH_STENCIL, 0, 1, 1 );
  49. }
  50. }
  51. //
  52. if ( renderContext.viewport ) {
  53. this.updateViewport( renderContext );
  54. } else {
  55. gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
  56. }
  57. const occlusionQueryCount = renderContext.occlusionQueryCount;
  58. if ( occlusionQueryCount > 0 ) {
  59. const renderContextData = this.get( renderContext );
  60. // Get a reference to the array of objects with queries. The renderContextData property
  61. // can be changed by another render pass before the async reading of all previous queries complete
  62. renderContextData.currentOcclusionQueries = renderContextData.occlusionQueries;
  63. renderContextData.currentOcclusionQueryObjects = renderContextData.occlusionQueryObjects;
  64. renderContextData.lastOcclusionObject = null;
  65. renderContextData.occlusionQueries = new Array( occlusionQueryCount );
  66. renderContextData.occlusionQueryObjects = new Array( occlusionQueryCount );
  67. renderContextData.occlusionQueryIndex = 0;
  68. }
  69. }
  70. finishRender( renderContext ) {
  71. const occlusionQueryCount = renderContext.occlusionQueryCount;
  72. if ( occlusionQueryCount > 0 ) {
  73. const renderContextData = this.get( renderContext );
  74. if ( occlusionQueryCount > renderContextData.occlusionQueryIndex ) {
  75. const { gl } = this;
  76. gl.endQuery( gl.ANY_SAMPLES_PASSED );
  77. }
  78. this.resolveOccludedAsync( renderContext );
  79. }
  80. }
  81. resolveOccludedAsync( renderContext ) {
  82. const renderContextData = this.get( renderContext );
  83. // handle occlusion query results
  84. const { currentOcclusionQueries, currentOcclusionQueryObjects } = renderContextData;
  85. if ( currentOcclusionQueries && currentOcclusionQueryObjects ) {
  86. const occluded = new WeakSet();
  87. const { gl } = this;
  88. renderContextData.currentOcclusionQueryObjects = null;
  89. renderContextData.currentOcclusionQueries = null;
  90. const check = () => {
  91. let completed = 0;
  92. // check all queries and requeue as appropriate
  93. for ( let i = 0; i < currentOcclusionQueries.length; i ++ ) {
  94. const query = currentOcclusionQueries[ i ];
  95. if ( query === null ) continue;
  96. if ( gl.getQueryParameter( query, gl.QUERY_RESULT_AVAILABLE ) ) {
  97. if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) > 0 ) occluded.add( currentOcclusionQueryObjects[ i ] );
  98. currentOcclusionQueries[ i ] = null;
  99. gl.deleteQuery( query );
  100. completed ++;
  101. }
  102. }
  103. if ( completed < currentOcclusionQueries.length ) {
  104. requestAnimationFrame( check );
  105. } else {
  106. renderContextData.occluded = occluded;
  107. }
  108. }
  109. check();
  110. }
  111. }
  112. isOccluded( renderContext, object ) {
  113. const renderContextData = this.get( renderContext );
  114. return renderContextData.occluded && renderContextData.occluded.has( object );
  115. }
  116. updateViewport( renderContext ) {
  117. const gl = this.gl;
  118. const { x, y, width, height } = renderContext.viewportValue;
  119. gl.viewport( x, y, width, height );
  120. }
  121. clear( renderContext, color, depth, stencil ) {
  122. const { gl } = this;
  123. //
  124. let clear = 0;
  125. if ( color ) clear |= gl.COLOR_BUFFER_BIT;
  126. if ( depth ) clear |= gl.DEPTH_BUFFER_BIT;
  127. if ( stencil ) clear |= gl.STENCIL_BUFFER_BIT;
  128. const clearColor = renderContext.clearColorValue;
  129. if ( clear === 0 ) return;
  130. gl.clearColor( clearColor.x, clearColor.y, clearColor.z, clearColor.a );
  131. gl.clear( clear );
  132. }
  133. beginCompute( /*computeGroup*/ ) {
  134. console.warn( 'Abstract class.' );
  135. }
  136. compute( /*computeGroup, computeNode, bindings, pipeline*/ ) {
  137. console.warn( 'Abstract class.' );
  138. }
  139. finishCompute( /*computeGroup*/ ) {
  140. console.warn( 'Abstract class.' );
  141. }
  142. draw( renderObject, info ) {
  143. const { pipeline, material, context } = renderObject;
  144. const { programGPU, vaoGPU } = this.get( pipeline );
  145. const { gl, state } = this;
  146. const contextData = this.get( context );
  147. //
  148. const bindings = renderObject.getBindings();
  149. for ( const binding of bindings ) {
  150. const bindingData = this.get( binding );
  151. const index = bindingData.index;
  152. if ( binding.isUniformsGroup ) {
  153. gl.bindBufferBase( gl.UNIFORM_BUFFER, index, bindingData.bufferGPU );
  154. } else if ( binding.isSampledTexture ) {
  155. gl.activeTexture( gl.TEXTURE0 + index );
  156. gl.bindTexture( bindingData.glTextureType, bindingData.textureGPU );
  157. }
  158. }
  159. state.setMaterial( material );
  160. gl.useProgram( programGPU );
  161. gl.bindVertexArray( vaoGPU );
  162. //
  163. const index = renderObject.getIndex();
  164. const object = renderObject.object;
  165. const geometry = renderObject.geometry;
  166. const drawRange = geometry.drawRange;
  167. const firstVertex = drawRange.start;
  168. //
  169. const lastObject = contextData.lastOcclusionObject;
  170. if ( lastObject !== object && lastObject !== undefined ) {
  171. if ( lastObject !== null && lastObject.occlusionTest === true ) {
  172. gl.endQuery( gl.ANY_SAMPLES_PASSED );
  173. contextData.occlusionQueryIndex ++;
  174. }
  175. if ( object.occlusionTest === true ) {
  176. const query = gl.createQuery();
  177. gl.beginQuery( gl.ANY_SAMPLES_PASSED, query );
  178. contextData.occlusionQueries[ contextData.occlusionQueryIndex ] = query;
  179. contextData.occlusionQueryObjects[ contextData.occlusionQueryIndex ] = object;
  180. }
  181. contextData.lastOcclusionObject = object;
  182. }
  183. //
  184. let mode;
  185. if ( object.isPoints ) mode = gl.POINTS;
  186. else if ( object.isLine ) mode = gl.LINE_STRIP;
  187. else if ( object.isLineLoop ) mode = gl.LINE_LOOP;
  188. else if ( object.isLineSegments ) mode = gl.LINES;
  189. else mode = gl.TRIANGLES;
  190. //
  191. const instanceCount = this.getInstanceCount( renderObject );
  192. if ( index !== null ) {
  193. const indexData = this.get( index );
  194. const indexCount = ( drawRange.count !== Infinity ) ? drawRange.count : index.count;
  195. if ( instanceCount > 1 ) {
  196. gl.drawElementsInstanced( mode, index.count, indexData.type, firstVertex, instanceCount );
  197. } else {
  198. gl.drawElements( mode, index.count, indexData.type, firstVertex );
  199. }
  200. info.update( object, indexCount, 1 );
  201. } else {
  202. const positionAttribute = geometry.attributes.position;
  203. const vertexCount = ( drawRange.count !== Infinity ) ? drawRange.count : positionAttribute.count;
  204. if ( instanceCount > 1 ) {
  205. gl.drawArraysInstanced( mode, 0, vertexCount, instanceCount );
  206. } else {
  207. gl.drawArrays( mode, 0, vertexCount );
  208. }
  209. //gl.drawArrays( mode, vertexCount, gl.UNSIGNED_SHORT, firstVertex );
  210. info.update( object, vertexCount, 1 );
  211. }
  212. //
  213. gl.bindVertexArray( null );
  214. }
  215. needsUpdate( renderObject ) {
  216. return false;
  217. }
  218. getCacheKey( renderObject ) {
  219. return renderObject.geometry.id;
  220. }
  221. // textures
  222. createSampler( /*texture*/ ) {
  223. //console.warn( 'Abstract class.' );
  224. }
  225. destroySampler( /*texture*/ ) {
  226. console.warn( 'Abstract class.' );
  227. }
  228. createDefaultTexture( texture ) {
  229. const { gl, textureUtils, defaultTextures } = this;
  230. const glTextureType = textureUtils.getGLTextureType( texture );
  231. let textureGPU = defaultTextures[ glTextureType ];
  232. if ( textureGPU === undefined ) {
  233. textureGPU = gl.createTexture();
  234. gl.bindTexture( glTextureType, textureGPU );
  235. gl.texParameteri( glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  236. gl.texParameteri( glTextureType, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  237. //gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  238. defaultTextures[ glTextureType ] = textureGPU;
  239. }
  240. this.set( texture, {
  241. textureGPU,
  242. glTextureType,
  243. isDefault: true
  244. } );
  245. }
  246. createTexture( texture, options ) {
  247. const { gl, utils, textureUtils } = this;
  248. const { levels, width, height } = options;
  249. const glFormat = utils.convert( texture.format, texture.colorSpace );
  250. const glType = utils.convert( texture.type );
  251. const glInternalFormat = textureUtils.getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
  252. const textureGPU = gl.createTexture();
  253. const glTextureType = textureUtils.getGLTextureType( texture );
  254. gl.bindTexture( glTextureType, textureGPU );
  255. gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  256. gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  257. gl.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  258. gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE );
  259. textureUtils.setTextureParameters( glTextureType, texture );
  260. gl.bindTexture( glTextureType, textureGPU );
  261. if ( ! texture.isVideoTexture ) {
  262. gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height );
  263. }
  264. this.set( texture, {
  265. textureGPU,
  266. glTextureType,
  267. glFormat,
  268. glType,
  269. glInternalFormat
  270. } );
  271. }
  272. updateTexture( texture, options ) {
  273. const { gl } = this;
  274. const { width, height } = options;
  275. const { textureGPU, glTextureType, glFormat, glType, glInternalFormat } = this.get( texture );
  276. const getImage = ( source ) => {
  277. if ( source.isDataTexture ) {
  278. return source.image.data;
  279. } else if ( source instanceof ImageBitmap || source instanceof OffscreenCanvas ) {
  280. return source;
  281. }
  282. return source.data;
  283. };
  284. gl.bindTexture( glTextureType, textureGPU );
  285. if ( texture.isCubeTexture ) {
  286. const images = options.images;
  287. for ( let i = 0; i < 6; i ++ ) {
  288. const image = getImage( images[ i ] );
  289. gl.texSubImage2D( gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, width, height, glFormat, glType, image );
  290. }
  291. } else if ( texture.isVideoTexture ) {
  292. texture.update();
  293. gl.texImage2D( glTextureType, 0, glInternalFormat, glFormat, glType, options.image );
  294. } else {
  295. const image = getImage( options.image );
  296. gl.texSubImage2D( glTextureType, 0, 0, 0, width, height, glFormat, glType, image );
  297. }
  298. }
  299. generateMipmaps( texture ) {
  300. const { gl } = this;
  301. const { textureGPU, glTextureType } = this.get( texture );
  302. gl.bindTexture( glTextureType, textureGPU );
  303. gl.generateMipmap( glTextureType );
  304. }
  305. destroyTexture( /*texture*/ ) {
  306. console.warn( 'Abstract class.' );
  307. }
  308. copyTextureToBuffer( /*texture, x, y, width, height*/ ) {
  309. console.warn( 'Abstract class.' );
  310. }
  311. // node builder
  312. createNodeBuilder( object, renderer, scene = null ) {
  313. return new GLSLNodeBuilder( object, renderer, scene );
  314. }
  315. // program
  316. createProgram( program ) {
  317. const gl = this.gl;
  318. const { stage, code } = program;
  319. const shader = stage === 'vertex' ? gl.createShader( gl.VERTEX_SHADER ) : gl.createShader( gl.FRAGMENT_SHADER );
  320. gl.shaderSource( shader, code );
  321. gl.compileShader( shader );
  322. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  323. console.error( 'THREE.WebGLBackend:', gl.getShaderInfoLog( shader ) );
  324. }
  325. this.set( program, {
  326. shaderGPU: shader
  327. } );
  328. }
  329. destroyProgram( /*program*/ ) {
  330. console.warn( 'Abstract class.' );
  331. }
  332. createRenderPipeline( renderObject ) {
  333. const gl = this.gl;
  334. const pipeline = renderObject.pipeline;
  335. // Program
  336. const { fragmentProgram, vertexProgram } = pipeline;
  337. const programGPU = gl.createProgram();
  338. gl.attachShader( programGPU, this.get( fragmentProgram ).shaderGPU );
  339. gl.attachShader( programGPU, this.get( vertexProgram ).shaderGPU );
  340. gl.linkProgram( programGPU );
  341. if ( gl.getProgramParameter( programGPU, gl.LINK_STATUS ) === false ) {
  342. console.error( 'THREE.WebGLBackend:', gl.getProgramInfoLog( programGPU ) );
  343. }
  344. gl.useProgram( programGPU );
  345. // Bindings
  346. const bindings = renderObject.getBindings();
  347. for ( const binding of bindings ) {
  348. const bindingData = this.get( binding );
  349. const index = bindingData.index;
  350. if ( binding.isUniformsGroup ) {
  351. const location = gl.getUniformBlockIndex( programGPU, binding.name );
  352. gl.uniformBlockBinding( programGPU, location, index );
  353. } else if ( binding.isSampledTexture ) {
  354. const location = gl.getUniformLocation( programGPU, binding.name );
  355. gl.uniform1i( location, index );
  356. }
  357. }
  358. // VAO
  359. const vaoGPU = gl.createVertexArray();
  360. const index = renderObject.getIndex();
  361. const attributes = renderObject.getAttributes();
  362. gl.bindVertexArray( vaoGPU );
  363. if ( index !== null ) {
  364. const indexData = this.get( index );
  365. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, indexData.bufferGPU );
  366. }
  367. for ( let i = 0; i < attributes.length; i ++ ) {
  368. const attribute = attributes[ i ];
  369. const attributeData = this.get( attribute );
  370. gl.bindBuffer( gl.ARRAY_BUFFER, attributeData.bufferGPU );
  371. gl.enableVertexAttribArray( i );
  372. let stride, offset;
  373. if ( attribute.isInterleavedBufferAttribute === true ) {
  374. stride = attribute.data.stride * attributeData.bytesPerElement;
  375. offset = attribute.offset * attributeData.bytesPerElement;
  376. } else {
  377. stride = 0;
  378. offset = 0;
  379. }
  380. gl.vertexAttribPointer( i, attribute.itemSize, attributeData.type, false, stride, offset );
  381. if ( attribute.isInstancedBufferAttribute && ! attribute.isInterleavedBufferAttribute ) {
  382. gl.vertexAttribDivisor( i, attribute.meshPerAttribute );
  383. } else if ( attribute.isInterleavedBufferAttribute && attribute.data.isInstancedInterleavedBuffer ) {
  384. gl.vertexAttribDivisor( i, attribute.data.meshPerAttribute );
  385. }
  386. }
  387. gl.bindVertexArray( null );
  388. //
  389. this.set( pipeline, {
  390. programGPU,
  391. vaoGPU
  392. } );
  393. }
  394. createComputePipeline( /*computePipeline, bindings*/ ) {
  395. console.warn( 'Abstract class.' );
  396. }
  397. createBindings( bindings ) {
  398. this.updateBindings( bindings );
  399. }
  400. updateBindings( bindings ) {
  401. const { gl } = this;
  402. let groupIndex = 0;
  403. let textureIndex = 0;
  404. for ( const binding of bindings ) {
  405. if ( binding.isUniformsGroup ) {
  406. const bufferGPU = gl.createBuffer();
  407. const data = binding.buffer;
  408. gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
  409. gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
  410. gl.bindBufferBase( gl.UNIFORM_BUFFER, groupIndex, bufferGPU );
  411. this.set( binding, {
  412. index: groupIndex ++,
  413. bufferGPU
  414. } );
  415. } else if ( binding.isSampledTexture ) {
  416. const { textureGPU, glTextureType } = this.get( binding.texture );
  417. this.set( binding, {
  418. index: textureIndex ++,
  419. textureGPU,
  420. glTextureType
  421. } );
  422. }
  423. }
  424. }
  425. updateBinding( binding ) {
  426. const gl = this.gl;
  427. if ( binding.isUniformsGroup ) {
  428. const bindingData = this.get( binding );
  429. const bufferGPU = bindingData.bufferGPU;
  430. const data = binding.buffer;
  431. gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
  432. gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
  433. }
  434. }
  435. // attributes
  436. createIndexAttribute( attribute ) {
  437. const gl = this.gl;
  438. this.attributeUtils.createAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  439. }
  440. createAttribute( attribute ) {
  441. const gl = this.gl;
  442. this.attributeUtils.createAttribute( attribute, gl.ARRAY_BUFFER );
  443. }
  444. createStorageAttribute( /*attribute*/ ) {
  445. console.warn( 'Abstract class.' );
  446. }
  447. updateAttribute( attribute ) {
  448. this.attributeUtils.updateAttribute( attribute );
  449. }
  450. destroyAttribute( /*attribute*/ ) {
  451. console.warn( 'Abstract class.' );
  452. }
  453. updateSize() {
  454. //console.warn( 'Abstract class.' );
  455. }
  456. hasFeature( name ) {
  457. return true;
  458. }
  459. copyFramebufferToTexture( /*texture, renderContext*/ ) {
  460. console.warn( 'Abstract class.' );
  461. }
  462. _setFramebuffer( renderContext ) {
  463. const { gl } = this;
  464. if ( renderContext.textures !== null ) {
  465. const renderContextData = this.get( renderContext );
  466. let fb = renderContextData.framebuffer;
  467. if ( fb === undefined ) {
  468. fb = gl.createFramebuffer();
  469. gl.bindFramebuffer( gl.FRAMEBUFFER, fb );
  470. const textures = renderContext.textures;
  471. const drawBuffers = [];
  472. for ( let i = 0; i < textures.length; i++ ) {
  473. const texture = textures[ i ];
  474. const { textureGPU } = this.get( texture );
  475. const attachment = gl.COLOR_ATTACHMENT0 + i;
  476. gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, textureGPU, 0 );
  477. drawBuffers.push( attachment );
  478. }
  479. gl.drawBuffers( drawBuffers );
  480. if ( renderContext.depthTexture !== null ) {
  481. const { textureGPU } = this.get( renderContext.depthTexture );
  482. gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );
  483. }
  484. renderContextData.framebuffer = fb;
  485. } else {
  486. gl.bindFramebuffer( gl.FRAMEBUFFER, fb );
  487. }
  488. } else {
  489. gl.bindFramebuffer( gl.FRAMEBUFFER, null );
  490. }
  491. }
  492. }
  493. export default WebGLBackend;