Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting Maximum Samples for AntiAliasing with an OpenGL-enabled QWindow ...
QtWS25 Last Chance

Setting Maximum Samples for AntiAliasing with an OpenGL-enabled QWindow ...

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k Views
  • 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.
  • T Offline
    T Offline
    tmason101
    wrote on last edited by
    #1

    Hello,

    I'd like to set the maximum number of FSAA anti-aliasing samples in my QWindow upon creation/initialization.

    Currently, the constructor for my QWindow looks like this:

    @
    setSurfaceType(QWindow::OpenGLSurface);
    QSurfaceFormat QTOpenGLProperties;
    QTOpenGLProperties.setProfile(QTOpenGLProperties.CompatibilityProfile);
    /*

    This code errors out because I would need to call initializeOpenGLFunctions() first.

    int MaxSamples = 0;
    glGetIntegerv(GL_MAX_SAMPLES, &MaxSamples);
    QTOpenGLProperties.setSamples(MaxSamples);

    */
    QTOpenGLProperties.setSamples(4);
    setFormat(QTOpenGLProperties);
    setAnimating(true);
    installEventFilter(this);
    @

    What I would like to do is call the setSamples() function with the maximum number of samples the graphics card supports.

    Of course, later in the program I would still need to call glENABLE(GL_MULTISAMPLE) to enable multisampling.

    So how can I set the samples to be the maximum number?

    Thank you.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It's a classic OpenGL context chicken and egg problem. To get GL_MAX_SAMPLES you need a context and to create a context you need that value.

      The solution is to create a dummy context, make it current, get the value, destroy the dummy and use the value in your "real" context creation.

      Something like this:
      @
      GLint getMaxSamples() {
      GLint maxSamples = 0;
      QOffscreenSurface sfc;
      sfc.create();
      QOpenGLContext ctx;
      if(ctx.create()) {
      ctx.makeCurrent(&sfc);
      glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
      ctx.doneCurrent();
      }
      return maxSamples;
      }
      @

      The other way is to set the sample count to some high value (e.g. 1000) and when the context is created it will give you the most it can. You can then check with samples() what value was used. I'm not sure this is a defined behavior (might be, haven't checked) but it works at least on my machine.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tmason101
        wrote on last edited by
        #3

        I see; looks good.

        I will try this and update the post on how it goes.

        Thank you very much.

        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