c++ - Draw a dashed and dotted bezier curve in QML -
i've seen there example implementation of a bezier curve in qml, i'm looking hint how implement dashed or dotted bezier curve line. far see, tha authors of bezier curve example using qsggeometrynode
store inside qsggeometry
qsgflatcolormaterial
material applied on it. create list of points , draw segments between them.
is possible write shader
, apply qsgflatcolormaterial
(to display line dashed
, dotted
, etc)?
eventually, possible store more 1 qsggeometry
inside qsggeometrynode
?
update
i implement in "pure qtquick
" - not in "old" interfaces (like qpainter etc
) - because not want use something, switches context (opengl , cpu). prefer solution custom shader (if doable) - because i'll have more possibilities in implementing custom , feel (dashed, doted, colored, maybe animated etc).
if not possible, i'll use qpainter
.
i don't think task candidate implementing using qsggeometrynode
, easier implement using qpainter
based drawing , qquickpainteditem
. still benefits of opengl, since qpainter
supports gl drawing , still faster software. can use stock qpen
stock dotted or dashed patterns or make own simple qvector
.
alternatively, can go custom gl drawing approach instead of using classes provided qt, pretty limited when comes representing advanced compound geometry. can use instancing (if available) improve performance further, , position dashes or dot geometry along path curve.
last not least, can use qml canvas element, supports pretty same operations qpainter
, offers same performance.
edit: update suggests, missed part said qpainter
can draw in both software , gl, gl drawing being faster. also, drawing gl context, don't have move framebuffer cpu gpu memory, kept in gpu memory. no overhead. animations , other stuff, sure, not possible qpainter
limited whatever qpen
provides - different joins, caps , on can used modify shape extent, no miracles... won't possible shaders too, possible custom geometry. , if use qobject
based object each dash/dot element in order independently animate them, end quite expenssive, qobject
heavy , should not used such light hand. custom gl rendering fbo pretty way go if want kind of flexibility, have move out of qtquick api , gl land.
at rate, dashed line shader should not complex, color fragment based on distance curve , "period" along length. found this example, haven't tried myself. animate thresholds, use sine function funky looking styling.
as "pure" qtquick implementation, api has not been designed handle such type of drawing tasks, why canvas element provided fill gap , advanced paining functionality qml/js. canvas wrapper around qpainter
draws onto fbo.
in end doesn't boil down possible/impossible approach makes sense , efficient @ getting job done. try qquickpainteditem
approach first, since easiest, if not happy performance, can implement more complex solution , profile against first. after all, why qquickpainteditem
introduced in first place - handle legacy painting not convenient qquickitem
class.
Comments
Post a Comment