Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
16
17//______________________________________________________________________________
19{
20 //Constructor.
21
22 //gGLManager is a singleton, it's created by the plugin manager
23 //(either from TRootCanvas or TRootEmbeddedCanvas),
24 //never by user.
25
26 assert(gGLManager == 0 && "TGOSXGLManager, gGLManager is initialized");
27 gGLManager = this;
28
29 if (gROOT && gROOT->GetListOfSpecials())
30 gROOT->GetListOfSpecials()->Add(this);
31}
32
33
34//______________________________________________________________________________
36{
37 //Destructor.
38
39 if (gROOT && gROOT->GetListOfSpecials())
40 gROOT->GetListOfSpecials()->Remove(this);
41}
42
43
44//______________________________________________________________________________
46{
47 typedef std::pair<UInt_t, Int_t> component_type;
48
49 std::vector<component_type> format;//Where is the hummer when you need one??? (I mean C++11 initializers '{xxx}').
50
51 format.push_back(component_type(Rgl::kDoubleBuffer, 1));//1 means nothing, kDoubleBuffer is enough :)
52 format.push_back(component_type(Rgl::kStencil, 8));
53 format.push_back(component_type(Rgl::kDepth, 32));
54
55 if (gEnv) {
56 const Int_t nSamples = gEnv->GetValue("OpenGL.Framebuffer.Multisample", 0);
57 if (nSamples > 0 && nSamples <= 8) //TODO: check the 'upper limit' using API, not hardcoded 8.
58 format.push_back(component_type(Rgl::kMultiSample, nSamples));
59 }
60
61 //Now, the interface is quite ugly, that's why it's called TVirtualX :)
62 Int_t x = 0, y = 0;
63 UInt_t width = 0, height = 0;
64 gVirtualX->GetWindowSize(parentID, x, y, width, height);
65
66 const Window_t glWin = gVirtualX->CreateOpenGLWindow(parentID, width, height, format);
67 if (glWin != kNone) {
68 //TRootCanvas/TRootEmbeddedCanvas never do this,
69 //so ...
70 gVirtualX->MapWindow(glWin);
71 }
72
73 //Window_t is long, in principle it's a potential problem: do I need a mapping?
74 //But if you have billions of windows ... ;)
75 return Int_t(glWin);
76}
77
78
79//______________________________________________________________________________
81{
82 //Called from TRootCanvas, it never shares :) -> the second parameter is kNone.
83 //Handle_t is long, I'm converting to int, which can be a problem if you ...
84 //have billions of gl contexts :)
85 const Handle_t ctx = gVirtualX->CreateOpenGLContext(winID, kNone);
86 fCtxToWin[ctx] = Window_t(winID);
87
88 return Int_t(ctx);
89}
90
91//______________________________________________________________________________
93{
94 //Just delegate.
95 gVirtualX->DeleteOpenGLContext(ctxInd);
96}
97
98//______________________________________________________________________________
100{
101 assert(fCtxToWin.find(Handle_t(ctxInd)) != fCtxToWin.end() &&
102 "MakeCurrent, window not found for a given context");
103
104 return gVirtualX->MakeOpenGLContextCurrent(Handle_t(ctxInd), fCtxToWin[Handle_t(ctxInd)]);
105}
106
107//______________________________________________________________________________
109{
110 gVirtualX->FlushOpenGLBuffer(ctxInd);
111}
112
113
114//______________________________________________________________________________
119
120//A bunch of (now) noop functions - this is a legacy from the time when
121//we had a real off-screen OpenGL rendering. Nowadays we always do it "on-screen"
122
123//______________________________________________________________________________
129
130
131//______________________________________________________________________________
137
138
139//______________________________________________________________________________
144
145
146//______________________________________________________________________________
148{
149 //NOOP.
150}
151
152//______________________________________________________________________________
154{
155 //NOOP.
156}
157
158//______________________________________________________________________________
160{
161 //NOOP.
162}
163
164//These 'delegating' functions are legacy - were required (many years ago) on Windows.
165
166//______________________________________________________________________________
168{
169 //Why all this mess with pointers/references and not pointers/references everywhere???
170
171 assert(manip != 0 && "SelectManip, parameter 'manip' is null");
172 assert(camera != 0 && "SelectManip, parameter 'camera' is null");
173 assert(rect != 0 && "SelectManip, parameter 'rect' is null");
174 assert(sceneBox != 0 && "SelectManip, parameter 'sceneBox' is null");
175
176 // Select manipulator.
177 return manip->Select(*camera, *rect, *sceneBox);
178}
179
180//______________________________________________________________________________
182{
183 //Analog of TObject::DistancetoPrimitive
184 assert(plot != 0 && "PlotSelected, parameter 'plot' is null");
185
186 return plot->PlotSelected(px, py);
187}
188
189//______________________________________________________________________________
191{
192 //Analog of TObject::GetObjectInfo
193 assert(plot != 0 && "GetPlotInfo, parameter 'plot' is null");
194
195 return plot->GetPlotInfo(px, py);
196}
197
198//______________________________________________________________________________
200{
201 // Paint a single object.
202 assert(p != 0 && "PaintSingleObject, parameter 'p' is null");
203
204 p->Paint();
205}
206
207//______________________________________________________________________________
209{
210 // Pan objects.
211 assert(object != 0 && "PanObject, parameter 'object' is null");
212
213 return object->Pan(x, y);
214}
215
216//______________________________________________________________________________
218{
219 // Print viewer.
220 assert(vv != 0 && "PrintViewer, parameter 'vv' is null");
221
222 vv->PrintObjects();
223}
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Handle_t kNone
Definition GuiTypes.h:88
ULongptr_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
#define gROOT
Definition TROOT.h:411
#define gGLManager
Definition TVirtualGL.h:159
#define gVirtualX
Definition TVirtualX.h:337
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
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:422
~TGOSXGLManager() override
Definition TGOSXGL.mm:35
Bool_t SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox) override
Definition TGOSXGL.mm:167
void PanObject(TVirtualGLPainter *o, Int_t x, Int_t y) override
Definition TGOSXGL.mm:208
CtxToWindowMap_t fCtxToWin
Definition TGOSXGL.h:52
Bool_t PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py) override
Definition TGOSXGL.mm:181
void ExtractViewport(Int_t devInd, Int_t *vp) override
Definition TGOSXGL.mm:153
void SelectOffScreenDevice(Int_t devInd) override
Definition TGOSXGL.mm:140
Int_t CreateGLContext(Int_t winInd) override
Definition TGOSXGL.mm:80
Int_t GetVirtualXInd(Int_t devInd) override
Definition TGOSXGL.mm:115
char * GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py) override
Definition TGOSXGL.mm:190
void ReadGLBuffer(Int_t devInd) override
Definition TGOSXGL.mm:159
void DeleteGLContext(Int_t devInd) override
Definition TGOSXGL.mm:92
void Flush(Int_t ctxInd) override
Definition TGOSXGL.mm:108
Bool_t MakeCurrent(Int_t devInd) override
Definition TGOSXGL.mm:99
void PaintSingleObject(TVirtualGLPainter *) override
Definition TGOSXGL.mm:199
Bool_t ResizeOffScreenDevice(Int_t devInd, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Definition TGOSXGL.mm:132
Bool_t AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Definition TGOSXGL.mm:124
void MarkForDirectCopy(Int_t devInd, Bool_t) override
Definition TGOSXGL.mm:147
Int_t InitGLWindow(Window_t winID) override
Definition TGOSXGL.mm:45
void PrintViewer(TVirtualViewer3D *vv) override
Definition TGOSXGL.mm:217
Abstract 3D shapes viewer.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
@ kDepth
Definition TVirtualGL.h:130
@ kMultiSample
Definition TVirtualGL.h:134
@ kStencil
Definition TVirtualGL.h:132
@ kDoubleBuffer
Definition TVirtualGL.h:129