Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "gl-util", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Set of practical webgl utils", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,33 @@ # gl-util [![unstable](http://badges.github.io/stability-badges/dist/unstable.svg)](http://github.com/badges/stability-badges) | ||
```js | ||
const util = require('gl-util'); | ||
let gl = util.context({preserveDrawingBuffer: false}) | ||
document.body.appendChild(gl.canvas) | ||
util.program(gl, ` | ||
precision mediump float; | ||
attribute vec2 position; | ||
void main() { | ||
gl_Position = vec4(position * 2. - 1., 0, 1); | ||
} | ||
`, ` | ||
precision mediump float; | ||
uniform vec4 color; | ||
void main () { | ||
gl_FragColor = color; | ||
} | ||
`); | ||
util.attribute(gl, 'position', [0,0, 1,0, 0,1]); | ||
util.uniform(gl, 'color', [1, .2, 0, 1.]); | ||
gl.drawArrays(gl.TRIANGLES, 0, 3); | ||
``` | ||
## API | ||
### `context(options)` | ||
@@ -14,2 +45,5 @@ | ||
|---|---|---| | ||
| `canvas` | | An existing canvas element to re-use rather than creating a new one. | | ||
| `width` | | If specified, will set the canvas width. | | ||
| `height` | | If specified, will set the canvas height. | | ||
| `antialias` | `true` | Enable antialiasing. | | ||
@@ -22,4 +56,15 @@ | `alpha` | `true` | Whether canvas contains an alpha buffer, i. e. can be transparent. If `false`, an alpha blending function `gl.blendEquation( gl.FUNC_ADD ); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)` will be enabled. | | ||
| `float` | `true` | Enable `OES_texture_float`/`OES_texture_float_linear` or `OES_texture_half_float`/`OES_texture_half_float_linear` extensions. | | ||
| `failIfMajorPerformanceCaveat` | `null` | Context will be created if the system performance is low. | | ||
| `failIfMajorPerformanceCaveat` | | Context will be created if the system performance is low. | | ||
```js | ||
const getContext = require('gl-util/context') | ||
let canvas = document.createElement('canvas') | ||
let gl = getContext('webgl', { | ||
canvas: canvas, | ||
antialias: true | ||
}) | ||
``` | ||
### `program(gl, program?)` | ||
@@ -30,2 +75,26 @@ ### `program(gl, vertSource, fragSource)` | ||
```js | ||
const createProgram = require('gl-util/program') | ||
let program = createProgram(gl, ` | ||
precision mediump float; | ||
attribute vec2 position; | ||
void main() { | ||
gl_Position = vec4(position * 2. - 1., 0, 1); | ||
} | ||
`, ` | ||
precision mediump float; | ||
uniform sampler2D image; | ||
uniform vec2 shape; | ||
uniform float x; | ||
void main () { | ||
gl_FragColor = texture2D(image, gl_FragCoord.xy / shape); | ||
} | ||
`) | ||
``` | ||
### `uniform(gl, name?, data?, program?)` | ||
@@ -36,2 +105,8 @@ ### `uniform(gl, {name: data, ...}, program?)` | ||
```js | ||
const uniform = require('gl-util/uniform') | ||
uniform(gl, 'color', [1, .2, 0, 1]); | ||
``` | ||
### `texture(gl, name?, data|parameters?, program?)` | ||
@@ -56,2 +131,8 @@ ### `texture(gl, {name: data|parameters, ...}, program?)` | ||
```js | ||
const texture = require('gl-util/texture') | ||
texture(gl, 'image', './picture.gif'); | ||
``` | ||
### `attribute(gl, name?, data|parameters?, program?)` | ||
@@ -77,2 +158,8 @@ ### `attribute(gl, {name: data|parameters, ...}, program?)` | ||
```js | ||
const attribute = require('gl-util/attribute') | ||
attribute(gl, 'position', [0,0,1,0,0,1]); | ||
``` | ||
## Motivation | ||
@@ -79,0 +166,0 @@ |
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
86903
165