[Interest] Using OpenGL with Qt
Sean Harmer
sean.harmer at kdab.com
Mon Mar 17 16:03:49 CET 2014
On Monday 17 March 2014 13:42:04 Yves Bailly wrote:
> Le 17/03/2014 12:59, Agocs Laszlo a écrit :
> > 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.
> As you say, "some" find it ugly ;-) myself included, but I'm not the only
> one.
> > 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.
> This would probably be the best approach. However this is not a new project,
> we're dealing with a huge (and old) code base, such a refactoring is not
> (yet) an option.
>
> So I'm back to my initial question: can Glew be used nicely with Qt? Seems
> so in my quick test program (even using QOpenGLShaderProgram), but I'm
> wondering in larger contexts.
>
> Thanks anyway for your inputs Laszlo :-)
I would also suggest refactoring to separate out the data you're rendering
(the 10,000 instances) and how you render it (the function pointers).
In fact if you're looking at rendering 10k instances of something you probably
want to be looking at glDrawElementsInstanced() or maybe even
glMultiDrawIndirect() type functions.
The cost of even just iterating over 10k items and calling a function on each
per frame will be bad enough but if each of those then has to call a GL draw
call that will be horrible for performance. Much better to put the per-
instance data into another VBO and use glVertexAttribDivisor and
glDrawElementsInstanced(). If you need more then the indirect draw calls are
your friend.
As a relatively quick alternative just make one QOpenGLFunctions_3_3_Core
object and pass a pointer to it around to your 10k instances. Yes, you need
the gl->glBlah type sytanx but that seems much better than having 10k
instances of the functions object.
Cheers,
Sean
--
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions
More information about the Interest
mailing list