Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:01

0001 // @(#)root/gl:$Id$
0002 // Author:  Matevz Tadel, Feb 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGLScene_H
0013 #define ROOT_TGLScene_H
0014 
0015 #include "TGLSceneBase.h"
0016 #include "TGLSceneInfo.h"
0017 
0018 #include <map>
0019 #include <vector>
0020 
0021 class TGLObject;
0022 class TGLCamera;
0023 class TGLLogicalShape;
0024 class TGLPhysicalShape;
0025 
0026 class TGLContextIdentity;
0027 
0028 class TGLScene : public TGLSceneBase
0029 {
0030 private:
0031    TGLScene(const TGLScene&) = delete;
0032    TGLScene& operator=(const TGLScene&) = delete;
0033 
0034    // Compare physical-shape volumes/diagonals -- for draw-vec sorting
0035    static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape* shape1,
0036                                         const TGLPhysicalShape* shape2);
0037    static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape* shape1,
0038                                           const TGLPhysicalShape* shape2);
0039 public:
0040    // Logical shapes
0041    typedef std::map<TObject*, TGLLogicalShape*>    LogicalShapeMap_t;
0042    typedef LogicalShapeMap_t::value_type           LogicalShapeMapValueType_t;
0043    typedef LogicalShapeMap_t::iterator             LogicalShapeMapIt_t;
0044    typedef LogicalShapeMap_t::const_iterator       LogicalShapeMapCIt_t;
0045 
0046    // Physical Shapes
0047    typedef std::map<UInt_t, TGLPhysicalShape*>     PhysicalShapeMap_t;
0048    typedef PhysicalShapeMap_t::value_type          PhysicalShapeMapValueType_t;
0049    typedef PhysicalShapeMap_t::iterator            PhysicalShapeMapIt_t;
0050    typedef PhysicalShapeMap_t::const_iterator      PhysicalShapeMapCIt_t;
0051 
0052 
0053    struct DrawElement_t
0054    {
0055       const TGLPhysicalShape* fPhysical; // Physical shape.
0056 
0057       Float_t    fPixelSize; // Size of largest lod-axis in pixels.
0058       Short_t    fPixelLOD;  // Size in LOD units.
0059       Short_t    fFinalLOD;  // Corrected with SceneLOD and quantized.
0060 
0061       DrawElement_t(const TGLPhysicalShape* pshp=nullptr) :
0062          fPhysical(pshp), fPixelSize(0), fPixelLOD(0), fFinalLOD(0) {}
0063    };
0064 
0065    typedef std::vector<DrawElement_t>              DrawElementVec_t;
0066    typedef std::vector<DrawElement_t>::iterator    DrawElementVec_i;
0067 
0068    typedef std::vector<DrawElement_t*>             DrawElementPtrVec_t;
0069    typedef std::vector<DrawElement_t*>::iterator   DrawElementPtrVec_i;
0070 
0071    // List of physical shapes ordered by volume/diagonal
0072    typedef std::vector<const TGLPhysicalShape*>    ShapeVec_t;
0073    typedef ShapeVec_t::iterator                    ShapeVec_i;
0074 
0075    // ----------------------------------------------------------------
0076    // SceneInfo ... extended scene context
0077 
0078    class TSceneInfo : public TGLSceneInfo
0079    {
0080    private:
0081       Bool_t CmpDrawElements(const DrawElement_t& de1, const DrawElement_t& de2);
0082 
0083    protected:
0084       void ClearDrawElementVec(DrawElementVec_t& vec, Int_t maxSize);
0085       void ClearDrawElementPtrVec(DrawElementPtrVec_t& vec, Int_t maxSize);
0086 
0087    public:
0088       ShapeVec_t          fShapesOfInterest;
0089 
0090       DrawElementVec_t    fVisibleElements;
0091 
0092       UInt_t              fMinorStamp;
0093       DrawElementPtrVec_t fOpaqueElements;
0094       DrawElementPtrVec_t fTranspElements;
0095       DrawElementPtrVec_t fSelOpaqueElements;
0096       DrawElementPtrVec_t fSelTranspElements;
0097 
0098       TSceneInfo(TGLViewerBase* view=nullptr, TGLScene* scene=nullptr);
0099       ~TSceneInfo() override;
0100 
0101       void ClearAfterRebuild();
0102       void ClearAfterUpdate();
0103 
0104       void Lodify(TGLRnrCtx& ctx);
0105 
0106       void PreDraw();
0107       void PostDraw();
0108 
0109       // ---------------
0110       // Draw statistics
0111 
0112       Int_t                     fOpaqueCnt;
0113       Int_t                     fTranspCnt;
0114       Int_t                     fAsPixelCnt;
0115       std::map<TClass*, UInt_t> fByShapeCnt;
0116 
0117       void ResetDrawStats();
0118       void UpdateDrawStats(const TGLPhysicalShape& shape, Short_t lod);
0119       void DumpDrawStats(); // Debug
0120    };
0121    friend class TSceneInfo; // for solaris cc
0122 
0123 
0124 protected:
0125    LogicalShapeMap_t      fLogicalShapes;  //!
0126    PhysicalShapeMap_t     fPhysicalShapes; //!
0127 
0128    virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit);
0129 
0130    // GLcontext
0131    TGLContextIdentity * fGLCtxIdentity;
0132    void ReleaseGLCtxIdentity();
0133 
0134    // Smart Refresh -- will go in this version
0135    Bool_t                    fInSmartRefresh;    //!
0136    mutable LogicalShapeMap_t fSmartRefreshCache; //!
0137 
0138    // State that requires recreation of display-lists
0139    Float_t                   fLastPointSizeScale;
0140    Float_t                   fLastLineWidthScale;
0141 
0142    // ----------------------------------------------------------------
0143    // ----------------------------------------------------------------
0144 
0145 public:
0146    TGLScene();
0147    ~TGLScene() override;
0148 
0149    void CalcBoundingBox() const override;
0150 
0151    TSceneInfo* CreateSceneInfo(TGLViewerBase* view) override;
0152    void        RebuildSceneInfo(TGLRnrCtx& rnrCtx) override;
0153    void        UpdateSceneInfo(TGLRnrCtx& rnrCtx) override;
0154    void        LodifySceneInfo(TGLRnrCtx& rnrCtx) override;
0155 
0156 
0157    // Rendering
0158    void PreDraw        (TGLRnrCtx& rnrCtx) override;
0159    // virtual void PreRender   (TGLRnrCtx& rnrCtx);
0160    // virtual void Render      (TGLRnrCtx& rnrCtx);
0161    void RenderOpaque   (TGLRnrCtx& rnrCtx) override;
0162    void RenderTransp   (TGLRnrCtx& rnrCtx) override;
0163    void RenderSelOpaque(TGLRnrCtx& rnrCtx) override;
0164    void RenderSelTransp(TGLRnrCtx& rnrCtx) override;
0165    void RenderSelOpaqueForHighlight(TGLRnrCtx& rnrCtx) override;
0166    void RenderSelTranspForHighlight(TGLRnrCtx& rnrCtx) override;
0167 
0168    virtual void RenderHighlight(TGLRnrCtx&           rnrCtx,
0169                                 DrawElementPtrVec_t& elVec);
0170 
0171    // virtual void PostRender(TGLRnrCtx& rnrCtx);
0172    void PostDraw       (TGLRnrCtx& rnrCtx) override;
0173 
0174    virtual void RenderAllPasses(TGLRnrCtx&           rnrCtx,
0175                                 DrawElementPtrVec_t& elVec,
0176                                 Bool_t               check_timeout);
0177 
0178 
0179    virtual void RenderElements (TGLRnrCtx&           rnrCtx,
0180                                 DrawElementPtrVec_t& elVec,
0181                                 Bool_t               check_timeout,
0182                                 const TGLPlaneSet_t* clipPlanes = nullptr);
0183 
0184    // Selection
0185    Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx) override;
0186 
0187    // Basic logical shape management
0188    virtual void              AdoptLogical(TGLLogicalShape& shape);
0189    virtual Bool_t            DestroyLogical(TObject* logid, Bool_t mustFind=kTRUE);
0190    virtual Int_t             DestroyLogicals();
0191    TGLLogicalShape*  FindLogical(TObject* logid)  const override;
0192 
0193    // Basic physical shape management
0194    virtual void              AdoptPhysical(TGLPhysicalShape& shape);
0195    virtual Bool_t            DestroyPhysical(UInt_t phid);
0196    virtual Int_t             DestroyPhysicals();
0197    virtual TGLPhysicalShape* FindPhysical(UInt_t phid) const;
0198 
0199    virtual UInt_t            GetMaxPhysicalID();
0200 
0201    // ----------------------------------------------------------------
0202    // Updates / removals of logical and physical shapes
0203 
0204    virtual Bool_t BeginUpdate();
0205    virtual void   EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE);
0206 
0207    virtual void UpdateLogical(TObject* logid);
0208 
0209    virtual void UpdatePhysical(UInt_t phid, Double_t* trans, UChar_t* col);
0210    virtual void UpdatePhysical(UInt_t phid, Double_t* trans, Color_t cidx=-1, UChar_t transp=0);
0211 
0212    virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, UChar_t* col);
0213    virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, Color_t cidx, UChar_t transp);
0214 
0215    // Temporary export for setting selected-state of physical shapes.
0216    LogicalShapeMap_t& RefLogicalShapes() { return fLogicalShapes; }
0217 
0218 
0219    // ----------------------------------------------------------------
0220    // SmartRefresh
0221 
0222    UInt_t            BeginSmartRefresh();
0223    void              EndSmartRefresh();
0224    TGLLogicalShape*  FindLogicalSmartRefresh(TObject* ID) const;
0225 
0226 
0227    // ----------------------------------------------------------------
0228    // GL-context holding display-list definitions
0229 
0230    TGLContextIdentity* GetGLCtxIdentity() const { return fGLCtxIdentity; }
0231 
0232 
0233    // ----------------------------------------------------------------
0234    // Helpers
0235 
0236    UInt_t SizeOfScene() const;
0237    void   DumpMapSizes() const;
0238 
0239    static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0);
0240 
0241    static Bool_t IsOutside(const TGLBoundingBox& box,
0242                            const TGLPlaneSet_t& planes);
0243 
0244    ClassDefOverride(TGLScene, 0); // Standard ROOT OpenGL scene with logial/physical shapes.
0245 };
0246 
0247 
0248 #endif