static/local array

Discussion in 'C++' started by Chris Forone, Jan 10, 2013.

  1. Chris Forone

    Chris Forone Guest

    hello,

    i have some strange behavior in my multithreaded app. i do some
    matrix-multiplications in a methode. if i use local arrays there it
    works, but if i use a static member array (some kind of reusable array)
    it doesnt work anymore. some code snippets:

    [matrix multiplication]
    template <typename T>
    inline void MultiplyMatrix(T(&first)[16], T(&second)[16])
    {
    GLfloat result[16];

    for (std::size_t i(0); i < 16; i += 4)
    for (std::size_t j(0); j < 4; ++j)
    result[i + j] = first * second[j]
    + first[i + 1] * second[j + 4]
    + first[i + 2] * second[j + 8]
    + first[i + 3] * second[j + 12];

    std::copy(result, result + 16, first);
    }

    [here i use matrix multiplication, write to local/static array]
    void Object::Draw() const
    {
    GLfloat localTempMatrix[] =
    {
    1.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 1.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
    };

    localTempMatrix[12] = position[Coordinate::X];
    localTempMatrix[13] = position[Coordinate::Y];
    MultiplyMatrix(localTempMatrix, projectionMatrix);

    GLint programId(0);
    glGetIntegerv(GL_CURRENT_PROGRAM, &programId);

    glUniformMatrix4fv(glGetUniformLocation(programId, "matrix"), 1,
    GL_FALSE, localTempMatrix);
    ....
    }

    thanks a lot!

    cheers, chris
     
    Chris Forone, Jan 10, 2013
    #1
    1. Advertising

  2. Chris Forone

    Chris Forone Guest

    ok, i now use the new std::array<float, 16> and it works perfect. thanks
    a lot!

    cheers, chris
     
    Chris Forone, Jan 10, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    1
    Views:
    783
    George Ter-Saakov
    Jun 26, 2003
  2. =?Utf-8?B?WVNVVA==?=

    Access local port or Running local exe file

    =?Utf-8?B?WVNVVA==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    532
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  3. Jim in Arizona
    Replies:
    8
    Views:
    4,990
    Jim in Arizona
    Jan 24, 2006
  4. Patrick Hoffmann
    Replies:
    3
    Views:
    2,878
    Christian Jan├čen
    Aug 8, 2003
  5. Martin Wells

    Static inline functions with static local variables

    Martin Wells, Oct 6, 2007, in forum: C Programming
    Replies:
    10
    Views:
    721
    Army1987
    Oct 8, 2007
Loading...

Share This Page