8613985b |
1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV |
3 | // Copyright (c) 2011-2013 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _OpenGl_Material_Header |
17 | #define _OpenGl_Material_Header |
18 | |
19 | #include <Graphic3d_MaterialAspect.hxx> |
20 | #include <OpenGl_Vec.hxx> |
21 | |
22 | //! OpenGL material definition |
23 | struct OpenGl_Material |
24 | { |
25 | |
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 |
31 | |
32 | float Shine() const { return Params.x(); } |
33 | float& ChangeShine() { return Params.x(); } |
34 | |
35 | float Transparency() const { return Params.y(); } |
36 | float& ChangeTransparency() { return Params.y(); } |
37 | |
38 | //! Set material color. |
39 | void SetColor (const OpenGl_Vec4& theColor) |
40 | { |
41 | // apply the same formula as in Graphic3d_MaterialAspect::SetColor() |
bc379358 |
42 | Ambient.SetValues (theColor.rgb() * 0.25f, Ambient.a()); |
43 | Diffuse.SetValues (theColor.rgb(), Diffuse.a()); |
8613985b |
44 | } |
45 | |
46 | //! Initialize material |
47 | void Init (const Graphic3d_MaterialAspect& theProp, |
48 | const Quantity_Color& theInteriorColor); |
49 | |
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; } |
53 | |
54 | //! Check this material for equality with another material (without tolerance!). |
55 | bool IsEqual (const OpenGl_Material& theOther) const |
56 | { |
57 | return std::memcmp (this, &theOther, sizeof(OpenGl_Material)) == 0; |
58 | } |
59 | |
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); } |
63 | |
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); } |
67 | |
68 | }; |
69 | |
70 | //! Material flag |
71 | enum OpenGl_MaterialFlag |
72 | { |
73 | OpenGl_MaterialFlag_Front, //!< material for front faces |
74 | OpenGl_MaterialFlag_Back //!< material for back faces |
75 | }; |
76 | |
77 | #endif // _OpenGl_Material_Header |