test/testgles.c
changeset 3110 e6c21c14ce3a
parent 3099 82e60908fab1
child 3139 7f684f249ec9
     1.1 --- a/test/testgles.c	Tue Apr 28 04:33:30 2009 +0000
     1.2 +++ b/test/testgles.c	Tue Apr 28 04:38:51 2009 +0000
     1.3 @@ -14,16 +14,26 @@
     1.4  #include "SDL_opengles.h"
     1.5  
     1.6  static CommonState *state;
     1.7 -static SDL_GLContext context;
     1.8 +static SDL_GLContext *context=NULL;
     1.9  
    1.10  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.11  static void
    1.12  quit(int rc)
    1.13  {
    1.14 -    if (context) {
    1.15 -        /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
    1.16 -        SDL_GL_DeleteContext(context);
    1.17 +    int i;
    1.18 +
    1.19 +    if (context!=NULL)
    1.20 +    {
    1.21 +        for (i=0; i<state->num_windows; i++)
    1.22 +        {
    1.23 +            if (context[i]) {
    1.24 +                SDL_GL_DeleteContext(context[i]);
    1.25 +            }
    1.26 +        }
    1.27 +
    1.28 +        SDL_free(context);
    1.29      }
    1.30 +
    1.31      CommonQuit(state);
    1.32      exit(rc);
    1.33  }
    1.34 @@ -139,11 +149,21 @@
    1.35          quit(2);
    1.36      }
    1.37  
    1.38 -    /* Create OpenGL context */
    1.39 -    context = SDL_GL_CreateContext(state->windows[0]);
    1.40 -    if (!context) {
    1.41 -        fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
    1.42 -        quit(2);
    1.43 +    context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext));
    1.44 +    if (context==NULL)
    1.45 +    {
    1.46 +       fprintf(stderr, "Out of memory!\n");
    1.47 +       quit(2);
    1.48 +    }
    1.49 +
    1.50 +    /* Create OpenGL ES contexts */
    1.51 +    for (i=0; i<state->num_windows; i++)
    1.52 +    {
    1.53 +        context[i] = SDL_GL_CreateContext(state->windows[i]);
    1.54 +        if (!context[i]) {
    1.55 +            fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
    1.56 +            quit(2);
    1.57 +        }
    1.58      }
    1.59  
    1.60      if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
    1.61 @@ -165,38 +185,38 @@
    1.62      if (!status) {
    1.63          printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
    1.64      } else {
    1.65 -        printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
    1.66 +        fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
    1.67      }
    1.68      status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
    1.69      if (!status) {
    1.70          printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
    1.71      } else {
    1.72 -        printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
    1.73 +        fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
    1.74      }
    1.75      status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
    1.76      if (!status) {
    1.77          printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
    1.78      } else {
    1.79 -        printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
    1.80 +        fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
    1.81      }
    1.82      status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
    1.83      if (!status) {
    1.84          printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
    1.85      } else {
    1.86 -        printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
    1.87 +        fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
    1.88      }
    1.89      if (fsaa) {
    1.90          status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
    1.91          if (!status) {
    1.92              printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
    1.93          } else {
    1.94 -            printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
    1.95 +            fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
    1.96          }
    1.97          status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
    1.98          if (!status) {
    1.99              printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
   1.100          } else {
   1.101 -            printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
   1.102 +            fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
   1.103          }
   1.104      }
   1.105      if (accel) {
   1.106 @@ -205,19 +225,30 @@
   1.107          {
   1.108              printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   1.109          } else {
   1.110 -            printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
   1.111 +            fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
   1.112          }
   1.113      }
   1.114  
   1.115 -    /* Set rendering settings */
   1.116 -    glMatrixMode(GL_PROJECTION);
   1.117 -    glLoadIdentity();
   1.118 -    glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
   1.119 -    glMatrixMode(GL_MODELVIEW);
   1.120 -    glLoadIdentity();
   1.121 -    glEnable(GL_DEPTH_TEST);
   1.122 -    glDepthFunc(GL_LESS);
   1.123 -    glShadeModel(GL_SMOOTH);
   1.124 +    /* Set rendering settings for each context */
   1.125 +    for (i = 0; i < state->num_windows; ++i) {
   1.126 +        status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
   1.127 +        if (status)
   1.128 +        {
   1.129 +            printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
   1.130 +
   1.131 +            /* Continue for next window */
   1.132 +            continue;
   1.133 +        }
   1.134 +
   1.135 +        glMatrixMode(GL_PROJECTION);
   1.136 +        glLoadIdentity();
   1.137 +        glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
   1.138 +        glMatrixMode(GL_MODELVIEW);
   1.139 +        glLoadIdentity();
   1.140 +        glEnable(GL_DEPTH_TEST);
   1.141 +        glDepthFunc(GL_LESS);
   1.142 +        glShadeModel(GL_SMOOTH);
   1.143 +    }
   1.144  
   1.145      /* Main render loop */
   1.146      frames = 0;
   1.147 @@ -231,7 +262,14 @@
   1.148          }
   1.149          for (i = 0; i < state->num_windows; ++i) {
   1.150              int w, h;
   1.151 -            SDL_GL_MakeCurrent(state->windows[i], context);
   1.152 +            status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
   1.153 +            if (status)
   1.154 +            {
   1.155 +               printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
   1.156 +
   1.157 +               /* Continue for next window */
   1.158 +               continue;
   1.159 +            }
   1.160              SDL_GetWindowSize(state->windows[i], &w, &h);
   1.161              glViewport(0, 0, w, h);
   1.162              Render();