summaryrefslogtreecommitdiff
path: root/src/Fl_Gl_Choice.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2018-10-19 16:44:50 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2018-10-19 16:44:50 +0000
commit1f3c17c8b9c3ed9aad19c2033c4f89c52f297048 (patch)
tree50ee6cf45dbe42bdc19b4f8ee16a22530452aedd /src/Fl_Gl_Choice.cxx
parentdd8e60a9563489bce47b3c507b8b70105e871af5 (diff)
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
Diffstat (limited to 'src/Fl_Gl_Choice.cxx')
-rw-r--r--src/Fl_Gl_Choice.cxx44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/Fl_Gl_Choice.cxx b/src/Fl_Gl_Choice.cxx
index 3fbce41f7..c0e337674 100644
--- a/src/Fl_Gl_Choice.cxx
+++ b/src/Fl_Gl_Choice.cxx
@@ -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);