|
@@ -317,6 +317,8 @@ function WebGLState( gl, extensions, capabilities ) {
|
|
let enabledCapabilities = {};
|
|
let enabledCapabilities = {};
|
|
|
|
|
|
let currentBoundFramebuffers = {};
|
|
let currentBoundFramebuffers = {};
|
|
|
|
+ let currentDrawbuffers = new WeakMap();
|
|
|
|
+ let defaultDrawbuffers = [];
|
|
|
|
|
|
let currentProgram = null;
|
|
let currentProgram = null;
|
|
|
|
|
|
@@ -461,6 +463,84 @@ function WebGLState( gl, extensions, capabilities ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function drawBuffers( renderTarget, framebuffer ) {
|
|
|
|
+
|
|
|
|
+ let drawBuffers = defaultDrawbuffers;
|
|
|
|
+
|
|
|
|
+ let needsUpdate = false;
|
|
|
|
+
|
|
|
|
+ if ( renderTarget ) {
|
|
|
|
+
|
|
|
|
+ drawBuffers = currentDrawbuffers.get( framebuffer );
|
|
|
|
+
|
|
|
|
+ if ( drawBuffers === undefined ) {
|
|
|
|
+
|
|
|
|
+ drawBuffers = [];
|
|
|
|
+ currentDrawbuffers.set( framebuffer, drawBuffers );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( renderTarget.isWebGLMultipleRenderTargets ) {
|
|
|
|
+
|
|
|
|
+ const textures = renderTarget.texture;
|
|
|
|
+
|
|
|
|
+ if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {
|
|
|
|
+
|
|
|
|
+ for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
|
|
+
|
|
|
|
+ drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ drawBuffers.length = textures.length;
|
|
|
|
+
|
|
|
|
+ needsUpdate = true;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ if ( drawBuffers.length !== 1 || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {
|
|
|
|
+
|
|
|
|
+ drawBuffers[ 0 ] = gl.COLOR_ATTACHMENT0;
|
|
|
|
+ drawBuffers.length = 1;
|
|
|
|
+
|
|
|
|
+ needsUpdate = true;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ if ( drawBuffers.length !== 1 || drawBuffers[ 0 ] !== gl.BACK ) {
|
|
|
|
+
|
|
|
|
+ drawBuffers[ 0 ] = gl.BACK;
|
|
|
|
+ drawBuffers.length = 1;
|
|
|
|
+
|
|
|
|
+ needsUpdate = true;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( needsUpdate ) {
|
|
|
|
+
|
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
+
|
|
|
|
+ gl.drawBuffers( drawBuffers );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ extensions.get( 'WEBGL_draw_buffers' ).drawBuffersWEBGL( drawBuffers );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
function useProgram( program ) {
|
|
function useProgram( program ) {
|
|
|
|
|
|
if ( currentProgram !== program ) {
|
|
if ( currentProgram !== program ) {
|
|
@@ -1047,6 +1127,8 @@ function WebGLState( gl, extensions, capabilities ) {
|
|
currentBoundTextures = {};
|
|
currentBoundTextures = {};
|
|
|
|
|
|
currentBoundFramebuffers = {};
|
|
currentBoundFramebuffers = {};
|
|
|
|
+ currentDrawbuffers = new WeakMap();
|
|
|
|
+ defaultDrawbuffers = [];
|
|
|
|
|
|
currentProgram = null;
|
|
currentProgram = null;
|
|
|
|
|
|
@@ -1089,6 +1171,7 @@ function WebGLState( gl, extensions, capabilities ) {
|
|
disable: disable,
|
|
disable: disable,
|
|
|
|
|
|
bindFramebuffer: bindFramebuffer,
|
|
bindFramebuffer: bindFramebuffer,
|
|
|
|
+ drawBuffers: drawBuffers,
|
|
|
|
|
|
useProgram: useProgram,
|
|
useProgram: useProgram,
|
|
|
|
|