# @andrewray/glsl-preprocessor

> Preprocess GLSL source code

Latest version **1.0.1** (published 2019-01-06) · GPLv2 license · 0 weekly downloads

## Install

```sh
npm install @andrewray/glsl-preprocessor
pnpm add @andrewray/glsl-preprocessor
yarn add @andrewray/glsl-preprocessor
bun add @andrewray/glsl-preprocessor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-01-06 |
| First published | 2019-01-06 |
| Weekly downloads | 0 |
| License | GPLv2 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 35.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Andrew Ray |
| Maintainers | andrewray |
| Keywords | preprocessor, compile, compiler, glsl |

## Links

- npm: https://www.npmjs.com/package/@andrewray/glsl-preprocessor
- Repository: https://github.com/AndrewRayCode/glsl-preprocessor
- Homepage: https://github.com/AndrewRayCode/glsl-preprocessor#readme
- Issues: https://github.com/AndrewRayCode/glsl-preprocessor/issues
- npm.io page: https://npm.io/package/@andrewray/glsl-preprocessor

## Dependencies (1)

- [glsl-tokenizer](https://npm.io/package/glsl-tokenizer.md) ^2.1.5

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-01-06
- 1.0.0 — 2019-01-06

## README

A GLSL preprocessor based on the [C-Preprocessor](https://github.com/ParksProjets/C-Preprocessor) library.

# Usage

```js
import Preprocessor from '@andrewray/glsl-preprocessor';

const result = new Preprocessor(options).preprocess(src);
```

# Options

This are the defaults options. You can modify them by passing an option object.

```js
var options = {
  // Predefined constants (ex: { "MY_CONST": "42" })
  constants: {},

  // Predefined macros (ex: { "MACRO": "(a,b) a+b" })
  macros: {},

  // End of line character
  newLine: '\n',

  // Escape '//#' & '/*#' comments (see extra/comments)
  commentEscape: true,

  // Empty lines to add between code and included files
  includeSpaces: 0,

  // Limit of empty following lines (0 = no limit)
  emptyLinesLimit: 0,

  // Base path for including files
  basePath: './'
};
```

# Features

##### Define

```glsl
// Define a constant
#define MY_CONST 42

// Define a macro
#define SUM(a,b) a + b
```

Create a constant or a macro.

##### Undefine

```glsl
#undef MY_CONST
```

Delete a constant or a macro.

##### Condition

```glsl
#if A + B == 5 && defined(MY_CONST)
  // Do stuff
#elif "MY_CONST2" == "House"
  // Do other stuff
#else
  // Do other stuff
#endif

#ifndef MY_CONST3
  // Do stuff
#endif
```

C like conditions.  
`#if` condition is evaluated in JS so you must add **"** between string
constants.  
Note: `#ifdef C` and `#ifndef C` are faster than `#if defined(C)` and `#if !defined(C)`.

##### Error

```glsl
#error This is an error
```

Stop the compiler and raise the error.

### Extra

##### Compiler constants

```glsl
__LINE__ // Current line (where this constant is used).
__FILE__ // Current file (where this constant is used).
```

This constants are predefined by the compiler.

##### Comments

```glsl
//# One line comment

/*#

Multi-lines comment

#*/
```

This comments will be deleted in the compiled file.  
Note: `options.commentEscape` must be `true`.

---
_Source: https://npm.io/package/@andrewray/glsl-preprocessor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
