New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gl-shader

Package Overview
Dependencies
Maintainers
11
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl-shader - npm Package Compare versions

Comparing version 4.2.1 to 4.3.1

50

lib/create-attributes.js

@@ -61,2 +61,36 @@ 'use strict'

var allFns = [
function (gl, v, x0) {
if (x0.length === undefined) {
return gl.vertexAttrib1f(v, x0)
} else {
return gl.vertexAttrib1fv(v, x0)
}
},
function (gl, v, x0, x1) {
if (x0.length === undefined) {
return gl.vertexAttrib2f(v, x0, x1)
} else {
return gl.vertexAttrib2fv(v, x0)
}
},
function (gl, v, x0, x1, x2) {
if (x0.length === undefined) {
return gl.vertexAttrib3f(v, x0, x1, x2)
} else {
return gl.vertexAttrib3fv(v, x0)
}
},
function (gl, v, x0, x1, x2, x3) {
if (x0.length === undefined) {
return gl.vertexAttrib4f(v, x0, x1, x2, x3)
} else {
return gl.vertexAttrib4fv(v, x0)
}
}
]
//Adds a vector attribute to obj

@@ -72,17 +106,3 @@ function addVectorAttribute(

//Construct constant function
var constFuncArgs = [ 'gl', 'v' ]
var varNames = []
for(var i=0; i<dimension; ++i) {
constFuncArgs.push('x'+i)
varNames.push('x'+i)
}
constFuncArgs.push(
'if(x0.length===void 0){return gl.vertexAttrib' +
dimension + 'f(v,' +
varNames.join() +
')}else{return gl.vertexAttrib' +
dimension +
'fv(v,x0)}')
var constFunc = Function.apply(null, constFuncArgs)
var constFunc = allFns[dimension]

@@ -89,0 +109,0 @@ //Create attribute wrapper

@@ -10,4 +10,5 @@ 'use strict'

function identity(x) {
var c = new Function('y', 'return function(){return y}')
return c(x)
return function() {
return x
}
}

@@ -26,46 +27,79 @@

function makeGetter(index) {
var proc = new Function(
'gl'
, 'wrapper'
, 'locations'
, 'return function(){return gl.getUniform(wrapper.program,locations[' + index + '])}')
return proc(gl, wrapper, locations)
function makeGetter(idx) {
return function(gl, wrapper, locations) {
return gl.getUniform(wrapper.program, locations[idx])
}
}
function makePropSetter(path, index, type) {
switch(type) {
case 'bool':
case 'int':
case 'sampler2D':
case 'samplerCube':
return 'gl.uniform1i(locations[' + index + '],obj' + path + ')'
case 'float':
return 'gl.uniform1f(locations[' + index + '],obj' + path + ')'
default:
var vidx = type.indexOf('vec')
if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) {
var d = type.charCodeAt(type.length-1) - 48
if(d < 2 || d > 4) {
throw new GLError('', 'Invalid data type')
function makeSetter(type) {
return function updateProperty(obj){
var indices = enumerateIndices('', type)
for(var i=0; i<indices.length; ++i) {
var item = indices[i]
var path = item[0]
var idx = item[1]
if(locations[idx]) {
var objPath = obj
if(typeof path === 'string' && (
path.indexOf('.') === 0 ||
path.indexOf('[') === 0
)) {
var key = path
if(path.indexOf('.') === 0) {
key = path.slice(1)
}
if(key.indexOf(']') === key.length - 1) {
var j = key.indexOf('[')
var k1 = key.slice(0, j)
var k2 = key.slice(j + 1, key.length - 1)
objPath = k1? obj[k1][k2] : obj[k2]
} else {
objPath = obj[key]
}
}
switch(type.charAt(0)) {
case 'b':
case 'i':
return 'gl.uniform' + d + 'iv(locations[' + index + '],obj' + path + ')'
case 'v':
return 'gl.uniform' + d + 'fv(locations[' + index + '],obj' + path + ')'
var t = uniforms[idx].type
var d
switch(t) {
case 'bool':
case 'int':
case 'sampler2D':
case 'samplerCube':
gl.uniform1i(locations[idx], objPath)
break
case 'float':
gl.uniform1f(locations[idx], objPath)
break
default:
throw new GLError('', 'Unrecognized data type for vector ' + name + ': ' + type)
var vidx = t.indexOf('vec')
if(0 <= vidx && vidx <= 1 && t.length === 4 + vidx) {
d = t.charCodeAt(t.length-1) - 48
if(d < 2 || d > 4) {
throw new GLError('', 'Invalid data type')
}
switch(t.charAt(0)) {
case 'b':
case 'i':
gl['uniform' + d + 'iv'](locations[idx], objPath)
break
case 'v':
gl['uniform' + d + 'fv'](locations[idx], objPath)
break
default:
throw new GLError('', 'Unrecognized data type for vector ' + name + ': ' + t)
}
} else if(t.indexOf('mat') === 0 && t.length === 4) {
d = t.charCodeAt(t.length-1) - 48
if(d < 2 || d > 4) {
throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + t)
}
gl['uniformMatrix' + d + 'fv'](locations[idx], false, objPath)
break
} else {
throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + t)
}
}
} else if(type.indexOf('mat') === 0 && type.length === 4) {
var d = type.charCodeAt(type.length-1) - 48
if(d < 2 || d > 4) {
throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + type)
}
return 'gl.uniformMatrix' + d + 'fv(locations[' + index + '],false,obj' + path + ')'
} else {
throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type)
}
break
}
}

@@ -96,17 +130,2 @@ }

function makeSetter(type) {
var code = [ 'return function updateProperty(obj){' ]
var indices = enumerateIndices('', type)
for(var i=0; i<indices.length; ++i) {
var item = indices[i]
var path = item[0]
var idx = item[1]
if(locations[idx]) {
code.push(makePropSetter(path, idx, uniforms[idx].type))
}
}
code.push('return obj}')
var proc = new Function('gl', 'locations', code.join('\n'))
return proc(gl, locations)
}

@@ -143,3 +162,2 @@ function defaultValue(type) {

}
break
}

@@ -146,0 +164,0 @@ }

{
"name": "gl-shader",
"version": "4.2.1",
"version": "4.3.1",
"description": "WebGL shader wrapper",

@@ -5,0 +5,0 @@ "main": "index.js",

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