wxGLCanvas/wxGLContext: How to query pixel format?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rob190
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sun Jun 14, 2020 8:20 pm

wxGLCanvas/wxGLContext: How to query pixel format?

Post by Rob190 »

In windows you can query the pixel format of a device context using:

Code: Select all

int GetPixelFormat (HDC hdc);

int DescribePixelFormat (
                          HDC                     hdc,
                          int                     iPixelFormat,
                          UINT                    nBytes,
                          LPPIXELFORMATDESCRIPTOR ppfd
                        );
PIXELFORMATDESCRIPTOR is a large struct which includes the size and offsets of each colour channel. This struct is actually used in the msw implementation of wxGLCanvas e.g. in wxGLCanvas::Create(...) but I don't see any function to query it.

The background to this is that I have an app which uses glReadPixels. It works with render buffers (because the app knows the format) but I want to extend it so that it works with windows as well. (And yes, I know about the issues with swap buffers and obscured windows.)

I've not checked how this is done on other platforms so maybe the answer is that it's impossible and I just have to use windows-specific code. Or is it there and I just missed it?

Rob.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGLCanvas/wxGLContext: How to query pixel format?

Post by Manolo »

No, wxWidgets doesn't provide a function for retrieving the pixel format (PF). Normally, this PF is the same the app asked for (the wxGLCanvas attributes). But you can can use MSW specific function GetPixelFormat, and use it with the HDC returned by wxGLCanvas::GetHDC()
so that it works with windows as well
Sorry, I don't understand this sentence. OpenGL works with its own buffers, not with "window buffer".
Rob190
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sun Jun 14, 2020 8:20 pm

Re: wxGLCanvas/wxGLContext: How to query pixel format?

Post by Rob190 »

Manolo wrote: Sun Mar 28, 2021 8:01 pm No, wxWidgets doesn't provide a function for retrieving the pixel format (PF). Normally, this PF is the same the app asked for (the wxGLCanvas attributes). But you can can use MSW specific function GetPixelFormat, and use it with the HDC returned by wxGLCanvas::GetHDC()
In my case, the app uses the platform defaults so it doesn't know the format being requested. I guess I could possibly use wxGLAttributes::GetGLAttrs() but documentation doesn't specify the details of what is returned:

"Returns a pointer to the internal list of attributes. It's very unlikely you need this function. If the list is empty the returned value is NULL."
so that it works with windows as well
Sorry, I don't understand this sentence. OpenGL works with its own buffers, not with "window buffer".
I meant the back buffer where the corresponding front buffer is displayed in the window. ('display buffer' maybe?)

Is there a reason GetPixelFormat isn't in wxWidgets? It seems an obvious function to include and I've seen various requests for it in the past.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxGLCanvas/wxGLContext: How to query pixel format?

Post by ONEEYEMAN »

Hi,
Its Windows-specific.

Unless you can find how to make it work under other platforms, it will remain this way.

Thank you.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGLCanvas/wxGLContext: How to query pixel format?

Post by Manolo »

I guess I could possibly use wxGLAttributes::GetGLAttrs() but documentation doesn't specify the details of what is returned:
Oh, yes, I forgot this function. It returns a pointer-to-integer with the list of "ints" that compose the list of parameters needed for OGL. The parameters values are OS-dependant, but this is not an issue as you will use them also in OS-dependant way.
I meant the back buffer
Then tell OGL to select it before using glReadPixels.
Rob190
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sun Jun 14, 2020 8:20 pm

Re: wxGLCanvas/wxGLContext: How to query pixel format?

Post by Rob190 »

I found that OpenGL actually provides this functionality. There's a bit of complexity if you need it to work with both windows and FBOs but all the queries are there e.g.

Code: Select all

glGetNamedFramebufferAttachmentParameteriv (0, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result); // Check this is GL_FRAMEBUFFER_DEFAULT
glGetNamedFramebufferAttachmentParameteriv (0, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &result);
// etc. 
More details in the OpenGL man pages:

https://www.khronos.org/registry/OpenGL ... eter.xhtml
Post Reply