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

gl-util

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl-util

Set of practical webgl utils

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179K
increased by1.02%
Maintainers
1
Weekly downloads
 
Created
Source

gl-util unstable

Set of practical functions for webgl.

npm install gl-util

program(gl, program?)

program(gl, vertSource, fragSource)

Get/set current program or create new program from vertex and fragment sources.

uniform(gl, name?, data?)

uniform(gl, {name: data, ...})

Get/set uniform or multiple uniforms. Returns object with uniform parameters: {name, location, data, type}.

texture(gl, name?, data|parameters?)

texture(gl, {name: data|parameters, ...})

Set texture[s] data or parameters:

NameMeaning
dataData passed to texture.
indexTexture unit number, if undefined - calculated automatically.
filterSets texture scaling for both min and mag. Can be defined as two separate properties minFilter and magFilter. By default gl.LINEAR.
wrapDefines texture tiling vertically and horizontally. Can be defined precisely as wrapS and wrapT. By default gl.MIRRORED_REPEAT.
widthIn pixels
heightIn pixels
formatBy default gl.RGBA
typegl.UNSIGNED_BYTE, can be gl.FLOAT with proper extension enabled

Returns object with texture properties {data, index, minFilter, magFilter, wrapS, wrapT, width, height, format, type}.

attribute(gl, name?, data|parameters?)

attribute(gl, {name: data|parameters, ...})

Set attribute[s] data or parameters:

NameDefaultMeaning
datanullData for the attribute, can be array or typed array
size2Number of data items per vertex
stride0Offset in bytes between the beginning of consecutive vertex attributes.
offset0Offset in bytes of the first component in the data. Must be a multiple of type.
typegl.FLOATData type of each component in the data array. Must be one of: gl.BYTE, gl.UNSIGNED_BYTE, gl.SHORT, gl.UNSIGNED_SHORT, gl.FLOAT.
usagegl.STATIC_DRAWMode of draw: gl.STATIC_DRAW (rare changes), gl.DYNAMIC_DRAW (frequent changes) or gl.STREAM_DRAW (frequent updates)
normalizedfalseIf fixed-point data values should be normalized or are to converted to fixed point values when accessed.
index0Attribute unit number, detected automatically if omitted.
targetgl.ARRAY_BUFFER
buffernullWebGLBuffer to use for attribute

Returns attribute properties {data, size, stride, offset, usage, type, normalized, index, target, buffer}

Related docs: vertexAttribPointer.

Motivation

There are regl, stack.gl and other assorted libs, so why bother?

Because I have hard time remembering their API or pure webgl API. Also they supersede webgl API, so that if one would like to debug vanilla webgl for a moment it would be utterly impossible. Also oftentimes I need minimalistic webgl setup, but regl or stack.gl components tend to be relatively massive.

gl-util is like functions from any webgl tutorial. Tiny, handy and already familiar, so.

Keywords

FAQs

Package last updated on 30 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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