File indexing completed on 2026-09-24 09:16:55
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 NCollection_Vec4<float> Diffuse;
0029 NCollection_Vec4<float> Emission;
0030 NCollection_Vec4<float> SpecularShininess;
0031 NCollection_Vec4<float> Ambient;
0032
0033 float Shine() const { return SpecularShininess.a(); }
0034
0035 float& ChangeShine() { return SpecularShininess.a(); }
0036
0037
0038 OpenGl_MaterialCommon()
0039 : Diffuse(1.0f),
0040 Emission(1.0f),
0041 SpecularShininess(1.0f, 1.0f, 1.0f, 0.0f),
0042 Ambient(1.0f)
0043 {
0044 }
0045
0046
0047 void SetColor(const NCollection_Vec3<float>& theColor)
0048 {
0049
0050 Ambient.SetValues(theColor * 0.25f, Ambient.a());
0051 Diffuse.SetValues(theColor, Diffuse.a());
0052 }
0053 };
0054
0055
0056 struct OpenGl_MaterialPBR
0057 {
0058
0059 NCollection_Vec4<float> BaseColor;
0060
0061 NCollection_Vec4<float> EmissionIOR;
0062
0063 NCollection_Vec4<float> Params;
0064
0065 float Metallic() const { return Params.b(); }
0066
0067 float& ChangeMetallic() { return Params.b(); }
0068
0069 float Roughness() const { return Params.g(); }
0070
0071 float& ChangeRoughness() { return Params.g(); }
0072
0073
0074 OpenGl_MaterialPBR()
0075 : BaseColor(1.0f),
0076 EmissionIOR(1.0f),
0077 Params(1.0f, 1.0f, 1.0f, 1.0f)
0078 {
0079 }
0080
0081
0082 void SetColor(const NCollection_Vec3<float>& theColor)
0083 {
0084 BaseColor.SetValues(theColor, BaseColor.a());
0085 }
0086 };
0087
0088
0089 struct OpenGl_Material
0090 {
0091 OpenGl_MaterialCommon Common[2];
0092 OpenGl_MaterialPBR Pbr[2];
0093
0094
0095 void SetColor(const NCollection_Vec3<float>& theColor)
0096 {
0097 Common[0].SetColor(theColor);
0098 Common[1].SetColor(theColor);
0099 Pbr[0].SetColor(theColor);
0100 Pbr[1].SetColor(theColor);
0101 }
0102
0103
0104 void Init(const OpenGl_Context& theCtx,
0105 const Graphic3d_MaterialAspect& theFront,
0106 const Quantity_Color& theFrontColor,
0107 const Graphic3d_MaterialAspect& theBack,
0108 const Quantity_Color& theBackColor);
0109
0110
0111 bool IsEqual(const OpenGl_Material& theOther) const
0112 {
0113 return std::memcmp(this, &theOther, sizeof(OpenGl_Material)) == 0;
0114 }
0115
0116
0117 bool operator==(const OpenGl_Material& theOther) { return IsEqual(theOther); }
0118
0119 bool operator==(const OpenGl_Material& theOther) const { return IsEqual(theOther); }
0120
0121
0122 bool operator!=(const OpenGl_Material& theOther) { return !IsEqual(theOther); }
0123
0124 bool operator!=(const OpenGl_Material& theOther) const { return !IsEqual(theOther); }
0125
0126
0127 const NCollection_Vec4<float>* PackedCommon() const
0128 {
0129 return reinterpret_cast<const NCollection_Vec4<float>*>(Common);
0130 }
0131
0132 static int NbOfVec4Common() { return 4 * 2; }
0133
0134
0135 const NCollection_Vec4<float>* PackedPbr() const
0136 {
0137 return reinterpret_cast<const NCollection_Vec4<float>*>(Pbr);
0138 }
0139
0140 static int NbOfVec4Pbr() { return 3 * 2; }
0141
0142 private:
0143
0144 void init(const OpenGl_Context& theCtx,
0145 const Graphic3d_MaterialAspect& theMat,
0146 const Quantity_Color& theColor,
0147 const int theIndex);
0148 };
0149
0150
0151 enum OpenGl_MaterialFlag
0152 {
0153 OpenGl_MaterialFlag_Front,
0154 OpenGl_MaterialFlag_Back
0155 };
0156
0157 #endif