Reputation: 352
I'm studying three.js and going through the documentation. I don't get the meaning of the following description, can anyone help me?
Since you are manually creating the WebGL 2 rendering context, you also have to pass in all necessary context attributes. Note: It's not possible to modify these attributes after the context has been created, so passing them to the WebGLRenderer won't have any effect.
var canvas = document.createElement( 'canvas' );
var context = canvas.getContext( 'webgl2', { alpha: false } );
var renderer = new THREE.WebGLRenderer( { canvas: canvas, context: context } );
Upvotes: 1
Views: 167
Reputation: 8896
In this case, you are creating WebGLRenderer
and passing in the GL context, rather than letting the WebGLRenderer
constructor create it for you.
This means that YOU are creating the context. In your case, the WebGL2RenderingContext
. When you create the context in this way, you need to supply all of the options during the getContext
call. Passing GL options into the WebGLRenderer
constructor will not alter the context after-the-fact.
Consider this:
var canvas = document.createElement( 'canvas' );
var context = canvas.getContext( 'webgl2', { alpha: false } );
var renderer = new THREE.WebGLRenderer( { canvas: canvas, context: context, alpha: true } );
On the last line, passing alpha: true
will have absolutely no effect, because the previous line got the context (that you're giving to WebGLRenderer
using alpha: false
.
Upvotes: 2