Ignore:
Timestamp:
08/03/05 14:12:41 (19 years ago)
Author:
mattausch
Message:

changed to ogre 103
added readme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp

    r183 r193  
    4545        LRESULT D3D9RenderWindow::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
    4646        { 
    47                 LPCREATESTRUCT lpcs; 
    48                 D3D9RenderWindow* win; 
    49  
    50                 // look up window instance 
    51                 if( WM_CREATE != uMsg ) 
    52                         // Get window pointer 
    53                         win = (D3D9RenderWindow*)GetWindowLong( hWnd, 0 ); 
     47                if (uMsg == WM_CREATE) 
     48                { 
     49                        // copy D3D9RenderWindow* from createwindow param to userdata slot 
     50                        SetWindowLong(hWnd, GWL_USERDATA, 
     51                                (LONG)(((LPCREATESTRUCT)lParam)->lpCreateParams)); 
     52                        return 0; 
     53                } 
     54 
     55                D3D9RenderWindow* win = 
     56                        (D3D9RenderWindow*)GetWindowLong(hWnd, GWL_USERDATA); 
     57 
     58                if (!win) 
     59                        return DefWindowProc(hWnd, uMsg, wParam, lParam); 
    5460 
    5561                switch( uMsg ) 
    5662                { 
    5763                case WM_ACTIVATE: 
    58                         if( WA_INACTIVE == LOWORD( wParam ) ) 
    59                                 win->mActive = false; 
    60                         else 
    61                                 win->mActive = true; 
     64                        win->mActive = (LOWORD(wParam) != WA_INACTIVE); 
    6265                        break; 
    6366 
    64                 case WM_CREATE: 
    65                         // Log the new window 
    66                         // Get CREATESTRUCT 
    67                         lpcs = (LPCREATESTRUCT)lParam; 
    68                         win = (D3D9RenderWindow*)(lpcs->lpCreateParams); 
    69                         // Store pointer in window user data area 
    70                         SetWindowLong( hWnd, 0, (long)win ); 
    71                         win->mActive = true; 
    72  
    73                         return 0; 
     67                case WM_ENTERSIZEMOVE: 
     68                        win->mSizing = true; 
    7469                        break; 
    7570 
    76                 case WM_KEYDOWN: 
    77                         // TEMPORARY CODE 
    78                         // TODO - queue up keydown / keyup events with 
    79                         //  window name and timestamp to be processed 
    80                         //  by main loop 
    81  
    82                         // ESCAPE closes window 
    83                         /* 
    84                         if (wParam == VK_ESCAPE) 
    85                         { 
    86                         win->mClosed = true; 
    87                         return 0L; 
    88                         } 
    89                         */ 
     71                case WM_EXITSIZEMOVE: 
     72                        win->windowMovedOrResized(); 
     73                        win->mSizing = false; 
    9074                        break; 
    9175 
    92                 case WM_PAINT: 
    93                         // If we get WM_PAINT messges, it usually means our window was 
    94                         // comvered up, so we need to refresh it by re-showing the contents 
    95                         // of the current frame. 
    96                         if( win->mActive && win->mReady ) 
    97                                 win->update(); 
    98                         break; 
    99  
    10076                case WM_MOVE: 
    101                         // Move messages need to be tracked to update the screen rects 
    102                         // used for blitting the backbuffer to the primary 
    103                         // *** This doesn't need to be used to Direct3D9 *** 
    104                         break; 
    105  
    106                 case WM_ENTERSIZEMOVE: 
    107                         // Previent rendering while moving / sizing 
    108                         win->mReady = false; 
    109                         break; 
    110  
    111                 case WM_EXITSIZEMOVE: 
    112                         win->WindowMovedOrResized(); 
    113                         win->mReady = true; 
    114                         break; 
    115  
    11677                case WM_SIZE: 
    117                         // Check to see if we are losing or gaining our window.  Set the  
    118                         // active flag to match 
    119                         if( SIZE_MAXHIDE == wParam || SIZE_MINIMIZED == wParam ) 
    120                                 win->mActive = false; 
    121                         else 
    122                         { 
    123                                 win->mActive = true; 
    124                                 if( win->mReady ) 
    125                                         win->WindowMovedOrResized(); 
    126                         } 
     78                        if (!win->mSizing) 
     79                                win->windowMovedOrResized(); 
    12780                        break; 
    12881 
     
    13487 
    13588                case WM_CLOSE: 
    136                         DestroyWindow( win->mHWnd ); 
     89                        win->destroy(); // cleanup and call DestroyWindow 
    13790                        win->mClosed = true; 
    13891                        return 0; 
     
    147100        { 
    148101                mIsFullScreen = false; 
    149                 mIsSwapChain = deviceIfSwapChain != NULL; 
     102                mIsSwapChain = (deviceIfSwapChain != NULL); 
     103                mIsExternal = false; 
    150104                mHWnd = 0; 
    151105                mActive = false; 
    152                 mReady = false; 
     106                mSizing = false; 
    153107                mClosed = false; 
    154108        } 
     
    161115                        LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice(); 
    162116                        SAFE_RELEASE( mpD3DDevice ); 
    163                         mDriver->setD3DDevice( mpD3DDevice ); 
     117                        mDriver->setD3DDevice( NULL ); 
    164118                } 
    165119        } 
     
    192146                String title = name; 
    193147                unsigned int colourDepth = 32; 
    194                 unsigned int left = 0; // Defaults to screen center 
    195                 unsigned int top = 0; // Defaults to screen center 
     148                int left = -1; // Defaults to screen center 
     149                int top = -1; // Defaults to screen center 
    196150                bool depthBuffer = true; 
     151                String border = ""; 
     152                bool outerSize = false; 
    197153                 
    198154                if(miscParams) 
     
    203159                        opt = miscParams->find("left"); 
    204160                        if(opt != miscParams->end()) 
    205                                 left = StringConverter::parseUnsignedInt(opt->second); 
     161                                left = StringConverter::parseInt(opt->second); 
    206162                        // top (y) 
    207163                        opt = miscParams->find("top"); 
    208164                        if(opt != miscParams->end()) 
    209                                 top = StringConverter::parseUnsignedInt(opt->second); 
     165                                top = StringConverter::parseInt(opt->second); 
    210166                        // Window title 
    211167                        opt = miscParams->find("title"); 
    212168                        if(opt != miscParams->end()) 
    213169                                title = opt->second; 
     170                        // parentWindowHandle           -> parentHWnd 
     171                        opt = miscParams->find("parentWindowHandle"); 
     172                        if(opt != miscParams->end()) 
     173                                parentHWnd = (HWND)StringConverter::parseUnsignedInt(opt->second); 
    214174                        // externalWindowHandle         -> externalHandle 
    215175                        opt = miscParams->find("externalWindowHandle"); 
     
    240200                        if(opt != miscParams->end()) 
    241201                                mFSAAQuality = StringConverter::parseUnsignedInt(opt->second); 
     202                        // window border style 
     203                        opt = miscParams->find("border"); 
     204                        if(opt != miscParams->end()) 
     205                                border = opt->second; 
     206                        // set outer dimensions? 
     207                        opt = miscParams->find("outerDimensions"); 
     208                        if(opt != miscParams->end()) 
     209                                outerSize = StringConverter::parseBool(opt->second); 
    242210                } 
    243211                 
     
    249217                if (!externalHandle) 
    250218                { 
    251                         DWORD dwStyle = (fullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW) | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 
     219                        DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 
    252220                        RECT rc; 
    253221 
    254222                        mWidth = width; 
    255223                        mHeight = height; 
     224                        mTop = top; 
     225                        mLeft = left; 
    256226 
    257227                        if (!fullScreen) 
    258228                        { 
    259                                 // Calculate window dimensions required to get the requested client area 
     229                                if (parentHWnd) 
     230                                { 
     231                                        dwStyle |= WS_CHILD; 
     232                                } 
     233                                else 
     234                                { 
     235                                        if (border == "none") 
     236                                                dwStyle |= WS_POPUP; 
     237                                        else if (border == "fixed") 
     238                                                dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION | 
     239                                                WS_SYSMENU | WS_MINIMIZEBOX; 
     240                                        else 
     241                                                dwStyle |= WS_OVERLAPPEDWINDOW; 
     242                                } 
     243 
     244                                if (!outerSize) 
     245                                { 
     246                                        // Calculate window dimensions required 
     247                                        // to get the requested client area 
    260248                                SetRect(&rc, 0, 0, mWidth, mHeight); 
    261249                                AdjustWindowRect(&rc, dwStyle, false); 
     
    264252 
    265253                                // Clamp width and height to the desktop dimensions 
    266                                 if (mWidth > (unsigned)GetSystemMetrics(SM_CXSCREEN)) 
    267                                         mWidth = (unsigned)GetSystemMetrics(SM_CXSCREEN); 
    268                                 if (mHeight > (unsigned)GetSystemMetrics(SM_CYSCREEN)) 
    269                                         mHeight = (unsigned)GetSystemMetrics(SM_CYSCREEN); 
    270  
    271                                 if (!left) 
    272                                         mLeft = (GetSystemMetrics(SM_CXSCREEN) / 2) - (mWidth / 2); 
    273                                 else 
    274                                         mLeft = left; 
    275                                 if (!top) 
    276                                         mTop = (GetSystemMetrics(SM_CYSCREEN) / 2) - (mHeight / 2); 
    277                                 else 
    278                                         mTop = top; 
     254                                        int screenw = GetSystemMetrics(SM_CXSCREEN); 
     255                                        int screenh = GetSystemMetrics(SM_CYSCREEN); 
     256                                        if ((int)mWidth > screenw) 
     257                                                mWidth = screenw; 
     258                                        if ((int)mHeight > screenh) 
     259                                                mHeight = screenh; 
     260                                        if (mLeft < 0) 
     261                                                mLeft = (screenw - mWidth) / 2; 
     262                                        if (mTop < 0) 
     263                                                mTop = (screenh - mHeight) / 2; 
     264                                } 
    279265                        } 
    280266                        else 
     267                        { 
     268                                dwStyle |= WS_POPUP; 
    281269                                mTop = mLeft = 0; 
     270                        } 
    282271 
    283272                        // Register the window class 
    284273                        // NB allow 4 bytes of window data for D3D9RenderWindow pointer 
    285             WNDCLASS wndClass = { CS_HREDRAW | CS_VREDRAW, WndProc, 0, 4, hInst, 
    286                                 LoadIcon( NULL, IDI_APPLICATION ), 
    287                                 LoadCursor( NULL, IDC_ARROW ), 
    288                                 (HBRUSH)GetStockObject( BLACK_BRUSH ), NULL, 
    289                                 TEXT(title.c_str()) }; 
    290                         RegisterClass( &wndClass ); 
     274                        WNDCLASS wc = { 0, WndProc, 0, 0, hInst, 
     275                                LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), 
     276                                (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "OgreD3D9Wnd" }; 
     277                        RegisterClass(&wc); 
    291278 
    292279                        // Create our main window 
    293280                        // Pass pointer to self 
    294                         HWND hWnd = CreateWindow(TEXT(title.c_str()), 
    295                                                                          TEXT(title.c_str()), 
    296                                                                          dwStyle, mLeft, mTop, 
    297                                                                          mWidth, mHeight, 0L, 0L, hInst, this); 
    298                         GetClientRect(hWnd,&rc); 
     281                        mIsExternal = false; 
     282                        mHWnd = CreateWindow("OgreD3D9Wnd", title.c_str(), dwStyle, 
     283                                mLeft, mTop, mWidth, mHeight, parentHWnd, 0, hInst, this); 
     284                } 
     285                else 
     286                { 
     287                        mHWnd = externalHandle; 
     288                        mIsExternal = true; 
     289                } 
     290 
     291                        RECT rc; 
     292                // top and left represent outer window coordinates 
     293                GetWindowRect(mHWnd, &rc); 
     294                mTop = rc.top; 
     295                mLeft = rc.left; 
     296                // width and height represent interior drawable area 
     297                        GetClientRect(mHWnd,&rc); 
    299298                        mWidth = rc.right; 
    300299                        mHeight = rc.bottom; 
    301300 
    302                         ShowWindow(hWnd, SW_SHOWNORMAL); 
    303                         UpdateWindow(hWnd); 
    304  
    305                         mHWnd = hWnd; 
    306                         // Store info 
    307301                        mName = name; 
    308302                        mIsDepthBuffered = depthBuffer; 
    309303                        mIsFullScreen = fullScreen; 
    310                 } 
    311                 else 
    312                 { 
    313                         mHWnd = externalHandle; 
    314                         ShowWindow(mHWnd, SW_SHOWNORMAL); 
    315                         UpdateWindow(mHWnd); 
    316                         RECT rc; 
    317                         GetClientRect(mHWnd,&rc); 
    318                         mWidth = rc.right; 
    319                         mHeight = rc.bottom; 
    320                         mLeft = rc.left; 
    321                         mTop = rc.top; 
    322                         mName = name; 
    323                         mIsDepthBuffered = depthBuffer; 
    324                         mIsFullScreen = fullScreen; 
    325                 } 
    326  
    327                 // track colour depth 
    328304                mColourDepth = colourDepth; 
    329305 
     
    337313                createD3DResources(); 
    338314 
    339                 mReady = true; 
     315                mActive = true; 
    340316        } 
    341317 
     
    365341                md3dpp.BackBufferWidth                  = mWidth; 
    366342                md3dpp.BackBufferHeight                 = mHeight; 
     343 
    367344#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    368345        //md3dpp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; 
     
    504481        } 
    505482 
    506          
    507         void D3D9RenderWindow::destroy() 
     483        void D3D9RenderWindow::destroyD3DResources() 
    508484        { 
    509485                mpRenderSurface = 0; 
     
    515491                else 
    516492                { 
    517                         // ignore deptzh buffer, access device through driver 
     493                        // ignore depth buffer, access device through driver 
    518494                        mpRenderZBuffer = 0; 
    519495                        LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice(); 
    520496                        SAFE_RELEASE(mpD3DDevice); 
    521                         mDriver->setD3DDevice( mpD3DDevice ); 
     497                        mDriver->setD3DDevice(NULL); 
     498                } 
     499        } 
     500 
     501        void D3D9RenderWindow::destroy() 
     502        { 
     503                if (mHWnd && !mIsExternal) 
    522504                        DestroyWindow( mHWnd ); 
    523                 } 
    524505                mHWnd = 0; 
     506                mActive = false; 
     507        } 
     508 
     509        bool D3D9RenderWindow::isVisible() const 
     510        { 
     511                return (mHWnd && !IsIconic(mHWnd)); 
     512        } 
     513 
     514        void D3D9RenderWindow::reposition(int top, int left) 
     515        { 
     516                if (mHWnd && !mIsFullScreen) 
     517                { 
     518                        SetWindowPos(mHWnd, 0, top, left, 0, 0, 
     519                                SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); 
     520                } 
    525521        } 
    526522 
    527523        void D3D9RenderWindow::resize( unsigned int width, unsigned int height ) 
    528524        { 
     525                if (mHWnd && !mIsFullScreen) 
     526                { 
     527                        RECT rc = { 0, 0, width, height }; 
     528                        AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false); 
     529                        width = rc.right - rc.left; 
     530                        height = rc.bottom - rc.top; 
     531                        SetWindowPos(mHWnd, 0, 0, 0, width, height, 
     532                                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); 
     533                } 
     534        } 
     535 
     536        void D3D9RenderWindow::windowMovedOrResized() 
     537        { 
     538                if (!mHWnd || IsIconic(mHWnd)) 
     539                        return; 
     540 
     541                RECT rc; 
     542                // top and left represent outer window position 
     543                GetWindowRect(mHWnd, &rc); 
     544                mTop = rc.top; 
     545                mLeft = rc.left; 
     546                // width and height represent drawable area only 
     547                GetClientRect(mHWnd, &rc); 
     548                unsigned int width = rc.right; 
     549                unsigned int height = rc.bottom; 
     550                if (mWidth == width && mHeight == height) 
     551                        return; 
    529552                 
    530553                if (mIsSwapChain)  
     
    584607                        } 
    585608                } 
    586                 // primary windows would reset the device - not implemented yet. 
     609                // primary windows must reset the device 
    587610                else  
    588611                { 
    589                         mWidth = width; 
    590                         mHeight = height; 
     612                        md3dpp.BackBufferWidth = mWidth = width; 
     613                        md3dpp.BackBufferHeight = mHeight = height; 
     614                        static_cast<D3D9RenderSystem*>( 
     615                                Root::getSingleton().getRenderSystem())->_notifyDeviceLost(); 
    591616                } 
    592617 
     
    595620                while( it != mViewportList.end() ) 
    596621                        (*it++).second->_updateDimensions(); 
    597                 // TODO - resize window 
    598622        } 
    599623 
     
    617641                                static_cast<D3D9RenderSystem*>( 
    618642                                        Root::getSingleton().getRenderSystem())->_notifyDeviceLost(); 
    619                                 Sleep(500); 
    620  
    621643                        } 
    622644                        else if( FAILED(hr) ) 
     
    668690                        return; 
    669691                } 
    670         } 
    671  
    672         void D3D9RenderWindow::WindowMovedOrResized() 
    673         { 
    674                 // TODO 
    675692        } 
    676693 
     
    863880                                else 
    864881                                        SAFE_RELEASE (mpRenderZBuffer); 
    865                                 Sleep(500); 
     882                                Sleep(50); 
    866883                                return; 
    867884                        } 
    868                         else if (hr == D3DERR_DEVICENOTRESET) 
     885                        else 
    869886                        { 
    870887                                // device lost, and we can reset 
     
    875892                                { 
    876893                                        // Wait a while 
    877                                         Sleep(500); 
     894                                        Sleep(50); 
    878895                                        return; 
    879896                                } 
Note: See TracChangeset for help on using the changeset viewer.