OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #ifndef GrPLSPathRenderer_DEFINED | 8 #ifndef GrPLSPathRenderer_DEFINED |
10 #define GrPLSPathRenderer_DEFINED | 9 #define GrPLSPathRenderer_DEFINED |
11 | 10 |
12 #include "GrPathRenderer.h" | 11 #include "GrPathRenderer.h" |
13 | 12 |
14 /* | 13 /* |
15 * Renders arbitrary antialiased paths using pixel local storage as a scratch bu
ffer. The overall | 14 * Renders arbitrary antialiased paths using pixel local storage as a scratch bu
ffer. The overall |
16 * technique is very similar to the approach presented in "Resolution independen
t rendering of | 15 * technique is very similar to the approach presented in "Resolution independen
t rendering of |
17 * deformable vector objects using graphics hardware" by Kokojima et al. | 16 * deformable vector objects using graphics hardware" by Kokojima et al. |
18 | 17 |
19 * We first render the straight-line portions of the path (essentially pretendin
g as if all segments | 18 * We first render the straight-line portions of the path (essentially pretendin
g as if all segments |
20 * were kLine_Verb) as a triangle fan, using a fragment shader which updates the
winding counts | 19 * were kLine_Verb) as a triangle fan, using a fragment shader which updates the
winding counts |
21 * appropriately. We then render the curved portions of the path using a Loop-Bl
inn shader which | 20 * appropriately. We then render the curved portions of the path using a Loop-Bl
inn shader which |
22 * calculates which portion of the triangle is covered by the quad (conics and c
ubics are split down | 21 * calculates which portion of the triangle is covered by the quad (conics and c
ubics are split down |
23 * to quads). Where we diverge from Kokojima is that, instead of rendering into
the stencil buffer | 22 * to quads). Where we diverge from Kokojima is that, instead of rendering into
the stencil buffer |
24 * and using built-in MSAA to handle straight-line antialiasing, we use the pixe
l local storage area | 23 * and using built-in MSAA to handle straight-line antialiasing, we use the pixe
l local storage area |
25 * and calculate the MSAA ourselves in the fragment shader. Essentially, we manu
ally evaluate the | 24 * and calculate the MSAA ourselves in the fragment shader. Essentially, we manu
ally evaluate the |
26 * coverage of each pixel four times, storing four winding counts into the pixel
local storage area, | 25 * coverage of each pixel four times, storing four winding counts into the pixel
local storage area, |
27 * and compute the final coverage based on those winding counts. | 26 * and compute the final coverage based on those winding counts. |
28 * | 27 * |
29 * Our approach is complicated by the need to perform antialiasing on straight e
dges as well, | 28 * Our approach is complicated by the need to perform antialiasing on straight e
dges as well, |
30 * without relying on hardware MSAA. We instead bloat the triangles to ensure co
mplete coverage, | 29 * without relying on hardware MSAA. We instead bloat the triangles to ensure co
mplete coverage, |
31 * pass the original (un-bloated) vertices in to the fragment shader, and then h
ave the fragment | 30 * pass the original (un-bloated) vertices in to the fragment shader, and then h
ave the fragment |
32 * shader use these vertices to evaluate whether a given sample is located withi
n the triangle or | 31 * shader use these vertices to evaluate whether a given sample is located withi
n the triangle or |
33 * not. This gives us MSAA4 edges on triangles which line up nicely with no seam
s. We similarly face | 32 * not. This gives us MSAA4 edges on triangles which line up nicely with no seam
s. We similarly face |
34 * problems on the back (flat) edges of quads, where we have to ensure that the
back edge is | 33 * problems on the back (flat) edges of quads, where we have to ensure that the
back edge is |
35 * antialiased in the same way. Similar to the triangle case, we pass in the two
(unbloated) | 34 * antialiased in the same way. Similar to the triangle case, we pass in the two
(unbloated) |
36 * vertices defining the back edge of the quad and the fragment shader uses thes
e vertex coordinates | 35 * vertices defining the back edge of the quad and the fragment shader uses thes
e vertex coordinates |
37 * to discard samples falling on the other side of the quad's back edge. | 36 * to discard samples falling on the other side of the quad's back edge. |
38 */ | 37 */ |
39 class GrPLSPathRenderer : public GrPathRenderer { | 38 class GrPLSPathRenderer : public GrPathRenderer { |
40 public: | 39 public: |
41 GrPLSPathRenderer(); | 40 GrPLSPathRenderer(); |
42 | 41 |
43 bool onCanDrawPath(const CanDrawPathArgs& args) const override; | 42 bool onCanDrawPath(const CanDrawPathArgs& args) const override; |
44 | 43 |
45 protected: | 44 protected: |
46 bool onDrawPath(const DrawPathArgs& args) override; | 45 bool onDrawPath(const DrawPathArgs& args) override; |
47 }; | 46 }; |
48 | 47 |
49 #endif | 48 #endif |
OLD | NEW |