Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
AbstractGlCurve.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef ABSTRACTGLCURVE_H
22 #define ABSTRACTGLCURVE_H
23 
24 #if defined(_MSC_VER)
25 #include <Windows.h>
26 #endif
27 
28 #if defined(__APPLE__)
29 #include <OpenGL/gl.h>
30 #include <OpenGL/glu.h>
31 #else
32 #include <GL/gl.h>
33 #include <GL/glu.h>
34 # if defined(__WIN32__)
35 # include <GL/glext.h>
36 # endif
37 #endif
38 
39 #include <tulip/GlSimpleEntity.h>
40 #include <tulip/Color.h>
41 
42 namespace tlp {
43 
44 class GlShaderProgram;
45 class GlShader;
46 
47 class TLP_GL_SCOPE AbstractGlCurve : public GlSimpleEntity {
48 
49 public :
50 
51  AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
52 
53  AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode, const std::vector<Coord> &controlPoints,
54  const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints);
55 
56  virtual ~AbstractGlCurve();
57 
58  void draw(float lod, Camera *camera);
59 
60  void translate(const Coord &move);
61 
62  virtual void setTexture(const std::string &texture) {
63  this->texture = texture;
64  }
65 
66  virtual void setOutlined(const bool outlined) {
67  this->outlined = outlined;
68  }
69 
70  virtual void setOutlineColor(const Color &outlineColor) {
71  this->outlineColor = outlineColor;
72  }
73 
74  /**
75  * If set to true, the curve quad outlines will have the same colors
76  * than the curve quad
77  */
78  virtual void setOutlineColorInterpolation(const bool outlineColorInterpolation) {
79  this->outlineColorInterpolation = outlineColorInterpolation;
80  }
81 
82  /**
83  * If set to true, the curve is drawn as a line and not as a thick quad
84  */
85  void setLineCurve(const bool lineCurve) {
86  this->lineCurve = lineCurve;
87  }
88 
89  void setCurveLineWidth(const float curveLineWidth) {
90  this->curveLineWidth = curveLineWidth;
91  }
92 
93  void setCurveQuadBordersWidth(const float curveQuadBorderWidth) {
94  this->curveQuadBordersWidth = curveQuadBorderWidth;
95  }
96 
97  virtual void setBillboardCurve(const bool billboardCurve) {
98  this->billboardCurve = billboardCurve;
99  }
100 
101  virtual void setLookDir(const Coord &lookDir) {
102  this->lookDir = lookDir;
103  }
104 
105  void getXML(std::string &);
106 
107  void setWithXML(const std::string &,unsigned int &);
108 
109  virtual void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints=100);
110 
111 protected:
112 
113  virtual void setCurveVertexShaderRenderingSpecificParameters() {}
114 
115  virtual void cleanupAfterCurveVertexShaderRendering() {}
116 
117  virtual Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) = 0;
118 
119  virtual void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints, std::vector<Coord> &curvePoints, unsigned int nbCurvePoints) = 0;
120 
121  static void buildCurveVertexBuffers(const unsigned int nbCurvePoints, bool vboOk);
122 
123  void initShader(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
124 
125  static std::map<unsigned int, GLfloat *> curveVertexBuffersData;
126  static std::map<unsigned int, std::vector<GLushort *> > curveVertexBuffersIndices;
127  static std::map<unsigned int, GLuint* > curveVertexBuffersObject;
128  static std::map<std::string, GlShaderProgram *> curvesShadersMap;
129  static std::map<std::string, GlShaderProgram *> curvesBillboardShadersMap;
130  static GlShader *curveVertexShaderNormalMain;
131  static GlShader *curveVertexShaderBillboardMain;
132  static GlShader *fisheyeDistortionVertexShader;
133  static bool canUseGeometryShader;
134  static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesGeometryShadersMap;
135  static GlShader *curveVertexGeometryShaderNormalMain;
136  static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesBillboardGeometryShadersMap;
137 
138  std::string shaderProgramName;
139  GlShaderProgram *curveShaderProgramNormal;
140  GlShaderProgram *curveShaderProgramBillboard;
141  GlShaderProgram *curveShaderProgram;
142 
143 
144  std::vector<Coord> controlPoints;
145  Color startColor;
146  Color endColor;
147  float startSize;
148  float endSize;
149  unsigned int nbCurvePoints;
150  bool outlined;
151  Color outlineColor;
152  std::string texture;
153  float texCoordFactor;
154  bool billboardCurve;
155  Coord lookDir;
156  bool lineCurve;
157  float curveLineWidth;
158  float curveQuadBordersWidth;
159  bool outlineColorInterpolation;
160 };
161 
162 }
163 
164 #endif
165 
166 ///@endcond