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'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\bin\</OutDir> <OutDir>.\bin\</OutDir>
<IntDir>.\bin\</IntDir> <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> <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.1.2.bin.WIN32\lib-vc2015;$(LibraryPath)</LibraryPath> <LibraryPath>extern\glew-1.13.0\lib\Release\Win32;extern\glfw-3.2.bin.WIN32\lib-vc2015;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <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) 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 This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages 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 * A library for OpenGL, window and input
*------------------------------------------------------------------------ *------------------------------------------------------------------------
* Copyright (c) 2002-2006 Marcus Geelnard * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@ -38,20 +38,30 @@ extern "C" {
* Doxygen documentation * 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 /*! @defgroup native Native access
* *
* **By using the native access functions you assert that you know what you're * **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 * doing and how to fix problems caused by using them. If you don't, you
* shouldn't be using them.** * shouldn't be using them.**
* *
* Before the inclusion of @ref glfw3native.h, you must define exactly one * Before the inclusion of @ref glfw3native.h, you may define exactly one
* window system API macro and exactly one context creation API macro. Failure * window system API macro and zero or more context creation API macros.
* to do this will cause a compile-time error. *
* 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: * The available window API macros are:
* * `GLFW_EXPOSE_NATIVE_WIN32` * * `GLFW_EXPOSE_NATIVE_WIN32`
* * `GLFW_EXPOSE_NATIVE_COCOA` * * `GLFW_EXPOSE_NATIVE_COCOA`
* * `GLFW_EXPOSE_NATIVE_X11` * * `GLFW_EXPOSE_NATIVE_X11`
* * `GLFW_EXPOSE_NATIVE_WAYLAND`
* * `GLFW_EXPOSE_NATIVE_MIR`
* *
* The available context API macros are: * The available context API macros are:
* * `GLFW_EXPOSE_NATIVE_WGL` * * `GLFW_EXPOSE_NATIVE_WGL`
@ -86,20 +96,23 @@ extern "C" {
#elif defined(GLFW_EXPOSE_NATIVE_X11) #elif defined(GLFW_EXPOSE_NATIVE_X11)
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#else #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
#error "No window API selected" #include <wayland-client.h>
#elif defined(GLFW_EXPOSE_NATIVE_MIR)
#include <mir_toolkit/mir_client_library.h>
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_WGL) #if defined(GLFW_EXPOSE_NATIVE_WGL)
/* WGL is declared by windows.h */ /* 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 */ /* NSGL is declared by Cocoa.h */
#elif defined(GLFW_EXPOSE_NATIVE_GLX) #endif
#if defined(GLFW_EXPOSE_NATIVE_GLX)
#include <GL/glx.h> #include <GL/glx.h>
#elif defined(GLFW_EXPOSE_NATIVE_EGL) #endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)
#include <EGL/egl.h> #include <EGL/egl.h>
#else
#error "No context API selected"
#endif #endif
@ -114,11 +127,10 @@ extern "C" {
* of the specified monitor, or `NULL` if an [error](@ref error_handling) * of the specified monitor, or `NULL` if an [error](@ref error_handling)
* occurred. * occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.1.
* Added in GLFW 3.1.
* *
* @ingroup native * @ingroup native
*/ */
@ -130,11 +142,10 @@ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
* `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.1.
* Added in GLFW 3.1.
* *
* @ingroup native * @ingroup native
*/ */
@ -145,11 +156,10 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
* @return The `HWND` of the specified window, or `NULL` if an * @return The `HWND` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -162,11 +172,10 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
* @return The `HGLRC` of the specified window, or `NULL` if an * @return The `HGLRC` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -179,11 +188,10 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
* @return The `CGDirectDisplayID` of the specified monitor, or * @return The `CGDirectDisplayID` of the specified monitor, or
* `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.1.
* Added in GLFW 3.1.
* *
* @ingroup native * @ingroup native
*/ */
@ -194,11 +202,10 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
* @return The `NSWindow` of the specified window, or `nil` if an * @return The `NSWindow` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -211,11 +218,10 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
* @return The `NSOpenGLContext` of the specified window, or `nil` if an * @return The `NSOpenGLContext` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -228,11 +234,10 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
* @return The `Display` used by GLFW, or `NULL` if an * @return The `Display` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -243,11 +248,10 @@ GLFWAPI Display* glfwGetX11Display(void);
* @return The `RRCrtc` of the specified monitor, or `None` if an * @return The `RRCrtc` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.1.
* Added in GLFW 3.1.
* *
* @ingroup native * @ingroup native
*/ */
@ -258,11 +262,10 @@ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
* @return The `RROutput` of the specified monitor, or `None` if an * @return The `RROutput` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.1.
* Added in GLFW 3.1.
* *
* @ingroup native * @ingroup native
*/ */
@ -273,11 +276,10 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
* @return The `Window` of the specified window, or `None` if an * @return The `Window` of the specified window, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -290,15 +292,116 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
* @return The `GLXContext` of the specified window, or `NULL` if an * @return The `GLXContext` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); 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 #endif
#if defined(GLFW_EXPOSE_NATIVE_EGL) #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 * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -322,11 +424,10 @@ GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
* @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @ingroup native
*/ */
@ -337,11 +438,10 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
* @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @par Thread Safety * @thread_safety This function may be called from any thread. Access is not
* This function may be called from any thread. Access is not synchronized. * synchronized.
* *
* @par History * @since Added in version 3.0.
* Added in GLFW 3.0.
* *
* @ingroup native * @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 pushd ..\bin
set GLEW=..\extern\glew-1.13.0 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 STB=..\extern\stb-master
set GLM=..\extern\glm-0.9.7.5 set GLM=..\extern\glm-0.9.7.5

View File

@ -14,6 +14,7 @@
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
#include <string> #include <string>
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode) 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); 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) if (!window)
{ {
@ -91,20 +92,23 @@ int main()
glfwSetWindowUserPointer(window, static_cast<void *>(&game)); glfwSetWindowUserPointer(window, static_cast<void *>(&game));
f32 deltaTime = 0.0f; // Time between current frame and last frame f32 secondsElapsed = 0.0f; // Time between current frame and last frame
f32 lastFrame = 0.0f; // Time of 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 */ /* Main game loop */
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
f32 currentFrame = static_cast<f32>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
/* Check and call events */ /* Check and call events */
glfwPollEvents(); glfwPollEvents();
game.update(deltaTime); game.update(secondsElapsed);
/* Rendering commands here*/ /* Rendering commands here*/
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
@ -115,6 +119,31 @@ int main()
/* Swap the buffers */ /* Swap the buffers */
glfwSwapBuffers(window); 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(); glfwTerminate();

View File

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