mirror of
https://github.com/glfw/glfw.git
synced 2024-11-24 05:34:36 +00:00
Tests: Add damage tracking to MSAA
This lets compositors avoid re-rendering the entire buffer when only the outside of the squares changed. If glfwGetBufferAge() returns 0 for any reason (the buffer was just created, there was an error, or the underlying API doesn’t track buffer age), we swap the entire buffer again.
This commit is contained in:
parent
c8233ce7d3
commit
8e51c4a577
20
tests/msaa.c
20
tests/msaa.c
@ -102,6 +102,19 @@ int main(int argc, char** argv)
|
|||||||
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
|
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
|
||||||
GLint mvp_location, vpos_location;
|
GLint mvp_location, vpos_location;
|
||||||
|
|
||||||
|
// Minimum static damage for both squares.
|
||||||
|
GLFWrect rects[8] =
|
||||||
|
{{ 25, 25, 350, 90},
|
||||||
|
{ 25, 285, 350, 90},
|
||||||
|
{ 25, 115, 90, 170},
|
||||||
|
{285, 115, 90, 170},
|
||||||
|
|
||||||
|
{425, 25, 350, 90},
|
||||||
|
{425, 285, 350, 90},
|
||||||
|
{425, 115, 90, 170},
|
||||||
|
{685, 115, 90, 170},
|
||||||
|
};
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "hs:")) != -1)
|
while ((ch = getopt(argc, argv, "hs:")) != -1)
|
||||||
{
|
{
|
||||||
switch (ch)
|
switch (ch)
|
||||||
@ -178,11 +191,13 @@ int main(int argc, char** argv)
|
|||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
float ratio;
|
float ratio;
|
||||||
|
int buffer_age;
|
||||||
int width, height;
|
int width, height;
|
||||||
mat4x4 m, p, mvp;
|
mat4x4 m, p, mvp;
|
||||||
const double angle = glfwGetTime() * M_PI / 180.0;
|
const double angle = glfwGetTime() * M_PI / 180.0;
|
||||||
|
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
|
buffer_age = glfwGetBufferAge(window);
|
||||||
ratio = width / (float) height;
|
ratio = width / (float) height;
|
||||||
|
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
@ -208,6 +223,11 @@ int main(int argc, char** argv)
|
|||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
|
||||||
|
// If buffer_age is 0, we can’t assume anything about the previous buffer
|
||||||
|
// so swap the entire buffer.
|
||||||
|
if (buffer_age > 0)
|
||||||
|
glfwSwapBuffersWithDamage(window, rects, 8);
|
||||||
|
else
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user