00001 #ifndef _VTXACCUMULATOR_H_
00002 #define _VTXACCUMULATOR_H_
00003
00004 #include "fv_inc.h"
00005 #include "fv_assert.h"
00006 #include "Enums.h"
00007 #include "BBox3D.h"
00008 #include "Matrix.h"
00009 #include "RenderParams.h"
00010 #include "MathHelper.h"
00011 #include "Shader.h"
00012 #include<cstddef>
00013 #include <string>
00014 #include <vector>
00015
00016 namespace FemViewer {
00017
00018 extern GLuint g_GLList;
00019 extern bool initGLLists();
00020 extern GLuint createGLLists(const GLuint type,int size);
00021
00022 class Legend;
00023 class ViewManager;
00024
00025
00026
00027
00028
00029
00030 class PrimitiveAccumulator;
00031 class Light;
00032 class VtxAccumulator;
00033 typedef void (VtxAccumulator::*drawMethod)(const RenderParams&);
00034
00035
00036
00037
00038
00039
00040
00041 class VtxAccumulator
00042 {
00043 enum {
00044 UBO_PROJ = 0,
00045 UBO_PARAMS,
00046 VBO_VERTICES,
00047 VBO_FACES,
00048 VBO_PIXEL,
00049 IBO_EDGES,
00050 IBO_FACES,
00051 ALL_BO
00052 };
00053
00054 static int counter;
00055
00056 public:
00057 void setUniformMatrix(const GLfloat *pData,const int pType = 0);
00058 void setUniformParams();
00059 typedef GLuint index_type_t;
00060 public:
00061 explicit VtxAccumulator();
00062 ~VtxAccumulator();
00063 bool init(const size_t nVerts,const size_t nEdges, const int type = LINEAR);
00064 bool reset(int type = -1);
00065 void update();
00066 void create();
00067 void createVertexBuffer();
00068 void createIndexBuffer();
00069 void createEdges(GLuint *pVAO);
00070 void createTriangles(GLuint *pVA0);
00071 void createTriangleStrips(GLuint *pVA0);
00072 void createText(const GLuint type,const float *color);
00073 void createGLCL();
00074 void cleanUp();
00075 void addColor (const Vec3D& pColor);
00076
00077 void addVertex(const Vertex& pVertex,const int dest = vtxEdge);
00078 bool isVertexInitialized(const size_t index) const {
00079 return !(aVertices.at(index).color.x < 0.0f);
00080 }
00081 void addNode (const fvmath::Vec3f& pNode) {
00082 aNodes.push_back(pNode);
00083 aBBox += pNode;
00084 }
00085 void addEdge (const int s,const int e) {
00086 assert(s != e);
00087 if (s != e) {
00088 aEdIndices.push_back(s);
00089 aEdIndices.push_back(e);
00090
00091 }
00092 }
00093
00094 void addNodeColor(const fvmath::Vec3f& color) {
00095 aNodeColors.push_back(color);
00096 }
00097
00098 void addNormal2Node(const fvmath::Vec3f& normal) {
00099 aNodeNormals.push_back(normal);
00100 }
00101
00102 void addIndexOfNode(const unsigned int index,const int type = vtxTriangle) {
00103 if (type == vtxTriangle) aTrIndices.push_back(index);
00104 else aQuIndices.push_back(index);
00105 }
00106
00107 void addLocalIndexOfNode(const index_type_t index,const int type = vtxTriangle) {
00108 if (type == vtxTriangle) aTrLocIndices.push_back(index);
00109 else aQuLocIndices.push_back(index);
00110 }
00111
00112 void addPrimitiveCount(const unsigned int count,const int dest = vtxTriangle) {
00113 if (dest) aQFaceCounts.push_back(count);
00114 else aTFaceCounts.push_back(count);
00115 }
00116
00117
00118
00119
00120
00121
00122 void dumpCharacteristics(std::ostream& pOstream,
00123 const std::string& pIndentation,
00124 const Matrix<float>& pTransformation) const;
00125
00126
00127 bool getVerticesFrozen () const;
00128 bool getColorsFrozen () const;
00129
00130 bool freezeColors ();
00131 void freezeVertices ();
00132
00133 typedef std::size_t size_type;
00134 typedef std::vector<Vec3D> Colors;
00135 typedef std::vector<Vec3D> Normals;
00136
00137 typedef std::vector<Vertex> Vertices;
00138 typedef fvmath::Vec3f NodeCoords;
00139 typedef fvmath::Vec3f NodeColor;
00140 typedef std::vector<NodeCoords> Nodes;
00141 typedef std::vector<NodeColor> NodeColors;
00142 typedef std::vector<NodeCoords> NodeNormals;
00143 typedef Nodes::size_type NodesSizeType;
00144 typedef std::vector<unsigned int> Indices;
00145 typedef std::vector<GLsizei> Counts;
00146 typedef std::vector<GLint> BaseIndices;
00147 typedef std::vector<Shader *> Shaders;
00148 typedef std::vector<index_type_t> LocalIndices;
00149
00150
00151 Vertices& getVertices(const int type = vtxEdge) {
00152 if (type == vtxEdge) return aVertices;
00153 return (type == vtxTriangle ? aTrVertices : aQuVertices);
00154 }
00155
00156 Indices& getIndices(const int type = vtxEdge) {
00157 if (type == vtxEdge) return aEdIndices;
00158 return (type == vtxTriangle) ? aTrIndices : aQuIndices;
00159 }
00160
00161 LocalIndices& getLocalIndices(const int type = vtxTriangle) {
00162 if (type) return aQuLocIndices;
00163 else return aTrLocIndices;
00164 }
00165 NodeColors& getNodeColors() { return aNodeColors; }
00166
00167 size_t& getVertexCounter() { return aVertexCounter; }
00168
00169
00170 GLuint* getPixelBufferHandle() { return &aBufferName[VBO_PIXEL]; }
00171
00172 BBox3D getBBox3D() { return aBBox; }
00173
00174
00175 protected:
00176 const ViewManager* viewmgr_ptr;
00177 drawMethod renderer;
00178 int aType;
00179 Vertices aVertices;
00180 Indices aEdIndices;
00181 Vertices aTrVertices;
00182 Indices aTrIndices;
00183 Vertices aQuVertices;
00184 Indices aQuIndices;
00185 bool aGLinited;
00186 GLuint aVAOIds[vtxAll];
00187 GLuint aBufferName[ALL_BO];
00188 Counts aTFaceCounts;
00189 Counts aQFaceCounts;
00190 std::vector<int64_t> aCounts;
00191 unsigned int aNumTriFaces;
00192 const Matrixf& aProjection;
00193 const Matrixf& aModelView;
00194 const Light& aLight;
00195 const Legend& aLegend;
00196 Colors aColors;
00197 bool aColorsFrozen;
00198 Normals aNormals;
00199 bool aSimplifiedDirty;
00200
00201
00202 bool aVerticesFrozen;
00203 Nodes aNodes;
00204 NodeColors aNodeColors;
00205 NodeNormals aNodeNormals;
00206
00207
00208
00209
00210
00211 CVec3f aEdgeColor;
00212 float aEdgeThickness;
00213
00214
00215 GLuint aUniforms[5];
00216 EdgeShader* edges_renderer;
00217 TriangleShader* faces_renderer;
00218
00219 LocalIndices aTrLocIndices;
00220 LocalIndices aQuLocIndices;
00221
00222
00223 size_type aVertexCounter;
00224 BBox3D aBBox;
00225
00226 public:
00227 mutable bool aUpdateRenderParams;
00228 bool aRenderEdges;
00229 bool aRenderIsoLines;
00230 bool aRenderTraingleStrips;
00231 bool aRenderTraingles;
00232 const Colors& getColors() const;
00233 const Vertices& getVertices() const;
00234 const Nodes& getNodes() const { return aNodes; }
00235
00236
00237
00238 Normals& getNormals();
00239 void render(const RenderParams& pPram);
00240
00241 void setEdgeColor(const Vec3f& color) { aEdgeColor = color; }
00242 void setEdgeWidth(const float width) { aEdgeThickness = width; }
00243 private:
00244 void init_gl(bool quiet = true);
00245 void UpdateRenderParams() const;
00246
00247 void renderTriangleStrips(const RenderParams& pPr);
00248 void renderTriangles(const RenderParams& pPr);
00249 void renderEdges(const RenderParams& pPr);
00250 void renderIdle(const RenderParams& pPr);
00251 void renderGLCL(const RenderParams& pPr);
00252
00253
00254 private:
00255
00256
00257 VtxAccumulator(const VtxAccumulator&);
00258 VtxAccumulator& operator=(const VtxAccumulator&);
00259 };
00260
00261 }
00262
00263 #endif
00264