Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
VectorGraphics.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #include <vlVG/VectorGraphics.hpp>
33 
34 using namespace vl;
35 
36 //-----------------------------------------------------------------------------
38 {
39  mDefaultEffect = new Effect;
40  mDefaultEffect->shader()->enable(EN_BLEND);
41  mActors.setAutomaticDelete(false);
42 }
43 //-----------------------------------------------------------------------------
44 Actor* VectorGraphics::drawLine(double x1, double y1, double x2, double y2)
45 {
46  std::vector<dvec2> ln;
47  ln.push_back(dvec2(x1,y1));
48  ln.push_back(dvec2(x2,y2));
49  return drawLines(ln);
50 }
51 //-----------------------------------------------------------------------------
52 Actor* VectorGraphics::drawLines(const std::vector<dvec2>& ln)
53 {
54  // fill the vertex position array
55  ref<Geometry> geom = prepareGeometry(ln);
56  // generate texture coords
57  if (mState.mImage)
58  {
59  ref<ArrayFloat2> tex_array = new ArrayFloat2;
60  tex_array->resize(geom->vertexArray()->size());
61  float u1 = 1.0f / mState.mImage->width() * 0.5f;
62  float u2 = 1.0f - 1.0f / mState.mImage->width() * 0.5f;
63  for(size_t i=0; i<tex_array->size(); i+=2)
64  {
65  tex_array->at(i+0) = fvec2(u1, 0);
66  tex_array->at(i+1) = fvec2(u2, 0);
67  }
68  // generate geometry
69  geom->setTexCoordArray(0, tex_array.get());
70  }
71  // issue the primitive
72  geom->drawCalls().push_back( new DrawArrays(PT_LINES, 0, (int)ln.size()) );
73  // add the actor
74  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
75 }
76 //-----------------------------------------------------------------------------
77 Actor* VectorGraphics::drawLineStrip(const std::vector<dvec2>& ln)
78 {
79  // fill the vertex position array
80  ref<Geometry> geom = prepareGeometry(ln);
81  // generate texture coords
82  generateLinearTexCoords(geom.get());
83  // issue the primitive
84  geom->drawCalls().push_back( new DrawArrays(PT_LINE_STRIP, 0, (int)ln.size()) );
85  // add the actor
86  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
87 }
88 //-----------------------------------------------------------------------------
89 Actor* VectorGraphics::drawLineLoop(const std::vector<dvec2>& ln)
90 {
91  // fill the vertex position array
92  ref<Geometry> geom = prepareGeometry(ln);
93  // generate texture coords
94  generateLinearTexCoords(geom.get());
95  // issue the primitive
96  geom->drawCalls().push_back( new DrawArrays(PT_LINE_LOOP, 0, (int)ln.size()) );
97  // add the actor
98  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
99 }
100 //-----------------------------------------------------------------------------
101 Actor* VectorGraphics::fillPolygon(const std::vector<dvec2>& poly)
102 {
103  // fill the vertex position array
104  ref<Geometry> geom = prepareGeometryPolyToTriangles(poly);
105  // generate texture coords
106  generatePlanarTexCoords(geom.get(), poly);
107  // issue the primitive
108  geom->drawCalls().push_back( new DrawArrays(PT_TRIANGLES, 0, (int)geom->vertexArray()->size()) );
109  // add the actor
110  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
111 }
112 //-----------------------------------------------------------------------------
113 Actor* VectorGraphics::fillTriangles(const std::vector<dvec2>& triangles)
114 {
115  // fill the vertex position array
116  ref<Geometry> geom = prepareGeometry(triangles);
117  // generate texture coords
118  generatePlanarTexCoords(geom.get(), triangles);
119  // issue the primitive
120  geom->drawCalls().push_back( new DrawArrays(PT_TRIANGLES, 0, (int)triangles.size()) );
121  // add the actor
122  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
123 }
124 //-----------------------------------------------------------------------------
125 Actor* VectorGraphics::fillTriangleFan(const std::vector<dvec2>& fan)
126 {
127  // fill the vertex position array
128  ref<Geometry> geom = prepareGeometry(fan);
129  // generate texture coords
130  generatePlanarTexCoords(geom.get(), fan);
131  // issue the primitive
132  geom->drawCalls().push_back( new DrawArrays(PT_TRIANGLE_FAN, 0, (int)fan.size()) );
133  // add the actor
134  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
135 }
136 //-----------------------------------------------------------------------------
137 Actor* VectorGraphics::fillTriangleStrip(const std::vector<dvec2>& strip)
138 {
139  // fill the vertex position array
140  ref<Geometry> geom = prepareGeometry(strip);
141  // generate texture coords
142  generatePlanarTexCoords(geom.get(), strip);
143  // issue the primitive
144  geom->drawCalls().push_back( new DrawArrays(PT_TRIANGLE_STRIP, 0, (int)strip.size()) );
145  // add the actor
146  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
147 }
148 //-----------------------------------------------------------------------------
149 Actor* VectorGraphics::fillQuads(const std::vector<dvec2>& quads)
150 {
151  // fill the vertex position array
152  ref<Geometry> geom = prepareGeometry(quads);
153  // generate texture coords
154  generateQuadsTexCoords(geom.get(), quads);
155  // issue the primitive
156  geom->drawCalls().push_back( new DrawArrays(PT_QUADS, 0, (int)quads.size()) );
157  // add the actor
158  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
159 }
160 //-----------------------------------------------------------------------------
161 Actor* VectorGraphics::fillQuadStrip(const std::vector<dvec2>& quad_strip)
162 {
163  // fill the vertex position array
164  ref<Geometry> geom = prepareGeometry(quad_strip);
165  // generate texture coords
166  generatePlanarTexCoords(geom.get(), quad_strip);
167  // issue the primitive
168  geom->drawCalls().push_back( new DrawArrays(PT_QUAD_STRIP, 0, (int)quad_strip.size()) );
169  // add the actor
170  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
171 }
172 //-----------------------------------------------------------------------------
173 Actor* VectorGraphics::drawPoint(double x, double y)
174 {
175  std::vector<dvec2> pt;
176  pt.push_back(dvec2(x,y));
177  return drawPoints(pt);
178 }
179 //-----------------------------------------------------------------------------
180 Actor* VectorGraphics::drawPoints(const std::vector<dvec2>& pt)
181 {
182  // transform the points
183  ref<ArrayFloat3> pos_array = new ArrayFloat3;
184  pos_array->resize(pt.size());
185  // transform done using high precision
186  for(unsigned i=0; i<pt.size(); ++i)
187  {
188  pos_array->at(i) = (fvec3)(matrix() * dvec3(pt[i].x(), pt[i].y(), 0));
189  // needed for pixel/perfect rendering
190  if (mState.mPointSize % 2 == 0)
191  {
192  pos_array->at(i).s() += 0.5;
193  pos_array->at(i).t() += 0.5;
194  }
195  }
196  // generate geometry
197  ref< Geometry > geom = new Geometry;
198  geom->setVertexArray(pos_array.get());
199  geom->drawCalls().push_back( new DrawArrays(PT_POINTS, 0, (int)pos_array->size()) );
200  // add the actor
201  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
202 }
203 //-----------------------------------------------------------------------------
204 Actor* VectorGraphics::drawEllipse(double origx, double origy, double xaxis, double yaxis, int segments)
205 {
206  std::vector<dvec2> points;
207  points.resize(segments);
208  for(int i=0; i<segments; ++i)
209  {
210  double t = (double)i/(segments-1) * dPi * 2.0 + dPi * 0.5;
211  points[i] = dvec2(cos(t)*xaxis*0.5+origx, sin(t)*yaxis*0.5+origy);
212  }
213  return drawLineStrip(points);
214 }
215 //-----------------------------------------------------------------------------
216 Actor* VectorGraphics::fillEllipse(double origx, double origy, double xaxis, double yaxis, int segments)
217 {
218  std::vector<dvec2> points;
219  points.resize(segments);
220  for(int i=0; i<segments; ++i)
221  {
222  double t = (double)i/segments * dPi * 2.0 + dPi * 0.5;
223  points[i] = dvec2(cos(t)*xaxis*0.5+origx, sin(t)*yaxis*0.5+origy);
224  }
225  return fillPolygon(points);
226 }
227 //-----------------------------------------------------------------------------
228 Actor* VectorGraphics::drawQuad(double left, double bottom, double right, double top)
229 {
230  std::vector<dvec2> quad;
231  quad.push_back(dvec2(left,bottom));
232  quad.push_back(dvec2(left,top));
233  quad.push_back(dvec2(right,top));
234  quad.push_back(dvec2(right,bottom));
235  return drawLineLoop(quad);
236 }
237 //-----------------------------------------------------------------------------
238 Actor* VectorGraphics::fillQuad(double left, double bottom, double right, double top)
239 {
240  std::vector<dvec2> quad;
241  quad.push_back(dvec2(left,bottom));
242  quad.push_back(dvec2(left,top));
243  quad.push_back(dvec2(right,top));
244  quad.push_back(dvec2(right,bottom));
245  // fill the vertex position array
246  ref<Geometry> geom = prepareGeometry(quad);
247  // generate texture coords
248  generateQuadsTexCoords(geom.get(), quad);
249  // issue the primitive
250  geom->drawCalls().push_back( new DrawArrays(PT_TRIANGLE_FAN, 0, (int)quad.size()) );
251  // add the actor
252  return addActor( new Actor(geom.get(), currentEffect(), NULL) );
253 }
254 //-----------------------------------------------------------------------------
256 {
257  /*mActors.clear();*/ // keep the currently drawn actors
258 
259  /*mVGToEffectMap.clear();*/ // keeps cached resources
260  /*mImageToTextureMap.clear();*/ // keeps cached resources
261  /*mRectToScissorMap.clear();*/ // keeps cached resources
262 
263  // restore the default states
264  mState = State();
265  mMatrix = dmat4();
266  mMatrixStack.clear();
267  mStateStack.clear();
268 }
269 //-----------------------------------------------------------------------------
270 void VectorGraphics::endDrawing(bool release_cache)
271 {
272  if (release_cache)
273  {
274  mVGToEffectMap.clear();
275  mImageToTextureMap.clear();
276  mRectToScissorMap.clear();
277  }
278  /*mState = State();
279  mMatrix = dmat4();*/
280  mMatrixStack.clear();
281  mStateStack.clear();
282 }
283 //-----------------------------------------------------------------------------
285 {
286  // remove all the actors
287  mActors.clear();
288 
289  // reset everything
290  mVGToEffectMap.clear();
291  mImageToTextureMap.clear();
292  mRectToScissorMap.clear();
293 
294  // restore the default states
295  mState = State();
296  mMatrix = dmat4();
297  mMatrixStack.clear();
298  mStateStack.clear();
299 }
300 //-----------------------------------------------------------------------------
302 {
303  switch(stipple)
304  {
305  case LineStipple_Solid: mState.mLineStipple = 0xFFFF; break;
306  case LineStipple_Dot: mState.mLineStipple = 0xAAAA; break;
307  case LineStipple_Dash: mState.mLineStipple = 0xCCCC; break;
308  case LineStipple_Dash4: mState.mLineStipple = 0xF0F0; break;
309  case LineStipple_Dash8: mState.mLineStipple = 0xFF00; break;
310  case LineStipple_DashDot: mState.mLineStipple = 0xF840; break;
311  case LineStipple_DashDotDot: mState.mLineStipple = 0xF888; break;
312  }
313 }
314 //-----------------------------------------------------------------------------
316 {
317  unsigned char solid_stipple[] = {
318  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
319  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
320  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
321  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
322  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
323  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
324  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
325  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF };
326  unsigned char hline_stipple[] = {
327  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
328  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
329  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
330  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
331  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
332  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
333  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,
334  0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00 };
335  unsigned char vline_stipple[] = {
336  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
337  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
338  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
339  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
340  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
341  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
342  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
343  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA };
344  unsigned char chain_stipple[] = {
345  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
346  0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55,
347  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
348  0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55,
349  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
350  0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55,
351  0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA, 0xAA,0xAA,0xAA,0xAA,
352  0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55, 0x55,0x55,0x55,0x55 };
353  unsigned char dot_stipple[] = {
354  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
355  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
356  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
357  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
358  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
359  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
360  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55,
361  0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0x55 };
362  switch(stipple)
363  {
364  case PolygonStipple_Solid: setPolygonStipple(solid_stipple); break;
365  case PolygonStipple_Dot: setPolygonStipple(dot_stipple); break;
366  case PolygonStipple_Chain: setPolygonStipple(chain_stipple); break;
367  case PolygonStipple_HLine: setPolygonStipple(hline_stipple); break;
368  case PolygonStipple_VLine: setPolygonStipple(vline_stipple); break;
369  }
370 }
371 //-----------------------------------------------------------------------------
373 {
374  mState.mBlendFactorSrcRGB = src_rgb;
375  mState.mBlendFactorDstRGB = dst_rgb;
376  mState.mBlendFactorSrcAlpha = src_alpha;
377  mState.mBlendFactorDstAlpha = dst_alpha;
378 }
379 //-----------------------------------------------------------------------------
380 void VectorGraphics::getBlendFunc(EBlendFactor& src_rgb, EBlendFactor& dst_rgb, EBlendFactor& src_alpha, EBlendFactor& dst_alpha) const
381 {
382  src_rgb = mState.mBlendFactorSrcRGB;
383  dst_rgb = mState.mBlendFactorDstRGB;
384  src_alpha = mState.mBlendFactorSrcAlpha;
385  dst_alpha = mState.mBlendFactorDstAlpha;
386 }
387 //-----------------------------------------------------------------------------
389 {
390  mState.mBlendEquationRGB = rgb_eq;
391  mState.mBlendEquationAlpha = alpha_eq;
392 }//-----------------------------------------------------------------------------
393 
395 {
396  rgb_eq = mState.mBlendEquationRGB;
397  alpha_eq = mState.mBlendEquationAlpha;
398 }
399 //-----------------------------------------------------------------------------
401 {
402  mState.mStencil_SFail = sfail;
403  mState.mStencil_DpFail = dpfail;
404  mState.mStencil_DpPass = dppass;
405 }
406 //-----------------------------------------------------------------------------
408 {
409  sfail = mState.mStencil_SFail;
410  dpfail = mState.mStencil_DpFail;
411  dppass = mState.mStencil_DpPass;
412 }
413 //-----------------------------------------------------------------------------
414 void VectorGraphics::setStencilFunc(EFunction func, int refval, unsigned int mask)
415 {
416  mState.mStencil_Function = func;
417  mState.mStencil_RefValue = refval;
418  mState.mStencil_FunctionMask = mask;
419 }
420 //-----------------------------------------------------------------------------
421 void VectorGraphics::getStencilFunc(EFunction& func, int& refval, unsigned int& mask)
422 {
423  func = mState.mStencil_Function;
424  refval = mState.mStencil_RefValue;
425  mask = mState.mStencil_FunctionMask;
426 }
427 //-----------------------------------------------------------------------------
428 Actor* VectorGraphics::clearColor(const fvec4& color, int x, int y, int w, int h)
429 {
430  ref<Clear> clear = new Clear;
431  clear->setClearColorBuffer(true);
432  clear->setClearColorValue(color);
433  clear->setScissorBox(x,y,w,h);
434  return addActor( new Actor( clear.get(), /*mDefaultEffect.get()*/currentEffect(), NULL) );
435 }
436 //-----------------------------------------------------------------------------
437 Actor* VectorGraphics::clearStencil(int clear_val, int x, int y, int w, int h)
438 {
439  ref<Clear> clear = new Clear;
440  clear->setClearStencilBuffer(true);
441  clear->setClearStencilValue(clear_val);
442  clear->setScissorBox(x,y,w,h);
443  return addActor( new Actor( clear.get(), /*mDefaultEffect.get()*/currentEffect(), NULL) );
444 }
445 //-----------------------------------------------------------------------------
447 {
448  if (text->font() == NULL)
449  text->setFont(mState.mFont.get());
450  return addActor( new Actor(text, /*mDefaultEffect.get()*/currentEffect(), NULL) );
451 }
452 //-----------------------------------------------------------------------------
453 Actor* VectorGraphics::drawText(int x, int y, const String& text, int alignment)
454 {
455  pushMatrix();
456  mMatrix = dmat4::getTranslation(x,y,0) * mMatrix;
457  Actor* act = drawText(text, alignment);
458  popMatrix();
459  return act;
460 }
461 //-----------------------------------------------------------------------------
462 Actor* VectorGraphics::drawText(const String& text, int alignment)
463 {
464  ref<Text> t = new Text;
465  t->setText( text );
466  t->setAlignment(alignment);
468  t->setColor( mState.mColor );
469  t->setMatrix( (fmat4)matrix() );
470  return drawText(t.get());
471 }
472 //-----------------------------------------------------------------------------
473 Actor* VectorGraphics::drawActor(Actor* actor, Transform* transform, bool keep_effect)
474 {
475  VL_CHECK(actor->effect())
476  if (!keep_effect || !actor->effect())
477  actor->setEffect(currentEffect());
478  if (transform != NULL)
479  actor->setTransform(transform);
480  return addActor(actor);
481 }
482 //-----------------------------------------------------------------------------
484 {
485  ref<Actor> copy = new Actor(*actor);
486  copy->setTransform(transform);
487  drawActor(copy.get());
488  return copy.get();
489 }
490 //-----------------------------------------------------------------------------
491 void VectorGraphics::rotate(double deg)
492 {
493  mMatrix = mMatrix * dmat4::getRotation(deg, 0,0,1.0);
494 }
495 //-----------------------------------------------------------------------------
496 void VectorGraphics::translate(double x, double y, double z)
497 {
498  mMatrix = mMatrix * dmat4::getTranslation(x,y,z);
499 }
500 //-----------------------------------------------------------------------------
501 void VectorGraphics::scale(double x, double y, double z)
502 {
503  mMatrix = mMatrix * dmat4::getScaling(x,y,z);
504 }
505 //-----------------------------------------------------------------------------
507 {
508  if (mMatrixStack.empty())
509  {
510  Log::error("VectorGraphics::popMatrix() matrix stack underflow!\n");
511  return;
512  }
513  setMatrix(mMatrixStack.back());
514  mMatrixStack.pop_back();
515 }
516 //-----------------------------------------------------------------------------
518 {
519  mStateStack.push_back(mState);
520  pushMatrix();
521 }
522 //-----------------------------------------------------------------------------
524 {
525  popMatrix();
526  if (mStateStack.empty())
527  {
528  Log::error("VectorGraphics::popState() matrix stack underflow!\n");
529  return;
530  }
531  mState = mStateStack.back();
532  mStateStack.pop_back();
533 }
534 //-----------------------------------------------------------------------------
535 void VectorGraphics::pushScissor(int x, int y, int w, int h)
536 {
537  mScissorStack.push_back(mScissor.get());
538  RectI newscissor = mScissor ? mScissor->scissorRect().intersected(RectI(x,y,w,h)) : RectI(x,y,w,h);
539  setScissor(newscissor.x(), newscissor.y(), newscissor.width(), newscissor.height());
540 }
541 //-----------------------------------------------------------------------------
543 {
544  if (mScissorStack.empty())
545  {
546  Log::error("VectorGraphics::popScissor() scissor stack underflow!\n");
547  return;
548  }
549  mScissor = mScissorStack.back();
550  mScissorStack.pop_back();
551 }
552 //-----------------------------------------------------------------------------
553 void VectorGraphics::generateQuadsTexCoords(Geometry* geom, const std::vector<dvec2>& points)
554 {
555  // generate only if there is an image active
556  if (mState.mImage)
557  {
558  ref<ArrayFloat2> tex_array = new ArrayFloat2;
559  tex_array->resize(geom->vertexArray()->size());
560  geom->setTexCoordArray(0, tex_array.get());
561  if (mState.mTextureMode == TextureMode_Clamp)
562  {
563  float du = 1.0f / mState.mImage->width() / 2.0f;
564  float dv = mState.mImage->height() ? (1.0f / mState.mImage->height() / 2.0f) : 0.5f;
565  // 1----2
566  // | |
567  // | |
568  // 0 3
569  fvec2 texc[] = { fvec2(du,dv), fvec2(du,1.0f-dv), fvec2(1.0f-du,1.0f-dv), fvec2(1.0f-du,dv) };
570  for(unsigned i=0; i<points.size(); ++i)
571  {
572  float s = texc[i%4].s();
573  float t = texc[i%4].t();
574  tex_array->at(i).s() = s;
575  tex_array->at(i).t() = t;
576  }
577  }
578  else
579  {
580  AABB aabb;
581  for(unsigned i=0; i<points.size(); ++i)
582  aabb.addPoint( geom->vertexArray()->getAsVec3(i) );
583  for(unsigned i=0; i<points.size(); ++i)
584  {
585  vec4 v = geom->vertexArray()->getAsVec4(i);
586  double s = (v.s()-aabb.minCorner().s()) / (mState.mImage->width() );
587  double t = (v.t()-aabb.minCorner().t()) / (mState.mImage->height());
588  tex_array->at(i).s() = (float)s;
589  tex_array->at(i).t() = (float)t;
590  }
591  }
592  }
593 }
594 //-----------------------------------------------------------------------------
595 void VectorGraphics::generatePlanarTexCoords(Geometry* geom, const std::vector<dvec2>& points)
596 {
597  // generate only if there is an image active
598  if (mState.mImage)
599  {
600  // generate uv coordinates based on the aabb
601  ref<ArrayFloat2> tex_array = new ArrayFloat2;
602  tex_array->resize(geom->vertexArray()->size());
603  geom->setTexCoordArray(0, tex_array.get());
604  if (mState.mTextureMode == TextureMode_Clamp)
605  {
606  // compute aabb
607  AABB aabb;
608  for(unsigned i=0; i<points.size(); ++i)
609  aabb.addPoint( (vec3)dvec3(points[i],0.0) );
610  for(unsigned i=0; i<points.size(); ++i)
611  {
612  float s = float((points[i].x() - aabb.minCorner().x()) / aabb.width() );
613  float t = float((points[i].y() - aabb.minCorner().y()) / aabb.height());
614  tex_array->at(i).s() = s;
615  tex_array->at(i).t() = t;
616  }
617  }
618  else
619  {
620  AABB aabb;
621  for(unsigned i=0; i<points.size(); ++i)
622  aabb.addPoint( geom->vertexArray()->getAsVec3(i)+vec3(0.5f,0.5f,0.0f) );
623  for(unsigned i=0; i<points.size(); ++i)
624  {
625  vec4 v = geom->vertexArray()->getAsVec4(i);
626  double s = (v.s()-aabb.minCorner().s()) / mState.mImage->width();
627  double t = (v.t()-aabb.minCorner().t()) / mState.mImage->height();
628  tex_array->at(i).s() = (float)s;
629  tex_array->at(i).t() = (float)t;
630  }
631  }
632  }
633 }
634 //-----------------------------------------------------------------------------
635 void VectorGraphics::generateLinearTexCoords(Geometry* geom)
636 {
637  if (mState.mImage)
638  {
639  ref<ArrayFloat2> tex_array = new ArrayFloat2;
640  tex_array->resize(geom->vertexArray()->size());
641  float u1 = 1.0f / mState.mImage->width() * 0.5f;
642  float u2 = 1.0f - 1.0f / mState.mImage->width() * 0.5f;
643  for(size_t i=0; i<tex_array->size(); ++i)
644  {
645  float t = (float)i/(tex_array->size()-1);
646  tex_array->at(i).s() = u1 * (1.0f-t) + u2 * t;
647  tex_array->at(i).t() = 0;
648  }
649  // generate geometry
650  geom->setTexCoordArray(0, tex_array.get());
651  }
652 }
653 //-----------------------------------------------------------------------------
654 ref<Geometry> VectorGraphics::prepareGeometryPolyToTriangles(const std::vector<dvec2>& ln)
655 {
656  // transform the lines
657  ref<ArrayFloat3> pos_array = new ArrayFloat3;
658  pos_array->resize( (ln.size()-2) * 3 );
659  // transform done using high precision
660  for(unsigned i=0, itri=0; i<ln.size()-2; ++i, itri+=3)
661  {
662  pos_array->at(itri+0) = (fvec3)(matrix() * dvec3(ln[0].x(), ln[0].y(), 0));
663  pos_array->at(itri+1) = (fvec3)(matrix() * dvec3(ln[i+1].x(), ln[i+1].y(), 0));
664  pos_array->at(itri+2) = (fvec3)(matrix() * dvec3(ln[i+2].x(), ln[i+2].y(), 0));
665  }
666  // generate geometry
667  ref< Geometry > geom = new Geometry;
668  geom->setVertexArray(pos_array.get());
669  return geom;
670 }
671 //-----------------------------------------------------------------------------
672 ref<Geometry> VectorGraphics::prepareGeometry(const std::vector<dvec2>& ln)
673 {
674  // transform the lines
675  ref<ArrayFloat3> pos_array = new ArrayFloat3;
676  pos_array->resize(ln.size());
677  // transform done using high precision
678  for(unsigned i=0; i<ln.size(); ++i)
679  pos_array->at(i) = (fvec3)(matrix() * dvec3(ln[i].x(), ln[i].y(), 0));
680  // generate geometry
681  ref< Geometry > geom = new Geometry;
682  geom->setVertexArray(pos_array.get());
683  return geom;
684 }
685 //-----------------------------------------------------------------------------
686 Scissor* VectorGraphics::resolveScissor(int x, int y, int width, int height)
687 {
688  ref<Scissor> scissor = mRectToScissorMap[RectI(x,y,width,height)];
689  if (!scissor)
690  {
691  scissor = new Scissor(x,y,width,height);
692  mRectToScissorMap[RectI(x,y,width,height)] = scissor;
693  }
694  return scissor.get();
695 }
696 //-----------------------------------------------------------------------------
697 Texture* VectorGraphics::resolveTexture(const Image* image)
698 {
699  Texture* texture = mImageToTextureMap[ImageState(image,mState.mTextureMode)].get();
700  if (!texture)
701  {
702  texture = new Texture( image, TF_RGBA, true, false);
705  #if 0
706  texture->getTexParameter()->setBorderColor(fvec4(1,0,1,1)); // for debuggin purposes
707  #else
708  texture->getTexParameter()->setBorderColor(fvec4(1,1,1,0)); // transparent white
709  #endif
710  if (mState.mTextureMode == vl::TextureMode_Repeat)
711  {
712  texture->getTexParameter()->setWrapS(TPW_REPEAT);
713  texture->getTexParameter()->setWrapT(TPW_REPEAT);
714  }
715  else
716  {
717  texture->getTexParameter()->setWrapS(TPW_CLAMP);
718  texture->getTexParameter()->setWrapT(TPW_CLAMP);
719  }
720  mImageToTextureMap[ImageState(image,mState.mTextureMode)] = texture;
721  }
722  return texture;
723 }
724 //-----------------------------------------------------------------------------
725 Effect* VectorGraphics::currentEffect(const State& vgs)
726 {
727  Effect* effect = mVGToEffectMap[vgs].get();
728  // create a Shader reflecting the current VectorGraphics state machine state
729  if (!effect)
730  {
731  effect = new Effect;
732  mVGToEffectMap[vgs] = effect;
733  Shader* shader = effect->shader();
734  /*shader->disable(EN_DEPTH_TEST);*/
735  shader->enable(EN_BLEND);
736  // color
737  shader->enable(EN_LIGHTING);
738  shader->gocMaterial()->setFlatColor(vgs.mColor);
739  // point size
740  shader->gocPointSize()->set((float)vgs.mPointSize);
741  // logicop
742  if (vgs.mLogicOp != LO_COPY)
743  {
744  shader->gocLogicOp()->set(vgs.mLogicOp);
745  shader->enable(EN_COLOR_LOGIC_OP);
746  }
747  // line stipple
748  if ( vgs.mLineStipple != 0xFFFF )
749  {
750 #if defined(VL_OPENGL)
751  shader->gocLineStipple()->set(1, vgs.mLineStipple);
752  shader->enable(EN_LINE_STIPPLE);
753 #else
754  Log::error("vl::VectorGraphics: line stipple not supported under OpenGL ES. Try using a stipple texture instead.\n");
755 #endif
756  }
757  // line width
758  if (vgs.mLineWidth != 1.0f)
759  shader->gocLineWidth()->set(vgs.mLineWidth);
760  // point smooth
761  if (vgs.mPointSmoothing)
762  {
764  shader->enable(EN_POINT_SMOOTH);
765  }
766  // line smooth
767  if (vgs.mLineSmoothing)
768  {
769  shader->gocHint()->setLineSmoothHint(HM_NICEST);
770  shader->enable(EN_LINE_SMOOTH);
771  }
772  // polygon smooth
773  if (vgs.mPolygonSmoothing)
774  {
776  shader->enable(EN_POLYGON_SMOOTH);
777  }
778  // poly stipple
779  unsigned char solid_stipple[] = {
780  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
781  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
782  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
783  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
784  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
785  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
786  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
787  0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF
788  };
789  if ( memcmp(vgs.mPolyStipple, solid_stipple, 32*32/8) != 0 )
790  {
791 #if defined(VL_OPENGL)
792  shader->gocPolygonStipple()->set(vgs.mPolyStipple);
793  shader->enable(EN_POLYGON_STIPPLE);
794 #else
795  Log::error("vl::VectorGraphics: polygon stipple not supported under OpenGL ES. Try using a stipple texture instead.\n");
796 #endif
797  }
798  // blending equation and function
799  shader->gocBlendEquation()->set(vgs.mBlendEquationRGB, vgs.mBlendEquationAlpha);
800  shader->gocBlendFunc()->set(vgs.mBlendFactorSrcRGB, vgs.mBlendFactorDstRGB, vgs.mBlendFactorSrcAlpha, vgs.mBlendFactorDstAlpha);
801  if (vgs.mAlphaFunc != FU_ALWAYS)
802  {
803  shader->enable(EN_ALPHA_TEST);
804  shader->gocAlphaFunc()->set(vgs.mAlphaFunc, vgs.mAlphaFuncRefValue);
805  }
806  // masks (by default they are all 'true')
807  if (vgs.mColorMask != ivec4(1,1,1,1) )
808  shader->gocColorMask()->set(vgs.mColorMask.r()?true:false,vgs.mColorMask.g()?true:false,vgs.mColorMask.b()?true:false,vgs.mColorMask.a()?true:false);
809  // stencil
810  if (vgs.mStencilTestEnabled)
811  {
812  shader->enable(EN_STENCIL_TEST);
813  shader->gocStencilMask()->set(PF_FRONT_AND_BACK, vgs.mStencilMask);
814  shader->gocStencilOp()->set(PF_FRONT_AND_BACK, vgs.mStencil_SFail, vgs.mStencil_DpFail, vgs.mStencil_DpPass);
815  shader->gocStencilFunc()->set(PF_FRONT_AND_BACK, vgs.mStencil_Function, vgs.mStencil_RefValue, vgs.mStencil_FunctionMask);
816  }
817  /*if (!vgs.mDepthMask)
818  shader->gocDepthMask()->set(false);*/
819  // texture
820  if (vgs.mImage)
821  {
822  shader->gocTextureSampler(0)->setTexture( resolveTexture(vgs.mImage.get()) );
823  if (Has_Point_Sprite)
824  {
825  shader->gocTexEnv(0)->setPointSpriteCoordReplace(true);
826  shader->enable(EN_POINT_SPRITE);
827  }
828  else
829  Log::error("GL_ARB_point_sprite not supported.\n");
830  }
831  }
832  return effect;
833 }
834 //-----------------------------------------------------------------------------
835 Actor* VectorGraphics::addActor(Actor* actor)
836 {
837  actor->setScissor(mScissor.get());
838  mActors.push_back(actor);
839  return actor;
840 }
841 //-----------------------------------------------------------------------------
Actor * drawEllipse(double origx, double origy, double xaxis, double yaxis, int segments=64)
Renders the outline of an ellipse.
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
Material * gocMaterial()
Definition: Shader.cpp:119
void setPointSpriteCoordReplace(bool replace)
Definition: Shader.hpp:1637
void setEffect(Effect *effect)
Binds an Effect to an Actor.
Definition: Actor.hpp:196
TexParameter * getTexParameter()
The TexParameter object associated to a Texture.
Definition: Texture.hpp:246
void setTexture(Texture *texture)
The texture sampler by a texture unit.
Definition: Shader.hpp:1765
Actor * drawLine(double x1, double y1, double x2, double y2)
Renders a line starting a point <x1,y1> and ending at point <x2,y2>
Hint * gocHint()
Definition: Shader.cpp:93
const T_Scalar & t() const
Definition: Vector2.hpp:145
Actor * fillQuads(const std::vector< dvec2 > &quads)
Renders a set of rectangles as defined by the OpenGL primitive GL_QUADS.
void set(EPolygonFace face, unsigned int mask)
Definition: Shader.hpp:1427
const double dPi
Greek Pi constant using double precision.
Definition: std_types.hpp:64
const fvec4 & color() const
The current color. Note that the current color also modulates the currently active image...
void setPointSmoothHint(EHintMode mode)
Definition: Shader.hpp:364
Vector3< float > fvec3
A 3 components vector with float precision.
Definition: Vector3.hpp:252
Vector2< double > dvec2
A 2 components vector with double precision.
Definition: Vector2.hpp:284
LineWidth * gocLineWidth()
Definition: Shader.cpp:131
void setAutomaticDelete(bool autodel_on)
If set to true the Object is deleted when its reference count reaches 0.
Definition: Object.hpp:275
Implements a 4x4 matrix transform used to define the position and orientation of an Actor...
Definition: Transform.hpp:72
void setLineSmoothHint(EHintMode mode)
Definition: Shader.hpp:363
const T * get() const
Definition: Object.hpp:128
void pushState()
Pushes the current VectorGraphics state (including the matrix state) in the state stack in order to r...
The texture is repeated over the primitive.
Actor * drawActor(Actor *actor, Transform *transform=NULL, bool keep_effect=false)
Draws the specified Actor with the specified Transform.
Vector4< float > fvec4
A 4 components vector with float precision.
Definition: Vector4.hpp:279
StencilFunc * gocStencilFunc()
Definition: Shader.cpp:141
The RectI class represents a 2D rectangular area using int precision.
Definition: Rect.hpp:163
const T_Scalar & s() const
Definition: Vector4.hpp:121
void pushMatrix()
Pushes the current matrix in the matrix stack in order to restore it later with popMatrix().
Matrix4< double > dmat4
A 4x4 matrix using double precision.
Definition: Matrix4.hpp:1227
A Renderable that renders text with a given Font.
Definition: Text.hpp:50
TextureSampler * gocTextureSampler(int unit_index)
Definition: Shader.cpp:171
void set(int factor, GLushort pattern)
Definition: Shader.hpp:1195
T sin(T a)
Definition: glsl_math.hpp:199
const T_Scalar & s() const
Definition: Vector2.hpp:144
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
void getStencilOp(EStencilOp &sfail, EStencilOp &dpfail, EStencilOp &dppass)
Current stencil operation.
If enabled, use the current polygon stipple pattern when rendering polygons, see also PolygonStipple...
void set(const unsigned char *mask)
Definition: Shader.cpp:600
If enabled, use the current lighting parameters to compute the vertex color; Otherwise, simply associate the current color with each vertex, see also Material, LightModel, and Light.
const ArrayAbstract * vertexArray() const
Conventional vertex array.
Definition: Geometry.hpp:248
StencilOp * gocStencilOp()
Definition: Shader.cpp:143
void setText(const String &text)
Definition: Text.hpp:63
If enabled, blend the incoming RGBA color values with the values in the color buffers, see also BlendFunc for more information.
void set(EBlendEquation mode_rgba)
Definition: Shader.hpp:673
The poligon is completely filled (default)
void endDrawing(bool release_cache=true)
Ends the rendering on a VectorGraphics and releases the resources used during the Actor generation pr...
void getBlendFunc(EBlendFactor &src_rgb, EBlendFactor &dst_rgb, EBlendFactor &src_alpha, EBlendFactor &dst_alpha) const
The current blending factor.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
Definition: Log.cpp:165
void setWrapT(ETexParamWrap texturewrap)
Definition: Texture.hpp:88
bool Has_Point_Sprite
Definition: OpenGL.cpp:98
LineStipple * gocLineStipple()
Definition: Shader.cpp:135
void setPolygonSmoohtHint(EHintMode mode)
Definition: Shader.hpp:362
void set(EFunction alphafunc, float ref_value)
Definition: Shader.hpp:751
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
Definition: Geometry.cpp:155
void setBlendFunc(EBlendFactor src_rgb, EBlendFactor dst_rgb, EBlendFactor src_alpha, EBlendFactor dst_alpha)
The current blending factor, see also http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml for more information.
void setFont(Font *font)
Definition: Text.hpp:88
Wraps an OpenGL texture object representing and managing all the supported texture types...
Definition: Texture.hpp:143
void setWrapS(ETexParamWrap texturewrap)
Definition: Texture.hpp:87
void setStencilOp(EStencilOp sfail, EStencilOp dpfail, EStencilOp dppass)
Current stencil operation, see also http://www.opengl.org/sdk/docs/man/xhtml/glStencilOp.xml for more information.
void resize(size_t dim)
Definition: Array.hpp:233
AlphaFunc * gocAlphaFunc()
Definition: Shader.cpp:117
PointSize * gocPointSize()
Definition: Shader.cpp:133
If enabled, draw points with proper filtering; Otherwise, draw aliased points, see also PointSize...
ELineStipple
Line stipple patterns.
virtual vec3 getAsVec3(size_t vector_index) const =0
Returns a vector from the buffer as a vec3 value.
void setStencilFunc(EFunction func, int refval, unsigned int mask)
The current stencil function, see also http://www.opengl.org/sdk/docs/man/xhtml/glStencilFunc.xml for more information.
EStencilOp
If enabled, performs alpha testing, see also AlphaFunc for more information.
void popState()
Pops the top most state in the state stack and sets it as the current state.
The texture is stretched over the primitive.
size_t size() const
Returns the number of elements of an array.
Definition: Array.hpp:235
Effect * currentEffect()
Returns the Effect representing the current VectorGraphic&#39;s state.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Definition: Geometry.hpp:66
void setScissor(int x, int y, int width, int height)
Defines the scissor box and enables the scissor test.
Visualization Library main namespace.
BlendEquation * gocBlendEquation()
Definition: Shader.cpp:115
Actor * fillTriangleStrip(const std::vector< dvec2 > &strip)
Renders a strip of triangles as defined by the OpenGL primitive GL_TRIANGLE_STRIP.
T height() const
Definition: Rect.hpp:72
void set(EPolygonFace face, EFunction function, int refvalue, unsigned int mask)
Definition: Shader.hpp:1296
Actor * drawLineStrip(const std::vector< dvec2 > &ln)
Renders a line passing through the points defined by &#39;ln&#39;.
T width() const
Definition: Rect.hpp:71
Actor * clearColor(const fvec4 &color, int x=0, int y=0, int w=-1, int h=-1)
Clears the specific area of the viewport.
Vector2< float > fvec2
A 2 components vector with float precision.
Definition: Vector2.hpp:282
void set(float linewidth)
Definition: Shader.hpp:1097
void setPolygonStipple(EPolygonStipple stipple)
The current polygon stipple, see also http://www.opengl.org/sdk/docs/man/xhtml/glPolygonStipple.xml for more information.
void setMinFilter(ETexParamFilter minfilter)
Definition: Texture.hpp:84
Actor * drawQuad(double left, double bottom, double right, double top)
Utility function that renders the outline of a quad.
Actor * drawPoints(const std::vector< dvec2 > &pt)
Renders a set of points using the currently set pointSize(), color() and image(). ...
void continueDrawing()
Continues the rendering on a VectorGraphics object.
Actor * fillTriangles(const std::vector< dvec2 > &triangles)
Renders a set of triangles. The &#39;triangles&#39; parameters must contain N triplets of dvec2...
void popScissor()
Pops the top most scissor in the scissor stack and sets it as the current scissor.
void getBlendEquation(EBlendEquation &rgb_eq, EBlendEquation &alpha_eq) const
The current blend equation.
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
Actor * fillTriangleFan(const std::vector< dvec2 > &fan)
Renders a triangle fan.
void translate(double x, double y, double z=0.0)
Translates the current transform matrix.
The line is completely filled (default)
void setClearColorValue(const fvec4 &clear_val)
Definition: Clear.hpp:84
real width() const
Returns the width of the AABB computed as max.x - min.x.
Definition: AABB.cpp:151
void setBorderColor(fvec4 bordercolor)
Definition: Texture.hpp:90
Actor * fillEllipse(double origx, double origy, double xaxis, double yaxis, int segments=64)
Renders an ellipse.
void push_back(T *data)
Definition: Collection.hpp:76
If enabled, draw lines with correct filtering; Otherwise, draw aliased lines, see also LineWidth...
Vector3< double > dvec3
A 3 components vector with double precision.
Definition: Vector3.hpp:254
void addPoint(const vec3 &p, real radius)
Updates the AABB to contain the given point.
Definition: AABB.cpp:135
EBlendFactor
T x() const
Definition: Rect.hpp:69
const T_Scalar & y() const
Definition: Vector3.hpp:90
The Clear class is a Renderable used to clear the whole or a portion of the color, stencil or depth buffer.
Definition: Clear.hpp:69
void set(ELogicOp logicop)
Definition: Shader.hpp:1019
void setTransform(Transform *transform)
Binds a Transform to an Actor.
Definition: Actor.hpp:182
void setLineStipple(ELineStipple stipple)
The current line stipple, see also http://www.opengl.org/sdk/docs/man/xhtml/glLineStipple.xml for more information.
void setMatrix(const dmat4 &matrix)
Sets the current transform matrix.
void clear()
Resets the VectorGraphics removing all the graphics objects and resetting its internal state...
void setTexCoordArray(int tex_unit, ArrayAbstract *data)
Conventional texture coords arrays.
Definition: Geometry.cpp:222
EBlendEquation
If enabled, calculate texture coordinates for points based on texture environment and point parameter...
const T_Scalar & s() const
Definition: Vector3.hpp:105
void scale(double x, double y, double z=1.0)
Scales the current transform matrix.
#define NULL
Definition: OpenGLDefs.hpp:81
If enabled, apply the currently selected logical operation to the incoming RGBA color and color buffe...
Manages most of the OpenGL rendering states responsible of the final aspect of the rendered objects...
Definition: Shader.hpp:1830
void getStencilFunc(EFunction &func, int &refval, unsigned int &mask)
The current stencil function.
Actor * drawPoint(double x, double y)
Renders a single point. This is only an utility function. If you want to draw many points use drawPoi...
Actor * fillQuadStrip(const std::vector< dvec2 > &quad_strip)
Renders a set of rectangles as defined by the OpenGL primitive GL_QUAD_STRIP.
Actor * fillPolygon(const std::vector< dvec2 > &poly)
Renders a convex polygon whose corners are defined by &#39;poly&#39;.
void set(float pointsize)
Definition: Shader.hpp:1130
Shader * shader(int lodi=0, int pass=0)
Utility function, same as &#39;lod(lodi)->at(pass);&#39;.
Definition: Effect.hpp:178
Actor * clearStencil(int clear_val, int x=0, int y=0, int w=-1, int h=-1)
Clears the specific area of the viewport.
T y() const
Definition: Rect.hpp:70
Defines the sequence of Shader objects used to render an Actor.
Definition: Effect.hpp:91
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
Definition: AABB.hpp:190
static Matrix4 & getRotation(Matrix4 &out, double degrees, double x, double y, double z)
Definition: Matrix4.hpp:904
void setColor(const fvec4 &color)
Definition: Text.hpp:66
T_VectorType & at(size_t i)
Definition: Array.hpp:255
Effect * effect()
Returns the Effect bound to an Actor.
Definition: Actor.hpp:199
const dmat4 & matrix() const
Returns the current transform matrix.
void set(bool red, bool green, bool blue, bool alpha)
Definition: Shader.hpp:1502
fvec3 vec3
Defined as: &#39;typedef fvec3 vec3&#39;. See also VL_PIPELINE_PRECISION.
Definition: Vector3.hpp:269
ColorMask * gocColorMask()
Definition: Shader.cpp:109
const T_Scalar & t() const
Definition: Vector3.hpp:106
virtual size_t size() const =0
Returns the number of elements of an array.
void setClearColorBuffer(bool clear)
Definition: Clear.hpp:78
void popMatrix()
Pops the top most matrix in the matrix stack and sets it as the current matrix.
Actor * fillQuad(double left, double bottom, double right, double top)
Utility function that renders a single quad.
EPolygonStipple
Poligon stipple patterns.
static Matrix4 & getTranslation(Matrix4 &out, const Vector3< double > &v)
Definition: Matrix4.hpp:548
const T_Scalar & t() const
Definition: Vector4.hpp:122
If enabled, do stencil testing and update the stencil buffer, see also StencilFunc and StencilOp...
T cos(T a)
Definition: glsl_math.hpp:225
BlendFunc * gocBlendFunc()
Definition: Shader.cpp:149
static Matrix4 & getScaling(Matrix4 &out, const Vector3< double > &v)
Definition: Matrix4.hpp:584
const T_Scalar & x() const
Definition: Vector3.hpp:89
LogicOp * gocLogicOp()
Definition: Shader.cpp:127
void setViewportAlignment(int align)
Definition: Text.hpp:97
void setScissor(Scissor *scissor)
Sets the Scissor to be used when rendering an Actor.
Definition: Actor.hpp:404
const Scissor * scissor() const
Returns the currently active Scissor.
Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps.
Definition: Image.hpp:54
virtual vec4 getAsVec4(size_t vector_index) const =0
Returns a vector from the buffer as a vec4 value.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
An array of vl::fvec3.
Definition: Array.hpp:414
const Font * font() const
Definition: Text.hpp:86
void setFlatColor(const fvec4 &color)
Definition: Shader.cpp:421
The Scissor class wraps the OpenGL function glScissor(), see http://www.opengl.org/sdk/docs/man/xhtml...
Definition: Scissor.hpp:47
Actor * drawLines(const std::vector< dvec2 > &ln)
Renders a set of lines. The &#39;ln&#39; parameter shoud contain N pairs of dvec2. Each pair defines a line s...
Actor * drawLineLoop(const std::vector< dvec2 > &ln)
Renders a closed line passing through the points defined by &#39;ln&#39;.
If enabled, draw polygons with proper filtering; Otherwise, draw aliased polygons; For correct antial...
const Image * image() const
The current image used to texture the rendered objects. Note that the current color also modulates th...
Wraps the OpenGL function glDrawArrays().
Definition: DrawArrays.hpp:57
Actor * drawActorCopy(Actor *actor, Transform *transform=NULL)
Like drawActor() but instead of drawing the given actor creates a copy of it and draws that...
void setMagFilter(ETexParamFilter magfilter)
Definition: Shader.cpp:754
An array of vl::fvec2.
Definition: Array.hpp:412
void setAlignment(int align)
Definition: Text.hpp:94
Actor * drawText(Text *text)
Draw the specified Text object.
void setClearStencilBuffer(bool clear)
Definition: Clear.hpp:82
TexEnv * gocTexEnv(int unit_index)
Definition: Shader.cpp:175
void set(EPolygonFace face, EStencilOp sfail, EStencilOp dpfail, EStencilOp dppass)
Definition: Shader.hpp:1363
void pushScissor(int x, int y, int w, int h)
Pushes the current scissor in the scissor stack in order to restore it later with popScissor() and ac...
#define VL_CHECK(expr)
Definition: checks.hpp:73
void enable(EEnable capability)
Definition: Shader.hpp:2158
void setMatrix(const fmat4 &matrix)
Definition: Text.hpp:91
void rotate(double deg)
Performs a rotation of &#39;deg&#39; degrees around the z axis.
void setClearStencilValue(int clear_val)
Definition: Clear.hpp:92
void set(EBlendFactor src_rgb, EBlendFactor dst_rgb, EBlendFactor src_alpha, EBlendFactor dst_alpha)
Definition: Shader.hpp:617
void setScissorBox(int x, int y, int w, int h)
Defines which portion of the rendering buffers should be cleared.
Definition: Clear.hpp:102
PolygonStipple * gocPolygonStipple()
Definition: Shader.cpp:137
If enabled, use the current line stipple pattern when drawing lines, see also LineStipple.
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
Definition: Geometry.hpp:102
void setBlendEquation(EBlendEquation rgb_eq, EBlendEquation alpha_eq)
The current blend equation, see also http://www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml for more information.
StencilMask * gocStencilMask()
Definition: Shader.cpp:145
real height() const
Returns the height of the AABB computed as max.y - min.y.
Definition: AABB.cpp:158