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