Logo ROOT   6.16/01
Reference Guide
TGLSelectBuffer.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Matevz Tadel, Feb 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 "TGLSelectBuffer.h"
13#include "TGLSelectRecord.h"
14#include <TMath.h>
15
16#include <algorithm>
17
18/** \class TGLSelectBuffer
19\ingroup opengl
20Encapsulates OpenGL select buffer.
21Provides sorting of the results based on z-coordinate of the
22selection hit and can fill the TGLSelectRecordBase records.
23*/
24
25Int_t TGLSelectBuffer::fgMaxBufSize = 1 << 20; // 1MByte
26
27////////////////////////////////////////////////////////////////////////////////
28/// Constructor.
29
31 fBufSize (1024),
32 fBuf (new UInt_t [fBufSize]),
33 fNRecords (-1)
34{
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Destructor.
39
41{
42 delete [] fBuf;
43}
44
45////////////////////////////////////////////////////////////////////////////////
46///static: return true if current buffer is smaller than the max buffer size
47
49{
50 return 2 * fBufSize < fgMaxBufSize;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Increase size of the select buffer.
55
57{
58 delete [] fBuf;
60 fBuf = new UInt_t[fBufSize];
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Process result of GL-selection: sort the hits by their minimum
65/// z-coordinate.
66
68{
69 // The '-1' case should be handled on the caller side.
70 // Here we just assume no hits were recorded.
71
72 if (glResult < 0)
73 glResult = 0;
74
75 fNRecords = glResult;
77
78 if (fNRecords > 0)
79 {
80 Int_t i;
81 UInt_t* buf = fBuf;
82 for (i = 0; i < fNRecords; ++i)
83 {
84 fSortedRecords[i].first = buf[1]; // minimum depth
85 fSortedRecords[i].second = buf; // record address
86 buf += 3 + buf[0];
87 }
88 std::sort(fSortedRecords.begin(), fSortedRecords.end());
89 }
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Fill select record rec with data on (sorted) position i.
94/// Returns depth of name-stack for this record.
95
97{
99 return rec.GetN();
100}
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
void ProcessResult(Int_t glResult)
Process result of GL-selection: sort the hits by their minimum z-coordinate.
virtual ~TGLSelectBuffer()
Destructor.
void Grow()
Increase size of the select buffer.
vRawRecord_t fSortedRecords
static Int_t fgMaxBufSize
Bool_t CanGrow()
static: return true if current buffer is smaller than the max buffer size
TGLSelectBuffer()
Constructor.
Int_t SelectRecord(TGLSelectRecordBase &rec, Int_t i)
Fill select record rec with data on (sorted) position i.
Base class for select records.
Int_t GetN() const
virtual void Set(UInt_t *data)
Setup the record from raw buffer.
static constexpr double second
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180