AlShader

Base object for representing shader data

Synopsis

#include <AlShader.h>
class AlShader : public AlObject , public AlAnimatable
AlShader();
virtual ~AlShader();
virtual statusCode deleteObject();
virtual AlObject *copyWrapper() const;
statusCode create();
virtual AlAnimatable* asAnimatablePtr();
virtual AlObjectType type() const;
virtual AlShader* asShaderPtr();
virtual const char* name() const;
virtual statusCode setName( const char * );
statusCode parameter( const AlShadingFields, double* ) const;
statusCode parameter( const AlShadingFields, double& ) const;
statusCode setParameter( const AlShadingFields, const double );
const char* shadingModel() const;
statusCode setShadingModel( const char* );
AlTexture* firstTexture() const;
AlTexture* nextTexture( const AlTexture* ) const;
statusCode nextTextureD( AlTexture* ) const;
AlList* fields() const;
AlList* mappedFields() const;
statusCode addTexture( const char*, const char*, AlTexture** returnedTexture = NULL );
statusCode removeTexture( const char* );
statusCode applyIteratorToTextures( AlIterator*, int& );
AlShader* copyObject();
boolean isUsed();

Description

This class encapsulates the basic functionality for checking and setting the name of a shader as well as accessing the textures that a particular shader refers to, and the animation on the shader. Shader objects are accessible through both the AlUniverse class and the objects that reference them (AlSurface and AlFace classes).

A shader object may reference textures. The firstTexture() and nextTexture() methods are used to access these textures.

firstTexture() returns the first texture that the shader object references. nextTexture() moves from a given referenced texture to the next texture in order, as related to the shader object. (See the similar methods for the AlTexture/AlEnvironment classes.)

The animation on a shader can be accessed through the firstChannel() and nextChannel() methods. All the channels on the shader can be deleted by calling deleteAnimation().

The shader parameters can be accessed through the parameter() and setParameter() methods. Each shader has a specific set of parameters that are valid for it that depend on its type. The full list of shader parameters can be seen in the file AlShadingFields.h. For example, all parameters specific to the Blinn shader have names of the form kFLD_SHADING_BLINN_*. Parameters common to all shaders have the form kFLD_SHADING_COMMON_*. All parameters are treated as doubles even though this may not necessarily be what they are. This is done to make the interface as simple and consistent as possible.

Summary

AlAnimatable *AlShader::asAnimatablePtr()

Description

This virtual function returns a non-null pointer to itself, indicating that it is safe to cast to an object of this class.

AlShader::AlShader()

Description

Constructs an AlShader wrapper object. Use the create() method to initialize an AlShader.

AlShader::~AlShader()

Description

Deletes an AlShader wrapper object.

statusCode AlShader::create()

Description

Does any initialization and allocation of data for an AlShader. Allocates space for this AlShader and adds it to the global list of shaders in AlUniverse. The shader is initialized as the Alias default shader.

Return codes

sSuccess - if creation succeeded.

sInsufficientMemory - if not enough memory available.

statusCode AlShader::deleteObject()

Description

Deletes the AlShader and the AlTextures hanging off of the shader. All objects that were assigned this shader will be assigned the default shader. Note that after this operation, any pointers to AlTextures that had been part of this shader will no longer be valid.

Return codes

sSuccess - shader was deleted

sFailure - shader was not deleted

sInvalidObject - the shader was invalid

AlObject *AlShader::copyWrapper() const

Description

Return an exact duplicate of this AlShader wrapper.

AlObjectType AlShader::type() const

Description

Returns the class identifier 'kShaderType'.

AlShader* AlShader::asShaderPtr()

Description

This virtual function returns a non-null pointer to itself, indicating that it is safe to cast to an object of this class.

const char* AlShader::name() const

Description

Returns the name of the shader.

statusCode AlShader::setName( const char *newName)

Description

Changes the name of the shader to a new name. If the given name is not a unique one or contains illegal characters, then a new unique name is generated based on the given name and assigned to the shader. 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

Arguments

< newName - new name of the object

Return codes

sSuccess - name was changed

sInvalidArgument - 'newName' was NULL

sInvalidObject - the shader is invalid

sNameChangedToUniqueOne - name was changed to be a unique version of the given name

statusCode AlShader::parameter( const AlShadingFields field,double& result )const

Description

This method finds the value of a given shader field.

Arguments

< field - shader field type

> result - Returned result of the field

Return codes

sSuccess - field was returned

sInvalidArgument - field was not legal for this shader

sFailure - field could not be returned

sInvalidObject - the shader is invalid

statusCode AlShader::setParameter( const AlShadingFields field,const double value )

Description

This method changes the value of the shader field. If the given field is not valid then a status code of sInvalidArgument is returned.

Arguments

< field - shader field type

< value - new value that the shader field is to take

Return codes

sSuccess - field was changed

sInvalidArgument - field was not legal for this shader

sFailure - field could not be changed

sInvalidObject - the shader is invalid

const char* AlShader::shadingModel() const

Description

This method returns a string representing the shading model. The returned string will be one of BLINN, PHONG, LAMBERT, or LIGHTSOURCE.

statusCode AlShader::setShadingModel( const char* model )

Description

This method tries to set the shading model of the shader. The model must be one of LIGHTSOURCE, LAMBERT, BLINN, or PHONG.

Return codes

sSuccess - the shading model was successfully set.

sInvalidArgument - the given string is not a shading model.

sInvalidObject - the shader is not valid.

AlTexture* AlShader::firstTexture() const

Description

Returns the first texture that this shader object references. If there are none then NULL is returned.

AlTexture* AlShader::nextTexture( const AlTexture* last_texture ) const

Description

Returns the texture after the given one in the shader's texture list. Specifying NULL as parameter will return the first texture.

Arguments

< last_texture - Texture from which to walk forward

statusCode AlShader::nextTextureD( AlTexture* last_texture ) const

Description

Destructively points the last_texture wrapper to the next the texture after the given one in the shader's texture list.

Arguments

<> last_texture - Texture from which to walk forward

Return codes

sSuccess - the wrapper points to the next texture

sInvalidArgument - 'last_texture' was invalid or NULL

sFailure - there is no next texture

sInvalidObject - the shader is invalid

AlList* AlShader::fields() const

Description

This method returns an AlList of AlShadingFieldItems, each of which contains an AlShadingFields value valid for this shader.

AlList* AlShader::mappedFields() const

Description

This method returns an AlList of AlMappedFieldItems, each of which contains a character string identifier identifying a field on this shader which may be texture mapped. Note that these strings are identical to the SDL identifiers and the complete list can be found in the SDL manual.

statusCode AlShader::removeTexture( const char* fieldName )

Description

This method removes a texture from a particular field of the AlShader. The first argument is the name of the field which will have the texture applied to it. Only those fields valid for this shader should be provided; any others will cause this method to fail. Valid fields are any returned by the fields() method.

Arguments

< fieldName - name of the field which will have the texture removed from it

Return codes

sSuccess - the texture was added successfully.

sFailure - no texture was present.

sCannotDelete - a texture already existed on the field which could not be deleted.

sInvalidArgument - the argument was not valid for the shader.

sInvalidObject - the shader is invalid

statusCode AlShader::addTexture( const char* fieldName, const char* textureName, AlTexture** returnCreatedTexture )

Description

This method adds a texture to a particular field of the AlShader. The first argument is the name of the field which will have the texture applied to it. Only those fields valid for this shader 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.

Note: most of these names are also found on the widgets themselves (e.g. 'sRock' or 'Fractal')

For example, to add shaders to the 'color' fields, one would use commands such as

shader->addTexture( "color", "sRock" ) shader->addTexture( "color", "Fractal" )

Arguments

< fieldName - name of the field which will have the texture applied to it

< textureName - name of the texture type to apply to the field

returnCreatedTexture - returns the created texture if not NULL

Return codes

sSuccess - the texture was added successfully.

sFailure - the texture was not added.

sCannotDelete - a texture already existed on the field which could not be deleted.

sInvalidArgument - either argument was not valid for the shader.

sInvalidObject - the shader is invalid

statusCode AlShader::applyIteratorToTextures( AlIterator *iter, int &rc )

Description

Apply the given AlIterator to all textures in the shader. 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.

Arguments

< iter - the iterator to apply

> rc - the return value of the last application of the iterator

Return codes

sSuccess - the application of the iterator terminated normally

sFailure - the application of the iterator terminated abnormally

sInvalidObject - the shader is invalid

sInvalidArgument - the iterator was NULL.

AlShader *AlShader::copyObject()

Description

Copy this AlShader returning a pointer to the new copy or NULL if the copy failed.

boolean AlShader::isUsed()

Description

Returns TRUE if the shader is being used by another object. Return value is FALSE otherwise.





aliasdocs@aw.sgi.com
Copyright © 1996, Alias|Wavefront, a Silicon Graphics Company. All rights reserved.