Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: GLMath assignment to swizzle doesn't work ?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2009
    Location
    amsterdam NL
    Posts
    18

    GLMath assignment to swizzle doesn't work ?

    Hi there,

    I notice that the following doesn't seem to work:

    mat4 mat;
    mat[3].xyz = vec3( 10.0f, 10.0f, 10.0f );

    Is this due to my compilationsettings, or is it not a feature of GLM ?

    I figured GLM has a full GLSL implementation, and since you can do this in GLSL, it should work..

    anyone ?

    thanks,

    Jochem

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2009
    Location
    amsterdam NL
    Posts
    18

    Re: GLMath assignment to swizzle doesn't work ?

    hmm, looking at type_vec4.inl in GLMath-0.8.4.0 I see:

    template <typename valType>
    inline tvec3<valType> tvec4<valType>::swizzle(comp x, comp y, comp z) const {
    return tvec3<valType>(
    (*this)[x],
    (*this)[y],
    (*this)[z]);
    }

    this creates a new instance of a vec4 and so doesn't offer access to the members of a vec4, which doesn't comply with GLSL spec 1.20.8 (page 34, "The component group notation can occur on the left hand side of an expression." ) as GLM claims.

    J

  3. #3
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    937

    Re: GLMath assignment to swizzle doesn't work ?

    #include <glm/setup.hpp>
    #define GLM_SWIZZLE GLM_SWIZZLE_XYZW
    #include <glm/glm.hpp>

    int main()
    {
    glm::vec4 v1(1, 2, 3, 4);
    glm::vec4 v2;
    glm::vec4 v3;
    glm::vec4 v4;
    v2.wyxz = v1.zyxw;
    v3 = v1.xzyw;
    v4.xzyw = v1;

    return 0;
    }

    And that will work.
    I'm not sure if I can advice to use it... that's why the feature isn't able by default.

    xyzw is actually a #define which can bring some compatibility with OSs or software libraries.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •