0028927: Visualization - Graphic3d_StructureManager destructor should invalidate...
[occt.git] / src / Graphic3d / Graphic3d_TextureParams.hxx
1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Graphic3d_TextureParams_HeaderFile
15 #define _Graphic3d_TextureParams_HeaderFile
16
17 #include <Graphic3d_LevelOfTextureAnisotropy.hxx>
18 #include <Graphic3d_Vec2.hxx>
19 #include <Graphic3d_Vec4.hxx>
20 #include <Graphic3d_TextureUnit.hxx>
21 #include <Graphic3d_TypeOfTextureFilter.hxx>
22 #include <Graphic3d_TypeOfTextureMode.hxx>
23 #include <Standard.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_ShortReal.hxx>
26 #include <Standard_Type.hxx>
27 #include <Standard_Transient.hxx>
28
29 //! This class describes texture parameters.
30 class Graphic3d_TextureParams : public Standard_Transient
31 {
32   DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureParams, Standard_Transient)
33 public:
34
35   //! Default constructor.
36   Standard_EXPORT Graphic3d_TextureParams();
37
38   //! Destructor.
39   Standard_EXPORT virtual ~Graphic3d_TextureParams();
40
41   //! Default texture unit to be used, default is Graphic3d_TextureUnit_BaseColor.
42   Graphic3d_TextureUnit TextureUnit() const { return myTextureUnit; }
43
44   //! Setup default texture unit.
45   void SetTextureUnit (Graphic3d_TextureUnit theUnit) { myTextureUnit = theUnit; }
46
47   //! @return TRUE if the texture is modulate.
48   //! Default value is FALSE.
49   Standard_Boolean IsModulate() const { return myToModulate; }
50   
51   //! @param theToModulate turn modulation on/off.
52   Standard_EXPORT void SetModulate (const Standard_Boolean theToModulate);
53   
54   //! @return TRUE if the texture repeat is enabled.
55   //! Default value is FALSE.
56   Standard_Boolean IsRepeat() const { return myToRepeat; }
57   
58   //! @param theToRepeat turn texture repeat mode ON or OFF (clamping).
59   Standard_EXPORT void SetRepeat (const Standard_Boolean theToRepeat);
60   
61   //! @return texture interpolation filter.
62   //! Default value is Graphic3d_TOTF_NEAREST.
63   Graphic3d_TypeOfTextureFilter Filter() const { return myFilter; }
64   
65   //! @param theFilter texture interpolation filter.
66   Standard_EXPORT void SetFilter (const Graphic3d_TypeOfTextureFilter theFilter);
67   
68   //! @return level of anisontropy texture filter.
69   //! Default value is Graphic3d_LOTA_OFF.
70   Graphic3d_LevelOfTextureAnisotropy AnisoFilter() const { return myAnisoLevel; }
71   
72   //! @param theLevel level of anisontropy texture filter.
73   Standard_EXPORT void SetAnisoFilter (const Graphic3d_LevelOfTextureAnisotropy theLevel);
74   
75   //! @return rotation angle in degrees
76   //! Default value is 0.
77   Standard_ShortReal Rotation() const { return myRotAngle; }
78   
79   //! @param theAngleDegrees rotation angle.
80   Standard_EXPORT void SetRotation (const Standard_ShortReal theAngleDegrees);
81   
82   //! @return scale factor
83   //! Default value is no scaling (1.0; 1.0).
84   const Graphic3d_Vec2& Scale() const { return myScale; }
85   
86   //! @param theScale scale factor.
87   Standard_EXPORT void SetScale (const Graphic3d_Vec2 theScale);
88   
89   //! @return translation vector
90   //! Default value is no translation (0.0; 0.0).
91   const Graphic3d_Vec2& Translation() const { return myTranslation; }
92   
93   //! @param theVec translation vector.
94   Standard_EXPORT void SetTranslation (const Graphic3d_Vec2 theVec);
95   
96   //! @return texture coordinates generation mode.
97   //! Default value is Graphic3d_TOTM_MANUAL.
98   Graphic3d_TypeOfTextureMode GenMode() const { return myGenMode; }
99   
100   //! @return texture coordinates generation plane S.
101   const Graphic3d_Vec4& GenPlaneS() const { return myGenPlaneS; }
102   
103   //! @return texture coordinates generation plane T.
104   const Graphic3d_Vec4& GenPlaneT() const { return myGenPlaneT; }
105   
106   //! Setup texture coordinates generation mode.
107   Standard_EXPORT void SetGenMode (const Graphic3d_TypeOfTextureMode theMode, const Graphic3d_Vec4 thePlaneS, const Graphic3d_Vec4 thePlaneT);
108
109   //! Return modification counter of parameters related to sampler state.
110   unsigned int SamplerRevision() const { return mySamplerRevision; }
111
112 private:
113
114   //! Increment revision.
115   void updateSamplerRevision() { ++mySamplerRevision; }
116
117 private:
118
119   Graphic3d_Vec4                     myGenPlaneS;       //!< texture coordinates generation plane S
120   Graphic3d_Vec4                     myGenPlaneT;       //!< texture coordinates generation plane T
121   Graphic3d_Vec2                     myScale;           //!< texture coordinates scale factor vector; (1,1) by default
122   Graphic3d_Vec2                     myTranslation;     //!< texture coordinates translation vector;  (0,0) by default
123   unsigned int                       mySamplerRevision; //!< modification counter of parameters related to sampler state
124   Graphic3d_TextureUnit              myTextureUnit;     //!< default texture unit to bind texture; Graphic3d_TextureUnit_BaseColor by default
125   Graphic3d_TypeOfTextureFilter      myFilter;          //!< texture filter, Graphic3d_TOTF_NEAREST by default
126   Graphic3d_LevelOfTextureAnisotropy myAnisoLevel;      //!< level of anisotropy filter, Graphic3d_LOTA_OFF by default
127   Graphic3d_TypeOfTextureMode        myGenMode;         //!< texture coordinates generation mode, Graphic3d_TOTM_MANUAL by default
128   Standard_ShortReal                 myRotAngle;        //!< texture coordinates rotation angle in degrees, 0 by default
129   Standard_Boolean                   myToModulate;      //!< flag to modulate texture with material color, FALSE by default
130   Standard_Boolean                   myToRepeat;        //!< flag to repeat (true) or wrap (false) texture coordinates out of [0,1] range
131
132 };
133
134 DEFINE_STANDARD_HANDLE(Graphic3d_TextureParams, Standard_Transient)
135
136 #endif // _Graphic3d_TextureParams_HeaderFile