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
00023 struct allegro_gl_driver *__allegro_gl_driver = NULL;
00024 struct allegro_gl_display_info allegro_gl_display_info;
00025
00026
00027 int __allegro_gl_required_settings, __allegro_gl_suggested_settings;
00028
00029
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
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,
00102 NULL,
00103 NULL, NULL, NULL,
00104 NULL,
00105 NULL,
00106 NULL, NULL,
00107 NULL, NULL,
00108 NULL, NULL, NULL, NULL,
00109 NULL,
00110 NULL, NULL,
00111 NULL,
00112 0, 0,
00113 0,
00114 0, 0,
00115 0,
00116 0,
00117 FALSE
00118 };
00119
00120
00121
00165
00182 void allegro_gl_clear_settings(void)
00183 {
00184 memset(&allegro_gl_display_info, 0, sizeof allegro_gl_display_info);
00185
00186 __allegro_gl_required_settings = __allegro_gl_suggested_settings = 0;
00187
00188
00189 allegro_gl_display_info.fullscreen = 1;
00190 allegro_gl_display_info.rmethod = 1;
00191 allegro_gl_display_info.doublebuffered = 1;
00192 allegro_gl_display_info.vidmem_policy = AGL_KEEP;
00193 __allegro_gl_suggested_settings =
00194 AGL_FULLSCREEN | AGL_RENDERMETHOD | AGL_DOUBLEBUFFER;
00195 }
00196
00197
00198
00199
00261 void allegro_gl_set(int option, int value)
00262 {
00263 switch (option) {
00264
00265 case AGL_REQUIRE:
00266 __allegro_gl_required_settings |= value;
00267 __allegro_gl_suggested_settings &= ~value;
00268 break;
00269 case AGL_SUGGEST:
00270 __allegro_gl_suggested_settings |= value;
00271 __allegro_gl_required_settings &= ~value;
00272 break;
00273 case AGL_DONTCARE:
00274 __allegro_gl_required_settings &= ~value;
00275 __allegro_gl_suggested_settings &= ~value;
00276 break;
00277
00278
00279 case AGL_ALLEGRO_FORMAT:
00280 allegro_gl_display_info.allegro_format = value;
00281 break;
00282 case AGL_RED_DEPTH:
00283 allegro_gl_display_info.pixel_size.rgba.r = value;
00284 break;
00285 case AGL_GREEN_DEPTH:
00286 allegro_gl_display_info.pixel_size.rgba.g = value;
00287 break;
00288 case AGL_BLUE_DEPTH:
00289 allegro_gl_display_info.pixel_size.rgba.b = value;
00290 break;
00291 case AGL_ALPHA_DEPTH:
00292 allegro_gl_display_info.pixel_size.rgba.a = value;
00293 break;
00294 case AGL_COLOR_DEPTH:
00295 switch (value) {
00296 case 8:
00297 allegro_gl_set(AGL_RED_DEPTH, 3);
00298 allegro_gl_set(AGL_GREEN_DEPTH, 3);
00299 allegro_gl_set(AGL_BLUE_DEPTH, 2);
00300 allegro_gl_set(AGL_ALPHA_DEPTH, 0);
00301 break;
00302 case 15:
00303 allegro_gl_set(AGL_RED_DEPTH, 5);
00304 allegro_gl_set(AGL_GREEN_DEPTH, 5);
00305 allegro_gl_set(AGL_BLUE_DEPTH, 5);
00306 allegro_gl_set(AGL_ALPHA_DEPTH, 1);
00307 break;
00308 case 16:
00309 allegro_gl_set(AGL_RED_DEPTH, 5);
00310 allegro_gl_set(AGL_GREEN_DEPTH, 6);
00311 allegro_gl_set(AGL_BLUE_DEPTH, 5);
00312 allegro_gl_set(AGL_ALPHA_DEPTH, 0);
00313 break;
00314 case 24:
00315 case 32:
00316 allegro_gl_set(AGL_RED_DEPTH, 8);
00317 allegro_gl_set(AGL_GREEN_DEPTH, 8);
00318 allegro_gl_set(AGL_BLUE_DEPTH, 8);
00319 allegro_gl_set(AGL_ALPHA_DEPTH, value-24);
00320 break;
00321 }
00322 allegro_gl_display_info.colour_depth = value;
00323 break;
00324 case AGL_ACC_RED_DEPTH:
00325 allegro_gl_display_info.accum_size.rgba.r = value;
00326 break;
00327 case AGL_ACC_GREEN_DEPTH:
00328 allegro_gl_display_info.accum_size.rgba.g = value;
00329 break;
00330 case AGL_ACC_BLUE_DEPTH:
00331 allegro_gl_display_info.accum_size.rgba.b = value;
00332 break;
00333 case AGL_ACC_ALPHA_DEPTH:
00334 allegro_gl_display_info.accum_size.rgba.a = value;
00335 break;
00336
00337 case AGL_DOUBLEBUFFER:
00338 allegro_gl_display_info.doublebuffered = value;
00339 break;
00340 case AGL_STEREO:
00341 allegro_gl_display_info.stereo = value;
00342 break;
00343 case AGL_AUX_BUFFERS:
00344 allegro_gl_display_info.aux_buffers = value;
00345 break;
00346 case AGL_Z_DEPTH:
00347 allegro_gl_display_info.depth_size = value;
00348 break;
00349 case AGL_STENCIL_DEPTH:
00350 allegro_gl_display_info.stencil_size = value;
00351 break;
00352
00353 case AGL_WINDOW_X:
00354 allegro_gl_display_info.x = value;
00355 break;
00356 case AGL_WINDOW_Y:
00357 allegro_gl_display_info.y = value;
00358 break;
00359
00360 case AGL_RENDERMETHOD:
00361 allegro_gl_display_info.rmethod = value;
00362 break;
00363
00364 case AGL_FULLSCREEN:
00365 allegro_gl_display_info.fullscreen = value;
00366 break;
00367
00368 case AGL_WINDOWED:
00369 allegro_gl_display_info.fullscreen = !value;
00370 break;
00371 case AGL_VIDEO_MEMORY_POLICY:
00372 if ((value == AGL_KEEP) || (value == AGL_RELEASE))
00373 allegro_gl_display_info.vidmem_policy = value;
00374 break;
00375 case AGL_SAMPLE_BUFFERS:
00376 allegro_gl_display_info.sample_buffers = value;
00377 break;
00378 case AGL_SAMPLES:
00379 allegro_gl_display_info.samples = value;
00380 break;
00381 }
00382 }
00383
00384
00385
00402 int allegro_gl_get(int option)
00403 {
00404 switch (option) {
00405
00406 case AGL_REQUIRE:
00407 return __allegro_gl_required_settings;
00408 case AGL_SUGGEST:
00409 return __allegro_gl_suggested_settings;
00410 case AGL_DONTCARE:
00411 return ~0 & ~(__allegro_gl_required_settings |
00412 __allegro_gl_suggested_settings);
00413
00414
00415 case AGL_ALLEGRO_FORMAT:
00416 return allegro_gl_display_info.allegro_format;
00417 case AGL_RED_DEPTH:
00418 return allegro_gl_display_info.pixel_size.rgba.r;
00419 case AGL_GREEN_DEPTH:
00420 return allegro_gl_display_info.pixel_size.rgba.g;
00421 case AGL_BLUE_DEPTH:
00422 return allegro_gl_display_info.pixel_size.rgba.b;
00423 case AGL_ALPHA_DEPTH:
00424 return allegro_gl_display_info.pixel_size.rgba.a;
00425 case AGL_COLOR_DEPTH:
00426 return allegro_gl_display_info.pixel_size.rgba.r
00427 + allegro_gl_display_info.pixel_size.rgba.g
00428 + allegro_gl_display_info.pixel_size.rgba.b
00429 + allegro_gl_display_info.pixel_size.rgba.a;
00430 case AGL_ACC_RED_DEPTH:
00431 return allegro_gl_display_info.accum_size.rgba.r;
00432 case AGL_ACC_GREEN_DEPTH:
00433 return allegro_gl_display_info.accum_size.rgba.g;
00434 case AGL_ACC_BLUE_DEPTH:
00435 return allegro_gl_display_info.accum_size.rgba.b;
00436 case AGL_ACC_ALPHA_DEPTH:
00437 return allegro_gl_display_info.accum_size.rgba.a;
00438 case AGL_DOUBLEBUFFER:
00439 return allegro_gl_display_info.doublebuffered;
00440 case AGL_STEREO:
00441 return allegro_gl_display_info.stereo;
00442 case AGL_AUX_BUFFERS:
00443 return allegro_gl_display_info.aux_buffers;
00444 case AGL_Z_DEPTH:
00445 return allegro_gl_display_info.depth_size;
00446 case AGL_STENCIL_DEPTH:
00447 return allegro_gl_display_info.stencil_size;
00448 case AGL_WINDOW_X:
00449 return allegro_gl_display_info.x;
00450 case AGL_WINDOW_Y:
00451 return allegro_gl_display_info.y;
00452 case AGL_FULLSCREEN:
00453 return allegro_gl_display_info.fullscreen;
00454 case AGL_WINDOWED:
00455 return !allegro_gl_display_info.fullscreen;
00456 case AGL_VIDEO_MEMORY_POLICY:
00457 return allegro_gl_display_info.vidmem_policy;
00458 case AGL_SAMPLE_BUFFERS:
00459 return allegro_gl_display_info.sample_buffers;
00460 case AGL_SAMPLES:
00461 return allegro_gl_display_info.samples;
00462 }
00463 return -1;
00464 }
00465
00466
00467
00468
00469
00470
00471 static void build_settings(int opt, char *section, char *name) {
00472 char buf[2048];
00473
00474 usetc(buf, 0);
00475
00476 if (opt & AGL_ALLEGRO_FORMAT)
00477 ustrcat(buf, "allegro_format ");
00478 if (opt & AGL_RED_DEPTH)
00479 ustrcat(buf, "red_depth ");
00480 if (opt & AGL_GREEN_DEPTH)
00481 ustrcat(buf, "green_depth ");
00482 if (opt & AGL_BLUE_DEPTH)
00483 ustrcat(buf, "blue_depth ");
00484 if (opt & AGL_ALPHA_DEPTH)
00485 ustrcat(buf, "alpha_depth ");
00486 if (opt & AGL_COLOR_DEPTH)
00487 ustrcat(buf, "color_depth ");
00488 if (opt & AGL_ACC_RED_DEPTH)
00489 ustrcat(buf, "accum_red_depth ");
00490 if (opt & AGL_ACC_GREEN_DEPTH)
00491 ustrcat(buf, "accum_green_depth ");
00492 if (opt & AGL_ACC_BLUE_DEPTH)
00493 ustrcat(buf, "accum_blue_depth ");
00494 if (opt & AGL_ACC_ALPHA_DEPTH)
00495 ustrcat(buf, "accum_alpha_depth ");
00496 if (opt & AGL_DOUBLEBUFFER)
00497 ustrcat(buf, "double_buffer ");
00498 if (opt & AGL_STEREO)
00499 ustrcat(buf, "stereo_display ");
00500 if (opt & AGL_AUX_BUFFERS)
00501 ustrcat(buf, "aux_buffers ");
00502 if (opt & AGL_Z_DEPTH)
00503 ustrcat(buf, "z_depth ");
00504 if (opt & AGL_STENCIL_DEPTH)
00505 ustrcat(buf, "stencil_depth ");
00506 if (opt & AGL_WINDOW_X)
00507 ustrcat(buf, "window_x ");
00508 if (opt & AGL_WINDOW_Y)
00509 ustrcat(buf, "window_y ");
00510 if (opt & AGL_FULLSCREEN)
00511 ustrcat(buf, "fullscreen ");
00512 if (opt & AGL_WINDOWED)
00513 ustrcat(buf, "windowed ");
00514 if (opt & AGL_VIDEO_MEMORY_POLICY)
00515 ustrcat(buf, "video_memory_policy ");
00516 if (opt & AGL_SAMPLE_BUFFERS)
00517 ustrcat(buf, "sample_buffers ");
00518 if (opt & AGL_SAMPLES)
00519 ustrcat(buf, "samples ");
00520
00521 set_config_string(section, name, buf);
00522 }
00523
00524
00525
00526
00533 void allegro_gl_save_settings() {
00534
00535 char *section = "OpenGL";
00536 int save = allegro_gl_get(AGL_REQUIRE) | allegro_gl_get(AGL_SUGGEST);
00537
00538 if (save & AGL_ALLEGRO_FORMAT)
00539 set_config_int(section, "allegro_format",
00540 allegro_gl_get(AGL_ALLEGRO_FORMAT));
00541 if (save & AGL_RED_DEPTH)
00542 set_config_int(section, "red_depth",
00543 allegro_gl_get(AGL_RED_DEPTH));
00544 if (save & AGL_GREEN_DEPTH)
00545 set_config_int(section, "green_depth",
00546 allegro_gl_get(AGL_GREEN_DEPTH));
00547 if (save & AGL_BLUE_DEPTH)
00548 set_config_int(section, "blue_depth",
00549 allegro_gl_get(AGL_BLUE_DEPTH));
00550 if (save & AGL_ALPHA_DEPTH)
00551 set_config_int(section, "alpha_depth",
00552 allegro_gl_get(AGL_ALPHA_DEPTH));
00553 if (save & AGL_COLOR_DEPTH)
00554 set_config_int(section, "color_depth",
00555 allegro_gl_get(AGL_COLOR_DEPTH));
00556 if (save & AGL_ACC_RED_DEPTH)
00557 set_config_int(section, "accum_red_depth",
00558 allegro_gl_get(AGL_ACC_RED_DEPTH));
00559 if (save & AGL_ACC_GREEN_DEPTH)
00560 set_config_int(section, "accum_green_depth",
00561 allegro_gl_get(AGL_ACC_GREEN_DEPTH));
00562 if (save & AGL_ACC_BLUE_DEPTH)
00563 set_config_int(section, "accum_blue_depth",
00564 allegro_gl_get(AGL_ACC_BLUE_DEPTH));
00565 if (save & AGL_ACC_ALPHA_DEPTH)
00566 set_config_int(section, "accum_alpha_depth",
00567 allegro_gl_get(AGL_ACC_ALPHA_DEPTH));
00568 if (save & AGL_DOUBLEBUFFER)
00569 set_config_int(section, "double_buffer",
00570 allegro_gl_get(AGL_DOUBLEBUFFER));
00571 if (save & AGL_STEREO)
00572 set_config_int(section, "stereo_display",
00573 allegro_gl_get(AGL_STEREO));
00574 if (save & AGL_AUX_BUFFERS)
00575 set_config_int(section, "aux_buffers",
00576 allegro_gl_get(AGL_AUX_BUFFERS));
00577 if (save & AGL_Z_DEPTH)
00578 set_config_int(section, "z_depth",
00579 allegro_gl_get(AGL_Z_DEPTH));
00580 if (save & AGL_STENCIL_DEPTH)
00581 set_config_int(section, "stencil_depth",
00582 allegro_gl_get(AGL_STENCIL_DEPTH));
00583 if (save & AGL_WINDOW_X)
00584 set_config_int(section, "window_x",
00585 allegro_gl_get(AGL_WINDOW_X));
00586 if (save & AGL_WINDOW_Y)
00587 set_config_int(section, "window_y",
00588 allegro_gl_get(AGL_WINDOW_Y));
00589 if (save & AGL_FULLSCREEN)
00590 set_config_int(section, "fullscreen",
00591 allegro_gl_get(AGL_FULLSCREEN));
00592 if (save & AGL_WINDOWED)
00593 set_config_int(section, "windowed",
00594 allegro_gl_get(AGL_WINDOWED));
00595 if (save & AGL_VIDEO_MEMORY_POLICY)
00596 set_config_int(section, "video_memory_policy",
00597 allegro_gl_get(AGL_VIDEO_MEMORY_POLICY));
00598 if (save & AGL_SAMPLE_BUFFERS)
00599 set_config_int(section, "sample_buffers",
00600 allegro_gl_get(AGL_SAMPLE_BUFFERS));
00601 if (save & AGL_SAMPLES)
00602 set_config_int(section, "samples",
00603 allegro_gl_get(AGL_SAMPLES));
00604
00605 if (save & AGL_REQUIRE)
00606 build_settings(allegro_gl_get(AGL_REQUIRE), section, "require");
00607 if (save & AGL_SUGGEST)
00608 build_settings(allegro_gl_get(AGL_SUGGEST), section, "suggest");
00609 }
00610
00611
00612
00613
00614 static void agl_parse_section(int sec, char *section, char *name) {
00615 const char *end;
00616 char *buf;
00617 char *ptr;
00618 int strsize;
00619 int opt = 0;
00620
00621 end = get_config_string(section, name, "");
00622 strsize = ustrsizez(end);
00623
00624 buf = (char*)malloc(sizeof(char) * strsize);
00625
00626 if (!buf) {
00627 TRACE("** ERROR ** parse_section: Ran out of memory "
00628 "while trying to allocate %i bytes!",
00629 (int)sizeof(char) * strsize);
00630 return;
00631 }
00632
00633 memcpy(buf, end, strsize);
00634 end = buf + strsize;
00635 ptr = buf;
00636
00637 while (ptr < end) {
00638 char *s = ustrtok_r(ptr, " ;|+", &ptr);
00639
00640 if (!ustrcmp(s, "allegro_format"))
00641 opt |= AGL_ALLEGRO_FORMAT;
00642 if (!ustrcmp(s, "red_depth"))
00643 opt |= AGL_RED_DEPTH;
00644 if (!ustrcmp(s, "green_depth"))
00645 opt |= AGL_GREEN_DEPTH;
00646 if (!ustrcmp(s, "blue_depth"))
00647 opt |= AGL_BLUE_DEPTH;
00648 if (!ustrcmp(s, "alpha_depth"))
00649 opt |= AGL_ALPHA_DEPTH;
00650 if (!ustrcmp(s, "color_depth"))
00651 opt |= AGL_COLOR_DEPTH;
00652 if (!ustrcmp(s, "accum_red_depth"))
00653 opt |= AGL_ACC_RED_DEPTH;
00654 if (!ustrcmp(s, "accum_green_depth"))
00655 opt |= AGL_ACC_GREEN_DEPTH;
00656 if (!ustrcmp(s, "accum_blue_depth"))
00657 opt |= AGL_ACC_BLUE_DEPTH;
00658 if (!ustrcmp(s, "accum_alpha_depth"))
00659 opt |= AGL_ACC_ALPHA_DEPTH;
00660 if (!ustrcmp(s, "double_buffer"))
00661 opt |= AGL_DOUBLEBUFFER;
00662 if (!ustrcmp(s, "stereo_display"))
00663 opt |= AGL_STEREO;
00664 if (!ustrcmp(s, "aux_buffers"))
00665 opt |= AGL_AUX_BUFFERS;
00666 if (!ustrcmp(s, "z_depth"))
00667 opt |= AGL_Z_DEPTH;
00668 if (!ustrcmp(s, "stencil_depth"))
00669 opt |= AGL_STENCIL_DEPTH;
00670 if (!ustrcmp(s, "window_x"))
00671 opt |= AGL_WINDOW_X;
00672 if (!ustrcmp(s, "window_y"))
00673 opt |= AGL_WINDOW_Y;
00674 if (!ustrcmp(s, "fullscreen"))
00675 opt |= AGL_FULLSCREEN;
00676 if (!ustrcmp(s, "windowed"))
00677 opt |= AGL_WINDOWED;
00678 if (!ustrcmp(s, "video_memory_policy"))
00679 opt |= AGL_VIDEO_MEMORY_POLICY;
00680 if (!ustrcmp(s, "sample_buffers"))
00681 opt |= AGL_SAMPLE_BUFFERS;
00682 if (!ustrcmp(s, "samples"))
00683 opt |= AGL_SAMPLES;
00684 }
00685
00686 free(buf);
00687
00688 allegro_gl_set(sec, opt);
00689 }
00690
00691
00692
00693
00704 void allegro_gl_load_settings() {
00705
00706 int set;
00707 char *section = "OpenGL";
00708
00709 set = get_config_int(section, "allegro_format", -1);
00710 if (set != -1)
00711 allegro_gl_set(AGL_ALLEGRO_FORMAT, set);
00712 set = get_config_int(section, "red_depth", -1);
00713 if (set != -1)
00714 allegro_gl_set(AGL_RED_DEPTH, set);
00715 set = get_config_int(section, "green_depth", -1);
00716 if (set != -1)
00717 allegro_gl_set(AGL_GREEN_DEPTH, set);
00718 set = get_config_int(section, "blue_depth", -1);
00719 if (set != -1)
00720 allegro_gl_set(AGL_BLUE_DEPTH, set);
00721 set = get_config_int(section, "alpha_depth", -1);
00722 if (set != -1)
00723 allegro_gl_set(AGL_ALPHA_DEPTH, set);
00724 set = get_config_int(section, "color_depth", -1);
00725 if (set != -1)
00726 allegro_gl_set(AGL_COLOR_DEPTH, set);
00727 set = get_config_int(section, "accum_red_depth", -1);
00728 if (set != -1)
00729 allegro_gl_set(AGL_ACC_RED_DEPTH, set);
00730 set = get_config_int(section, "accum_green_depth", -1);
00731 if (set != -1)
00732 allegro_gl_set(AGL_ACC_GREEN_DEPTH, set);
00733 set = get_config_int(section, "accum_blue_depth", -1);
00734 if (set != -1)
00735 allegro_gl_set(AGL_ACC_BLUE_DEPTH, set);
00736 set = get_config_int(section, "accum_alpha_depth", -1);
00737 if (set != -1)
00738 allegro_gl_set(AGL_ACC_ALPHA_DEPTH, set);
00739 set = get_config_int(section, "double_buffer", -1);
00740 if (set != -1)
00741 allegro_gl_set(AGL_DOUBLEBUFFER, set);
00742 set = get_config_int(section, "stereo_display", -1);
00743 if (set != -1)
00744 allegro_gl_set(AGL_STEREO, set);
00745 set = get_config_int(section, "aux_buffers", -1);
00746 if (set != -1)
00747 allegro_gl_set(AGL_AUX_BUFFERS, set);
00748 set = get_config_int(section, "z_depth", -1);
00749 if (set != -1)
00750 allegro_gl_set(AGL_Z_DEPTH, set);
00751 set = get_config_int(section, "stencil_depth", -1);
00752 if (set != -1)
00753 allegro_gl_set(AGL_STENCIL_DEPTH, set);
00754 set = get_config_int(section, "window_x", -1);
00755 if (set != -1)
00756 allegro_gl_set(AGL_WINDOW_X, set);
00757 set = get_config_int(section, "window_y", -1);
00758 if (set != -1)
00759 allegro_gl_set(AGL_WINDOW_Y, set);
00760 set = get_config_int(section, "fullscreen", -1);
00761 if (set != -1)
00762 allegro_gl_set(AGL_FULLSCREEN, set);
00763 set = get_config_int(section, "windowed", -1);
00764 if (set != -1)
00765 allegro_gl_set(AGL_WINDOWED, set);
00766 set = get_config_int(section, "video_memory_policy", -1);
00767 if (set != -1)
00768 allegro_gl_set(AGL_VIDEO_MEMORY_POLICY, set);
00769 set = get_config_int(section, "sample_buffers", -1);
00770 if (set != -1)
00771 allegro_gl_set(AGL_SAMPLE_BUFFERS, set);
00772 set = get_config_int(section, "samples", -1);
00773 if (set != -1)
00774 allegro_gl_set(AGL_SAMPLES, set);
00775
00776 agl_parse_section(AGL_REQUIRE, section, "require");
00777 agl_parse_section(AGL_SUGGEST, section, "suggest");
00778 }
00779
00780
00781
00782
00793 int install_allegro_gl(void)
00794 {
00795 if (!system_driver)
00796 return -1;
00797
00798 if (atexit(remove_allegro_gl))
00799 return -1;
00800
00801 if (system_driver->gfx_drivers)
00802 saved_gfx_drivers = system_driver->gfx_drivers;
00803 else
00804 saved_gfx_drivers = list_saved_gfx_drivers;
00805
00806 system_driver->gfx_drivers = our_gfx_drivers;
00807
00808 allegro_gl_clear_settings();
00809
00810
00811 #ifdef ALLEGRO_COLOR8
00812 __blit_between_formats8 = __linear_vtable8.blit_between_formats;
00813 __linear_vtable8.blit_between_formats =
00814 allegro_gl_memory_blit_between_formats;
00815 #endif
00816 #ifdef ALLEGRO_COLOR16
00817 __blit_between_formats15 = __linear_vtable15.blit_between_formats;
00818 __linear_vtable15.blit_between_formats =
00819 allegro_gl_memory_blit_between_formats;
00820 __blit_between_formats16 = __linear_vtable16.blit_between_formats;
00821 __linear_vtable16.blit_between_formats
00822 = allegro_gl_memory_blit_between_formats;
00823 #endif
00824 #ifdef ALLEGRO_COLOR24
00825 __blit_between_formats24 = __linear_vtable24.blit_between_formats;
00826 __linear_vtable24.blit_between_formats
00827 = allegro_gl_memory_blit_between_formats;
00828 #endif
00829 #ifdef ALLEGRO_COLOR32
00830 __blit_between_formats32 = __linear_vtable32.blit_between_formats;
00831 __linear_vtable32.blit_between_formats
00832 = allegro_gl_memory_blit_between_formats;
00833 #endif
00834
00835 usetc(allegro_gl_error, 0);
00836
00837 return 0;
00838 }
00839
00840
00841
00842
00851 void remove_allegro_gl(void)
00852 {
00853 if ((!system_driver) || (!saved_gfx_drivers))
00854 return;
00855
00856 if (saved_gfx_drivers == &list_saved_gfx_drivers)
00857 system_driver->gfx_drivers = NULL;
00858 else
00859 system_driver->gfx_drivers = saved_gfx_drivers;
00860
00861
00862
00863
00864
00865 saved_gfx_drivers = NULL;
00866
00867
00868 #ifdef ALLEGRO_COLOR8
00869 __linear_vtable8.blit_between_formats = __blit_between_formats8;
00870 #endif
00871 #ifdef ALLEGRO_COLOR16
00872 __linear_vtable15.blit_between_formats = __blit_between_formats15;
00873 __linear_vtable16.blit_between_formats = __blit_between_formats16;
00874 #endif
00875 #ifdef ALLEGRO_COLOR24
00876 __linear_vtable24.blit_between_formats = __blit_between_formats24;
00877 #endif
00878 #ifdef ALLEGRO_COLOR32
00879 __linear_vtable32.blit_between_formats = __blit_between_formats32;
00880 #endif
00881 }
00882
00883
00884
00885
00909 void allegro_gl_flip(void)
00910 {
00911 __allegro_gl_driver->flip();
00912 }
00913
00914
00915
00916
00929 float allegro_gl_opengl_version() {
00930
00931 const GLubyte *str;
00932
00933 if (!__allegro_gl_valid_context)
00934 return 0.0f;
00935
00936 str = glGetString(GL_VERSION);
00937
00938 if ((strncmp(str, "1.0 ", 4) == 0) || (strncmp(str, "1.0.0 ", 6) == 0))
00939 return 1.0;
00940 if ((strncmp(str, "1.1 ", 4) == 0) || (strncmp(str, "1.1.0 ", 6) == 0))
00941 return 1.1;
00942 if ((strncmp(str, "1.2 ", 4) == 0) || (strncmp(str, "1.2.0 ", 6) == 0))
00943 return 1.2;
00944 if ((strncmp(str, "1.2.1 ", 6) == 0))
00945 return 1.21;
00946 if ((strncmp(str, "1.2.2 ", 6) == 0))
00947 return 1.22;
00948 if ((strncmp(str, "1.3 ", 4) == 0) || (strncmp(str, "1.3.0 ", 6) == 0))
00949 return 1.3;
00950 if ((strncmp(str, "1.4 ", 4) == 0) || (strncmp(str, "1.4.0 ", 6) == 0))
00951 return 1.4;
00952 if ((strncmp(str, "1.5 ", 4) == 0) || (strncmp(str, "1.5.0 ", 6) == 0))
00953 return 1.5;
00954 if ((strncmp(str, "2.0 ", 4) == 0) || (strncmp(str, "2.0.0 ", 6) == 0))
00955 return 2.0;
00956
00957
00958
00959
00960 if (!str) {
00961 return 1.0;
00962 }
00963
00964 return atof(str);
00965 }
00966
00967
00968
00969 void __allegro_gl_set_allegro_image_format(int big_endian)
00970 {
00971
00972 _rgb_r_shift_15 = 11;
00973 _rgb_g_shift_15 = 6;
00974 _rgb_b_shift_15 = 1;
00975
00976 _rgb_r_shift_16 = 11;
00977 _rgb_g_shift_16 = 5;
00978 _rgb_b_shift_16 = 0;
00979
00980 if (big_endian) {
00981 _rgb_r_shift_24 = 16;
00982 _rgb_g_shift_24 = 8;
00983 _rgb_b_shift_24 = 0;
00984
00985 _rgb_a_shift_32 = 0;
00986 _rgb_r_shift_32 = 24;
00987 _rgb_g_shift_32 = 16;
00988 _rgb_b_shift_32 = 8;
00989 }
00990 else {
00991 _rgb_r_shift_24 = 0;
00992 _rgb_g_shift_24 = 8;
00993 _rgb_b_shift_24 = 16;
00994
00995 _rgb_r_shift_32 = 0;
00996 _rgb_g_shift_32 = 8;
00997 _rgb_b_shift_32 = 16;
00998 _rgb_a_shift_32 = 24;
00999 }
01000
01001 return;
01002 }
01003
01004
01005
01006
01007
01008
01009
01010
01011 static BITMAP *allegro_gl_default_gfx_init(int w, int h, int vw, int vh,
01012 int depth)
01013 {
01014 BITMAP* bmp = NULL;
01015
01016 if (allegro_gl_display_info.fullscreen) {
01017 TRACE("* Note * default_gfx_init: Trying to set up fullscreen mode.\n");
01018
01019 #ifdef GFX_OPENGL_FULLSCREEN
01020
01021 gfx_driver = &gfx_allegro_gl_fullscreen;
01022
01023 if (__allegro_gl_required_settings & AGL_FULLSCREEN)
01024
01025 return gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01026 else
01027 bmp = gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01028
01029 if (bmp)
01030
01031 return bmp;
01032
01033 #endif
01034
01035
01036
01037
01038 TRACE("* Note * default_gfx_init: Failed to set up fullscreen mode!\n");
01039 #ifdef GFX_OPENGL_WINDOWED
01040 TRACE("* Note * default_gfx_init: Trying windowed mode...\n");
01041 allegro_gl_display_info.fullscreen = FALSE;
01042 gfx_driver = &gfx_allegro_gl_windowed;
01043 return gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01044 #else
01045 return NULL;
01046 #endif
01047 }
01048 else {
01049 TRACE("* Note * default_gfx_init: Trying to set up windowed mode...\n");
01050
01051 #ifdef GFX_OPENGL_WINDOWED
01052
01053 gfx_driver = &gfx_allegro_gl_windowed;
01054
01055 if (__allegro_gl_required_settings & AGL_WINDOWED)
01056
01057 return gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01058 else
01059 bmp = gfx_allegro_gl_windowed.init(w, h, vw, vh, depth);
01060
01061 if (bmp)
01062
01063 return bmp;
01064
01065 #endif
01066
01067
01068
01069
01070 TRACE("* Note * default_gfx_init: Failed to set up windowed mode...\n");
01071 #ifdef GFX_OPENGL_FULLSCREEN
01072 TRACE("* Note * default_gfx_init: Trying fullscreen mode...\n");
01073 allegro_gl_display_info.fullscreen = TRUE;
01074 gfx_driver = &gfx_allegro_gl_fullscreen;
01075 return gfx_allegro_gl_fullscreen.init(w, h, vw, vh, depth);
01076 #else
01077 return NULL;
01078 #endif
01079 }
01080 }
01081
01082
01083
01084 #ifdef DEBUGMODE
01085 #ifdef LOGLEVEL
01086
01087 void __allegro_gl_log(int level, const char *str)
01088 {
01089 if (level <= LOGLEVEL)
01090 TRACE("* Log * [%d] %s", level, str);
01091 }
01092
01093 #endif
01094 #endif
01095