Skip to content

Commit 83639f2

Browse files
committed
stuff
1 parent 81f1589 commit 83639f2

4 files changed

Lines changed: 312 additions & 47 deletions

File tree

src/ruisapp/glue/windows/display.cxx

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
354437
display_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)

src/ruisapp/glue/windows/display.hxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <utki/windows.hpp>
44

5+
#ifdef RUISAPP_RENDER_OPENGL
6+
# include <GL/wglext.h>
7+
#endif
8+
59
namespace {
610
class display_wrapper {
711
public:
@@ -25,6 +29,24 @@ struct window_class_wrapper {
2529
window_class_wrapper dummy_window_class;
2630
window_class_wrapper regular_window_class;
2731

32+
#ifdef RUISAPP_RENDER_OPENGL
33+
struct wgl_procedures_wrapper {
34+
PFNWGLCHOOSEPIXELFORMATARBPROC wgl_choose_pixel_format_arb = nullptr;
35+
PFNWGLCREATECONTEXTATTRIBSARBPROC wgl_create_context_attribs_arb = nullptr;
36+
37+
wgl_procedures_wrapper();
38+
39+
wgl_procedures_wrapper(const wgl_procedures_wrapper&) = delete;
40+
wgl_procedures_wrapper& operator=(const wgl_procedures_wrapper&) = delete;
41+
42+
wgl_procedures_wrapper(wgl_procedures_wrapper&&) = delete;
43+
wgl_procedures_wrapper& operator=(wgl_procedures_wrapper&&) = delete;
44+
45+
~wgl_procedures_wrapper() = default;
46+
47+
}wgl_procedures;
48+
#endif
49+
2850
display_wrapper();
2951
};
3052
}

0 commit comments

Comments
 (0)