---
title: "emitGlslFragment(): function in Emit, TypeShade API"
description: "emitGlslFragment, a function in Emit. Emit a module as a GLSL ES 3.00 fragment for a host that owns the program: the declarations and helper functions…"
url: https://typeshade.dev/api/emitglslfragment/
language: en
---

# `emitGlslFragment()`

Function in Emit

Emit a module as a GLSL ES 3.00 fragment for a host that owns the program: the declarations and helper functions, without #version, without the precision lines and, by default, without the stage entry point.

`import { emitGlslFragment } from 'typeshade'`

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

## Syntax

```ts
function emitGlslFragment(
  m: ModuleDecl,
  stage?: 'vertex' | 'fragment',
  opts?: GlslEmitOptions & { entryPoints?: boolean },
): EmitFragment
```

## Parameters

**`m` `ModuleDecl`**

the module to emit.

**`stage` optional `'vertex' | 'fragment'`**

which stage’s scope to emit; omit for the whole module.

**`opts` optional `GlslEmitOptions & { entryPoints?: boolean }`**

the [`GlslEmitOptions`](https://typeshade.dev/api/glslemitoptions/), plus `entryPoints` to keep the entries.

## Return value

`EmitFragment`

the fragment: its `source`, `preamble`, `declares` and `requires`.

## Exceptions

**`Error`**

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

## Description

The host splices the returned `source` into a program it assembles itself.

What the header would have carried comes back as data in [`EmitFragment.preamble`](https://typeshade.dev/api/emitfragment-interface/): the `#version` line, any `#extension … : require` a declared capability needs, and the precision lines, including the ones for the integer and array sampler types derived from the module’s texture bindings. A host merges and de-duplicates those across the fragments it assembles.

Entry points are omitted unless `opts.entryPoints` is `true`. They are listed in `declares.entryPoints` either way, and they still decide the stage scope, so the fragment carries exactly the helpers, structs and bindings the stage’s entry reaches.

## Examples

### Example

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

const frag = emitGlslFragment(MODULE, 'fragment')
// frag.preamble: ['#version 300 es', 'precision highp float;', 'precision highp int;']
// frag.source: the declarations and helpers, ready to splice into a host program
```

## 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

- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`EmitFragment`](https://typeshade.dev/api/emitfragment-interface/)
- [`GlslEmitOptions`](https://typeshade.dev/api/glslemitoptions/)
- [`emitGlslModule`](https://typeshade.dev/api/emitglslmodule/)

## Source

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