Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLFormat.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov, Jun 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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#include <cassert>
13#include <algorithm>
14#include <set>
15
16#include "TGLFormat.h"
17#include "TGLWSIncludes.h"
18#include "TGLWidget.h"
19
20#include "TEnv.h"
21#include "TError.h"
22#include "TVirtualX.h"
23#include "RConfigure.h"
24
25/** \class TGLFormat
26\ingroup opengl
27Encapsulation of format / contents of an OpenGL buffer.
28*/
29
30
31std::vector<Int_t> TGLFormat::fgAvailableSamples;
32
33////////////////////////////////////////////////////////////////////////////////
34
36 fDoubleBuffered(kTRUE),
37 fStereo(kFALSE),
39 fDepthSize(32),
40#else
41 // 16-bits needed for some virtual machines (VirtualBox) and Xming-mesa
42 // (when running ssh from windows to linux).
43 // All others seem to have 24-bit depth-buffers only and use this anyway.
44 fDepthSize(16),
45#endif
46 fAccumSize(0),
47 fStencilSize(8),
48 fSamples(GetDefaultSamples())
49{
50 //Default ctor. Default surface is:
51 //-double buffered
52 //-RGBA
53 //-with depth buffer
54 //-no accumulation buffer
55 //-with stencil
56 //-multi-sampling depends on setting of "OpenGL.Framebuffer.Multisample"
57}
58
59////////////////////////////////////////////////////////////////////////////////
60///Define surface using options.
61
63 fDoubleBuffered(opt & Rgl::kDoubleBuffer),
64 fStereo(kFALSE),
66 fDepthSize(opt & Rgl::kDepth ? 32 : 0),
67#else
68 fDepthSize(opt & Rgl::kDepth ? 16 : 0),//FIXFIX
69#endif
70 fAccumSize(opt & Rgl::kAccum ? 8 : 0), //I've never tested accumulation buffer size.
71 fStencilSize(opt & Rgl::kStencil ? 8 : 0), //I've never tested stencil buffer size.
72 fSamples(opt & Rgl::kMultiSample ? GetDefaultSamples() : 0)
73{
74}
75
76////////////////////////////////////////////////////////////////////////////////
77///Destructor.
78
82
83////////////////////////////////////////////////////////////////////////////////
84///Check if two formats are equal.
85
87{
88 return fDoubleBuffered == rhs.fDoubleBuffered && fDepthSize == rhs.fDepthSize &&
89 fAccumSize == rhs.fAccumSize && fStencilSize == rhs.fStencilSize;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93///Check for non-equality.
94
96{
97 return !(*this == rhs);
98}
99
100////////////////////////////////////////////////////////////////////////////////
101///Get the size of depth buffer.
102
104{
105 return fDepthSize;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109///Set the size of color buffer.
110
116
117////////////////////////////////////////////////////////////////////////////////
118///Check, if this surface has depth buffer.
119
121{
122 return GetDepthSize() != 0;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126///Get the size of stencil buffer.
127
129{
130 return fStencilSize;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134///Set the size of stencil buffer.
135
141
142////////////////////////////////////////////////////////////////////////////////
143///Check, if this surface has stencil buffer.
144
146{
147 return GetStencilSize() != 0;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151///Get the size of accum buffer.
152
154{
155 return fAccumSize;
156}
157
158////////////////////////////////////////////////////////////////////////////////
159///Set the size of accum buffer.
160
166
167////////////////////////////////////////////////////////////////////////////////
168///Check, if this surface has accumulation buffer.
169
171{
172 return GetAccumSize() != 0;
173}
174
175////////////////////////////////////////////////////////////////////////////////
176///Check, if the surface is double buffered.
177
182
183////////////////////////////////////////////////////////////////////////////////
184///Set the surface as double/single buffered.
185
190
191////////////////////////////////////////////////////////////////////////////////
192///Check, if the surface is stereo buffered.
193
195{
196 return fStereo;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200///Set the surface as stereo/non-stereo buffered.
201
203{
204 fStereo = db;
205}
206
207////////////////////////////////////////////////////////////////////////////////
208///Get the number of samples for multi-sampling.
209
211{
212 return fSamples;
213}
214
215////////////////////////////////////////////////////////////////////////////////
216///Set the number of samples for multi-sampling.
217
219{
220 fSamples = samples;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224///Check, if multi-sampling is required.
225
227{
228 return fSamples != 0;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Return default number of samples for multi-sampling.
233
235{
236 Int_t req = gEnv->GetValue("OpenGL.Framebuffer.Multisample", 0);
237
238 // Avoid query of available multi-sample modes when not required.
239 // Over ssh, SLC5 lies about supporting the GLX_SAMPLES_ARB
240 // extension and then dies horribly when the query is made.
241 if (req == 0) {
242 return 0;
243 }
244
245 if (fgAvailableSamples.empty())
247
248 std::vector<Int_t>::iterator i = fgAvailableSamples.begin();
249 while (i != fgAvailableSamples.end() - 1 && *i < req)
250 ++i;
251
252 if (*i != req) {
253 Info("TGLFormat::GetDefaultSamples", "Requested multi-sampling %d not available, using %d. Adjusting default.", req, *i);
254 gEnv->SetValue("OpenGL.Framebuffer.Multisample", *i);
255 }
256
257 return *i;
258}
259
260////////////////////////////////////////////////////////////////////////////////
261
263{
264 std::set<Int_t> ns_set;
265 ns_set.insert(0);
266
267#ifdef WIN32
268
269 // Missing implementation.
270#elif defined(R__HAS_COCOA)
271 ns_set.insert(8);
272 ns_set.insert(16);
273#else
275 widget->MakeCurrent();
276
278 {
279 Display *dpy = (Display*) gVirtualX->GetDisplay();
280 XVisualInfo tmpl; tmpl.screen = gVirtualX->GetScreen();
281 long mask = VisualScreenMask;
282 int numVisuals, use_gl, ms_ns;
284 for (int i = 0; i < numVisuals; i++)
285 {
286 if (glXGetConfig(dpy, &vis[i], GLX_USE_GL, &use_gl) == 0)
287 {
289 ns_set.insert(ms_ns);
290 }
291 }
292 XFree(vis);
293 }
294
295 delete widget;
296#endif
297
298 fgAvailableSamples.reserve(ns_set.size());
299 for (std::set<Int_t>::iterator i = ns_set.begin(); i != ns_set.end(); ++i)
300 {
301 fgAvailableSamples.push_back(*i);
302 }
303}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
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
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
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 mask
#define gVirtualX
Definition TVirtualX.h:337
const_iterator begin() const
const_iterator end() const
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
Definition TEnv.cxx:735
Encapsulation of format / contents of an OpenGL buffer.
Definition TGLFormat.h:36
void SetStereo(Bool_t db)
Set the surface as stereo/non-stereo buffered.
Bool_t IsStereo() const
Check, if the surface is stereo buffered.
Int_t GetDepthSize() const
Get the size of depth buffer.
static Int_t GetDefaultSamples()
Return default number of samples for multi-sampling.
static void InitAvailableSamples()
Bool_t fDoubleBuffered
Definition TGLFormat.h:38
virtual ~TGLFormat()
Destructor.
Definition TGLFormat.cxx:79
Bool_t operator!=(const TGLFormat &rhs) const
Check for non-equality.
Definition TGLFormat.cxx:95
Int_t fStencilSize
Definition TGLFormat.h:42
Int_t GetStencilSize() const
Get the size of stencil buffer.
Bool_t fStereo
Definition TGLFormat.h:39
Int_t fDepthSize
Definition TGLFormat.h:40
void SetAccumSize(Int_t accum)
Set the size of accum buffer.
void SetSamples(Int_t samples)
Set the number of samples for multi-sampling.
Int_t fAccumSize
Definition TGLFormat.h:41
void SetDoubleBuffered(Bool_t db)
Set the surface as double/single buffered.
static std::vector< Int_t > fgAvailableSamples
Definition TGLFormat.h:45
Bool_t HasMultiSampling() const
Check, if multi-sampling is required.
Int_t GetSamples() const
Get the number of samples for multi-sampling.
Bool_t HasStencil() const
Check, if this surface has stencil buffer.
void SetStencilSize(Int_t stencil)
Set the size of stencil buffer.
Bool_t HasDepth() const
Check, if this surface has depth buffer.
Bool_t IsDoubleBuffered() const
Check, if the surface is double buffered.
Int_t GetAccumSize() const
Get the size of accum buffer.
Bool_t operator==(const TGLFormat &rhs) const
Check if two formats are equal.
Definition TGLFormat.cxx:86
Bool_t HasAccumBuffer() const
Check, if this surface has accumulation buffer.
void SetDepthSize(Int_t depth)
Set the size of color buffer.
Int_t fSamples
Definition TGLFormat.h:43
GL window with context.
Definition TGLWidget.h:28
static TGLWidget * CreateDummy()
Static constructor for creating widget with default pixel format.
Definition TGLWidget.cxx:72
EFormatOptions
Definition TVirtualGL.h:127
static char accum[256]
Definition gifencode.c:210