I am creating a path and drawing it n number of time by appending data to the same. i am calling vgDrawPath just once and cause of that all the line segments are of the same color. Is there a way to draw line segments of different colors and still use vgDrawPath just once?
No. Use multiple paths (at least one per each color).
I suppose if your lines are in a very regular pattern and not touching, it might be possible to construct a linear gradient to color them differently, but I don’t see that scenario as likely.
Why are you determined to use only path anyways? It’s not like you’re saving any work to the display driver by submitting it all in one go.
I want to minimize the amount of CPU usage and the time it takes to draw on the board. Hence I was appending everything to one path so I call VgDrawpath() just once, which I think is the most tedious call. All the line segments I am using are the same paths. But I am not able to draw multiple paths but not of different colors. I was going through the manual and found VgAppendPath() and I am wondering if it can help me out. It would be great if you could point me in the right direction.
I’ve said this before (as recently as in the answer to your last post), but cramming everything in one giant vgPath is not a way to make things run faster. In fact, the opposite can easily happen.
To understand why, please refer to the spec in section “8.7.2 Stroking Paths”. In monolithic paths, that intersection must be detected and eliminated by the OpenVG driver. Chances are high, that this will involve at least a O( n log(n) ) operation on the number of segments [and perhaps even an O( n^2) operation]. This operation is complex (usually all intersection points of the widened geometry need to be found), and odds are high it will be done in software. Not all calls to vgDrawPath() are created equal (i.e. 50 calls @ 10ms each < 1 call @ 750 ms)! In general the length the vgDrawPath() call takes is directly proportional to the number of pixels on the screen you are changing times the complexity of the operation you are doing to them ( please note: (pixels_a+pixels_b)complexity_c == pixels_acomplexity_c + pixels_b*complexity_c ).
If you keep the size of paths sane, odds are it will run much faster than a single huge 5000 segment mega-path. That does not mean you need 1 path per segment, but it is probably best to stick to under 200 segments or so (give or take a couple hundred) per path.
Much more important than submitting stuff in one giant batch is to call vgAppendPathData() only once, and then call vgDrawPath() repeatedly without modifying the geometry. So, for example, if you’re animating, it’s thus better to have a separate path for each animation frame, then to be updating the same path each frame with new data.
So just use different paths for different colors. It’ll make you life easier, and I doubt it will have any great negative impact on rendering speed.
The size of path I am using is between 20 - 30 and I think that number is reasonable enough. Presently the render time is low but I want to reduce it further and that is why I was planning to call VGdrawPath() just once. If I draw for all the segments individually as compared to one call, my cpu time as well as the render time increases. Creating several paths is true is size of paths is really huge. I read at multiple places that there is an overhead of VGDrawPath(). I was just wondering if I that can be avoided some how.
It is probably worth considering that Draw commands will have both fixed overhead, and some overhead the first time a path is drawn - the nature of the implementation will be the determining factor in how large or small the division is. In general I would recommend that you work on the assumption that any OpenVG implementation may work better when given the opportunity to partially cache some of the data required:
- Use path capabilities, if you know you are not going to use some operations, tell OpenVG,
- Try to avoid operations that could invalidate cached data, such as:
> Changing a paths segment data -> create once and use multiple times,
> Drawing a path multiple times with different stroke/dash parameters -> consider using multiple path objects to minimise the ‘path to params’ ratio.
For your use case of drawing lines with different colours, I would say that the most generally efficient way of drawing would be to create one path, add data to it once, use vgTranslate/Rotate etc for positioning, and use vgSetColor to change the paint colour if you are just using solid paint. If you are using more complicated paints, you may also see benefit in maintaining multiple paint objects. If you are altering stroke/dash parameters, consider creating multiple copies of your path.
Also, if you are targeting a specific platform, there may be some more advice people could give you.
If you do find anything that helps (or not), please post back your findings