Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer: Add "target" argument to "getClearColor" #20818

Merged
merged 12 commits into from
Dec 4, 2020
2 changes: 1 addition & 1 deletion docs/api/en/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ <h3>[method:null forceContextLoss]( )</h3>
<h3>[method:Float getClearAlpha]()</h3>
<p>Returns a [page:Float float] with the current clear alpha. Ranges from 0 to 1.</p>

<h3>[method:Color getClearColor]()</h3>
<h3>[method:Color getClearColor]( [param:Color target] )</h3>
<p>Returns a [page:Color THREE.Color] instance with the current clear color.</p>

<h3>[method:WebGLRenderingContext getContext]()</h3>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/zh/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ <h3>[method:null forceContextLoss]( )</h3>
<h3>[method:Float getClearAlpha]()</h3>
<p>返回一个表示当前alpha值的[page:Float float],范围0到1</p>

<h3>[method:Color getClearColor]()</h3>
<h3>[method:Color getClearColor]( [param:Color target] )</h3>
<p>返回一个表示当前颜色值的[page:Color THREE.Color]实例</p>

<h3>[method:WebGLRenderingContext getContext]()</h3>
Expand Down
2 changes: 1 addition & 1 deletion examples/js/postprocessing/BokehPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )

this.scene.overrideMaterial = this.materialDepth;

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
var oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down
7 changes: 4 additions & 3 deletions examples/js/postprocessing/ClearPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ THREE.ClearPass = function ( clearColor, clearAlpha ) {

this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
this.oldClearColor = new THREE.Color();
gkjohnson marked this conversation as resolved.
Show resolved Hide resolved

};

Expand All @@ -15,11 +16,11 @@ THREE.ClearPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )

render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {

var oldClearColor, oldClearAlpha;
var oldClearAlpha;

if ( this.clearColor ) {

oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
oldClearAlpha = renderer.getClearAlpha();

renderer.setClearColor( this.clearColor, this.clearAlpha );
Expand All @@ -31,7 +32,7 @@ THREE.ClearPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )

if ( this.clearColor ) {

renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/js/postprocessing/OutlinePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

if ( this.selectedObjects.length > 0 ) {

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;

Expand Down
7 changes: 4 additions & 3 deletions examples/js/postprocessing/RenderPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clear
this.clear = true;
this.clearDepth = false;
this.needsSwap = false;
this.oldClearColor = new THREE.Color();

};

Expand All @@ -25,7 +26,7 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

var oldClearColor, oldClearAlpha, oldOverrideMaterial;
var oldClearAlpha, oldOverrideMaterial;

if ( this.overrideMaterial !== undefined ) {

Expand All @@ -37,7 +38,7 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype

if ( this.clearColor ) {

oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
oldClearAlpha = renderer.getClearAlpha();

renderer.setClearColor( this.clearColor, this.clearAlpha );
Expand All @@ -58,7 +59,7 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype

if ( this.clearColor ) {

renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
6 changes: 3 additions & 3 deletions examples/js/postprocessing/SAOPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ THREE.SAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),

}

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down Expand Up @@ -311,7 +311,7 @@ THREE.SAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
renderPass: function ( renderer, passMaterial, renderTarget, clearColor, clearAlpha ) {

// save original state
this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down Expand Up @@ -339,7 +339,7 @@ THREE.SAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),

renderOverride: function ( renderer, overrideMaterial, renderTarget, clearColor, clearAlpha ) {

this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down
5 changes: 3 additions & 2 deletions examples/js/postprocessing/SSAARenderPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ THREE.SSAARenderPass = function ( scene, camera, clearColor, clearAlpha ) {
// as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
this.oldClearColor = new THREE.Color();

if ( THREE.CopyShader === undefined ) console.error( "THREE.SSAARenderPass relies on THREE.CopyShader" );

Expand Down Expand Up @@ -77,7 +78,7 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
var autoClear = renderer.autoClear;
renderer.autoClear = false;

var oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
var oldClearAlpha = renderer.getClearAlpha();

var baseSampleWeight = 1.0 / jitterOffsets.length;
Expand Down Expand Up @@ -134,7 +135,7 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
if ( this.camera.clearViewOffset ) this.camera.clearViewOffset();

renderer.autoClear = autoClear;
renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
4 changes: 2 additions & 2 deletions examples/js/postprocessing/SSAOPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
renderPass: function ( renderer, passMaterial, renderTarget, clearColor, clearAlpha ) {

// save original state
this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down Expand Up @@ -280,7 +280,7 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),

renderOverride: function ( renderer, overrideMaterial, renderTarget, clearColor, clearAlpha ) {

this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down
2 changes: 1 addition & 1 deletion examples/js/postprocessing/UnrealBloomPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto

render: function ( renderer, writeBuffer, readBuffer, deltaTime, maskActive ) {

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/postprocessing/BokehPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ BokehPass.prototype = Object.assign( Object.create( Pass.prototype ), {

this.scene.overrideMaterial = this.materialDepth;

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
var oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down
10 changes: 7 additions & 3 deletions examples/jsm/postprocessing/ClearPass.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {
Color
} from "../../../build/three.module.js";
import { Pass } from "../postprocessing/Pass.js";

var ClearPass = function ( clearColor, clearAlpha ) {
Expand All @@ -8,6 +11,7 @@ var ClearPass = function ( clearColor, clearAlpha ) {

this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
this.oldClearColor = new Color();

};

Expand All @@ -17,11 +21,11 @@ ClearPass.prototype = Object.assign( Object.create( Pass.prototype ), {

render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {

var oldClearColor, oldClearAlpha;
var oldClearAlpha;

if ( this.clearColor ) {

oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
oldClearAlpha = renderer.getClearAlpha();

renderer.setClearColor( this.clearColor, this.clearAlpha );
Expand All @@ -33,7 +37,7 @@ ClearPass.prototype = Object.assign( Object.create( Pass.prototype ), {

if ( this.clearColor ) {

renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/postprocessing/OutlinePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

if ( this.selectedObjects.length > 0 ) {

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;

Expand Down
10 changes: 7 additions & 3 deletions examples/jsm/postprocessing/RenderPass.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {
Color
} from "../../../build/three.module.js";
import { Pass } from "../postprocessing/Pass.js";

var RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
Expand All @@ -15,6 +18,7 @@ var RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAl
this.clear = true;
this.clearDepth = false;
this.needsSwap = false;
this.oldClearColor = new Color();

};

Expand All @@ -27,7 +31,7 @@ RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

var oldClearColor, oldClearAlpha, oldOverrideMaterial;
var oldClearAlpha, oldOverrideMaterial;

if ( this.overrideMaterial !== undefined ) {

Expand All @@ -39,7 +43,7 @@ RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {

if ( this.clearColor ) {

oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
oldClearAlpha = renderer.getClearAlpha();

renderer.setClearColor( this.clearColor, this.clearAlpha );
Expand All @@ -60,7 +64,7 @@ RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {

if ( this.clearColor ) {

renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/postprocessing/SAOPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ SAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {

}

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down Expand Up @@ -339,7 +339,7 @@ SAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {
renderPass: function ( renderer, passMaterial, renderTarget, clearColor, clearAlpha ) {

// save original state
this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down Expand Up @@ -367,7 +367,7 @@ SAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {

renderOverride: function ( renderer, overrideMaterial, renderTarget, clearColor, clearAlpha ) {

this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down
6 changes: 4 additions & 2 deletions examples/jsm/postprocessing/SSAARenderPass.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AdditiveBlending,
Color,
LinearFilter,
RGBAFormat,
ShaderMaterial,
Expand Down Expand Up @@ -32,6 +33,7 @@ var SSAARenderPass = function ( scene, camera, clearColor, clearAlpha ) {
// as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
this.oldClearColor = new Color();

if ( CopyShader === undefined ) console.error( "SSAARenderPass relies on CopyShader" );

Expand Down Expand Up @@ -88,7 +90,7 @@ SSAARenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
var autoClear = renderer.autoClear;
renderer.autoClear = false;

var oldClearColor = renderer.getClearColor().getHex();
renderer.getClearColor( this.oldClearColor );
var oldClearAlpha = renderer.getClearAlpha();

var baseSampleWeight = 1.0 / jitterOffsets.length;
Expand Down Expand Up @@ -145,7 +147,7 @@ SSAARenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
if ( this.camera.clearViewOffset ) this.camera.clearViewOffset();

renderer.autoClear = autoClear;
renderer.setClearColor( oldClearColor, oldClearAlpha );
renderer.setClearColor( this.oldClearColor, oldClearAlpha );

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/postprocessing/SSAOPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ SSAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {
renderPass: function ( renderer, passMaterial, renderTarget, clearColor, clearAlpha ) {

// save original state
this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down Expand Up @@ -310,7 +310,7 @@ SSAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {

renderOverride: function ( renderer, overrideMaterial, renderTarget, clearColor, clearAlpha ) {

this.originalClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.originalClearColor );
var originalClearAlpha = renderer.getClearAlpha();
var originalAutoClear = renderer.autoClear;

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/postprocessing/UnrealBloomPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ UnrealBloomPass.prototype = Object.assign( Object.create( Pass.prototype ), {

render: function ( renderer, writeBuffer, readBuffer, deltaTime, maskActive ) {

this.oldClearColor.copy( renderer.getClearColor() );
renderer.getClearColor( this.oldClearColor );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
Expand Down
2 changes: 1 addition & 1 deletion src/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class PMREMGenerator {

const outputEncoding = renderer.outputEncoding;
const toneMapping = renderer.toneMapping;
_clearColor.copy( renderer.getClearColor() );
renderer.getClearColor( _clearColor );
const clearAlpha = renderer.getClearAlpha();

renderer.toneMapping = NoToneMapping;
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class WebGLRenderer implements Renderer {
/**
* Returns a THREE.Color instance with the current clear color.
*/
getClearColor(): Color;
getClearColor( target: Color ): Color;

/**
* Sets the clear color, using color for the color and alpha for the opacity.
Expand Down