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