File indexing completed on 2025-01-18 10:04:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _OpenGl_Material_Header
0017 #define _OpenGl_Material_Header
0018
0019 #include <Graphic3d_MaterialAspect.hxx>
0020 #include <OpenGl_Vec.hxx>
0021
0022 class OpenGl_Context;
0023
0024
0025 struct OpenGl_MaterialCommon
0026 {
0027
0028 OpenGl_Vec4 Diffuse;
0029 OpenGl_Vec4 Emission;
0030 OpenGl_Vec4 SpecularShininess;
0031 OpenGl_Vec4 Ambient;
0032
0033 float Shine() const { return SpecularShininess.a(); }
0034 float& ChangeShine() { return SpecularShininess.a(); }
0035
0036
0037 OpenGl_MaterialCommon() : Diffuse (1.0f), Emission (1.0f), SpecularShininess (1.0f, 1.0f, 1.0f, 0.0f), Ambient (1.0f) {}
0038
0039
0040 void SetColor (const OpenGl_Vec3& theColor)
0041 {
0042
0043 Ambient.SetValues (theColor * 0.25f, Ambient.a());
0044 Diffuse.SetValues (theColor, Diffuse.a());
0045 }
0046
0047 };
0048
0049
0050 struct OpenGl_MaterialPBR
0051 {
0052
0053 OpenGl_Vec4 BaseColor;
0054 OpenGl_Vec4 EmissionIOR;
0055 OpenGl_Vec4 Params;
0056
0057 float Metallic() const { return Params.b(); }
0058 float& ChangeMetallic() { return Params.b(); }
0059
0060 float Roughness() const { return Params.g(); }
0061 float& ChangeRoughness() { return Params.g(); }
0062
0063
0064 OpenGl_MaterialPBR() : BaseColor (1.0f), EmissionIOR (1.0f), Params (1.0f, 1.0f, 1.0f, 1.0f) {}
0065
0066
0067 void SetColor (const OpenGl_Vec3& theColor)
0068 {
0069 BaseColor.SetValues (theColor, BaseColor.a());
0070 }
0071
0072 };
0073
0074
0075 struct OpenGl_Material
0076 {
0077 OpenGl_MaterialCommon Common[2];
0078 OpenGl_MaterialPBR Pbr[2];
0079
0080
0081 void SetColor (const OpenGl_Vec3& theColor)
0082 {
0083 Common[0].SetColor (theColor);
0084 Common[1].SetColor (theColor);
0085 Pbr[0].SetColor (theColor);
0086 Pbr[1].SetColor (theColor);
0087 }
0088
0089
0090 void Init (const OpenGl_Context& theCtx,
0091 const Graphic3d_MaterialAspect& theFront,
0092 const Quantity_Color& theFrontColor,
0093 const Graphic3d_MaterialAspect& theBack,
0094 const Quantity_Color& theBackColor);
0095
0096
0097 bool IsEqual (const OpenGl_Material& theOther) const
0098 {
0099 return std::memcmp (this, &theOther, sizeof(OpenGl_Material)) == 0;
0100 }
0101
0102
0103 bool operator== (const OpenGl_Material& theOther) { return IsEqual (theOther); }
0104 bool operator== (const OpenGl_Material& theOther) const { return IsEqual (theOther); }
0105
0106
0107 bool operator!= (const OpenGl_Material& theOther) { return !IsEqual (theOther); }
0108 bool operator!= (const OpenGl_Material& theOther) const { return !IsEqual (theOther); }
0109
0110
0111 const OpenGl_Vec4* PackedCommon() const { return reinterpret_cast<const OpenGl_Vec4*> (Common); }
0112 static Standard_Integer NbOfVec4Common() { return 4 * 2; }
0113
0114
0115 const OpenGl_Vec4* PackedPbr() const { return reinterpret_cast<const OpenGl_Vec4*> (Pbr); }
0116 static Standard_Integer NbOfVec4Pbr() { return 3 * 2; }
0117
0118 private:
0119
0120
0121 void init (const OpenGl_Context& theCtx,
0122 const Graphic3d_MaterialAspect& theMat,
0123 const Quantity_Color& theColor,
0124 const Standard_Integer theIndex);
0125
0126 };
0127
0128
0129 enum OpenGl_MaterialFlag
0130 {
0131 OpenGl_MaterialFlag_Front,
0132 OpenGl_MaterialFlag_Back
0133 };
0134
0135 #endif