mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 12:08:59 +08:00
adds gl-texture2d types (#25378)
* adds gl-texture2d type * remove package.json
This commit is contained in:
committed by
Wesley Wigham
parent
27c9b44924
commit
447e24325a
79
types/gl-texture2d/gl-texture2d-tests.ts
Normal file
79
types/gl-texture2d/gl-texture2d-tests.ts
Normal file
@@ -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<T>(): {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<ImageData>());
|
||||
texture2d(gl, rawType<ImageData>(), gl.RGBA);
|
||||
texture2d(gl, rawType<ImageData>(), gl.RGBA, gl.UNSIGNED_BYTE);
|
||||
|
||||
texture2d(gl, rawType<ArrayBufferView>());
|
||||
texture2d(gl, rawType<ArrayBufferView>(), gl.RGBA);
|
||||
texture2d(gl, rawType<ArrayBufferView>(), gl.RGBA, gl.UNSIGNED_BYTE);
|
||||
|
||||
texture2d(gl, rawType<HTMLCanvasElement>());
|
||||
texture2d(gl, rawType<HTMLCanvasElement>(), gl.RGBA);
|
||||
texture2d(gl, rawType<HTMLCanvasElement>(), gl.RGBA, gl.UNSIGNED_BYTE);
|
||||
|
||||
texture2d(gl, rawType<HTMLImageElement>());
|
||||
texture2d(gl, rawType<HTMLImageElement>(), gl.RGBA);
|
||||
texture2d(gl, rawType<HTMLImageElement>(), gl.RGBA, gl.UNSIGNED_BYTE);
|
||||
|
||||
texture2d(gl, rawType<HTMLVideoElement>());
|
||||
texture2d(gl, rawType<HTMLVideoElement>(), gl.RGBA);
|
||||
texture2d(gl, rawType<HTMLVideoElement>(), 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;
|
||||
42
types/gl-texture2d/index.d.ts
vendored
Normal file
42
types/gl-texture2d/index.d.ts
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Type definitions for gl-texture2d 2.1
|
||||
// Project: https://github.com/stackgl/gl-texture2d
|
||||
// Definitions by: Mathias Paumgarten <https://github.com/MathiasPaumgarten>
|
||||
// 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;
|
||||
24
types/gl-texture2d/tsconfig.json
Normal file
24
types/gl-texture2d/tsconfig.json
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
3
types/gl-texture2d/tslint.json
Normal file
3
types/gl-texture2d/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user