Add type declaration for gl-fbo (#42394)

This commit is contained in:
Nick Krichevsky 2020-02-18 19:09:43 -05:00 committed by GitHub
parent 308f467a17
commit 71171f48b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import texture2D = require('gl-texture2d');
import glFBO from 'gl-fbo';
type Texture = ReturnType<typeof texture2D>;
const gl = new WebGLRenderingContext();
glFBO(gl, [12, 34]);
glFBO(gl, [12, 34], {preferFloat: true});
glFBO(gl, [12, 34], {float: false});
glFBO(gl, [12, 34], {color: 2});
glFBO(gl, [12, 34], {depth: false});
glFBO(gl, [12, 34], {stencil: false});
const fbo = glFBO(gl, [12, 34]);
fbo.bind();
fbo.dispose();
// $ExpectType [number, number]
fbo.shape;
// $ExpectType WebGLRenderingContext
fbo.gl;
// $ExpectType WebGLFramebuffer
fbo.handle;
// $ExpectType Texture[]
fbo.color;
// $ExpectType Texture | null
fbo.depth;

35
types/gl-fbo/index.d.ts vendored Normal file
View File

@ -0,0 +1,35 @@
// Type definitions for gl-fbo 2.0
// Project: https://github.com/stackgl/gl-fbo
// Definitions by: Nick Krichevsky <https://github.com/ollien>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import texture2D = require('gl-texture2d');
type Texture = ReturnType<typeof texture2D>;
declare class FrameBuffer {
shape: [number, number];
gl: WebGLRenderingContext;
handle: WebGLFramebuffer;
color: Texture[];
depth: Texture|null;
bind(): void;
dispose(): void;
}
interface FrameBufferOptions {
preferFloat?: boolean;
float?: boolean;
color?: number;
depth?: boolean;
stencil?: boolean;
}
declare function glFBO(
gl: WebGLRenderingContext,
shape: [number, number],
options?: FrameBufferOptions
): FrameBuffer;
export = glFBO;

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"gl-fbo-tests.ts"
]
}

1
types/gl-fbo/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }