15 #include <allegro/internal/aintern.h> 22 static void allegro_gl_amesa_exit(BITMAP *bmp);
23 static void __allegro_gl_init_texture_read_format(
void);
25 #ifdef GFX_OPENGL_FULLSCREEN 26 static BITMAP *allegro_gl_amesa_fullscreen_init(
int w,
int h,
int vw,
int vh,
int color_depth);
28 GFX_DRIVER gfx_allegro_gl_fullscreen =
33 "AllegroGL Fullscreen (AMesa)",
34 allegro_gl_amesa_fullscreen_init,
35 allegro_gl_amesa_exit,
44 allegro_gl_set_mouse_sprite,
45 allegro_gl_show_mouse,
46 allegro_gl_hide_mouse,
47 allegro_gl_move_mouse,
61 #ifdef GFX_OPENGL_WINDOWED 62 static BITMAP *allegro_gl_amesa_windowed_init(
int w,
int h,
int vw,
int vh,
int color_depth);
64 GFX_DRIVER gfx_allegro_gl_windowed =
69 "AllegroGL Windowed (AMesa)",
70 allegro_gl_amesa_windowed_init,
71 allegro_gl_amesa_exit,
80 allegro_gl_set_mouse_sprite,
81 allegro_gl_show_mouse,
82 allegro_gl_hide_mouse,
83 allegro_gl_move_mouse,
98 static int allegro_gl_amesa_create_window (
int fullscreen);
99 static BITMAP *allegro_gl_amesa_create_screen_bitmap (GFX_DRIVER *drv,
int w,
int h,
int depth);
105 AMesaContext context;
108 static struct AMESA_DATA _amesa;
109 static struct allegro_gl_driver allegro_gl_amesa;
111 static BITMAP* subscreen = NULL;
112 static BITMAP* saved_screen = NULL;
114 GFX_DRIVER *amesa_gfx_driver = NULL;
116 static GFX_VTABLE allegro_gl_generic_vtable;
117 static GFX_VTABLE *old_vtable;
124 static BITMAP *allegro_gl_amesa_create_screen(
int w,
int h,
int vw,
int vh,
int depth,
int fullscreen)
126 int _keyboard_was_installed = FALSE;
127 int _mouse_was_installed = FALSE;
128 GFX_VTABLE vtable, *pvtable;
132 if (keyboard_driver) {
133 _keyboard_was_installed = TRUE;
135 TRACE(
"* Note * amesa_create_screen: Removing Keyboard...\n");
139 _mouse_was_installed = TRUE;
141 TRACE(
"* Note * amesa_create_screen: Removing Mouse...\n");
144 if ((w == 0) && (h == 0)) {
149 if ((vw > w) || (vh > h)) {
150 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE,
151 get_config_text (
"OpenGL drivers do not support virtual screens"));
155 allegro_gl_display_info.w = w;
156 allegro_gl_display_info.h = h;
158 if (allegro_gl_amesa_create_window(fullscreen)) {
160 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE,
161 get_config_text (
"Unable to switch in AMesa fullscreen"));
164 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE,
165 get_config_text (
"Unable to create AMesa window"));
173 #ifdef GFX_OPENGL_FULLSCREEN 174 allegro_gl_screen = allegro_gl_amesa_create_screen_bitmap (&gfx_allegro_gl_fullscreen, w, h, allegro_gl_display_info.colour_depth);
178 #ifdef GFX_OPENGL_WINDOWED 179 allegro_gl_screen = allegro_gl_amesa_create_screen_bitmap (&gfx_allegro_gl_windowed, w, h, allegro_gl_display_info.colour_depth);
184 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE,
185 get_config_text (
"Error creating screen bitmap"));
189 __allegro_gl_valid_context = TRUE;
190 __allegro_gl_driver = &allegro_gl_amesa;
191 LOCK_DATA(&_amesa,
sizeof(AMESA_DATA));
192 LOCK_DATA(__allegro_gl_driver,
sizeof(
struct allegro_gl_driver));
207 __allegro_gl__glvtable_update_vtable(&pvtable);
211 __allegro_gl_init_screen_mode();
214 TRACE(
"\n\nOpenGL Version: %s\nVendor: %s\nRenderer: %s\n",
215 (
const char*)glGetString(GL_VERSION),
216 (
const char*)glGetString(GL_VENDOR),
217 (
const char*)glGetString(GL_RENDERER));
220 __allegro_gl_manage_extensions();
221 __allegro_gl_init_texture_read_format();
223 if (_keyboard_was_installed) {
225 TRACE(
"* Note * amesa_create_screen: Installing Keyboard...\n");
228 if (_mouse_was_installed) {
230 TRACE(
"* Note * amesa_create_screen: Installing Mouse...\n");
234 gfx_capabilities |= GFX_HW_CURSOR;
236 allegro_gl_info.is_mesa_driver = TRUE;
237 _amesa.fullscreen = fullscreen;
243 #ifdef GFX_OPENGL_WINDOWED 247 static BITMAP *allegro_gl_amesa_windowed_init(
int w,
int h,
int vw,
int vh,
int depth)
249 return allegro_gl_amesa_create_screen(w, h, vw, vh, depth, FALSE);
255 #ifdef GFX_OPENGL_FULLSCREEN 259 static BITMAP *allegro_gl_amesa_fullscreen_init(
int w,
int h,
int vw,
int vh,
int depth)
261 return allegro_gl_amesa_create_screen(w, h, vw, vh, depth, TRUE);
270 static void allegro_gl_amesa_exit(BITMAP *bmp)
273 screen = saved_screen;
275 destroy_bitmap(subscreen);
277 amesa_gfx_driver->exit(screen);
279 AMesaMakeCurrent(_amesa.context, NULL);
280 AMesaDestroyVisual(_amesa.visual);
281 AMesaDestroyBuffer(_amesa.buffer);
282 AMesaDestroyContext(_amesa.context);
284 __allegro_gl_valid_context = FALSE;
289 static void amesa_choose_gfx_mode(_DRIVER_INFO *driver_info,
int *w,
int *h,
292 GFX_MODE_LIST *mode_list;
296 TRACE(
"* Note * amesa_choose_gfx_mode: GFX driver : %s\n",
297 ((GFX_DRIVER*)driver_info->driver)->ascii_name);
302 mode_list = get_gfx_mode_list(driver_info->id);
305 TRACE(
"* Note * amesa_choose_gfx_mode: %i modes\n",
306 mode_list->num_modes);
308 mode = mode_list->mode;
310 for (i = 0; i < mode_list->num_modes; i++) {
311 TRACE(
"Mode %i : %ix%i %i bpp\n", i, mode->width, mode->height,
313 if ((mode->width >= *w) && (mode->height >= *h) &&
314 (mode->bpp >= *colour_depth)) {
321 if ((mode->width) && (mode->height) && (mode->bpp)) {
322 allegro_gl_display_info.w = *w = mode->width;
323 allegro_gl_display_info.h = *h = mode->height;
324 allegro_gl_display_info.colour_depth = *colour_depth = mode->bpp;
326 TRACE(
"Best Mode : %ix%i %i bpp\n", *w, *h, *colour_depth);
327 destroy_gfx_mode_list(mode_list);
330 TRACE(
"** Warning ** amesa_choose_gfx_mode: Can not list modes...\n" 331 "Trying %ix%i %i bpp anyway\n", *w, *h, *colour_depth);
343 static int amesa_set_gfx_mode(
int fullscreen)
345 extern void blit_end();
346 _DRIVER_INFO *driver_list;
348 char buf[512], tmp[64];
350 int card = GFX_AUTODETECT;
351 int w = allegro_gl_display_info.w;
352 int h = allegro_gl_display_info.h;
353 int check_mode = TRUE, require_window = FALSE;
355 driver_list = saved_gfx_drivers();
358 require_window = TRUE;
361 for (n=-2; n<255; n++) {
366 usprintf(buf, uconvert_ascii(
"gfx_card_%dx%dx%d", tmp), w, h,
372 usprintf(buf, uconvert_ascii(
"gfx_card_%dbpp", tmp),
378 ustrcpy(buf, uconvert_ascii(
"gfx_card", tmp));
383 usprintf(buf, uconvert_ascii(
"gfx_card%d", tmp), n);
386 card = get_config_id(uconvert_ascii(
"graphics", tmp), buf,
389 if (card != GFX_AUTODETECT) {
391 for (c=0; driver_list[c].driver; c++) {
392 if (driver_list[c].
id == card) {
393 amesa_gfx_driver = driver_list[c].driver;
396 if ( ((require_window) && (!amesa_gfx_driver->windowed))
397 || ((!require_window)
398 && (amesa_gfx_driver->windowed))) {
400 amesa_gfx_driver = NULL;
408 if (amesa_gfx_driver) {
410 amesa_gfx_driver->name = amesa_gfx_driver->desc
411 = get_config_text(amesa_gfx_driver->ascii_name);
413 amesa_choose_gfx_mode(&driver_list[c], &w, &h, &_color_depth);
415 screen = amesa_gfx_driver->init(w, h, 0, 0, _color_depth);
420 amesa_gfx_driver = NULL;
432 for (c=0; driver_list[c].driver; c++) {
434 if (driver_list[c].autodetect) {
436 amesa_gfx_driver = driver_list[c].driver;
438 if (((require_window) && (!amesa_gfx_driver->windowed)) ||
439 ((!require_window) && (amesa_gfx_driver->windowed)))
443 amesa_gfx_driver->name = amesa_gfx_driver->desc
444 = get_config_text(amesa_gfx_driver->ascii_name);
446 amesa_choose_gfx_mode(&driver_list[c], &w, &h, &_color_depth);
448 screen = amesa_gfx_driver->init(w, h, 0, 0, _color_depth);
458 amesa_gfx_driver = NULL;
462 LOCK_DATA(amesa_gfx_driver,
sizeof(GFX_DRIVER));
463 _register_switch_bitmap(screen, NULL);
473 static int allegro_gl_amesa_create_window (
int fullscreen)
475 if (!allegro_gl_display_info.colour_depth)
476 allegro_gl_display_info.colour_depth = _color_depth;
478 set_color_depth(allegro_gl_display_info.colour_depth);
480 if (amesa_set_gfx_mode(fullscreen)) {
481 TRACE(
"** ERROR ** amesa_create_window: Unable to set a gfx mode!\n");
485 _amesa.visual = AMesaCreateVisual(allegro_gl_display_info.doublebuffered,
486 allegro_gl_display_info.colour_depth,
488 allegro_gl_display_info.depth_size,
489 allegro_gl_display_info.stencil_size,
490 allegro_gl_display_info.accum_size.rgba.r,
491 allegro_gl_display_info.accum_size.rgba.g,
492 allegro_gl_display_info.accum_size.rgba.b,
493 allegro_gl_display_info.accum_size.rgba.a
495 if (!_amesa.visual) {
496 TRACE(
"** ERROR ** amesa_create_window: Unable to create AMesa " 501 _amesa.context = AMesaCreateContext(_amesa.visual, NULL);
502 if (!_amesa.context) {
503 TRACE(
"** ERROR ** amesa_create_window: Unable to create AMesa " 505 AMesaDestroyVisual(_amesa.visual);
509 if ((screen->w != allegro_gl_display_info.w)
510 || (screen->h != allegro_gl_display_info.h)) {
512 subscreen = create_sub_bitmap(screen, 0, 0,
513 allegro_gl_display_info.w, allegro_gl_display_info.h);
515 _amesa.buffer = AMesaCreateBuffer(_amesa.visual, subscreen);
517 TRACE(
"** Note ** amesa_create_window: Screen : %ix%i %i bpp\n",
518 ubscreen->w, subscreen->h, bitmap_color_depth(subscreen));
521 _amesa.buffer = AMesaCreateBuffer(_amesa.visual, screen);
524 if (!_amesa.buffer) {
525 AMesaDestroyContext(_amesa.context);
526 AMesaDestroyVisual(_amesa.visual);
527 TRACE(
"** ERROR ** amesa_create_window: Unable to create AMesa " 532 if (!AMesaMakeCurrent(_amesa.context, _amesa.buffer)) {
533 AMesaDestroyContext(_amesa.context);
534 AMesaDestroyVisual(_amesa.visual);
535 AMesaDestroyBuffer(_amesa.buffer);
536 TRACE(
"** ERROR ** amesa_create_window: Unable to make context " 541 saved_screen = screen;
547 static BITMAP *allegro_gl_amesa_create_screen_bitmap (GFX_DRIVER *drv,
548 int w,
int h,
int depth)
552 drv->linear = amesa_gfx_driver->linear;
553 drv->bank_size = amesa_gfx_driver->bank_size;
554 drv->bank_gran = amesa_gfx_driver->bank_gran;
555 drv->vid_mem = amesa_gfx_driver->vid_mem;
556 drv->vid_phys_base = amesa_gfx_driver->vid_phys_base;
558 return AMesaGetColorBuffer(_amesa.buffer, AMESA_ACTIVE);
563 static void __allegro_gl_init_texture_read_format(
void)
566 __allegro_gl_texture_read_format[0] = GL_UNSIGNED_BYTE_3_3_2;
569 if (_rgb_r_shift_15 > _rgb_b_shift_15) {
570 __allegro_gl_texture_read_format[1] = GL_UNSIGNED_SHORT_5_5_5_1;
571 if (_rgb_r_shift_15 == 10) {
572 __allegro_gl_texture_components[1] = GL_BGRA;
576 __allegro_gl_texture_read_format[1] = GL_UNSIGNED_SHORT_1_5_5_5_REV;
580 if (_rgb_r_shift_16 > _rgb_b_shift_16) {
581 __allegro_gl_texture_read_format[2] = GL_UNSIGNED_SHORT_5_6_5;
584 __allegro_gl_texture_read_format[2] = GL_UNSIGNED_SHORT_5_6_5_REV;
588 __allegro_gl_texture_read_format[3] = GL_UNSIGNED_BYTE;
591 if (_rgb_r_shift_32 > _rgb_b_shift_32) {
592 __allegro_gl_texture_read_format[4] = GL_UNSIGNED_INT_8_8_8_8_REV;
593 if (_rgb_r_shift_32 == 16) {
594 __allegro_gl_texture_components[4] = GL_BGRA;
598 __allegro_gl_texture_read_format[4] = GL_UNSIGNED_BYTE;
611 static void amesa_flip (
void)
613 AMesaSwapBuffers (_amesa.buffer);
621 static void amesa_gl_on (
void)
627 static void amesa_gl_off (
void)
637 static struct allegro_gl_driver allegro_gl_amesa = {
#define GFX_OPENGL_FULLSCREEN
Fullscreen OpenGL graphics driver for Allegro.
#define GFX_OPENGL_WINDOWED
Windowed OpenGL graphics driver for Allegro.
void allegro_gl_destroy_video_bitmap(BITMAP *bmp)
destroy_video_bitmap() overload.
Main header file for AllegroGL.
BITMAP * allegro_gl_screen
Direct-mode GL `screen' bitmap.
BITMAP * allegro_gl_create_video_bitmap(int w, int h)
create_video_bitmap() overload.