Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Implement QQuickItem with antialiasing for custom triangle object
Forum Updated to NodeBB v4.3 + New Features

Implement QQuickItem with antialiasing for custom triangle object

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #1

    Hi,

    I am writing a QQuickItem to draw custom triangle object. I have tried to run setAntialiasing(true) but it don't work on custom QQuickItem. Many suggestions relay on the multi-sampled context but it need to set globally. I prefer a method that affect my QQuickItem item only.

    Since I am not familiar with Qt Scene Graph , should I implement my custom QSGGeometryNode or QSGMaterial?

    I found that there has a private class called QSGSmoothColorMaterial. I wonder is that already the solution of my questions.

    Thanks for any advice.

    1 Reply Last reply
    0
    • slettaS Offline
      slettaS Offline
      sletta
      wrote on last edited by
      #2

      What kind of hardware are you running on? Depending on what your target is, turning on multisampling might not be a bad choice, and that gives you antialiasing for free.

      On many embedded chips, you have cheap 4x multisampling. On most desktop chips, you have more expensive 8-16x multisampling, but on a chip with a proper graphics card, it isn't a problem. Intel chips, especially the older ones, will struggle, if it is supported at all.

      If you want to implement per-vertex antialiasing, you would need to create a QSGGeometryNode. If you add just the triangle, it will be aliased. To get antialiasing you need to add more vertices along the exterior of the triangle which fade the interior color to transparent. You could do that with a QSGGeometryNode using 6 vertices and indices making up 7 triangles (1 for the interior and 2 for each antialiasing edge).

      A trivial implementation could use geometry of QSGGeometry::ColoredPoint2D combined with QSGVertexColorMaterial, where interior vertices get alpha=1 and exterior vertices get alpha=0.

      If you want to antialiasing edge adapt based on scale factor you would need to implement your own material and take the scale factor of the matrix into account in the vertex shader and change the width of the exterior based on that.

      Good Luck :)

      1 Reply Last reply
      0
      • benlauB Offline
        benlauB Offline
        benlau
        Qt Champions 2016
        wrote on last edited by
        #3

        hi sletta,

        Thanks for your reply! Your explanation is very clear!

        My target platform is Android and iOS. I think it don't has any problem in iOS but not sure about Android.

        Is it safe to use multisampling on Android platform?

        I think the hard part of per-vertex antialising is to determine the no. of vertex should be added. Making triangle is just my first step. I need to make a lots of arrow and zoom-in is supported.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved