Workspace 6.21.5
Public Types | Public Member Functions | Protected Member Functions | List of all members
Texturizer Class Referenceabstract

Base class for texturizers to be used with a MeshModelInstance.

#include <Rendering/SceneComponents/Models/texturizer.h>

Inheritance diagram for Texturizer:
[legend]

Public Types

enum  Wrapping { ClampToEdge , ClampToBorder , Repeat , MirroredRepeat }
 

Public Member Functions

 ~Texturizer () override
 
bool canSerialize () const override
 
Texturizerclone () const override=0
 
QString getCacheId () const
 
virtual unsigned getDimensions () const =0
 
bool getEnabled () const
 
bool getInterpolate () const
 
unsigned getNumDimensionsEnabled () const
 
virtual unsigned getNumImages () const =0
 
unsigned getNumImagesEnabled () const
 
virtual Mesh::Vector3d getTextureCoords (const Mesh::NodeHandle &node) const =0
 
virtual TextureImage getTextureImage (int index) const =0
 
Wrapping getWrapping () const
 
bool load (const DataExecution::SerializedItem &item) override
 
bool save (DataExecution::SerializedItem &item) const override
 
void setEnabled (bool b)
 
void setInterpolate (bool b)
 
virtual bool setTexturedModel (const Mesh::MeshModelInterface &model, bool glyphing)
 
void setWrapping (Wrapping wrap)
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Protected Member Functions

 Texturizer ()
 
 Texturizer (const Texturizer &t)
 
Texturizeroperator= (const Texturizer &t)
 

Member Enumeration Documentation

◆ Wrapping

enum Wrapping
Enumerator
ClampToEdge 
ClampToBorder 
Repeat 
MirroredRepeat 

Constructor & Destructor Documentation

◆ Texturizer() [1/2]

Texturizer ( )
protected

Constructs a texturizer with the blend mode set to Decal and wrapping on.

◆ Texturizer() [2/2]

Texturizer ( const Texturizer t)
protected

◆ ~Texturizer()

~Texturizer ( )
override

Member Function Documentation

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual
Returns

Implements Serialize.

◆ clone()

Texturizer * clone ( ) const
overridepure virtual
Returns
A clone of this object.
Note
Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.

Implements Clonable.

Implemented in Texture2D, Texture3D, and NoTexture.

◆ getCacheId()

QString getCacheId ( ) const
Returns
A string which characterizes the parameters which affect the output of this object. It should be unique for each possible combination of the inputs. A common format is to append strings in the form ":key=value" to assist debugging, but any string that is unique for a given set of parameters is acceptable.
Note
The default implementation uses the serialization function save() to generate an appropriate string. Subclasses can override this function to provide a more efficient string if they so wish, since the default implementation is likely to be relatively expensive.

◆ getDimensions()

virtual unsigned getDimensions ( ) const
pure virtual
Returns
The number of dimensions this texturizer supports. This should always be 1, 2 or 3, although it is conceivable that a texturizer might have 4 dimensions (but really that would be a modification of 3 dimensions with the 4th dimension being associated with the w component). A value of zero can also be returned as a special case to denote a texturizer which does not apply a texture at all.

Implemented in Texture2D, Texture3D, and NoTexture.

◆ getEnabled()

bool getEnabled ( ) const
Returns
whether or not the texturizer is enabled.

◆ getInterpolate()

bool getInterpolate ( ) const
Returns
True if the texture image should be interpolated when it does not map exactly pixel for pixel onto an object.
See also
setInterpolate()

◆ getNumDimensionsEnabled()

unsigned getNumDimensionsEnabled ( ) const
inline
Returns
Convenience method to get dimensions conditionally if Texturizer is enabled

◆ getNumImages()

virtual unsigned getNumImages ( ) const
pure virtual
Returns
The number of images this texturizer holds. Some texturizers provide only one image, whereas others provide a set of images and the image to use for any given element is found by calling getTextureImage(). The getNumImages() function can be used by model processors to work out how many images they will need to handle during processing.

Implemented in Texture2D, Texture3D, and NoTexture.

◆ getNumImagesEnabled()

unsigned getNumImagesEnabled ( ) const
inline
Returns
Convenience method to get getNumImages conditionally if Texturizer is enabled

◆ getTextureCoords()

virtual Mesh::Vector3d getTextureCoords ( const Mesh::NodeHandle node) const
pure virtual
Parameters
nodeThe node we want the texture co-ordinate of
Precondition
setTexturedModel must have already been called with the MeshModelInterface that the supplied node belongs to.
Returns
The texture co-ordinates for the specified node. While the result returned is a 3D vector corresponding to the (s,t,r) texture co-ordinates, for lower dimensional textures simply ignore the latter components (eg 2D textures ignore the r component). For consistency, lower dimensional texturizers must set components they don't use to zero.
See also
getTextureImage(), setTexturedModel()

Implemented in NoTexture, Texture2D, and Texture3D.

◆ getTextureImage()

virtual TextureImage getTextureImage ( int  index) const
pure virtual
Parameters
indexThe index of the texture image to retrieve. It must be a non-negative number less than the result of getNumImages().
Returns
The texture image corresponding to the specified index.

Implemented in Texture2D, Texture3D, and NoTexture.

◆ getWrapping()

Texturizer::Wrapping getWrapping ( ) const
Returns
True if the texture image should be wrapped when texture co-ordinates fall outside the range [0,1].
See also
setWrapping()

◆ load()

bool load ( const DataExecution::SerializedItem item)
overridevirtual
Parameters
itemSupplies the state to be loaded into this object.

This function will load the state of this object from item. For many object types, this is most easily implemented in terms of the object's input operator (>>).

It would be reasonable for subclass implementations to assume that the data provided in item is in the same form as would have been saved from a call to save.

Returns
If the state of the object could not be loaded, the function returns false. A return value of true implies that the object state was successfully loaded. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ operator=()

Texturizer & operator= ( const Texturizer t)
protected

◆ save()

bool save ( DataExecution::SerializedItem item) const
overridevirtual
Parameters
itemWhere to save the state of this object.

This function will serialise the object by saving it to item. For most object types, this is most easily implemented in terms of the object's output operator (<<).

It is allowable for an object to only serialize part of itself. This would be useful if the data it represents has a set of defaults and only those values different to the defaults need to be serialized. Such an implementation then needs to be careful how it handles the complimentary load member function.

Returns
If an object could not be serialised or if the underlying object type does not support serialisation, this function should return false. A return value of true implies that the object was successfully saved to item. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ setEnabled()

void setEnabled ( bool  b)
Parameters
bwhether or not to enable the texturizer.

◆ setInterpolate()

void setInterpolate ( bool  b)
Parameters
bSpecifies whether to use some form of interpolation when a target pixel doesn't map exactly to a pixel in the texture image.

When mapping a texture onto an object, the object is unlikely to be a perfect pixel for pixel match to the size of the texture image. When this occurs, renderers can choose to simply choose the closest texture pixel or it can perform some kind of interpolation between pixels to create an "averaged" pixel color for that point on the object. If b is true, this averaging is permitted, but if false then the renderer must always choose the closest texture pixel and perform no averaging. Having averaging enabled can give a smoother blend from one pixel to another and may be more appropriate when the texture image has to be stretched or shrunk by a large amount, but it is slower and will generally lead to a fuzzier image, particularly when the texture image has to be magnified to a size bigger than its resolution.

The default setting for this is false.

See also
getInterpolate()

◆ setTexturedModel()

bool setTexturedModel ( const Mesh::MeshModelInterface model,
bool  glyphing 
)
virtual
Parameters
modelThe model about to be textured.
glyphingIf true, the texture image selection by getTextureImage() should be based on node states instead of element states, since the the glyph that will be textured reflects the node states and no model elements are normally present or shown.

Subclasses can reimplement this function to save internal data about the model that will be used for subsequent calls to getTextureCoords() and getTextureImage(). Clients are free to call this function at any time, so the subclass must keep this in mind, although it will usually only be called by a model appearance processor just before it uses the texturizer to process the specified model or before it outputs a glyph.

Returns
True if successful or false if there was an error when trying to use the specified model. If the texturizer will not be able to return valid texture co-ordinates (eg texture co-ordinate node states are missing in the model), this function should return false.

Reimplemented in NoTexture, Texture2D, and Texture3D.

◆ setWrapping()

void setWrapping ( Texturizer::Wrapping  wrap)
Parameters
wrapIf set to true, then for texture co-ordinates outside the range [0,1], the texture image will be wrapped to the opposite side as necessary. If set to false, then values outside this range are clamped to the closest end of the range.
See also
getWrapping()