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

Reply via email to