Windows/OpenGL: fix pixel format detection (STR #3119).
This patch fixes two aspects described in STR #3119: (a) enables detection and prefers pixel formats with composition (b) selects no more than 32 bit colors (8 bits per pixel) (a) was the reason for this STR, (b) was reported repeatedly in fltk.general (see STR #3119). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13072 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
dd8e60a956
commit
1f3c17c8b9
@ -137,6 +137,16 @@ void Fl_Cocoa_Gl_Window_Driver::delete_gl_context(GLContext context) {
|
||||
#include "drivers/WinAPI/Fl_WinAPI_Window_Driver.H"
|
||||
extern void fl_save_dc(HWND, HDC);
|
||||
|
||||
// STR #3191: select pixel format with composition support
|
||||
// ... and no more than 32 color bits (8 bits/color)
|
||||
// Ref: PixelFormatDescriptor Object
|
||||
// https://msdn.microsoft.com/en-us/library/cc231189.aspx
|
||||
#if !defined(PFD_SUPPORT_COMPOSITION)
|
||||
# define PFD_SUPPORT_COMPOSITION (0x8000)
|
||||
#endif
|
||||
|
||||
#define DEBUG_PFD (0) // 1 = PFD selection debug output, 0 = no debug output
|
||||
|
||||
Fl_Gl_Choice *Fl_WinAPI_Gl_Window_Driver::find(int m, const int *alistp)
|
||||
{
|
||||
Fl_Gl_Choice *g = Fl_Gl_Window_Driver::find_begin(m, alistp);
|
||||
@ -159,21 +169,47 @@ Fl_Gl_Choice *Fl_WinAPI_Gl_Window_Driver::find(int m, const int *alistp)
|
||||
if ((!(m & FL_STEREO)) != (!(pfd.dwFlags & PFD_STEREO))) continue;
|
||||
if ((m & FL_DEPTH) && !pfd.cDepthBits) continue;
|
||||
if ((m & FL_STENCIL) && !pfd.cStencilBits) continue;
|
||||
|
||||
#if DEBUG_PFD
|
||||
printf("pfd #%d supports composition: %s\n", i, (pfd.dwFlags & PFD_SUPPORT_COMPOSITION) ? "yes" : "no");
|
||||
printf(" ... & PFD_GENERIC_FORMAT: %s\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) ? "generic" : "accelerated");
|
||||
printf(" ... Overlay Planes : %d\n", pfd.bReserved & 15);
|
||||
printf(" ... Color & Depth : %d, %d\n", pfd.cColorBits, pfd.cDepthBits);
|
||||
if (pixelformat)
|
||||
printf(" current pixelformat : %d\n", pixelformat);
|
||||
fflush(stdout);
|
||||
#endif // DEBUG_PFD
|
||||
|
||||
// see if better than the one we have already:
|
||||
if (pixelformat) {
|
||||
// offering non-generic rendering is better (read: hardware accelleration)
|
||||
// offering non-generic rendering is better (read: hardware acceleration)
|
||||
if (!(chosen_pfd.dwFlags & PFD_GENERIC_FORMAT) &&
|
||||
(pfd.dwFlags & PFD_GENERIC_FORMAT)) continue;
|
||||
// offering overlay is better:
|
||||
else if (!(chosen_pfd.bReserved & 15) && (pfd.bReserved & 15)) {}
|
||||
// otherwise more bit planes is better:
|
||||
else if (chosen_pfd.cColorBits > pfd.cColorBits) continue;
|
||||
// otherwise prefer a format that supports composition (STR #3119)
|
||||
else if ((chosen_pfd.dwFlags & PFD_SUPPORT_COMPOSITION) &&
|
||||
!(pfd.dwFlags & PFD_SUPPORT_COMPOSITION)) continue;
|
||||
// otherwise more bit planes is better, but no more than 32 (8 bits per channel):
|
||||
else if (pfd.cColorBits > 32 || chosen_pfd.cColorBits > pfd.cColorBits) continue;
|
||||
else if (chosen_pfd.cDepthBits > pfd.cDepthBits) continue;
|
||||
}
|
||||
pixelformat = i;
|
||||
chosen_pfd = pfd;
|
||||
}
|
||||
//printf("Chosen pixel format is %d\n", pixelformat);
|
||||
|
||||
#if DEBUG_PFD
|
||||
static int bb = 0;
|
||||
if (!bb) {
|
||||
bb = 1;
|
||||
printf("PFD_SUPPORT_COMPOSITION = 0x%x\n", PFD_SUPPORT_COMPOSITION);
|
||||
}
|
||||
printf("Chosen pixel format is %d\n", pixelformat);
|
||||
printf("Color bits = %d, Depth bits = %d\n", chosen_pfd.cColorBits, chosen_pfd.cDepthBits);
|
||||
printf("Pixel format supports composition: %s\n", (chosen_pfd.dwFlags & PFD_SUPPORT_COMPOSITION) ? "yes" : "no");
|
||||
fflush(stdout);
|
||||
#endif // DEBUG_PFD
|
||||
|
||||
if (!pixelformat) return 0;
|
||||
|
||||
g = new Fl_Gl_Choice(m, alistp, first);
|
||||
|
Loading…
x
Reference in New Issue
Block a user