Support for GL initialization parameters has been added.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404131
This commit is contained in:
Mike Gorchak 2009-10-21 14:51:42 +00:00
parent 1cbfd5b6e0
commit 78dec43e00
4 changed files with 92 additions and 18 deletions

View File

@ -86,6 +86,28 @@ CommonCreateState(char **argv, Uint32 flags)
state->audiospec.format = AUDIO_S16; state->audiospec.format = AUDIO_S16;
state->audiospec.channels = 2; state->audiospec.channels = 2;
state->audiospec.samples = 2048; 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; return state;
} }
@ -621,6 +643,27 @@ CommonInit(CommonState * state)
SDL_GetCurrentVideoDriver()); 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) { if (state->verbose & VERBOSE_MODES) {
SDL_DisplayMode mode; SDL_DisplayMode mode;
int bpp; int bpp;

View File

@ -41,6 +41,27 @@ typedef struct
/* Audio info */ /* Audio info */
const char *audiodriver; const char *audiodriver;
SDL_AudioSpec audiospec; 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; } CommonState;
extern CommonState *CommonCreateState(char **argv, Uint32 flags); extern CommonState *CommonCreateState(char **argv, Uint32 flags);

View File

@ -204,18 +204,19 @@ main(int argc, char *argv[])
/* Set OpenGL parameters */ /* Set OpenGL parameters */
state->window_flags |= SDL_WINDOW_OPENGL; state->window_flags |= SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); state->gl_red_size = 5;
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); state->gl_green_size = 5;
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); state->gl_blue_size = 5;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); state->gl_depth_size = 16;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); state->gl_doublebuffer = 1;
if (fsaa) { if (fsaa) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); state->gl_multisamplebuffers = 1;
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); state->gl_multisamplesamples = fsaa;
} }
if (accel) { if (accel) {
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); state->gl_accelerated=1;
} }
if (!CommonInit(state)) { if (!CommonInit(state)) {
quit(2); quit(2);
} }

View File

@ -15,6 +15,7 @@
static CommonState *state; static CommonState *state;
static SDL_GLContext *context = NULL; static SDL_GLContext *context = NULL;
static int depth = 16;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
@ -118,12 +119,20 @@ main(int argc, char *argv[])
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) { } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
++accel; ++accel;
consumed = 1; 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 { } else {
consumed = -1; consumed = -1;
} }
} }
if (consumed < 0) { 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)); CommonUsage(state));
quit(1); quit(1);
} }
@ -132,16 +141,16 @@ main(int argc, char *argv[])
/* Set OpenGL parameters */ /* Set OpenGL parameters */
state->window_flags |= SDL_WINDOW_OPENGL; state->window_flags |= SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); state->gl_red_size = 5;
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); state->gl_green_size = 5;
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); state->gl_blue_size = 5;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); state->gl_depth_size = depth;
if (fsaa) { if (fsaa) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); state->gl_multisamplebuffers=1;
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); state->gl_multisamplesamples=fsaa;
} }
if (accel) { if (accel) {
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); state->gl_accelerated=1;
} }
if (!CommonInit(state)) { if (!CommonInit(state)) {
quit(2); quit(2);
@ -169,7 +178,7 @@ main(int argc, char *argv[])
} }
SDL_GetCurrentDisplayMode(&mode); SDL_GetCurrentDisplayMode(&mode);
printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format)); printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
printf("\n"); printf("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR)); printf("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER)); 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); status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { 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 { } else {
fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError()); SDL_GetError());