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

Extend WebGLMultipleRenderTargets from WebGLRenderTarget #519

Merged
merged 6 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions types/three/src/renderers/WebGLMultipleRenderTargets.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { EventDispatcher } from '../core/EventDispatcher';
import { Texture } from '../textures/Texture';
import { WebGLRenderTargetOptions } from './WebGLRenderTarget';

/**
* This class originall extended WebGLMultipleRenderTarget
* However, there are some issues with this method as documented below
*/
export class WebGLMultipleRenderTargets extends EventDispatcher {
texture: Texture[];

readonly isWebGLMultipleRenderTargets = true;
import { WebGLRenderTarget, WebGLRenderTargetOptions } from './WebGLRenderTarget';

export class WebGLMultipleRenderTargets extends WebGLRenderTarget<Texture[]> {
/**
* @param width The width of the render target.
* @param height The height of the render target.
Expand All @@ -20,10 +11,5 @@ export class WebGLMultipleRenderTargets extends EventDispatcher {
*/
constructor(width?: number, height?: number, count?: number, options?: WebGLRenderTargetOptions);

setSize(width: number, height: number, depth?: number): this;
copy(source: WebGLMultipleRenderTargets): this;
clone(): this;
dispose(): void;
// This is an available method, however it will break the code see https://github.com/mrdoob/three.js/issues/21930
setTexture(texture: Texture): void;
readonly isWebGLMultipleRenderTargets: true;
}
66 changes: 12 additions & 54 deletions types/three/src/renderers/WebGLRenderTarget.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Vector4 } from './../math/Vector4';
import { Texture } from './../textures/Texture';
import { DepthTexture } from './../textures/DepthTexture';
import { EventDispatcher } from './../core/EventDispatcher';
import { Vector4 } from '../math/Vector4';
import { Texture } from '../textures/Texture';
import { DepthTexture } from '../textures/DepthTexture';
import { EventDispatcher } from '../core/EventDispatcher';
import {
Wrapping,
TextureDataType,
Expand All @@ -16,27 +16,28 @@ export interface WebGLRenderTargetOptions {
wrapT?: Wrapping | undefined;
magFilter?: MagnificationTextureFilter | undefined;
minFilter?: MinificationTextureFilter | undefined;
generateMipmaps?: boolean | undefined; // true;
format?: number | undefined; // RGBAFormat;
type?: TextureDataType | undefined; // UnsignedByteType;
anisotropy?: number | undefined; // 1;
colorSpace?: ColorSpace | undefined;
depthBuffer?: boolean | undefined; // true;
stencilBuffer?: boolean | undefined; // false;
generateMipmaps?: boolean | undefined; // true;
depthTexture?: DepthTexture | undefined;
/** @deprecated Use 'colorSpace' in three.js r152+. */
encoding?: TextureEncoding | undefined;
colorSpace?: ColorSpace | undefined;

/**
* Defines the count of MSAA samples. Can only be used with WebGL 2. Default is **0**.
* @default 0
*/
samples?: number;
/** @deprecated Use 'colorSpace' in three.js r152+. */
encoding?: TextureEncoding | undefined;
}

export class WebGLRenderTarget extends EventDispatcher {
export class WebGLRenderTarget<TTexture extends Texture | Texture[] = Texture> extends EventDispatcher {
constructor(width?: number, height?: number, options?: WebGLRenderTargetOptions);

readonly isWebGLRenderTarget: true;

width: number;
height: number;
depth: number;
Expand All @@ -47,7 +48,7 @@ export class WebGLRenderTarget extends EventDispatcher {
*/
scissorTest: boolean;
viewport: Vector4;
texture: Texture;
texture: TTexture;

/**
* @default true
Expand All @@ -70,49 +71,6 @@ export class WebGLRenderTarget extends EventDispatcher {
*/
samples: number;

readonly isWebGLRenderTarget: true;

/**
* @deprecated Use {@link Texture#wrapS texture.wrapS} instead.
*/
wrapS: any;
/**
* @deprecated Use {@link Texture#wrapT texture.wrapT} instead.
*/
wrapT: any;
/**
* @deprecated Use {@link Texture#magFilter texture.magFilter} instead.
*/
magFilter: any;
/**
* @deprecated Use {@link Texture#minFilter texture.minFilter} instead.
*/
minFilter: any;
/**
* @deprecated Use {@link Texture#anisotropy texture.anisotropy} instead.
*/
anisotropy: any;
/**
* @deprecated Use {@link Texture#offset texture.offset} instead.
*/
offset: any;
/**
* @deprecated Use {@link Texture#repeat texture.repeat} instead.
*/
repeat: any;
/**
* @deprecated Use {@link Texture#format texture.format} instead.
*/
format: any;
/**
* @deprecated Use {@link Texture#type texture.type} instead.
*/
type: any;
/**
* @deprecated Use {@link Texture#generateMipmaps texture.generateMipmaps} instead.
*/
generateMipmaps: any;

setSize(width: number, height: number, depth?: number): void;
clone(): this;
copy(source: WebGLRenderTarget): this;
Expand Down
4 changes: 2 additions & 2 deletions types/three/test/unit/examples/jsm/postprocessing/SavePass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as THREE from 'three';
import { SavePass } from 'three/examples/jsm/postprocessing/SavePass';

let pass = new SavePass(); // $ExpectType SavePass
let rt = pass.renderTarget; // $ExpectType WebGLRenderTarget
let rt = pass.renderTarget; // $ExpectType WebGLRenderTarget<Texture>

pass = new SavePass(new THREE.WebGLRenderTarget(128, 128)); // $ExpectType SavePass
rt = pass.renderTarget; // $ExpectType WebGLRenderTarget
rt = pass.renderTarget; // $ExpectType WebGLRenderTarget<Texture>