int stw_pixelformat_choose( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ) { uint count; uint index; uint bestindex; uint bestdelta; (void) hdc; count = stw_pixelformat_get_extended_count(); bestindex = 0; bestdelta = ~0U; for (index = 1; index <= count; index++) { uint delta = 0; const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index ); if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && !!(ppfd->dwFlags & PFD_DOUBLEBUFFER) != !!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) continue; /* FIXME: Take in account individual channel bits */ if (ppfd->cColorBits != pfi->pfd.cColorBits) { if (ppfd->cColorBits && !pfi->pfd.cColorBits) delta += 10000; else if (ppfd->cColorBits > pfi->pfd.cColorBits) delta += 100; else if (ppfd->cColorBits < pfi->pfd.cColorBits) delta++; } if (ppfd->cDepthBits != pfi->pfd.cDepthBits) { if (ppfd->cDepthBits && !pfi->pfd.cDepthBits) delta += 10000; else if (ppfd->cDepthBits > pfi->pfd.cDepthBits) delta += 200; else if (ppfd->cDepthBits < pfi->pfd.cDepthBits) delta += 2; } if (ppfd->cStencilBits != pfi->pfd.cStencilBits) { if (ppfd->cStencilBits && !pfi->pfd.cStencilBits) delta += 10000; else if (ppfd->cStencilBits > pfi->pfd.cStencilBits) delta += 400; else if (ppfd->cStencilBits < pfi->pfd.cStencilBits) delta++; } if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits) { if (ppfd->cAlphaBits && !pfi->pfd.cAlphaBits) delta += 10000; else if (ppfd->cAlphaBits > pfi->pfd.cAlphaBits) delta += 100; else if (ppfd->cAlphaBits < pfi->pfd.cAlphaBits) delta++; } if (delta < bestdelta) { bestindex = index; bestdelta = delta; if (bestdelta == 0) break; } } return bestindex; }