Skip to content

Fix asynchronous GLUT main loop utilizing tests that raced against reftest XHR. #24575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/float_tex.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <assert.h>
#include <math.h>
#include <stdio.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
Expand Down Expand Up @@ -99,6 +102,9 @@ static void glut_draw_callback(void) {
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_POINTS, 0, NUM_NODES);
glutSwapBuffers();
#ifdef __EMSCRIPTEN__
EM_ASM(doReftest()); // All done, perform the JS side image comparison reftest.
#endif
}

GLuint createShader(const char source[], int type) {
Expand Down Expand Up @@ -160,6 +166,11 @@ int main(int argc, char *argv[]) {
/* Set up glut callback functions */
glutDisplayFunc(glut_draw_callback);
gl_init();
#ifdef __EMSCRIPTEN__
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
// reftest immediately after falling out from main.
EM_ASM({ delete Module['postRun']; });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we have a reftestBlock / reftestUnblock API for this. See #22672

#endif
glutMainLoop();
return 0;
}
12 changes: 12 additions & 0 deletions test/gl_subdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <stdio.h>
#include <string.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <GL/gl.h>
Expand Down Expand Up @@ -99,6 +103,9 @@ static void glut_draw_callback(void) {
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_POINTS, 0, NUM_NODES);
glutSwapBuffers();
#ifdef __EMSCRIPTEN__
EM_ASM(doReftest()); // All done, perform the JS side image comparison reftest.
#endif
}

GLuint createShader(const char* source, int type) {
Expand Down Expand Up @@ -155,6 +162,11 @@ int main(int argc, char *argv[]) {
/* Set up glut callback functions */
glutDisplayFunc(glut_draw_callback);
gl_init();
#ifdef __EMSCRIPTEN__
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
// reftest immediately after falling out from main.
EM_ASM({ delete Module['postRun']; });
#endif
glutMainLoop();
return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions test/hello_world_gles.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ gears_draw(void)
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);

glutSwapBuffers();
#ifdef __EMSCRIPTEN__
EM_ASM({if (typeof doReftest !== 'undefined') doReftest();}); // All done, perform the JS side image comparison reftest.
#endif

#ifdef LONGTEST
glutPostRedisplay(); // check for issues with not throttling calls
Expand Down Expand Up @@ -773,6 +776,11 @@ main(int argc, char *argv[])
/* Initialize the gears */
gears_init();

#ifdef __EMSCRIPTEN__
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
// reftest immediately after falling out from main.
EM_ASM({ if (typeof doReftest !== 'undefined' && Module['postRun'] == doReftest) delete Module['postRun']; });
#endif
glutMainLoop();

return 0;
Expand Down
11 changes: 11 additions & 0 deletions test/hello_world_gles_deriv.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <Glut/glut.h>
Expand Down Expand Up @@ -541,6 +544,9 @@ gears_draw(void)
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);

glutSwapBuffers();
#ifdef __EMSCRIPTEN__
EM_ASM(doReftest()); // All done, perform the JS side image comparison reftest.
#endif
}

/**
Expand Down Expand Up @@ -730,6 +736,11 @@ main(int argc, char *argv[])
/* Initialize the gears */
gears_init();

#ifdef __EMSCRIPTEN__
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
// reftest immediately after falling out from main.
EM_ASM({ if (typeof doReftest !== 'undefined' && Module['postRun'] == doReftest) delete Module['postRun']; });
#endif
glutMainLoop();

return 0;
Expand Down
10 changes: 9 additions & 1 deletion test/hello_world_gles_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <Glut/glut.h>
Expand Down Expand Up @@ -559,12 +562,17 @@ gears_draw(void)
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);

glutSwapBuffers();
#ifdef __EMSCRIPTEN__
EM_ASM({if (typeof doReftest !== 'undefined') doReftest();}); // All done, perform the JS side image comparison reftest.
#endif

#ifdef LONGTEST
glutPostRedisplay(); // check for issues with not throttling calls
#endif

#ifdef __EMSCRIPTEN__
EM_ASM({ window.close() });
#endif
}

/**
Expand Down Expand Up @@ -758,7 +766,7 @@ main(int argc, char *argv[])
// Don't trigger the reftest immediately after main finishes,
// this test uses rAF to perform rendering, so let it trigger
// the reftest after having rendered some frames.
EM_ASM(Module['postRun'] = undefined);
EM_ASM({ if (typeof doReftest !== 'undefined' && Module['postRun'] == doReftest) delete Module['postRun']; });
#endif

/* Initialize the window */
Expand Down