test/testgl2.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 7746 6a05d7352575
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
   179     SDL_DisplayMode mode;
   179     SDL_DisplayMode mode;
   180     SDL_Event event;
   180     SDL_Event event;
   181     Uint32 then, now, frames;
   181     Uint32 then, now, frames;
   182     int status;
   182     int status;
   183 
   183 
       
   184     /* Enable standard application logging */
       
   185     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
       
   186 
   184     /* Initialize parameters */
   187     /* Initialize parameters */
   185     fsaa = 0;
   188     fsaa = 0;
   186     accel = -1;
   189     accel = -1;
   187 
   190 
   188     /* Initialize test framework */
   191     /* Initialize test framework */
   204             } else {
   207             } else {
   205                 consumed = -1;
   208                 consumed = -1;
   206             }
   209             }
   207         }
   210         }
   208         if (consumed < 0) {
   211         if (consumed < 0) {
   209             fprintf(stderr, "Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
   212             SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
   210                     SDLTest_CommonUsage(state));
   213                     SDLTest_CommonUsage(state));
   211             quit(1);
   214             quit(1);
   212         }
   215         }
   213         i += consumed;
   216         i += consumed;
   214     }
   217     }
   233     }
   236     }
   234 
   237 
   235     /* Create OpenGL context */
   238     /* Create OpenGL context */
   236     context = SDL_GL_CreateContext(state->windows[0]);
   239     context = SDL_GL_CreateContext(state->windows[0]);
   237     if (!context) {
   240     if (!context) {
   238         fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
   241         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
   239         quit(2);
   242         quit(2);
   240     }
   243     }
   241 
   244 
   242     if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
   245     if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
   243         /* try late-swap-tearing first. If not supported, try normal vsync. */
   246         /* try late-swap-tearing first. If not supported, try normal vsync. */
   247     } else {
   250     } else {
   248         SDL_GL_SetSwapInterval(0);  /* disable vsync. */
   251         SDL_GL_SetSwapInterval(0);  /* disable vsync. */
   249     }
   252     }
   250 
   253 
   251     SDL_GetCurrentDisplayMode(0, &mode);
   254     SDL_GetCurrentDisplayMode(0, &mode);
   252     printf("Screen BPP    : %d\n", SDL_BITSPERPIXEL(mode.format));
   255     SDL_Log("Screen BPP    : %d\n", SDL_BITSPERPIXEL(mode.format));
   253     printf("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
   256     SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
   254     printf("\n");
   257     SDL_Log("\n");
   255     printf("Vendor        : %s\n", glGetString(GL_VENDOR));
   258     SDL_Log("Vendor        : %s\n", glGetString(GL_VENDOR));
   256     printf("Renderer      : %s\n", glGetString(GL_RENDERER));
   259     SDL_Log("Renderer      : %s\n", glGetString(GL_RENDERER));
   257     printf("Version       : %s\n", glGetString(GL_VERSION));
   260     SDL_Log("Version       : %s\n", glGetString(GL_VERSION));
   258     printf("Extensions    : %s\n", glGetString(GL_EXTENSIONS));
   261     SDL_Log("Extensions    : %s\n", glGetString(GL_EXTENSIONS));
   259     printf("\n");
   262     SDL_Log("\n");
   260 
   263 
   261     status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   264     status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   262     if (!status) {
   265     if (!status) {
   263         printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   266         SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   264     } else {
   267     } else {
   265         printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
   268         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
   266     }
   269     }
   267     status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   270     status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   268     if (!status) {
   271     if (!status) {
   269         printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   272         SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   270     } else {
   273     } else {
   271         printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
   274         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
   272     }
   275     }
   273     status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   276     status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   274     if (!status) {
   277     if (!status) {
   275         printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   278         SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   276     } else {
   279     } else {
   277         printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
   280         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
   278     }
   281     }
   279     status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   282     status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   280     if (!status) {
   283     if (!status) {
   281         printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   284         SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   282     } else {
   285     } else {
   283         printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
   286         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
   284     }
   287     }
   285     if (fsaa) {
   288     if (fsaa) {
   286         status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   289         status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   287         if (!status) {
   290         if (!status) {
   288             printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   291             SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   289         } else {
   292         } else {
   290             printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
   293             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
   291                    SDL_GetError());
   294                    SDL_GetError());
   292         }
   295         }
   293         status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   296         status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   294         if (!status) {
   297         if (!status) {
   295             printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   298             SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   296                    value);
   299                    value);
   297         } else {
   300         } else {
   298             printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
   301             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
   299                    SDL_GetError());
   302                    SDL_GetError());
   300         }
   303         }
   301     }
   304     }
   302     if (accel >= 0) {
   305     if (accel >= 0) {
   303         status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   306         status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   304         if (!status) {
   307         if (!status) {
   305             printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
   308             SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
   306                    value);
   309                    value);
   307         } else {
   310         } else {
   308             printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
   311 			SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
   309                    SDL_GetError());
   312                    SDL_GetError());
   310         }
   313         }
   311     }
   314     }
   312 
   315 
   313     /* Set rendering settings */
   316     /* Set rendering settings */
   341     }
   344     }
   342 
   345 
   343     /* Print out some timing information */
   346     /* Print out some timing information */
   344     now = SDL_GetTicks();
   347     now = SDL_GetTicks();
   345     if (now > then) {
   348     if (now > then) {
   346         printf("%2.2f frames per second\n",
   349         SDL_Log("%2.2f frames per second\n",
   347                ((double) frames * 1000) / (now - then));
   350                ((double) frames * 1000) / (now - then));
   348     }
   351     }
   349     quit(0);
   352     quit(0);
   350     return 0;
   353     return 0;
   351 }
   354 }
   353 #else /* HAVE_OPENGL */
   356 #else /* HAVE_OPENGL */
   354 
   357 
   355 int
   358 int
   356 main(int argc, char *argv[])
   359 main(int argc, char *argv[])
   357 {
   360 {
   358     printf("No OpenGL support on this system\n");
   361     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
   359     return 1;
   362     return 1;
   360 }
   363 }
   361 
   364 
   362 #endif /* HAVE_OPENGL */
   365 #endif /* HAVE_OPENGL */