Base object for representing texture data.
#include <AlTexture.h> class AlTexture : public AlObject, virtual ~AlTexture(); virtual statusCode deleteObject(); virtual AlObject *copyWrapper() const; virtual AlObjectType type() const; virtual const char* name() const; virtual statusCode setName(const char *); AlTexture* firstTexture() const; AlTexture* nextTexture( const AlTexture* ) const; statusCode nextTextureD( AlTexture* ); const char* textureType() const; const char* fieldType() const; statusCode parameter( const AlShadingFields, double& ) const; statusCode setParameter( const AlShadingFields, const double ); /* this section is only for file textures */ const char* filename() const; statusCode setFilename( const char* ); const char* firstPerObjectPixEntry(); const char* nextPerObjectPixEntry( const char *); const char* getPerObjectPixFilename( const char*) const; statusCode setPerObjectPixFilename( const char*, const char*); statusCode addPerObjectPixEntry( const char*, const char*); statusCode removePerObjectPixEntry( const char* ); boolean isParametric( void ) const; statusCode eval( double, double, double, double, double, double, double, double, double, double, double*, double*, double*, double*, boolean = TRUE, double = 1.0, double = 0.0, char *objectname = NULL ) const; AlList* fields() const; AlList* mappedFields() const; statusCode addTexture( const char*, const char*, AlTexture** returnedTexture = NULL ); statusCode removeTexture( const char* ); AlTextureNode* textureNode() const; statusCode applyIteratorToTextures( AlIterator*, int& ); /* for environment textures only */ statusCode environmentPixMap( AlPixel *, int, boolean );
Encapsulates the basic functionality for checking and setting the name of a texture as well as accessing the textures that this texture refers to, and the animation on this texture. These texture objects can be obtained from the AlShader class and the AlEnvironment class.
A texture object itself may also reference other textures. For this reason the firstTexture() and nextTexture() methods are used.
firstTexture() returns the first texture that the texture object references. nextTexture() moves from a given referenced texture to the next texture in order, as related to the texture object. (See the similar methods for the AlShader/AlEnvironment classes.)
The animation on a texture can be accessed through the firstChannel() and nextChannel() methods. All the channels on the texture can be deleted by calling deleteAnimation().
The texture parameters can be accessed through the parameter() and setParameter() methods. Each texture has a specific set of parameters that are valid for it that depend on its type. The full list of texture parameters can be seen in the file AlShadingFields.h. For example, all parameters specific to the water texture have names of the form kFLD_SHADING_WATER_*. Parameters common to all textures have the form kFLD_SHADING_COMMON_TEXTURE_*. All parameters are treated as doubles even though this may not necessarily be what they are. This was done to make the interface as simple and consistent as possible.
New AlTextures cannot be created by allocating a new AlTexture object because an AlTexture must be associated with a shader. Use the AlShader::addTexture() method to create the new AlTexture.
statusCode AlTexture::setName( const char *newName )
Changes the name of the texture to a new name. If the given name is not a unique one or contains illegal characters, then a unique name is generated based on the given name and assigned to the texture. In this case, a status code of sNameChangedToUniqueOne is returned. It is illegal for the new name to be NULL. #, digits, upper case letters, lower case letters, and _ are valid characters
AlTexture* AlTexture::nextTexture( const AlTexture* last_texture ) const
const char* AlTexture::fieldType() const
Returns a string which indicates which field of the parent object (AlShader, AlTexture, AlEnvironment) that this texture is mapped to. Note that the returned strings are identical to the field names written out to SDL. The SDL manual gives a complete list of possible return values for this function.
const char* AlTexture::getPerObjectPixFilename( const char* objname ) const
If the texture is a file texture and the objname is in the "per object pix file" list of the texture, this method returns the image file used for the objname object (object meaning an Alias geometry). If the object is not in the list, then the image file used will be AlTexture::filename() which contains the texture that is applied to all objects that are not specifically mentioned in the "per object pix file" list. If the return value of getPerObjectPixFilename() is NULL, then the object is not textured.
statusCode AlTexture::setPerObjectPixFilename( const char* objname,const char* filename )
If the texture is a file texture and the objname exists in the per obj pix list, this method sets the name of the image file use for that object (object in the sense of an Alias geometry). Otherwise, sFailure is returned (not file texture or object doesn’t exist). The filename string is duplicated, so you are responsible for the space allocated for the original copy
statusCode AlTexture::addPerObjectPixEntry( const char* objname,const char* filename )
If the texture is a file texture, this method adds a per object pix entry to the texture. If the texture is any other type, sFailure is returned. If the objname object is not already in the per object pix entry list, it is added. If the objname object does exist in the list, its filename field is modified to contain the given filename.
statusCode AlTexture::removePerObjectPixEntry( const char* objname )
statusCode AlTexture::removeTexture( const char* fieldName )
Removes a texture to a particular field of the AlTexture. The first argument is the name of the field that will have the texture applied to it. Only those fields valid for this texture should be provided; any others will cause this method to fail. Valid fields are any returned by the fields() method.
statusCode AlTexture::addTexture( const char* fieldName, const char* textureName, AlTexture** returnCreatedTexture )
Adds a texture to a particular field of the AlTexture. The first argument is the name of the field which will have the texture applied to it. Only those fields valid for this texture should be provided, any others will cause this method to fail. Valid fields are any returned by the fields() method. The second argument is the name of the texture type to apply to the field. The complete list of names is available in the SDL manual.
statusCode AlTexture::eval( double u, double v, double x, double y, double z, double nx, double ny, double nz, double usize, double vsize, double *r, double *g, double *b, double *a, boolean initialize, double blurmult, double bluroffset, char *objectname ) const
Evaluates a texture at the passed location. The initialize flag specifies whether the texture transforms should be initialized. Note that this is a costly operation, so initialize only when necessary, generally on the first call.
This routine allows you to find out for a given location what color the texture would return if that location was shaded by the renderer. The location of the color is specified by either u, v coordinates in parametric space for a 2D texture, or x, y, z coordinates in world space for a 3D texture
As some textures also require the normal at that point to be provided the user supplies the normal in the nx, ny, and nz fields. The usize and vsize are used to express the extent of the point in parametric space. This has the effect of blurring the texture with larger usize,vsize.
The value is returned in *r, *g, *b, *a. This is a color value. The *r, *g, *b, *a values should be set before calling Eval to the color you wish returned if the texture is not to be applied (for instance if the texture alpha value is 0).
The blurmult and bluroffset fields specify the amount of blurring to apply to the texture as per the controls in the interactive package.
The object name field is used to determine which texture should be used in file type textures that have more than one specific object/texture file pair. These textures may typically be created using Alias paint features.
< u, v - specify the parametric location at the evaluated point
< x, y, z - specify the world space location at the evaluated point
< nx, ny, nz - specify the normal at the evaluated point
< usize, vsize - specify the parametric extent of the point
< > *r, *g, *b, *a - will contain the resultant color
< initialize - initialize this texture. Must be initialized before first use.
< blurmult - how much to blur the sample by
< bluroffset - how much to offset the blur by
< objectname - optionally, the name of the object being textured. Used to texture objects using file textures with per object texture maps.
statusCode AlTexture::applyIteratorToTextures( AlIterator *iter, int &rc )
Applies the given AlIterator to all textures in the texture. The second argument will be set to the return value of the last application of the iterator’s function. See the AlIterator class for more information.
statusCode AlTexture::environmentPixMap( AlPixel *pixArray, int resolution, boolean imageMap )
Converts an environment texture to a square pix map. The AlPixel structure can be used in conjunction with the AlPixFile class to output the pix file.
Note: if this texture is not an environment map, this method will fail.