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

Thread: Maximizing the speed of a program

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    4

    Maximizing the speed of a program

    Ok, so guys, could you please give me some general tips on code structure that can help maximize the speed of my program
    Thanks
    Saxon

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    Ehm, plenty. What's the scenario? Are we talking general optimization or optimizing rendering? Are we talking C/C++ or other languages? Please be more specific when asking quetsitons!

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    4
    Optimizing rendering..
    C++..

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    An specific problems? You can't optimize unless you know where your bottelnecks are. Premature optimization is the root of all evil and high cholesterol!

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    4
    No, I have just been playing around with code structure, and I was curious as to whether or not there are actually things that can be done in order to optimize the speed.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    Sure you can. But optimization implies are sub-optimal state. Show us some code you wish to optimize.

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    4
    ok, specifically
    in the case of drawing a cube, what is faster, the following code,,
    or a loop coupled with an algorithm that can change the the x, y and z variables to the corresponding values.

    glBegin( GL_QUADS );
    glVertex3f( x, y, z);
    glVertex3f(-x, y, z);
    glVertex3f(-x,-y, z);
    glVertex3f( x,-y, z);

    glVertex3f( x, y,-z);
    glVertex3f(-x, y,-z);
    glVertex3f(-x, y, z);
    glVertex3f( x, y, z);

    glVertex3f(-x, y,-z);
    glVertex3f( x, y,-z);
    glVertex3f( x,-y,-z);
    glVertex3f(-x,-y,-z);

    glVertex3f( x, y,-z);
    glVertex3f( x, y, z);
    glVertex3f( x,-y, z);
    glVertex3f( x,-y,-z);

    glVertex3f(-x, y, z);
    glVertex3f(-x, y,-z);
    glVertex3f(-x,-y,-z);
    glVertex3f(-x,-y, z);

    glVertex3f( x,-y, z);
    glVertex3f(-x,-y, z);
    glVertex3f(-x,-y,-z);
    glVertex3f( x,-y,-z);
    glEnd();

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    If the compiler unrolls the loop, there isn't a difference at all and in this case it very well might do that. You should check out how to render stuff nowadays. The code you posted is so 1992. It's not that tragic for a cube, but for mesh with a few hundrd or thousand vertices, your current method (called immediate mode) is the slowest possible.

Posting Permissions

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