From 447e24325aafbe9e7ebf52d3731e317b3bd100fa Mon Sep 17 00:00:00 2001 From: Mathias Paumgarten Date: Fri, 27 Apr 2018 23:38:47 -0700 Subject: [PATCH] adds gl-texture2d types (#25378) * adds gl-texture2d type * remove package.json --- types/gl-texture2d/gl-texture2d-tests.ts | 79 ++++++++++++++++++++++++ types/gl-texture2d/index.d.ts | 42 +++++++++++++ types/gl-texture2d/tsconfig.json | 24 +++++++ types/gl-texture2d/tslint.json | 3 + 4 files changed, 148 insertions(+) create mode 100644 types/gl-texture2d/gl-texture2d-tests.ts create mode 100644 types/gl-texture2d/index.d.ts create mode 100644 types/gl-texture2d/tsconfig.json create mode 100644 types/gl-texture2d/tslint.json diff --git a/types/gl-texture2d/gl-texture2d-tests.ts b/types/gl-texture2d/gl-texture2d-tests.ts new file mode 100644 index 0000000000..f51046f420 --- /dev/null +++ b/types/gl-texture2d/gl-texture2d-tests.ts @@ -0,0 +1,79 @@ +import texture2d = require("gl-texture2d"); +import ndarray = require("ndarray"); + +const gl = new WebGLRenderingContext(); +const canvas = new HTMLCanvasElement(); +const video = new HTMLVideoElement(); +const image = new HTMLImageElement(); +const imageData = new ImageData(1, 1); + +// tslint:disable-next-line: no-unnecessary-generics +declare function rawType(): {width: number, height: number, raw: T}; + +texture2d(gl, canvas); +texture2d(gl, canvas, gl.RGBA); +texture2d(gl, canvas, gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, video); +texture2d(gl, video, gl.RGBA); +texture2d(gl, video, gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, image); +texture2d(gl, image, gl.RGBA); +texture2d(gl, image, gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, imageData); +texture2d(gl, imageData, gl.RGBA); +texture2d(gl, imageData, gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, [1, 1]); +texture2d(gl, [1, 1], gl.RGBA); +texture2d(gl, [1, 1], gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, rawType()); +texture2d(gl, rawType(), gl.RGBA); +texture2d(gl, rawType(), gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, rawType()); +texture2d(gl, rawType(), gl.RGBA); +texture2d(gl, rawType(), gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, rawType()); +texture2d(gl, rawType(), gl.RGBA); +texture2d(gl, rawType(), gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, rawType()); +texture2d(gl, rawType(), gl.RGBA); +texture2d(gl, rawType(), gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, rawType()); +texture2d(gl, rawType(), gl.RGBA); +texture2d(gl, rawType(), gl.RGBA, gl.UNSIGNED_BYTE); + +texture2d(gl, ndarray([1, 2, 3])); + +const texture = texture2d(gl, canvas); + +texture.bind(); +texture.bind(1); +texture.dispose(); +texture.generateMipmap(); + +texture.magFilter = 1; +texture.minFilter = 1; +texture.mipSamples = 1; + +texture.shape = [1, 1]; +texture.wrap = [gl.REPEAT, gl.REPEAT]; + + // $ExpectType WebGLRenderingContext +texture.gl; + +// $ExpectType WebGLTexture +texture.handle; + +// $ExpectType number +texture.format; + +// $expectType number +texture.type; diff --git a/types/gl-texture2d/index.d.ts b/types/gl-texture2d/index.d.ts new file mode 100644 index 0000000000..2b44b9985a --- /dev/null +++ b/types/gl-texture2d/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for gl-texture2d 2.1 +// Project: https://github.com/stackgl/gl-texture2d +// Definitions by: Mathias Paumgarten +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import ndarray = require("ndarray"); + +type InputType = ImageData | HTMLCanvasElement | HTMLImageElement | HTMLVideoElement; + +interface RawObject { + width: number; + height: number; + raw: ArrayBufferView | InputType | ImageBitmap; +} + +declare class Texture { + shape: [number, number]; + wrap: [GLenum, GLenum]; + magFilter: GLenum; + minFilter: GLenum; + mipSamples: GLenum; + + readonly gl: WebGLRenderingContext; + readonly handle: WebGLTexture; + readonly format: GLenum; + readonly type: GLenum; + + bind(id?: number): number; + dispose(): void; + generateMipmap(): void; +} + +declare function texture2d(gl: WebGLRenderingContext, array: ndarray): Texture; + +declare function texture2d( + gl: WebGLRenderingContext, + input: InputType | RawObject | [number, number], + format?: GLenum, + type?: GLenum): Texture; + +export = texture2d; diff --git a/types/gl-texture2d/tsconfig.json b/types/gl-texture2d/tsconfig.json new file mode 100644 index 0000000000..32954b0979 --- /dev/null +++ b/types/gl-texture2d/tsconfig.json @@ -0,0 +1,24 @@ +{ + "files": [ + "index.d.ts", + "gl-texture2d-tests.ts" + ], + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/types/gl-texture2d/tslint.json b/types/gl-texture2d/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/gl-texture2d/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}