Tulip  4.6.0
Better Visualization Through Research
library/tulip-ogl/include/tulip/AbstractGlCurve.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 ///@cond DOXYGEN_HIDDEN
00020 
00021 #ifndef ABSTRACTGLCURVE_H
00022 #define ABSTRACTGLCURVE_H
00023 
00024 #if defined(_MSC_VER)
00025 #include <Windows.h>
00026 #endif
00027 
00028 #if defined(__APPLE__)
00029 #include <OpenGL/gl.h>
00030 #include <OpenGL/glu.h>
00031 #else
00032 #include <GL/gl.h>
00033 #include <GL/glu.h>
00034 //# if defined(__WIN32__)
00035 //# include <GL/glext.h>
00036 //# endif
00037 #endif
00038 
00039 #include <map>
00040 #include <tulip/GlSimpleEntity.h>
00041 #include <tulip/Color.h>
00042 
00043 namespace tlp {
00044 
00045 class GlShaderProgram;
00046 class GlShader;
00047 
00048 class TLP_GL_SCOPE AbstractGlCurve : public GlSimpleEntity {
00049 
00050 public :
00051 
00052   AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
00053 
00054   AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode, const std::vector<Coord> &controlPoints,
00055                   const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints);
00056 
00057   virtual ~AbstractGlCurve();
00058 
00059   void draw(float lod, Camera *camera);
00060 
00061   void translate(const Coord &move);
00062 
00063   virtual void setTexture(const std::string &texture) {
00064     this->texture = texture;
00065   }
00066 
00067   virtual void setOutlined(const bool outlined) {
00068     this->outlined = outlined;
00069   }
00070 
00071   virtual void setOutlineColor(const Color &outlineColor) {
00072     this->outlineColor = outlineColor;
00073   }
00074 
00075   /**
00076    * If set to true, the curve quad outlines will have the same colors
00077    * than the curve quad
00078    */
00079   virtual void setOutlineColorInterpolation(const bool outlineColorInterpolation) {
00080     this->outlineColorInterpolation = outlineColorInterpolation;
00081   }
00082 
00083   /**
00084    * If set to true, the curve is drawn as a line and not as a thick quad
00085    */
00086   void setLineCurve(const bool lineCurve) {
00087     this->lineCurve = lineCurve;
00088   }
00089 
00090   void setCurveLineWidth(const float curveLineWidth) {
00091     this->curveLineWidth = curveLineWidth;
00092   }
00093 
00094   void setCurveQuadBordersWidth(const float curveQuadBorderWidth) {
00095     this->curveQuadBordersWidth = curveQuadBorderWidth;
00096   }
00097 
00098   virtual void setBillboardCurve(const bool billboardCurve) {
00099     this->billboardCurve = billboardCurve;
00100   }
00101 
00102   virtual void setLookDir(const Coord &lookDir) {
00103     this->lookDir = lookDir;
00104   }
00105 
00106   void getXML(std::string &);
00107 
00108   void setWithXML(const std::string &,unsigned int &);
00109 
00110   virtual void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints=100);
00111 
00112 protected:
00113 
00114   virtual void setCurveVertexShaderRenderingSpecificParameters() {}
00115 
00116   virtual void cleanupAfterCurveVertexShaderRendering() {}
00117 
00118   virtual Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) = 0;
00119 
00120   virtual void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints, std::vector<Coord> &curvePoints, unsigned int nbCurvePoints) = 0;
00121 
00122   static void buildCurveVertexBuffers(const unsigned int nbCurvePoints, bool vboOk);
00123 
00124   void initShader(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
00125 
00126   static std::map<unsigned int, GLfloat *> curveVertexBuffersData;
00127   static std::map<unsigned int, std::vector<GLushort *> > curveVertexBuffersIndices;
00128   static std::map<unsigned int, GLuint* > curveVertexBuffersObject;
00129   static std::map<std::string, GlShaderProgram *> curvesShadersMap;
00130   static std::map<std::string, GlShaderProgram *> curvesBillboardShadersMap;
00131   static GlShader *curveVertexShaderNormalMain;
00132   static GlShader *curveVertexShaderBillboardMain;
00133   static GlShader *fisheyeDistortionVertexShader;
00134   static bool canUseGeometryShader;
00135   static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesGeometryShadersMap;
00136   static GlShader *curveVertexGeometryShaderNormalMain;
00137   static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesBillboardGeometryShadersMap;
00138 
00139   std::string shaderProgramName;
00140   GlShaderProgram *curveShaderProgramNormal;
00141   GlShaderProgram *curveShaderProgramBillboard;
00142   GlShaderProgram *curveShaderProgram;
00143 
00144 
00145   std::vector<Coord> controlPoints;
00146   Color startColor;
00147   Color endColor;
00148   float startSize;
00149   float endSize;
00150   unsigned int nbCurvePoints;
00151   bool outlined;
00152   Color outlineColor;
00153   std::string texture;
00154   float texCoordFactor;
00155   bool billboardCurve;
00156   Coord lookDir;
00157   bool lineCurve;
00158   float curveLineWidth;
00159   float curveQuadBordersWidth;
00160   bool outlineColorInterpolation;
00161 };
00162 
00163 }
00164 
00165 #endif
00166 
00167 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties