[Interest] Using OpenGL with Qt

Agocs Laszlo Laszlo.Agocs at digia.com
Mon Mar 17 12:59:18 CET 2014


No, that is expected. After all it has to look up the versionFunction internals from the hash table maintained by the context.

With the design shown here, deriving GL_Model from QOpenGLFunctions* feels like an overkill indeed.

The options I see are:

1. Do not derive, just get an QOpenGLFunctions* instance. This of course leads to the f->glBlah() type of code which some (myself not included) may find ugly.

2. Use a different design. Separating the GL initialization/rendering into a separate class (e.g. GL_ModelRenderer) with a single instance could avoid the issue altogether.

Cheers,
Laszlo

________________________________________
From: interest-bounces+laszlo.agocs=digia.com at qt-project.org [interest-bounces+laszlo.agocs=digia.com at qt-project.org] on behalf of Yves Bailly [yves.bailly at sescoi.fr]
Sent: Monday, March 17, 2014 12:38 PM
To: interest at qt-project.org
Subject: Re: [Interest] Using OpenGL with Qt

Le 17/03/2014 10:05, Agocs Laszlo a écrit :
> I must correct my previous statement about not resolving functions that are not called. This deferred behavior is only true for QOpenGLFunctions. The versioned variants will resolve all functions for the given version already when initializeOpenGLFunctions() is first called with a given context.

Here's what I tried.

First I define a default GL format:
   QGLFormat fmt;
   fmt.setVersion(3, 3);
   fmt.setProfile(QGLFormat::CoreProfile);
   fmt.setStencilBufferSize(8);
   QGLFormat::setDefaultFormat(fmt);


Now let's say I have two classes:

class Gl_Model: protected QOpenGLFunctions_3_3_Core
{
   public:
     Gl_Model();
     void create();
     void draw();
   private:
     GLuint buff_ids[3];
}; // class Gl_Model

class Gl_Widget:
     public QGLWidget,
     protected QOpenGLFunctions_3_3_Core
{
     Q_OBJECT
   public:
     explicit Gl_Widget(QWidget* const parent = nullptr);
   protected:
     virtual void initializeGL() override;
     virtual void paintGL() override;
     virtual void resizeGL(int width, int height) override;
   private:
     Gl_Model* model{nullptr};
}; // class Gl_Widget

inside Gl_Model::create():
void Gl_Model::create()
{
   this->initializeOpenGLFunctions();
   /* ... */
}

inside Gl_Widget::initializeGL():
{
   QOpenGLContext* ctx = QOpenGLContext::currentContext();
   ctx->versionFunctions<QOpenGLFunctions_3_3_Core>();
   this->initializeOpenGLFunctions();
   this->model = new Gl_Model;
   this->model->create();
}


Now if I follow the program step-by-step, indeed the second call to
initializeOpenGLFunctions (inside Gl_Model::create) it will reuse some
already allocated data... but it will perform 12 searchs in a QHash<>.
If I have to create, say, 100000 instances of Gl_Model, that will
imply 1200000 searchs. I know QHash<> is quite fast, but that seems
a bit overkill to me...

Or am I missing something again?

--
      /- Yves Bailly - Software developer   -\
      \- Sescoi R&D  - http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list