码迷,mamicode.com
首页 > 其他好文 > 详细

AGG第三十四课 stroke_aa和outline_aa渲染线段效率对比

时间:2017-09-07 15:01:49      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:agg outline_aa stroke

渲染代码

 void TestStrokeAAPerformance()

  {

   agg::rendering_buffer &rbuf = rbuf_window();

   agg::pixfmt_bgr24 pixf(rbuf);

 

   typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;

   renderer_base_type renb(pixf);

 

   typedef agg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;

   renderder_scanline_type rensl(renb);

 

   agg::rasterizer_scanline_aa<> ras;

   agg::scanline_u8 sl;

   ras.reset();

 

   renb.clear(agg::rgba8(255,255,255));

   int nPointX[5]={20,80,20,80,20};

   int nPointY[5]={20,20,80,80,20};

 

   agg::path_storage ps;

   ps.move_to(nPointX[0],nPointY[0]);

 

   for (int i =1; i<= 4; i++)

    {

     ps.line_to(nPointX[i],nPointY[i]);

     ps.move_to(nPointX[i],nPointY[i]);

    }

stroke(trans);

   agg::conv_stroke<agg::path_storage> stroke(ps);

   stroke.width(nLineWidth);

   int start = ::GetTickCount();

   ras.gamma(agg::gamma_threshold(0.5));//取消抗锯齿;注释使用抗锯齿功能

   for (int x=0;x<1000;x++)

    {

     ras.add_path(stroke);

    }

   agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));

 

   int end = ::GetTickCount();

   int costTime = 0;

   costTime = end -start;

  }

 

 void TestOutLineAAPerformance()

  {

   agg::rendering_buffer &rbuf = rbuf_window();

   agg::pixfmt_bgr24 pixf(rbuf);

 

   typedef agg::renderer_outline_aa<agg::pixfmt_bgr24> renderer_type;

   agg::line_profile_aa profile;

   profile.gamma(agg::gamma_threshold(0.5));

   profile.width(nLineWidth);//强制性要求设置线宽

   renderer_type ren(pixf,profile);

 

   typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;

   rasterizer_type ras(ren);

 

   ren.color(agg::rgba8(255,0,0));//可选

   int nPointX[5]={20,80,20,80,20};

   int nPointY[5]={20,20,80,80,20};

 

   agg::path_storage ps;

   ps.move_to(nPointX[0],nPointY[0]);

 

   for (int i =1; i<= 4; i++)

    {

     ps.line_to(nPointX[i],nPointY[i]);

     ps.move_to(nPointX[i],nPointY[i]);

    }

   //agg::conv_transform<agg::path_storage,roundoff>trans(ps,roundoff());

   int start = ::GetTickCount();

   for (int x=0;x<1000;x++)

    {

     ras.add_path(ps);

    }

   int end = ::GetTickCount();

   int costTime = 0;

   costTime = end -start;

  }

 

简单说明:agg::gamma_threshold(0.5)主要应用于关闭抗锯齿功能,注释掉所在的代码行就可以启用抗锯齿功能。


3结论

1)是否设置抗锯齿,对于渲染的速度没有多大的帮助,不引入抗锯齿,耗时稍微多了一点。

2)在渲染细微的线的时候,采用outline_aa更快,如果是厚线,采用stroke_aa更好!!

 

如下是作者的观点:

1)亚像素精度和速度没有多大的关系

2)一般情况下,rasterizer_outline_aa渲染的速度是conv_strokerasterizer_scanline_aa的两倍。但是有非常明显的限制,只支持miter连接,生成一些工件(artifacts),在渲染厚线的时候更加明显。

3)实际上渲染锯齿的厚线远比抗锯齿的厚线更加的复杂,看起来可能非常奇怪。所以是否抗锯齿不会加快渲染速度。

4)渲染厚线(是否抗锯齿)是一项非常复杂的操作,目前只能够通过strokerscanline rasterizer配合工作使用。如果你需要一个非常非常快的渲染厚线的方法,AGG恐怕无法胜任,可能需要硬件加速,但是可能会有更多的限制!!

邮件观点

Having subpixel accuracy doesn‘t reallymatter for speed.

In general, rasterizer_outline_aa worksabout twice faster than conv_stroke

plus rasterizer_scanline_aa. But it hascertain restrictions (only miter joins)

and produces some artifacts, especiallywith thick lines.

 

It may seem strange, but it‘s moredifficult to draw aliased thick polyline

than anti-aliased one. You anyway have toconsider line joins at least. To turn

off anti-aliasing you can use thefollowing:

 

agg::line_profile_aa profile(10.0,agg::gamma_threshold(0.5));

 

But it won‘t speed up rendering.

Fully correct thick outline (aliased oranti-aliased) is a very complex task

and can be solved only with the strokerplus scanline rasterizer.

If you really need to draw thick lines veryvery fast, I‘m afraid that AGG is

not what you need. You can try somethingelse, with hardware acceleration

But this method is even more restrictivethan the general stroker.


AGG第三十四课 stroke_aa和outline_aa渲染线段效率对比

标签:agg outline_aa stroke

原文地址:http://fengyuzaitu.blog.51cto.com/5218690/1963387

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!