<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
<small>We can avoid using stencil test for cases where drawing twice
will produce same result.<br>
For example, opaque solid source with op OVER.<br>
<br>
Clearing entire stencil buffer for every stroke might be quite
expensive for most of drivers<br>
and GPUs. It would be good to restrict clearing area within
bounded rectangle.<br>
<br>
And have you measured the effect of glColorMask() in clipping
code?<br>
AFAIK, it was extremely expensive. (But I didn't measure it with
recent GPUs and drivers.)<br>
<br>
Here's my suggestion.<br>
<br>
if (! used_stencil_buffer_for_clip) {<br>
</small><small> glStencilFunc (GL_NEVER, ...); // Nothing will be
drawn to the color buffer<br>
glStencilOp (GL_ONE, GL_ONE, GL_ONE)</small>;<br>
<small> drawBoundedRectangle (); // Stroke extent</small><br>
<small>}<br>
<br>
One last thing is that you consumes stencil buffer to prevent
overlap thus it would be hard<br>
to cache stencil buffer for a clip.<br>
<br>
</small>On 10/17/2011 11:56 PM, Henry (Yu) Song - SISA wrote:
<blockquote
cite="mid:3955FA337689574EB32F94B12A7E6E9E0B18C84B@ex10mail"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.5pt;
        font-family:Consolas;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:Consolas;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">When stroking we do
not send our polygon to the tessellator, so<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">it may have
overlapping stroke components. Use the stencil buffer<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">to prevent stroke
components from overlapping.<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">---<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">src/cairo-gl-msaa-compositor.c
| 26 ++++++++++++++++++++++++++<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">1 files changed, 26
insertions(+), 0 deletions(-)<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p> </o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">diff --git
a/src/cairo-gl-msaa-compositor.c
b/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">index
7a0e828..01ef40f 100644<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">---
a/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+++
b/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">@@ -247,6 +247,27 @@
_stroke_shaper_add_quad (void *closure,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
quad);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">}<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+static void<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+_prevent_overlapping_drawing
(cairo_clip_t *clip,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+
cairo_bool_t used_stencil_buffer_for_clip)<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+{<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ if
(used_stencil_buffer_for_clip == FALSE) {<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ /* Enable the
stencil buffer, even if we have no clip so that<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ we can use
it below to prevent overlapping shapes. We initialize<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ it all to
one here which represents infinite clip. */<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ glDepthMask
(GL_TRUE);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ glEnable
(GL_STENCIL_TEST);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+
glClearStencil(1);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ glClear
(GL_STENCIL_BUFFER_BIT);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ glStencilFunc
(GL_EQUAL, 1, 1);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ }<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ /* This means
that once we draw to a particular pixel nothing else can<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ be drawn
there until the stencil buffer is reset or the stencil test<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ is disabled.
*/<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ glStencilOp
(GL_ZERO, GL_ZERO, GL_ZERO);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+}<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">static
cairo_int_status_t<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">_cairo_gl_msaa_compositor_stroke
(const cairo_compositor_t *compositor,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
cairo_composite_rectangles_t *composite,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">@@ -261,6 +282,8 @@
_cairo_gl_msaa_compositor_stroke (const
cairo_compositor_t *compositor,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
cairo_gl_surface_t *dst = (cairo_gl_surface_t *)
composite->surface;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> struct
_tristrip_composite_info info;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+ cairo_bool_t
used_stencil_buffer_for_clip = FALSE;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> if (antialias !=
CAIRO_ANTIALIAS_NONE)<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> return
CAIRO_INT_STATUS_UNSUPPORTED;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">@@ -296,11 +319,14 @@
_cairo_gl_msaa_compositor_stroke (const
cairo_compositor_t *compositor,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> if (!
_cairo_composite_rectangles_can_reduce_clip (composite,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
composite->clip))<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> {<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+
used_stencil_buffer_for_clip = TRUE;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> status =
_draw_clip_to_stencil_buffer (info.ctx, &info.setup,
composite->clip);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> if (unlikely
(status))<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> goto finish;<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> }<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+
_prevent_overlapping_drawing (composite->clip,
used_stencil_buffer_for_clip);<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">+<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"> status =
_cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *)
path,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
style,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">
ctm,<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">--
<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";">1.7.4.1<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p> </o:p></span></p>
<p class="MsoPlainText">--<o:p></o:p></p>
<p class="MsoPlainText">cairo mailing list<o:p></o:p></p>
<p class="MsoPlainText"><a moz-do-not-send="true"
href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><o:p></o:p></p>
<p class="MsoPlainText"><a moz-do-not-send="true"
href="http://lists.cairographics.org/mailman/listinfo/cairo">http://lists.cairographics.org/mailman/listinfo/cairo</a><o:p></o:p></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p> </o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;
font-family: "Courier New";"><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
--
cairo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cairo@cairographics.org">cairo@cairographics.org</a>
<a class="moz-txt-link-freetext" href="http://lists.cairographics.org/mailman/listinfo/cairo">http://lists.cairographics.org/mailman/listinfo/cairo</a></pre>
</blockquote>
<br>
</body>
</html>