# `Dala.Media.Texture`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/media/texture.ex#L1)

GPU texture pool to avoid constant allocation/deallocation.

Pre-allocates a pool of GPU textures and recycles them. Critical for
avoiding stutter and memory fragmentation during video playback.

## Example

    {:ok, pool} = Dala.Media.Texture.new_pool(1920, 1088, count: 8)

    # Acquire a texture (blocks if none available)
    texture_id = Dala.Media.Texture.acquire(pool)

    # Use the texture...
    Dala.Gpu.blit(surface, texture_id, 0, 0)

    # Release back to pool
    Dala.Media.Texture.release(pool, texture_id)

# `pool_ref`

```elixir
@type pool_ref() :: pid()
```

# `texture_id`

```elixir
@type texture_id() :: non_neg_integer()
```

# `acquire`

```elixir
@spec acquire(pool_ref(), timeout()) :: texture_id() | nil
```

Acquire a texture from the pool. Returns texture_id.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `destroy_pool`

```elixir
@spec destroy_pool(pool_ref()) :: :ok
```

Destroy the pool and release all textures.

# `new_pool`

```elixir
@spec new_pool(non_neg_integer(), non_neg_integer(), keyword()) ::
  {:ok, pool_ref()} | {:error, term()}
```

Create a texture pool with the given dimensions.

# `release`

```elixir
@spec release(pool_ref(), texture_id()) :: :ok
```

Release a texture back to the pool.

# `stats`

```elixir
@spec stats(pool_ref()) :: %{
  available: non_neg_integer(),
  in_use: non_neg_integer(),
  total: non_neg_integer()
}
```

Get pool statistics.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
