1Rendering Code
void Teststrokeaaperformance ()
{
Agg::rendering_buffer &rbuf = Rbuf_window ();
Agg::p ixfmt_bgr24 pixf (RBUF);
typedef agg::renderer_base<agg::p ixfmt_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::p ath_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::p ath_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::p ixfmt_bgr24 pixf (RBUF);
typedef agg::renderer_outline_aa<agg::p ixfmt_bgr24> renderer_type;
AGG::LINE_PROFILE_AA profile;
Profile.gamma (Agg::gamma_threshold (0.5));
Profile.width (nlinewidth);// mandatory requirement to set the line width
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));/ /Optional
int npointx[5]={20,80,20,80,20};
int npointy[5]={20,20,80,80,20};
AGG::p ath_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::p Ath_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;
}
Simple Note:agg::gamma_threshold (0.5) is primarily used to turn off antialiasing, and the line of code where it is commented out can enable antialiasing.
3Conclusion
1) Whether anti-aliasing is set, the speed of rendering is not much help, do not introduce anti-aliasing, time-consuming a little more.
2) in the rendering of small lines, the use of Outline_aa faster, if it is thick line, the use of STROKE_AA better!!
Here is the author's view:
1) sub-pixel accuracy and speed not much of a relationship
2) In general,the speed of Rasterizer_outline_aa rendering is twice times that of Conv_stroke and rasterizer_scanline_aa . However, there are very obvious restrictions, only support miter connection, generate some artifacts (artifacts), when rendering thick line more obvious.
3) In fact, the thick lines that render the jagged edges are far more complex than the thick lines of antialiasing, and may seem very strange. So antialiasing does not speed up rendering.
4) rendering thick lines (anti-aliasing) is a very complex operation that is currently only available with Stroker and scanline rasterizer . If you need a very very fast way to render thick lines,AGG may not be able to do the job, might require hardware acceleration, but there may be more restrictions!!
4Message View
Have 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 has 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's won ' t speed up rendering.
Fully correct thick outline (aliased oranti-aliased) is a very complex task
And can is solved only with the Strokerplus scanline rasterizer.
If you really need to draw thick lines veryvery fast, I ' m afraid that AGG are
not need. You can try somethingelse, with hardware acceleration,
But this method was even more Restrictivethan the general Stroker.
Stroke_aa and OUTLINE_AA rendering segment efficiency comparison