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

shader-program-compiler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shader-program-compiler - npm Package Compare versions

Comparing version

to
0.0.3

tmp/Appendix/ColoredTriangle.frag

154

lib/index.js

@@ -12,5 +12,8 @@ 'use strict';

fShader = _ref.fShader,
gl = _ref.gl;
gl = _ref.gl,
options = _ref.options;
var textureCount = 0;
function createShaderProgram(vShaderSource, fShaderSource, gl) {

@@ -89,21 +92,4 @@

manager.fill = function (data) {
var length = data.length / vecSize;
if (length - Math.floor(length) !== 0) {
throw new Error('attribute ' + attribute.name + '\'s length invalid, expect times of ' + vecSize + ' but ' + data.length);
}
if (attributeLength) {
if (attributeLength === data.length / vecSize) {
// ok, do nothing
} else {
throw new Error('attribute ' + attribute.name + '\'s length invalid, expect ' + attributeLength + ' but ' + data.length);
}
} else {
attributeLength = data.length / vecSize;
}
var buffer = gl.createBuffer();
manager.fill = function (buffer) {
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new ArrayType(data), gl.STATIC_DRAW);
gl.vertexAttribPointer(position, vecSize, gl[baseType], false, 0, 0);

@@ -113,2 +99,10 @@ gl.enableVertexAttribArray(position);

manager.createBuffer = function (value) {
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new ArrayType(value), gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
return buffer;
};
return _extends({

@@ -130,3 +124,3 @@ type: type }, manager);

'FLOAT': Float32Array,
'INT': Int16Array,
'INT': Int32Array,
'BOOL': Uint8Array

@@ -160,13 +154,40 @@ };

uniformMethodName = ['uniform', '1', 'i'].join('');
var texture = gl.createTexture();
manager.fill = function (image) {
manager.createTexture = function (image) {
var flipY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var texture = gl.createTexture();
gl.activeTexture(gl[textureUnitName]);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
if (flipY) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
}
if (image instanceof Uint8Array) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
if (flipY) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
}
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
};
manager.fill = function (texture) {
gl.activeTexture(gl[textureUnitName]);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.uniform1i(position, textureUnitIndex);
};
manager.update = function (image) {
manager.update = function (texture, image) {
gl.activeTexture(gl[textureUnitName]);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);

@@ -183,5 +204,2 @@ };

var attributeLength = void 0,
elementLength = void 0,
textureCount = 0;
var maxTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);

@@ -200,22 +218,78 @@

uniformList.forEach(function (uniform) {
uniforms[uniform.name] = uniformManager(uniform, program, gl);
var name = uniform.name;
if (name.endsWith('[0]')) {
name = name.replace('[0]', '');
}
uniforms[name] = uniformManager(uniform, program, gl);
});
gl.useProgram(program);
return {
program: program, uniforms: uniforms, attributes: attributes,
useProgram: function useProgram() {
gl.useProgram(program);
program: program,
uniforms: uniforms,
attributes: attributes,
drawArrays: function drawArrays(count) {
gl.drawArrays(gl.TRIANGLES, 0, count);
},
drawArrays: function drawArrays() {
gl.drawArrays(gl.TRIANGLES, 0, attributeLength);
drawElements: function drawElements(count) {
gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_SHORT, 0);
},
drawElements: function drawElements() {
gl.drawElements(gl.TRIANGLES, elementLength, gl.UNSIGNED_SHORT, 0);
},
fillElements: function fillElements(data) {
elementLength = data.length;
createElementsBuffer: function createElementsBuffer(value) {
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(data), gl.STATIC_DRAW);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(value), gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
return buffer;
},
fillElements: function fillElements(buffer) {
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
return buffer;
},
createFramebuffer: function createFramebuffer(width, height) {
var useColorBuffer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
var colorTarget = void 0,
depthTarget = void 0;
if (useColorBuffer) {
var _renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, _renderbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, _renderbuffer);
colorTarget = _renderbuffer;
} else {
var tex = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
colorTarget = tex;
}
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);
depthTarget = renderbuffer;
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
throw new Erroe("this combination of attachments does not work");
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return {
framebuffer: framebuffer,
colorTarget: colorTarget, depthTarget: depthTarget
};
}

@@ -222,0 +296,0 @@ };

{
"name": "shader-program-compiler",
"version": "0.0.1",
"version": "0.0.3",
"description": "",
"main": "lib/index.js",
"scripts": {
"prepublish": "babel src -d lib",
"build": "gulp build",
"dev": "gulp dev"
"prepublishOnly": "gulp compile"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"eslint": "^4.7.2",
"eslint-loader": "^1.9.0",
"express": "^4.15.5",
"gl-matrix": "^2.4.0",
"gulp": "^3.9.1",
"gulp-util": "^3.0.8",
"json-loader": "^0.5.7",
"raw-loader": "^0.5.1",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.6.0",
"webpack-dev-middleware": "^1.12.0",
"webpack-dev-server": "^2.8.2",
"webpack-stream": "^4.0.0"
"dalaran": "^0.1.5"
},

@@ -35,2 +18,2 @@ "keywords": [],

"license": "ISC"
}
}