> ## Documentation Index
> Fetch the complete documentation index at: https://glassen.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Share a surface across glass lenses

> Use one WebGL context and display clock for multiple independent lenses, place stationary content beneath them and control overlapping paint order.

A shared surface separates the glass from its content. Add stationary content once, then move independently sized lenses over the completed scene.

```js theme={null}
import { createGlassSurface } from 'glassen'

const surface = await createGlassSurface(canvas, { onError: console.error })
const content = surface.addContent(contentElement, { source })
let x = 0, y = 0
const lens = surface.add(lensElement, {
  appearance: 'light',
  onMove(delta, element) {
    x += delta.x
    y += delta.y
    element.style.transform = `translate(${x}px, ${y}px)`
  },
})

// Releases lenses, subscriptions, targets and the animation clock:
// surface.destroy()
```

Put the canvas inside a positioned `.goop-orb-surface` element. Size the surface explicitly. Place the content and lens elements inside it, with the `.goop-orb-scene-content` and `.goop-orb` classes respectively. Lens elements need a measurable box; interactive vanilla lenses need `tabindex="0"`, `role="group"` and an accessible label.

Ordinary drag stretches. Command-drag, or Command plus arrow keys, requests movement through `onMove`. The callback receives damped incremental CSS-pixel displacement, not an absolute position. The host applies it to the element. Without `onMove`, Command-drag retains stretch behavior. The built-in move modifier uses the Meta key; touch and hosts where the operating system reserves Meta need a host-provided positioning control.

## Overlap

`zIndex` sets back-to-front lens order; equal values keep mounting order. Match DOM input stacking with that order. Scene-backed lenses refract completed layers beneath them. A lens with its own explicit `source` continues sampling that source.

Independent lenses batch when texture bindings permit. Overlapping paint bounds require GPU backdrop copies; a hundred overlapping lenses cost more than a hundred separated lenses. This is one shared context with instanced draws, not a promise of one draw for every scene.

## Removal and reuse

`add` and `addContent` return `{ update(options), destroy() }`. Destroying a mount releases its own resources and source lease. It does not remove the host element or destroy caller-owned sources or shapes. Remove all consumers before destroying a shared shape or source.

Read `surface.stats` without copying it into React state each frame. See [performance](https://glassen.mintlify.site/performance.md) for interpreting its counters.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.