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//______________________________________________________________________________
168Bool_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}
ULong_t Handle_t
Definition: GuiTypes.h:25
const Handle_t kNone
Definition: GuiTypes.h:87
Handle_t Window_t
Definition: GuiTypes.h:28
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:365
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
#define gROOT
Definition: TROOT.h:415
#define gGLManager
Definition: TVirtualGL.h:162
#define gVirtualX
Definition: TVirtualX.h:345
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:44
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:421
CtxToWindowMap_t fCtxToWin
Definition: TGOSXGL.h:52
Int_t GetVirtualXInd(Int_t devInd)
Definition: TGOSXGL.mm:116
void ReadGLBuffer(Int_t devInd)
Definition: TGOSXGL.mm:160
void ExtractViewport(Int_t devInd, Int_t *vp)
Definition: TGOSXGL.mm:154
Bool_t AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: TGOSXGL.mm:125
Bool_t ResizeOffScreenDevice(Int_t devInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: TGOSXGL.mm:133
void Flush(Int_t ctxInd)
Definition: TGOSXGL.mm:109
void PaintSingleObject(TVirtualGLPainter *)
Definition: TGOSXGL.mm:200
Int_t InitGLWindow(Window_t winID)
Definition: TGOSXGL.mm:46
Bool_t SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox)
Definition: TGOSXGL.mm:168
void SelectOffScreenDevice(Int_t devInd)
Definition: TGOSXGL.mm:141
void PanObject(TVirtualGLPainter *o, Int_t x, Int_t y)
Definition: TGOSXGL.mm:209
void MarkForDirectCopy(Int_t devInd, Bool_t)
Definition: TGOSXGL.mm:148
Int_t CreateGLContext(Int_t winInd)
Definition: TGOSXGL.mm:81
void PrintViewer(TVirtualViewer3D *vv)
Definition: TGOSXGL.mm:218
void DeleteGLContext(Int_t devInd)
Definition: TGOSXGL.mm:93
char * GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py)
Definition: TGOSXGL.mm:191
Bool_t PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py)
Definition: TGOSXGL.mm:182
Bool_t MakeCurrent(Int_t devInd)
Definition: TGOSXGL.mm:100
virtual Bool_t Select(const TGLCamera &camera, const TGLRect &rect, const TGLBoundingBox &sceneBox)=0
virtual Bool_t PlotSelected(Int_t px, Int_t py)=0
virtual char * GetPlotInfo(Int_t px, Int_t py)=0
virtual void Paint()=0
Abstract 3D shapes viewer.
virtual void PrintObjects()
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
@ kDepth
Definition: TVirtualGL.h:132
@ kMultiSample
Definition: TVirtualGL.h:136
@ kStencil
Definition: TVirtualGL.h:134
@ kDoubleBuffer
Definition: TVirtualGL.h:131