ROOT  6.06/09
Reference Guide
TGOSXGL.mm
Go to the documentation of this file.
1 #include <utility>
2 #include <cassert>
3 #include <vector>
4 
5 #include <Foundation/Foundation.h>
6 
7 #include "TVirtualViewer3D.h"
8 #include "TSeqCollection.h"
9 #include "TVirtualGL.h"
10 #include "TVirtualX.h"
11 #include "TGOSXGL.h"
12 #include "TROOT.h"
13 #include "TEnv.h"
14 
15 
17 
18 //______________________________________________________________________________
20 {
21  //Constructor.
22 
23  //gGLManager is a singleton, it's created by the plugin manager
24  //(either from TRootCanvas or TRootEmbeddedCanvas),
25  //never by user.
26 
27  assert(gGLManager == 0 && "TGOSXGLManager, gGLManager is initialized");
28  gGLManager = this;
29 
30  //TODO: do we really need this?
31  if (gROOT && gROOT->GetListOfSpecials())
32  gROOT->GetListOfSpecials()->Add(this);
33 }
34 
35 
36 //______________________________________________________________________________
38 {
39  //Destructor.
40 
41  //TODO: do we really need this and does ROOT ever deletes 'this'?
42  if (gROOT && gROOT->GetListOfSpecials())
43  gROOT->GetListOfSpecials()->Remove(this);
44 }
45 
46 
47 //______________________________________________________________________________
49 {
50  typedef std::pair<UInt_t, Int_t> component_type;
51 
52  std::vector<component_type> format;//Where is the hummer when you need one??? (I mean C++11 initializers '{xxx}').
53 
54  //TODO: this values actually are quite random, as it was in TX11GLManager/TGWin32GLManager,
55  //find something better!
56 
57  format.push_back(component_type(Rgl::kDoubleBuffer, 1));//1 means nothing, kDoubleBuffer is enough :)
58  format.push_back(component_type(Rgl::kStencil, 8));
59  format.push_back(component_type(Rgl::kDepth, 32));
60 
61  if (gEnv) {
62  const Int_t nSamples = gEnv->GetValue("OpenGL.Framebuffer.Multisample", 0);
63  if (nSamples > 0 && nSamples <= 8) //TODO: check the 'upper limit' using API, not hardcoded 8.
64  format.push_back(component_type(Rgl::kMultiSample, nSamples));
65  }
66 
67  //Now, the interface is quite ugly, that's why it's called TVirtualX :)
68  Int_t x = 0, y = 0;
69  UInt_t width = 0, height = 0;
70  gVirtualX->GetWindowSize(parentID, x, y, width, height);
71 
72  const Window_t glWin = gVirtualX->CreateOpenGLWindow(parentID, width, height, format);
73  if (glWin != kNone) {
74  //TRootCanvas/TRootEmbeddedCanvas never do this,
75  //so ...
76  gVirtualX->MapWindow(glWin);
77  }
78 
79  //Window_t is long, in principle it's a potential problem: do I need a mapping?
80  //But if you have billions of windows ... ;)
81  return Int_t(glWin);
82 }
83 
84 
85 //______________________________________________________________________________
87 {
88  //Called from TRootCanvas, it never shares :) -> the second parameter is kNone.
89  //Handle_t is long, I'm converting to int, which can be a problem if you ...
90  //have billions of gl contexts :)
91  const Handle_t ctx = gVirtualX->CreateOpenGLContext(winID, kNone);
92  fCtxToWin[ctx] = Window_t(winID);
93 
94  return Int_t(ctx);
95 }
96 
97 //______________________________________________________________________________
99 {
100  //Just delegate.
101  gVirtualX->DeleteOpenGLContext(ctxInd);
102 }
103 
104 //______________________________________________________________________________
106 {
107  assert(fCtxToWin.find(Handle_t(ctxInd)) != fCtxToWin.end() &&
108  "MakeCurrent, window not found for a given context");
109 
110  return gVirtualX->MakeOpenGLContextCurrent(Handle_t(ctxInd), fCtxToWin[Handle_t(ctxInd)]);
111 }
112 
113 //______________________________________________________________________________
115 {
116  gVirtualX->FlushOpenGLBuffer(ctxInd);
117 }
118 
119 
120 //______________________________________________________________________________
122 {
123  return ctxInd;
124 }
125 
126 //A bunch of (now) noop functions - this is a legacy from the time when
127 //we had a real off-screen OpenGL rendering. Nowadays we always do it "on-screen"
128 
129 //______________________________________________________________________________
131 {
132  //NOOP.
133  return kFALSE;
134 }
135 
136 
137 //______________________________________________________________________________
139 {
140  //NOOP.
141  return kFALSE;
142 }
143 
144 
145 //______________________________________________________________________________
147 {
148  //NOOP.
149 }
150 
151 
152 //______________________________________________________________________________
154 {
155  //NOOP.
156 }
157 
158 //______________________________________________________________________________
160 {
161  //NOOP.
162 }
163 
164 //______________________________________________________________________________
166 {
167  //NOOP.
168 }
169 
170 //These 'delegating' functions are legacy - were required (many years ago) on Windows.
171 
172 //______________________________________________________________________________
173 Bool_t TGOSXGLManager::SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox)
174 {
175  //Why all this mess with pointers/references and not pointers/references everywhere???
176 
177  assert(manip != 0 && "SelectManip, parameter 'manip' is null");
178  assert(camera != 0 && "SelectManip, parameter 'camera' is null");
179  assert(rect != 0 && "SelectManip, parameter 'rect' is null");
180  assert(sceneBox != 0 && "SelectManip, parameter 'sceneBox' is null");
181 
182  // Select manipulator.
183  return manip->Select(*camera, *rect, *sceneBox);
184 }
185 
186 //______________________________________________________________________________
188 {
189  //Analog of TObject::DistancetoPrimitive
190  assert(plot != 0 && "PlotSelected, parameter 'plot' is null");
191 
192  return plot->PlotSelected(px, py);
193 }
194 
195 //______________________________________________________________________________
197 {
198  //Analog of TObject::GetObjectInfo
199  assert(plot != 0 && "GetPlotInfo, parameter 'plot' is null");
200 
201  return plot->GetPlotInfo(px, py);
202 }
203 
204 //______________________________________________________________________________
206 {
207  // Paint a single object.
208  assert(p != 0 && "PaintSingleObject, parameter 'p' is null");
209 
210  p->Paint();
211 }
212 
213 //______________________________________________________________________________
215 {
216  // Pan objects.
217  assert(object != 0 && "PanObject, parameter 'object' is null");
218 
219  return object->Pan(x, y);
220 }
221 
222 //______________________________________________________________________________
224 {
225  // Print viewer.
226  assert(vv != 0 && "PrintViewer, parameter 'vv' is null");
227 
228  vv->PrintObjects();
229 }
Bool_t ResizeOffScreenDevice(Int_t devInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: TGOSXGL.mm:138
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
void Flush(Int_t ctxInd)
Definition: TGOSXGL.mm:114
virtual Bool_t Select(const TGLCamera &camera, const TGLRect &rect, const TGLBoundingBox &sceneBox)=0
Int_t GetVirtualXInd(Int_t devInd)
Definition: TGOSXGL.mm:121
#define assert(cond)
Definition: unittest.h:542
#define gROOT
Definition: TROOT.h:340
virtual char * GetPlotInfo(Int_t px, Int_t py)=0
int Int_t
Definition: RtypesCore.h:41
virtual Bool_t PlotSelected(Int_t px, Int_t py)=0
bool Bool_t
Definition: RtypesCore.h:59
void ReadGLBuffer(Int_t devInd)
const Bool_t kFALSE
Definition: Rtypes.h:92
static std::string format(double x, double y, int digits, int width)
Double_t x[n]
Definition: legend1.C:17
Bool_t SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox)
Definition: TGOSXGL.mm:173
Int_t InitGLWindow(Window_t winID)
Definition: TGOSXGL.mm:48
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:426
Abstract 3D shapes viewer.
Bool_t PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py)
Definition: TGOSXGL.mm:187
void SelectOffScreenDevice(Int_t devInd)
CtxToWindowMap_t fCtxToWin
Definition: TGOSXGL.h:56
ClassImp(TGOSXGLManager) TGOSXGLManager
Definition: TGOSXGL.mm:16
Int_t CreateGLContext(Int_t winInd)
Definition: TGOSXGL.mm:86
Bool_t MakeCurrent(Int_t devInd)
Definition: TGOSXGL.mm:105
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
unsigned int UInt_t
Definition: RtypesCore.h:42
const Handle_t kNone
Definition: GuiTypes.h:89
void DeleteGLContext(Int_t devInd)
Definition: TGOSXGL.mm:98
void ExtractViewport(Int_t devInd, Int_t *vp)
Definition: TGOSXGL.mm:159
void PaintSingleObject(TVirtualGLPainter *)
Definition: TGOSXGL.mm:205
#define gVirtualX
Definition: TVirtualX.h:362
virtual void Paint()=0
Bool_t AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: TGOSXGL.mm:130
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
Double_t y[n]
Definition: legend1.C:17
#define gGLManager
Definition: TVirtualGL.h:168
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
char * GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py)
Definition: TGOSXGL.mm:196
Handle_t Window_t
Definition: GuiTypes.h:30
virtual void PrintObjects()
void PrintViewer(TVirtualViewer3D *vv)
Definition: TGOSXGL.mm:223
void PanObject(TVirtualGLPainter *o, Int_t x, Int_t y)
Definition: TGOSXGL.mm:214
void MarkForDirectCopy(Int_t devInd, Bool_t)
Definition: TGOSXGL.mm:153
ULong_t Handle_t
Definition: GuiTypes.h:27