HTML and CSS Reference
In-Depth Information
WebGL to use as texture data. The Turbulenz Engine includes a JavaScript implementation of such a DDS loader to
provide this functionality. In most cases, the binary data is just being passed to WebGL so there is little processing cost
in JavaScript, which makes this a quick way to load texture data.
For some textures in your game, you may want to include mipmaps. This common practice adds processing costs
for image formats that don't include mipmap data, such as PNG and JPEG. If the game requires mipmapped textures
created from these formats, they will be generated on the fly, adding to the total load time. The advantage of loading a
file format that supports mipmaps such as DDS is that they can be generated offline with more control over the level
of quality. This does add to the total size of the file (around 33%, as each mipmap is a quarter the size of the previous
level); however, these files tend to compress well with gzip, which can be enabled as a server compression option
(discussed later).
The decision for the exact format to use for texture data is often subjective when it comes to quality. The
more compression, the smaller the file size and faster load times, but the more visual artifacts that can be seen.
Think carefully about options for pixel formats, the use of an alpha channel, the pixel depth, and the compression
depending on the image content. The choice of which S3 compressed algorithm (DXT1, DXT3, DXT5) is like choosing
between PNGs for images with alpha and JPEGs for images where artifacting is less obvious: it depends on what they
support best. Quick loading is the goal, while still attempting to maintain an acceptable level of quality.
Audio Formats
Similar to texture formats; balancing data size and quality of audio files will affect the overall load time. Games are
among the power-users of audio on the Web when it comes to effects, music, experience, and interactivity. The many
variations of sound effects and music tracks can easily add up and eclipse the total size of the other types of data
combined (even mesh data). This of course depends on the game, and you should keep track of how much audio data
you are transferring during development. It is therefore important to consider different options for loading sounds
that best fit your game.
If you are using sound within your game, you should be familiar with HTML5 Audio and the Web Audio API
as the options available for browser audio support. The history of support for both the APIs and audio codecs has
been hampered due to the complex issue of patents surrounding some audio formats, which has resulted in an
uneven landscape of support across different browser vendors. The upshot is that audio support in games is not just
a matter selecting the optimal format for your sound data, but also choosing based on availability and licensing.
Familiar formats such as MP3 and AAC are supported by the latest versions of the majority of browsers, but cannot
be guaranteed due to some browser manufacturers intentionally avoiding licensing issues. Formats such as OGG
and WAV are also supported, but again not by all browser manufacturers. At the time of writing, the reality is that
documenting the current support of audio formats would quickly be out of date and wouldn't help address the
practicalities of efficiently loading audio for games. The best advice is to look at the following references to help
understand the current support for desktop and mobile browsers and to apply the suggestions in this section to your
choice of formats: ( and
docs/HTML/Supported_media_formats ) .
Transferring audio data is similar to other types of binary data. It can either be loaded directly by the browser
by specifying it in an <AUDIO> tag or via an XHR request. The latter gives the game control of when the sound file is
loaded and the option of what to do with it when it is received. The availability of the Web Audio API in browsers
means that most games should have a fallback to HTML5 Audio. As with texture formats, testing for support, then
deciding which format to use, is preferable to loading all data upfront. This does mean that you will probably be
required to have multiple encodings of the same audio data hosted on your server. This is the price of compatibility,
unlike textures where the choice is based mainly on performance. See Listing 2-5.
Search WWH ::

Custom Search