Free Electron
DrawCached.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_DrawCached_h__
8 #define __draw_DrawCached_h__
9 
10 #define DCH_MAX_VERTS 512
11 
12 namespace fe
13 {
14 namespace ext
15 {
16 
17 /**************************************************************************//**
18  @brief Delayed rendering to another DrawI, presumably an immediate one
19 
20  @ingroup draw
21 
22  Opportunites exist to use the cache for sorting, optimization,
23  and off-threading.
24 *//***************************************************************************/
25 class FE_DL_EXPORT DrawCached:
26  public DrawCommon,
27  public Initialize<DrawCached>
28 {
29  private:
30 
31  class Buffer
32  {
33  public:
34  SpatialVector m_pVertex[DCH_MAX_VERTS];
35  SpatialVector m_pNormal[DCH_MAX_VERTS];
36  Color m_pColor[DCH_MAX_VERTS];
37  Real m_pRadius[DCH_MAX_VERTS];
38  Vector2 m_pTexture[DCH_MAX_VERTS];
39  Vector3i m_pElement[DCH_MAX_VERTS];
40 #if FE_DOUBLE_REAL
41  U32 m_pFiller[DCH_MAX_VERTS];
42 #endif
43  };
44 
45  //* byte-wise same size as m_pTexture (for blind cast)
46  class CylinderOverlay
47  {
48  public:
49  Real m_pBaseScale[DCH_MAX_VERTS];
50  U32 m_pSlices[DCH_MAX_VERTS];
51  };
52 
53  class FE_DL_EXPORT Command
54  {
55  public:
56 
57  enum Instruction
58  {
59  e_null,
60  e_points,
61  e_lines,
62  e_triangles,
63  e_rectangles,
64  e_sphere,
65  e_cylinder,
66  e_cylinders,
67  e_raster,
68  e_drawable,
69  e_text,
70  e_max
71  };
72 
73  Command(void):
74  m_scissoring(FALSE),
75  m_projection(ViewI::e_current),
76  m_instruction(e_null),
77  m_stripMode(DrawI::e_discrete),
78  m_multicolor(FALSE),
79  m_multiradius(FALSE),
80  m_vertices(0),
81  m_elementCount(0),
82  m_pVertex(NULL),
83  m_pNormal(NULL),
84  m_pColor(NULL),
85  m_pRadius(NULL),
86  m_pTexture(NULL),
87  m_pElement(NULL)
88  {
89  m_pVertex=m_localBuffer.m_pVertex;
90  m_pNormal=m_localBuffer.m_pNormal;
91  m_pColor=m_localBuffer.m_pColor;
92  m_pTexture=m_localBuffer.m_pTexture;
93  m_pElement=m_localBuffer.m_pElement;
94  }
95 
96  Command(const Command& rCommand)
97  { operator=(rCommand); }
98 
99  Command& operator=(const Command& rCommand);
100 
101  I32 layer(void) const
102  { return m_spDrawMode.isValid()?
103  m_spDrawMode->layer(): -1; }
104 
105  BWORD m_scissoring;
106  Box2i m_scissor;
107  Box2i m_viewport;
108  sp<CameraEditable> m_spCameraEditable;
109  sp<DrawMode> m_spDrawMode;
110  sp<DrawBufferI> m_spDrawBuffer;
111  sp<ImageI> m_spImageI;
112  cp<DrawableI> m_cpDrawableI;
113  ViewI::Projection m_projection;
114  Instruction m_instruction;
115  StripMode m_stripMode;
116  BWORD m_multicolor;
117  BWORD m_multiradius;
118  U32 m_vertices;
119  U32 m_elementCount;
120 
121  SpatialVector* m_pVertex;
122  SpatialVector* m_pNormal;
123  Color* m_pColor;
124  Real* m_pRadius;
125  Vector2* m_pTexture;
126  Vector3i* m_pElement;
127  const Array<I32>* m_pVertexMap;
128  const Array<I32>* m_pHullPointMap;
129  const Array<Vector4i>* m_pHullFacePoint;
130 
131  //* TEMP should use variable size pool
132  Buffer m_localBuffer;
133  };
134 
135  class CommandQueue: public Array<Command>
136  {
137  public:
138  CommandQueue(void):
139  m_commands(0)
140  {
141  reserve(256);
142  }
143 
144  Command& access(U32 index)
145  {
146  if(index>=size())
147  {
148  resize(index+1);
149  }
150  return Array<Command>::operator[](index);
151  }
152 
153  U32 m_commands;
154  };
155 
156  public:
157  DrawCached();
158 virtual ~DrawCached();
159 
160  void initialize(void);
161 
162 virtual void flush(void);
163 virtual void flushLive(void);
164 virtual void clearInput(void);
165 virtual BWORD empty(void) const;
166 
167 virtual BWORD isDirect(void) const
168  { return m_spDrawChain.isValid() &&
169  m_spDrawChain->isDirect(); }
170 
171 virtual sp<FontI> font(void)
172  { if(!prepareChain()) sp<FontI>(NULL);
173  return m_spDrawChain->font(); }
174 
175 //~virtual void setFontBase(U32 index)
176 //~ { if(!prepareChain()) return;
177 //~ m_spDrawChain->setFontBase(index); }
178 //~virtual I32 fontHeight(I32* pAscent,I32* pDescent)
179 //~ { if(!prepareChain()) return 1;
180 //~ return m_spDrawChain->fontHeight(pAscent,pDescent); }
181 //~virtual I32 pixelWidth(String string)
182 //~ { if(!prepareChain()) return 1;
183 //~ return m_spDrawChain->pixelWidth(string); }
184 
185 virtual Real multiplication(void)
186  { if(!prepareChain()) return Real(1);
187  return m_spDrawChain->multiplication(); }
188 
190 
191 virtual void drawPoints(const SpatialVector *vertex,
192  const SpatialVector *normal,U32 vertices,
193  BWORD multicolor,const Color *color,
194  sp<DrawBufferI> spDrawBuffer);
195 
196  using DrawCommon::drawLines;
197 
198 virtual void drawLines(const SpatialVector *vertex,
199  const SpatialVector *normal,U32 vertices,
200  StripMode strip,
201  BWORD multicolor,const Color *color,
202  BWORD multiradius,const Real *radius,
203  const Vector3i *element,U32 elementCount,
204  sp<DrawBufferI> spDrawBuffer);
205 
207 
208 virtual void drawTriangles(const SpatialVector *vertex,
209  const SpatialVector *normal,
210  const Vector2 *texture,U32 vertices,
211  StripMode strip,BWORD multicolor,
212  const Color *color,
213  const Array<I32>* vertexMap,
214  const Array<I32>* hullPointMap,
215  const Array<Vector4i>* hullFacePoint,
216  sp<DrawBufferI> spDrawBuffer);
217 
218 virtual void drawRectangles(const SpatialVector *vertex,U32 vertices,
219  BWORD multicolor,const Color *color);
220 
221 virtual void drawSphere(const SpatialTransform &transform,
222  const SpatialVector *scale,const Color &color);
223 
225 
226 virtual void drawCylinder(const SpatialTransform &transform,
227  const SpatialVector *scale,
228  Real baseScale,const Color &color,U32 slices);
229 virtual void drawCylinders(const SpatialTransform* transform,
230  const SpatialVector* scale,const Real *baseScale,
231  const U32* slices,U32 cylinders,
232  BWORD multicolor,const Color* color);
233 
234  using DrawCommon::draw;
235 
236 virtual void draw(cp<DrawableI> cpDrawableI,const Color* color,
237  sp<DrawBufferI> spDrawBuffer);
238 
239  using DrawCommon::drawTransformed;
240 
241 virtual void drawTransformed(const SpatialTransform &transform,
242  cp<DrawableI> cpDrawableI,const Color* color,
243  sp<DrawBufferI> spDrawBuffer);
244 
245 virtual void drawRaster(sp<ImageI> spImageI,
246  const SpatialVector& location);
247 
248 virtual sp<DrawBufferI> createBuffer(void)
249  { return m_spDrawChain.isValid()?
250  m_spDrawChain->createBuffer():
251  sp<DrawBufferI>(NULL); }
252 
253 virtual void drawAlignedText(const SpatialVector &location,
254  const String text,const Color &color);
255 
256 virtual void setDrawChain(sp<DrawI> a_spDrawI)
257  { m_spDrawChain=a_spDrawI; }
258 virtual sp<DrawI> drawChain(void)
259  { return m_spDrawChain; }
260 
261  protected:
262 
263  BWORD prepareChain(void);
264  void drawOutput(U32 queue,BWORD a_clearQueue);
265  void clearCameraMap(void);
266 
267  sp<DrawI> m_spDrawChain;
268  U32 m_inputQueue;
269  U32 m_outputQueue;
270  U32 m_queues;
271 
272  private:
273 
274  void drawGeometry(Command::Instruction instruction,
275  const SpatialVector *vertex,
276  const SpatialVector *normal,
277  const Vector2 *texture,
278  const Real* auxReal,const U32* auxU32,
279  U32 vertices,StripMode strip,
280  BWORD multicolor,const Color *color,
281  BWORD multiradius,const Real *radius,
282  const Array<I32>* vertexMap,
283  const Array<I32>* hullPointMap,
284  const Array<Vector4i>* hullFacePoint,
285  const Vector3i *element,U32 elementCount,
286  sp<DrawBufferI> spDrawBuffer);
287 
288  void adoptView(DrawCached::Command& rCommand,
289  sp<ViewI> spViewI);
290 
291  U32 m_grain[Command::e_max];
292  U32 m_oversize[Command::e_max];
293 
294  CommandQueue* m_pCommandQueue;
295 
296  std::map< sp<CameraEditable>, sp<CameraEditable> > m_cameraMap;
297 };
298 
299 } /* namespace ext */
300 } /* namespace fe */
301 
302 #endif /* __draw_DrawCached_h__ */
virtual void drawPoints(const SpatialVector *vertex, const SpatialVector *normal, U32 vertices, BWORD multicolor, const Color *color)
Draw points vertex[vertices].
Definition: DrawCommon.cc:222
Drawing functions not specific to the graphics language.
Definition: DrawCommon.h:32
kernel
Definition: namespace.dox:3
StripMode
Format of vertices for tri-stripping.
Definition: DrawI.h:26
virtual void drawTriangles(const SpatialVector *vertex, const SpatialVector *normal, const Vector2 *texture, U32 vertices, StripMode strip, BWORD multicolor, const Color *color)
Draw triangles.
Definition: DrawCommon.cc:257
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
virtual BWORD isDirect(void) const
Returns TRUE is display is local and rendered directly.
Definition: DrawCached.h:167
virtual void draw(cp< DrawableI > cpDrawableI, const Color *color)
Draw DrawableI.
Definition: DrawCommon.cc:84
Special vector for color (RGBA)
Definition: Color.h:21
Delayed rendering to another DrawI, presumably an immediate one.
Definition: DrawCached.h:25
virtual void drawCylinder(const SpatialTransform &transform, const SpatialVector *scale, Real baseScale, const Color &color, U32 slices)
Draw a transformed cylinder or cone.
Definition: DrawCommon.cc:792
Automatically reference-counted string container.
Definition: String.h:128
virtual void drawLines(const SpatialVector *vertex, const SpatialVector *normal, U32 vertices, StripMode strip, BWORD multicolor, const Color *color)
Draw lines.
Definition: DrawCommon.cc:238
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Copy-On-Write shared pointer.
Definition: Protectable.h:93
virtual sp< FontI > font(void)
Get current font.
Definition: DrawCached.h:171
virtual Real multiplication(void)
Select the GL-specific index/handle.
Definition: DrawCached.h:185
virtual void setDrawChain(sp< DrawI > a_spDrawI)
Set next DrawI in a chain.
Definition: DrawCached.h:256