Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - miotatsu

Pages: [1]
1
Window / vsync always on?
« on: October 20, 2014, 10:01:09 am »
I have been playing around with game loops and physics. The other day, I added some debug statements to see how much time each frame of my game loop was taking. As expected, the results were in the 16ms range. However, I tried disabling vsync, and these results did not change. Clearly vsync was still occuring.

My system is as follows:

    $ inxi -SMG
    System: Host: c7 Kernel: 3.16.4-1-ARCH x86_64 (64 bit) Desktop: i3 4.8 Distro: Arch Linux
    Machine: System: Google product: Parrot v: 1.0
    Mobo: N/A model: N/A Bios: coreboot v: 4.0-4744-gac16405-dirty date: 10/23/2013
    Graphics: Card: Intel 2nd Generation Core Processor Family Integrated Graphics Controller
    Display Server: X.Org 1.16.1 driver: intel Resolution: 1366x768@60.02hz
    GLX Renderer: Mesa DRI Intel Sandybridge Mobile GLX Version: 3.0 Mesa 10.3.1

The SFML vsync test case is given below:
#include <chrono>
#include <iostream>
#include "SFML/Graphics.hpp"

int main()
{
    auto* window = new sf::RenderWindow(sf::VideoMode(640, 480), "test",
        sf::Style::Titlebar | sf::Style::Close);
    window->setVerticalSyncEnabled(true);
    auto firstTime = std::chrono::high_resolution_clock::now();
    while(window->isOpen())
    {
        //print frame timing
        {
            auto secondTime = std::chrono::high_resolution_clock::now();
            using dMsecs = std::chrono::duration<double, std::chrono::milliseconds::period>;
            auto elapsed = dMsecs(secondTime - firstTime);
            firstTime = secondTime;
            std::cout << elapsed.count() << '\n';
        }
        //event handler
        {
            sf::Event e;
            while(window->pollEvent(e))
            {
                if(e.type == sf::Event::EventType::Closed)
                    window->close();
            }
        }
        //render
        {
            window->clear();
            window->display();
        }
    }
}

I have another test case written with SDL2 for comparison:
#include <chrono>
#include <iostream>
#include "SDL2/SDL.h"

int main()
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    auto firstTime = std::chrono::high_resolution_clock::now();
    auto quit = false;
    while(!quit)
    {
        //print frame timing
        {
            auto secondTime = std::chrono::high_resolution_clock::now();
            using dMsecs = std::chrono::duration<double, std::chrono::milliseconds::period>;
            auto elapsed = dMsecs(secondTime - firstTime);
            firstTime = secondTime;
            std::cout << elapsed.count() << '\n';
        }
        //event handler
        {
            SDL_Event e;
            while(SDL_PollEvent(&e))
            {
                if(e.type == SDL_QUIT) quit = true;
            }
        }
        //render
        {
            SDL_RenderClear(renderer);
            SDL_RenderPresent(renderer);
        }
    }
}

SFML sample output, vsync on:
(click to show/hide)

SFML sample output, vsync off:
(click to show/hide)

SFML, window->display() commented out:
(click to show/hide)

SDL2, vsync on:
(click to show/hide)

SDL2, vsync off:
(click to show/hide)

If this is a driver issue, I don't understand why other libraries have vsync implementations that behave correctly on my system?
What is the difference in implementation between the two libraries causing this differing behaviour, and can it be resolved? How would I go about getting the correct behaviour with SFML?

Pages: [1]
anything