From 71171f48b5938c559765eb93836eeca76df0c45f Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Tue, 18 Feb 2020 19:09:43 -0500 Subject: [PATCH] Add type declaration for gl-fbo (#42394) --- types/gl-fbo/gl-fbo-tests.ts | 32 ++++++++++++++++++++++++++++++++ types/gl-fbo/index.d.ts | 35 +++++++++++++++++++++++++++++++++++ types/gl-fbo/tsconfig.json | 25 +++++++++++++++++++++++++ types/gl-fbo/tslint.json | 1 + 4 files changed, 93 insertions(+) create mode 100644 types/gl-fbo/gl-fbo-tests.ts create mode 100644 types/gl-fbo/index.d.ts create mode 100644 types/gl-fbo/tsconfig.json create mode 100644 types/gl-fbo/tslint.json diff --git a/types/gl-fbo/gl-fbo-tests.ts b/types/gl-fbo/gl-fbo-tests.ts new file mode 100644 index 0000000000..8d4f359f8b --- /dev/null +++ b/types/gl-fbo/gl-fbo-tests.ts @@ -0,0 +1,32 @@ +import texture2D = require('gl-texture2d'); +import glFBO from 'gl-fbo'; + +type Texture = ReturnType; + +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; diff --git a/types/gl-fbo/index.d.ts b/types/gl-fbo/index.d.ts new file mode 100644 index 0000000000..cc876eeb7f --- /dev/null +++ b/types/gl-fbo/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for gl-fbo 2.0 +// Project: https://github.com/stackgl/gl-fbo +// Definitions by: Nick Krichevsky +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import texture2D = require('gl-texture2d'); + +type Texture = ReturnType; + +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; diff --git a/types/gl-fbo/tsconfig.json b/types/gl-fbo/tsconfig.json new file mode 100644 index 0000000000..493e758360 --- /dev/null +++ b/types/gl-fbo/tsconfig.json @@ -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" + ] +} diff --git a/types/gl-fbo/tslint.json b/types/gl-fbo/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gl-fbo/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }