Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLObject.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel 7/4/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
13 #include "TGLObject.h"
14 #include "TGLRnrCtx.h"
15 #include "TObject.h"
16 #include "TClass.h"
17 #include "TBaseClass.h"
18 #include "TList.h"
19 #include "TString.h"
20 
21 /** \class TGLObject
22 \ingroup opengl
23 Base-class for direct OpenGL renderers.
24 This allows classes to circumvent passing of TBuffer3D and
25 use user-provided OpenGL code.
26 By convention, if you want class TFoo : public TObject to have direct rendering
27 you should also provide TFooGL : public TGLObject and implement
28 abstract functions SetModel() and SetBBox().
29 TAttBBox can be used to facilitate calculation of bounding-boxes.
30 See TPointSet3D and TPointSet3DGL.
31 */
32 
33 ClassImp(TGLObject);
34 
35 TMap TGLObject::fgGLClassMap;
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Decide if display-list should be used for this pass rendering,
39 /// as determined by rnrCtx.
40 
41 Bool_t TGLObject::ShouldDLCache(const TGLRnrCtx& rnrCtx) const
42 {
43  if (!fDLCache ||
44  !fScene ||
45  (rnrCtx.SecSelection() && SupportsSecondarySelect()) ||
46  (fMultiColor && (rnrCtx.Highlight() || rnrCtx.IsDrawPassOutlineLine())) ||
47  (AlwaysSecondarySelect() && rnrCtx.Highlight()))
48  {
49  return kFALSE;
50  }
51 
52  return kTRUE;
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Update bounding box from external source.
57 /// We call abstract SetBBox() and propagate the change to all
58 /// attached physicals.
59 
60 void TGLObject::UpdateBoundingBox()
61 {
62  SetBBox();
63  UpdateBoundingBoxesOfPhysicals();
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Checks if obj is of proper class and sets the model.
68 /// Protected helper for subclasses.
69 /// Most sub-classes use exception-throwing SetModelDynCast() instead.
70 
71 Bool_t TGLObject::SetModelCheckClass(TObject* obj, TClass* cls)
72 {
73  if(obj->InheritsFrom(cls) == kFALSE) {
74  Warning("TGLObject::SetModelCheckClass", "object of wrong class passed.");
75  return kFALSE;
76  }
77  fExternalObj = obj;
78 
79  return kTRUE;
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Set axis-aligned bounding-box.
84 /// Protected helper for subclasses.
85 
86 void TGLObject::SetAxisAlignedBBox(Float_t xmin, Float_t xmax,
87  Float_t ymin, Float_t ymax,
88  Float_t zmin, Float_t zmax)
89 {
90  fBoundingBox.SetAligned(TGLVertex3(xmin, ymin, zmin),
91  TGLVertex3(xmax, ymax, zmax));
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Set axis-aligned bounding-box.
96 /// Protected helper for subclasses.
97 
98 void TGLObject::SetAxisAlignedBBox(const Float_t* p)
99 {
100  SetAxisAlignedBBox(p[0], p[1], p[2], p[3], p[4], p[5]);
101 }
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Recursively search cls and its base classes for a GL-renderer
106 /// class.
107 
108 TClass* TGLObject::SearchGLRenderer(TClass* cls)
109 {
110  TString rnr( cls->GetName() );
111  rnr += "GL";
112  TClass* c = TClass::GetClass(rnr);
113  if (c != 0)
114  return c;
115 
116  TList* bases = cls->GetListOfBases();
117  if (bases == 0 || bases->IsEmpty())
118  return 0;
119 
120  TIter next_base(bases);
121  TBaseClass* bc;
122  while ((bc = (TBaseClass*) next_base()) != 0) {
123  cls = bc->GetClassPointer();
124  if ((c = SearchGLRenderer(cls)) != 0) {
125  return c;
126  }
127  }
128  return 0;
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Return direct-rendering GL class for class isa.
133 /// Zero is a valid response.
134 
135 TClass* TGLObject::GetGLRenderer(TClass* isa)
136 {
137  TPair* p = (TPair*) fgGLClassMap.FindObject(isa);
138  TClass* cls;
139  if (p != 0) {
140  cls = (TClass*) p->Value();
141  } else {
142  cls = SearchGLRenderer(isa);
143  fgGLClassMap.Add(isa, cls);
144  }
145  return cls;
146 }