vrj::GlWindowWin32 Class Reference

Win32-specific OpenGL windowing class. More...

#include <vrj/Draw/OGL/GlWindowWin32.h>

Inheritance diagram for vrj::GlWindowWin32:

Inheritance graph
[legend]
Collaboration diagram for vrj::GlWindowWin32:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GlWindowWin32 ()
virtual ~GlWindowWin32 ()
virtual bool open ()
 Opens the OpenGL window.
virtual bool close ()
 Closes the OpenGL window.
virtual bool makeCurrent ()
 Sets the current OpenGL context to this window.
virtual void swapBuffers ()
 Performs an OpenGL swap buffers command.
virtual void checkEvents ()
 Checks for window events.
void configWindow (vrj::Display *disp)
 Configure the GlWindow using information from the Display.

Protected Member Functions

LRESULT handleEvent (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
bool setPixelFormat (HDC hDC)
 Sets the pixel format for the given display context.
void sizeChanged (long width, long height)

Static Protected Member Functions

static bool registerWindowClass ()
static LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 Global Window event handler.
static void addWindow (HWND handle, GlWindowWin32 *glWin)
 Adds a window to the map.
static void removeWindow (HWND handle)
 Removes a window from the map.
static GlWindowWin32getGlWin (HWND handle)
 Gets the glWin we are dealing with.

Static Protected Attributes

static WNDCLASS mWinClass
 The window class to register.
static bool mWinRegisteredClass
 Window registration.
static std::map< HWND, GlWindowWin32 * > mGlWinMap

Detailed Description

Win32-specific OpenGL windowing class.

Definition at line 74 of file GlWindowWin32.h.


Constructor & Destructor Documentation

vrj::GlWindowWin32::GlWindowWin32 (  ) 

Definition at line 55 of file GlWindowWin32.cpp.

00056    : mRenderContext(NULL)
00057    , mDeviceContext(NULL)
00058 {
00059    // Event processing is not blocking.
00060    mBlocking = false;
00061 }

vrj::GlWindowWin32::~GlWindowWin32 (  )  [virtual]

Definition at line 63 of file GlWindowWin32.cpp.

References close().

00064 {
00065    this->close();
00066 }


Member Function Documentation

bool vrj::GlWindowWin32::open (  )  [virtual]

Opens the OpenGL window.

Precondition:
this has been configured.
Postcondition:
Window created. Create message sets the visual.
Returns:
true if the window opened correctly.

Reimplemented from vrj::GlWindow.

Definition at line 72 of file GlWindowWin32.cpp.

References addWindow(), GL_WINDOW_WIN32_CLASSNAME(), vrj::GlExtensionLoaderWin32::hasSwapGroupNV(), vrj::GlWindow::mHasBorder, vrj::GlWindow::mHideMouse, vrj::GlWindow::mOriginX, vrj::GlWindow::mOriginY, vrj::GlWindow::mWindowHeight, vrj::GlWindow::mWindowIsOpen, vrj::GlWindow::mWindowWidth, vrj::GlExtensionLoaderWin32::registerExtensions(), registerWindowClass(), setPixelFormat(), vrjDBG_DRAW_MGR(), vrj::GlExtensionLoaderWin32::wglBindSwapBarrierNV(), vrj::GlExtensionLoaderWin32::wglJoinSwapGroupNV(), and vrj::GlExtensionLoaderWin32::wglQueryMaxSwapGroupsNV().

00073 {
00074    if ( false == GlWindowWin32::registerWindowClass() )
00075    {
00076       return false;
00077    }
00078    
00079    if ( mWindowIsOpen )
00080    {
00081       return true;
00082    }
00083 
00084    HMODULE hMod = GetModuleHandle(NULL);
00085    DWORD style;
00086    int root_height;
00087 
00088    // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS.
00089    style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
00090 
00091    // If we want a border, create an overlapped window.  This will have
00092    // a titlebar and a border.
00093    if ( mHasBorder )
00094    {
00095       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
00096          << "[vrj::GlWindowWin32::open()] Attempting to give window a border"
00097          << std::endl << vprDEBUG_FLUSH;
00098       style |= WS_OVERLAPPEDWINDOW;
00099    }
00100    // Otherwise, come as close as possible to having no border by using
00101    // the thin-line border.
00102    else
00103    {
00104       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
00105          << "[vrj::GlWindowWin32::open()] Attempting to make window borderless"
00106          << std::endl << vprDEBUG_FLUSH;
00107       style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
00108    }
00109 
00110    root_height = GetSystemMetrics(SM_CYSCREEN);
00111 
00112    // Ensure that the input window base class has the right dimension
00113    // information.
00114    InputAreaWin32::resize(mWindowWidth, mWindowHeight);
00115 
00116    // Create the main application window
00117    mWinHandle = CreateWindow(GL_WINDOW_WIN32_CLASSNAME, mWindowName.c_str(),
00118                              style, mOriginX,
00119                              root_height - mOriginY - mWindowHeight,
00120                              mWindowWidth, mWindowHeight, NULL, NULL, hMod,
00121                              NULL);
00122 
00123    // If window was not created, quit
00124    if ( NULL == mWinHandle )
00125    {
00126       doInternalError("Could not create GlWindowWin32!");
00127       return false;
00128    }
00129 
00130    // Attach a pointer to the device for use from the WNDPROC
00131    SetWindowLongPtr(mWinHandle, GWLP_USERDATA, (LPARAM) this);
00132 
00133    // We have a valid window, so... Create the context
00134    mDeviceContext = GetDC(mWinHandle);            // Store the device context
00135    if ( false == setPixelFormat(mDeviceContext) ) // Select the pixel format
00136    {
00137       return false;
00138    }
00139 
00140    // Create the rendering context and make it current
00141    mRenderContext = wglCreateContext(mDeviceContext);
00142 
00143    if ( NULL == mRenderContext )
00144    {
00145       char* msg_buffer(NULL);
00146 
00147       DWORD error_code = GetLastError();
00148       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00149                     NULL, error_code,
00150                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00151                     (LPTSTR) &msg_buffer, 0, NULL);
00152 
00153       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00154          << "ERROR: [vrj::GlWindowWin32::open()] wglCreateContext() failed "
00155          << "with error code " << error_code << std::endl << vprDEBUG_FLUSH;
00156       vprDEBUG_NEXT(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00157          << msg_buffer << std::endl << vprDEBUG_FLUSH;
00158 
00159       LocalFree(msg_buffer);
00160 
00161       return false;
00162    }
00163 
00164    wglMakeCurrent(mDeviceContext, mRenderContext);
00165 
00166    // Register extensions in this window
00167    mExtensions.registerExtensions();
00168 
00169      // Check on using swap group
00170    jccl::ConfigElementPtr disp_sys_elt =
00171       DisplayManager::instance()->getDisplaySystemElement();
00172    bool use_swap_group = disp_sys_elt->getProperty<bool>("use_swap_group");
00173 
00174    if(use_swap_group)
00175    {
00176       vprDEBUG_OutputGuard(vprDBG_ALL, vprDBG_CONFIG_STATUS_LVL,
00177                            "Attempting to set up WGL swap group.\n", "");
00178        
00179       // Try NV swap group extension
00180       if(mExtensions.hasSwapGroupNV())
00181       {
00182          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_STATUS_LVL)
00183             << "SwapGroupNV: " << mExtensions.hasSwapGroupNV() << std::endl
00184             << vprDEBUG_FLUSH;
00185          GLuint max_groups, max_barriers;
00186          mExtensions.wglQueryMaxSwapGroupsNV(mDeviceContext, &max_groups,
00187                                              &max_barriers);
00188          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_STATUS_LVL)
00189             << "Max groups: " << max_groups << " Max Barriers:" << max_barriers
00190             << std::endl << vprDEBUG_FLUSH;
00191 
00192          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_STATUS_LVL)
00193             << "Setting up NV swap group and barrier group. "
00194             << "Group: 1, Barrier: 1\n" << vprDEBUG_FLUSH;
00195          // For now, just assume both groups are group 1
00196          // Note: In the future this code may need to be refactored to be
00197          //   controlled from the GlPipe class since it is really the thing
00198          //   that would correspond to the group and could group the correct
00199          //   windows to a group id.
00200          mExtensions.wglJoinSwapGroupNV(mDeviceContext, 1);
00201          mExtensions.wglBindSwapBarrierNV(1, 1);
00202       }
00203       else
00204       {
00205          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00206             << "Could not detect any WGL extensions that support swap groups.\n"
00207             << vprDEBUG_FLUSH;
00208          vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
00209             << "Proceeding with no swap locking.\n" << vprDEBUG_FLUSH;
00210       }
00211    }
00212 
00213    // Register the window with the window list
00214    GlWindowWin32::addWindow(mWinHandle,this);
00215 
00216    // Display the window
00217    ShowWindow(mWinHandle, SW_SHOW);
00218    UpdateWindow(mWinHandle);             // Tell the window to paint
00219    mWindowIsOpen = true;
00220 
00221    // If mHideMouse is true we must pass false to ShowCursor
00222    ShowCursor(! mHideMouse);
00223 
00224    return true;
00225 }

bool vrj::GlWindowWin32::close (  )  [virtual]

Closes the OpenGL window.

Returns:
true if the window closed correctly.
Note:
Must be called by the same thread that called open.

Reimplemented from vrj::GlWindow.

Definition at line 231 of file GlWindowWin32.cpp.

References vrj::GlWindow::mWindowIsOpen, and removeWindow().

Referenced by ~GlWindowWin32().

00232 {
00233    // if not open, then don't bother.
00234    if ( !mWindowIsOpen )
00235    {
00236       return false;
00237    }
00238 
00239    // Remove window from window list
00240    GlWindowWin32::removeWindow(mWinHandle);
00241 
00242    mWindowIsOpen = false;
00243 
00244    // destroy the win32 window
00245    return(1 == DestroyWindow(mWinHandle));
00246 }

bool vrj::GlWindowWin32::makeCurrent (  )  [virtual]

Sets the current OpenGL context to this window.

Postcondition:
this.context is active context.

Reimplemented from vrj::GlWindow.

Definition at line 252 of file GlWindowWin32.cpp.

00253 {
00254    vprASSERT((mDeviceContext != NULL) && (mRenderContext != NULL));
00255    wglMakeCurrent(mDeviceContext, mRenderContext);  // Make our context current
00256    return true;
00257 }

void vrj::GlWindowWin32::swapBuffers (  )  [virtual]

Performs an OpenGL swap buffers command.

Reimplemented from vrj::GlWindow.

Definition at line 261 of file GlWindowWin32.cpp.

References vrj::GlWindow::swapBuffers().

00262 {
00263    vprASSERT(mDeviceContext != NULL);
00264    GlWindow::swapBuffers();
00265    SwapBuffers(mDeviceContext);
00266 }

void vrj::GlWindowWin32::checkEvents (  )  [virtual]

Checks for window events.

Postcondition:
All win32 events have ben dispatched and dealt with.

Reimplemented from vrj::GlWindow.

Definition at line 269 of file GlWindowWin32.cpp.

00270 {
00271    handleEvents();
00272 }

void vrj::GlWindowWin32::configWindow ( vrj::Display disp  )  [virtual]

Configure the GlWindow using information from the Display.

Reimplemented from vrj::GlWindow.

Definition at line 274 of file GlWindowWin32.cpp.

References vrj::GlWindow::configWindow(), vrj::Display::getConfigElement(), vrj::Display::getName(), vrj::Display::getPipe(), and vrjDBG_DRAW_MGR().

00275 {
00276    const char neg_one_STRING[] = "-1";
00277    vprASSERT( disp != NULL );
00278    vrj::GlWindow::configWindow(disp);
00279 
00280    // Get the vector of display chunks
00281    jccl::ConfigElementPtr disp_sys_elt =
00282       DisplayManager::instance()->getDisplaySystemElement();
00283    jccl::ConfigElementPtr display_elt = disp->getConfigElement();
00284 
00285    // Get the lock KeyboardMouseDevice information.
00286    gadget::InputArea::config(display_elt);
00287 
00288    mWindowName = disp->getName();
00289    mPipe = disp->getPipe();
00290    vprASSERT(mPipe >= 0);
00291 
00292    mXDisplayName = disp_sys_elt->getProperty<std::string>("x11_pipes", mPipe);
00293    if (mXDisplayName == neg_one_STRING)    // Use display env
00294    {
00295        const std::string DISPLAY_str("DISPLAY");
00296        std::string d;
00297        vpr::System::getenv(DISPLAY_str, d);
00298        if ( ! d.empty() )
00299        {
00300           mXDisplayName = std::string( d );
00301        }
00302    }
00303    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_VERB_LVL)
00304       << "[vrj::GlWindowWin32::configWindow()] display name is: "
00305       << mXDisplayName << std::endl << vprDEBUG_FLUSH;
00306 }

LRESULT vrj::GlWindowWin32::handleEvent ( HWND  hWnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) [protected]

Definition at line 310 of file GlWindowWin32.cpp.

References setPixelFormat(), and sizeChanged().

Referenced by WndProc().

00312 {
00313    switch ( message )
00314    {
00315       // ---- Window creation, setup for OpenGL ---- //
00316       case WM_CREATE:
00317          vprASSERT(false);                               // Should never get called because
00318                                                          //we are not registered when this gets called
00319 
00320          mDeviceContext = GetDC(hWnd);                   // Store the device context
00321          if ( false == setPixelFormat(mDeviceContext) )  // Select the pixel format
00322          {
00323             return 0;
00324          }
00325 
00326          // Create the rendering context and make it current
00327          mRenderContext = wglCreateContext(mDeviceContext);
00328          wglMakeCurrent(mDeviceContext, mRenderContext);
00329          break;
00330 
00331          // ---- Window is being destroyed, cleanup ---- //
00332       case WM_DESTROY:
00333 
00334          // Deselect the current rendering context and delete it
00335          wglMakeCurrent(mDeviceContext, NULL);
00336          wglDeleteContext(mRenderContext);
00337 
00338          // Tell the application to terminate after the window
00339          // is gone.
00340          PostQuitMessage(0);
00341          break;
00342 
00343          // --- Window is resized. --- //
00344       case WM_SIZE:
00345          // Call our function which modifies the clipping
00346          // volume and viewport
00347          sizeChanged(LOWORD(lParam), HIWORD(lParam));
00348          InputAreaWin32::resize(LOWORD(lParam), HIWORD(lParam));
00349          break;
00350 
00351          // The painting function.  This message sent by Windows
00352          // whenever the screen needs updating.
00353       case WM_PAINT:
00354          {
00355             PAINTSTRUCT ps;         // Paint structure
00356             BeginPaint(hWnd, &ps);  // Validate the drawing of the window
00357             EndPaint(hWnd, &ps);
00358          }
00359          break;
00360       // Catch the ALT key so that it does not open the system menu.
00361       case WM_SYSKEYDOWN:
00362       case WM_SYSKEYUP:
00363          break;
00364       default:   // Passes it on if unproccessed
00365          return DefWindowProc(hWnd, message, wParam, lParam);
00366    }
00367 
00368    return(0L);
00369 }

bool vrj::GlWindowWin32::setPixelFormat ( HDC  hDC  )  [protected]

Sets the pixel format for the given display context.

Returns:
success

Definition at line 372 of file GlWindowWin32.cpp.

References vrj::Display::getGlFrameBufferConfig(), vrj::Display::getName(), vrj::Display::isStereoRequested(), vrj::GlWindow::mInStereo, vrj::GlWindow::mVrjDisplay, and vrjDBG_DRAW_MGR().

Referenced by handleEvent(), and open().

00373 {
00374    PIXELFORMATDESCRIPTOR pfd;
00375 
00376    memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
00377    pfd.nSize = (sizeof(PIXELFORMATDESCRIPTOR));
00378    pfd.nVersion = 1;
00379 
00380    int visual_id(-1);
00381    int red_size(8), green_size(8), blue_size(8), alpha_size(8), db_size(32),
00382        accum_red_size(1), accum_green_size(1), accum_blue_size(1),
00383        accum_alpha_size(1), stencil_size(1);
00384    int num_aux_bufs(0);
00385 
00386    jccl::ConfigElementPtr gl_fb_elt = mVrjDisplay->getGlFrameBufferConfig();
00387 
00388    if ( gl_fb_elt.get() != NULL )
00389    {
00390       if ( gl_fb_elt->getVersion() < 2 )
00391       {
00392          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00393             << clrOutBOLD(clrYELLOW, "WARNING:") << " Display window '"
00394             << mVrjDisplay->getName() << "'" << std::endl;
00395          vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00396             << "has an out of date OpenGL frame buffer configuration."
00397             << std::endl;
00398          vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00399             << "Expected version 2 but found version "
00400             << gl_fb_elt->getVersion() << ".\n";
00401          vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00402             << "Default values will be used for some frame buffer settings.\n"
00403             << vprDEBUG_FLUSH;
00404       }
00405 
00406       visual_id        = gl_fb_elt->getProperty<int>("visual_id");
00407       red_size         = gl_fb_elt->getProperty<int>("red_size");
00408       green_size       = gl_fb_elt->getProperty<int>("green_size");
00409       blue_size        = gl_fb_elt->getProperty<int>("blue_size");
00410       alpha_size       = gl_fb_elt->getProperty<int>("alpha_size");
00411       num_aux_bufs     = gl_fb_elt->getProperty<int>("auxiliary_buffer_count");
00412       db_size          = gl_fb_elt->getProperty<int>("depth_buffer_size");
00413       stencil_size     = gl_fb_elt->getProperty<int>("stencil_buffer_size");
00414       accum_red_size   = gl_fb_elt->getProperty<int>("accum_red_size");
00415       accum_green_size = gl_fb_elt->getProperty<int>("accum_green_size");
00416       accum_blue_size  = gl_fb_elt->getProperty<int>("accum_blue_size");
00417       accum_alpha_size = gl_fb_elt->getProperty<int>("accum_alpha_size");
00418    }
00419 
00420    int pixel_format;
00421 
00422    if ( visual_id != -1 )
00423    {
00424       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00425          << "Requesting visual 0x" << std::hex << visual_id << std::dec
00426          << " from WGL." << std::endl << vprDEBUG_FLUSH;
00427 
00428       int result = DescribePixelFormat(hDC, visual_id,
00429                                        sizeof(PIXELFORMATDESCRIPTOR), &pfd);
00430 
00431       if ( result == 0 )
00432       {
00433          std::stringstream error;
00434          error << "Failed to get requested visual (ID 0x" << std::hex
00435                << visual_id << std::dec << ")" << std::flush;
00436 
00437          doInternalError(error.str());
00438          return false;
00439       }
00440 
00441       mInStereo = (mVrjDisplay->isStereoRequested() &&
00442                    (pfd.dwFlags & PFD_STEREO));
00443       pixel_format = visual_id;
00444    }
00445    else
00446    {
00447       if ( red_size < 0 )
00448       {
00449          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00450             << clrOutBOLD(clrYELLOW, "WARNING:")
00451             << " Color buffer red channel size was negative ("
00452             << red_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00453          red_size = 1;
00454       }
00455 
00456       if ( green_size < 0 )
00457       {
00458          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00459             << clrOutBOLD(clrYELLOW, "WARNING:")
00460             << " Color buffer green channel size was negative ("
00461             << green_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00462          green_size = 1;
00463       }
00464 
00465       if ( blue_size < 0 )
00466       {
00467          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00468             << clrOutBOLD(clrYELLOW, "WARNING:")
00469             << " Color buffer blue channel size was negative ("
00470             << blue_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00471          blue_size = 1;
00472       }
00473 
00474       if ( alpha_size < 0 )
00475       {
00476          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00477             << clrOutBOLD(clrYELLOW, "WARNING:")
00478             << " Color buffer alpha channel size was negative ("
00479             << alpha_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00480          alpha_size = 1;
00481       }
00482 
00483       if ( num_aux_bufs < 0 )
00484       {
00485          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00486             << clrOutBOLD(clrYELLOW, "WARNING:")
00487             << " Auxiliary buffer count was negative (" << num_aux_bufs
00488             << ").  Setting to 0.\n" << vprDEBUG_FLUSH;
00489          num_aux_bufs = 0;
00490       }
00491 
00492       if ( db_size < 0 )
00493       {
00494          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00495             << clrOutBOLD(clrYELLOW, "WARNING:")
00496             << " Depth buffer size was negative (" << db_size
00497             << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00498          db_size = 1;
00499       }
00500 
00501       if ( stencil_size < 0 )
00502       {
00503          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00504             << clrOutBOLD(clrYELLOW, "WARNING:")
00505             << " Stencil buffer size was negative (" << stencil_size
00506             << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00507          stencil_size = 1;
00508       }
00509 
00510       if ( accum_red_size < 0 )
00511       {
00512          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00513             << clrOutBOLD(clrYELLOW, "WARNING:")
00514             << " Accumulation buffer red channel size was negative ("
00515             << accum_red_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00516          accum_red_size = 1;
00517       }
00518 
00519       if ( accum_green_size < 0 )
00520       {
00521          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00522             << clrOutBOLD(clrYELLOW, "WARNING:")
00523             << " Accumulation buffer green channel size was negative ("
00524             << accum_green_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00525          accum_green_size = 1;
00526       }
00527 
00528       if ( accum_blue_size < 0 )
00529       {
00530          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00531             << clrOutBOLD(clrYELLOW, "WARNING:")
00532             << " Accumulation buffer blue channel size was negative ("
00533             << accum_blue_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00534          accum_blue_size = 1;
00535       }
00536 
00537       if ( accum_alpha_size < 0 )
00538       {
00539          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00540             << clrOutBOLD(clrYELLOW, "WARNING:")
00541             << " Accumulation buffer alpha channel size was negative ("
00542             << accum_alpha_size << ").  Setting to 1.\n" << vprDEBUG_FLUSH;
00543          accum_alpha_size = 1;
00544       }
00545 
00546       /* Defaults. */
00547       pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
00548 
00549       if ( mVrjDisplay->isStereoRequested() )
00550       {
00551          mInStereo = true;
00552          pfd.dwFlags |= PFD_STEREO;
00553       }
00554       else
00555       {
00556          mInStereo = false;
00557       }
00558 
00559       pfd.iPixelType        = PFD_TYPE_RGBA;
00560       pfd.cColorBits        = red_size + green_size + blue_size + alpha_size;
00561       pfd.cRedBits          = red_size;       // Ignored by ChoosePixelFormat()
00562       pfd.cGreenBits        = green_size;     // Ignored by ChoosePixelFormat()
00563       pfd.cBlueBits         = blue_size;      // Ignored by ChoosePixelFormat()
00564       pfd.cAlphaBits        = alpha_size;     // Ignored by ChoosePixelFormat()
00565       pfd.cAccumBits        = accum_red_size + accum_green_size +
00566                                  accum_blue_size + accum_alpha_size;
00567       pfd.cAccumRedBits     = accum_red_size;   // Ignored by ChoosePixelFormat()
00568       pfd.cAccumGreenBits   = accum_green_size; // Ignored by ChoosePixelFormat()
00569       pfd.cAccumBlueBits    = accum_blue_size;  // Ignored by ChoosePixelFormat()
00570       pfd.cAccumAlphaBits   = accum_alpha_size; // Ignored by ChoosePixelFormat()
00571       pfd.cDepthBits        = db_size;
00572       pfd.cStencilBits      = stencil_size;
00573       pfd.cAuxBuffers       = num_aux_bufs;
00574 
00575       const unsigned int indent_level(2);
00576       const std::string indent_text(indent_level, ' ');
00577       const int pad_width_dot(40 - indent_level);
00578       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00579          << "OpenGL visual request settings for " << mVrjDisplay->getName()
00580          << ":\n";
00581       vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00582          << std::setiosflags(std::ios::left) << std::setfill('.')
00583          << indent_text << std::setw(pad_width_dot)
00584          << "Color bit size " << " " << (int) pfd.cColorBits << std::endl;
00585       vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00586          << std::setiosflags(std::ios::left) << std::setfill('.')
00587          << indent_text << std::setw(pad_width_dot)
00588          << "Auxiliary buffer count " << " " << (int) pfd.cAuxBuffers
00589          << std::endl;
00590       vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00591          << std::setiosflags(std::ios::left) << std::setfill('.')
00592          << indent_text << std::setw(pad_width_dot)
00593          << "Depth buffer size " << " " << (int) pfd.cDepthBits << std::endl;
00594       vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00595          << std::setiosflags(std::ios::left) << std::setfill('.')
00596          << indent_text << std::setw(pad_width_dot)
00597          << "Stencil buffer size " << " " << (int) pfd.cStencilBits
00598          << std::endl;
00599       vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00600          << std::setiosflags(std::ios::left) << std::setfill('.')
00601          << indent_text << std::setw(pad_width_dot)
00602          << "Accumulation buffer bit size " << " " << (int) pfd.cAccumBits
00603          << std::endl;
00604       vprDEBUG_CONTnl(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00605          << vprDEBUG_FLUSH;
00606 
00607       // Let Win32 choose one for us
00608       pixel_format = ChoosePixelFormat(hDC, &pfd);
00609 
00610       if ( pixel_format > 0 )
00611       {
00612          PIXELFORMATDESCRIPTOR match;
00613          DescribePixelFormat(hDC, pixel_format, sizeof(PIXELFORMATDESCRIPTOR),
00614                              &match);
00615 
00616          // ChoosePixelFormat is dumb in that it will return a pixel format
00617          // that doesn't have stereo even if it was requested so we need to
00618          // make sure that if stereo was selected, we got it.
00619          if ( mVrjDisplay->isStereoRequested() )
00620          {
00621             if ( !(match.dwFlags & PFD_STEREO) )
00622             {
00623                doInternalError("Could not get a stereo pixel format.");
00624                return false;
00625             }
00626          }
00627       }
00628    }
00629 
00630    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00631       << "Visual ID: 0x" << std::setw(2) << std::hex << pixel_format
00632       << std::dec << std::endl << vprDEBUG_FLUSH;
00633 
00634    // Set the pixel format for the device context
00635    SetPixelFormat(hDC, pixel_format, &pfd);
00636    return true;
00637 }

void vrj::GlWindowWin32::sizeChanged ( long  width,
long  height 
) [protected]

Definition at line 640 of file GlWindowWin32.cpp.

References vrj::GlWindow::mOriginX, vrj::GlWindow::mOriginY, vrj::GlWindow::setDirtyViewport(), and vrj::GlWindow::updateOriginSize().

Referenced by handleEvent().

00641 {
00642    // Make sure we don't have window of 1 size (divide by zero would follow).
00643    if ( width == 0 )
00644    {
00645       width = 1;
00646    }
00647 
00648    if ( height == 0 )
00649    {
00650       height = 1;
00651    }
00652 
00653    updateOriginSize(mOriginX, mOriginY, width, height);
00654    setDirtyViewport(true);
00655 }

bool vrj::GlWindowWin32::registerWindowClass (  )  [static, protected]

Definition at line 688 of file GlWindowWin32.cpp.

References GL_WINDOW_WIN32_CLASSNAME(), LIBNAME, mWinClass, mWinRegisteredClass, and WndProc().

Referenced by open().

00689 {
00690    if ( mWinRegisteredClass )
00691    {
00692       return true;
00693    }
00694 
00695    char lpszAppName[1024];
00696    GetModuleFileName(NULL,lpszAppName,sizeof(lpszAppName));
00697 
00698    mWinRegisteredClass = true;     // We have registered now
00699 
00700    HINSTANCE hInstance = GetModuleHandle(NULL);
00701 
00702    // Register Window style
00703    mWinClass.style       = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
00704    mWinClass.lpfnWndProc = (WNDPROC)GlWindowWin32::WndProc;
00705    mWinClass.cbClsExtra  = 0;
00706    mWinClass.cbWndExtra  = 0;
00707    mWinClass.hInstance   = hInstance;            // Get handle to the module that created current process
00708    mWinClass.hIcon       = LoadIcon(hInstance, "VRJUGGLER_ICON");
00709    mWinClass.hCursor     = LoadCursor(NULL, IDC_ARROW);
00710 
00711    // No need for background brush for OpenGL window
00712    //mWinClass.hbrBackground  = NULL;
00713    mWinClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
00714 
00715    mWinClass.lpszMenuName   = NULL;
00716    mWinClass.lpszClassName  = GL_WINDOW_WIN32_CLASSNAME;
00717 
00718 #ifdef _DEBUG
00719 #  define LIBNAME "vrj_ogl_d.dll"
00720 #else
00721 #  define LIBNAME "vrj_ogl.dll"
00722 #endif
00723 
00724    if (mWinClass.hIcon == NULL)
00725    {
00726       HINSTANCE hDLLInstance = LoadLibrary( LIBNAME );
00727       if (hDLLInstance != NULL)
00728       {
00729          mWinClass.hIcon = LoadIcon(hDLLInstance, "VRJUGGLER_ICON");
00730       }
00731    }
00732 
00733    // Register the window class
00734    if ( RegisterClass(&mWinClass) == 0 )
00735    {
00736       return false;
00737    }
00738    else
00739    {
00740       return true;
00741    }
00742 }

LRESULT CALLBACK vrj::GlWindowWin32::WndProc ( HWND  hWnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) [static, protected]

Global Window event handler.

Definition at line 660 of file GlWindowWin32.cpp.

References getGlWin(), handleEvent(), and vrjDBG_DRAW_MGR().

Referenced by registerWindowClass().

00662 {
00663    GlWindowWin32* glWin = getGlWin(hWnd);
00664    
00665    // If we can find a GLWindowWin32, make sure that
00666    // it handles the event.
00667    if ( glWin != NULL )
00668    {
00669       return glWin->handleEvent(hWnd, message, wParam, lParam);
00670    }
00671    else
00672    {
00673       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00674          << "Could not find GlWindow to process event."
00675          << std::endl << vprDEBUG_FLUSH;
00676 
00677       return DefWindowProc(hWnd, message, wParam, lParam);
00678    }
00679 }

void vrj::GlWindowWin32::addWindow ( HWND  handle,
GlWindowWin32 glWin 
) [static, protected]

Adds a window to the map.

Definition at line 744 of file GlWindowWin32.cpp.

References mGlWinMap.

Referenced by open().

00745 {
00746    vprASSERT(glWin != NULL);
00747    
00748    if ( mGlWinMap.find(handle) == mGlWinMap.end() )     // Not already there
00749    {
00750       mGlWinMap[handle] = glWin;
00751    }
00752 }

void vrj::GlWindowWin32::removeWindow ( HWND  handle  )  [static, protected]

Removes a window from the map.

Definition at line 754 of file GlWindowWin32.cpp.

References mGlWinMap.

Referenced by close().

00755 {
00756    mGlWinMap.erase(handle);     // Erase the entry in the list
00757 }

GlWindowWin32 * vrj::GlWindowWin32::getGlWin ( HWND  handle  )  [static, protected]

Gets the glWin we are dealing with.

Definition at line 759 of file GlWindowWin32.cpp.

References mGlWinMap.

Referenced by WndProc().

00760 {
00761    std::map<HWND, GlWindowWin32*>::iterator glWinIter;
00762 
00763    glWinIter = mGlWinMap.find(handle);
00764    if ( glWinIter == mGlWinMap.end() ) // Not found
00765    {
00766       return NULL;
00767    }
00768    else
00769    {
00770       return(*glWinIter).second;       // Return the found window
00771    }
00772 }


Member Data Documentation

WNDCLASS vrj::GlWindowWin32::mWinClass [static, protected]

The window class to register.

Definition at line 141 of file GlWindowWin32.h.

Referenced by registerWindowClass().

bool vrj::GlWindowWin32::mWinRegisteredClass [static, protected]

Window registration.

Definition at line 142 of file GlWindowWin32.h.

Referenced by registerWindowClass().

std::map< HWND, GlWindowWin32 * > vrj::GlWindowWin32::mGlWinMap [static, protected]

Definition at line 158 of file GlWindowWin32.h.

Referenced by addWindow(), getGlWin(), and removeWindow().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:22 2007 for VR Juggler by  doxygen 1.5.1