What is the correct file extension for GLSL shaders? [closed]
There's no official extension in the spec. OpenGL doesn't handle loading shaders from files; you just pass in the shader code as a string, so there's no specific file format.
However, glslang, Khronos' reference GLSL compiler/validator, uses the following extensions to determine what type of shader that the file is for:
.vert
- a vertex shader.tesc
- a tessellation control shader.tese
- a tessellation evaluation shader.geom
- a geometry shader.frag
- a fragment shader.comp
- a compute shader
The glslang compiler created by Khronos makes assumptions about the shader stage based on the extension, but there is no standard extension outside of this (and quite a few projects make up their own). The glslang compiler keys off of .vert
, .tesc
(TESsellation Control shaders), .tese
(TESsellation Evaluation shaders), .geom
, .frag
, and .comp
.
But that's about it for any form of standard extension.
Identifying file type by extension is a thing specific to Windows. All other operating systems use different approaches: MacOS X stores the file type in a special metadata structure in the file system entries. Most *nixes identify files by testing their internal structure against a database of known "magic bytes"; however text editors use the extension.
Anyway, GLSL sources are just like any other program source file: plain text, and that's their file type.
The extension you may choose as you wish. I use the following naming:
- ts.glsl
- gs.glsl
- vs.glsl
- fs.glsl
but that's my choice and technically my programs don't even enforce any naming or extension scheme. The naming is for humans to read and know what's in it; having a common major extension requires me to have an syntax highlighing rule for only one file extension set.