Question

I am using Pyopengl and Pyglet for an simple application. I am using Vsync to swap buffers at 120 Hz. Here is the problem. When I run many applications like Outlook, Chrome, NotePad++, Dora's great adventure on background, the Fps is steady enough at 120Hz. But, when I turn off all those applications, the fps goes from 114Hz to 125Hz !?!?

I thought that closing applications would in fact improve the fps, but no. My application is out of sync. I also thought that the fps given by Pyglet would stick between 119 & 121.

Can anybody help me figure that out? Am I not seeing some obvious stuff?

Here is some code

def on_draw(dt):
    cnt
    ScreenSwap
    left = True
    right = False
    Rval = 0.0/255.0
    Gval = 153.0/255.0
    Bval = 0.0/255.0

    ShapePosition(speed = 0.25)

    glClear(GL_COLOR_BUFFER_BIT)  # Clear the color buffer
    glLoadIdentity()              # Reset model-view matrix
    DrawChecker(Nbr = 16, Dark = 25.0/255, Light = 75.0/255)

    if ScreenSwap == 1:
        DrawQuestionMark(Rval, Gval, Bval, left)
        # Blue Line
        BlueLine(left)        
        # Line to see if we are dropping frame
        DropFrameTest(left)
        ScreenSwap = 0

    else:     
        DrawQuestionMark(Rval, Gval, Bval, right)    
        # Blue Line
        BlueLine(right)
        # Line to see if we are dropping frame
        DropFrameTest(right)
        ScreenSwap = 1


    fps = pyglet.clock.get_fps()
    fd.write( str(fps) + "\n")   # debug

And more:

display = pyglet.window.get_platform().get_default_display()
screens = display.get_screens()

# Direct OpenGL commands to this window.
config = Config(double_buffer = True)
window = pyglet.window.Window(config = config, screen=screens[1],  vsync=True)
# Set full screen in separate function to avoid flicker a the start
window.set_fullscreen(True)
pyglet.clock.ClockDisplay()
#pyglet.clock.set_fps_limit(120)
fps = pyglet.clock.get_fps()
dt = pyglet.clock.tick()    
pyglet.clock.schedule_interval(on_draw, 0.001)
pyglet.app.run()
fd.close()
Was it helpful?

Solution

Ok, I think I understand what is happening.

In order to understand the behavior, I wrote to a file the time and frame rate everytime I drew a frame. I also used a "GPU task manager" to get information on the GPU load at a specific time (GPU-Z).

When I have a lot of applications running in the back ground, my application runs fine and the GPU load is around 25%.

When I do not have a lot of applications running in the back ground, my application is constantly out of sync, the CPU load is higher and the GPU load is around not steady.

I made the observations on 2 different implementations of my code, and monitored GPU + CPU activity for 15 minutes each time.

At first, I assumed that the CPU was taking all of the load... but it seems I was wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top