From c49121c0c949c5b6ec4bd39e43c600f928557c35 Mon Sep 17 00:00:00 2001 From: Mike Gorchak Date: Wed, 21 Oct 2009 14:51:42 +0000 Subject: [PATCH] Support for GL initialization parameters has been added. --- test/common.c | 43 +++++++++++++++++++++++++++++++++++++++++++ test/common.h | 21 +++++++++++++++++++++ test/testgl2.c | 17 +++++++++-------- test/testgles.c | 29 +++++++++++++++++++---------- 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/test/common.c b/test/common.c index 98d31d4be..cc0bcd343 100644 --- a/test/common.c +++ b/test/common.c @@ -86,6 +86,28 @@ CommonCreateState(char **argv, Uint32 flags) 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 @@ CommonInit(CommonState * state) 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; diff --git a/test/common.h b/test/common.h index 46a3b7390..9f33fafd2 100644 --- a/test/common.h +++ b/test/common.h @@ -41,6 +41,27 @@ typedef struct /* 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); diff --git a/test/testgl2.c b/test/testgl2.c index 7374124b0..b5423d928 100644 --- a/test/testgl2.c +++ b/test/testgl2.c @@ -204,18 +204,19 @@ main(int argc, char *argv[]) /* 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); } diff --git a/test/testgles.c b/test/testgles.c index 5c4321284..ac58764c2 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -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 @@ main(int argc, char *argv[]) } 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 @@ main(int argc, char *argv[]) /* 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 @@ main(int argc, char *argv[]) } 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 @@ main(int argc, char *argv[]) } 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());