Comparing version 0.6.0 to 0.6.1
@@ -1,1 +0,1 @@ | ||
export * from './src/RenderingContext'; | ||
export * from "./src/RenderingContext"; |
// @flow | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -11,5 +11,5 @@ class RenderingContext { | ||
this.canvas = canvas; | ||
const gl = canvas.getContext('webgl'); | ||
const gl = canvas.getContext("webgl"); | ||
if (gl === null) { | ||
throw new Error('Missing WebGLRenderingContext'); | ||
throw new Error("Missing WebGLRenderingContext"); | ||
} | ||
@@ -42,13 +42,13 @@ this.gl = gl; | ||
switch (source.type) { | ||
case 'x-shader/x-vertex': | ||
case "x-shader/x-vertex": | ||
shader = gl.createShader(gl.VERTEX_SHADER); | ||
break; | ||
case 'x-shader/x-fragment': | ||
case "x-shader/x-fragment": | ||
shader = gl.createShader(gl.FRAGMENT_SHADER); | ||
break; | ||
default: | ||
throw new Error('The shader type is not an accepted value.'); | ||
throw new Error("The shader type is not an accepted value."); | ||
} | ||
if (shader === null) { | ||
throw new Error('Missing WebGLShader'); | ||
throw new Error("Missing WebGLShader"); | ||
} | ||
@@ -69,3 +69,3 @@ gl.shaderSource(shader, source.text); | ||
if (frameBuffer == null) { | ||
throw new Error('Failed to create WebGLFramebuffer'); | ||
throw new Error("Failed to create WebGLFramebuffer"); | ||
} | ||
@@ -75,3 +75,3 @@ gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); | ||
if (renderBuffer == null) { | ||
throw new Error('Failed to create WebGLRenderbuffer'); | ||
throw new Error("Failed to create WebGLRenderbuffer"); | ||
} | ||
@@ -90,3 +90,3 @@ gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer); | ||
if (texture == null) { | ||
throw new Error('Failed to create WebGLTexture'); | ||
throw new Error("Failed to create WebGLTexture"); | ||
} | ||
@@ -143,3 +143,3 @@ gl.bindTexture(gl.TEXTURE_2D, texture); | ||
if (texture === null) { | ||
throw new Error('Missing Texture'); | ||
throw new Error("Missing Texture"); | ||
} | ||
@@ -210,27 +210,27 @@ return texture; | ||
if (location === null) { | ||
throw new Error('Missing WebGLUniformLocation'); | ||
throw new Error("Missing WebGLUniformLocation"); | ||
} | ||
switch (type) { | ||
case 'matrix4fv': | ||
case "matrix4fv": | ||
gl.uniformMatrix4fv(location, false, value); | ||
break; | ||
case '4fv': | ||
case "4fv": | ||
gl.uniform4fv(location, value); | ||
break; | ||
case '3fv': | ||
case "3fv": | ||
gl.uniform3fv(location, value); | ||
break; | ||
case '2fv': | ||
case "2fv": | ||
gl.uniform2fv(location, value); | ||
break; | ||
case '1fv': | ||
case "1fv": | ||
gl.uniform1fv(location, value); | ||
break; | ||
case '1f': | ||
case "1f": | ||
gl.uniform1f(location, value); | ||
break; | ||
case '1iv': | ||
case "1iv": | ||
gl.uniform1iv(location, value); | ||
break; | ||
case '1i': | ||
case "1i": | ||
gl.uniform1i(location, value); | ||
@@ -263,3 +263,3 @@ break; | ||
} | ||
RenderingContext.AdditiveBlending = 'AdditiveBlending'; | ||
RenderingContext.AdditiveBlending = "AdditiveBlending"; | ||
exports.RenderingContext = RenderingContext; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const RenderingContext_1 = require("../src/RenderingContext"); | ||
describe('RenderingContext tests', () => { | ||
describe("RenderingContext tests", () => { | ||
afterEach(() => { | ||
@@ -11,14 +11,14 @@ const root = document.body; | ||
}); | ||
it('Should pass when exists specified HTMLCanvasElement', () => { | ||
it("Should pass when exists specified HTMLCanvasElement", () => { | ||
const canvas = '<canvas id="main"></canvas>'; | ||
document.body.insertAdjacentHTML('afterbegin', canvas); | ||
new RenderingContext_1.RenderingContext('main'); | ||
document.body.insertAdjacentHTML("afterbegin", canvas); | ||
const _ctx = new RenderingContext_1.RenderingContext("main"); | ||
}); | ||
it('Should throw error when missing specified HTMLCanvasElement', () => { | ||
it("Should throw error when missing specified HTMLCanvasElement", () => { | ||
const canvas = '<canvas id="missing"></canvas>'; | ||
document.body.insertAdjacentHTML('afterbegin', canvas); | ||
document.body.insertAdjacentHTML("afterbegin", canvas); | ||
expect(() => { | ||
new RenderingContext_1.RenderingContext('main'); | ||
}).toThrow(new Error('Missing HTMLCanvasElement id: main')); | ||
const _ctx = new RenderingContext_1.RenderingContext("main"); | ||
}).toThrow(new Error("Missing HTMLCanvasElement id: main")); | ||
}); | ||
}); |
@@ -1,1 +0,1 @@ | ||
export * from './src/RenderingContext' | ||
export * from "./src/RenderingContext"; |
@@ -5,16 +5,24 @@ { | ||
"devDependencies": { | ||
"@types/jasmine": "^2.8.6", | ||
"husky": "^0.14.3", | ||
"jasmine-core": "^3.0.0", | ||
"karma": "^2.0.0", | ||
"@types/jasmine": "^3.3.2", | ||
"eslint": "^5.10.0", | ||
"eslint-config-prettier": "^3.3.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"husky": "^1.3.0", | ||
"jasmine-core": "^3.3.0", | ||
"karma": "^3.1.4", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-cli": "^1.0.1", | ||
"karma-cli": "^2.0.0", | ||
"karma-coverage": "^1.1.1", | ||
"karma-jasmine": "^1.1.0", | ||
"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" | ||
"karma-jasmine": "^2.0.0", | ||
"karma-typescript": "^3.0.13", | ||
"lint-staged": "^8.1.0", | ||
"prettier": "^1.15.3", | ||
"tslint": "^5.12.0", | ||
"typescript": "^3.2.2", | ||
"typescript-eslint-parser": "^21.0.2" | ||
}, | ||
@@ -29,2 +37,3 @@ "files": [ | ||
], | ||
"types": "build/index.d.ts", | ||
"keywords": [ | ||
@@ -48,3 +57,3 @@ "WebGL" | ||
"build": "tsc -d", | ||
"fmt": "prettier --write '**/*.{js,json,md,ts}'", | ||
"fmt": "eslint --fix --ext .ts .", | ||
"karma": "karma start karma.conf.js --single-run", | ||
@@ -55,3 +64,3 @@ "precommit": "lint-staged", | ||
}, | ||
"version": "0.6.0" | ||
"version": "0.6.1" | ||
} |
# taiyaki | ||
[![](http://img.shields.io/npm/dm/taiyaki.svg)](https://www.npmjs.org/package/taiayaki) | ||
[![CircleCI](https://circleci.com/gh/dorayakikun/taiyaki.svg?style=svg)](https://circleci.com/gh/dorayakikun/taiyaki) | ||
[![npm version](https://badge.fury.io/js/taiyaki.svg)](https://www.npmjs.com/package/taiyaki) | ||
[![Build Status](https://travis-ci.org/dorayakikun/taiyaki.svg?branch=master)](https://travis-ci.org/dorayakikun/taiyaki) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/dorayakikun/taiyaki.svg)](https://greenkeeper.io/) | ||
@@ -7,0 +7,0 @@ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) |
// @flow | ||
'use strict' | ||
"use strict"; | ||
export interface TYVBO { | ||
name: string | ||
value: number | ||
stride: number | ||
name: string; | ||
value: number; | ||
stride: number; | ||
} | ||
export interface TYUniform { | ||
name: string | ||
type: string | ||
value: any | ||
name: string; | ||
type: string; | ||
value: any; | ||
} | ||
export interface TYColor { | ||
r: number | ||
g: number | ||
b: number | ||
a: number | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
} | ||
export interface TYViewport { | ||
x: number | ||
y: number | ||
width: number | ||
height: number | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
} | ||
export interface TYFrameBuffer { | ||
value: WebGLFramebuffer | ||
renderbuffer: WebGLRenderbuffer | ||
texture: WebGLTexture | ||
value: WebGLFramebuffer; | ||
renderbuffer: WebGLRenderbuffer; | ||
texture: WebGLTexture; | ||
} | ||
export class RenderingContext { | ||
canvas: HTMLCanvasElement | ||
gl: WebGLRenderingContext | ||
canvas: HTMLCanvasElement; | ||
gl: WebGLRenderingContext; | ||
static AdditiveBlending = 'AdditiveBlending' | ||
static AdditiveBlending = "AdditiveBlending"; | ||
constructor(id: string) { | ||
const canvas = document.getElementById(id) as HTMLCanvasElement | ||
const canvas = document.getElementById(id) as HTMLCanvasElement; | ||
if (canvas === null) { | ||
throw new Error(`Missing HTMLCanvasElement id: ${id}`) | ||
throw new Error(`Missing HTMLCanvasElement id: ${id}`); | ||
} | ||
this.canvas = canvas | ||
const gl = canvas.getContext('webgl') | ||
this.canvas = canvas; | ||
const gl = canvas.getContext("webgl"); | ||
if (gl === null) { | ||
throw new Error('Missing WebGLRenderingContext') | ||
throw new Error("Missing WebGLRenderingContext"); | ||
} | ||
this.gl = gl | ||
this.gl = gl; | ||
} | ||
createProgram(ids: string[]): WebGLProgram { | ||
const gl = this.gl | ||
const program = gl.createProgram() | ||
const gl = this.gl; | ||
const program = gl.createProgram() as WebGLProgram; | ||
ids.forEach(id => { | ||
gl.attachShader(program, this.createShader(id)) | ||
}) | ||
gl.attachShader(program, this.createShader(id)); | ||
}); | ||
gl.linkProgram(program) | ||
gl.linkProgram(program); | ||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { | ||
throw new Error(gl.getProgramInfoLog(program) as string) | ||
throw new Error(gl.getProgramInfoLog(program) as string); | ||
} | ||
return program as WebGLProgram | ||
return program as WebGLProgram; | ||
} | ||
useProgram(program: WebGLProgram) { | ||
this.gl.useProgram(program) | ||
this.gl.useProgram(program); | ||
} | ||
createShader(id: string): WebGLShader { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
const element = document.getElementById(id) | ||
const element = document.getElementById(id); | ||
if (element === null) { | ||
throw new Error(`Missing HTMLScriptElement id: ${id}`) | ||
throw new Error(`Missing HTMLScriptElement id: ${id}`); | ||
} | ||
const source: HTMLScriptElement = element as HTMLScriptElement | ||
let shader: WebGLShader | null | ||
const source: HTMLScriptElement = element as HTMLScriptElement; | ||
let shader: WebGLShader | null; | ||
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 | ||
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.') | ||
throw new Error("The shader type is not an accepted value."); | ||
} | ||
if (shader === null) { | ||
throw new Error('Missing WebGLShader') | ||
throw new Error("Missing WebGLShader"); | ||
} | ||
gl.shaderSource(shader, source.text) | ||
gl.compileShader(shader) | ||
gl.shaderSource(shader, source.text); | ||
gl.compileShader(shader); | ||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { | ||
throw new Error(gl.getShaderInfoLog(shader) as string) | ||
throw new Error(gl.getShaderInfoLog(shader) as string); | ||
} | ||
return shader | ||
return shader; | ||
} | ||
bindFramebuffer(frameBuffer: WebGLFramebuffer) { | ||
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer) | ||
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer); | ||
} | ||
createFrameBuffer(width: number, height: number): TYFrameBuffer { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
const frameBuffer: WebGLFramebuffer | null = gl.createFramebuffer() | ||
const frameBuffer: WebGLFramebuffer | null = gl.createFramebuffer(); | ||
if (frameBuffer == null) { | ||
throw new Error('Failed to create WebGLFramebuffer') | ||
throw new Error("Failed to create WebGLFramebuffer"); | ||
} | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer) | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); | ||
const renderBuffer: WebGLRenderbuffer | null = gl.createRenderbuffer() | ||
const renderBuffer: WebGLRenderbuffer | null = gl.createRenderbuffer(); | ||
if (renderBuffer == null) { | ||
throw new Error('Failed to create WebGLRenderbuffer') | ||
throw new Error("Failed to create WebGLRenderbuffer"); | ||
} | ||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer) | ||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer); | ||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height) | ||
gl.renderbufferStorage( | ||
gl.RENDERBUFFER, | ||
gl.DEPTH_COMPONENT16, | ||
width, | ||
height | ||
); | ||
gl.framebufferRenderbuffer( | ||
@@ -134,18 +139,18 @@ gl.FRAMEBUFFER, | ||
renderBuffer | ||
) | ||
); | ||
const texture = this.createFrameBufferTexture(width, height) | ||
gl.bindRenderbuffer(gl.RENDERBUFFER, null) | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, null) | ||
const texture = this.createFrameBufferTexture(width, height); | ||
gl.bindRenderbuffer(gl.RENDERBUFFER, null); | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, null); | ||
return { value: frameBuffer, renderbuffer: renderBuffer, texture } | ||
return { value: frameBuffer, renderbuffer: renderBuffer, texture }; | ||
} | ||
createFrameBufferTexture(width: number, height: number): WebGLTexture { | ||
const gl = this.gl | ||
const texture: WebGLTexture | null = gl.createTexture() | ||
const gl = this.gl; | ||
const texture: WebGLTexture | null = gl.createTexture(); | ||
if (texture == null) { | ||
throw new Error('Failed to create WebGLTexture') | ||
throw new Error("Failed to create WebGLTexture"); | ||
} | ||
gl.bindTexture(gl.TEXTURE_2D, texture) | ||
gl.bindTexture(gl.TEXTURE_2D, texture); | ||
@@ -162,9 +167,9 @@ gl.texImage2D( | ||
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_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.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); | ||
gl.framebufferTexture2D( | ||
@@ -176,7 +181,7 @@ gl.FRAMEBUFFER, | ||
0 | ||
) | ||
); | ||
gl.bindTexture(gl.TEXTURE_2D, null) | ||
gl.bindTexture(gl.TEXTURE_2D, null); | ||
return texture | ||
return texture; | ||
} | ||
@@ -186,27 +191,27 @@ | ||
vbos.forEach(vbo => { | ||
this.bindVbo(program, vbo) | ||
}) | ||
this.bindVbo(program, vbo); | ||
}); | ||
} | ||
bindVbo(program: WebGLProgram, vbo: TYVBO) { | ||
const gl = this.gl | ||
const location: number = 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) | ||
const gl = this.gl; | ||
const location: number = 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: number): WebGLBuffer | null { | ||
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 | ||
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; | ||
} | ||
bindIbo(index: number) { | ||
const gl = this.gl | ||
const ibo: WebGLBuffer | null = gl.createBuffer() | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo) | ||
const gl = this.gl; | ||
const ibo: WebGLBuffer | null = gl.createBuffer(); | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo); | ||
gl.bufferData( | ||
@@ -216,12 +221,12 @@ gl.ELEMENT_ARRAY_BUFFER, | ||
gl.STATIC_DRAW | ||
) | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null) | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo) | ||
); | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo); | ||
} | ||
createCanvasTexture(canvas2d: HTMLCanvasElement): WebGLTexture { | ||
const gl = this.gl | ||
const texture: WebGLTexture | null = gl.createTexture() | ||
const gl = this.gl; | ||
const texture: WebGLTexture | null = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, texture) | ||
gl.bindTexture(gl.TEXTURE_2D, texture); | ||
gl.texImage2D( | ||
@@ -234,37 +239,37 @@ gl.TEXTURE_2D, | ||
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.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) | ||
gl.bindTexture(gl.TEXTURE_2D, null); | ||
if (texture === null) { | ||
throw new Error('Missing Texture') | ||
throw new Error("Missing Texture"); | ||
} | ||
return texture | ||
return texture; | ||
} | ||
bindTexture(texture: WebGLTexture, slot: number) { | ||
const gl = this.gl | ||
gl.activeTexture(gl.TEXTURE0 + slot) | ||
gl.bindTexture(gl.TEXTURE_2D, texture) | ||
const gl = this.gl; | ||
gl.activeTexture(gl.TEXTURE0 + slot); | ||
gl.bindTexture(gl.TEXTURE_2D, texture); | ||
} | ||
enable(cap: number) { | ||
this.gl.enable(cap) | ||
this.gl.enable(cap); | ||
} | ||
disable(cap: number) { | ||
this.gl.disable(cap) | ||
this.gl.disable(cap); | ||
} | ||
toggleCulFace(enable: boolean) { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
if (enable) { | ||
gl.enable(gl.CULL_FACE) | ||
gl.enable(gl.CULL_FACE); | ||
} else { | ||
gl.disable(gl.CULL_FACE) | ||
gl.disable(gl.CULL_FACE); | ||
} | ||
@@ -274,7 +279,7 @@ } | ||
toggleDepthFunc(enable: boolean) { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
if (enable) { | ||
gl.enable(gl.DEPTH_TEST) | ||
gl.enable(gl.DEPTH_TEST); | ||
} else { | ||
gl.disable(gl.DEPTH_TEST) | ||
gl.disable(gl.DEPTH_TEST); | ||
} | ||
@@ -284,12 +289,12 @@ } | ||
depthFunc() { | ||
const gl = this.gl | ||
gl.depthFunc(gl.LEQUAL) | ||
const gl = this.gl; | ||
gl.depthFunc(gl.LEQUAL); | ||
} | ||
toggleBlend(enable: boolean) { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
if (enable) { | ||
gl.enable(gl.BLEND) | ||
gl.enable(gl.BLEND); | ||
} else { | ||
gl.disable(gl.BLEND) | ||
gl.disable(gl.BLEND); | ||
} | ||
@@ -299,9 +304,9 @@ } | ||
setBlending(type: string) { | ||
const gl = this.gl | ||
const gl = this.gl; | ||
switch (type) { | ||
case RenderingContext.AdditiveBlending: | ||
gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE) | ||
break | ||
gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); | ||
break; | ||
default: | ||
break | ||
break; | ||
} | ||
@@ -312,42 +317,42 @@ } | ||
uniforms.forEach(uniform => { | ||
this.bindUniform(program, uniform) | ||
}) | ||
this.bindUniform(program, uniform); | ||
}); | ||
} | ||
bindUniform(program: WebGLProgram, uniform: TYUniform) { | ||
const gl = this.gl | ||
const { name, type, value } = uniform | ||
const gl = this.gl; | ||
const { name, type, value } = uniform; | ||
const location: WebGLUniformLocation | null = gl.getUniformLocation( | ||
program, | ||
name | ||
) | ||
); | ||
if (location === null) { | ||
throw new Error('Missing WebGLUniformLocation') | ||
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 | ||
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: | ||
@@ -358,28 +363,28 @@ } | ||
clear(color: TYColor, depth: number) { | ||
const gl = this.gl | ||
let flag = gl.COLOR_BUFFER_BIT | ||
const gl = this.gl; | ||
let flag = gl.COLOR_BUFFER_BIT; | ||
gl.clearColor(color.r, color.g, color.b, color.a) | ||
gl.clearColor(color.r, color.g, color.b, color.a); | ||
if (depth) { | ||
gl.clearDepth(depth) | ||
flag = gl.DEPTH_BUFFER_BIT | ||
gl.clearDepth(depth); | ||
flag = gl.DEPTH_BUFFER_BIT; | ||
} | ||
gl.clear(flag) | ||
gl.clear(flag); | ||
} | ||
viewport(viewport: TYViewport) { | ||
this.gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height) | ||
this.gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); | ||
} | ||
drawArrays(mode: number, count: number, first: number = 0) { | ||
const gl = this.gl | ||
gl.drawArrays(mode, first, count) | ||
const gl = this.gl; | ||
gl.drawArrays(mode, first, count); | ||
} | ||
drawElements(mode: number, count: number, offset: number = 0) { | ||
const gl = this.gl | ||
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) | ||
const gl = this.gl; | ||
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25717
668
0
22
12