00001 // @(#)root/gl:$Id: TGLSceneBase.h 32867 2010-04-01 17:07:30Z matevz $ 00002 // Author: Matevz Tadel, Feb 2007 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TGLSceneBase_H 00013 #define ROOT_TGLSceneBase_H 00014 00015 #include "TGLLockable.h" 00016 #include "TGLBoundingBox.h" 00017 00018 #include <TString.h> 00019 00020 #include <list> 00021 00022 class TGLViewerBase; 00023 class TGLSceneInfo; 00024 class TGLClip; 00025 class TGLRnrCtx; 00026 class TGLLogicalShape; 00027 class TGLSelectRecord; 00028 00029 // Avoid TObject inheritance due to clash with TObject::Draw as well 00030 // as possible inheritance of TGLPadScene from VierualViewer3D. 00031 00032 class TGLSceneBase : public TGLLockable // : public TObject / TNamed 00033 { 00034 private: 00035 TGLSceneBase(const TGLSceneBase&); // Not implemented 00036 TGLSceneBase& operator=(const TGLSceneBase&); // Not implemented 00037 00038 static UInt_t fgSceneIDSrc; 00039 00040 protected: 00041 UInt_t fSceneID; // Unique scene id. 00042 TString fName; // Object identifier. 00043 TString fTitle; // Object title. 00044 00045 UInt_t fTimeStamp; // Counter increased on every update. 00046 UInt_t fMinorStamp; // Counter increased on minimal update. 00047 Short_t fLOD; // Scene-lod. 00048 Short_t fStyle; // Scene-style. 00049 Float_t fWFLineW; // Scene wire-frame line-width. 00050 Float_t fOLLineW; // Scene outline line-width. 00051 TGLClip * fClip; // Scene clipping-plane. 00052 Bool_t fSelectable; // Objects in the scene are selectable. 00053 00054 // BoundingBox 00055 mutable TGLBoundingBox fBoundingBox; // bounding box for scene (axis aligned) - lazy update - use BoundingBox() to access 00056 mutable Bool_t fBoundingBoxValid; // bounding box valid? 00057 00058 Bool_t fDoFrustumCheck; // Perform global frustum-check in UpdateSceneInfo() 00059 Bool_t fDoClipCheck; // Perform global clip-plane-check in UpdateSceneInfo() 00060 00061 // Interface to other components 00062 typedef std::list<TGLViewerBase*> ViewerList_t; 00063 typedef std::list<TGLViewerBase*>::iterator ViewerList_i; 00064 00065 ViewerList_t fViewers; 00066 Bool_t fAutoDestruct; 00067 00068 // Possible future extensions 00069 // TGLMatrix fGlobalTrans; 00070 00071 public: 00072 TGLSceneBase(); 00073 virtual ~TGLSceneBase(); 00074 00075 void AddViewer(TGLViewerBase* viewer); 00076 void RemoveViewer(TGLViewerBase* viewer); 00077 void TagViewersChanged(); 00078 00079 virtual const char* LockIdStr() const; 00080 00081 virtual const char *GetName() const { return fName; } 00082 virtual const char *GetTitle() const { return fTitle; } 00083 virtual void SetName (const char *name) { fName = name; } 00084 virtual void SetTitle(const char *title) { fTitle = title; } 00085 virtual void SetNameTitle(const char *name, const char *title) { SetName(name); SetTitle(title); } 00086 00087 virtual TGLSceneInfo* CreateSceneInfo(TGLViewerBase* view); 00088 virtual void RebuildSceneInfo(TGLRnrCtx& ctx); 00089 virtual void UpdateSceneInfo(TGLRnrCtx& ctx); 00090 virtual void LodifySceneInfo(TGLRnrCtx& ctx); 00091 00092 // Rendering 00093 virtual void PreDraw (TGLRnrCtx & rnrCtx); 00094 virtual void PreRender (TGLRnrCtx & rnrCtx); 00095 virtual void Render (TGLRnrCtx & rnrCtx); 00096 virtual void RenderOpaque (TGLRnrCtx & rnrCtx); 00097 virtual void RenderTransp (TGLRnrCtx & rnrCtx); 00098 virtual void RenderSelOpaque (TGLRnrCtx & rnrCtx); 00099 virtual void RenderSelTransp (TGLRnrCtx & rnrCtx); 00100 virtual void PostRender(TGLRnrCtx & rnrCtx); 00101 virtual void PostDraw (TGLRnrCtx & rnrCtx); 00102 00103 virtual TGLLogicalShape* FindLogical(TObject*) const { return 0; } 00104 00105 // Selection interface 00106 virtual Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx); 00107 00108 00109 // Getters & setters 00110 00111 UInt_t GetTimeStamp() const { return fTimeStamp; } 00112 void IncTimeStamp() { ++fTimeStamp; fMinorStamp = 1; } 00113 00114 UInt_t GetMinorStamp() const { return fMinorStamp; } 00115 void IncMinorStamp() { ++fMinorStamp; } 00116 00117 Short_t LOD() const { return fLOD; } 00118 void SetLOD(Short_t lod) { fLOD = lod; } 00119 00120 Short_t Style() const { return fStyle; } 00121 void SetStyle(Short_t st) { fStyle = st; } 00122 00123 TGLClip* Clip() const { return fClip; } 00124 void SetClip(TGLClip *p) { fClip = p; } 00125 00126 Bool_t GetSelectable() const { return fSelectable; } 00127 void SetSelectable(Bool_t a) { fSelectable = a; } 00128 00129 Bool_t GetAutoDestruct() const { return fAutoDestruct; } 00130 void SetAutoDestruct(Bool_t a) { fAutoDestruct = a; } 00131 00132 // BoundingBox 00133 00134 virtual void CalcBoundingBox() const = 0; 00135 void InvalidateBoundingBox() { fBoundingBoxValid = kFALSE; } 00136 const TGLBoundingBox& BoundingBox() const 00137 { if (!fBoundingBoxValid) CalcBoundingBox(); return fBoundingBox; } 00138 00139 00140 ClassDef(TGLSceneBase, 0) // Base-class for OpenGL scenes. 00141 }; // endclass TGLSceneBase 00142 00143 00144 #endif