![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2010 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00006 00007 #pragma once 00008 00009 #include <vrvGraphics/vrvGraphics.h> 00010 #include <vrvGraphics/DtPrimitiveRenderer.h> 00011 #include <vrvGraphics/DtFlat2DLineRenderer.h> 00012 00013 #include <vector> 00014 #include <boost/unordered_map.hpp> 00015 00016 namespace makVrv 00017 { 00018 class DtBufferObject; 00019 class DtFlat2DLineRenderer; 00020 class DtLineSegmentProxy; 00021 class DtOverlayResourceProvider; 00022 class DtProjected2DLineEffect; 00023 00026 class DT_DLL_VRVGRAPHICS DtLineRenderer : public DtPrimitiveRenderer 00027 { 00028 friend class DtLineSegmentProxy; 00029 public: 00030 00031 struct LineSegmentPrimitive 00032 { 00033 DtLineVertex p1; 00034 DtLineVertex p2; 00035 }; 00036 00037 const static unsigned short NoStipple = 0xFFFF; 00038 const static unsigned short NoLine = 0x0; 00039 00040 DtLineRenderer(DtOverlayResourceProvider& provider); 00041 00042 virtual ~DtLineRenderer(); 00043 00045 virtual int numberOfPrimitives() const; 00046 00048 virtual void render(bool geocentric, float geocentricAlpha, 00049 const double cameraLocation[3], 00050 const double positionMatrix[16], bool picking); 00051 00053 virtual void releaseResources(); 00054 00056 virtual bool isRenderModeSupported(int mode); 00057 00059 DtLineSegmentProxy* allocateNewSegment(); 00060 00061 protected: 00062 00063 // Called when a proxy modified data. 00064 void dirty(DtLineSegmentProxy*); 00065 00066 //Called in proxy destructor. 00067 void deallocateProxy(const DtLineSegmentProxy&); 00068 00069 // Move Segment from one list to another. 00070 int moveSegmentToOtherList( 00071 const float currentWidth, 00072 const int currentSegmentIndex, 00073 const int currentPrimativeIndex, 00074 const float desiredWidth, 00075 const int desiredSegmentIndex); 00076 00077 private: 00078 00079 typedef std::vector<LineSegmentPrimitive> LineSegments; 00080 typedef std::vector<DtLineSegmentProxy*> LineSegmentProxyList; 00081 00082 struct LineSegmentSets 00083 { 00084 LineSegmentProxyList mySimpleProxies; 00085 LineSegmentProxyList myStippledProxies; 00086 00087 LineSegments mySimpleLines; 00088 LineSegments myStippledLines; 00089 00090 LineSegments& segmentsByIndex(unsigned int index) 00091 { 00092 if(index == 0) 00093 return mySimpleLines; 00094 else 00095 return myStippledLines; 00096 } 00097 00098 LineSegmentProxyList& proxiesByIndex(unsigned int index) 00099 { 00100 if(index == 0) 00101 return mySimpleProxies; 00102 else 00103 return myStippledProxies; 00104 } 00105 }; 00106 00107 typedef boost::unordered_map<float,LineSegmentSets> LineMap; 00108 00109 void renderUsingVertexArrays(DtFlat2DLineRenderer& renderer); 00110 void renderStippledLineArrays(DtFlat2DLineRenderer& renderer, 00111 DtLineVertex* ptr, LineSegments& segments); 00112 void updateRenderData(); 00113 void sortByStipple(); 00114 00115 LineMap myLines; 00116 DtProjected2DLineEffect * myEffect; 00117 LineSegmentProxyList myDirtyList; 00118 DtBufferObject* myBufferObject; 00119 unsigned int myPrimativeCount; 00120 }; 00121 00125 class DT_DLL_VRVGRAPHICS DtLineSegmentProxy 00126 { 00127 friend class DtLineRenderer; 00128 public: 00129 ~DtLineSegmentProxy(); 00130 00131 const DtLineRenderer::LineSegmentPrimitive& mapReadOnly() const; 00132 DtLineRenderer::LineSegmentPrimitive& mapReadWrite(); 00133 00135 void enableStipple(); 00136 00138 void disableStipple(); 00139 00141 void setWidth(float w); 00142 00144 float width() const; 00145 00147 void setGroup(float group); 00148 00150 float group() const; 00151 00152 //Needed for sorting. 00153 static inline void swap(DtLineSegmentProxy*& v1,DtLineSegmentProxy*& v2) 00154 { 00155 //Swap what they point to 00156 std::swap(v1->myParent->myLines[v1->myWidth].segmentsByIndex(v1->mySegmentIndex)[v1->myIndex], 00157 v2->myParent->myLines[v2->myWidth].segmentsByIndex(v2->mySegmentIndex)[v2->myIndex]); 00158 //Swap their indices 00159 std::swap(v1->myIndex,v2->myIndex); 00160 //Swap themselves 00161 std::swap(v1,v2); 00162 } 00163 00164 //Needed for sorting. 00165 static inline bool less(DtLineSegmentProxy*& v1,DtLineSegmentProxy*& v2) 00166 { 00167 DtLineRenderer::LineSegmentPrimitive& line1 = 00168 v1->myParent->myLines[v1->myWidth].segmentsByIndex(v1->mySegmentIndex)[v1->myIndex]; 00169 DtLineRenderer::LineSegmentPrimitive& line2 = 00170 v1->myParent->myLines[v2->myWidth].segmentsByIndex(v2->mySegmentIndex)[v2->myIndex]; 00171 00172 return (((unsigned int)line1.p1.lineParams[0]) << 16 | 00173 (unsigned int)(line1.p1.lineParams[1])) 00174 < 00175 (((unsigned int)line2.p1.lineParams[0]) << 16 | 00176 (unsigned int)(line2.p1.lineParams[1])); 00177 } 00178 00179 //Needed for sorting. 00180 static inline bool equal(DtLineSegmentProxy*& v1,DtLineSegmentProxy*& v2) 00181 { 00182 DtLineRenderer::LineSegmentPrimitive& line1 = 00183 v1->myParent->myLines[v1->myWidth].segmentsByIndex(v1->mySegmentIndex)[v1->myIndex]; 00184 DtLineRenderer::LineSegmentPrimitive& line2 = 00185 v1->myParent->myLines[v2->myWidth].segmentsByIndex(v2->mySegmentIndex)[v2->myIndex]; 00186 00187 return (((unsigned int)line1.p1.lineParams[0]) << 16 | 00188 (unsigned int)(line1.p1.lineParams[1])) 00189 == 00190 (((unsigned int)line2.p1.lineParams[0]) << 16 | 00191 (unsigned int)(line2.p1.lineParams[1])); 00192 } 00193 00194 protected: 00195 DtLineSegmentProxy(DtLineRenderer& parent,int index); 00196 DtLineRenderer* myParent; 00197 00198 bool myDirtyFlag; 00199 int mySegmentIndex; 00200 int myIndex; 00201 float myWidth; 00202 00203 }; 00204 00205 }