@@ -351,8 +351,91 @@ display_wrapper::window_class_wrapper::~window_class_wrapper()
351351 );
352352}
353353
354+ namespace {
355+ const char * dummy_window_class_name = " ruisapp_dummy_window_class_name" ;
356+ }
357+
358+ #ifdef RUISAPP_RENDER_OPENGL
359+ display_wrapper::wgl_procedures_wrapper::wgl_procedures_wrapper () {
360+ HWND dummy_window = CreateWindowExA (
361+ 0 ,
362+ dummy_window_class_name,
363+ " " ,
364+ 0 ,
365+ CW_USEDEFAULT,
366+ CW_USEDEFAULT,
367+ CW_USEDEFAULT,
368+ CW_USEDEFAULT,
369+ 0 ,
370+ 0 ,
371+ GetModuleHandle (NULL ),
372+ 0 );
373+
374+ if (!dummy_window) {
375+ throw std::runtime_error (" CreateWindowExA() failed" );
376+ }
377+
378+ utki::scope_exit window_scope_exit ([&](){
379+ DestroyWindow (dummy_window);
380+ });
381+
382+ HDC dummy_dc = GetDC (dummy_window);
383+ if (dummy_dc == NULL ) {
384+ throw std::runtime_error (" GetDC() failed" );
385+ }
386+ utki::scope_exit device_context_scope_exit ([&]() {
387+ ReleaseDC (dummy_window, //
388+ dummy_dc);
389+ });
390+
391+ PIXELFORMATDESCRIPTOR pfd = {
392+ .nSize = sizeof (pfd),
393+ .nVersion = 1 ,
394+ .dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
395+ .iPixelType = PFD_TYPE_RGBA,
396+ .cColorBits = 32 ,
397+ .cAlphaBits = 8 ,
398+ .cDepthBits = 24 ,
399+ .cStencilBits = 8 ,
400+ .iLayerType = PFD_MAIN_PLANE
401+ };
402+
403+ int pixel_format = ChoosePixelFormat (dummy_dc, &pfd);
404+ if (!pixel_format) {
405+ throw std::runtime_error (" ChoosePixelFormat() failed" );
406+ }
407+ if (!SetPixelFormat (dummy_dc, pixel_format, &pfd)) {
408+ throw std::runtime_error (" SetPixelFormat() failed" );
409+ }
410+
411+ HGLRC dummy_context = wglCreateContext (dummy_dc);
412+ if (dummy_context == NULL ) {
413+ throw std::runtime_error (" wglCreateContext() failed" );
414+ }
415+
416+ utki::scope_exit rendering_context_scope_exit ([&](){
417+ wglMakeCurrent (dummy_dc,//
418+ NULL );
419+ wglDeleteContext (dummy_context);
420+ });
421+
422+ if (!wglMakeCurrent (dummy_dc, dummy_context)) {
423+ throw std::runtime_error (" wglMakeCurrent() failed" );
424+ }
425+
426+ this ->wgl_choose_pixel_format_arb = PFNWGLCHOOSEPIXELFORMATARBPROC (wglGetProcAddress (" wglChoosePixelFormatARB" ));
427+ if (!this ->wgl_choose_pixel_format_arb ) {
428+ throw std::runtime_error (" could not get wglChoosePixelFormatARB()" );
429+ }
430+ this ->wgl_create_context_attribs_arb = PFNWGLCREATECONTEXTATTRIBSARBPROC (wglGetProcAddress (" wglCreateContextAttribsARB" ));
431+ if (!this ->wgl_create_context_attribs_arb ) {
432+ throw std::runtime_error (" could not get wglCreateContextAttribsARB()" );
433+ }
434+ }
435+ #endif
436+
354437display_wrapper::display_wrapper () :
355- dummy_window_class(" ruisapp_dummy_window_class_name " ,//
438+ dummy_window_class(dummy_window_class_name ,//
356439 DefWindowProc),
357440 regular_window_class(" ruisapp_window_class_name" , //
358441 window_procedure)
0 commit comments