00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGLScene_H
00013 #define ROOT_TGLScene_H
00014
00015 #include "TGLSceneBase.h"
00016 #include "TGLSceneInfo.h"
00017
00018 #include "Gtypes.h"
00019
00020 #include <map>
00021 #include <vector>
00022
00023 class TGLObject;
00024 class TGLCamera;
00025 class TGLLogicalShape;
00026 class TGLPhysicalShape;
00027
00028 class TGLContextIdentity;
00029
00030 class TGLScene : public TGLSceneBase
00031 {
00032 private:
00033 TGLScene(const TGLScene&);
00034 TGLScene& operator=(const TGLScene&);
00035
00036
00037 static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape* shape1,
00038 const TGLPhysicalShape* shape2);
00039 static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape* shape1,
00040 const TGLPhysicalShape* shape2);
00041 public:
00042
00043 typedef std::map<TObject*, TGLLogicalShape*> LogicalShapeMap_t;
00044 typedef LogicalShapeMap_t::value_type LogicalShapeMapValueType_t;
00045 typedef LogicalShapeMap_t::iterator LogicalShapeMapIt_t;
00046 typedef LogicalShapeMap_t::const_iterator LogicalShapeMapCIt_t;
00047
00048
00049 typedef std::map<UInt_t, TGLPhysicalShape*> PhysicalShapeMap_t;
00050 typedef PhysicalShapeMap_t::value_type PhysicalShapeMapValueType_t;
00051 typedef PhysicalShapeMap_t::iterator PhysicalShapeMapIt_t;
00052 typedef PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t;
00053
00054
00055 struct DrawElement_t
00056 {
00057 const TGLPhysicalShape* fPhysical;
00058
00059 Float_t fPixelSize;
00060 Short_t fPixelLOD;
00061 Short_t fFinalLOD;
00062
00063 DrawElement_t(const TGLPhysicalShape* pshp=0) :
00064 fPhysical(pshp), fPixelSize(0), fPixelLOD(0), fFinalLOD(0) {}
00065 };
00066
00067 typedef std::vector<DrawElement_t> DrawElementVec_t;
00068 typedef std::vector<DrawElement_t>::iterator DrawElementVec_i;
00069
00070 typedef std::vector<DrawElement_t*> DrawElementPtrVec_t;
00071 typedef std::vector<DrawElement_t*>::iterator DrawElementPtrVec_i;
00072
00073
00074 typedef std::vector<const TGLPhysicalShape*> ShapeVec_t;
00075 typedef ShapeVec_t::iterator ShapeVec_i;
00076
00077
00078
00079
00080 class TSceneInfo : public TGLSceneInfo
00081 {
00082 private:
00083 Bool_t CmpDrawElements(const DrawElement_t& de1, const DrawElement_t& de2);
00084
00085 protected:
00086 void ClearDrawElementVec(DrawElementVec_t& vec, Int_t maxSize);
00087 void ClearDrawElementPtrVec(DrawElementPtrVec_t& vec, Int_t maxSize);
00088
00089 public:
00090 ShapeVec_t fShapesOfInterest;
00091
00092 DrawElementVec_t fVisibleElements;
00093
00094 UInt_t fMinorStamp;
00095 DrawElementPtrVec_t fOpaqueElements;
00096 DrawElementPtrVec_t fTranspElements;
00097 DrawElementPtrVec_t fSelOpaqueElements;
00098 DrawElementPtrVec_t fSelTranspElements;
00099
00100 TSceneInfo(TGLViewerBase* view=0, TGLScene* scene=0);
00101 virtual ~TSceneInfo();
00102
00103 void ClearAfterRebuild();
00104 void ClearAfterUpdate();
00105
00106 void Lodify(TGLRnrCtx& ctx);
00107
00108 void PreDraw();
00109 void PostDraw();
00110
00111
00112
00113
00114 Int_t fOpaqueCnt;
00115 Int_t fTranspCnt;
00116 Int_t fAsPixelCnt;
00117 std::map<TClass*, UInt_t> fByShapeCnt;
00118
00119 void ResetDrawStats();
00120 void UpdateDrawStats(const TGLPhysicalShape& shape, Short_t lod);
00121 void DumpDrawStats();
00122 };
00123 friend class TSceneInfo;
00124
00125
00126 protected:
00127 LogicalShapeMap_t fLogicalShapes;
00128 PhysicalShapeMap_t fPhysicalShapes;
00129
00130 virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit);
00131
00132
00133 TGLContextIdentity * fGLCtxIdentity;
00134 void ReleaseGLCtxIdentity();
00135
00136
00137 Bool_t fInSmartRefresh;
00138 mutable LogicalShapeMap_t fSmartRefreshCache;
00139
00140
00141 Float_t fLastPointSizeScale;
00142 Float_t fLastLineWidthScale;
00143
00144
00145
00146
00147 public:
00148 TGLScene();
00149 virtual ~TGLScene();
00150
00151 virtual void CalcBoundingBox() const;
00152
00153 virtual TSceneInfo* CreateSceneInfo(TGLViewerBase* view);
00154 virtual void RebuildSceneInfo(TGLRnrCtx& rnrCtx);
00155 virtual void UpdateSceneInfo(TGLRnrCtx& rnrCtx);
00156 virtual void LodifySceneInfo(TGLRnrCtx& rnrCtx);
00157
00158
00159
00160 virtual void PreDraw (TGLRnrCtx& rnrCtx);
00161
00162
00163 virtual void RenderOpaque (TGLRnrCtx& rnrCtx);
00164 virtual void RenderTransp (TGLRnrCtx& rnrCtx);
00165 virtual void RenderSelOpaque (TGLRnrCtx& rnrCtx);
00166 virtual void RenderSelTransp (TGLRnrCtx& rnrCtx);
00167
00168 virtual void PostDraw (TGLRnrCtx& rnrCtx);
00169
00170 virtual void RenderAllPasses(TGLRnrCtx& rnrCtx,
00171 DrawElementPtrVec_t& elVec,
00172 Bool_t check_timeout);
00173
00174
00175 virtual void RenderElements (TGLRnrCtx& rnrCtx,
00176 DrawElementPtrVec_t& elVec,
00177 Bool_t check_timeout,
00178 const TGLPlaneSet_t* clipPlanes = 0);
00179
00180
00181 virtual Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx);
00182
00183
00184 virtual void AdoptLogical(TGLLogicalShape& shape);
00185 virtual Bool_t DestroyLogical(TObject* logid, Bool_t mustFind=kTRUE);
00186 virtual Int_t DestroyLogicals();
00187 virtual TGLLogicalShape* FindLogical(TObject* logid) const;
00188
00189
00190 virtual void AdoptPhysical(TGLPhysicalShape& shape);
00191 virtual Bool_t DestroyPhysical(UInt_t phid);
00192 virtual Int_t DestroyPhysicals();
00193 virtual TGLPhysicalShape* FindPhysical(UInt_t phid) const;
00194
00195 virtual UInt_t GetMaxPhysicalID();
00196
00197
00198
00199
00200 virtual Bool_t BeginUpdate();
00201 virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE);
00202
00203 virtual void UpdateLogical(TObject* logid);
00204
00205 virtual void UpdatePhysical(UInt_t phid, Double_t* trans, UChar_t* col);
00206 virtual void UpdatePhysical(UInt_t phid, Double_t* trans, Color_t cidx=-1, UChar_t transp=0);
00207
00208 virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, UChar_t* col);
00209 virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, Color_t cidx, UChar_t transp);
00210
00211
00212 LogicalShapeMap_t& RefLogicalShapes() { return fLogicalShapes; }
00213
00214
00215
00216
00217
00218 UInt_t BeginSmartRefresh();
00219 void EndSmartRefresh();
00220 TGLLogicalShape* FindLogicalSmartRefresh(TObject* ID) const;
00221
00222
00223
00224
00225
00226 TGLContextIdentity* GetGLCtxIdentity() const { return fGLCtxIdentity; }
00227
00228
00229
00230
00231
00232 UInt_t SizeOfScene() const;
00233 void DumpMapSizes() const;
00234
00235 static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0);
00236
00237 static Bool_t IsOutside(const TGLBoundingBox& box,
00238 const TGLPlaneSet_t& planes);
00239
00240 ClassDef(TGLScene, 0);
00241 };
00242
00243
00244 #endif