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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
import { Scene } from './../scenes/Scene';
import { Camera } from './../cameras/Camera';
import { WebGLExtensions } from './webgl/WebGLExtensions';
import { WebGLInfo } from './webgl/WebGLInfo';
import { WebGLShadowMap } from './webgl/WebGLShadowMap';
import { WebGLCapabilities } from './webgl/WebGLCapabilities';
import { WebGLProperties } from './webgl/WebGLProperties';
import { WebGLRenderLists } from './webgl/WebGLRenderLists';
import { WebGLState } from './webgl/WebGLState';
import { Vector2 } from './../math/Vector2';
import { Vector4 } from './../math/Vector4';
import { Color } from './../math/Color';
import { WebGLRenderTarget } from './WebGLRenderTarget';
import { Object3D } from './../core/Object3D';
import { Material } from './../materials/Material';
import { Fog } from './../scenes/Fog';
import { Texture } from './../textures/Texture';
import { ToneMapping, ShadowMapType, CullFace } from '../constants';
import { WebVRManager } from '../renderers/webvr/WebVRManager';
import { RenderTarget } from './webgl/WebGLRenderLists';

export interface Renderer {
  domElement: HTMLCanvasElement;

  render(scene: Scene, camera: Camera): void;
  setSize(width: number, height: number, updateStyle?: boolean): void;
}

export interface WebGLRendererParameters {
  /**
   * A Canvas where the renderer draws its output.
   */
  canvas?: HTMLCanvasElement;

  /**
   * A WebGL Rendering Context.
   * (https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext)
   *  Default is null
   */
  context?: WebGLRenderingContext;

  /**
   *  shader precision. Can be "highp", "mediump" or "lowp".
   */
  precision?: string;

  /**
   * default is true.
   */
  alpha?: boolean;

  /**
   * default is true.
   */
  premultipliedAlpha?: boolean;

  /**
   * default is false.
   */
  antialias?: boolean;

  /**
   * default is true.
   */
  stencil?: boolean;

  /**
   * default is false.
   */
  preserveDrawingBuffer?: boolean;

  /**
   *  Can be "high-performance", "low-power" or "default"
   */
  powerPreference?: string;

  /**
   * default is true.
   */
  depth?: boolean;

  /**
   * default is false.
   */
  logarithmicDepthBuffer?: boolean;
}

/**
 * The WebGL renderer displays your beautifully crafted scenes using WebGL, if your device supports it.
 * This renderer has way better performance than CanvasRenderer.
 *
 * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js">src/renderers/WebGLRenderer.js</a>
 */
export class WebGLRenderer implements Renderer {
  /**
   * parameters is an optional object with properties defining the renderer's behaviour. The constructor also accepts no parameters at all. In all cases, it will assume sane defaults when parameters are missing.
   */
  constructor(parameters?: WebGLRendererParameters);

  /**
   * A Canvas where the renderer draws its output.
   * This is automatically created by the renderer in the constructor (if not provided already); you just need to add it to your page.
   */
  domElement: HTMLCanvasElement;

  /**
   * The HTML5 Canvas's 'webgl' context obtained from the canvas where the renderer will draw.
   */
  context: WebGLRenderingContext;

  /**
   * Defines whether the renderer should automatically clear its output before rendering.
   */
  autoClear: boolean;

  /**
   * If autoClear is true, defines whether the renderer should clear the color buffer. Default is true.
   */
  autoClearColor: boolean;

  /**
   * If autoClear is true, defines whether the renderer should clear the depth buffer. Default is true.
   */
  autoClearDepth: boolean;

  /**
   * If autoClear is true, defines whether the renderer should clear the stencil buffer. Default is true.
   */
  autoClearStencil: boolean;

  /**
   * Defines whether the renderer should sort objects. Default is true.
   */
  sortObjects: boolean;

  clippingPlanes: any[];
  localClippingEnabled: boolean;

  extensions: WebGLExtensions;

  /**
   * Default is false.
   */
  gammaInput: boolean;

  /**
   * Default is false.
   */
  gammaOutput: boolean;

  physicallyCorrectLights: boolean;
  toneMapping: ToneMapping;
  toneMappingExposure: number;
  toneMappingWhitePoint: number;

  /**
   * Default is false.
   */
  shadowMapDebug: boolean;

  /**
   * Default is 8.
   */
  maxMorphTargets: number;

  /**
   * Default is 4.
   */
  maxMorphNormals: number;

  info: WebGLInfo;

  shadowMap: WebGLShadowMap;

  pixelRation: number;

  capabilities: WebGLCapabilities;
  properties: WebGLProperties;
  renderLists: WebGLRenderLists;
  state: WebGLState;

  vr: WebVRManager;

  /**
   * Return the WebGL context.
   */
  getContext(): WebGLRenderingContext;
  getContextAttributes(): any;
  forceContextLoss(): void;

  /**
   * @deprecated Use {@link WebGLCapabilities#getMaxAnisotropy .capabilities.getMaxAnisotropy()} instead.
   */
  getMaxAnisotropy(): number;

  /**
   * @deprecated Use {@link WebGLCapabilities#precision .capabilities.precision} instead.
   */
  getPrecision(): string;

  getPixelRatio(): number;
  setPixelRatio(value: number): void;

  getDrawingBufferSize(): { width: number; height: number };
  setDrawingBufferSize(width: number, height: number, pixelRatio: number): void;

  getSize(target: Vector2): Vector2;

  /**
   * Resizes the output canvas to (width, height), and also sets the viewport to fit that size, starting in (0, 0).
   */
  setSize(width: number, height: number, updateStyle?: boolean): void;

  getCurrentViewport(target: Vector4): Vector4;

  /**
   * Copies the viewport into target.
   */
  getViewport(target: Vector4): Vector4;

  /**
   * Sets the viewport to render from (x, y) to (x + width, y + height).
   * (x, y) is the lower-left corner of the region.
   */
  setViewport(x: Vector4 | number, y?: number, width?: number, height?: number): void;

  /**
   * Copies the scissor area into target.
   */
  getScissor(target: Vector4): Vector4;

  /**
   * Sets the scissor area from (x, y) to (x + width, y + height).
   */
  setScissor(x: Vector4 | number, y?: number, width?: number, height?: number): void;

  /**
   * Returns true if scissor test is enabled; returns false otherwise.
   */
  getScissorTest(): boolean;

  /**
   * Enable the scissor test. When this is enabled, only the pixels within the defined scissor area will be affected by further renderer actions.
   */
  setScissorTest(enable: boolean): void;

  /**
   * Returns a THREE.Color instance with the current clear color.
   */
  getClearColor(): Color;

  /**
   * Sets the clear color, using color for the color and alpha for the opacity.
   */
  setClearColor(color: Color, alpha?: number): void;
  setClearColor(color: string, alpha?: number): void;
  setClearColor(color: number, alpha?: number): void;

  /**
   * Returns a float with the current clear alpha. Ranges from 0 to 1.
   */
  getClearAlpha(): number;

  setClearAlpha(alpha: number): void;

  /**
   * Tells the renderer to clear its color, depth or stencil drawing buffer(s).
   * Arguments default to true
   */
  clear(color?: boolean, depth?: boolean, stencil?: boolean): void;

  clearColor(): void;
  clearDepth(): void;
  clearStencil(): void;
  clearTarget(
    renderTarget: WebGLRenderTarget,
    color: boolean,
    depth: boolean,
    stencil: boolean
  ): void;

  /**
   * @deprecated Use {@link WebGLState#reset .state.reset()} instead.
   */
  resetGLState(): void;
  dispose(): void;

  /**
   * Tells the shadow map plugin to update using the passed scene and camera parameters.
   *
   * @param scene an instance of Scene
   * @param camera — an instance of Camera
   */
  renderBufferImmediate(
    object: Object3D,
    program: Object,
    material: Material
  ): void;

  renderBufferDirect(
    camera: Camera,
    fog: Fog,
    material: Material,
    geometryGroup: any,
    object: Object3D
  ): void;

  /**
   * A build in function that can be used instead of requestAnimationFrame. For WebVR projects this function must be used.
   * @param callback The function will be called every available frame. If `null` is passed it will stop any already ongoing animation.
   */
  setAnimationLoop(callback: Function): void;

  /**
   * @deprecated Use {@link WebGLRenderer#setAnimationLoop .setAnimationLoop()} instead.
   */
  animate(callback: Function): void;

  /**
   * Render a scene using a camera.
   * The render is done to a previously specified {@link WebGLRenderTarget#renderTarget .renderTarget} set by calling
   * {@link WebGLRenderer#setRenderTarget .setRenderTarget} or to the canvas as usual.
   *
   * By default render buffers are cleared before rendering but you can prevent this by setting the property
   * {@link WebGLRenderer#autoClear autoClear} to false. If you want to prevent only certain buffers being cleared
   * you can set either the {@link WebGLRenderer#autoClearColor autoClearColor},
   * {@link WebGLRenderer#autoClearStencil autoClearStencil} or {@link WebGLRenderer#autoClearDepth autoClearDepth}
   * properties to false. To forcibly clear one ore more buffers call {@link WebGLRenderer#clear .clear}.
   */
  render(
    scene: Scene,
    camera: Camera
  ): void;

  /**
   * @deprecated
   */
  getRenderTarget(): RenderTarget;
  /**
   * @deprecated Use {@link WebGLRenderer#getRenderTarget .getRenderTarget()} instead.
   */
  getCurrentRenderTarget(): RenderTarget;
  setRenderTarget(renderTarget?: RenderTarget, activeCubeFace?: number, activeMipMapLevel?: number): void;
  readRenderTargetPixels(
    renderTarget: RenderTarget,
    x: number,
    y: number,
    width: number,
    height: number,
    buffer: any
  ): void;

  /**
   * @deprecated
   */
  gammaFactor: number;

  /**
   * @deprecated Use {@link WebGLShadowMap#enabled .shadowMap.enabled} instead.
   */
  shadowMapEnabled: boolean;

  /**
   * @deprecated Use {@link WebGLShadowMap#type .shadowMap.type} instead.
   */
  shadowMapType: ShadowMapType;

  /**
   * @deprecated Use {@link WebGLShadowMap#cullFace .shadowMap.cullFace} instead.
   */
  shadowMapCullFace: CullFace;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'OES_texture_float' )} instead.
   */
  supportsFloatTextures(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'OES_texture_half_float' )} instead.
   */
  supportsHalfFloatTextures(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'OES_standard_derivatives' )} instead.
   */
  supportsStandardDerivatives(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'WEBGL_compressed_texture_s3tc' )} instead.
   */
  supportsCompressedTextureS3TC(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'WEBGL_compressed_texture_pvrtc' )} instead.
   */
  supportsCompressedTexturePVRTC(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'EXT_blend_minmax' )} instead.
   */
  supportsBlendMinMax(): any;

  /**
   * @deprecated Use {@link WebGLCapabilities#vertexTextures .capabilities.vertexTextures} instead.
   */
  supportsVertexTextures(): any;

  /**
   * @deprecated Use {@link WebGLExtensions#get .extensions.get( 'ANGLE_instanced_arrays' )} instead.
   */
  supportsInstancedArrays(): any;

  /**
   * @deprecated Use {@link WebGLRenderer#setScissorTest .setScissorTest()} instead.
   */
  enableScissorTest(boolean: any): any;
}