99 releases

0.45.0 Mar 21, 2024
0.44.0 Dec 3, 2023
0.43.0 Jun 2, 2023
0.39.0 Mar 26, 2023
0.0.11 Oct 28, 2019

#95 in WebAssembly

Download history 168/week @ 2024-08-04 395/week @ 2024-08-11 207/week @ 2024-08-18 174/week @ 2024-08-25 6/week @ 2024-09-01 17/week @ 2024-09-08 113/week @ 2024-09-15 84/week @ 2024-09-22 224/week @ 2024-09-29 186/week @ 2024-10-06 174/week @ 2024-10-13 53/week @ 2024-10-20 133/week @ 2024-10-27 47/week @ 2024-11-03 2/week @ 2024-11-10 125/week @ 2024-11-17

309 downloads per month
Used in dominator_helpers

MIT/Apache

375KB
8K SLoC

Build Status LICENSE LICENSE Crates.io Documentation Demo

DEMO

About

awsm_web is primarily used as a building block for other crates in the awsm ecosystem.

Description

The approach with this library is similar in spirit to gloo - that is to say, it bridges the gap between the auto-generated WebIDL-powered bindings web-sys provides, and the type of code we'd typically consider a real starting point in web apps.

Features

Features are heavily gated keep dependencies minimal. The default is for no features to be enabled, but the all feature will turn them all on (except those that are only meant for debugging like debug_log)

WebGL

Cache

The goal is to keep it very low level and low-cost abstraction that is almost universal. However, almost universal is not without opinions. For example, the webgl wrapper provides a lazy caching mechanism for all string lookups (including ubo offsets and texture samplers) and stores local state to avoid making unnecessary gl calls.

In terms of whether to use strings or precalculated integers:

  1. uniforms: you can't know those in advance, you have to get them via a web api call that takes a string
  2. uniform buffer objects: you can sorta set and calculate it in advance, but it's very error prone and fragile
  3. sampler index: can be set in advance but requires syncing with the uniform value
  4. attributes: can be set in advance, either through shader code or web api

Therefore, for everything other than attributes, it's best to use strings everywhere - after the first call, it's merely a local cache lookup.

Note also that there is a global registry for specifying ubo and attribute locations in advance of any shader code

Api

It happens in a couple levels

The first is very thin wrappers over the native web_sys types, added as extension traits on the contexts (both webgl1 and 2). These can be used directly on the contexts and are prefixed awsm_*. At this level, no additional state is maintained.

Then, the WebGlRenderer wrappers (also for 1 and 2) contain all the state and caching stuff mentiond above. For ease of use, many of the functions that could be called on the context directly are re-exported on the renderer without the awsm_ prefix.

Dependencies

~7–10MB
~188K SLoC