-
-
Save ThePhD/b4be01e11ea90b397ece to your computer and use it in GitHub Desktop.
Yech...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef FURROVINEWIN | |
std::vector<int> GetAllPixelFormats( ) { | |
struct hglrc_deleter { | |
void operator () ( HGLRC hglrc ) { | |
wglDeleteContext( hglrc ); | |
} | |
}; | |
WindowDriver driver; | |
Window dummywindow( driver, WindowDescription( "Dummy", { 0, 0 }, nullopt, WindowStyle::None, WindowState::Minimized, false, false, "Dummy OpenGL Initialization" ) ); | |
HWND dummyhwnd = static_cast<HWND>( dummywindow.Handle( ) ); | |
unique<HDC, delete_window_dc_handle> dummyhdc( GetDC( dummyhwnd ), delete_window_dc_handle( dummyhwnd ) ); | |
if ( dummyhdc == null ) { | |
return{}; | |
} | |
PIXELFORMATDESCRIPTOR pfd = { | |
sizeof( PIXELFORMATDESCRIPTOR ), // Size of This Pixel Format Descriptor | |
1, // Version Number | |
PFD_DRAW_TO_WINDOW // Format Must Support Window | |
| PFD_SUPPORT_OPENGL // Format Must Support OpenGL | |
| PFD_DOUBLEBUFFER, // Must Support Double Buffering | |
PFD_TYPE_RGBA, // Request An RGBA Format | |
static_cast<BYTE>( ToByteSize( SurfaceFormat::Red8Green8Blue8Alpha8 ) * 8 ), // Select Our Color Depth | |
0, 0, 0, 0, 0, 0, // Color Bits Ignored | |
0, // No Alpha Buffer | |
0, // Shift Bit Ignored | |
0, // No Accumulation Buffer | |
0, 0, 0, 0, // Accumulation Bits Ignored | |
static_cast<BYTE>( DepthBits( DepthStencilFormat::Depth24Stencil8 ) ), // 24Bit Z-Buffer (Depth Buffer) | |
static_cast<BYTE>( StencilBits( DepthStencilFormat::Depth24Stencil8 ) ), // 8 bit stencil buffer | |
0, // No Auxiliary Buffer | |
PFD_MAIN_PLANE, // Main Drawing Layer | |
0, // Reserved | |
0, 0, 0 // Layer Masks Ignored | |
}; | |
GLint pixelformat = ChoosePixelFormat( dummyhdc, &pfd ); | |
if ( pixelformat == 0 ) { | |
return{}; | |
} | |
cbool initialpixelformatresult = SetPixelFormat( dummyhdc, pixelformat, &pfd ); | |
if ( initialpixelformatresult == 0 ) { | |
return{}; | |
} | |
// Windows oddity: | |
// because of the way opengl32.lib is, we need | |
// to first query a device context (which by default hands us an OpenGL ~2.1 context) | |
// Now that we have the inital context, we can call | |
// OpenGL extension functions | |
unique<HGLRC, hglrc_deleter> hglrc = wglCreateContext( dummyhdc ); | |
if ( hglrc == null ) { | |
return{}; | |
} | |
cbool wglresult = wglMakeCurrent( dummyhdc, hglrc ); | |
if ( wglresult == 0 ) { | |
return{}; | |
} | |
std::vector<int> pixelformats( wgl::NUMBER_PIXEL_FORMATS_ARB ); | |
UINT pixelformatssize; | |
static const int pixelformatattribs[ ] = { | |
wgl::DRAW_TO_WINDOW_ARB, gl::TRUE_, | |
wgl::SUPPORT_OPENGL_ARB, gl::TRUE_, | |
wgl::DOUBLE_BUFFER_ARB, gl::TRUE_, | |
wgl::ACCELERATION_ARB, wgl::FULL_ACCELERATION_ARB, | |
wgl::FRAMEBUFFER_SRGB_CAPABLE_ARB, gl::TRUE_, | |
wgl::PIXEL_TYPE_ARB, wgl::TYPE_RGBA_ARB, | |
wgl::COLOR_BITS_ARB, 32, | |
wgl::DEPTH_BITS_ARB, 0, | |
wgl::STENCIL_BITS_ARB, 0, | |
0, | |
}; | |
cbool pixelformatresult = wgl::ChoosePixelFormatARB( hdc, pixelformatattribs, null, | |
pixelformats.size( ), pixelformats.data( ), &pixelformatssize ); | |
if ( pixelformatresult == 0 || pixelformatssize == 0 ) { | |
return{}; | |
} | |
pixelformats.resize( pixelformatssize ); | |
return pixelformats; | |
} | |
#endif // WINDOWS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment