---
title: "emitGlslStages(): function in Emit, TypeShade API reference"
description: "emitGlslStages, a function in Emit. Emit both stages of one module, lowering and optimizing it once."
url: https://typeshade.dev/api/emitglslstages/
language: en
---

# `emitGlslStages()`

Function in Emit

Emit both stages of one module, lowering and optimizing it once.

`import { emitGlslStages } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function emitGlslStages(
  m: ModuleDecl,
  opts?: GlslEmitOptions & { vertexEntry?: string; fragmentEntry?: string },
): { vertex: string; fragment: string }
```

## Parameters

**`m` `ModuleDecl`**

the module to emit.

**`opts` optional `GlslEmitOptions & { vertexEntry?: string; fragmentEntry?: string }`**

the [`GlslEmitOptions`](https://typeshade.dev/api/glslemitoptions/), plus `vertexEntry` and `fragmentEntry`.

## Return value

`{ vertex: string; fragment: string }`

the vertex and fragment sources, each `#version 300 es` first.

## Exceptions

**`Error`**

the same errors as [`emitGlslModule`](https://typeshade.dev/api/emitglslmodule/).

**`UnsupportedFeatureError`**

GLSL allows one main() per stage, so a module with two fragment entries needs fragmentEntry to say which one becomes main(); the other entries are left out of that stage’s source, and with none named such a stage throws UnsupportedFeatureError (SD0030).

**[`SD0030`](https://typeshade.dev/reference/errors/sd0030/)**

GLSL allows one main() per stage, so a module with two fragment entries needs fragmentEntry to say which one becomes main(); the other entries are left out of that stage’s source, and with none named such a stage throws UnsupportedFeatureError (SD0030).

## Description

The result is the same stage sources as separate `emitGlslModule` calls, while the optimizer runs once. The pair also checks that one texture uses one sampler across the selected stages: a linked GLSL program shares each combined texture uniform. Use it from a host that creates a pipeline, which always needs both.

`opts.vertexEntry` and `opts.fragmentEntry` name the entry to emit for each stage, for a module that declares several entries of one stage. GLSL allows one `main()` per stage, so a module with two fragment entries needs `fragmentEntry` to say which one becomes `main()`; the other entries are left out of that stage’s source, and with none named such a stage throws [`UnsupportedFeatureError`](https://typeshade.dev/api/unsupportedfeatureerror/) ([`SD0030`](https://typeshade.dev/reference/errors/sd0030/)). The output does not depend on which other entries the module carries, because every optimizer pass works on one function at a time.

## Examples

### Example

```ts
import { emitGlslStages } from 'typeshade'

const { vertex, fragment } = emitGlslStages(MODULE, { fragmentEntry: 'fs_pattern' })
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Does not apply | |
| GLSL ES 3.00 (WebGL2) | Supported | Writes GLSL ES 3.00 for WebGL2. |
| CPU oracle | Does not apply | |

## In the guide

- [Language guide](https://typeshade.dev/guide/internals/)
- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [GLSL float precision](https://typeshade.dev/guide/internals/glsl-float-precision/)

## See also

- [`UnsupportedFeatureError`](https://typeshade.dev/api/unsupportedfeatureerror/)
- [`GlslEmitOptions`](https://typeshade.dev/api/glslemitoptions/)
- [`emitGlslModule`](https://typeshade.dev/api/emitglslmodule/)

## Source

[`src/core/backends/glsl.ts`, line 210](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/glsl.ts#L210), at commit af54ddad5
