Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

taiyaki

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

taiyaki - npm Package Compare versions

Comparing version 0.5.13 to 0.6.0

build/index.d.ts

545

build/src/RenderingContext.js

@@ -0,344 +1,257 @@

// @flow
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var RenderingContext = function () {
function RenderingContext(id) {
_classCallCheck(this, RenderingContext);
var canvas = document.getElementById(id);
if (canvas === null) {
throw new Error('Missing HTMLCanvasElement id: ' + id);
Object.defineProperty(exports, "__esModule", { value: true });
class RenderingContext {
constructor(id) {
const canvas = document.getElementById(id);
if (canvas === null) {
throw new Error(`Missing HTMLCanvasElement id: ${id}`);
}
this.canvas = canvas;
const gl = canvas.getContext('webgl');
if (gl === null) {
throw new Error('Missing WebGLRenderingContext');
}
this.gl = gl;
}
this.canvas = canvas;
var gl = canvas.getContext('webgl');
if (gl === null) {
throw new Error('Missing WebGLRenderingContext');
createProgram(ids) {
const gl = this.gl;
const program = gl.createProgram();
ids.forEach(id => {
gl.attachShader(program, this.createShader(id));
});
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error(gl.getProgramInfoLog(program));
}
return program;
}
this.gl = gl;
}
_createClass(RenderingContext, [{
key: 'createProgram',
value: function createProgram(ids) {
var _this = this;
var gl = this.gl;
var program = gl.createProgram();
ids.forEach(function (id) {
gl.attachShader(program, _this.createShader(id));
});
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error(gl.getProgramInfoLog(program));
}
return program;
useProgram(program) {
this.gl.useProgram(program);
}
}, {
key: 'useProgram',
value: function useProgram(program) {
this.gl.useProgram(program);
createShader(id) {
const gl = this.gl;
const element = document.getElementById(id);
if (element === null) {
throw new Error(`Missing HTMLScriptElement id: ${id}`);
}
const source = element;
let shader;
switch (source.type) {
case 'x-shader/x-vertex':
shader = gl.createShader(gl.VERTEX_SHADER);
break;
case 'x-shader/x-fragment':
shader = gl.createShader(gl.FRAGMENT_SHADER);
break;
default:
throw new Error('The shader type is not an accepted value.');
}
if (shader === null) {
throw new Error('Missing WebGLShader');
}
gl.shaderSource(shader, source.text);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw new Error(gl.getShaderInfoLog(shader));
}
return shader;
}
}, {
key: 'createShader',
value: function createShader(id) {
var gl = this.gl;
var source = document.getElementById(id);
if (source === null) {
throw new Error('Missing HTMLScriptElement id: ' + id);
}
var shader = void 0;
switch (source.type) {
case 'x-shader/x-vertex':
shader = gl.createShader(gl.VERTEX_SHADER);
break;
case 'x-shader/x-fragment':
shader = gl.createShader(gl.FRAGMENT_SHADER);
break;
default:
throw new Error('The shader type is not an accepted value.');
}
if (shader === null) {
throw new Error('Missing WebGLShader');
}
gl.shaderSource(shader, source.text);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw new Error(gl.getShaderInfoLog(shader));
}
return shader;
bindFramebuffer(frameBuffer) {
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer);
}
}, {
key: 'bindFramebuffer',
value: function bindFramebuffer(frameBuffer) {
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer);
createFrameBuffer(width, height) {
const gl = this.gl;
const frameBuffer = gl.createFramebuffer();
if (frameBuffer == null) {
throw new Error('Failed to create WebGLFramebuffer');
}
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
const renderBuffer = gl.createRenderbuffer();
if (renderBuffer == null) {
throw new Error('Failed to create WebGLRenderbuffer');
}
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderBuffer);
const texture = this.createFrameBufferTexture(width, height);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { value: frameBuffer, renderbuffer: renderBuffer, texture };
}
}, {
key: 'createFrameBuffer',
value: function createFrameBuffer(width, height) {
var gl = this.gl;
var frameBuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
var renderBuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderBuffer);
var texture = this.createFrameBufferTexture(width, height);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { value: frameBuffer, renderbuffer: renderBuffer, texture: texture };
createFrameBufferTexture(width, height) {
const gl = this.gl;
const texture = gl.createTexture();
if (texture == null) {
throw new Error('Failed to create WebGLTexture');
}
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
}
}, {
key: 'createFrameBufferTexture',
value: function createFrameBufferTexture(width, height) {
var gl = this.gl;
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
bindVbos(program, vbos) {
vbos.forEach(vbo => {
this.bindVbo(program, vbo);
});
}
}, {
key: 'bindVbos',
value: function bindVbos(program, vbos) {
var _this2 = this;
vbos.forEach(function (vbo) {
_this2.bindVbo(program, vbo);
});
bindVbo(program, vbo) {
const gl = this.gl;
const location = gl.getAttribLocation(program, vbo.name);
gl.bindBuffer(gl.ARRAY_BUFFER, this.createVbo(vbo.value));
gl.enableVertexAttribArray(location);
gl.vertexAttribPointer(location, vbo.stride, gl.FLOAT, false, 0, 0);
}
}, {
key: 'bindVbo',
value: function bindVbo(program, vbo) {
var gl = this.gl;
var location = gl.getAttribLocation(program, vbo.name);
gl.bindBuffer(gl.ARRAY_BUFFER, this.createVbo(vbo.value));
gl.enableVertexAttribArray(location);
gl.vertexAttribPointer(location, vbo.stride, gl.FLOAT, false, 0, 0);
createVbo(value) {
const gl = this.gl;
const vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(value), gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
return vbo;
}
}, {
key: 'createVbo',
value: function createVbo(value) {
var gl = this.gl;
var vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(value), gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
return vbo;
bindIbo(index) {
const gl = this.gl;
const ibo = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array(index), gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
}
}, {
key: 'bindIbo',
value: function bindIbo(index) {
var gl = this.gl;
var ibo = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array(index), gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
createCanvasTexture(canvas2d) {
const gl = this.gl;
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
gl.bindTexture(gl.TEXTURE_2D, null);
if (texture === null) {
throw new Error('Missing Texture');
}
return texture;
}
}, {
key: 'createCanvasTexture',
value: function createCanvasTexture(canvas2d) {
var gl = this.gl;
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
bindTexture(texture, slot) {
const gl = this.gl;
gl.activeTexture(gl.TEXTURE0 + slot);
gl.bindTexture(gl.TEXTURE_2D, texture);
}
}, {
key: 'bindTexture',
value: function bindTexture(texture, slot) {
var gl = this.gl;
gl.activeTexture(gl.TEXTURE0 + slot);
gl.bindTexture(gl.TEXTURE_2D, texture);
enable(cap) {
this.gl.enable(cap);
}
}, {
key: 'enable',
value: function enable(cap) {
this.gl.enable(cap);
disable(cap) {
this.gl.disable(cap);
}
}, {
key: 'disable',
value: function disable(cap) {
this.gl.disable(cap);
toggleCulFace(enable) {
const gl = this.gl;
if (enable) {
gl.enable(gl.CULL_FACE);
}
else {
gl.disable(gl.CULL_FACE);
}
}
}, {
key: 'toggleCulFace',
value: function toggleCulFace(enable) {
var gl = this.gl;
if (enable) {
gl.enable(gl.CULL_FACE);
} else {
gl.disable(gl.CULL_FACE);
}
toggleDepthFunc(enable) {
const gl = this.gl;
if (enable) {
gl.enable(gl.DEPTH_TEST);
}
else {
gl.disable(gl.DEPTH_TEST);
}
}
}, {
key: 'toggleDepthFunc',
value: function toggleDepthFunc(enable) {
var gl = this.gl;
if (enable) {
gl.enable(gl.DEPTH_TEST);
} else {
gl.disable(gl.DEPTH_TEST);
}
depthFunc() {
const gl = this.gl;
gl.depthFunc(gl.LEQUAL);
}
}, {
key: 'depthFunc',
value: function depthFunc() {
var gl = this.gl;
gl.depthFunc(gl.LEQUAL);
toggleBlend(enable) {
const gl = this.gl;
if (enable) {
gl.enable(gl.BLEND);
}
else {
gl.disable(gl.BLEND);
}
}
}, {
key: 'toggleBlend',
value: function toggleBlend(enable) {
var gl = this.gl;
if (enable) {
gl.enable(gl.BLEND);
} else {
gl.disable(gl.BLEND);
}
setBlending(type) {
const gl = this.gl;
switch (type) {
case RenderingContext.AdditiveBlending:
gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE);
break;
default:
break;
}
}
}, {
key: 'setBlending',
value: function setBlending(type) {
var gl = this.gl;
switch (type) {
case RenderingContext.AdditiveBlending:
gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE);
break;
default:
break;
}
bindUniforms(program, uniforms) {
uniforms.forEach(uniform => {
this.bindUniform(program, uniform);
});
}
}, {
key: 'bindUniforms',
value: function bindUniforms(program, uniforms) {
var _this3 = this;
uniforms.forEach(function (uniform) {
_this3.bindUniform(program, uniform);
});
bindUniform(program, uniform) {
const gl = this.gl;
const { name, type, value } = uniform;
const location = gl.getUniformLocation(program, name);
if (location === null) {
throw new Error('Missing WebGLUniformLocation');
}
switch (type) {
case 'matrix4fv':
gl.uniformMatrix4fv(location, false, value);
break;
case '4fv':
gl.uniform4fv(location, value);
break;
case '3fv':
gl.uniform3fv(location, value);
break;
case '2fv':
gl.uniform2fv(location, value);
break;
case '1fv':
gl.uniform1fv(location, value);
break;
case '1f':
gl.uniform1f(location, value);
break;
case '1iv':
gl.uniform1iv(location, value);
break;
case '1i':
gl.uniform1i(location, value);
break;
default:
}
}
}, {
key: 'bindUniform',
value: function bindUniform(program, uniform) {
var gl = this.gl;
var name = uniform.name,
type = uniform.type,
value = uniform.value;
var location = gl.getUniformLocation(program, name);
switch (type) {
case 'matrix4fv':
gl.uniformMatrix4fv(location, false, value);
break;
case '4fv':
gl.uniform4fv(location, value);
break;
case '3fv':
gl.uniform3fv(location, value);
break;
case '2fv':
gl.uniform2fv(location, value);
break;
case '1fv':
gl.uniform1fv(location, value);
break;
case '1f':
gl.uniform1f(location, value);
break;
case '1iv':
gl.uniform1iv(location, value);
break;
case '1i':
gl.uniform1i(location, value);
break;
default:
}
clear(color, depth) {
const gl = this.gl;
let flag = gl.COLOR_BUFFER_BIT;
gl.clearColor(color.r, color.g, color.b, color.a);
if (depth) {
gl.clearDepth(depth);
flag = gl.DEPTH_BUFFER_BIT;
}
gl.clear(flag);
}
}, {
key: 'clear',
value: function clear(color, depth) {
var gl = this.gl;
var flag = gl.COLOR_BUFFER_BIT;
gl.clearColor(color.r, color.g, color.b, color.a);
if (depth) {
gl.clearDepth(depth);
flag = gl.DEPTH_BUFFER_BIT;
}
gl.clear(flag);
viewport(viewport) {
this.gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
}
}, {
key: 'viewport',
value: function viewport(_viewport) {
this.gl.viewport(_viewport.x, _viewport.y, _viewport.width, _viewport.height);
drawArrays(mode, count, first = 0) {
const gl = this.gl;
gl.drawArrays(mode, first, count);
}
}, {
key: 'drawArrays',
value: function drawArrays(mode, count) {
var first = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var gl = this.gl;
gl.drawArrays(mode, first, count);
drawElements(mode, count, offset = 0) {
const gl = this.gl;
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset);
}
}, {
key: 'drawElements',
value: function drawElements(mode, count) {
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var gl = this.gl;
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset);
}
}]);
return RenderingContext;
}();
}
RenderingContext.AdditiveBlending = 'AdditiveBlending';
exports.RenderingContext = RenderingContext;
exports.RenderingContext = RenderingContext;
{
"name": "taiyaki",
"author": "dorayakikun",
"description": "the lightweight library of WebGL.",
"version": "0.5.13",
"author": "dorayakikun",
"devDependencies": {
"babel-cli": "6.26.0",
"babel-eslint": "8.2.0",
"babel-plugin-istanbul": "4.1.5",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-preset-es2015": "6.24.1",
"babel-preset-flow": "6.23.0",
"babelify": "^8.0.0",
"browserify": "^15.1.0",
"eslint": "4.17.0",
"eslint-config-fbjs": "^2.0.1",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-flowtype": "^2.42.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.1",
"eslint-plugin-relay": "0.0.20",
"flow-bin": "0.64.0",
"flow-copy-source": "^1.2.1",
"flow-typed": "^2.1.2",
"@types/jasmine": "^2.8.6",
"husky": "^0.14.3",
"jasmine-core": "^2.6.2",
"jasmine-core": "^3.0.0",
"karma": "^2.0.0",
"karma-babel-preprocessor": "^7.0.0",
"karma-browserify": "5.1.3",
"karma-chrome-launcher": "^2.1.1",
"karma-cli": "^1.0.1",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"lint-staged": "^6.0.0",
"prettier": "^1.10.1"
"karma-typescript": "^3.0.12",
"lint-staged": "^7.0.0",
"prettier": "^1.10.1",
"tslint": "^5.9.1",
"typescript": "^2.7.2",
"typings": "^2.1.1"
},

@@ -39,3 +23,3 @@ "files": [

"LICENSE",
"index.js",
"index.ts",
"package.json",

@@ -55,3 +39,4 @@ "src",

},
"main": "index.js",
"main": "build/index.js",
"name": "taiyaki",
"repository": {

@@ -62,12 +47,10 @@ "type": "git",

"scripts": {
"build": "babel src --out-dir build/src",
"fmt": "prettier --write '**/*.{js,json,md}'",
"flow": "flow",
"build": "tsc -d",
"fmt": "prettier --write '**/*.{js,json,md,ts}'",
"karma": "karma start karma.conf.js --single-run",
"lint": "eslint src",
"precommit": "lint-staged",
"prepare": "npm run build",
"prepush": "npm run build",
"prepack": "npm run build",
"test": "echo \"Please run karma\""
}
},
"version": "0.6.0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc