Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
AbstractGlCurve.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
4 *
5 * Authors: David Auber and the Tulip development Team
6 * from LaBRI, University of Bordeaux
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#include <tulip/OpenGlIncludes.h>
25
26#include <unordered_map>
27
28#include <tulip/Color.h>
29#include <tulip/Coord.h>
30#include <tulip/GlSimpleEntity.h>
31
32namespace tlp {
33
34class GlShaderProgram;
35class GlShader;
36
37class TLP_GL_SCOPE AbstractGlCurve : public GlSimpleEntity {
38
39public:
40 AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
41
42 AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode,
43 const std::vector<Coord> &controlPoints, const Color &startColor,
44 const Color &endColor, const float startSize, const float endSize,
45 const unsigned int nbCurvePoints);
46
47 ~AbstractGlCurve() override;
48
49 void draw(float lod, Camera *camera) override;
50
51 void translate(const Coord &move) override;
52
53 virtual void setTexture(const std::string &texture) {
54 this->texture = texture;
55 }
56
57 virtual void setOutlined(const bool outlined) {
58 this->outlined = outlined;
59 }
60
61 virtual void setOutlineColor(const Color &outlineColor) {
62 this->outlineColor = outlineColor;
63 }
64
65 /**
66 * If set to true, the curve quad outlines will have the same colors
67 * than the curve quad
68 */
69 virtual void setOutlineColorInterpolation(const bool outlineColorInterpolation) {
70 this->outlineColorInterpolation = outlineColorInterpolation;
71 }
72
73 /**
74 * If set to true, the curve is drawn as a line and not as a thick quad
75 */
76 void setLineCurve(const bool lineCurve) {
77 this->lineCurve = lineCurve;
78 }
79
80 void setCurveLineWidth(const float curveLineWidth) {
81 this->curveLineWidth = curveLineWidth;
82 }
83
84 void setCurveQuadBordersWidth(const float curveQuadBorderWidth) {
85 this->curveQuadBordersWidth = curveQuadBorderWidth;
86 }
87
88 virtual void setBillboardCurve(const bool billboardCurve) {
89 this->billboardCurve = billboardCurve;
90 }
91
92 virtual void setLookDir(const Coord &lookDir) {
93 this->lookDir = lookDir;
94 }
95
96 void getXML(std::string &) override;
97
98 void setWithXML(const std::string &, unsigned int &) override;
99
100 virtual void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor,
101 const Color &endColor, const float startSize, const float endSize,
102 const unsigned int nbCurvePoints = 100);
103
104protected:
105 virtual void setCurveVertexShaderRenderingSpecificParameters() {}
106
107 virtual void cleanupAfterCurveVertexShaderRendering() {}
108
109 virtual Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) = 0;
110
111 virtual void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints,
112 std::vector<Coord> &curvePoints,
113 unsigned int nbCurvePoints) = 0;
114
115 static void buildCurveVertexBuffers(const unsigned int nbCurvePoints, bool vboOk);
116
117 void initShader(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
118
119 static std::unordered_map<unsigned int, GLfloat *> curveVertexBuffersData;
120 static std::unordered_map<unsigned int, std::vector<GLushort *>> curveVertexBuffersIndices;
121 static std::unordered_map<unsigned int, GLuint *> curveVertexBuffersObject;
122 static std::unordered_map<std::string, GlShaderProgram *> curvesShadersMap;
123 static std::unordered_map<std::string, GlShaderProgram *> curvesBillboardShadersMap;
124 static GlShader *curveVertexShaderNormalMain;
125 static GlShader *curveVertexShaderBillboardMain;
126 static GlShader *fisheyeDistortionVertexShader;
127 static GlShader *curveFragmentShader;
128 static bool canUseGeometryShader;
129 static std::unordered_map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *>>
130 curvesGeometryShadersMap;
131 static GlShader *curveVertexGeometryShaderNormalMain;
132 static std::unordered_map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *>>
133 curvesBillboardGeometryShadersMap;
134
135 std::string shaderProgramName;
136 GlShaderProgram *curveShaderProgramNormal;
137 GlShaderProgram *curveShaderProgramBillboard;
138 GlShaderProgram *curveShaderProgram;
139
140 std::vector<Coord> controlPoints;
141 Color startColor;
142 Color endColor;
143 float startSize;
144 float endSize;
145 unsigned int nbCurvePoints;
146 bool outlined;
147 Color outlineColor;
148 std::string texture;
149 float texCoordFactor;
150 bool billboardCurve;
151 Coord lookDir;
152 bool lineCurve;
153 float curveLineWidth;
154 float curveQuadBordersWidth;
155 bool outlineColorInterpolation;
156};
157} // namespace tlp
158
159#endif
160
161///@endcond