1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Material_Header
17 #define _OpenGl_Material_Header
19 #include <Graphic3d_MaterialAspect.hxx>
20 #include <OpenGl_Vec.hxx>
22 //! OpenGL material definition
23 struct OpenGl_Material
26 OpenGl_Vec4 Ambient; //!< ambient reflection coefficient
27 OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient
28 OpenGl_Vec4 Specular; //!< glossy reflection coefficient
29 OpenGl_Vec4 Emission; //!< material emission
30 OpenGl_Vec4 Params; //!< extra packed parameters
32 float Shine() const { return Params.x(); }
33 float& ChangeShine() { return Params.x(); }
35 float Transparency() const { return Params.y(); }
36 float& ChangeTransparency() { return Params.y(); }
38 //! Set material color.
39 void SetColor (const OpenGl_Vec4& theColor)
41 // apply the same formula as in Graphic3d_MaterialAspect::SetColor()
42 Ambient.SetValues (theColor.rgb() * 0.25f, Ambient.a());
43 Diffuse.SetValues (theColor.rgb(), Diffuse.a());
46 //! Initialize material
47 void Init (const Graphic3d_MaterialAspect& theProp,
48 const Quantity_Color& theInteriorColor);
50 //! Returns packed (serialized) representation of material properties
51 const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
52 static Standard_Integer NbOfVec4() { return 5; }
54 //! Check this material for equality with another material (without tolerance!).
55 bool IsEqual (const OpenGl_Material& theOther) const
57 return std::memcmp (this, &theOther, sizeof(OpenGl_Material)) == 0;
60 //! Check this material for equality with another material (without tolerance!).
61 bool operator== (const OpenGl_Material& theOther) { return IsEqual (theOther); }
62 bool operator== (const OpenGl_Material& theOther) const { return IsEqual (theOther); }
64 //! Check this material for non-equality with another material (without tolerance!).
65 bool operator!= (const OpenGl_Material& theOther) { return !IsEqual (theOther); }
66 bool operator!= (const OpenGl_Material& theOther) const { return !IsEqual (theOther); }
71 enum OpenGl_MaterialFlag
73 OpenGl_MaterialFlag_Front, //!< material for front faces
74 OpenGl_MaterialFlag_Back //!< material for back faces
77 #endif // _OpenGl_Material_Header