Boost logo

Boost :

Subject: Re: [boost] Review manager for Boost QVM?
From: Emil Dotchevski (emil_at_[hidden])
Date: 2014-06-06 16:00:36


On Fri, Jun 6, 2014 at 11:50 AM, Erik H <ice.rikh_at_[hidden]> wrote:
> Hi Emil,
>
> Apologies for being yet another random support requester :) I use GLM
> <http://www.g-truc.net/project-0016.html#menu> here and there and boost
> quite a bit; replacing the GLM dependency with boost::QVM is therefore
> attractive, assuming it is approved. As a GLM user, I have a couple
> questions:

Ha, I didn't mean to imply that I'm annoyed by support questions. :)

> Would I have to use QVM with my own matrix type if I want to feed a QVM
> matrix to glUniformMatrix4fv without a temp copy? With GLM, I do this
> using, for example, glUniformMatrix4fv(fooLoc, 1, GL_FALSE,
> glm::value_ptr(fooMatrix)).

If a matrix type stores its values as anything but a 1-dimensional
array in column-major order, you can't (portably) feed it into
glUniformMatrix4fv without a temporary; at least it'd require a cast,
which in theory may not work on some platform.

The solution if you use QVM is to define your own matrix type that
stores the values as an array internally, which would let you pass it
to OpenGL without a temp:

struct gl_mat4
{
  float el[16];
};

Then you specialize the m_traits type from the QVM library to enable
the appropriate matrix operations for objects of type gl_mat4:

template <>
struct m_traits<gl_mat4>
{
    static int const rows = 4;
    static int const cols = 4;
    typedef float scalar_type;

    template <int R,int C> static scalar_type r( gl_mat4 const & m ) {
return m.el[C*4+R]; }
    template <int R,int C> static scalar_type & w( gl_mat4 & m ) {
return m.el[C*4+R]; }

    static scalar_type ir( int r, int c, gl_mat4 const & m ) { return
m.el[c*4+r]; }
    static scalar_type & iw( int r, int c, gl_mat4 & m ) { return m.el[c*4+r]; }
};

Now if you want to pass a gl_mat4 to glUniformMatrix4fv, you just do
m.el, yet you get all matrix operations automatically working for
gl_mat4 objects, including if you mix them with other matrix types,
e.g. the ones that come from the 3D engine you use, or the physics
simulation library you use, etc.

HTH,
Emil


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk