Main | API | Textures (TBO)

Textures

Textures are stored as 32-bit unsigned integer typed arrays in WebRender, which are stored in texture buffers, which record all the image data as well as some extra information used when rendering. A texture buffer can be created with getTBOId, which will allocate a position in the buffer array and return you the reference id. This id is then used by other functions to modify and read that texture.

The reason we store textures as 32-bit colour integers, is so that when sampling the texture in the pixel/fragment shader, we only need to lookup and return a single value. This can be a little tricky to work with in the pixel shader, therefore Tutorial 3 covers how the colour channels can be separated, along with everything else you need to do to load and use textures.

Although WebRender stores textures as 32-bit nubmers, when loading a texture it must be in 8-bit colour channels. The reason for this is that reading a texture that has been loaded into a HTMl5 canvas, you will end up with an image with in the format of 8-bit colour channels. Rather than having the application convert the image, WebRender does it instead to guarantee that it ends up in the right colour format (RGBA).

In order to use a texture it must be bound to the rendering using bindtbo. This links a texture with one of the eight texture references that can be accessed by the pixel/fragment shader. Then when sampling, the texture reference that the buffer was bound to will link to your buffer.

Summary

Related Functions

getTBOId

loadTBO

bindTBO

clearTBO

getTexturePixelColour