Mudbox/material.h Source File

material.h
Go to the documentation of this file.
1 
2 //**************************************************************************/
3 // Copyright (c) 2008 - 2010 Autodesk, Inc.
4 // All rights reserved.
5 //
6 // Use of this software is subject to the terms of the Autodesk license
7 // agreement provided at the time of installation or download, or which
8 // otherwise accompanies this software in either electronic or hard copy form.
9 //
10 //**************************************************************************/
11 // DESCRIPTION: Mudbox Plugin API header -- Material and Texture classes.
12 // CREATED: October 2008
13 //**************************************************************************/
14 
15 namespace mudbox {
16 //------------------------------------------------------------------------------
73 class MBDLL_DECL Material : virtual public TreeNode
74 {
76 
81  enum VertexDataUsage
82  {
86  eVDUPosition,
87  eVDUNormal,
88  eVDUTextureCoordinate,
89  eVDUVertexColor,
90  eVDUBoneIndices,
91  eVDUBoneWeights,
92  eVDUTangent,
94  eVDUBinormal,
95 
100  eVDUDirectTextureCoordinate0,
101  eVDUDirectTextureCoordinate1,
102  eVDUDirectTextureCoordinate2,
103  eVDUDirectTextureCoordinate3,
104  eVDUDirectTextureCoordinate4,
105  eVDUDirectTextureCoordinate5,
106  eVDUDirectTextureCoordinate6,
107  eVDUDirectTextureCoordinate7,
108 
110  eVDUNotUsed
111  };
112 
113 protected:
119  Material( void );
120 
121 public:
122  ~Material();
123 
130  virtual bool Activate(
131  const Mesh *pMesh,
132  const AxisAlignedBoundingBox &cUVArea,
133  const Color &cColor = Color::white
135  );
136 
138  virtual void Deactivate( void );
139 
149  virtual float Transparency( void ) const;
150 
153  virtual void SetTransparency(
154  float fTransparency
155  );
156 
168  virtual bool TexturesVisible( void ) const;
169 
171  virtual void SetTexturesVisible(
172  bool bVisible
173  );
174 
181  virtual bool IsTCNeeded( void ) const;
182 
189  virtual bool IsTNBNeeded( void ) const;
190 
192  virtual unsigned int TextureCount( void ) const;
193 
195  virtual class TexturePool *Texture(
196  unsigned int iTextureIndex
197  ) const;
198 
212  virtual bool SetTextureTileLive(
213  const AxisAlignedBoundingBox &cUVArea,
214  bool bLive,
215  float fTCGrad = -1.0f,
216  bool bSync = false,
217  bool bLazyUpdate = false
218  );
219 
221  virtual bool IsTextureTileLive(
222  const AxisAlignedBoundingBox &cUVArea
223  );
224 
226  virtual unsigned int TextureTileCount() const;
227 
229  virtual void SetTextureTileLODBias(
230  const AxisAlignedBoundingBox& cArea,
231  float fTCGrad
232  );
233 
238  virtual qint64 TileVideoMemoryUsage(
239  const AxisAlignedBoundingBox& cArea,
240  float fTCGrad = -1.0f
241  ) const;
242 
244  virtual AxisAlignedBoundingBox TextureTileArea(
245  unsigned int iTileIndex
246  ) const;
247 
254  virtual void ActivateUVArea( const AxisAlignedBoundingBox &cArea );
255 
260  virtual VertexDataUsage MapVertexData(
261  VertexDataUsage eUsage
262  ) const;
264 
266  virtual Layer *ImportPaintLayer(
267  const QString &sFileName,
268  const QString &sChallenName,
270  Mesh *pMesh = 0
271  );
273 };
274 
275 
276 //-----------------------------------------------------------------------------
279 {
281 
282 protected:
288  TextureMixer( void );
289 
290 public:
292  virtual unsigned int BlendModeCount( void ) const;
293 
295  virtual QString BlendModeDisplayName(
296  int iBlendMode
297  ) const;
298 
300  virtual QString BlendModeName(
301  int iBlendMode
302  ) const;
303 
307  virtual void SetBlendMode(
308  int iBlendMode
309  ) ;
310 
313  virtual void SetBlendModeParameters(
314  const Store<float>& pParameters
315  );
316 
318  virtual void SetLayerCount(
319  unsigned int iLayerCount
320  );
321 
323  virtual void SetLayerData(
324  unsigned int iLayerIndex,
325  int iTextureID,
326  float fTransparency,
327  int iMaskID = 0,
328  float fMaskTransparency = 1.0f
329  );
330 
332  virtual void Mix(
333  class Texture *d,
334  unsigned int iWidth,
335  unsigned int iHeight,
336  enum Image::Format eFormat
337  );
338 
341  static Image* Mix(
342  Store< const TexturePool* >& aLayers,
343  AxisAlignedBoundingBox& cArea
344  );
345 
346  static int s_iCompositingFBO;
347 };
348 
349 //-----------------------------------------------------------------------------
355  private:
356  // this describes a texture tile. It has a pointer to the texture and
357  // a small amount of frequently accessed metadata. This object should
358  // be kept as small as possible, as there will be a 2D, non-sparse
359  // array of these kept my the texture pool.
360  // presently 16 bytes on a 64 bit machine, 12 bytes on a 32 bit machine.
361  class TileDescriptor {
362  public:
363  TileDescriptor() : m_TileStateIndex(-1) {}
364  int m_TileStateIndex;
365  };
366 
367 
368  float m_UOrigin, m_VOrigin; // origin (may be negative) in UV space of this array.
369  int m_USize, m_VSize; // Size in U and V covered by this tile array
370 
371  TileDescriptor *m_Tiles; // pointer to the tile array - declared as 1D, but
372  // accessed as a 2D array by tileFromUV
373 
374  // given UV coordinates, return the TileDescriptor
375  TileDescriptor *tileFromUV(float U, float V) const
376  {
377  U -= m_UOrigin; V -= m_VOrigin; // bring to 0 origin
378  int u = (int)U, v = (int)V; // same as floor now that they are positive
379  return &m_Tiles[(v * m_USize) + u]; // classic 2D array access math.
380  }
381 
382  // resize the TileArray to include these UV coordinates.
383  void resizeArrayToInclude(float U, float V);
384 
385  // initialize the class.
386  void init()
387  {
388  m_UOrigin, m_VOrigin = 0;
389  m_USize, m_VSize = 0;
390  m_Tiles = NULL;
391  }
392 
393  public :
394 
395  TextureTileArray() { init(); }
396  ~TextureTileArray() { dropAll(); }
397 
400  float getMinU() const { return m_UOrigin; }
403  float getMinV() const { return m_VOrigin; }
406  float getMaxU() const { return m_UOrigin + (float)m_USize; }
409  float getMaxV() const { return m_VOrigin + (float)m_VSize; }
410 
412  void getTotalUVBounds(float &minU, float &minV, float &maxU, float &maxV) const
413  {
414  minU = m_UOrigin;
415  minV = m_VOrigin;
416  maxU = minU + (float)m_USize;
417  maxV = minV + (float)m_VSize;
418  }
419 
422  bool contains(float U, float V) const
423  {
424  return m_Tiles && U >= getMinU() && U < getMaxU() && V >= getMinV() && V < getMaxV();
425  }
426 
427 
428  int getTileStateIndex(float U, float V) const
429  {
430  if (!contains(U, V)) return -1; else
431  return tileFromUV(U, V)->m_TileStateIndex;
432  }
433 
434  void setTileStateIndex(float U, float V, int indx)
435  {
436  if (!contains(U, V)) resizeArrayToInclude(U, V);
437  tileFromUV(U, V)->m_TileStateIndex = indx;
438  }
439 
440 
445  void dropAll();
446 
447  void clearTileStateIndices();
448 };
449 
450 
451 //-----------------------------------------------------------------------------
467 class MBDLL_DECL TexturePool : virtual public Node
468 {
470 
471 protected:
477  TexturePool( void );
478 
480 
481 public:
482 
485  {
486  unsigned int m_iWidth;
487  unsigned int m_iHeight;
488  enum Image::Format m_eFormat;
489  unsigned int m_iChannelCount;
492 
493  TileDescriptor( unsigned int iW, unsigned int iH, enum Image::Format eFormat, unsigned int iChannelCount, const QString& sFileFormat, const Color& cFillColor );
494 
495  TileDescriptor();
496 
497  TileDescriptor( const TileDescriptor& pOther, unsigned int iChannelCount );
498 
499  bool IsValid() const;
500 
501  virtual void Serialize( Stream& s );
502  };
503 
505  {
508  renderModeVertexColor
509  };
510 
511  enum Location
512  {
516  locationDisk
517  };
518 
519  enum Usage
520  {
525  usageUnknown
526  };
527 
529  virtual const TileDescriptor& DefaultTileDescriptor( void ) const;
530 
532  virtual void SetDefaultTileDescriptor( const TileDescriptor& pDesc );
533 
543  virtual enum Usage Usage() const;
544 
546  virtual void SetUsage( enum Usage eUsage );
547 
549  virtual QString Name( void ) const;
550 
552  virtual void SetName(
553  const QString &sName
554  );
556 
558  virtual unsigned int RenderMode( void ) const;
559 
561  virtual void SetRenderMode( unsigned int iMode );
562 
564  virtual void SetLocation( unsigned int iLocation );
565 
567  virtual unsigned int Location( void ) const;
568 
569  virtual TexturePool &operator =( TexturePool &cT );
570 
580  virtual int Width( void ) const;
581 
583  virtual void SetWidth( int iWidth );
584 
593  virtual void SetFileName(
594  const QString &sFileName
595  );
596 
599  virtual const QString& FileName( void ) const;
600 
604  virtual void Save(
605  const QString &sFileName = "",
606  const QString &sFormat = "",
607  Material *m = NULL,
610  bool bForced = false
611  );
612 
615  virtual void Export(
616  const QString &sFileName,
617  const QString &sFormat = "",
618  Material *m = NULL
621  );
622 
626  virtual void SetDirty(
627  bool bDirty
628  );
629 
631  virtual bool IsDirty( void ) const;
632 
634  virtual void AddToDirtyArea(
635  const Vector &cPoint
636  );
637 
639  virtual void SetTilesDirty( void );
640 
642  virtual void Reload( void );
643 
645  virtual void SetContentChanged( void );
646 
648  virtual bool IsContentChanged( void );
649 
651  virtual unsigned int TileCount( void ) const;
652 
654  virtual class Texture *Tile(
655  unsigned int iTileIndex
656  );
657 
660  virtual class Texture *Tile(
661  const AxisAlignedBoundingBox &cTCArea,
662  bool bAlloc = true
663  );
665 
669  virtual class Texture *Tile(float U, float V, bool bAlloc = true);
670 
672  virtual AxisAlignedBoundingBox TileArea(
673  unsigned int iTileIndex
674  ) const;
675 
676  TextureTileArray *getTextureTileArray() { return &m_TextureTileArray; }
677 
679  virtual TextureMixer *Mixer( void ) const;
680 
682  virtual int BlendMode( void ) const;
683 
685  virtual void SetBlendMode(
686  int iMode
687  );
689 
690  virtual void SetMaterial(
691  Material* pMaterial
692  );
693 
694  virtual Material *GetMaterial() const;
695 
696  // Internal use only.
697  virtual TexturePool *Buffer( void ) const;
698 
702  virtual qint64 TileVideoMemoryUsage(
703  const AxisAlignedBoundingBox& cArea,
704  float fTCGrad = -1
705  );
706 };
707 
708 //-----------------------------------------------------------------------------
716 class MBDLL_DECL Texture : virtual public Node
717 {
720 
721 protected:
727  Texture( void );
728 
729 public:
731  virtual void Create(
732  unsigned int iWidth,
733  unsigned int iHeight,
734  unsigned int iChannelCount,
735  enum Image::Format eFormat,
736  const Color &cColor
737  );
738 
740  virtual void Create(
741  unsigned int iWidth,
742  unsigned int iHeight,
743  unsigned int iChannelCount,
744  enum Image::Format eFormat
745  );
746 
748  virtual bool CreateFromFile(
749  const QString &sFileName,
750  unsigned int iChannelCount = 0,
751  enum Image::Format eFormat = Image::eUnknown
752  );
753 
755  virtual const Image *AsImage( void );
756 
759  virtual void CopyTo(
760  Texture &cTexture
761  ) const;
762 
764  virtual unsigned int Width( void ) const;
765 
767  virtual unsigned int Height( void ) const;
768 
770  virtual unsigned int BitDepth( void ) const;
771 
773  static unsigned int BitDepth( enum Image::Format eFormat );
774 
776  virtual enum Image::Format Format( void ) const;
777 
779  virtual unsigned int ChannelCount( void ) const;
780 
785  virtual bool Activate( void ) const;
786 
789  virtual bool Deactivate( void ) const;
790 
792  virtual unsigned int OpenGLName( void ) const;
793 
795  virtual bool SetAsRenderTarget( void );
796 
798  virtual bool RestoreRenderTarget( void );
799 
800  virtual abool *getFilteringPref();
801 
803  virtual void CopyFrom(
804  Image *pImage,
805  const ImgTile* pRegion = 0
806  );
807 
809  virtual void ReplaceWith(
810  Image *pImage,
811  const ImgTile* pRegion = 0
812  );
813 
816  virtual void CopyTo(
817  Image *pImage,
818  bool tiled = true,
819  const ImgTile *region = 0,
821  );
823 
824 
825 
827  virtual void SetLocation(
828  unsigned int iLocation
829  );
831 
836  virtual unsigned int Location( void ) const;
837 
839  virtual int64 TotalMemoryUsage( void ) const;
840 
842  virtual qint64 VideoMemoryUsage( float fTCGrad = -1.0f ) const;
843 
845  virtual void SetLive(
846  bool bLive
847  );
848 
850  virtual bool IsLive( void ) const;
851 
854 
855 
863  virtual bool NewVersion();
864 
871  virtual bool PrevVersion();
872 
879  virtual bool NextVersion();
880 
883  virtual int NumVersions();
884 
889  virtual bool MergeOldestVersions();
890 
898  virtual bool PurgeNewerVersions();
899 
902  virtual bool PurgeAllButCurrentVersion();
903 
909  virtual bool BeginUndoableOperation();
910 
913  virtual bool EndUndoableOperation();
914 
916 
918  virtual void SetFiltered(
919  bool bFiltered
920  );
921 
924  virtual void SetConvert32To16bitFloat(
925  bool bConvert
926  );
927 
934  virtual bool setProxyLevel(
935  unsigned char level,
936  bool bLazySet = false
937  );
938 
940  virtual void SyncContent();
941 
943  virtual unsigned char getProxyLevel() const;
944 
948  virtual void Composite(
949  const Texture* pTex,
950  ImgDirtyRegion* pRegion = 0,
951  unsigned int iBlendMode = 0,
952  const Store<float>* aBlendParameters = 0
953  );
954 
962  static unsigned char ProxyLevel(
963  float fTCGrad,
964  unsigned int iTextureSize
965  );
966 
971  virtual void CopyGLTextureToImage(
972  Image *pImage,
973  bool tiled = true,
974  const ImgTile *region = 0,
976  ) const;
978 protected:
980 
981 
982 public:
983 
985  virtual bool IsDirty( void ) const;
986 
988  virtual void SetDirty( bool bDirty );
989 
994 
996 
999  {
1000  m_DirtyRegion.ClearDirtyRegion();
1001  }
1002 
1010  virtual void AddDirtyPixel(
1011  int x,
1012  int y
1013  )
1014  {
1015  m_DirtyRegion.AddToDirtyRegion(ImgTile(x, y, 1, 1));
1016  }
1017 
1023  virtual void AddDirtyTile(
1024  const ImgTile &t
1025  )
1026  {
1027  m_DirtyRegion.AddToDirtyRegion(t);
1028  }
1029 
1030 
1032  ImgTile DirtyTile() const { return m_DirtyRegion.GetTotalBounds(); }
1033 
1035  ImgDirtyRegion *DirtyRegion() { return &m_DirtyRegion; }
1036 
1038 };
1039 
1040 
1041 //-----------------------------------------------------------------------------
1049 {
1050  DECLARE_CLASS;
1051 
1052  enum Slot
1053  {
1054  eSlotColor0 = 0,
1055  eSlotColor1,
1056  eSlotColor2,
1057  eSlotColor3,
1058  eSlotDepth,
1059  eSlotCount // placeholder for last position - not a type of slot
1060  };
1061 
1062 public:
1065  virtual void DrawTexture(
1066  const class Texture *pTexture
1067  );
1068 
1071  virtual bool Attach(
1072  mudbox::Texture *pTexture,
1073  Slot eSlot = eSlotColor0
1074  );
1075 
1077  virtual void Detach(
1078  Slot eSlot = eSlotColor0
1079  );
1080 
1082  virtual mudbox::Texture *Texture(
1083  Slot eSlot = eSlotColor0
1084  ) const;
1085 
1087  virtual unsigned int Width( void ) const;
1088 
1090  virtual unsigned int Height( void ) const;
1091 
1093  virtual void SetSize(
1094  unsigned int iWidth,
1095  unsigned int iHeight
1096  );
1097 
1099  virtual void Activate( void );
1100 
1102  virtual void Restore( void );
1103 
1105  virtual void SetMultisampling( bool bMultisampling );
1106 };
1107 
1108 
1109 
1110 
1111 
1112 }; // end of namespace mudbox
1113 
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
Definition: GLee.h:10762
GLenum GLint GLint y
Definition: GLee.h:876
float getMaxU() const
returns the maximum U coordinate.
Definition: material.h:406
GLint level
Definition: GLee.h:905
Represents a 3D vector or point with S23E8 floating point elements.
Definition: math.h:35
int getTileStateIndex(float U, float V) const
Definition: material.h:428
A Mesh is a collection of vertices organized into faces, and optional Texture Coordinate information...
Definition: mesh.h:452
Represents a texture mixer.
Definition: material.h:278
bool contains(float U, float V) const
returns true if the array is big enough to contain the specified UV coordinates
Definition: material.h:422
This is a container class for simple textures.
Definition: material.h:467
ImgTile DirtyTile() const
Returns the dirty rectangle of the texture. Deprecated.
Definition: material.h:1032
Format
Image channel datatype type.
Definition: image.h:1522
This is the base class for anything which is an element of a list with a fixed order and a transparen...
Definition: layer.h:20
ImgDirtyRegion * DirtyRegion()
returns the dirty region.
Definition: material.h:1035
long long qint64
Definition: qglobal.h:947
unsigned int m_iHeight
The default width, in pixels of new texture tiles.
Definition: material.h:487
Represents a bounding box whose axes are aligned with the coordinate system.
Definition: math.h:838
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
void setTileStateIndex(float U, float V, int indx)
Definition: material.h:434
Implement a somewhat smarter image region that a simple rectangle.
Definition: image.h:1080
virtual void AddDirtyTile(const ImgTile &t)
Notifies the texture that part of it has changed.
Definition: material.h:1023
Color m_cFillColor
The default channel count of new texture tiles.
Definition: material.h:490
QString m_sFileFormat
The color used to fill new texture tiles.
Definition: material.h:491
long long int64
Definition: mudbox.h:173
Represents a color with four components: red, green, blue, alpha.
Definition: math.h:674
MemoryChannelOrder
Describe channel ordering for 4 channel images – these are the order of the channels in memory...
Definition: image.h:1273
void ClearDirtyRegion()
clear the dirty region – resets it completely.
Definition: image.h:1121
unsigned int m_iChannelCount
The default pixel format of new texture tiles.
Definition: material.h:489
GLenum GLint x
Definition: GLee.h:876
void getTotalUVBounds(float &minU, float &minV, float &maxU, float &maxV) const
get the bounds of this texture tile array
Definition: material.h:412
ImgTile GetTotalBounds() const
return the total bounds of the dirty region as one rectangle.
Definition: image.h:1144
This class describes a 2D array of texture tiles.
Definition: material.h:354
const GLdouble * v
Definition: GLee.h:1174
TextureTileArray * getTextureTileArray()
Definition: material.h:676
virtual void AddDirtyPixel(int x, int y)
Notifies the texture that part of it has changed.
Definition: material.h:1010
void ResetDirtyTile()
Resets the dirty region to be empty.
Definition: material.h:998
Represents a texture tile inside a texture pool.
Definition: material.h:716
Class: ConvolutionKernel.
Definition: array.h:15
This class is the base of all node types that can be structured in a hierarchy.
Definition: treenode.h:18
This structure describes the default texture parameters used when creating texture tiles for this Tex...
Definition: material.h:484
static Color white
Definition: math.h:794
Describes a material of a geometry including its surface colors, transparency and texture information...
Definition: material.h:73
Represents a rectangle. Used to specify rectangular regions of an image.
Definition: image.h:960
Streams are used to read information from a file, or to write it to a file.
Definition: stream.h:39
float getMinU() const
returns the minimum U coordinate.
Definition: material.h:400
#define DECLARE_CLASS
This macro should be used in declaration of classes which are inherited from the Node class (or any d...
Definition: node.h:91
void AddToDirtyRegion(const ImgTile &dirtyTile)
add a imgTile to the dirty region If you are partway through iterating the tiles, this will reset tha...
float getMinV() const
returns the minimum V coordinate.
Definition: material.h:403
RenderTarget is an abstraction of an OpenGL renderbuffer object.
Definition: material.h:1048
static int s_iCompositingFBO
Definition: material.h:346
GLdouble GLdouble t
Definition: GLee.h:1181
Location
Definition: qsql.h:55
GLdouble s
Definition: GLee.h:1173
This is the base image type defining the interface to images.
Definition: image.h:1504
GLclampf f
Definition: GLee.h:9303
#define Q_DECLARE_TR_FUNCTIONS(context)
#define MBDLL_DECL
Definition: dllinterface.h:35
TextureTileArray m_TextureTileArray
Definition: material.h:479
ImgDirtyRegion m_DirtyRegion
Definition: material.h:979
float getMaxV() const
returns the maximum V coordinate.
Definition: material.h:409