alleggl.c

Go to the documentation of this file.
00001 
00008 #include <string.h>
00009 #include <stdlib.h>
00010 
00011 #include "alleggl.h"
00012 #include "allglint.h"
00013 
00014 #include <allegro/internal/aintern.h>
00015 #ifdef ALLEGRO_MACOSX
00016 #include <OpenGL/glu.h>
00017 #else
00018 #include <GL/glu.h>
00019 #endif
00020 
00021 
00022 /* Structs containing the current driver state */
00023 struct allegro_gl_driver *__allegro_gl_driver = NULL;
00024 struct allegro_gl_display_info allegro_gl_display_info;
00025 
00026 /* Settings required/suggested */
00027 int __allegro_gl_required_settings, __allegro_gl_suggested_settings;
00028 
00029 /* Valid context state */
00030 int __allegro_gl_valid_context = 0;
00031 
00032 
00033 
00034 char allegro_gl_error[AGL_ERROR_SIZE] = EMPTY_STRING;
00035 
00036 BLIT_BETWEEN_FORMATS_FUNC __blit_between_formats8;
00037 BLIT_BETWEEN_FORMATS_FUNC __blit_between_formats15;
00038 BLIT_BETWEEN_FORMATS_FUNC __blit_between_formats16;
00039 BLIT_BETWEEN_FORMATS_FUNC __blit_between_formats24;
00040 BLIT_BETWEEN_FORMATS_FUNC __blit_between_formats32;
00041 
00042 
00043 
00052 BITMAP *allegro_gl_screen;
00053 
00054 
00055 
00056 /* Allegro GFX_DRIVER list handling */
00057 static _DRIVER_INFO our_driver_list[] = {
00058 #ifdef GFX_OPENGL_WINDOWED
00059     {GFX_OPENGL_WINDOWED, &gfx_allegro_gl_windowed, FALSE},
00060 #endif
00061 #ifdef GFX_OPENGL_FULLSCREEN
00062     {GFX_OPENGL_FULLSCREEN, &gfx_allegro_gl_fullscreen, FALSE},
00063 #endif
00064     {GFX_OPENGL, &gfx_allegro_gl_default, FALSE},
00065     {0, NULL, FALSE}
00066 };
00067 
00068 
00069 
00070 static _DRIVER_INFO *our_gfx_drivers(void)
00071 {
00072     return our_driver_list;
00073 }
00074 
00075 
00076 
00077 _DRIVER_INFO *(*saved_gfx_drivers) (void) = NULL;
00078 
00079 
00080 
00081 static _DRIVER_INFO *list_saved_gfx_drivers(void)
00082 {
00083     return _gfx_driver_list;
00084 }
00085 
00086 
00087 
00088 static BITMAP *allegro_gl_default_gfx_init(int w, int h, int vw, int vh, int depth);
00089 
00090 
00091 
00092 GFX_DRIVER gfx_allegro_gl_default =
00093 {
00094    GFX_OPENGL,
00095    EMPTY_STRING,
00096    EMPTY_STRING,
00097    "AllegroGL Default Driver",
00098    allegro_gl_default_gfx_init,
00099    NULL,
00100    NULL,
00101    NULL,               //_xwin_vsync,
00102    NULL,
00103    NULL, NULL, NULL,
00104    NULL,        /* create_video_bitmap */
00105    NULL,
00106    NULL, NULL,  /* No show/request video bitmaps */
00107    NULL, NULL,
00108    NULL, NULL, NULL, NULL,
00109    NULL,
00110    NULL, NULL,
00111 #if GET_ALLEGRO_VERSION() >= MAKE_VER(4, 1, 18)
00112    NULL,        /* set_blender_mode */
00113 #endif
00114    NULL,        /* No fetch_mode_list */
00115    0, 0,
00116    0,
00117    0, 0,
00118    0,
00119    0,
00120    FALSE        /* Windowed mode */
00121 };
00122 
00123 
00124 
00168 /* void allegro_gl_clear_settings(void) */
00185 void allegro_gl_clear_settings(void)
00186 {
00187     memset(&allegro_gl_display_info, 0, sizeof allegro_gl_display_info);
00188 
00189     __allegro_gl_required_settings = __allegro_gl_suggested_settings = 0;
00190     
00191     /* Pick sensible defaults */
00192     allegro_gl_display_info.fullscreen = 1;
00193     allegro_gl_display_info.rmethod = 1;
00194     allegro_gl_display_info.doublebuffered = 1;
00195     allegro_gl_display_info.vidmem_policy = AGL_KEEP;
00196     __allegro_gl_suggested_settings =
00197                            AGL_FULLSCREEN | AGL_RENDERMETHOD | AGL_DOUBLEBUFFER;
00198 }
00199 
00200 
00201 
00202 /* void allegro_gl_set(int option, int value) */
00266 void allegro_gl_set(int option, int value)
00267 {
00268     switch (option) {
00269             /* Options stating importance of other options */
00270         case AGL_REQUIRE:
00271             __allegro_gl_required_settings |= value;
00272             __allegro_gl_suggested_settings &= ~value;
00273             break;
00274         case AGL_SUGGEST:
00275             __allegro_gl_suggested_settings |= value;
00276             __allegro_gl_required_settings &= ~value;
00277             break;
00278         case AGL_DONTCARE:
00279             __allegro_gl_required_settings &= ~value;
00280             __allegro_gl_suggested_settings &= ~value;
00281             break;
00282 
00283             /* Options configuring the mode set */
00284         case AGL_ALLEGRO_FORMAT:
00285             allegro_gl_display_info.allegro_format = value;
00286             break;
00287         case AGL_RED_DEPTH:
00288             allegro_gl_display_info.pixel_size.rgba.r = value;
00289             break;
00290         case AGL_GREEN_DEPTH:
00291             allegro_gl_display_info.pixel_size.rgba.g = value;
00292             break;
00293         case AGL_BLUE_DEPTH:
00294             allegro_gl_display_info.pixel_size.rgba.b = value;
00295             break;
00296         case AGL_ALPHA_DEPTH:
00297             allegro_gl_display_info.pixel_size.rgba.a = value;
00298             break;
00299         case AGL_COLOR_DEPTH:
00300             switch (value) {
00301                 case 8:
00302                     allegro_gl_set(AGL_RED_DEPTH, 3);
00303                     allegro_gl_set(AGL_GREEN_DEPTH, 3);
00304                     allegro_gl_set(AGL_BLUE_DEPTH, 2);
00305                     allegro_gl_set(AGL_ALPHA_DEPTH, 0);
00306                     break;
00307                 case 15:
00308                     allegro_gl_set(AGL_RED_DEPTH, 5);
00309                     allegro_gl_set(AGL_GREEN_DEPTH, 5);
00310                     allegro_gl_set(AGL_BLUE_DEPTH, 5);
00311                     allegro_gl_set(AGL_ALPHA_DEPTH, 1);
00312                     break;
00313                 case 16:
00314                     allegro_gl_set(AGL_RED_DEPTH, 5);
00315                     allegro_gl_set(AGL_GREEN_DEPTH, 6);
00316                     allegro_gl_set(AGL_BLUE_DEPTH, 5);
00317                     allegro_gl_set(AGL_ALPHA_DEPTH, 0);
00318                     break;
00319                 case 24:
00320                 case 32:
00321                     allegro_gl_set(AGL_RED_DEPTH, 8);
00322                     allegro_gl_set(AGL_GREEN_DEPTH, 8);
00323                     allegro_gl_set(AGL_BLUE_DEPTH, 8);
00324                     allegro_gl_set(AGL_ALPHA_DEPTH, value-24);
00325                     break;
00326             }
00327             allegro_gl_display_info.colour_depth = value;
00328             break;
00329         case AGL_ACC_RED_DEPTH:
00330             allegro_gl_display_info.accum_size.rgba.r = value;
00331             break;
00332         case AGL_ACC_GREEN_DEPTH:
00333             allegro_gl_display_info.accum_size.rgba.g = value;
00334             break;
00335         case AGL_ACC_BLUE_DEPTH:
00336             allegro_gl_display_info.accum_size.rgba.b = value;
00337             break;
00338         case AGL_ACC_ALPHA_DEPTH:
00339             allegro_gl_display_info.accum_size.rgba.a = value;
00340             break;
00341 
00342         case AGL_DOUBLEBUFFER:
00343             allegro_gl_display_info.doublebuffered = value;
00344             break;
00345         case AGL_STEREO:
00346             allegro_gl_display_info.stereo = value;
00347             break;
00348         case AGL_AUX_BUFFERS:
00349             allegro_gl_display_info.aux_buffers = value;
00350             break;
00351         case AGL_Z_DEPTH:
00352             allegro_gl_display_info.depth_size = value;
00353             break;
00354         case AGL_STENCIL_DEPTH:
00355             allegro_gl_display_info.stencil_size = value;
00356             break;
00357 
00358         case AGL_WINDOW_X:
00359             allegro_gl_display_info.x = value;
00360             break;
00361         case AGL_WINDOW_Y:
00362             allegro_gl_display_info.y = value;
00363             break;
00364 
00365         case AGL_RENDERMETHOD:
00366             allegro_gl_display_info.rmethod = value;
00367             break;
00368 
00369         case AGL_FULLSCREEN:
00370             allegro_gl_display_info.fullscreen = value;
00371             break;
00372 
00373         case AGL_WINDOWED:
00374             allegro_gl_display_info.fullscreen = !value;
00375             break;
00376         case AGL_VIDEO_MEMORY_POLICY:
00377             if ((value == AGL_KEEP) || (value == AGL_RELEASE))
00378                 allegro_gl_display_info.vidmem_policy = value;
00379             break;
00380         case AGL_SAMPLE_BUFFERS:
00381             allegro_gl_display_info.sample_buffers = value;
00382             break;
00383         case AGL_SAMPLES:
00384             allegro_gl_display_info.samples = value;
00385             break;
00386         case AGL_FLOAT_COLOR:
00387             allegro_gl_display_info.float_color = value;
00388             break;
00389         case AGL_FLOAT_Z:
00390             allegro_gl_display_info.float_depth = value;
00391             break;
00392     }
00393 }
00394 
00395 
00396 
00413 int allegro_gl_get(int option)
00414 {
00415     switch (option) {
00416             /* Options stating importance of other options */
00417         case AGL_REQUIRE:
00418             return __allegro_gl_required_settings;
00419         case AGL_SUGGEST:
00420             return __allegro_gl_suggested_settings;
00421         case AGL_DONTCARE:
00422             return ~0 & ~(__allegro_gl_required_settings |
00423                           __allegro_gl_suggested_settings);
00424 
00425             /* Options configuring the mode set */
00426         case AGL_ALLEGRO_FORMAT:
00427             return allegro_gl_display_info.allegro_format;
00428         case AGL_RED_DEPTH:
00429             return allegro_gl_display_info.pixel_size.rgba.r;
00430         case AGL_GREEN_DEPTH:
00431             return allegro_gl_display_info.pixel_size.rgba.g;
00432         case AGL_BLUE_DEPTH:
00433             return allegro_gl_display_info.pixel_size.rgba.b;
00434         case AGL_ALPHA_DEPTH:
00435             return allegro_gl_display_info.pixel_size.rgba.a;
00436         case AGL_COLOR_DEPTH:
00437             return allegro_gl_display_info.pixel_size.rgba.r
00438                 + allegro_gl_display_info.pixel_size.rgba.g
00439                 + allegro_gl_display_info.pixel_size.rgba.b
00440                 + allegro_gl_display_info.pixel_size.rgba.a;
00441         case AGL_ACC_RED_DEPTH:
00442             return allegro_gl_display_info.accum_size.rgba.r;
00443         case AGL_ACC_GREEN_DEPTH:
00444             return allegro_gl_display_info.accum_size.rgba.g;
00445         case AGL_ACC_BLUE_DEPTH:
00446             return allegro_gl_display_info.accum_size.rgba.b;
00447         case AGL_ACC_ALPHA_DEPTH:
00448             return allegro_gl_display_info.accum_size.rgba.a;
00449         case AGL_DOUBLEBUFFER:
00450             return allegro_gl_display_info.doublebuffered;
00451         case AGL_STEREO:
00452             return allegro_gl_display_info.stereo;
00453         case AGL_AUX_BUFFERS:
00454             return allegro_gl_display_info.aux_buffers;
00455         case AGL_Z_DEPTH:
00456             return allegro_gl_display_info.depth_size;
00457         case AGL_STENCIL_DEPTH:
00458             return allegro_gl_display_info.stencil_size;
00459         case AGL_WINDOW_X:
00460             return allegro_gl_display_info.x;
00461         case AGL_WINDOW_Y:
00462             return allegro_gl_display_info.y;
00463         case AGL_FULLSCREEN:
00464             return allegro_gl_display_info.fullscreen;
00465         case AGL_WINDOWED:
00466             return !allegro_gl_display_info.fullscreen;
00467         case AGL_VIDEO_MEMORY_POLICY:
00468             return allegro_gl_display_info.vidmem_policy;
00469         case AGL_SAMPLE_BUFFERS:
00470             return allegro_gl_display_info.sample_buffers;
00471         case AGL_SAMPLES:
00472             return allegro_gl_display_info.samples;
00473         case AGL_FLOAT_COLOR:
00474             return allegro_gl_display_info.float_color;
00475         case AGL_FLOAT_Z:
00476             return allegro_gl_display_info.float_depth;
00477     }
00478     return -1;
00479 }
00480 
00481 
00482 
00483 /* Builds a string corresponding to the options set in 'opt'
00484  * and writes in the config file
00485  */
00486 static void build_settings(int opt, char *section, char *name) {
00487     char buf[2048];
00488 
00489     usetc(buf, 0);
00490 
00491     if (opt & AGL_ALLEGRO_FORMAT)
00492         ustrcat(buf, "allegro_format ");
00493     if (opt & AGL_RED_DEPTH)
00494         ustrcat(buf, "red_depth ");
00495     if (opt & AGL_GREEN_DEPTH)
00496         ustrcat(buf, "green_depth ");
00497     if (opt & AGL_BLUE_DEPTH)
00498         ustrcat(buf, "blue_depth ");
00499     if (opt & AGL_ALPHA_DEPTH)
00500         ustrcat(buf, "alpha_depth ");
00501     if (opt & AGL_COLOR_DEPTH)
00502         ustrcat(buf, "color_depth ");
00503     if (opt & AGL_ACC_RED_DEPTH)
00504         ustrcat(buf, "accum_red_depth ");
00505     if (opt & AGL_ACC_GREEN_DEPTH)
00506         ustrcat(buf, "accum_green_depth ");
00507     if (opt & AGL_ACC_BLUE_DEPTH)
00508         ustrcat(buf, "accum_blue_depth ");
00509     if (opt & AGL_ACC_ALPHA_DEPTH)
00510         ustrcat(buf, "accum_alpha_depth ");
00511     if (opt & AGL_DOUBLEBUFFER)
00512         ustrcat(buf, "double_buffer ");
00513     if (opt & AGL_STEREO)
00514         ustrcat(buf, "stereo_display ");
00515     if (opt & AGL_AUX_BUFFERS)
00516         ustrcat(buf, "aux_buffers ");
00517     if (opt & AGL_Z_DEPTH)
00518         ustrcat(buf, "z_depth ");
00519     if (opt & AGL_STENCIL_DEPTH)
00520         ustrcat(buf, "stencil_depth ");
00521     if (opt & AGL_WINDOW_X)
00522         ustrcat(buf, "window_x ");
00523     if (opt & AGL_WINDOW_Y)
00524         ustrcat(buf, "window_y ");
00525     if (opt & AGL_FULLSCREEN)
00526         ustrcat(buf, "fullscreen ");
00527     if (opt & AGL_WINDOWED)
00528         ustrcat(buf, "windowed ");
00529     if (opt & AGL_VIDEO_MEMORY_POLICY)
00530         ustrcat(buf, "video_memory_policy ");
00531     if (opt & AGL_SAMPLE_BUFFERS)
00532         ustrcat(buf, "sample_buffers ");
00533     if (opt & AGL_SAMPLES)
00534         ustrcat(buf, "samples ");
00535     if (opt & AGL_FLOAT_COLOR)
00536         ustrcat(buf, "float_color ");
00537     if (opt & AGL_FLOAT_Z)
00538         ustrcat(buf, "float_depth ");
00539         
00540     set_config_string(section, name, buf);
00541 }
00542 
00543 
00544 
00545 /* void allegro_gl_save_settings() */
00552 void allegro_gl_save_settings() {
00553 
00554     char *section = "OpenGL";
00555     int save = allegro_gl_get(AGL_REQUIRE) | allegro_gl_get(AGL_SUGGEST);
00556     
00557     if (save & AGL_ALLEGRO_FORMAT)
00558         set_config_int(section, "allegro_format",
00559             allegro_gl_get(AGL_ALLEGRO_FORMAT));
00560     if (save & AGL_RED_DEPTH)
00561         set_config_int(section, "red_depth",
00562             allegro_gl_get(AGL_RED_DEPTH));
00563     if (save & AGL_GREEN_DEPTH)
00564         set_config_int(section, "green_depth",
00565             allegro_gl_get(AGL_GREEN_DEPTH));
00566     if (save & AGL_BLUE_DEPTH)
00567         set_config_int(section, "blue_depth",
00568             allegro_gl_get(AGL_BLUE_DEPTH));
00569     if (save & AGL_ALPHA_DEPTH)
00570         set_config_int(section, "alpha_depth",
00571             allegro_gl_get(AGL_ALPHA_DEPTH));
00572     if (save & AGL_COLOR_DEPTH)
00573         set_config_int(section, "color_depth",
00574             allegro_gl_get(AGL_COLOR_DEPTH));
00575     if (save & AGL_ACC_RED_DEPTH)
00576         set_config_int(section, "accum_red_depth",
00577             allegro_gl_get(AGL_ACC_RED_DEPTH));
00578     if (save & AGL_ACC_GREEN_DEPTH)
00579         set_config_int(section, "accum_green_depth",
00580             allegro_gl_get(AGL_ACC_GREEN_DEPTH));
00581     if (save & AGL_ACC_BLUE_DEPTH)
00582         set_config_int(section, "accum_blue_depth",
00583             allegro_gl_get(AGL_ACC_BLUE_DEPTH));
00584     if (save & AGL_ACC_ALPHA_DEPTH)
00585         set_config_int(section, "accum_alpha_depth",
00586             allegro_gl_get(AGL_ACC_ALPHA_DEPTH));
00587     if (save & AGL_DOUBLEBUFFER)
00588         set_config_int(section, "double_buffer",
00589             allegro_gl_get(AGL_DOUBLEBUFFER));
00590     if (save & AGL_STEREO)
00591         set_config_int(section, "stereo_display",
00592             allegro_gl_get(AGL_STEREO));
00593     if (save & AGL_AUX_BUFFERS)
00594         set_config_int(section, "aux_buffers",
00595             allegro_gl_get(AGL_AUX_BUFFERS));
00596     if (save & AGL_Z_DEPTH)
00597         set_config_int(section, "z_depth",
00598             allegro_gl_get(AGL_Z_DEPTH));
00599     if (save & AGL_STENCIL_DEPTH)
00600         set_config_int(section, "stencil_depth",
00601             allegro_gl_get(AGL_STENCIL_DEPTH));
00602     if (save & AGL_WINDOW_X)
00603         set_config_int(section, "window_x",
00604             allegro_gl_get(AGL_WINDOW_X));
00605     if (save & AGL_WINDOW_Y)
00606         set_config_int(section, "window_y",
00607             allegro_gl_get(AGL_WINDOW_Y));
00608     if (save & AGL_FULLSCREEN)
00609         set_config_int(section, "fullscreen",
00610             allegro_gl_get(AGL_FULLSCREEN));
00611     if (save & AGL_WINDOWED)
00612         set_config_int(section, "windowed",
00613             allegro_gl_get(AGL_WINDOWED));
00614     if (save & AGL_VIDEO_MEMORY_POLICY)
00615         set_config_int(section, "video_memory_policy",
00616             allegro_gl_get(AGL_VIDEO_MEMORY_POLICY));
00617     if (save & AGL_SAMPLE_BUFFERS)
00618         set_config_int(section, "sample_buffers",
00619                        allegro_gl_get(AGL_SAMPLE_BUFFERS));
00620     if (save & AGL_SAMPLES)
00621         set_config_int(section, "samples",
00622                        allegro_gl_get(AGL_SAMPLES));
00623     if (save & AGL_FLOAT_COLOR)
00624         set_config_int(section, "float_color",
00625                        allegro_gl_get(AGL_FLOAT_COLOR));
00626     if (save & AGL_FLOAT_Z)
00627         set_config_int(section, "float_depth",
00628                        allegro_gl_get(AGL_FLOAT_Z));
00629 
00630     if (save & AGL_REQUIRE)
00631         build_settings(allegro_gl_get(AGL_REQUIRE), section, "require");
00632     if (save & AGL_SUGGEST)
00633         build_settings(allegro_gl_get(AGL_SUGGEST), section, "suggest");
00634 }
00635 
00636 
00637 
00638 /* Parses an input string to read settings */
00639 static void agl_parse_section(int sec, char *section, char *name) {
00640     const char *end;
00641     char *buf;
00642     char *ptr;
00643     int strsize;
00644     int opt = 0;
00645 
00646     end = get_config_string(section, name, "");
00647     strsize = ustrsizez(end);
00648     
00649     buf = (char*)malloc(sizeof(char) * strsize);
00650     
00651     if (!buf) {
00652         TRACE("** ERROR ** parse_section: Ran out of memory "
00653               "while trying to allocate %i bytes!",
00654               (int)sizeof(char) * strsize);
00655         return;
00656     }
00657 
00658     memcpy(buf, end, strsize);
00659     end = buf + strsize;
00660     ptr = buf;
00661 
00662     while (ptr < end) {
00663         char *s = ustrtok_r(ptr, " ;|+", &ptr);
00664         
00665         if (!ustrcmp(s, "allegro_format"))
00666             opt |= AGL_ALLEGRO_FORMAT;
00667         if (!ustrcmp(s, "red_depth"))
00668             opt |= AGL_RED_DEPTH;
00669         if (!ustrcmp(s, "green_depth"))
00670             opt |= AGL_GREEN_DEPTH;
00671         if (!ustrcmp(s, "blue_depth"))
00672             opt |= AGL_BLUE_DEPTH;
00673         if (!ustrcmp(s, "alpha_depth"))
00674             opt |= AGL_ALPHA_DEPTH;
00675         if (!ustrcmp(s, "color_depth"))
00676             opt |= AGL_COLOR_DEPTH;
00677         if (!ustrcmp(s, "accum_red_depth"))
00678             opt |= AGL_ACC_RED_DEPTH;
00679         if (!ustrcmp(s, "accum_green_depth"))
00680             opt |= AGL_ACC_GREEN_DEPTH;
00681         if (!ustrcmp(s, "accum_blue_depth"))
00682             opt |= AGL_ACC_BLUE_DEPTH;
00683         if (!ustrcmp(s, "accum_alpha_depth"))
00684             opt |= AGL_ACC_ALPHA_DEPTH;
00685         if (!ustrcmp(s, "double_buffer"))
00686             opt |= AGL_DOUBLEBUFFER;
00687         if (!ustrcmp(s, "stereo_display"))
00688             opt |= AGL_STEREO;
00689         if (!ustrcmp(s, "aux_buffers"))
00690             opt |= AGL_AUX_BUFFERS;
00691         if (!ustrcmp(s, "z_depth"))
00692             opt |= AGL_Z_DEPTH;
00693         if (!ustrcmp(s, "stencil_depth"))
00694             opt |= AGL_STENCIL_DEPTH;
00695         if (!ustrcmp(s, "window_x"))
00696             opt |= AGL_WINDOW_X;
00697         if (!ustrcmp(s, "window_y"))
00698             opt |= AGL_WINDOW_Y;
00699         if (!ustrcmp(s, "fullscreen"))
00700             opt |= AGL_FULLSCREEN;
00701         if (!ustrcmp(s, "windowed"))
00702             opt |= AGL_WINDOWED;
00703         if (!ustrcmp(s, "video_memory_policy"))
00704             opt |= AGL_VIDEO_MEMORY_POLICY;
00705         if (!ustrcmp(s, "sample_buffers"))
00706             opt |= AGL_SAMPLE_BUFFERS;
00707         if (!ustrcmp(s, "samples"))
00708             opt |= AGL_SAMPLES;
00709         if (!ustrcmp(s, "float_color"))
00710             opt |= AGL_FLOAT_COLOR;
00711         if (!ustrcmp(s, "float_depth"))
00712             opt |= AGL_FLOAT_Z;
00713     }
00714     
00715     free(buf);
00716     
00717     allegro_gl_set(sec, opt);
00718 }
00719 
00720 
00721 
00722 /* void allegro_gl_load_settings() */
00733 void allegro_gl_load_settings() {
00734 
00735     int set;
00736     char *section = "OpenGL";
00737     
00738     set = get_config_int(section, "allegro_format", -1);
00739     if (set != -1)
00740         allegro_gl_set(AGL_ALLEGRO_FORMAT, set);
00741     set = get_config_int(section, "red_depth", -1);
00742     if (set != -1)
00743         allegro_gl_set(AGL_RED_DEPTH, set);
00744     set = get_config_int(section, "green_depth", -1);
00745     if (set != -1)
00746         allegro_gl_set(AGL_GREEN_DEPTH, set);
00747     set = get_config_int(section, "blue_depth", -1);
00748     if (set != -1)
00749         allegro_gl_set(AGL_BLUE_DEPTH, set);
00750     set = get_config_int(section, "alpha_depth", -1);
00751     if (set != -1)
00752         allegro_gl_set(AGL_ALPHA_DEPTH, set);
00753     set = get_config_int(section, "color_depth", -1);
00754     if (set != -1)
00755         allegro_gl_set(AGL_COLOR_DEPTH, set);
00756     set = get_config_int(section, "accum_red_depth", -1);
00757     if (set != -1)
00758         allegro_gl_set(AGL_ACC_RED_DEPTH, set);
00759     set = get_config_int(section, "accum_green_depth", -1);
00760     if (set != -1)
00761         allegro_gl_set(AGL_ACC_GREEN_DEPTH, set);
00762     set = get_config_int(section, "accum_blue_depth", -1);
00763     if (set != -1)
00764         allegro_gl_set(AGL_ACC_BLUE_DEPTH, set);
00765     set = get_config_int(section, "accum_alpha_depth", -1);
00766     if (set != -1)
00767         allegro_gl_set(AGL_ACC_ALPHA_DEPTH, set);
00768     set = get_config_int(section, "double_buffer", -1);
00769     if (set != -1)
00770         allegro_gl_set(AGL_DOUBLEBUFFER, set);
00771     set = get_config_int(section, "stereo_display", -1);
00772     if (set != -1)
00773         allegro_gl_set(AGL_STEREO, set);
00774     set = get_config_int(section, "aux_buffers", -1);
00775     if (set != -1)
00776         allegro_gl_set(AGL_AUX_BUFFERS, set);
00777     set = get_config_int(section, "z_depth", -1);
00778     if (set != -1)
00779         allegro_gl_set(AGL_Z_DEPTH, set);
00780     set = get_config_int(section, "stencil_depth", -1);
00781     if (set != -1)
00782         allegro_gl_set(AGL_STENCIL_DEPTH, set);
00783     set = get_config_int(section, "window_x", -1);
00784     if (set != -1)
00785         allegro_gl_set(AGL_WINDOW_X, set);
00786     set = get_config_int(section, "window_y", -1);
00787     if (set != -1)
00788         allegro_gl_set(AGL_WINDOW_Y, set);
00789     set = get_config_int(section, "fullscreen", -1);
00790     if (set != -1)
00791         allegro_gl_set(AGL_FULLSCREEN, set);
00792     set = get_config_int(section, "windowed", -1);
00793     if (set != -1)
00794         allegro_gl_set(AGL_WINDOWED, set);
00795     set = get_config_int(section, "video_memory_policy", -1);
00796     if (set != -1)
00797         allegro_gl_set(AGL_VIDEO_MEMORY_POLICY, set);
00798     set = get_config_int(section, "sample_buffers", -1);
00799     if (set != -1)
00800         allegro_gl_set(AGL_SAMPLE_BUFFERS, set);
00801     set = get_config_int(section, "samples", -1);
00802     if (set != -1)
00803         allegro_gl_set(AGL_SAMPLES, set);
00804     set = get_config_int(section, "float_color", -1);
00805     if (set != -1)
00806         allegro_gl_set(AGL_FLOAT_COLOR, set);
00807     set = get_config_int(section, "float_depth", -1);
00808     if (set != -1)
00809         allegro_gl_set(AGL_FLOAT_Z, set);
00810     
00811     agl_parse_section(AGL_REQUIRE, section, "require");
00812     agl_parse_section(AGL_SUGGEST, section, "suggest");
00813 }
00814 
00815 
00816 
00817 /* int install_allegro_gl(void) */
00828 int install_allegro_gl(void)
00829 {
00830     if (!system_driver)
00831         return -1;
00832 
00833     if (atexit(remove_allegro_gl))
00834         return -1;
00835     
00836     if (system_driver->gfx_drivers)
00837         saved_gfx_drivers = system_driver->gfx_drivers;
00838     else
00839         saved_gfx_drivers = list_saved_gfx_drivers;
00840     
00841     system_driver->gfx_drivers = our_gfx_drivers;
00842 
00843     allegro_gl_clear_settings();
00844 
00845     /* Save and replace old blit_between_formats methods */
00846 #ifdef ALLEGRO_COLOR8
00847     __blit_between_formats8 = __linear_vtable8.blit_between_formats;
00848     __linear_vtable8.blit_between_formats =
00849                                          allegro_gl_memory_blit_between_formats;
00850 #endif
00851 #ifdef ALLEGRO_COLOR16
00852     __blit_between_formats15 = __linear_vtable15.blit_between_formats;
00853     __linear_vtable15.blit_between_formats =
00854                                          allegro_gl_memory_blit_between_formats;
00855     __blit_between_formats16 = __linear_vtable16.blit_between_formats;
00856     __linear_vtable16.blit_between_formats
00857                                        = allegro_gl_memory_blit_between_formats;
00858 #endif
00859 #ifdef ALLEGRO_COLOR24
00860     __blit_between_formats24 = __linear_vtable24.blit_between_formats;
00861     __linear_vtable24.blit_between_formats
00862                                        = allegro_gl_memory_blit_between_formats;
00863 #endif
00864 #ifdef ALLEGRO_COLOR32
00865     __blit_between_formats32 = __linear_vtable32.blit_between_formats;
00866     __linear_vtable32.blit_between_formats
00867                                        = allegro_gl_memory_blit_between_formats;
00868 #endif
00869 
00870     usetc(allegro_gl_error, 0);
00871     
00872     return 0;
00873 }
00874 
00875 
00876 
00877 /* void remove_allegro_gl(void) */
00886 void remove_allegro_gl(void)
00887 {
00888     if ((!system_driver) || (!saved_gfx_drivers))
00889         return;
00890 
00891     if (saved_gfx_drivers == &list_saved_gfx_drivers)
00892         system_driver->gfx_drivers = NULL;
00893     else
00894         system_driver->gfx_drivers = saved_gfx_drivers;
00895 
00896     /* This function may be called twice (once by a user explicit call
00897      * and once again at exit since the function is registered with at_exit)
00898      * In order to prevent crashes, 'saved_gfx_drivers' is set to NULL
00899      */
00900     saved_gfx_drivers = NULL;
00901 
00902     /* Restore the blit_between_formats methods */
00903     #ifdef ALLEGRO_COLOR8
00904     __linear_vtable8.blit_between_formats = __blit_between_formats8;
00905     #endif
00906     #ifdef ALLEGRO_COLOR16
00907     __linear_vtable15.blit_between_formats = __blit_between_formats15;
00908     __linear_vtable16.blit_between_formats = __blit_between_formats16;
00909     #endif
00910     #ifdef ALLEGRO_COLOR24
00911     __linear_vtable24.blit_between_formats = __blit_between_formats24;
00912     #endif
00913     #ifdef ALLEGRO_COLOR32
00914     __linear_vtable32.blit_between_formats = __blit_between_formats32;
00915     #endif
00916 }
00917 
00918 
00919 
00920 /* void allegro_gl_flip(void) */
00944 void allegro_gl_flip(void)
00945 {
00946     __allegro_gl_driver->flip();
00947 }
00948 
00949 
00950 
00951 /* float allegro_gl_opengl_version() */
00964 float allegro_gl_opengl_version() {
00965     
00966     const char *str;
00967     
00968     if (!__allegro_gl_valid_context)
00969         return 0.0f;
00970     
00971     str = (const char*)glGetString(GL_VERSION);
00972 
00973     if ((strncmp(str, "1.0 ", 4) == 0) || (strncmp(str, "1.0.0 ", 6) == 0))
00974         return 1.0;
00975     if ((strncmp(str, "1.1 ", 4) == 0) || (strncmp(str, "1.1.0 ", 6) == 0))
00976         return 1.1;
00977     if ((strncmp(str, "1.2 ", 4) == 0) || (strncmp(str, "1.2.0 ", 6) == 0))
00978         return 1.2;
00979     if ((strncmp(str, "1.2.1 ", 6) == 0))
00980         return 1.21;
00981     if ((strncmp(str, "1.2.2 ", 6) == 0))
00982         return 1.22;
00983     if ((strncmp(str, "1.3 ", 4) == 0) || (strncmp(str, "1.3.0 ", 6) == 0))
00984         return 1.3;
00985     if ((strncmp(str, "1.4 ", 4) == 0) || (strncmp(str, "1.4.0 ", 6) == 0))
00986         return 1.4;
00987     if ((strncmp(str, "1.5 ", 4) == 0) || (strncmp(str, "1.5.0 ", 6) == 0))
00988         return 1.5;
00989     if ((strncmp(str, "2.0 ", 4) == 0) || (strncmp(str, "2.0.0 ", 6) == 0))
00990         return 2.0;
00991 
00992     /* The OpenGL driver does not return a version
00993      * number. However it probably supports at least OpenGL 1.0
00994      */ 
00995     if (!str) {
00996         return 1.0;
00997     }
00998     
00999     return atof(str);
01000 }
01001 
01002 
01003 
01004 void __allegro_gl_set_allegro_image_format(int big_endian)
01005 {
01006     /* Sets up Allegro to use OpenGL formats */
01007     _rgb_r_shift_15 = 11;
01008     _rgb_g_shift_15 = 6;
01009     _rgb_b_shift_15 = 1;
01010 
01011     _rgb_r_shift_16 = 11;
01012     _rgb_g_shift_16 = 5;
01013     _rgb_b_shift_16 = 0;
01014 
01015     if (big_endian) {
01016         _rgb_r_shift_24 = 16;
01017         _rgb_g_shift_24 = 8;
01018         _rgb_b_shift_24 = 0;
01019 
01020         _rgb_a_shift_32 = 0;
01021         _rgb_r_shift_32 = 24;
01022         _rgb_g_shift_32 = 16;
01023         _rgb_b_shift_32 = 8;
01024     }
01025     else {
01026         _rgb_r_shift_24 = 0;
01027         _rgb_g_shift_24 = 8;
01028         _rgb_b_shift_24 = 16;
01029 
01030         _rgb_r_shift_32 = 0;
01031         _rgb_g_shift_32 = 8;
01032         _rgb_b_shift_32 = 16;
01033         _rgb_a_shift_32 = 24;
01034     }
01035 
01036     return;
01037 }
01038 
01039 
01040 
01041 /* allegro_gl_default_init:
01042  *  Sets a graphics mode according to the mode (fullscreen or windowed)
01043  *  requested by the user. If it fails to set up the mode then it tries
01044  *  (if available) the other one unless the user has "AGL_REQUIRED" the mode.
01045  */
01046 static BITMAP *allegro_gl_default_gfx_init(int w, int h, int vw, int vh,
01047                                                                      int depth)
01048 {
01049     BITMAP* bmp = NULL;
01050     
01051     if (allegro_gl_display_info.fullscreen) {
01052         TRACE("* Note * default_gfx_init: Trying to set up fullscreen mode.\n");
01053         
01054 #ifdef GFX_OPENGL_FULLSCREEN
01055         /* Looks for fullscreen mode in our_driver_list */
01056         gfx_driver = &gfx_allegro_gl_fullscreen;
01057 
01058         if (__allegro_gl_required_settings & AGL_FULLSCREEN)
01059             /* Fullscreen mode required and found */
01060             return gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01061         else
01062             bmp = gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01063         
01064         if (bmp)
01065             /* Fullscreen mode found but not required (probably suggested) */
01066             return bmp;
01067 
01068 #endif /*GFX_OPENGL_FULLSCREEN*/
01069 
01070         /* Fullscreen mode not available but not required :
01071          * let's try windowed mode :
01072          */
01073         TRACE("* Note * default_gfx_init: Failed to set up fullscreen mode!\n");
01074 #ifdef GFX_OPENGL_WINDOWED
01075         TRACE("* Note * default_gfx_init: Trying windowed mode...\n");
01076         allegro_gl_display_info.fullscreen = FALSE;
01077         gfx_driver = &gfx_allegro_gl_windowed;
01078         return gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01079 #else
01080         return NULL;
01081 #endif /* GFX_OPENGL_WINDOWED */
01082     }
01083     else {
01084         TRACE("* Note * default_gfx_init: Trying to set up windowed mode...\n");
01085         
01086 #ifdef GFX_OPENGL_WINDOWED
01087         /* Looks for windowed mode in our_driver_list */
01088         gfx_driver = &gfx_allegro_gl_windowed;
01089 
01090         if (__allegro_gl_required_settings & AGL_WINDOWED)
01091             /* Windowed mode required and found */
01092             return gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01093         else
01094             bmp = gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01095         
01096         if (bmp)
01097             /* Windowed mode found but not required (probably suggested) */
01098             return bmp;
01099 
01100 #endif /* GFX_OPENGL_WINDOWED */
01101 
01102         /* Windowed mode not available but not required :
01103          * let's try fullscreen mode :
01104          */
01105         TRACE("* Note * default_gfx_init: Failed to set up windowed mode...\n");
01106 #ifdef GFX_OPENGL_FULLSCREEN
01107         TRACE("* Note * default_gfx_init: Trying fullscreen mode...\n");
01108         allegro_gl_display_info.fullscreen = TRUE;
01109         gfx_driver = &gfx_allegro_gl_fullscreen;
01110         return gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01111 #else
01112         return NULL;
01113 #endif /*GFX_OPENGL_FULLSCREEN*/
01114     }
01115 }
01116 
01117 
01118 
01119 #ifdef DEBUGMODE
01120 #ifdef LOGLEVEL
01121 
01122 void __allegro_gl_log(int level, const char *str)
01123 {
01124     if (level <= LOGLEVEL)
01125         TRACE("* Log * [%d] %s", level, str);
01126 }
01127 
01128 #endif
01129 #endif
01130 

Generated on Mon Apr 3 18:20:12 2006 for AllegroGL by  doxygen 1.4.6