Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/OpenGLLinesProgram.cpp @ 2063:b6b5e1ca1cc2 deep-learning
rename
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 May 2023 22:00:38 +0200 |
parents | 8bb8d9c0cfd0 |
children | fdb012c86a75 |
rev | line source |
---|---|
592 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
592 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
592 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
592 | 21 **/ |
22 | |
23 | |
24 #include "OpenGLLinesProgram.h" | |
611
e3f21a265be5
Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents:
592
diff
changeset
|
25 #include "OpenGLShaderVersionDirective.h" |
592 | 26 |
1624 | 27 #include <Logging.h> |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
28 #include <OrthancException.h> |
592 | 29 |
30 | |
31 static const unsigned int COMPONENTS_POSITION = 3; | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
32 static const unsigned int COMPONENTS_COLOR = 3; |
592 | 33 static const unsigned int COMPONENTS_MITER = 2; |
34 | |
35 | |
36 static const char* VERTEX_SHADER = | |
611
e3f21a265be5
Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents:
592
diff
changeset
|
37 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE |
592 | 38 "attribute vec2 a_miter_direction; \n" |
39 "attribute vec4 a_position; \n" | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
40 "attribute vec3 a_color; \n" |
592 | 41 "uniform float u_thickness; \n" |
42 "uniform mat4 u_matrix; \n" | |
43 "varying float v_distance; \n" | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
44 "varying vec3 v_color; \n" |
592 | 45 "void main() \n" |
46 "{ \n" | |
47 " v_distance = a_position.z; \n" | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
48 " v_color = a_color; \n" |
592 | 49 " gl_Position = u_matrix * vec4(a_position.xy + a_position.z * a_miter_direction * u_thickness, 0, 1); \n" |
50 "}"; | |
51 | |
52 | |
53 static const char* FRAGMENT_SHADER = | |
611
e3f21a265be5
Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents:
592
diff
changeset
|
54 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE |
592 | 55 "uniform bool u_antialiasing; \n" |
56 "uniform float u_antialiasing_start; \n" | |
57 "varying float v_distance; \n" // Distance of the point to the segment | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
58 "varying vec3 v_color; \n" |
592 | 59 "void main() \n" |
60 "{ \n" | |
61 " float d = abs(v_distance); \n" | |
62 " if (!u_antialiasing || \n" | |
63 " d <= u_antialiasing_start) \n" | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
64 " gl_FragColor = vec4(v_color, 1); \n" |
592 | 65 " else if (d >= 1.0) \n" |
66 " gl_FragColor = vec4(0, 0, 0, 0); \n" | |
67 " else \n" | |
68 " { \n" | |
69 " float alpha = 1.0 - smoothstep(u_antialiasing_start, 1.0, d); \n" | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
70 " gl_FragColor = vec4(v_color * alpha, alpha); \n" |
592 | 71 " } \n" |
72 "}"; | |
73 | |
74 | |
75 namespace OrthancStone | |
76 { | |
77 namespace Internals | |
78 { | |
79 class OpenGLLinesProgram::Data::Segment | |
80 { | |
81 private: | |
82 bool isEmpty_; | |
83 double x1_; | |
84 double y1_; | |
85 double x2_; | |
86 double y2_; | |
87 double miterX1_; | |
88 double miterY1_; | |
89 double miterX2_; | |
90 double miterY2_; | |
91 | |
92 Vector lineAbove_; // In homogeneous coordinates (size = 3) | |
93 Vector lineBelow_; | |
94 | |
95 public: | |
96 Segment(const PolylineSceneLayer::Chain& chain, | |
97 size_t index1, | |
98 size_t index2) : | |
99 isEmpty_(false) | |
100 { | |
101 if (index1 >= chain.size() || | |
102 index2 >= chain.size()) | |
103 { | |
104 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
105 } | |
106 else | |
107 { | |
108 const ScenePoint2D& p = chain[index1]; | |
109 const ScenePoint2D& q = chain[index2]; | |
110 | |
111 x1_ = p.GetX(); | |
112 y1_ = p.GetY(); | |
113 x2_ = q.GetX(); | |
114 y2_ = q.GetY(); | |
115 | |
116 const double dx = x2_ - x1_; | |
117 const double dy = y2_ - y1_; | |
118 const double norm = sqrt(dx * dx + dy * dy); | |
119 | |
120 if (LinearAlgebra::IsCloseToZero(norm)) | |
121 { | |
122 isEmpty_ = true; | |
123 } | |
124 else | |
125 { | |
126 isEmpty_ = false; | |
127 const double normalX = -dy / norm; | |
128 const double normalY = dx / norm; | |
129 | |
130 miterX1_ = normalX; | |
131 miterY1_ = normalY; | |
132 miterX2_ = normalX; | |
133 miterY2_ = normalY; | |
134 | |
135 Vector a = LinearAlgebra::CreateVector(x1_ + normalX, y1_ + normalY, 1); | |
136 Vector b = LinearAlgebra::CreateVector(x2_ + normalX, y2_ + normalY, 1); | |
137 LinearAlgebra::CrossProduct(lineAbove_, a, b); | |
138 | |
139 a = LinearAlgebra::CreateVector(x1_ - normalX, y1_ - normalY, 1); | |
140 b = LinearAlgebra::CreateVector(x2_ - normalX, y2_ - normalY, 1); | |
141 LinearAlgebra::CrossProduct(lineBelow_, a, b); | |
142 } | |
143 } | |
144 } | |
145 | |
146 bool IsEmpty() const | |
147 { | |
148 return isEmpty_; | |
149 } | |
150 | |
151 static double ComputeSignedArea(double x1, | |
152 double y1, | |
153 double x2, | |
154 double y2, | |
155 double x3, | |
156 double y3) | |
157 { | |
158 // This computes the signed area of a 2D triangle. This | |
159 // formula is e.g. used in the sorting algorithm of Graham's | |
160 // scan to compute the convex hull. | |
161 // https://en.wikipedia.org/wiki/Graham_scan | |
162 return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1); | |
163 } | |
164 | |
165 static void CreateMiter(Segment& left, | |
166 Segment& right) | |
167 { | |
168 if (!left.IsEmpty() && | |
169 !right.IsEmpty()) | |
170 { | |
171 Vector above, below; | |
172 LinearAlgebra::CrossProduct(above, left.lineAbove_, right.lineAbove_); | |
173 LinearAlgebra::CrossProduct(below, left.lineBelow_, right.lineBelow_); | |
174 | |
175 if (!LinearAlgebra::IsCloseToZero(above[2]) && | |
176 !LinearAlgebra::IsCloseToZero(below[2])) | |
177 { | |
178 // Back to inhomogeneous 2D coordinates | |
179 above /= above[2]; | |
180 below /= below[2]; | |
181 | |
182 // Check whether "above" and "below" intersection points | |
183 // are on the half-plane defined by the endpoints of the | |
184 // two segments. This is an indicator of whether the angle | |
185 // is too acute. | |
186 double s1 = ComputeSignedArea(left.x1_, left.y1_, | |
187 above[0], above[1], | |
188 right.x2_, right.y2_); | |
189 double s2 = ComputeSignedArea(left.x1_, left.y1_, | |
190 below[0], below[1], | |
191 right.x2_, right.y2_); | |
192 | |
193 // The two signed areas must have the same sign | |
194 if (s1 * s2 >= 0) | |
195 { | |
196 left.miterX2_ = above[0] - left.x2_; | |
197 left.miterY2_ = above[1] - left.y2_; | |
198 | |
199 right.miterX1_ = left.miterX2_; | |
200 right.miterY1_ = left.miterY2_; | |
201 } | |
202 } | |
203 } | |
204 } | |
205 | |
206 void AddTriangles(std::vector<float>& coords, | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
207 std::vector<float>& miterDirections, |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
208 std::vector<float>& colors, |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
209 const Color& color) |
592 | 210 { |
211 if (isEmpty_) | |
212 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
213 LOG(ERROR) << "OpenGLLinesProgram -- AddTriangles: (isEmpty_)"; |
592 | 214 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
215 } | |
216 | |
217 // First triangle | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
218 coords.push_back(static_cast<float>(x1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
219 coords.push_back(static_cast<float>(y1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
220 coords.push_back(static_cast<float>(1)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
221 coords.push_back(static_cast<float>(x2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
222 coords.push_back(static_cast<float>(y2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
223 coords.push_back(static_cast<float>(-1)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
224 coords.push_back(static_cast<float>(x2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
225 coords.push_back(static_cast<float>(y2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
226 coords.push_back(static_cast<float>(1)); |
592 | 227 |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
228 miterDirections.push_back(static_cast<float>(miterX1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
229 miterDirections.push_back(static_cast<float>(miterY1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
230 miterDirections.push_back(static_cast<float>(miterX2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
231 miterDirections.push_back(static_cast<float>(miterY2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
232 miterDirections.push_back(static_cast<float>(miterX2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
233 miterDirections.push_back(static_cast<float>(miterY2_)); |
592 | 234 |
235 // Second triangle | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
236 coords.push_back(static_cast<float>(x1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
237 coords.push_back(static_cast<float>(y1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
238 coords.push_back(static_cast<float>(1)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
239 coords.push_back(static_cast<float>(x1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
240 coords.push_back(static_cast<float>(y1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
241 coords.push_back(static_cast<float>(-1)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
242 coords.push_back(static_cast<float>(x2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
243 coords.push_back(static_cast<float>(y2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
244 coords.push_back(static_cast<float>(-1)); |
592 | 245 |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
246 miterDirections.push_back(static_cast<float>(miterX1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
247 miterDirections.push_back(static_cast<float>(miterY1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
248 miterDirections.push_back(static_cast<float>(miterX1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
249 miterDirections.push_back(static_cast<float>(miterY1_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
250 miterDirections.push_back(static_cast<float>(miterX2_)); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
251 miterDirections.push_back(static_cast<float>(miterY2_)); |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
252 |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
253 // Add the colors of the 2 triangles (leading to 2 * 3 values) |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
254 for (unsigned int i = 0; i < 6; i++) |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
255 { |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
256 colors.push_back(color.GetRedAsFloat()); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
257 colors.push_back(color.GetGreenAsFloat()); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
258 colors.push_back(color.GetBlueAsFloat()); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
259 } |
592 | 260 } |
261 }; | |
262 | |
263 | |
264 OpenGLLinesProgram::Data::Data(OpenGL::IOpenGLContext& context, | |
265 const PolylineSceneLayer& layer) : | |
266 context_(context), | |
267 verticesCount_(0), | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
268 thickness_(static_cast<float>(layer.GetThickness())) |
592 | 269 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
270 if (!context_.IsContextLost()) |
592 | 271 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
272 // High-level reference: |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
273 // https://mattdesl.svbtle.com/drawing-lines-is-hard |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
274 // https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader |
592 | 275 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
276 size_t countVertices = 0; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
277 for (size_t i = 0; i < layer.GetChainsCount(); i++) |
592 | 278 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
279 size_t countSegments = layer.GetChain(i).size() - 1; |
592 | 280 |
281 if (layer.IsClosedChain(i)) | |
282 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
283 countSegments++; |
592 | 284 } |
285 | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
286 // Each segment is made of 2 triangles. One triangle is |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
287 // defined by 3 points in 2D => 6 vertices per segment. |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
288 countVertices += countSegments * 2 * 3; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
289 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
290 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
291 std::vector<float> coords, colors, miterDirections; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
292 coords.reserve(countVertices * COMPONENTS_POSITION); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
293 colors.reserve(countVertices * COMPONENTS_COLOR); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
294 miterDirections.reserve(countVertices * COMPONENTS_MITER); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
295 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
296 for (size_t i = 0; i < layer.GetChainsCount(); i++) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
297 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
298 const PolylineSceneLayer::Chain& chain = layer.GetChain(i); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
299 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
300 if (chain.size() > 1) |
592 | 301 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
302 std::vector<Segment> segments; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
303 for (size_t j = 1; j < chain.size(); j++) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
304 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
305 segments.push_back(Segment(chain, j - 1, j)); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
306 } |
592 | 307 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
308 if (layer.IsClosedChain(i)) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
309 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
310 segments.push_back(Segment(chain, chain.size() - 1, 0)); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
311 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
312 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
313 // Try and create nice miters |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
314 for (size_t j = 1; j < segments.size(); j++) |
592 | 315 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
316 Segment::CreateMiter(segments[j - 1], segments[j]); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
317 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
318 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
319 if (layer.IsClosedChain(i)) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
320 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
321 Segment::CreateMiter(segments.back(), segments.front()); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
322 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
323 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
324 for (size_t j = 0; j < segments.size(); j++) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
325 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
326 if (!segments[j].IsEmpty()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
327 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
328 segments[j].AddTriangles(coords, miterDirections, colors, layer.GetColor(i)); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
329 } |
592 | 330 } |
331 } | |
332 } | |
333 | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
334 assert(coords.size() == colors.size()); |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
335 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
336 if (!coords.empty()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
337 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
338 verticesCount_ = coords.size() / COMPONENTS_POSITION; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
339 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
340 context_.MakeCurrent(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
341 glGenBuffers(3, buffers_); |
592 | 342 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
343 glBindBuffer(GL_ARRAY_BUFFER, buffers_[0]); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
344 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * coords.size(), &coords[0], GL_STATIC_DRAW); |
592 | 345 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
346 glBindBuffer(GL_ARRAY_BUFFER, buffers_[1]); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
347 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * miterDirections.size(), &miterDirections[0], GL_STATIC_DRAW); |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
348 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
349 glBindBuffer(GL_ARRAY_BUFFER, buffers_[2]); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
350 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * colors.size(), &colors[0], GL_STATIC_DRAW); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
351 } |
592 | 352 } |
353 } | |
354 | |
355 | |
356 OpenGLLinesProgram::Data::~Data() | |
357 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
358 if (!context_.IsContextLost() && !IsEmpty()) |
592 | 359 { |
360 context_.MakeCurrent(); | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
361 ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT("About to call glDeleteBuffers"); |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
362 glDeleteBuffers(3, buffers_); |
592 | 363 } |
364 } | |
365 | |
366 GLuint OpenGLLinesProgram::Data::GetVerticesBuffer() const | |
367 { | |
368 if (IsEmpty()) | |
369 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
370 LOG(ERROR) << "OpenGLLinesProgram::Data::GetVerticesBuffer(): (IsEmpty())"; |
592 | 371 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
372 } | |
373 else | |
374 { | |
375 return buffers_[0]; | |
376 } | |
377 } | |
378 | |
379 | |
380 GLuint OpenGLLinesProgram::Data::GetMiterDirectionsBuffer() const | |
381 { | |
382 if (IsEmpty()) | |
383 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
384 LOG(ERROR) << "OpenGLLinesProgram::Data::GetMiterDirectionsBuffer(): (IsEmpty())"; |
592 | 385 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
386 } | |
387 else | |
388 { | |
389 return buffers_[1]; | |
390 } | |
391 } | |
392 | |
393 | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
394 GLuint OpenGLLinesProgram::Data::GetColorsBuffer() const |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
395 { |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
396 if (IsEmpty()) |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
397 { |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
398 LOG(ERROR) << "OpenGLLinesProgram::Data::GetColorsBuffer(): (IsEmpty())"; |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
399 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
400 } |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
401 else |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
402 { |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
403 return buffers_[2]; |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
404 } |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
405 } |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
406 |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
407 |
592 | 408 OpenGLLinesProgram::OpenGLLinesProgram(OpenGL::IOpenGLContext& context) : |
409 context_(context) | |
410 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
411 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
412 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
413 context_.MakeCurrent(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
414 program_.reset(new OpenGL::OpenGLProgram(context_)); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
415 program_->CompileShaders(VERTEX_SHADER, FRAGMENT_SHADER); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
416 } |
592 | 417 } |
418 | |
419 void OpenGLLinesProgram::Apply(const Data& data, | |
420 const AffineTransform2D& transform, | |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
421 unsigned int canvasWidth, |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
422 unsigned int canvasHeight, |
592 | 423 bool antialiasing, |
424 bool scaleIndependantThickness) | |
425 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
426 if (!context_.IsContextLost() && !data.IsEmpty()) |
592 | 427 { |
428 context_.MakeCurrent(); | |
2057
8bb8d9c0cfd0
added "checkStatus" argument to OpenGLProgram::Use()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
429 program_->Use(true); |
592 | 430 |
431 GLint locationPosition = program_->GetAttributeLocation("a_position"); | |
432 GLint locationMiterDirection = program_->GetAttributeLocation("a_miter_direction"); | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
433 GLint locationColor = program_->GetAttributeLocation("a_color"); |
592 | 434 |
435 float m[16]; | |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
436 transform.ConvertToOpenGLMatrix(m, canvasWidth, canvasHeight); |
592 | 437 |
438 glUniformMatrix4fv(program_->GetUniformLocation("u_matrix"), 1, GL_FALSE, m); | |
439 | |
440 glBindBuffer(GL_ARRAY_BUFFER, data.GetVerticesBuffer()); | |
441 glEnableVertexAttribArray(locationPosition); | |
442 glVertexAttribPointer(locationPosition, COMPONENTS_POSITION, GL_FLOAT, GL_FALSE, 0, 0); | |
443 | |
444 glBindBuffer(GL_ARRAY_BUFFER, data.GetMiterDirectionsBuffer()); | |
445 glEnableVertexAttribArray(locationMiterDirection); | |
446 glVertexAttribPointer(locationMiterDirection, COMPONENTS_MITER, GL_FLOAT, GL_FALSE, 0, 0); | |
447 | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
448 glBindBuffer(GL_ARRAY_BUFFER, data.GetColorsBuffer()); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
449 glEnableVertexAttribArray(locationColor); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
450 glVertexAttribPointer(locationColor, COMPONENTS_COLOR, GL_FLOAT, GL_FALSE, 0, 0); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
451 |
592 | 452 glUniform1i(program_->GetUniformLocation("u_antialiasing"), (antialiasing ? 1 : 0)); |
453 | |
454 const double zoom = transform.ComputeZoom(); | |
455 const double thickness = data.GetThickness() / 2.0; | |
456 const double aliasingBorder = 2.0; // Border for antialiasing ramp, in pixels | |
457 assert(aliasingBorder > 0); // Prevent division by zero with "t1" | |
458 | |
459 if (scaleIndependantThickness) | |
460 { | |
461 if (antialiasing) | |
462 { | |
463 double t1 = std::max(thickness, aliasingBorder); | |
464 double t0 = std::max(0.0, thickness - aliasingBorder); | |
465 | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
466 glUniform1f(program_->GetUniformLocation("u_thickness"), |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
467 static_cast<GLfloat>(t1 / zoom)); |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
468 glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
469 static_cast<GLfloat>(t0 / t1)); |
592 | 470 } |
471 else | |
472 { | |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
473 glUniform1f(program_->GetUniformLocation("u_thickness"), |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
474 static_cast<GLfloat>(thickness / zoom)); |
592 | 475 } |
476 } | |
477 else | |
478 { | |
479 if (antialiasing) | |
480 { | |
481 double t1 = std::max(thickness, aliasingBorder / zoom); | |
482 double t0 = std::max(0.0, thickness - aliasingBorder / zoom); | |
483 | |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
484 glUniform1f(program_->GetUniformLocation("u_thickness"), |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
485 static_cast<GLfloat>(t1)); |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
486 glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
487 static_cast<GLfloat>(t0 / t1)); |
592 | 488 } |
489 else | |
490 { | |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
491 glUniform1f(program_->GetUniformLocation("u_thickness"), |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
611
diff
changeset
|
492 static_cast<GLfloat>(thickness)); |
592 | 493 } |
494 } | |
495 | |
496 if (antialiasing) | |
497 { | |
498 glEnable(GL_BLEND); | |
499 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
500 glDrawArrays(GL_TRIANGLES, 0, |
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
501 static_cast<GLsizei>(data.GetVerticesCount())); |
592 | 502 glDisable(GL_BLEND); |
503 } | |
504 else | |
505 { | |
694
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
506 glDrawArrays(GL_TRIANGLES, 0, |
7c6197d9acc9
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
693
diff
changeset
|
507 static_cast<GLsizei>(data.GetVerticesCount())); |
592 | 508 } |
509 | |
510 glDisableVertexAttribArray(locationPosition); | |
511 glDisableVertexAttribArray(locationMiterDirection); | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
702
diff
changeset
|
512 glDisableVertexAttribArray(locationColor); |
592 | 513 } |
514 } | |
515 } | |
516 } |