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

发布时间:2020-07-14 02:42:09 作者:fengyuzaitu
来源:网络 阅读:467

渲染代码

 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.


推荐阅读:
  1. AGG第四十五课 性能优化
  2. AGG第三十九课 rasterizer_scanline_aa画线函数疑惑

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

aa agg outline

上一篇:Redis Cluster集群部署方案

下一篇:MyBatis拦截器:给参数对象属性赋值

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》