Free Electron
DrawMode.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __draw_DrawMode_h__
8 #define __draw_DrawMode_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Configuration for rendering such as line width and backface culling
17 
18  @ingroup draw
19 
20  An instance of a DrawMode is shared between all draw operations that
21  occur while it is the current DrawMode to a DrawI.
22  Changing a DrawMode at any time can affect all elements that are
23  associated with that DrawMode.
24 
25  It is intended for these modes to be configured and left alone prior
26  to being used. They are not an indirect interface extension to DrawI.
27 
28  The DrawMode is an optimization for cached rendering. Without them,
29  either every draw operation would have to cache an entire drawing
30  state or there would be an extraordinary amount of cross checking
31  to match up coincidentally identical states.
32 *//***************************************************************************/
33 class FE_DL_EXPORT DrawMode: public Counted
34 {
35  public:
36 
37  /** @brief Rendering schemes that an an
38  implementation @em may recognize
39 
40  Not all methods may be available in a
41  particular situation. */
42  enum DrawStyle
43  {
44  e_defaultStyle,
45  e_pointCloud,
46  e_wireframe,
47  e_outline,
48  e_solid,
49  e_edgedSolid,
50  e_foreshadow,
51  e_ghost,
52  e_drawStyleCount
53  };
54 
55  enum Coloring
56  {
57  e_color,
58  e_normal,
59  e_tangent,
60  e_uv,
61  e_partition,
62  e_coloringCount
63  };
64 
65  DrawMode(void):
66  m_textureImageID(-1),
67  m_drawStyle(e_defaultStyle),
68  m_coloring(e_color),
69  m_layer(0),
70  m_pointSize(1.0f),
71  m_lineWidth(1.0f),
72  m_refinement(0),
73  m_antialias(FALSE),
74  m_frontfaceCulling(FALSE),
75  m_backfaceCulling(TRUE),
76  m_twoSidedLighting(FALSE),
77  m_zBuffering(TRUE),
78  m_lit(TRUE),
79  m_shadows(FALSE),
80  m_uvSpace(FALSE)
81  { setName("DrawMode"); }
82 
83  void copy(sp<DrawMode> a_spDrawMode)
84  {
85  m_spTextureImage=a_spDrawMode->m_spTextureImage;
86  m_textureImageID=a_spDrawMode->m_textureImageID;
87  m_drawStyle=a_spDrawMode->m_drawStyle;
88  m_coloring=a_spDrawMode->m_coloring;
89  m_group=a_spDrawMode->m_group;
90  m_layer=a_spDrawMode->m_layer;
91  m_pointSize=a_spDrawMode->m_pointSize;
92  m_lineWidth=a_spDrawMode->m_lineWidth;
93  m_refinement=a_spDrawMode->m_refinement;
94  m_antialias=a_spDrawMode->m_antialias;
95  m_frontfaceCulling=a_spDrawMode->m_frontfaceCulling;
96  m_backfaceCulling=a_spDrawMode->m_backfaceCulling;
97  m_twoSidedLighting=a_spDrawMode->m_twoSidedLighting;
98  m_zBuffering=a_spDrawMode->m_zBuffering;
99  m_lit=a_spDrawMode->m_lit;
100  m_shadows=a_spDrawMode->m_shadows;
101  m_uvSpace=a_spDrawMode->m_uvSpace;
102  }
103 
104  /// @brief Set raster for texture mapping
106  { m_spTextureImage=spImageI; }
107 
108  /// @brief Get raster for texture mapping
110  { return m_spTextureImage; }
111 
112  /** @brief Set raster for texture mapping
113 
114  An id less than zero indicates to just use the
115  currently selected image id for the ImageI.
116  */
117  void setTextureImageID(I32 a_imageId)
118  { m_textureImageID=a_imageId; }
119 
120  /// @brief Get raster for texture mapping
121  I32 textureImageID(void) const
122  { return m_textureImageID; }
123 
124  /// @brief Set rendering scheme (see DrawStyle)
125  void setDrawStyle(DrawStyle style) { m_drawStyle=style; }
126 
127  /// @brief Get rendering scheme (see DrawStyle)
128  DrawStyle drawStyle(void) const { return m_drawStyle; }
129 
130  /// @brief Set color source (see Coloring)
131  void setColoring(Coloring coloring) { m_coloring=coloring; }
132 
133  /// @brief Get color source (see Coloring)
134  Coloring coloring(void) const { return m_coloring; }
135 
136  /// @brief Set named group
137  void setGroup(String a_group) { m_group=a_group; }
138 
139  /// @brief Get named group
140  String group(void) const { return m_group; }
141 
142  /// @brief Set rendering ordering (highest last)
143  void setLayer(I32 set) { m_layer=set; }
144 
145  /// @brief Get rendering ordering (highest last)
146  I32 layer(void) const { return m_layer; }
147 
148  /// @brief Set diameter of all following drawn points
149  void setPointSize(Real pixels)
150  { m_pointSize=pixels; }
151 
152  /// @brief Get diameter of all following drawn points
153  Real pointSize(void) const
154  { return m_pointSize; }
155 
156  /// @brief Set width of all following drawn lines
157  void setLineWidth(Real pixels)
158  { m_lineWidth=pixels; }
159 
160  /// @brief Get width of all following drawn lines
161  Real lineWidth(void) const
162  { return m_lineWidth; }
163 
164  /// @brief Set subvision level of all following drawn polys
165  void setRefinement(I32 level)
166  { m_refinement=level; }
167 
168  /// @brief Get subvision level of all following drawn polys
169  I32 refinement(void) const
170  { return m_refinement; }
171 
172  /// @brief Set rasterization anti-aliasing
173  void setAntialias(BWORD antialias)
174  { m_antialias=antialias; }
175 
176  /// @brief Get whether anti-aliasing is used
177  BWORD antialias(void) const
178  { return m_antialias; }
179 
180  /// @brief Set whether frontfaces are removed
181  void setFrontfaceCulling(BWORD frontfaceCulling)
182  { m_frontfaceCulling=frontfaceCulling; }
183 
184  /// @brief Get whether frontfaces are removed
185  BWORD frontfaceCulling(void) const
186  { return m_frontfaceCulling; }
187 
188  /// @brief Set whether backfaces are removed
189  void setBackfaceCulling(BWORD backfaceCulling)
190  { m_backfaceCulling=backfaceCulling; }
191 
192  /// @brief Get whether backfaces are removed
193  BWORD backfaceCulling(void) const
194  { return m_backfaceCulling; }
195 
196  /** @brief Set whether backfaces have an independent
197  material */
198  void setTwoSidedLighting(BWORD twoSidedLighting)
199  { m_twoSidedLighting=twoSidedLighting; }
200 
201  /** @brief Get whether backfaces have an independent
202  material */
203  BWORD twoSidedLighting(void) const
204  { return m_twoSidedLighting; }
205 
206  /// @brief Set whether z-buffering is used
207  void setZBuffering(BWORD zBuffering)
208  { m_zBuffering=zBuffering; }
209 
210  /// @brief Get whether z-buffering is used
211  BWORD zBuffering(void) const
212  { return m_zBuffering; }
213 
214  /** @brief Set lit */
215  void setLit(BWORD lit)
216  { m_lit=lit; }
217 
218  /// @brief Get whether lit
219  BWORD lit(void) const
220  { return m_lit; }
221 
222  /** @brief Set shadows */
223  void setShadows(BWORD shadows)
224  { m_shadows=shadows; }
225 
226  /// @brief Get whether shadows
227  BWORD shadows(void) const
228  { return m_shadows; }
229 
230  /** @brief Set whether in UV space */
231  void setUvSpace(BWORD uvSpace)
232  { m_uvSpace=uvSpace; }
233 
234  /// @brief Get whether in UV space
235  BWORD uvSpace(void) const
236  { return m_uvSpace; }
237 
238 static DrawStyle stringToStyle(const String &a_styleName);
239 
240 static Coloring stringToColoring(const String &a_coloringName);
241 
242  private:
243 
244  sp<ImageI> m_spTextureImage;
245  I32 m_textureImageID;
246  DrawStyle m_drawStyle;
247  Coloring m_coloring;
248  String m_group;
249  I32 m_layer;
250  Real m_pointSize;
251  Real m_lineWidth;
252  I32 m_refinement;
253  BWORD m_antialias;
254  BWORD m_frontfaceCulling;
255  BWORD m_backfaceCulling;
256  BWORD m_twoSidedLighting;
257  BWORD m_zBuffering;
258  BWORD m_lit;
259  BWORD m_shadows;
260  BWORD m_uvSpace;
261 };
262 
263 static char DrawStyleText[DrawMode::e_drawStyleCount][32] =
264 {
265  "default",
266  "pointCloud",
267  "wireframe",
268  "outline",
269  "solid",
270  "edgedSolid",
271  "foreshadow",
272  "ghost"
273 };
274 
275 static char ColoringText[DrawMode::e_coloringCount][32] =
276 {
277  "color",
278  "normal",
279  "tangent",
280  "uv",
281  "partition"
282 };
283 
284 inline DrawMode::DrawStyle DrawMode::stringToStyle(const String &a_styleName)
285 {
286  if(a_styleName == "pointCloud") { return e_pointCloud; }
287  if(a_styleName == "wireframe") { return e_wireframe; }
288  if(a_styleName == "outline") { return e_outline; }
289  if(a_styleName == "edgedSolid") { return e_edgedSolid; }
290  if(a_styleName == "solid") { return e_solid; }
291  if(a_styleName == "foreshadow") { return e_foreshadow; }
292  if(a_styleName == "ghost") { return e_ghost; }
293 
294  return e_defaultStyle;
295 }
296 
297 inline DrawMode::Coloring DrawMode::stringToColoring(
298  const String &a_coloringName)
299 {
300  if(a_coloringName == "normal") { return e_normal; }
301  if(a_coloringName == "tangent") { return e_tangent; }
302  if(a_coloringName == "uv") { return e_uv; }
303  if(a_coloringName == "partition" ||
304  a_coloringName == "part") { return e_partition; }
305 
306  return e_color;
307 }
308 
309 } /* namespace ext */
310 } /* namespace fe */
311 
312 namespace fe
313 {
314 
315 inline String print(ext::DrawMode::DrawStyle a_drawStyle)
316 {
317  return ext::DrawStyleText[a_drawStyle%ext::DrawMode::e_drawStyleCount];
318 }
319 
320 inline String print(ext::DrawMode::Coloring a_coloring)
321 {
322  return ext::ColoringText[a_coloring%ext::DrawMode::e_coloringCount];
323 }
324 
325 inline String print(const sp<ext::DrawMode> spDrawMode)
326 {
327  String s;
328  s.sPrintf("style \"%s\" coloring \"%s\" layer %d pointSize %g lineWidth %g"
329  " refinement %d\n aa %d front %d back %d twoSided %d z %d lit %d"
330  " shadows %d uv %d texture %p group \"%s\"",
331 
332  ext::DrawStyleText[spDrawMode->drawStyle()%
333  ext::DrawMode::e_drawStyleCount],
334 
335  ext::ColoringText[spDrawMode->coloring()%
336  ext::DrawMode::e_coloringCount],
337 
338  spDrawMode->layer(),
339  spDrawMode->pointSize(),
340  spDrawMode->lineWidth(),
341  spDrawMode->refinement(),
342  spDrawMode->antialias(),
343  spDrawMode->frontfaceCulling(),
344  spDrawMode->backfaceCulling(),
345  spDrawMode->twoSidedLighting(),
346  spDrawMode->zBuffering(),
347  spDrawMode->lit(),
348  spDrawMode->shadows(),
349  spDrawMode->uvSpace(),
350  spDrawMode->textureImage().raw(),
351  spDrawMode->group().c_str());
352  return s;
353 }
354 
355 } /* namespace fe */
356 
357 #endif /* __draw_DrawMode_h__ */
BWORD zBuffering(void) const
Get whether z-buffering is used.
Definition: DrawMode.h:211
void setFrontfaceCulling(BWORD frontfaceCulling)
Set whether frontfaces are removed.
Definition: DrawMode.h:181
BWORD shadows(void) const
Get whether shadows.
Definition: DrawMode.h:227
BWORD backfaceCulling(void) const
Get whether backfaces are removed.
Definition: DrawMode.h:193
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Real pointSize(void) const
Get diameter of all following drawn points.
Definition: DrawMode.h:153
String group(void) const
Get named group.
Definition: DrawMode.h:140
kernel
Definition: namespace.dox:3
Configuration for rendering such as line width and backface culling.
Definition: DrawMode.h:33
Real lineWidth(void) const
Get width of all following drawn lines.
Definition: DrawMode.h:161
void setLineWidth(Real pixels)
Set width of all following drawn lines.
Definition: DrawMode.h:157
void setShadows(BWORD shadows)
Set shadows.
Definition: DrawMode.h:223
void setTextureImageID(I32 a_imageId)
Set raster for texture mapping.
Definition: DrawMode.h:117
void setTextureImage(sp< ImageI > spImageI)
Set raster for texture mapping.
Definition: DrawMode.h:105
void setBackfaceCulling(BWORD backfaceCulling)
Set whether backfaces are removed.
Definition: DrawMode.h:189
I32 refinement(void) const
Get subvision level of all following drawn polys.
Definition: DrawMode.h:169
void setAntialias(BWORD antialias)
Set rasterization anti-aliasing.
Definition: DrawMode.h:173
void setRefinement(I32 level)
Set subvision level of all following drawn polys.
Definition: DrawMode.h:165
void setGroup(String a_group)
Set named group.
Definition: DrawMode.h:137
BWORD frontfaceCulling(void) const
Get whether frontfaces are removed.
Definition: DrawMode.h:185
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
Automatically reference-counted string container.
Definition: String.h:128
void setDrawStyle(DrawStyle style)
Set rendering scheme (see DrawStyle)
Definition: DrawMode.h:125
BWORD uvSpace(void) const
Get whether in UV space.
Definition: DrawMode.h:235
void setLit(BWORD lit)
Set lit.
Definition: DrawMode.h:215
void setTwoSidedLighting(BWORD twoSidedLighting)
Set whether backfaces have an independent material.
Definition: DrawMode.h:198
void setLayer(I32 set)
Set rendering ordering (highest last)
Definition: DrawMode.h:143
BWORD antialias(void) const
Get whether anti-aliasing is used.
Definition: DrawMode.h:177
sp< ImageI > textureImage(void) const
Get raster for texture mapping.
Definition: DrawMode.h:109
DrawStyle drawStyle(void) const
Get rendering scheme (see DrawStyle)
Definition: DrawMode.h:128
DrawStyle
Rendering schemes that an an implementation may recognize.
Definition: DrawMode.h:42
void setColoring(Coloring coloring)
Set color source (see Coloring)
Definition: DrawMode.h:131
Coloring coloring(void) const
Get color source (see Coloring)
Definition: DrawMode.h:134
I32 textureImageID(void) const
Get raster for texture mapping.
Definition: DrawMode.h:121
I32 layer(void) const
Get rendering ordering (highest last)
Definition: DrawMode.h:146
BWORD twoSidedLighting(void) const
Get whether backfaces have an independent material.
Definition: DrawMode.h:203
void setZBuffering(BWORD zBuffering)
Set whether z-buffering is used.
Definition: DrawMode.h:207
BWORD lit(void) const
Get whether lit.
Definition: DrawMode.h:219
void setUvSpace(BWORD uvSpace)
Set whether in UV space.
Definition: DrawMode.h:231
void setPointSize(Real pixels)
Set diameter of all following drawn points.
Definition: DrawMode.h:149