Giter VIP home page Giter VIP logo

Comments (6)

raysan5 avatar raysan5 commented on May 17, 2024

After further investigation, it seems that high (100% or 25% for quad-cores) CPU usage is the expected behavior for most cases in OpenGL/Direct3D games, it mainly depends on graphics driver implementation. Game loop just keeps running all the time if not locked in any way. In GLFW3 is possible to glfwWaitEvents() instead of glfwPollEvent() so frame swap can be locked waiting for events and CPU usage falls to ~1% but that's not the desired behaviour in a game. Enabling VSYNC could have a similar effect but it also depends on graphics driver...

A couple of links with further info:

http://stackoverflow.com/questions/18365269/cpu-usage-is-high-when-using-opengl-control-class
http://gamedev.stackexchange.com/questions/19066/why-is-opengl-using-100-cpu-shortly-after-start-up-when-wglswapintervalext-is-e

from raylib.

kd7tck avatar kd7tck commented on May 17, 2024

Having an option in the lib API for vsync might help allot. When vendor drivers have trouble with vsync, the opengl software can make up for that and override the driver settings.

#ifdef _WIN32
    // Turn on vertical screen sync under Windows.
    // (I.e. it uses the WGL_EXT_swap_control extension)
    typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
    PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
    wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
    if(wglSwapIntervalEXT)
        wglSwapIntervalEXT(1);
#endif

from raylib.

raysan5 avatar raysan5 commented on May 17, 2024

GLFW already uses WGL_EXT_swap_control extension to provide VSYNC (where this extension is available) but, again, it can be overriden by graphic driver, forcing on or off. Here it is further information on Swap Internal:

https://www.opengl.org/wiki/Swap_Interval

But there is something I can do; I can expose GLFW VSYNC mechanism to raylib users through a flag, to be set before windows creation. That way users can try forcing VSYNC and wait for the driver to respond.

I'm working on it.

from raylib.

kd7tck avatar kd7tck commented on May 17, 2024

Thank you for the time and effort you have put into this.

from raylib.

raysan5 avatar raysan5 commented on May 17, 2024

Use function: SetConfigFlags(FLAG_VSYNC_HINT); // Use before InitWindow()

Underlying system, GLFW3, will try to enable vsync if graphic driver allows it.

Upcoming raylib v1.3 includes this change.

from raylib.

raysan5 avatar raysan5 commented on May 17, 2024

Issue corrected on commit b681e8c.

from raylib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.