]>
Commit | Line | Data |
---|---|---|
bada2039 | 1 | #include "GLUtilNS.h" |
2 | ||
3 | #include <TAttMarker.h> | |
4 | #include <GL/gl.h> | |
5 | ||
6 | namespace GLUtilNS { | |
7 | ||
8 | void RenderPolyMarkers(TAttMarker& marker, Float_t* p, Int_t n, | |
9 | Bool_t selection, Bool_t sec_selection) | |
10 | { | |
11 | // Store attributes GL_POINT_BIT and GL_LINE_BIT before call this function ! | |
12 | ||
13 | Int_t s = marker.GetMarkerStyle(); | |
14 | if (s == 2 || s == 3 || s == 5 || s == 28) | |
15 | RenderCrosses(marker, p, n, sec_selection); | |
16 | else | |
17 | RenderPoints(marker, p, n, selection, sec_selection); | |
18 | } | |
19 | ||
20 | //______________________________________________________________________________ | |
21 | void RenderPoints(TAttMarker& marker, Float_t* p, Int_t n, | |
22 | Bool_t selection, Bool_t sec_selection) | |
23 | { | |
24 | // Render markers as circular or square points. | |
25 | { | |
26 | Int_t ms = marker.GetMarkerStyle(); | |
27 | Float_t size = 5*marker.GetMarkerSize(); | |
28 | if (ms == 4 || ms == 20 || ms == 24) | |
29 | { | |
30 | if (ms == 4 || ms == 24) | |
31 | glEnable(GL_BLEND); | |
32 | glEnable(GL_POINT_SMOOTH); | |
33 | } else | |
34 | { | |
35 | glDisable(GL_POINT_SMOOTH); | |
36 | if (ms == 1) size = 1; | |
37 | else if (ms == 6) size = 2; | |
38 | else if (ms == 7) size = 3; | |
39 | } | |
40 | glPointSize(size); | |
41 | ||
42 | // During selection extend picking region for large point-sizes. | |
43 | static const Int_t sPickRadius = 3; // Hardcoded also in TGLViewer::RequestSelect() | |
44 | Bool_t changePM = kFALSE; | |
45 | if (selection && size > sPickRadius) | |
46 | { | |
47 | changePM = kTRUE; | |
48 | glMatrixMode(GL_PROJECTION); | |
49 | glPushMatrix(); | |
50 | Float_t pm[16]; | |
51 | glGetFloatv(GL_PROJECTION_MATRIX, pm); | |
52 | Float_t scale = (Float_t) sPickRadius / size; | |
53 | for (Int_t i=0; i<=12; i+=4) { | |
54 | pm[i] *= scale; pm[i+1] *= scale; | |
55 | } | |
56 | glLoadMatrixf(pm); | |
57 | } | |
58 | ||
59 | if (sec_selection) | |
60 | { | |
61 | glPushName(0); | |
62 | for (Int_t i=0; i<n; ++i, p+=3) | |
63 | { | |
64 | glLoadName(i); | |
65 | glBegin(GL_POINTS); | |
66 | glVertex3fv(p); | |
67 | glEnd(); | |
68 | } | |
69 | glPopName(); | |
70 | } | |
71 | else | |
72 | { | |
73 | glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); | |
74 | glVertexPointer(3, GL_FLOAT, 0, p); | |
75 | glEnableClientState(GL_VERTEX_ARRAY); | |
76 | { // Circumvent bug in ATI's linux drivers. | |
77 | Int_t nleft = n; | |
78 | Int_t ndone = 0; | |
79 | const Int_t maxChunk = 8192; | |
80 | while (nleft > maxChunk) | |
81 | { | |
82 | glDrawArrays(GL_POINTS, ndone, maxChunk); | |
83 | nleft -= maxChunk; | |
84 | ndone += maxChunk; | |
85 | } | |
86 | glDrawArrays(GL_POINTS, ndone, nleft); | |
87 | } | |
88 | glPopClientAttrib(); | |
89 | } | |
90 | ||
91 | if (changePM) | |
92 | { | |
93 | glPopMatrix(); | |
94 | glMatrixMode(GL_MODELVIEW); | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | //______________________________________________________________________________ | |
100 | void RenderCrosses(TAttMarker& marker, Float_t* p, Int_t n, | |
101 | Bool_t sec_selection) | |
102 | { | |
103 | // Render markers as crosses. | |
104 | // | |
105 | if (marker.GetMarkerStyle() == 28) | |
106 | { | |
107 | glEnable(GL_BLEND); | |
108 | glEnable(GL_LINE_SMOOTH); | |
109 | glLineWidth(2); | |
110 | } | |
111 | else | |
112 | { | |
113 | glDisable(GL_LINE_SMOOTH); | |
114 | } | |
115 | ||
116 | // cross dim | |
117 | const Float_t d = marker.GetMarkerSize(); | |
118 | if (sec_selection) | |
119 | { | |
120 | glPushName(0); | |
121 | for (Int_t i=0; i<n; ++i, p+=3) | |
122 | { | |
123 | glLoadName(i); | |
124 | glBegin(GL_LINES); | |
125 | glVertex3f(p[0]-d, p[1], p[2]); glVertex3f(p[0]+d, p[1], p[2]); | |
126 | glVertex3f(p[0], p[1]-d, p[2]); glVertex3f(p[0], p[1]+d, p[2]); | |
127 | glVertex3f(p[0], p[1], p[2]-d); glVertex3f(p[0], p[1], p[2]+d); | |
128 | glEnd(); | |
129 | } | |
130 | glPopName(); | |
131 | } | |
132 | else | |
133 | { | |
134 | glBegin(GL_LINES); | |
135 | for (Int_t i=0; i<n; ++i, p+=3) | |
136 | { | |
137 | glVertex3f(p[0]-d, p[1], p[2]); glVertex3f(p[0]+d, p[1], p[2]); | |
138 | glVertex3f(p[0], p[1]-d, p[2]); glVertex3f(p[0], p[1]+d, p[2]); | |
139 | glVertex3f(p[0], p[1], p[2]-d); glVertex3f(p[0], p[1], p[2]+d); | |
140 | } | |
141 | glEnd(); | |
142 | } | |
143 | } | |
144 | ||
145 | /**************************************************************************/ | |
146 | } // end namespace GLUtilNS |