15 #include "wglGraphicsWindow.h" 16 #include "config_wgldisplay.h" 17 #include "config_windisplay.h" 18 #include "wglGraphicsPipe.h" 19 #include "pStatTimer.h" 50 ~wglGraphicsWindow() {
65 begin_frame_spam(mode);
71 if (wgldisplay_cat.is_spam()) {
73 <<
"Not drawing " <<
this <<
": unexposed.\n";
78 if (wgldisplay_cat.is_spam()) {
80 <<
"Drawing " <<
this <<
": exposed.\n";
84 DCAST_INTO_R(wglgsg, _gsg,
false);
87 nassertr(context,
false);
89 wglGraphicsPipe::wgl_make_current(_hdc, context, &_make_current_pcollector);
90 wglgsg->reset_if_new();
92 if (mode == FM_render) {
93 clear_cube_map_selection();
97 return _gsg->begin_frame(current_thread);
109 end_frame_spam(mode);
113 if (mode == FM_render) {
117 _gsg->end_frame(current_thread);
119 if (mode == FM_render) {
121 clear_cube_map_selection();
166 DCAST_INTO_V(wglgsg, _gsg);
169 wglGraphicsPipe::wgl_make_current(_hdc, context, &_make_current_pcollector);
186 if (_hdc != NULL && _flip_ready) {
193 DCAST_INTO_V(wglgsg, _gsg);
196 wglGraphicsPipe::wgl_make_current(_hdc, context, &_make_current_pcollector);
208 void wglGraphicsWindow::
211 wglGraphicsPipe::wgl_make_current(_hdc, NULL, &_make_current_pcollector);
214 ReleaseDC(_hWnd, _hdc);
216 WinGraphicsWindow::close_window();
226 bool wglGraphicsWindow::
228 if (!WinGraphicsWindow::open_window()) {
243 DCAST_INTO_R(wglgsg, _gsg,
false);
255 PIXELFORMATDESCRIPTOR pixelformat;
256 DescribePixelFormat(_hdc, pfnum,
sizeof(PIXELFORMATDESCRIPTOR),
261 sprintf(msg,
"Selected GL PixelFormat is #%d", pfnum);
262 print_pfd(&pixelformat, msg);
265 BOOL set_pfnum = SetPixelFormat(_hdc, pfnum, &pixelformat);
269 wgldisplay_cat.error()
270 <<
"SetPixelFormat(" << pfnum <<
") failed; trying " 274 DescribePixelFormat(_hdc, pfnum,
sizeof(PIXELFORMATDESCRIPTOR),
278 sprintf(msg,
"Selected GL PixelFormat is #%d", pfnum);
279 print_pfd(&pixelformat, msg);
282 DescribePixelFormat(_hdc, pfnum,
sizeof(PIXELFORMATDESCRIPTOR),
284 set_pfnum = SetPixelFormat(_hdc, pfnum, &pixelformat);
289 wgldisplay_cat.error()
290 <<
"SetPixelFormat(" << pfnum <<
") failed after window create\n";
296 if (gl_force_invalid) {
297 wgldisplay_cat.error()
298 <<
"Artificially failing window.\n";
305 setup_colormap(pixelformat);
308 wglGraphicsPipe::wgl_make_current(_hdc, wglgsg->
get_context(_hdc), &_make_current_pcollector);
309 wglgsg->reset_if_new();
310 wglgsg->report_my_gl_errors();
312 (_fb_properties,wglgsg->get_gl_renderer())) {
328 void wglGraphicsWindow::
329 setup_colormap(
const PIXELFORMATDESCRIPTOR &pixelformat) {
333 if (!(pixelformat.dwFlags & PFD_NEED_PALETTE ||
334 pixelformat.iPixelType == PFD_TYPE_COLORINDEX))
337 n = 1 << pixelformat.cColorBits;
341 logical = (LOGPALETTE*)malloc(
sizeof(LOGPALETTE) +
342 sizeof(PALETTEENTRY) * n);
343 memset(logical, 0,
sizeof(LOGPALETTE) +
sizeof(PALETTEENTRY) * n);
346 logical->palVersion = 0x300;
347 logical->palNumEntries = n;
350 GetSystemPaletteEntries(_hdc, 0, 256, &logical->palPalEntry[0]);
352 if (pixelformat.iPixelType == PFD_TYPE_RGBA) {
353 int redMask = (1 << pixelformat.cRedBits) - 1;
354 int greenMask = (1 << pixelformat.cGreenBits) - 1;
355 int blueMask = (1 << pixelformat.cBlueBits) - 1;
359 for (i = 0; i < n; ++i) {
360 logical->palPalEntry[i].peRed =
361 (((i >> pixelformat.cRedShift) & redMask) * 255) / redMask;
362 logical->palPalEntry[i].peGreen =
363 (((i >> pixelformat.cGreenShift) & greenMask) * 255) / greenMask;
364 logical->palPalEntry[i].peBlue =
365 (((i >> pixelformat.cBlueShift) & blueMask) * 255) / blueMask;
366 logical->palPalEntry[i].peFlags = 0;
370 _colormap = CreatePalette(logical);
373 SelectPalette(_hdc, _colormap, FALSE);
374 RealizePalette(_hdc);
380 static char *OGLDrvStrings[3] = {
"Software",
"MCD",
"ICD"};
388 void wglGraphicsWindow::
389 print_pfd(PIXELFORMATDESCRIPTOR *pfd,
char *msg) {
390 if (!wgldisplay_cat.is_debug()) {
394 OGLDriverType drvtype;
395 if ((pfd->dwFlags & PFD_GENERIC_ACCELERATED) &&
396 (pfd->dwFlags & PFD_GENERIC_FORMAT)) {
398 }
else if (!(pfd->dwFlags & PFD_GENERIC_ACCELERATED) && !(pfd->dwFlags & PFD_GENERIC_FORMAT)) {
404 #define PRINT_FLAG(FLG) ((pfd->dwFlags & PFD_##FLG) ? (" PFD_" #FLG "|") : "") 405 wgldisplay_cat.debug()
406 <<
"================================\n";
408 wgldisplay_cat.debug()
409 << msg <<
", " << OGLDrvStrings[drvtype] <<
" driver\n" 410 <<
"PFD flags: 0x" << (
void*)pfd->dwFlags <<
" (" 411 << PRINT_FLAG(GENERIC_ACCELERATED)
412 << PRINT_FLAG(GENERIC_FORMAT)
413 << PRINT_FLAG(DOUBLEBUFFER)
414 << PRINT_FLAG(SUPPORT_OPENGL)
415 << PRINT_FLAG(SUPPORT_GDI)
416 << PRINT_FLAG(STEREO)
417 << PRINT_FLAG(DRAW_TO_WINDOW)
418 << PRINT_FLAG(DRAW_TO_BITMAP)
419 << PRINT_FLAG(SWAP_EXCHANGE)
420 << PRINT_FLAG(SWAP_COPY)
421 << PRINT_FLAG(SWAP_LAYER_BUFFERS)
422 << PRINT_FLAG(NEED_PALETTE)
423 << PRINT_FLAG(NEED_SYSTEM_PALETTE)
424 << PRINT_FLAG(SUPPORT_DIRECTDRAW) <<
")\n" 425 <<
"PFD iPixelType: " 426 << ((pfd->iPixelType==PFD_TYPE_RGBA) ?
"PFD_TYPE_RGBA":
"PFD_TYPE_COLORINDEX")
428 <<
"PFD cColorBits: " << (DWORD)pfd->cColorBits
429 <<
" R: " << (DWORD)pfd->cRedBits
430 <<
" G: " << (DWORD)pfd->cGreenBits
431 <<
" B: " << (DWORD)pfd->cBlueBits << endl
432 <<
"PFD cAlphaBits: " << (DWORD)pfd->cAlphaBits
433 <<
" DepthBits: " << (DWORD)pfd->cDepthBits
434 <<
" StencilBits: " << (DWORD)pfd->cStencilBits
435 <<
" AccumBits: " << (DWORD)pfd->cAccumBits
int get_pfnum() const
Returns the pixel format number chosen for windows that use this context.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...
bool fail_pfnum()
This is called by wglGraphicsWindow when it finds it cannot use the pfnum determined by the GSG...
virtual void ready_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
A tiny specialization on GLGraphicsStateGuardian to add some wgl-specific information.
bool get_unexposed_draw() const
See set_unexposed_draw().
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An abstract base class for glGraphicsWindow and dxGraphicsWindow (and, in general, graphics windows that interface with the Microsoft Windows API).
HGLRC get_context(HDC hdc)
Returns the GL context associated with the GSG.
void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer)
Selects a pixel format for all the windows and buffers that use this gsg.
An object to create GraphicsOutputs that share a particular 3-D API.
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const
Validates that the properties represent the desired kind of renderer (hardware or software)...
This is a base class for the various different classes that represent the result of a frame of render...
const FrameBufferProperties & get_fb_properties() const
Returns the properties of the pixel format that was chosen for this gsg.
A thread; that is, a lightweight process.
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
Encapsulates all the communication with a particular instance of a given rendering backend...
bool subsumes(const FrameBufferProperties &other) const
Returns true if this set of properties makes strictly greater or equal demands of the framebuffer tha...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.