From: <mm...@us...> - 2008-08-06 11:51:32
|
Revision: 10312 http://alleg.svn.sourceforge.net/alleg/?rev=10312&view=rev Author: mmimica Date: 2008-08-06 11:51:39 +0000 (Wed, 06 Aug 2008) Log Message: ----------- * Further development of pixel format selection code in WGL. * Fixed a std::list iteration in the demo. Modified Paths: -------------- allegro/branches/4.9/demo/src/logic.cpp allegro/branches/4.9/include/allegro5/bitmap_new.h allegro/branches/4.9/include/allegro5/internal/aintern_bitmap.h allegro/branches/4.9/include/allegro5/internal/aintern_opengl.h allegro/branches/4.9/src/opengl/ogl_bitmap.c allegro/branches/4.9/src/pixels.c allegro/branches/4.9/src/win/wgl_disp.c allegro/branches/4.9/src/win/wnewwin.c Modified: allegro/branches/4.9/demo/src/logic.cpp =================================================================== --- allegro/branches/4.9/demo/src/logic.cpp 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/demo/src/logic.cpp 2008-08-06 11:51:39 UTC (rev 10312) @@ -53,9 +53,8 @@ return false; } - std::list<Entity *>::iterator it; - - for (it = entities.begin(); it != entities.end(); it++) { + std::list<Entity *>::iterator it = entities.begin(); + while (it != entities.end()) { Entity *e = *it; if (!e->logic(step)) { if (e->isUFO()) { @@ -65,6 +64,8 @@ delete e; it = entities.erase(it); } + else + it++; } for (it = new_entities.begin(); it != new_entities.end(); it++) { Modified: allegro/branches/4.9/include/allegro5/bitmap_new.h =================================================================== --- allegro/branches/4.9/include/allegro5/bitmap_new.h 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/include/allegro5/bitmap_new.h 2008-08-06 11:51:39 UTC (rev 10312) @@ -96,32 +96,32 @@ * ALLEGRO_PIXEL_FORMAT_XRGB_8888 - 32 bit */ enum ALLEGRO_PIXEL_FORMAT { - ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA = 0, - ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_15_NO_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_15_WITH_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_16_NO_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_24_WITH_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA, - ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA, - ALLEGRO_PIXEL_FORMAT_ARGB_8888, - ALLEGRO_PIXEL_FORMAT_RGBA_8888, - ALLEGRO_PIXEL_FORMAT_ARGB_4444, - ALLEGRO_PIXEL_FORMAT_RGB_888, /* 24 bit format */ - ALLEGRO_PIXEL_FORMAT_RGB_565, - ALLEGRO_PIXEL_FORMAT_RGB_555, - ALLEGRO_PIXEL_FORMAT_PALETTE_8, - ALLEGRO_PIXEL_FORMAT_RGBA_5551, - ALLEGRO_PIXEL_FORMAT_ARGB_1555, - ALLEGRO_PIXEL_FORMAT_ABGR_8888, - ALLEGRO_PIXEL_FORMAT_XBGR_8888, - ALLEGRO_PIXEL_FORMAT_BGR_888, /* 24 bit format */ - ALLEGRO_PIXEL_FORMAT_BGR_565, - ALLEGRO_PIXEL_FORMAT_BGR_555, - ALLEGRO_PIXEL_FORMAT_RGBX_8888, - ALLEGRO_PIXEL_FORMAT_XRGB_8888, + ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA = 0, + ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_15_NO_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_15_WITH_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_16_NO_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_24_WITH_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA, + ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA, + ALLEGRO_PIXEL_FORMAT_ARGB_8888, + ALLEGRO_PIXEL_FORMAT_RGBA_8888, + ALLEGRO_PIXEL_FORMAT_ARGB_4444, + ALLEGRO_PIXEL_FORMAT_RGB_888, /* 24 bit format */ + ALLEGRO_PIXEL_FORMAT_RGB_565, + ALLEGRO_PIXEL_FORMAT_RGB_555, + ALLEGRO_PIXEL_FORMAT_PALETTE_8, + ALLEGRO_PIXEL_FORMAT_RGBA_5551, + ALLEGRO_PIXEL_FORMAT_ARGB_1555, + ALLEGRO_PIXEL_FORMAT_ABGR_8888, + ALLEGRO_PIXEL_FORMAT_XBGR_8888, + ALLEGRO_PIXEL_FORMAT_BGR_888, /* 24 bit format */ + ALLEGRO_PIXEL_FORMAT_BGR_565, + ALLEGRO_PIXEL_FORMAT_BGR_555, + ALLEGRO_PIXEL_FORMAT_RGBX_8888, + ALLEGRO_PIXEL_FORMAT_XRGB_8888, }; Modified: allegro/branches/4.9/include/allegro5/internal/aintern_bitmap.h =================================================================== --- allegro/branches/4.9/include/allegro5/internal/aintern_bitmap.h 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/include/allegro5/internal/aintern_bitmap.h 2008-08-06 11:51:39 UTC (rev 10312) @@ -115,6 +115,7 @@ bool _al_format_has_alpha(int format); bool _al_pixel_format_is_real(int format); int _al_get_pixel_format_bits(int format); +bool _al_pixel_format_fits(int format1, int format2); /* Memory bitmap blitting */ void _al_draw_bitmap_region_memory(ALLEGRO_BITMAP *bitmap, Modified: allegro/branches/4.9/include/allegro5/internal/aintern_opengl.h =================================================================== --- allegro/branches/4.9/include/allegro5/internal/aintern_opengl.h 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/include/allegro5/internal/aintern_opengl.h 2008-08-06 11:51:39 UTC (rev 10312) @@ -44,6 +44,7 @@ int stencil_size; int r_shift, g_shift, b_shift, a_shift; int r_size, g_size, b_size, a_size; + int color_size; int fullscreen; int sample_buffers; int samples; Modified: allegro/branches/4.9/src/opengl/ogl_bitmap.c =================================================================== --- allegro/branches/4.9/src/opengl/ogl_bitmap.c 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/src/opengl/ogl_bitmap.c 2008-08-06 11:51:39 UTC (rev 10312) @@ -480,11 +480,11 @@ /* FIXME: do this right */ if (! _al_pixel_format_is_real(format)) { - format = d->format; - //if (_al_format_has_alpha(format)) - // format = ALLEGRO_PIXEL_FORMAT_ABGR_8888; - //else - // format = ALLEGRO_PIXEL_FORMAT_XBGR_8888; + //format = d->format; + if (_al_format_has_alpha(format)) + format = ALLEGRO_PIXEL_FORMAT_ABGR_8888; + else + format = ALLEGRO_PIXEL_FORMAT_XBGR_8888; } pitch = true_w * al_get_pixel_size(format); Modified: allegro/branches/4.9/src/pixels.c =================================================================== --- allegro/branches/4.9/src/pixels.c 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/src/pixels.c 2008-08-06 11:51:39 UTC (rev 10312) @@ -50,16 +50,16 @@ static int pixel_sizes[] = { 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 2, + 2, + 2, + 2, + 3, + 3, 4, 4, + 4, + 4, 2, 3, 2, @@ -79,16 +79,16 @@ static int pixel_bits[] = { 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 15, + 15, + 16, + 16, + 24, + 24, 32, 32, + 32, + 32, 16, 24, 16, @@ -188,7 +188,33 @@ return format_is_real[format]; } +/* Returns true if real format1 fits into format2. */ +bool _al_pixel_format_fits(int format1, int format2) +{ + ASSERT(format1 >= 0); + ASSERT(format1 < ALLEGRO_NUM_PIXEL_FORMATS); + ASSERT(format_is_real[format1]); + ASSERT(format2 >= 0); + ASSERT(format2 < ALLEGRO_NUM_PIXEL_FORMATS); + if (format1 == format2) + return true; + + if (format_alpha_table[format1] && format2 == ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA) + return true; + + if (!format_alpha_table[format1] && format2 == ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA) + return true; + + if (pixel_sizes[format1] == pixel_sizes[format2] + && format_alpha_table[format1] == format_alpha_table[format2] + && !format_is_real[format2]) + return true; + + return false; +} + + /* Color mapping functions */ /* Function: al_map_rgba Modified: allegro/branches/4.9/src/win/wgl_disp.c =================================================================== --- allegro/branches/4.9/src/win/wgl_disp.c 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/src/win/wgl_disp.c 2008-08-06 11:51:39 UTC (rev 10312) @@ -284,10 +284,9 @@ static void deduce_color_format(OGL_PIXEL_FORMAT *pf) { /* FIXME: complete this with all formats */ - /* FIXME: how to detect XRGB formats? */ /* XXX REVEIW: someone check this!!! */ if (pf->r_size == 8 && pf->g_size == 8 && pf->b_size == 8) { - if (pf->a_size == 8) { + if (pf->a_size == 8 && pf->color_size == 32) { if (pf->a_shift == 0 && pf->b_shift == 8 && pf->g_shift == 16 && pf->r_shift == 24) { pf->format = ALLEGRO_PIXEL_FORMAT_RGBA_8888; } @@ -298,7 +297,7 @@ pf->format = ALLEGRO_PIXEL_FORMAT_ARGB_8888; } } - else if (pf->a_size == 0) { + else if (pf->a_size == 0 && pf->color_size == 24) { if (pf->b_shift == 0 && pf->g_shift == 8 && pf->r_shift == 16) { pf->format = ALLEGRO_PIXEL_FORMAT_RGB_888; } @@ -306,6 +305,14 @@ pf->format = ALLEGRO_PIXEL_FORMAT_BGR_888; } } + else if (pf->a_size == 0 && pf->color_size == 32) { + if (pf->b_shift == 0 && pf->g_shift == 8 && pf->r_shift == 16) { + pf->format = ALLEGRO_PIXEL_FORMAT_XRGB_8888; + } + else if (pf->r_shift == 0 && pf->g_shift == 8 && pf->b_shift == 16) { + pf->format = ALLEGRO_PIXEL_FORMAT_XBGR_8888; + } + } } else if (pf->r_size == 5 && pf->g_size == 6 && pf->b_size == 5) { if (pf->r_shift == 0 && pf->g_shift == 5 && pf->b_shift == 11) { @@ -375,6 +382,7 @@ pf->doublebuffered = pfd->dwFlags & PFD_DOUBLEBUFFER; pf->depth_size = pfd->cDepthBits; pf->stencil_size = pfd->cStencilBits; + pf->color_size = pfd->cColorBits; /* These are the component shifts. */ pf->r_shift = pfd->cRedShift; @@ -500,6 +508,9 @@ else if (attrib[i] == WGL_DEPTH_BITS_ARB) { pf->depth_size = value[i]; } + else if (attrib[i] == WGL_COLOR_BITS_ARB) { + pf->color_size = value[i]; + } /* Multisampling bits */ else if (attrib[i] == WGL_SAMPLE_BUFFERS_ARB) { pf->sample_buffers = value[i]; @@ -637,11 +648,14 @@ DEVMODE fallback_dm; int i, modeswitch, result; int fallback_dm_valid = 0; + int bpp; memset(&fallback_dm, 0, sizeof(fallback_dm)); memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(DEVMODE); + bpp = _al_get_pixel_format_bits(d->format); + i = 0; do { modeswitch = EnumDisplaySettings(NULL, i, &dm); @@ -650,7 +664,7 @@ if ((dm.dmPelsWidth == (unsigned) d->w) && (dm.dmPelsHeight == (unsigned) d->h) - && (dm.dmBitsPerPel == 32) /* FIXME */ + && (dm.dmBitsPerPel == bpp) && (dm.dmDisplayFrequency != (unsigned) d->refresh_rate)) { /* Keep it as fallback if refresh rate request could not * be satisfied. Try to get as close to 60Hz as possible though, @@ -671,7 +685,7 @@ } while ((dm.dmPelsWidth != (unsigned) d->w) || (dm.dmPelsHeight != (unsigned) d->h) - || (dm.dmBitsPerPel != 32) /* FIXME */ + || (dm.dmBitsPerPel != bpp) || (dm.dmDisplayFrequency != (unsigned) d->refresh_rate)); if (!modeswitch && !fallback_dm_valid) { @@ -842,7 +856,13 @@ for (i = 1; i <= maxindex; i++) { OGL_PIXEL_FORMAT *pf = pf_list[i-1]; /* TODO: implement a choice system (scoring?) */ - if (pf && pf->doublebuffered && pf->format == format) { + if (pf + && pf->doublebuffered + && pf->rmethod + && _al_pixel_format_fits(pf->format, format) + && pf->float_color == 0 + && pf->float_depth == 0 + && pf->sample_buffers == 0) { if (try_to_set_pixel_format(i)) { PIXELFORMATDESCRIPTOR pdf; TRACE(PREFIX_I "select_pixel_format(): Chose visual no. %i\n\n", i); @@ -914,8 +934,7 @@ memset(display, 0, sizeof *wgl_display); display->w = w; display->h = h; - //FIXME - display->format = ALLEGRO_PIXEL_FORMAT_ARGB_8888;//al_get_new_display_format(); + display->format = al_get_new_display_format(); display->refresh_rate = al_get_new_display_refresh_rate(); display->flags = al_get_new_display_flags(); display->vt = vt; Modified: allegro/branches/4.9/src/win/wnewwin.c =================================================================== --- allegro/branches/4.9/src/win/wnewwin.c 2008-08-05 20:55:54 UTC (rev 10311) +++ allegro/branches/4.9/src/win/wnewwin.c 2008-08-06 11:51:39 UTC (rev 10312) @@ -168,7 +168,7 @@ ALLEGRO_EVENT_SOURCE *es = NULL; RECT pos; ALLEGRO_SYSTEM *system = al_system_driver(); - WIN_WINDOW *win; + WIN_WINDOW *win = NULL; if (message == _al_win_msg_call_proc) { return ((int (*)(void))wParam) (); @@ -193,7 +193,8 @@ found: if (message == _al_win_msg_suicide) { - _AL_FREE(win); + if (win) + _AL_FREE(win); _al_vector_find_and_delete(&win_window_list, &win); //SendMessage(_al_win_compat_wnd, _al_win_msg_suicide, 0, 0); DestroyWindow(hWnd); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |