Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
prettier-plugin-glsl
Advanced tools
Prettier (https://prettier.io) plugin for GLSL (OpenGL Shading Language).
This is a plugin for Prettier (version 3.x), the opinionated code formatter, for GLSL, the shading language used in WebGL and other places. It uses a custom parser based on Chevrotain and does not require any external dependencies.
NB: this is still in active development, breaking/formatting changes may be included in any version.
This plugin tries to match the formatting rules for JavaScript as closely as possible. Issues or PRs which make the formatting closer to JavaScript are welcome.
This plugin will attempt to parse #define
macros as top-level declarations,
statements or expressions. If successful, these will be formatted as usual.
For example,
#define MAX3(genType) genType max3(genType a, genType b, genType c) { /* comment */ return max(max(a, b), c); }
will be formatted as:
#define MAX3(genType) \
genType max3(genType a, genType b, genType c) { \
/* comment */ \
return max(max(a, b), c); \
}
Comments which start with /**
will be passed to the markdown formatter.
For an example, see ./builtins.glsl.
npm install --save-dev prettier-plugin-glsl
Prettier will automatically pick up the plugin. The following extensions will be recognized as GLSL files by default.
.fp
.frag
.frg
.fs
.fsh
.fshader
.geo
.geom
.glsl
.glslf
.glslv
.gs
.gshader
.rchit
.rmiss
.shader
.tesc
.tese
.vert
.vrx
.vsh
.vshader
Note that .frag
files are recognized as JavaScript files by default. Add the
following to your Prettier configuration to format them as GLSL.
"overrides": [{"files": ["*.frag"], "options": {"parser": "glsl-parser"}}]
As GLSL includes a C++-style preprocessor, this presents some difficulties when formatting. For example, the plugin does not attempt to be able to format crazy (but technically valid) constructs such as:
#define LBRACE {
void main() LBRACE
}
Instead, the plugin effectively treats preprocessor directives such as #define
as their own statements. This covers most cases, for example, the following
works fine:
#define AA 2
#define ZERO (min(iFrame, 0))
void main() {
// ...
#if AA > 1
for (int m = ZERO; m < AA; m++)
for (int n = ZERO; n < AA; n++) {
// pixel coordinates
vec2 o = vec2(float(m), float(n)) / float(AA) - 0.5;
vec2 p = (2.0 * (fragCoord + o) - iResolution.xy) / iResolution.y;
#else
vec2 p = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
#endif
// use p
#if AA > 1
}
tot /= float(AA * AA);
#endif
}
However, the following does not, as the #else
and #endif
are treated as the
bodies of the if-statement, which leads to the else
following a {}
block
instead of an if block, which is invalid.
#if FOO
if (a())
#else
if (b())
#endif
{ }
else
{ }
In general this approach works well. Of the top 100 Shadertoy shaders, 145/152 compilation units (95%) can be formatted without any changes.
#if/#endif
.)#if/#else/#endif
and if/else
which leads to issues as above.FAQs
Prettier (https://prettier.io) plugin for GLSL (OpenGL Shading Language).
The npm package prettier-plugin-glsl receives a total of 2,274 weekly downloads. As such, prettier-plugin-glsl popularity was classified as popular.
We found that prettier-plugin-glsl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.