{"_id":"@ahmerhh/webgraphiclibrary-program","name":"@ahmerhh/webgraphiclibrary-program","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@ahmerhh/webgraphiclibrary-program","version":"1.0.1","description":"WebGraphicLibrary program wrapper.","main":"dist/index.js","scripts":{"test":"browserify test/index.js -t babelify | browser-run | tap-spec","build":"browserify src/index.js -t babelify -s @ahmerhh/WebGraphicLibrary-program > dist/index.js","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/ahmerhh/WebGraphicLibrary-program.git"},"keywords":["WebGraphicLibrary","WebGL","program"],"author":{"name":"ahmerhh","email":"ahmerhh@protonmail.com"},"license":"MIT","bugs":{"url":"https://github.com/ahmerhh/WebGraphicLibrary-program/issues"},"homepage":"https://github.com/ahmerhh/WebGraphicLibrary-program#readme","dependencies":{"@ahmerhh/WebGraphicLibrary-context":"^1.0.2","@ahmerhh/WebGraphicLibrary-shader":"^1.0.1"},"devDependencies":{"babel-preset-es2015":"^6.3.13","babelify":"^7.2.0","browser-run":"^3.0.8","browserify":"^13.0.0","tap-spec":"^4.1.1","tape":"^4.4.0"},"_id":"@ahmerhh/webgraphiclibrary-program@1.0.1","gitHead":"57d88c72e3983dd0173ebff3928e4236c93eec63","_nodeVersion":"18.15.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-cqQYczp08M+g36gTuBOKRfggqn9VE/vJqY95kiinRn73FCQK+mhznUoHFT56dxKVnizgyqREd8xWRev+Jd8sGw==","shasum":"c72f9fd48b1926ba7500c18cf17c0fab6872ab2a","tarball":"https://registry.npmjs.org/@ahmerhh/webgraphiclibrary-program/-/webgraphiclibrary-program-1.0.1.tgz","fileCount":6,"unpackedSize":10568,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCLgacee5fTG76SUCSndLLy+C1sEPYxmZD+hGjhxHl1LwIgIFYg+8ncnpOqP5GMaJg3cSh65aYI4jXhMXklftAAXIM="}]},"_npmUser":{"name":"ahmerhh","email":"ahmerhabibb@gmail.com"},"directories":{},"maintainers":[{"name":"ahmerhh","email":"ahmerhabibb@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webgraphiclibrary-program_1.0.1_1691926107555_0.615512580934084"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-13T11:28:27.457Z","1.0.1":"2023-08-13T11:28:27.742Z","modified":"2023-08-13T11:28:27.989Z"},"maintainers":[{"name":"ahmerhh","email":"ahmerhabibb@gmail.com"}],"description":"WebGraphicLibrary program wrapper.","homepage":"https://github.com/ahmerhh/WebGraphicLibrary-program#readme","keywords":["WebGraphicLibrary","WebGL","program"],"repository":{"type":"git","url":"git+https://github.com/ahmerhh/WebGraphicLibrary-program.git"},"author":{"name":"ahmerhh","email":"ahmerhh@protonmail.com"},"bugs":{"url":"https://github.com/ahmerhh/WebGraphicLibrary-program/issues"},"license":"MIT","readme":"# GL Program\r\n\r\nWebGL program wrapper.\r\n\r\n## Installation\r\n\r\n```sh\r\n$ npm install --save @ahmerhh/webgraphiclibrary-program\r\n```\r\n\r\n## Usage\r\n\r\n```js\r\nimport Program from '@ahmerhh/WebGraphicLibrary-program';\r\n\r\n// Setup canvas, WebGL context, and buffers\r\n\r\n// Create a new program instance\r\nconst program = new Program(gl,\r\n  `\r\n  attribute vec3 aPosition;\r\n\r\n  void main() {\r\n    gl_Position = vec4(aPosition, 1.0);\r\n  }\r\n  `,\r\n  `\r\n  uniform vec3 uColor;\r\n\r\n  void main() {\r\n    gl_FragColor = vec4(uColor, 1.0);\r\n  }\r\n  `\r\n);\r\n\r\n// Add attributes to the program\r\nprogram.addAttribute('aPosition', 3, gl.FLOAT);\r\n\r\n// Add uniform to the program\r\nprogram.addUniform('uColor', gl.FLOAT_VEC3);\r\n\r\n// Bind the attribute pointer to the current active buffer\r\nvertsBuffer.bind();\r\nprogram.setAttributePointer('aPosition');\r\n\r\n// Set uniform value\r\nprogram.setUniform('uColor', [1, 0, 0]);\r\n```\r\n\r\n## API\r\n\r\n#### `program = new Program(gl, vertex, fragment)`\r\n\r\nCreate a new program, where:\r\n- `gl` is the [WebGL context](https://github.com/ahmerhh/WebGraphicLibrary-context).\r\n- `vertex` is the vertex shader. It can either be a [`Shader`](https://github.com/ahmerhh/WebGraphicLibrary-shader) instance or a `string`.\r\n- `fragment` is the fragment shader. It can either be a [`Shader`](https://github.com/ahmerhh/WebGraphicLibrary-shader) instance or a `string`.\r\n\r\n#### `program.addAttribute(name, size, type)`\r\n\r\nAdd a new attribute to the program. Size is usually `2` (vec2) or `3` (vec3), and type `gl.FLOAT`.\r\n\r\n#### `program.setAttributePointer(name)`\r\n\r\nSet the attribut pointer to the current active buffer.\r\n\r\n#### `program.addUniform(name, type)`\r\n\r\nAdd a new uniform where the type can be:\r\n- `gl.INT`\r\n- `gl.INT_VEC2`\r\n- `gl.INT_VEC3`\r\n- `gl.INT_VEC4`\r\n- `gl.FLOAT`\r\n- `gl.FLOAT_VEC2`\r\n- `gl.FLOAT_VEC3`\r\n- `gl.FLOAT_VEC4`\r\n- `gl.FLOAT_MAT2`\r\n- `gl.FLOAT_MAT3`\r\n- `gl.FLOAT_MAT4`\r\n\r\n#### `program.setUniform(name, value)`\r\n\r\nSet uniform value.\r\n\r\n#### `program.bind()`\r\n\r\nMake this program the active one. Calls `gl.useProgram()`.\r\n\r\n#### `program.dispose()`\r\n\r\nDelete instance. Calls `gl.deleteProgram()`.\r\n\r\n## License\r\n\r\nMIT, see [LICENSE.md](https://github.com/ahmerhh/gl-program/blob/master/LICENSE.md) for more details.\r\n\r\n## Credits\r\n\r\nThanks to the amazing [stackgl](http://stack.gl/) for the inspiration.","readmeFilename":"README.md"}