anatomist  5.1.2
3D neuroimaging data viewer
Shader.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANA_SURFACE_SHADER_H
36 #define ANA_SURFACE_SHADER_H
37 
38 #include <iostream>
39 
40 namespace anatomist
41 {
42  struct ViewState;
43  class GLComponent;
44  class AObject;
45  class GLMObject;
46  class ATexSurface;
47  class AVolumeBase;
48 
49  class Shader
50  {
51  public:
53  struct LightingModel_ {
54  enum EnumType
55  {
57  None,
62  };
63  };
66 
69  enum EnumType
70  {
76  Phong
77  };
78  };
81 
83  struct ColoringModel_ {
84  enum EnumType
85  {
91  Direction
92  };
93  };
96 
98  struct MaterialModel_ {
99  enum EnumType
100  {
104  OrenNayar
105  };
106  };
109 
111  Shader(const Shader &);
112 
113  virtual ~Shader();
114 
115  inline void setLightingModel(LightingModel m);
117  inline void setColoringModel(ColoringModel m);
118  inline void setMaterialModel(MaterialModel m);
119  inline void setModels(LightingModel lm, InterpolationModel im,
121 
122  inline LightingModel getLightingModel() const;
124  inline ColoringModel getColoringModel() const;
125  inline MaterialModel getMaterialModel() const;
126 
127 
128  // is shader supported by the system ?
129  static bool isSupported(void);
130  // is shader activated by default in anatomist ?
131  static bool getAnatomistDefaultBehaviour(void);
132  // is shader currently activated ?
133  static bool isActivated(void);
134  // is shader-based pipeline used by default in object rendering ?
135  static bool isUsedByDefault(void);
136 
137  // bind current shader on the givien GL component
138  void bind(const GLComponent &glc, const ViewState & state);
139  // release the current shader (get back on the default OpenGL pipeline)
140  void release(void);
141  // reload current shader
142  void reload(void);
143  // enable shader
144  void enable(void);
145  // disable shader
146  void disable(void);
147  // lazy shader loading
148  void load_if_needed(void);
149 
150  //set shader parameters for several known anatomist types
151  void setShaderParameters(const GLComponent &obj, const ViewState & state) const;
152  void setShaderParameters(const GLMObject &obj, const ViewState & state) const;
153  void setShaderParameters(const AVolumeBase &obj, const ViewState & state) const;
154  void setShaderParameters(const ATexSurface &obj, const ViewState & state) const;
155 
157  friend std::ostream &operator << (std::ostream &,
158  const anatomist::Shader &);
159  bool operator != ( const Shader & ) const;
160  bool operator == ( const Shader & mat ) const
161  { return( !operator != ( mat ) ); }
162 
163 
164  static void enable_all(void);
165  static void disable_all(void);
166 
167  protected:
168  // force shader loading
169  void load(void);
170  static bool _isSupported(void);
171 
176 
177  private:
178  struct Private;
179  Private *d;
180  };
181 
182  std::ostream &operator << (std::ostream &, const anatomist::Shader &);
183 
185  {
186  _lighting_model = m;
187  }
188 
190  {
192  }
193 
195  {
196  _coloring_model = m;
197  }
198 
200  {
201  _material_model = m;
202  }
203 
208  {
209  _lighting_model = lm;
211  _coloring_model = cm;
212  _material_model = mm;
213  }
214 
216  {
217  return _lighting_model;
218  }
219 
221  {
222  return _interpolation_model;
223  }
224 
226  {
227  return _coloring_model;
228  }
229 
231  {
232  return _material_model;
233  }
234 }
235 
236 #endif
Fusion object merging a triangulation and a texture object.
Definition: texsurface.h:100
VolumeBase object : use for generic dynamic_cast of all AVolume<T>, thus the visitor design pattern c...
Definition: Volume.h:54
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition: glcomponent.h:67
A Multi-object with OpenGL rendering capabilities.
Definition: glmobject.h:50
static bool isUsedByDefault(void)
MaterialModel _material_model
Definition: Shader.h:175
void disable(void)
Shader(const Shader &)
void release(void)
static bool isActivated(void)
static bool isSupported(void)
void setShaderParameters(const GLComponent &obj, const ViewState &state) const
void setShaderParameters(const AVolumeBase &obj, const ViewState &state) const
static void enable_all(void)
bool operator==(const Shader &mat) const
Definition: Shader.h:160
void load_if_needed(void)
friend std::ostream & operator<<(std::ostream &, const anatomist::Shader &)
LightingModel _lighting_model
Definition: Shader.h:172
static MaterialModel_::EnumType DefaultMaterialModel
Definition: Shader.h:108
LightingModel_::EnumType LightingModel
Definition: Shader.h:64
InterpolationModel _interpolation_model
Definition: Shader.h:173
ColoringModel getColoringModel() const
Definition: Shader.h:225
void setColoringModel(ColoringModel m)
Definition: Shader.h:194
static ColoringModel_::EnumType DefaultColoringModel
Definition: Shader.h:95
static LightingModel_::EnumType DefaultLightingModel
Definition: Shader.h:65
static void disable_all(void)
void setInterpolationModel(InterpolationModel m)
Definition: Shader.h:189
MaterialModel_::EnumType MaterialModel
Definition: Shader.h:107
static bool getAnatomistDefaultBehaviour(void)
InterpolationModel_::EnumType InterpolationModel
Definition: Shader.h:79
void enable(void)
void setShaderParameters(const ATexSurface &obj, const ViewState &state) const
void reload(void)
ColoringModel_::EnumType ColoringModel
Definition: Shader.h:94
ColoringModel _coloring_model
Definition: Shader.h:174
InterpolationModel getInterpolationModel() const
Definition: Shader.h:220
static InterpolationModel_::EnumType DefaultInterpolationModel
Definition: Shader.h:80
void setLightingModel(LightingModel m)
Definition: Shader.h:184
MaterialModel getMaterialModel() const
Definition: Shader.h:230
void setModels(LightingModel lm, InterpolationModel im, ColoringModel cm, MaterialModel mm)
Definition: Shader.h:204
void setShaderParameters(const GLMObject &obj, const ViewState &state) const
LightingModel getLightingModel() const
Definition: Shader.h:215
bool operator!=(const Shader &) const
Shader & operator=(const Shader &)
void bind(const GLComponent &glc, const ViewState &state)
void setMaterialModel(MaterialModel m)
Definition: Shader.h:199
static bool _isSupported(void)
std::ostream & operator<<(std::ostream &, const anatomist::Material &)
Coloring model flags.
Definition: Shader.h:83
@ Material
Material model.
Definition: Shader.h:87
@ Direction
Direction model.
Definition: Shader.h:91
Interpolation model flags.
Definition: Shader.h:68
Light model flags.
Definition: Shader.h:53
Material model flags.
Definition: Shader.h:98
@ OrenNayar
Oren-Nayar model.
Definition: Shader.h:104
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:67