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....@qt-project.org 
[interest-bounces+laszlo.agocs=digia....@qt-project.org] on behalf of Yves 
Bailly [yves.bai...@sescoi.fr]
Sent: Monday, March 17, 2014 12:38 PM
To: interest@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@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to