[Interest] Drawing dashed line with QSGSimpleMaterialShader
Gunnar Sletta
gunnar at sletta.org
Mon Jun 6 12:29:13 CEST 2016
> On 06 Jun 2016, at 09:27, Artem Fedoskin <afedoskin3 at gmail.com> wrote:
>
> Hi Gunnar,
>
> Thank you for your reply.
>
> > An alternative approach would be to generate the line segments for the dashes and combining that with QSGGeometry::>defaultAttributes_ColorizedPoint2D() and QSGVertexColorMaterial. It will be a bit more work to prepare and take up a bit more >memory, but on the plus side, it will batch in the renderer, so it will probably be faster to draw if you have many instances of these >dashed objects. The modelview/cos based implementation you link to will not support batching because each line needs a unique >shader state, the model view matrix and perhaps also the source point.
>
> Initially I wanted to choose this approach but then I thought that with custom shaders it makes more sense as I can separate geometry and material. I didn't know that batching is not applicable to shaders. Are there any ways to do it with shaders and allow batching?
If you don't care about the dashes starting on the exact line start, you could replace the modelview matrix and line source offset with picking up gl_FragCoord in the fragment shader.
>
> Another question - is there any way to draw text solely in Scene Graph using QSG classes? I need to draw a lot of text labels and what only came to my mind is to draw them using QPainter on a QImage and store it as a QSGSimpleTextureNode in the node itself.
Nope, the text API is all internally, unfortunately. Going through the QImage + texture node code path shouldn't be too bad though.
>
> Regards, Artem
>
> 2016-06-06 7:39 GMT+02:00 Gunnar Sletta <gunnar at sletta.org>:
>
> > On 05 Jun 2016, at 00:50, Artem Fedoskin <afedoskin3 at gmail.com> wrote:
> >
> > As I understand there is no way to draw dashed line in Qt Quick Scene Graph so I decided to create shader material to do this.
> > I'm trying to apply this approach http://korkd.com/2012/02/15/dashed-lines/ to this example http://doc.qt.io/qt-5/qtquick-scenegraph-simplematerial-example.html.
> > • How can I get ModelView matrix in my shader? I need to multiply ModelView matrix by vertex to get its current position.
>
> Hi Artem,
>
> The model view matrix is part of the QSGMaterialShader::RenderState that is passed in to the QSGMaterialShader::updateState() function which you use to apply the state for you material.
>
> > • How in this example works QSGGeometry::defaultAttributes_TexturedPoint2D? What values does it store?
>
> The vertex shader in the code you link only uses a colorized 2D point, one vec4 for the position and one vec4 for the color, so you want that kind of vertex structure. QSGGeometry::defaultAttributes_ColorizedPoint2D() implements that for 2D at least.
>
> > • How can I pass sourcePoint (the first point of a line) to my shader?
>
> It is a uniform, so you write it during the QSGMaterialShader::updateState() function.
>
> > If someone knows better way to draw dashed line I would be grateful to you for telling me it.
>
> An alternative approach would be to generate the line segments for the dashes and combining that with QSGGeometry::defaultAttributes_ColorizedPoint2D() and QSGVertexColorMaterial. It will be a bit more work to prepare and take up a bit more memory, but on the plus side, it will batch in the renderer, so it will probably be faster to draw if you have many instances of these dashed objects. The modelview/cos based implementation you link to will not support batching because each line needs a unique shader state, the model view matrix and perhaps also the source point.
>
> cheers,
> Gunnar
>
> >
> > Regards, Artem
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
>
>
More information about the Interest
mailing list