Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
glsl-token-descope
Advanced tools
"Descope" an array of GLSL tokens such that they can be safely inlined alongside within another shader without causing any global variable conflicts.
"Descope" an array of GLSL tokens such that they can be safely inlined alongside within another shader without causing any global variable conflicts.
Useful for modularising GLSL source files, e.g. as is done in glslify, but should be useful in other tools too.
Written with WebGL's GLSL syntax in mind – all the same, pull requests to support other variants would be much appreciated :)
descope(tokens, [rename(name)])
Takes an array of GLSL tokens
produced by
glsl-tokenizer and renames variables
to avoid global conflicts by modifying their "data" property in-place.
For example:
var tokenize = require('glsl-tokenizer/string')
var descope = require('glsl-token-descope')
var stringify = require('glsl-token-string')
var src = `
precision mediump float;
uniform mat4 top1;
uniform float top2;
void main() {
float x = 1.0;
gl_FragColor = vec4(vec3(x), top2);
}
`.trim()
var tokens = tokenize(src)
console.log(stringify(descope(tokens)))
Which should rename main
, top1
and top2
to result in this output:
precision mediump float;
uniform mat4 top1_0;
uniform float top2_1;
void main_2() {
float x = 1.0;
gl_FragColor = vec4(vec3(x), top2_1);
}
Optionally, you may pass in a custom rename
function as descope
's second
argument to choose how you rename your variables. For example, adding a custom
rename
function to the previous function:
descope(tokens, function(name) {
return 'a_' + name
})
Would result in the following shader:
precision mediump float;
uniform mat4 a_top1;
uniform float a_top2;
void a_main() {
float x = 1.0;
gl_FragColor = vec4(vec3(x), a_top2);
}
MIT. See LICENSE.md for details.
FAQs
"Descope" an array of GLSL tokens such that they can be safely inlined alongside within another shader without causing any global variable conflicts.
We found that glsl-token-descope demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.