test/testrendertarget.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
     1.1 --- a/test/testrendertarget.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testrendertarget.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -15,6 +15,10 @@
     1.4  #include <stdio.h>
     1.5  #include <time.h>
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10 +
    1.11  #include "SDL_test_common.h"
    1.12  
    1.13  
    1.14 @@ -29,6 +33,10 @@
    1.15      int scale_direction;
    1.16  } DrawState;
    1.17  
    1.18 +DrawState *drawstates;
    1.19 +int done;
    1.20 +SDL_bool test_composite = SDL_FALSE;
    1.21 +
    1.22  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.23  static void
    1.24  quit(int rc)
    1.25 @@ -214,15 +222,33 @@
    1.26      return SDL_TRUE;
    1.27  }
    1.28  
    1.29 +void
    1.30 +loop()
    1.31 +{
    1.32 +    int i;
    1.33 +    SDL_Event event;
    1.34 +
    1.35 +    /* Check for events */
    1.36 +    while (SDL_PollEvent(&event)) {
    1.37 +        SDLTest_CommonEvent(state, &event, &done);
    1.38 +    }
    1.39 +    for (i = 0; i < state->num_windows; ++i) {
    1.40 +        if (state->windows[i] == NULL)
    1.41 +            continue;
    1.42 +        if (test_composite) {
    1.43 +            if (!DrawComposite(&drawstates[i])) done = 1;
    1.44 +        } else {
    1.45 +            if (!Draw(&drawstates[i])) done = 1;
    1.46 +        }
    1.47 +    }
    1.48 +}
    1.49 +
    1.50  int
    1.51  main(int argc, char *argv[])
    1.52  {
    1.53 -    DrawState *drawstates;
    1.54 -    int i, done;
    1.55 -    SDL_Event event;
    1.56 +    int i;
    1.57      int frames;
    1.58      Uint32 then, now;
    1.59 -    SDL_bool test_composite = SDL_FALSE;
    1.60  
    1.61      /* Enable standard application logging */
    1.62      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.63 @@ -278,22 +304,15 @@
    1.64      frames = 0;
    1.65      then = SDL_GetTicks();
    1.66      done = 0;
    1.67 +
    1.68 +#ifdef __EMSCRIPTEN__
    1.69 +    emscripten_set_main_loop(loop, 0, 1);
    1.70 +#else
    1.71      while (!done) {
    1.72 -        /* Check for events */
    1.73          ++frames;
    1.74 -        while (SDL_PollEvent(&event)) {
    1.75 -            SDLTest_CommonEvent(state, &event, &done);
    1.76 -        }
    1.77 -        for (i = 0; i < state->num_windows; ++i) {
    1.78 -            if (state->windows[i] == NULL)
    1.79 -                continue;
    1.80 -            if (test_composite) {
    1.81 -                if (!DrawComposite(&drawstates[i])) done = 1;
    1.82 -            } else {
    1.83 -                if (!Draw(&drawstates[i])) done = 1;
    1.84 -            }
    1.85 -        }
    1.86 +        loop();
    1.87      }
    1.88 +#endif
    1.89  
    1.90      /* Print out some timing information */
    1.91      now = SDL_GetTicks();