We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 77 - Behaviour of ChoosePixelFormat
Summary: Behaviour of ChoosePixelFormat
Status: RESOLVED ABANDONED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-24 02:39 UTC by Sam Lantinga
Modified: 2018-08-06 21:20 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Lantinga 2006-01-24 02:39:33 UTC
Date: Sat, 9 Aug 2003 19:41:11 +0200
From: Ignacio Castano <castanyo@yahoo.es>
Subject: [SDL] Behaviour of ChoosePixelFormat

The wgl's ChoosePixelFormat function uses some kind of euristic to return
the closest match to the given pixel format descriptor, whereas both, the
ARB's ChoosePixelFormat and the glX's ChooseVisual suceed only if they find
a pixel format that matches the given attributes. Since SDL abstract those
details, your apps may have different behaviours depending on the platform
or target machine.

For example, if you request a 32bit pixel format, when only 16bits is
available, wgl will return a 16bit pixel format, while the ARB and glX code
path will fail.

It would be nice to have a consistent behaviour in different targets, and
that can be done replacing wgl's ChoosePixelFormat with your own function. I
can provide such replacement if there's enough interest.

--
Ignacio Castano
castanyo@yahoo.es

Comment 1 Sam Lantinga 2006-01-24 02:40:21 UTC
The following code enumerates the existing pixel formats and returns the
index of the first matching pixel format. Returns 0 if no matching pixel
format available.

static int MyChoosePixelFormat( HDC  hdc, const PIXELFORMATDESCRIPTOR *
target ) {

 PIXELFORMATDESCRIPTOR pfd;

 int format_num = DescribePixelFormat( hdc, 1, sizeof(pfd), NULL );

 int format_idx;
 for( format_idx = 1; format_idx <= format_num; format_idx++ ) {

  if( !DescribePixelFormat( hdc, format_idx, sizeof(pfd), &pfd ) ) {
   // error?
   continue;
  }

  if( (pfd.dwFlags & target->dwFlags) != target->dwFlags ) continue;

  if( pfd.iPixelType != target->iPixelType ) continue;

  if( pfd.cColorBits < target->cColorBits ) continue;
  if( pfd.cRedBits < target->cRedBits ) continue;
  if( pfd.cGreenBits < target->cGreenBits ) continue;
  if( pfd.cBlueBits < target->cBlueBits ) continue;
  if( pfd.cAlphaBits < target->cAlphaBits ) continue;
  if( pfd.cAccumBits < target->cAccumBits ) continue;
  if( pfd.cAccumRedBits < target->cAccumRedBits ) continue;
  if( pfd.cAccumGreenBits < target->cAccumGreenBits ) continue;
  if( pfd.cAccumBlueBits < target->cAccumBlueBits ) continue;      
  if( pfd.cAccumAlphaBits < target->cAccumAlphaBits ) continue;
  if( pfd.cDepthBits < target->cDepthBits ) continue;
  if( pfd.cStencilBits < target->cStencilBits ) continue;       

  return format_idx;
 }          

 return 0;
};
Comment 2 Ryan C. Gordon 2006-01-27 11:23:23 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.

Comment 3 Sam Lantinga 2007-07-04 14:42:47 UTC
At this point, I don't want to introduce a change in 1.2 that would cause an OpenGL context to fail when it didn't previously, even if it makes it more consistent across platforms.

It might be worth making a change like this in 1.3, but we would need to make a more robust pixel format choosing function - one that tries to get a closest match rather than just enforcing a minimum.
Comment 4 Sam Lantinga 2007-07-04 23:15:04 UTC
This is fixed in 1.3 in subversion revision 3150.
Comment 5 Jānis Rūcis 2014-03-20 00:07:01 UTC
Hi,

We're currently having to work around an issue in SDL2 that seems to be directly related to this old bug report. There is still some inconsistent behavior when it comes to handling attributes such as SDL_GL_MULTISAMPLESAMPLES. Requesting an excessive number of samples fails on Linux, but succeeds on Windows resulting in a context below minimum specifications:

https://github.com/Neverball/neverball/issues/49
Comment 6 Ryan C. Gordon 2018-08-06 21:20:18 UTC
Hello, and sorry if you're getting dozens of copies of this message by email.

We are closing out bugs that appear to be abandoned in some form. This can happen for lots of reasons: we couldn't reproduce it, conversation faded out, the bug was noted as fixed in a comment but we forgot to mark it resolved, the report is good but the fix is impractical, we fixed it a long time ago without realizing there was an associated report, etc.

Individually, any of these bugs might have a better resolution (such as WONTFIX or WORKSFORME or INVALID) but we've added a new resolution of ABANDONED to make this easily searchable and make it clear that it's not necessarily unreasonable to revive a given bug report.

So if this bug is still a going concern and you feel it should still be open: please feel free to reopen it! But unless you respond, we'd like to consider these bugs closed, as many of them are several years old and overwhelming our ability to prioritize recent issues.

(please note that hundred of bug reports were sorted through here, so we apologize for any human error. Just reopen the bug in that case!)

Thanks,
--ryan.