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