changeset 3408:55541ddf13e3

Support for GL initialization parameters has been added.
author Mike Gorchak <lestat@i.com.ua>
date Wed, 21 Oct 2009 14:51:42 +0000
parents d3baf5ac4e37
children c8f580ebc96a
files test/common.c test/common.h test/testgl2.c test/testgles.c
diffstat 4 files changed, 92 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/test/common.c	Mon Oct 19 13:31:58 2009 +0000
+++ b/test/common.c	Wed Oct 21 14:51:42 2009 +0000
@@ -86,6 +86,28 @@
     state->audiospec.format = AUDIO_S16;
     state->audiospec.channels = 2;
     state->audiospec.samples = 2048;
+
+    /* Set some very sane GL defaults */
+    state->gl_red_size = 3;
+    state->gl_green_size = 3;
+    state->gl_blue_size = 2;
+    state->gl_alpha_size = 0;
+    state->gl_buffer_size = 0;
+    state->gl_depth_size = 16;
+    state->gl_stencil_size = 0;
+    state->gl_double_buffer = 1;
+    state->gl_accum_red_size = 0;
+    state->gl_accum_green_size = 0;
+    state->gl_accum_blue_size = 0;
+    state->gl_accum_alpha_size = 0;
+    state->gl_stereo = 0;
+    state->gl_multisamplebuffers = 0;
+    state->gl_multisamplesamples = 0;
+    state->gl_retained_backing = 1;
+    state->gl_accelerated = 1;
+    state->gl_major_version = 2;
+    state->gl_minor_version = 1;
+
     return state;
 }
 
@@ -621,6 +643,27 @@
                     SDL_GetCurrentVideoDriver());
         }
 
+        /* Upload GL settings */
+        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
+        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
+        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
+        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
+        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
+        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
+        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
+        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
+        SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
+        SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
+        SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
+        SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
+        SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
+        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
+        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
+        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, state->gl_accelerated);
+        SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
+
         if (state->verbose & VERBOSE_MODES) {
             SDL_DisplayMode mode;
             int bpp;
--- a/test/common.h	Mon Oct 19 13:31:58 2009 +0000
+++ b/test/common.h	Wed Oct 21 14:51:42 2009 +0000
@@ -41,6 +41,27 @@
     /* Audio info */
     const char *audiodriver;
     SDL_AudioSpec audiospec;
+
+    /* GL settings */
+    int gl_red_size;
+    int gl_green_size;
+    int gl_blue_size;
+    int gl_alpha_size;
+    int gl_buffer_size;
+    int gl_depth_size;
+    int gl_stencil_size;
+    int gl_double_buffer;
+    int gl_accum_red_size;
+    int gl_accum_green_size;
+    int gl_accum_blue_size;
+    int gl_accum_alpha_size;
+    int gl_stereo;
+    int gl_multisamplebuffers;
+    int gl_multisamplesamples;
+    int gl_retained_backing;
+    int gl_accelerated;
+    int gl_major_version;
+    int gl_minor_version;
 } CommonState;
 
 extern CommonState *CommonCreateState(char **argv, Uint32 flags);
--- a/test/testgl2.c	Mon Oct 19 13:31:58 2009 +0000
+++ b/test/testgl2.c	Wed Oct 21 14:51:42 2009 +0000
@@ -204,18 +204,19 @@
 
     /* Set OpenGL parameters */
     state->window_flags |= SDL_WINDOW_OPENGL;
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
-    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+    state->gl_red_size = 5;
+    state->gl_green_size = 5;
+    state->gl_blue_size = 5;
+    state->gl_depth_size = 16;
+    state->gl_doublebuffer = 1;
     if (fsaa) {
-        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
-        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
+        state->gl_multisamplebuffers = 1;
+        state->gl_multisamplesamples = fsaa;
     }
     if (accel) {
-        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
+        state->gl_accelerated=1;
     }
+
     if (!CommonInit(state)) {
         quit(2);
     }
--- a/test/testgles.c	Mon Oct 19 13:31:58 2009 +0000
+++ b/test/testgles.c	Wed Oct 21 14:51:42 2009 +0000
@@ -15,6 +15,7 @@
 
 static CommonState *state;
 static SDL_GLContext *context = NULL;
+static int depth = 16;
 
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
 static void
@@ -118,12 +119,20 @@
             } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
                 ++accel;
                 consumed = 1;
+            } else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
+                i++;
+                if (!argv[i]) {
+                    consumed = -1;
+                } else {
+                    depth = SDL_atoi(argv[i]);
+                    consumed = 1;
+                }
             } else {
                 consumed = -1;
             }
         }
         if (consumed < 0) {
-            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
+            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
                     CommonUsage(state));
             quit(1);
         }
@@ -132,16 +141,16 @@
 
     /* Set OpenGL parameters */
     state->window_flags |= SDL_WINDOW_OPENGL;
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+    state->gl_red_size = 5;
+    state->gl_green_size = 5;
+    state->gl_blue_size = 5;
+    state->gl_depth_size = depth;
     if (fsaa) {
-        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
-        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
+        state->gl_multisamplebuffers=1;
+        state->gl_multisamplesamples=fsaa;
     }
     if (accel) {
-        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
+        state->gl_accelerated=1;
     }
     if (!CommonInit(state)) {
         quit(2);
@@ -169,7 +178,7 @@
     }
 
     SDL_GetCurrentDisplayMode(&mode);
-    printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
+    printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
     printf("\n");
     printf("Vendor     : %s\n", glGetString(GL_VENDOR));
     printf("Renderer   : %s\n", glGetString(GL_RENDERER));
@@ -200,7 +209,7 @@
     }
     status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
     if (!status) {
-        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
+        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
     } else {
         fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
                 SDL_GetError());