Add frame limiter, update glfw to 3.2

This commit is contained in:
Doyle Thai 2016-06-17 03:00:11 +10:00
parent 5cebf9ad0d
commit 9861a02ed1
41 changed files with 1616 additions and 608 deletions

View File

@ -71,8 +71,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\bin\</OutDir>
<IntDir>.\bin\</IntDir>
<IncludePath>extern\glm-0.9.7.5\include;extern\stb-master\include;src\include;extern\glew-1.13.0\include;extern\glfw-3.1.2.bin.WIN32\include;$(IncludePath)</IncludePath>
<LibraryPath>extern\glew-1.13.0\lib\Release\Win32;extern\glfw-3.1.2.bin.WIN32\lib-vc2015;$(LibraryPath)</LibraryPath>
<IncludePath>extern\glm-0.9.7.5\include;extern\stb-master\include;src\include;extern\glew-1.13.0\include;extern\glfw-3.2.bin.WIN32\include;$(IncludePath)</IncludePath>
<LibraryPath>extern\glew-1.13.0\lib\Release\Win32;extern\glfw-3.2.bin.WIN32\lib-vc2015;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
Copyright (c) 2002-2006 Marcus Geelnard
Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,9 +1,9 @@
/*************************************************************************
* GLFW 3.1 - www.glfw.org
* GLFW 3.2 - www.glfw.org
* A library for OpenGL, window and input
*------------------------------------------------------------------------
* Copyright (c) 2002-2006 Marcus Geelnard
* Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
* Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@ -38,20 +38,30 @@ extern "C" {
* Doxygen documentation
*************************************************************************/
/*! @file glfw3native.h
* @brief The header of the native access functions.
*
* This is the header file of the native access functions. See @ref native for
* more information.
*/
/*! @defgroup native Native access
*
* **By using the native access functions you assert that you know what you're
* doing and how to fix problems caused by using them. If you don't, you
* shouldn't be using them.**
*
* Before the inclusion of @ref glfw3native.h, you must define exactly one
* window system API macro and exactly one context creation API macro. Failure
* to do this will cause a compile-time error.
* Before the inclusion of @ref glfw3native.h, you may define exactly one
* window system API macro and zero or more context creation API macros.
*
* The chosen backends must match those the library was compiled for. Failure
* to do this will cause a link-time error.
*
* The available window API macros are:
* * `GLFW_EXPOSE_NATIVE_WIN32`
* * `GLFW_EXPOSE_NATIVE_COCOA`
* * `GLFW_EXPOSE_NATIVE_X11`
* * `GLFW_EXPOSE_NATIVE_WAYLAND`
* * `GLFW_EXPOSE_NATIVE_MIR`
*
* The available context API macros are:
* * `GLFW_EXPOSE_NATIVE_WGL`
@ -86,20 +96,23 @@ extern "C" {
#elif defined(GLFW_EXPOSE_NATIVE_X11)
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#else
#error "No window API selected"
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
#include <wayland-client.h>
#elif defined(GLFW_EXPOSE_NATIVE_MIR)
#include <mir_toolkit/mir_client_library.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_WGL)
/* WGL is declared by windows.h */
#elif defined(GLFW_EXPOSE_NATIVE_NSGL)
#endif
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
/* NSGL is declared by Cocoa.h */
#elif defined(GLFW_EXPOSE_NATIVE_GLX)
#endif
#if defined(GLFW_EXPOSE_NATIVE_GLX)
#include <GL/glx.h>
#elif defined(GLFW_EXPOSE_NATIVE_EGL)
#endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)
#include <EGL/egl.h>
#else
#error "No context API selected"
#endif
@ -114,11 +127,10 @@ extern "C" {
* of the specified monitor, or `NULL` if an [error](@ref error_handling)
* occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
@ -130,11 +142,10 @@ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
* `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
@ -145,11 +156,10 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
* @return The `HWND` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -162,11 +172,10 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
* @return The `HGLRC` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -179,11 +188,10 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
* @return The `CGDirectDisplayID` of the specified monitor, or
* `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
@ -194,11 +202,10 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
* @return The `NSWindow` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -211,11 +218,10 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
* @return The `NSOpenGLContext` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -228,11 +234,10 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
* @return The `Display` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -243,11 +248,10 @@ GLFWAPI Display* glfwGetX11Display(void);
* @return The `RRCrtc` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
@ -258,11 +262,10 @@ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
* @return The `RROutput` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
@ -273,11 +276,10 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
* @return The `Window` of the specified window, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -290,15 +292,116 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
* @return The `GLXContext` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
/*! @brief Returns the `GLXWindow` of the specified window.
*
* @return The `GLXWindow` of the specified window, or `None` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
/*! @brief Returns the `struct wl_display*` used by GLFW.
*
* @return The `struct wl_display*` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
/*! @brief Returns the `struct wl_output*` of the specified monitor.
*
* @return The `struct wl_output*` of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
/*! @brief Returns the main `struct wl_surface*` of the specified window.
*
* @return The main `struct wl_surface*` of the specified window, or `NULL` if
* an [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_MIR)
/*! @brief Returns the `MirConnection*` used by GLFW.
*
* @return The `MirConnection*` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI MirConnection* glfwGetMirDisplay(void);
/*! @brief Returns the Mir output ID of the specified monitor.
*
* @return The Mir output ID of the specified monitor, or zero if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
/*! @brief Returns the `MirSurface*` of the specified window.
*
* @return The `MirSurface*` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)
@ -307,11 +410,10 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
* @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -322,11 +424,10 @@ GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
* @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
@ -337,11 +438,10 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
* @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@ IF NOT EXIST ..\bin mkdir ..\bin
pushd ..\bin
set GLEW=..\extern\glew-1.13.0
set GLFW=..\extern\glfw-3.1.2.bin.WIN32
set GLFW=..\extern\glfw-3.2.bin.WIN32
set STB=..\extern\stb-master
set GLM=..\extern\glm-0.9.7.5

View File

@ -14,6 +14,7 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode)
@ -49,7 +50,7 @@ int main()
glm::ivec2 windowSize = glm::ivec2(1280, 720);
GLFWwindow *window = glfwCreateWindow(windowSize.x, windowSize.y, "Breakout", nullptr, nullptr);
GLFWwindow *window = glfwCreateWindow(windowSize.x, windowSize.y, "Dengine", nullptr, nullptr);
if (!window)
{
@ -91,20 +92,23 @@ int main()
glfwSetWindowUserPointer(window, static_cast<void *>(&game));
f32 deltaTime = 0.0f; // Time between current frame and last frame
f32 lastFrame = 0.0f; // Time of last frame
f32 secondsElapsed = 0.0f; // Time between current frame and last frame
// TODO(doyle): Get actual monitor refresh rate
i32 monitorRefreshHz = 60;
f32 targetSecondsPerFrame = 1.0f / static_cast<f32>(monitorRefreshHz);
f32 startTime = static_cast<f32>(glfwGetTime());
//glfwSwapInterval(1);
/* Main game loop */
while (!glfwWindowShouldClose(window))
{
f32 currentFrame = static_cast<f32>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
/* Check and call events */
glfwPollEvents();
game.update(deltaTime);
game.update(secondsElapsed);
/* Rendering commands here*/
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
@ -115,6 +119,31 @@ int main()
/* Swap the buffers */
glfwSwapBuffers(window);
f32 endTime = static_cast<f32>(glfwGetTime());
secondsElapsed = endTime - startTime;
// TODO(doyle): Busy waiting, should sleep
while (secondsElapsed < targetSecondsPerFrame)
{
endTime = static_cast<f32>(glfwGetTime());
secondsElapsed = endTime - startTime;
}
LOCAL_PERSIST f32 titleUpdateFrequencyInSeconds = 0.5f;
titleUpdateFrequencyInSeconds -= secondsElapsed;
if (titleUpdateFrequencyInSeconds <= 0)
{
f32 msPerFrame = secondsElapsed * 1000.0f;
f32 framesPerSecond = 1.0f / secondsElapsed;
std::stringstream ss;
ss << "Dengine | " << msPerFrame << " ms/f | " << framesPerSecond << " fps";
glfwSetWindowTitle(window, ss.str().c_str());
titleUpdateFrequencyInSeconds = 0.5f;
}
startTime = endTime;
}
glfwTerminate();

View File

@ -5,11 +5,13 @@
typedef uint8_t u8;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t i32;
typedef i32 b32;
typedef float f32;
typedef double f64;
#define TRUE 1
#define FALSE 0