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. QOpenGLWidget QSurfaceFormat irregularities
Forum Updated to NodeBB v4.3 + New Features

QOpenGLWidget QSurfaceFormat irregularities

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • A Offline
    A Offline
    asian_invasion
    wrote on last edited by A Former User
    #1

    Hello

    I was using QOpenGLWindow to render a line with MSAA enabled by using QSurfaceFormat::setDefaultFormat(format) and it works fine, however if I use the exact same code except I subclass it and use QOpenGLWidget something odd happens,

    #include "test.h"
    #include "Display.h"
    #include <QtWidgets/QApplication>
    #include <QSurfaceFormat>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {	
    	QApplication a(argc, argv);	
    	QSurfaceFormat format;
    	format.setVersion(3, 3);
    	//format.setOption(QSurfaceFormat::DebugContext);
    	format.setProfile(QSurfaceFormat::CoreProfile);
    	format.setDepthBufferSize(24);
    	format.setSamples(16);
    	format.setStencilBufferSize(8);
    	QSurfaceFormat::setDefaultFormat(format);
    	ProjectileMotionSim w;
    	w.show();
    	return a.exec();
    }
    

    in the subclass's constructor the format is this:

    QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 16, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile))
    

    notice how the sample is set at 16 as specified by me in the main function, this is what I expect to see,
    however in the initializeGL function the format now looks like this:

    QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile))
    

    the only things that I can change in the second one(even if I set it in the main function) is the depthbuffersize and the OpenGLversion nothing else will change. Also if I set the version to 2.0 I get this:

    ARB::createContext: wglCreateContextAttribsARB() failed (GL error code: 0x502) for format: QSurfaceFormat(version 2.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 16, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile)), shared context: 0x0 ()
    ARB::createContext: wglCreateContextAttribsARB() failed (GL error code: 0x502) for format: QSurfaceFormat(version 2.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile)), shared context: 0x30000 ()
    

    This does not happen when using QOpenGLWindow, it uses 2.0 fine, The documentation did mention if the system does not support MSAA the request will get ignored which is clearly not the case here since I can set (something) to 16 samples.

    any help would be appreciated,
    thanks

    m.sueM 1 Reply Last reply
    0
    • A asian_invasion

      Hello

      I was using QOpenGLWindow to render a line with MSAA enabled by using QSurfaceFormat::setDefaultFormat(format) and it works fine, however if I use the exact same code except I subclass it and use QOpenGLWidget something odd happens,

      #include "test.h"
      #include "Display.h"
      #include <QtWidgets/QApplication>
      #include <QSurfaceFormat>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {	
      	QApplication a(argc, argv);	
      	QSurfaceFormat format;
      	format.setVersion(3, 3);
      	//format.setOption(QSurfaceFormat::DebugContext);
      	format.setProfile(QSurfaceFormat::CoreProfile);
      	format.setDepthBufferSize(24);
      	format.setSamples(16);
      	format.setStencilBufferSize(8);
      	QSurfaceFormat::setDefaultFormat(format);
      	ProjectileMotionSim w;
      	w.show();
      	return a.exec();
      }
      

      in the subclass's constructor the format is this:

      QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 16, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile))
      

      notice how the sample is set at 16 as specified by me in the main function, this is what I expect to see,
      however in the initializeGL function the format now looks like this:

      QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile))
      

      the only things that I can change in the second one(even if I set it in the main function) is the depthbuffersize and the OpenGLversion nothing else will change. Also if I set the version to 2.0 I get this:

      ARB::createContext: wglCreateContextAttribsARB() failed (GL error code: 0x502) for format: QSurfaceFormat(version 2.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 16, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile)), shared context: 0x0 ()
      ARB::createContext: wglCreateContextAttribsARB() failed (GL error code: 0x502) for format: QSurfaceFormat(version 2.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile  QSurfaceFormat::OpenGLContextProfile(CoreProfile)), shared context: 0x30000 ()
      

      This does not happen when using QOpenGLWindow, it uses 2.0 fine, The documentation did mention if the system does not support MSAA the request will get ignored which is clearly not the case here since I can set (something) to 16 samples.

      any help would be appreciated,
      thanks

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi @asian_invasion

      You should set QSurfaceFormat before QApplication.

      -Michael.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        asian_invasion
        wrote on last edited by
        #3

        Thanks for the reply,

        I tried that, and it still doesn't work

        thanks

        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