00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifndef VRS_OPENGL_SHAPEMATERIALGL_H
00073 #define VRS_OPENGL_SHAPEMATERIALGL_H
00074
00075 #include <vrs/color.h>
00076 #include <vrs/monoattribute.h>
00077
00078 namespace VRS {
00079
00080 class VRS_CORE_API ShapeMaterialGL : public MonoAttribute {
00081 public:
00082 enum Side { Front = 0, Back = 1 };
00083 VRS_SERIALIZABLE_CLASS_ENUM(Side);
00084
00085 enum MaterialComponent { Emission = 0, Ambient = 1, Diffuse = 2, AmbientAndDiffuse = 3, Specular = 4 };
00086 VRS_SERIALIZABLE_CLASS_ENUM(MaterialComponent);
00087
00088 ShapeMaterialGL(
00089 const Color& perVertexColor = Color(0.5),
00090 const Color& specular = Color(0.5),
00091 double shininess = 115.0,
00092 MaterialComponent perVertexColorMapping = ShapeMaterialGL::AmbientAndDiffuse,
00093 const Color& ambient = Color(0.2),
00094 const Color& diffuse = Color(0.5),
00095 const Color& emission = Color(0.0),
00096 bool distinguishSides = false,
00097 bool enablePerVertexMaterial = true
00098 );
00111 bool operator==(const ShapeMaterialGL& other) const;
00112
00113 void setPerVertexColor(const Color&, Side = ShapeMaterialGL::Front);
00114 Color getPerVertexColor(Side = ShapeMaterialGL::Front) const;
00124 void setAmbient(const Color&, Side = ShapeMaterialGL::Front);
00125 Color getAmbient(Side = ShapeMaterialGL::Front) const;
00127
00128 void setDiffuse(const Color&, Side = ShapeMaterialGL::Front);
00129 Color getDiffuse(Side = ShapeMaterialGL::Front) const;
00131
00132 void setSpecular(const Color&, Side = ShapeMaterialGL::Front);
00133 Color getSpecular(Side = ShapeMaterialGL::Front) const;
00135
00136 void setShininess(double, Side = ShapeMaterialGL::Front);
00137 double getShininess(Side = ShapeMaterialGL::Front) const;
00139
00141 void setEmission(const Color&, Side = ShapeMaterialGL::Front);
00142 Color getEmission(Side = ShapeMaterialGL::Front) const;
00144
00145 void setVertexColorMapping(MaterialComponent, Side = ShapeMaterialGL::Front);
00146 MaterialComponent getVertexColorMapping(Side = ShapeMaterialGL::Front) const;
00155 void setDistinguishSides(bool onOff);
00156 bool getDistinguishSides() const;
00166 bool isTransparent() const;
00170 void enablePerVertexColoring(bool enable=true);
00174 bool isPerVertexColoringEnabled () const;
00177 VRS_TYPEINFO(ShapeMaterialGL, MonoAttribute);
00178 VRS_SERIALIZABLE(ShapeMaterialGL);
00179
00180 private:
00181 Color m_perVertexColor[2];
00182
00183 Color m_ambient[2];
00184 Color m_diffuse[2];
00185 Color m_specular[2];
00186 double m_shininess[2];
00187 Color m_emission[2];
00188
00189 MaterialComponent m_colorMapping[2];
00190
00191 bool m_distinguishSides;
00192 bool m_enablePerVertexColoring;
00193 };
00194
00195 inline Color ShapeMaterialGL::getPerVertexColor(ShapeMaterialGL::Side side) const {
00196 return m_perVertexColor[m_distinguishSides ? side : Front];
00197 }
00198
00199 inline Color ShapeMaterialGL::getAmbient(ShapeMaterialGL::Side side) const {
00200 return m_ambient[m_distinguishSides ? side : Front];
00201 }
00202
00203 inline Color ShapeMaterialGL::getDiffuse(ShapeMaterialGL::Side side) const {
00204 return m_diffuse[m_distinguishSides ? side : Front];
00205 }
00206
00207 inline Color ShapeMaterialGL::getSpecular(ShapeMaterialGL::Side side) const {
00208 return m_specular[m_distinguishSides ? side : Front];
00209 }
00210
00211 inline double ShapeMaterialGL::getShininess(ShapeMaterialGL::Side side) const {
00212 return m_shininess[m_distinguishSides ? side : Front];
00213 }
00214
00215 inline Color ShapeMaterialGL::getEmission(ShapeMaterialGL::Side side) const {
00216 return m_emission[m_distinguishSides ? side : Front];
00217 }
00218
00219 inline ShapeMaterialGL::MaterialComponent ShapeMaterialGL::getVertexColorMapping(ShapeMaterialGL::Side side) const {
00220 return m_colorMapping[m_distinguishSides ? side : Front];
00221 }
00222
00223 inline bool ShapeMaterialGL::getDistinguishSides() const {
00224 return m_distinguishSides;
00225 }
00226
00227 inline bool ShapeMaterialGL::isPerVertexColoringEnabled () const {
00228 return m_enablePerVertexColoring;
00229 }
00230
00231
00232 }
00233
00234 #endif // VRS_OPENGL_SHAPEMATERIALGL_H