Add a glfwGetBufferAge() symbol

This new API lets the application know when the current buffer was last
written to.  If it returns 0, it means the user shouldn’t rely on what
was last present in this buffer and should draw everything again, as
usual.

This provides a significant boost in efficiency, especially on tiling
GPUs, by letting the application avoid to clear and redraw everything at
every frame.
This commit is contained in:
Emmanuel Gil Peyrot 2019-12-08 17:24:50 +01:00
parent a94b96c954
commit 0d2ce23071
3 changed files with 53 additions and 0 deletions

View File

@ -5656,6 +5656,7 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* window);
* @sa @ref buffer_swap * @sa @ref buffer_swap
* @sa @ref glfwSwapBuffers * @sa @ref glfwSwapBuffers
* @sa @ref glfwSwapInterval * @sa @ref glfwSwapInterval
* @sa @ref glfwGetBufferAge
* *
* @since Added in version 3.4. * @since Added in version 3.4.
* *
@ -5709,6 +5710,36 @@ GLFWAPI void glfwSwapBuffersWithDamage(GLFWwindow* window, GLFWrect* rects, int
*/ */
GLFWAPI void glfwSwapInterval(int interval); GLFWAPI void glfwSwapInterval(int interval);
/*! @brief Returns the buffer age of the windows current buffer.
*
* This function returns the age of the current buffer, in frames. It may be
* used to redraw only the parts of the buffer that have changed since this
* buffer was last used, thus avoiding a clear and draw of the entire buffer.
*
* A context must be current on the calling thread. Calling this function
* without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error.
*
* This function does not apply to Vulkan. If you are rendering with Vulkan,
* see the present mode of your swapchain instead.
*
* @param[in] window The window whose buffers to swap.
* @return The age of the back buffer if the extension is available, or 0
* otherwise.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NO_CURRENT_CONTEXT and @ref GLFW_PLATFORM_ERROR.
*
* @thread_safety This function may be called from any thread.
*
* @sa @ref buffer_swap
* @sa @ref glfwSwapBuffersWithDamage
*
* @since Added in version 3.4.
*
* @ingroup context
*/
GLFWAPI int glfwGetBufferAge(GLFWwindow* window);
/*! @brief Returns whether the specified extension is available. /*! @brief Returns whether the specified extension is available.
* *
* This function returns whether the specified * This function returns whether the specified

View File

@ -694,6 +694,26 @@ GLFWAPI void glfwSwapInterval(int interval)
window->context.swapInterval(interval); window->context.swapInterval(interval);
} }
GLFWAPI int glfwGetBufferAge(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (window->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT,
"Cannot get buffer age of a window that has no OpenGL or OpenGL ES context");
return 0;
}
if (window->context.getBufferAge)
return window->context.getBufferAge(window);
return 0;
}
GLFWAPI int glfwExtensionSupported(const char* extension) GLFWAPI int glfwExtensionSupported(const char* extension)
{ {
_GLFWwindow* window; _GLFWwindow* window;

View File

@ -80,6 +80,7 @@ typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*); typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
typedef void (* _GLFWswapbufferswithdamagefun)(_GLFWwindow*,GLFWrect*,int); typedef void (* _GLFWswapbufferswithdamagefun)(_GLFWwindow*,GLFWrect*,int);
typedef void (* _GLFWswapintervalfun)(int); typedef void (* _GLFWswapintervalfun)(int);
typedef int (* _GLFWgetbufferagefun)(_GLFWwindow*);
typedef int (* _GLFWextensionsupportedfun)(const char*); typedef int (* _GLFWextensionsupportedfun)(const char*);
typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*); typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*); typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
@ -353,6 +354,7 @@ struct _GLFWcontext
_GLFWswapbuffersfun swapBuffers; _GLFWswapbuffersfun swapBuffers;
_GLFWswapbufferswithdamagefun swapBuffersWithDamage; _GLFWswapbufferswithdamagefun swapBuffersWithDamage;
_GLFWswapintervalfun swapInterval; _GLFWswapintervalfun swapInterval;
_GLFWgetbufferagefun getBufferAge;
_GLFWextensionsupportedfun extensionSupported; _GLFWextensionsupportedfun extensionSupported;
_GLFWgetprocaddressfun getProcAddress; _GLFWgetprocaddressfun getProcAddress;
_GLFWdestroycontextfun destroy; _GLFWdestroycontextfun destroy;