C++11 Threads

Discussion in 'C++' started by Chris Forone, Nov 5, 2012.

  1. Chris Forone

    Chris Forone Guest

    hello group,

    im working on an app and have two (ok more) questions:

    1) i want to sync my pgm-logic to its "natural" periode: the vertical
    retrace of the monitor. i do this with a function named eglSwapBuffers
    (http://www.khronos.org/registry/egl/sdk/docs/man/xhtml)

    this func blocks until the vsync occurs: "Subsequent client API commands
    may be issued on that context immediately after calling eglSwapBuffers,
    but are not executed until the buffer exchange is completed." (quote) i
    think its some sort of polling-func?!

    now i have the idea, to put some kind of logic to the new c++11 threads.
    in pseudo-code:

    getTimeStamp start (from steady-clock)
    doAllLogic to listOfObjects
    drawAllObjects (should be fast because of opengl/gpu)
    getTimeStamp now

    if timeStamp now - start < refreshRateTime
    sleep

    eglSwapBuffers

    is this a good approach or are there big problems because of
    thread-resolution and this things?

    can i have an influence to some thread-params to optimize thread-behavior?

    sorry for my bad english.

    second question will follow soon...

    thanks for your time, cheers, chris
    Chris Forone, Nov 5, 2012
    #1
    1. Advertising

  2. Chris Forone

    Nobody Guest

    On Mon, 05 Nov 2012 11:18:43 +0100, Chris Forone wrote:

    > 1) i want to sync my pgm-logic to its "natural" periode: the vertical
    > retrace of the monitor. i do this with a function named eglSwapBuffers
    > (http://www.khronos.org/registry/egl/sdk/docs/man/xhtml)
    >
    > this func blocks until the vsync occurs:


    No it doesn't:

    > "Subsequent client API commands
    > may be issued on that context immediately after calling eglSwapBuffers,
    > but are not executed until the buffer exchange is completed." (quote) i
    > think its some sort of polling-func?!


    eglSwapBuffers() inserts a "swap buffers" operation into the graphics
    pipeline. The operation will only be performed once any preceding
    operations have completed. If vsync has been enabled with
    eglSwapInterval(), it will only be performed once the current frame has
    finished being displayed.

    > now i have the idea, to put some kind of logic to the new c++11 threads.
    > in pseudo-code:
    >
    > getTimeStamp start (from steady-clock)
    > doAllLogic to listOfObjects
    > drawAllObjects (should be fast because of opengl/gpu)
    > getTimeStamp now
    >
    > if timeStamp now - start < refreshRateTime
    > sleep
    >
    > eglSwapBuffers
    >
    > is this a good approach or are there big problems because of
    > thread-resolution and this things?


    This is pointless.

    If vsync is enabled, your program will naturally be clamped to the refresh
    rate by virtue of the graphics pipeline having a fixed size. If you try to
    render frames faster than the refresh rate, the pipeline will fill and
    rendering functions will block until space is available.

    Neither EGL nor OpenGL ES have any direct way of monitoring the progress
    of the graphics pipeline (unlike OpenGL 3.x which has sync objects).
    Nobody, Nov 5, 2012
    #2
    1. Advertising

  3. Chris Forone

    Chris Forone Guest

    Am 05.11.2012 13:04, schrieb Nobody:
    > On Mon, 05 Nov 2012 11:18:43 +0100, Chris Forone wrote:
    >
    >> 1) i want to sync my pgm-logic to its "natural" periode: the vertical
    >> retrace of the monitor. i do this with a function named eglSwapBuffers
    >> (http://www.khronos.org/registry/egl/sdk/docs/man/xhtml)
    >>
    >> this func blocks until the vsync occurs:

    >
    > No it doesn't:
    >
    >> "Subsequent client API commands
    >> may be issued on that context immediately after calling eglSwapBuffers,
    >> but are not executed until the buffer exchange is completed." (quote) i
    >> think its some sort of polling-func?!

    >
    > eglSwapBuffers() inserts a "swap buffers" operation into the graphics
    > pipeline. The operation will only be performed once any preceding
    > operations have completed. If vsync has been enabled with
    > eglSwapInterval(), it will only be performed once the current frame has
    > finished being displayed.
    >
    >> now i have the idea, to put some kind of logic to the new c++11 threads.
    >> in pseudo-code:
    >>
    >> getTimeStamp start (from steady-clock)
    >> doAllLogic to listOfObjects
    >> drawAllObjects (should be fast because of opengl/gpu)
    >> getTimeStamp now
    >>
    >> if timeStamp now - start < refreshRateTime
    >> sleep
    >>
    >> eglSwapBuffers
    >>
    >> is this a good approach or are there big problems because of
    >> thread-resolution and this things?

    >
    > This is pointless.
    >
    > If vsync is enabled, your program will naturally be clamped to the refresh
    > rate by virtue of the graphics pipeline having a fixed size. If you try to
    > render frames faster than the refresh rate, the pipeline will fill and
    > rendering functions will block until space is available.
    >
    > Neither EGL nor OpenGL ES have any direct way of monitoring the progress
    > of the graphics pipeline (unlike OpenGL 3.x which has sync objects).
    >

    in this article they add a glFinish after the swap to achieve sync:
    http://www.opengl.org/wiki/Swap_Interval but this is apparently no good
    solution.

    thanks a lot, chris
    Chris Forone, Nov 5, 2012
    #3
    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. Codemonkey
    Replies:
    1
    Views:
    399
    Ying-Shen Yu[MSFT]
    Oct 30, 2003
  2. yoda
    Replies:
    2
    Views:
    408
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    374
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,390
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    125
    Une bévue
    Jun 14, 2006
Loading...

Share This Page