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 5 of 5

Thread: multiply 2 matrices: whats faster: "manually" or via OpenGL?

Hybrid View

  1. #1
    Guest

    multiply 2 matrices: whats faster: "manually" or via OpenGL?

    This is not a math question but a performance question:

    I have a transformation matrix M.

    I have a static number of transformation matrices - say N1, N2, ..Nn. These remain static, too. They're defined once.

    Based on specific info I need to multiply M with Nx. And: I need the resulting matrix (R) for further "manual" number crunching. I've implemented this in two ways - my question to you is, which one is faster/better?

    way 1 - do it via OpenGL:

    for example N1 is defined/initialized as a DisplayList (some rotatef, etc.).

    glLoadMatrix(M);
    // select theDisplayList based on some
    // specific data, then call this list
    glCallList(theDisplayList);

    glGetDoublev(GL_MODELVIEW_MATRIX, R);

    No I have R and can play with it.


    OR


    N1 is defined in my own MatrixTypeDef, I do everything "internally", I multiply M with N1 by my own MatrixMultiplicationFunction, I get R and the only thing OpenGL has to say is:

    glLoadMatrix(R)


    I think the 2nd one is cleaner: more Model-View-Controller like. But the 2nd one could be faster, eventually. Is this correct? Is it relevant? Is it worth it, if the application is not meant to be highly portable?

  2. #2
    Guest

    Re: multiply 2 matrices: whats faster: "manually" or via OpenGL?

    !!! In the last paragraph - the FIRST way is meant to be faster

    (I'm registering right now, so I can edit my future posts, sorry)

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    May 2000
    Location
    Oxford, England
    Posts
    547

    Re: multiply 2 matrices: whats faster: "manually" or via OpenGL?

    glGet is very slow, the second should be faster.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: multiply 2 matrices: whats faster: "manually" or via OpenGL?

    There are four reasons why you shouldn't use OpenGL as a math library.

    1: It isn't a math library.
    2: It involves a glGet* command, which might stall the rendering pipeline, and might cause a performance hit.
    3: The code becomes less easy to read, follow and uderstand. Even though you know what it does, someone else might not. It's just a "dirty coding style".
    4: You can do much better yourself, with your own code. That is, the total time needed to obtain the resulting matrix.

    Even though OpenGL might perform the actual matrix multiplication faster than you can, it involves much more than just multiplying two matrices. If you do it on your own, you don't have to stall the rendering pipeline either.

  5. #5
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: multiply 2 matrices: whats faster: "manually" or via OpenGL?

    I agree with the above, it is worth doing this in OpenGL only if you intend to use the matrix to transform vertices in hardware and don't need to read it back, otherwise use your own math. Using glGet for state that's deep in the pipeline is a bad thing.

Posting Permissions

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