Textures are 2D images that can be applied to the materials that make up a mesh or a mesh instance. For example, the mesh for a door might use a texture image to make it look like wood grain, or the mesh for a wall might use a stone texture.
You can create a texture from the contents of an image file on disk, or programmatically by providing the Beast API with the RGBA values for each pixel in the texture.
In order to apply a texture that you create to a mesh instance in a scene, you need to link the texture to a specific input parameter of the shader set up for the material used by that mesh instance. See Creating Physical Materials.
Beast can read RGB(A) texture data from any of the following file types:
To create a texture from a file:
The source file is copied to the Beast cache and used from there. Once the source is copied to the cache, it is no longer used.
Note that you do not call ILBBeginTexture() or ILBEndTexture() when you create the texture from a file on disk.
ILBTextureHandle tex; ILBReferenceTexture(beastManager, _T("MyTextureName"), _T("C:\textures\floor.png"), &tex);
When you create a texture programmatically, you provide the color data for each pixel in the texture one-by-one. You start with the pixel at the bottom left corner, and progress upward line by line. In other words, you first provide the bottom horizontal line in the image from left to right; then the next line up starting from the left again; etc.
For each pixel, you can provide a monochrome value, a three-channel RGB color, or a four-channel RGBA color.
You can provide the color of each pixel in either HDR or LDR format.
To create a texture programmatically:
For each pixel, you must add a number of data elements of a type that corresponds to the pixel format you set in your call to ILBBeginTexture(). For example, if you want to set an RGBA colors for each pixel in HDR format (ILB_PF_RGBA_FLOAT), you need to provide four floating-point numbers for each pixel.
ILBTextureHandle tex; ILBBeginTexture(beastManager, "texture1", width, height, ILB_PF_RGBA_BYTE, &tex) ILBAddPixelDataLDR(tex, pixelDataArray, arrayLength); ILBEndTexture(tex)
If you need to re-interpret the line order or color values from a source data structure, you can avoid creating a full temporary copy of the texture by adding pixel data in batches using an approach such as this:
ILBTextureHandle tex; ILBBeginTexture(bm, "texture2", width, height, ILB_PF_RGBA_BYTE, &tex) // Add data line by line for(int y = 0; y < height; ++y) { // Prepare a scanline of data by looking it up in source data structure char* lineData = prepareLine(y); // Add a scanline of data ILBAddPixelDataLDR(tex, lineData, width); } ILBEndTexture(tex)
You can create multiple different textures simultaneously in multiple threads. In addition, multiple threads can find textures in the cache and use them simultaneously. However, only one thread should add pixel data to any given texture at any time; therefore, each texture should be created entirely within a single thread and not split across multiple threads.
API functions related to the creation and setup of textures are declared in the beasttexture.h file.