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

changed to ogre 103
added readme

Location:
trunk/VUT/work/ogre_changes/RenderSystems
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9RenderWindow.h

    r153 r193  
    4646                    bool fullScreen, const NameValuePairList *miscParams); 
    4747                void destroy(void); 
    48                 bool isActive() const { return mActive; } 
     48                bool isVisible() const; 
    4949                bool isClosed() const { return mClosed; } 
    50                 void reposition( int left, int top ) {} 
     50                void reposition(int left, int top); 
    5151                void resize( unsigned int width, unsigned int height ); 
    5252                void swapBuffers( bool waitForVSync = true ); 
     
    6161                */ 
    6262                void writeContentsToFile(const String& filename); 
     63                bool requiresTextureFlipping() const { return false; } 
    6364 
     65                // Method for dealing with resize / move & 3d library 
     66                void windowMovedOrResized(); 
    6467#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    6568                uchar *getBufferContents(int &dimx, int &dimy); 
    6669#endif // GTP_VISIBILITY_MODIFIED_OGRE 
    6770 
    68                 bool requiresTextureFlipping() const { return false; } 
    69  
    70                 // Method for dealing with resize / move & 3d library 
    71                 virtual void WindowMovedOrResized(void); 
    72  
    73                 bool isReady() const { return mReady; } 
    74                 void setReady(bool set) { mReady = set; } 
    75                 void setActive(bool set) { mActive = set; } 
    7671                /// Get the presentation parameters used with this window 
    7772                D3DPRESENT_PARAMETERS* getPresentationParameters(void)  
    7873                { return &md3dpp; } 
     74 
    7975                /// @copydoc RenderTarget::update 
    80                 void update(void); 
     76                void update(); 
    8177 
    8278                /** Create (or recreate) the D3D device or SwapChain for this window. 
    8379                */ 
    84                 void createD3DResources(void); 
     80                void createD3DResources(); 
     81         
     82                /** Destroy the D3D device or SwapChain for this window. 
     83                */ 
     84                void destroyD3DResources(); 
    8585         
    8686        protected: 
     
    8888                D3D9Driver *mDriver;                    // D3D9 driver 
    8989                HWND    mHWnd;                                  // Win32 Window handle 
    90                 bool    mActive;                                // Is active i.e. visible 
    91                 bool    mReady;                                 // Is ready i.e. available for update 
     90                bool    mIsExternal;                    // window not created by Ogre 
     91                bool    mSizing; 
    9292                bool    mClosed; 
    9393                bool    mIsSwapChain;                   // Is this a secondary window? 
  • trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9Texture.h

    r154 r193  
    161161                static PixelFormat _getClosestSupportedPF(PixelFormat ogrePF); 
    162162 
    163                 /// For dealing with lost devices - release the resource if in the default pool 
    164                 void releaseIfDefaultPool(void); 
    165                 /// For dealing with lost devices - recreate the resource if in the default pool 
    166                 void recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev); 
     163                /// For dealing with lost devices - release the resource if in the default pool (and return true) 
     164                bool releaseIfDefaultPool(void); 
     165                /// For dealing with lost devices - recreate the resource if in the default pool (and return true) 
     166                bool recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev); 
    167167 
    168168    }; 
     
    243243                (mName + "_PRIVATE##", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
    244244                texType, mWidth, mHeight, 0, internalFormat, TU_RENDERTARGET ); 
     245                        mPrivateTex->load(); 
    245246        } 
    246247                 
  • trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp

    r115 r193  
    8787                                mSkipCounter = 0;  
    8888} 
    89                         //std::stringstream d; d << "count: " << mSkipCounter; 
    90                         //LogManager::getSingleton().logMessage(d.str()); 
    9189                        if (mSkipCounter == 0) 
    9290                { 
  • 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                                } 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/include/OgreGLPrerequisites.h

    r115 r193  
    5252#       define APIENTRY 
    5353#   endif 
     54#   define GL_GLEXT_LEGACY  
    5455#   include <OpenGL/gl.h> 
    5556#   include <OpenGL/glu.h> 
     
    270271    if (errCode != GL_NO_ERROR) {  \ 
    271272    errString = gluErrorString (errCode);  \ 
    272     LogManager::getSingleton().logMessage  ("[GL] :" + ERROR_MSG +  \ 
     273    LogManager::getSingleton().logMessage  ("[GL] :" + Ogre::String(ERROR_MSG) +  \ 
    273274    " : " + Ogre::String( (const char*) errString)); \ 
    274275        } \ 
     
    282283    errString = gluErrorString (errCode);  \ 
    283284    OGRE_EXCEPT (Exception::ERR_INTERNAL_ERROR,  \ 
    284     ERROR_MSG +  \ 
     285    Ogre::String(ERROR_MSG) +  \ 
    285286    " : " + Ogre::String( (const char*) errString), String("")); \ 
    286287        } \ 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/include/OgreWin32Window.h

    r153 r193  
    4040                    bool fullScreen, const NameValuePairList *miscParams); 
    4141        void destroy(void); 
    42         bool isActive(void) const; 
     42        bool isVisible() const; 
    4343        bool isClosed(void) const; 
    4444        void reposition(int left, int top); 
     
    6161                // Method for dealing with resize / move & 3d library 
    6262                virtual void windowMovedOrResized(void); 
    63                 bool isReady() const { return mReady; } 
    64                 void setReady(bool set) { mReady = set; } 
    65                 void setActive(bool set) { mActive = set; } 
    6663                 
    6764                void getCustomAttribute( const String& name, void* pData ); 
     
    7269                HDC             mHDC; 
    7370                HGLRC   mGlrc; 
    74                 int             mOldSwapIntervall; 
    75                 bool    mActive;                                // Is active i.e. visible 
    76                 bool    mReady;                                 // Is ready i.e. available for update 
     71        bool    mIsExternal; 
     72        bool    mSizing; 
    7773                bool    mClosed; 
     74        int     mDisplayFrequency;      // fullscreen only, to restore display 
    7875        Win32Context *mContext; 
    7976 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp

    r115 r193  
    2727#include "OgreException.h" 
    2828 
    29  
    3029namespace Ogre { 
    3130 
     
    5251        // Check for hardware occlusion support 
    5352        // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported. 
    54         //if (glGenQueriesARB_ptr != 0) 
     53#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     54        if (glGenQueriesARB_ptr != 0) 
     55#else 
    5556        if (glGenOcclusionQueriesNV_ptr != 0) 
     57#endif 
    5658    { 
    5759                mHasOcclusionSupport = true; 
     
    6466        if(mHasOcclusionSupport) 
    6567        { 
    66                 //glGenQueriesARB_ptr(1, &mQueryID );    
     68#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     69                glGenQueriesARB_ptr(1, &mQueryID );      
     70#else 
    6771                glGenOcclusionQueriesNV_ptr(1, &mQueryID); 
     72#endif 
    6873        } 
    6974} 
     
    7681        if( mHasOcclusionSupport ) 
    7782        { 
    78                 //glDeleteQueriesARB_ptr(1, &mQueryID);   
     83#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     84                glDeleteQueriesARB_ptr(1, &mQueryID); 
     85#else 
    7986                glDeleteOcclusionQueriesNV_ptr(1, &mQueryID);   
     87#endif 
    8088        }        
    8189} 
     
    101109                if (mSkipCounter == 0) 
    102110                { 
    103                         //glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID); 
     111#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     112                        glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID); 
     113#else 
    104114                        glBeginOcclusionQueryNV_ptr(mQueryID); 
     115#endif 
    105116                } 
    106117        } 
     
    114125                if( mSkipCounter == 0) 
    115126                { 
    116                         //glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 
     127#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     128                        glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 
     129#else 
    117130                        glEndOcclusionQueryNV_ptr(); 
     131#endif 
    118132                } 
    119133 
     
    129143        if( mHasOcclusionSupport )      // Make it fail silently if hardware occlusion isn't supported 
    130144        { 
    131                 //glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); 
     145#ifdef GTP_VISIBILITY_USE_ARB_QUERIES 
     146                glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); 
     147#else 
    132148glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); 
     149#endif 
    133150        } 
    134151        else 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLRenderSystem.cpp

    r150 r193  
    149149 
    150150    GLRenderSystem::GLRenderSystem() 
    151       : mExternalWindowHandle(0), mDepthWrite(true), mHardwareBufferManager(0), 
     151      : mDepthWrite(true), mHardwareBufferManager(0), 
    152152        mGpuProgramManager(0) 
    153153    { 
     
    173173        for (i = 0; i < OGRE_MAX_TEXTURE_COORD_SETS; i++) 
    174174        { 
    175             mTextureCoordIndex[i] = 0; 
     175                        // Dummy value 
     176            mTextureCoordIndex[i] = 99; 
    176177        } 
    177178 
     
    334335            GLint units; 
    335336            glGetIntegerv( GL_MAX_TEXTURE_UNITS, &units ); 
     337                        mFixedFunctionTextureUnits = units; 
     338 
     339                        if (mGLSupport->checkExtension("GL_ARB_fragment_program")) 
     340                        { 
     341                                // Also check GL_MAX_TEXTURE_IMAGE_UNITS_ARB since NV at least 
     342                                // only increased this on the FX/6x00 series 
     343                                GLint arbUnits; 
     344                                glGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &arbUnits ); 
     345                                if (arbUnits > units) 
     346                                        units = arbUnits; 
     347                        } 
    336348 
    337349            mCapabilities->setNumTextureUnits(units); 
     350 
    338351        } 
    339352        else 
     
    405418            mGpuProgramManager->_pushSyntaxCode("arbvp1"); 
    406419            mGpuProgramManager->registerProgramFactory("arbvp1", createGLArbGpuProgram); 
     420                        if (mGLSupport->checkExtension("GL_NV_vertex_program2_option")) 
     421                        { 
     422                                mCapabilities->setMaxVertexProgramVersion("vp30"); 
     423                                mGpuProgramManager->_pushSyntaxCode("vp30"); 
     424                                mGpuProgramManager->registerProgramFactory("vp30", createGLArbGpuProgram); 
     425                        } 
     426 
     427                        if (mGLSupport->checkExtension("GL_NV_vertex_program3")) 
     428                        { 
     429                                mCapabilities->setMaxVertexProgramVersion("vp40"); 
     430                                mGpuProgramManager->_pushSyntaxCode("vp40"); 
     431                                mGpuProgramManager->registerProgramFactory("vp40", createGLArbGpuProgram); 
     432                        } 
    407433        } 
    408434 
     
    455481            mGpuProgramManager->_pushSyntaxCode("arbfp1"); 
    456482            mGpuProgramManager->registerProgramFactory("arbfp1", createGLArbGpuProgram); 
     483                        if (mGLSupport->checkExtension("GL_NV_fragment_program_option")) 
     484                        { 
     485                                mCapabilities->setMaxFragmentProgramVersion("fp30"); 
     486                                mGpuProgramManager->_pushSyntaxCode("fp30"); 
     487                                mGpuProgramManager->registerProgramFactory("fp30", createGLArbGpuProgram); 
     488                        } 
     489 
     490                        if (mGLSupport->checkExtension("GL_NV_fragment_program2")) 
     491                        { 
     492                                mCapabilities->setMaxFragmentProgramVersion("fp40"); 
     493                                mGpuProgramManager->_pushSyntaxCode("fp40"); 
     494                                mGpuProgramManager->registerProgramFactory("fp40", createGLArbGpuProgram); 
     495                        }         
    457496        } 
    458497 
     
    911950 
    912951        GLfloat mat[16]; 
    913         makeGLMatrix(mat, mViewMatrix); 
     952                makeGLMatrix( mat, mViewMatrix * mWorldMatrix ); 
    914953        glMatrixMode(GL_MODELVIEW); 
    915954        glLoadMatrixf(mat); 
    916  
    917         makeGLMatrix(mat, mWorldMatrix); 
    918         glMultMatrixf(mat); 
    919955 
    920956        setGLClipPlanes(); 
     
    10251061            if(lastTextureType != mTextureTypes[stage] && lastTextureType != 0) 
    10261062            { 
     1063                                if (stage < mFixedFunctionTextureUnits) 
     1064                                { 
    10271065                glDisable( lastTextureType ); 
    10281066            } 
    1029  
     1067            } 
     1068 
     1069                        if (stage < mFixedFunctionTextureUnits) 
     1070                        { 
    10301071                        glEnable( mTextureTypes[stage] ); 
     1072                        } 
     1073 
    10311074                        if(!tex.isNull()) 
    10321075                                glBindTexture( mTextureTypes[stage], tex->getGLID() ); 
     1076 
    10331077        } 
    10341078        else 
    10351079        { 
     1080                        if (stage < mFixedFunctionTextureUnits) 
     1081                        { 
    10361082            if (lastTextureType != 0) 
    10371083            { 
     
    10401086                        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    10411087        } 
     1088        } 
    10421089 
    10431090        glActiveTextureARB_ptr( GL_TEXTURE0 ); 
     1091 
    10441092    } 
    10451093 
     
    10531101        const Frustum* frustum) 
    10541102    { 
     1103                if (stage >= mFixedFunctionTextureUnits) 
     1104                { 
     1105                        // Can't do this 
     1106                        return; 
     1107                } 
     1108 
     1109                 
    10551110        GLfloat M[16]; 
    10561111        Matrix4 projectionBias; 
     
    12091264    void GLRenderSystem::_setTextureMatrix(size_t stage, const Matrix4& xform) 
    12101265    { 
     1266                if (stage >= mFixedFunctionTextureUnits) 
     1267                { 
     1268                        // Can't do this 
     1269                        return; 
     1270                } 
     1271 
    12111272        GLfloat mat[16]; 
    12121273        makeGLMatrix(mat, xform); 
     
    12861347        GLint sourceBlend = getBlendMode(sourceFactor); 
    12871348        GLint destBlend = getBlendMode(destFactor); 
    1288          
     1349        if(sourceFactor == SBF_ONE && destFactor == SBF_ZERO) 
     1350        { 
     1351            glDisable(GL_BLEND); 
     1352        } 
     1353        else 
     1354        { 
    12891355        glEnable(GL_BLEND); 
    12901356        glBlendFunc(sourceBlend, destBlend); 
    12911357    } 
     1358    } 
    12921359    //----------------------------------------------------------------------------- 
    12931360    void GLRenderSystem::_setAlphaRejectSettings(CompareFunction func, unsigned char value) 
    12941361    { 
     1362        if(func == CMPF_ALWAYS_PASS) 
     1363        { 
     1364            glDisable(GL_ALPHA_TEST); 
     1365        } 
     1366        else 
     1367        { 
    12951368        glEnable(GL_ALPHA_TEST); 
    12961369        glAlphaFunc(convertCompareFunction(func), value / 255.0f); 
     1370    } 
    12971371    } 
    12981372    //----------------------------------------------------------------------------- 
     
    13451419                "GLRenderSystem::_beginFrame"); 
    13461420 
     1421        // Activate the viewport clipping 
     1422        glEnable(GL_SCISSOR_TEST); 
    13471423        // Clear the viewport if required 
    13481424        if (mActiveViewport->getClearEveryFrame()) 
    13491425        { 
    1350             // Activate the viewport clipping 
    1351             glEnable(GL_SCISSOR_TEST); 
    1352  
    13531426            clearFrameBuffer(FBT_COLOUR | FBT_DEPTH,  
    13541427                mActiveViewport->getBackgroundColour()); 
     
    18391912    void GLRenderSystem::_setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) 
    18401913    {        
     1914                if (stage >= mFixedFunctionTextureUnits) 
     1915                { 
     1916                        // Can't do this 
     1917                        return; 
     1918                } 
     1919 
    18411920        // Check to see if blending is supported 
    18421921        if(!mCapabilities->hasCapability(RSC_BLENDING)) 
     
    20952174            { 
    20962175                pBufferData = static_cast<const GLDefaultHardwareVertexBuffer*>(vertexBuffer.get())->getDataPtr(elem->getOffset()); 
     2176            } 
     2177            if (op.vertexData->vertexStart) 
     2178            { 
     2179                pBufferData = static_cast<char*>(pBufferData) + op.vertexData->vertexStart * vertexBuffer->getVertexSize(); 
    20972180            } 
    20982181 
     
    21322215            case VES_TEXTURE_COORDINATES: 
    21332216 
    2134                 for (i = 0; i < mCapabilities->getNumTextureUnits(); i++) 
     2217                for (i = 0; i < OGRE_MAX_TEXTURE_COORD_SETS; i++) 
    21352218                { 
    21362219                                        // Only set this texture unit's texcoord pointer if it 
     
    22272310        else 
    22282311        { 
    2229             glDrawArrays(primType, op.vertexData->vertexStart, 
    2230                 op.vertexData->vertexCount); 
     2312            glDrawArrays(primType, 0, op.vertexData->vertexCount); 
    22312313        } 
    22322314 
    22332315        glDisableClientState( GL_VERTEX_ARRAY ); 
    2234         for (int i = 0; i < mCapabilities->getNumTextureUnits(); i++) 
     2316        for (int i = 0; i < OGRE_MAX_TEXTURE_COORD_SETS; i++) 
    22352317        { 
    22362318            glClientActiveTextureARB_ptr(GL_TEXTURE0 + i); 
     
    24512533        dest[3][2] = -1; 
    24522534    } 
     2535 
    24532536    // ------------------------------------------------------------------ 
    24542537    void GLRenderSystem::setClipPlane (ushort index, Real A, Real B, Real C, Real D) 
     
    24962579    } 
    24972580        //--------------------------------------------------------------------- 
    2498         void GLRenderSystem::resizeRepositionWindow(void* wich) 
    2499         { 
    2500                 mGLSupport->resizeRepositionWindow(wich); 
    2501                 for (RenderTargetMap::iterator it = mRenderTargets.begin(); it != mRenderTargets.end(); ++it)            
    2502                 { 
    2503                         if (it->second->isActive()) 
    2504                         { 
    2505                                 mGLSupport->resizeReposition(it->second); 
    2506                         } 
    2507                 } 
    2508         } 
    2509     //--------------------------------------------------------------------- 
    25102581    void GLRenderSystem::_applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,  
    25112582        bool forGpuProgram) 
     
    25412612        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);         
    25422613        glEnable(GL_COLOR_SUM); 
     2614        glDisable(GL_DITHER); 
    25432615 
    25442616        // Check for FSAA 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLTexture.cpp

    r156 r193  
    3737#include "OgreCodec.h" 
    3838#include "OgreImageCodec.h" 
    39  
     39#include "OgreStringConverter.h" 
    4040 
    4141#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 
     
    200200                                if(depth>1)             depth = depth/2; 
    201201                        } 
    202                         delete tmpdata; 
     202                        delete [] tmpdata; 
    203203                } 
    204204                else 
     
    355355                        for(int mip=0; mip<=getNumMipmaps(); mip++) 
    356356                        { 
    357                                 mSurfaceList.push_back(HardwarePixelBufferSharedPtr( 
    358                                         new GLHardwarePixelBuffer(getGLTextureTarget(), mTextureID, face, mip, 
    359                                                 static_cast<HardwareBuffer::Usage>(mUsage), doSoftware && mip==0) 
    360                                 )); 
     357                GLHardwarePixelBuffer *buf = new GLHardwarePixelBuffer(getGLTextureTarget(), mTextureID, face, mip, 
     358                                                static_cast<HardwareBuffer::Usage>(mUsage), doSoftware && mip==0); 
     359                                mSurfaceList.push_back(HardwarePixelBufferSharedPtr(buf)); 
     360                 
     361                /// Check for error 
     362                if(buf->getWidth()==0 || buf->getHeight()==0 || buf->getDepth()==0) 
     363                { 
     364                    OGRE_EXCEPT( 
     365                        Exception::ERR_RENDERINGAPI_ERROR,  
     366                        "Zero sized texture surface on texture "+getName()+ 
     367                            " face "+StringConverter::toString(face)+ 
     368                            " mipmap "+StringConverter::toString(mip)+ 
     369                            ". Probably, the GL driver refused to create the texture.",  
     370                            "GLTexture::_createSurfaceList"); 
     371                } 
    361372                        } 
    362373                } 
  • trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreWin32Window.cpp

    r156 r193  
    4242                mIsFullScreen = false; 
    4343                mHWnd = 0; 
     44                mIsExternal = false; 
     45                mSizing = false; 
     46                mClosed = false; 
     47                mDisplayFrequency = 0; 
    4448                mActive = false; 
    45                 mReady = false; 
    46                 mClosed = false; 
    4749    } 
    4850 
     
    5557                    bool fullScreen, const NameValuePairList *miscParams) 
    5658    { 
    57         HWND parentHWnd = 0; 
    58                 HWND externalHandle = 0; 
     59                // destroy current window, if any 
     60                if (mHWnd) 
     61                        destroy(); 
     62 
    5963                HINSTANCE hInst = GetModuleHandle("RenderSystem_GL.dll"); 
     64 
     65                mHWnd = 0; 
     66                mName = name; 
     67                mIsFullScreen = fullScreen; 
     68                mClosed = false; 
     69 
     70                // load window defaults 
     71                mLeft = mTop = -1; // centered 
     72                mWidth = width; 
     73                mHeight = height; 
     74                mDisplayFrequency = 0; 
     75                mIsDepthBuffered = true; 
     76                mColourDepth = mIsFullScreen? 32 : GetDeviceCaps(GetDC(0), BITSPIXEL); 
     77 
     78                HWND parent = 0; 
     79                String title = name; 
    6080                bool vsync = false; 
    61                 unsigned int displayFrequency = 0; 
    62                 String title = name; 
    63                 unsigned int colourDepth = 32; 
    64                 unsigned int left = 0; // Defaults to screen center 
    65                 unsigned int top = 0; // Defaults to screen center 
    66                 bool depthBuffer = true; 
    67                 int multisample = 0; 
     81                int fsaa = 0; 
     82                String border = ""; 
     83                bool outerSize = false; 
    6884 
    6985                if(miscParams) 
     
    7187                        // Get variable-length params 
    7288                        NameValuePairList::const_iterator opt; 
    73                         // left (x) 
    74                         opt = miscParams->find("left"); 
     89                        NameValuePairList::const_iterator end = miscParams->end(); 
     90 
     91                        if ((opt = miscParams->find("title")) != end) 
     92                                title = opt->second; 
     93 
     94                        if ((opt = miscParams->find("left")) != end) 
     95                                mLeft = StringConverter::parseInt(opt->second); 
     96 
     97                        if ((opt = miscParams->find("top")) != end) 
     98                                mTop = StringConverter::parseInt(opt->second); 
     99 
     100                        if ((opt = miscParams->find("depthBuffer")) != end) 
     101                                mIsDepthBuffered = StringConverter::parseBool(opt->second); 
     102 
     103                        if ((opt = miscParams->find("vsync")) != end) 
     104                                vsync = StringConverter::parseBool(opt->second); 
     105 
     106                        if ((opt = miscParams->find("FSAA")) != end) 
     107                                fsaa = StringConverter::parseUnsignedInt(opt->second); 
     108 
     109                        if ((opt = miscParams->find("externalWindowHandle")) != end) 
     110                        { 
     111                                mHWnd = (HWND)StringConverter::parseUnsignedInt(opt->second); 
     112                                if (mHWnd) 
     113                                { 
     114                                        mIsExternal = true; 
     115                                        mIsFullScreen = false; 
     116                                } 
     117                        } 
     118                        // window border style 
     119                        opt = miscParams->find("border"); 
    75120                        if(opt != miscParams->end()) 
    76                                 left = StringConverter::parseUnsignedInt(opt->second); 
    77                         // top (y) 
    78                         opt = miscParams->find("top"); 
     121                                border = opt->second; 
     122                        // set outer dimensions? 
     123                        opt = miscParams->find("outerDimensions"); 
    79124                        if(opt != miscParams->end()) 
    80                                 top = StringConverter::parseUnsignedInt(opt->second); 
    81                         // Window title 
    82                         opt = miscParams->find("title"); 
    83                         if(opt != miscParams->end()) 
    84                                 title = opt->second; 
    85                         // externalWindowHandle         -> externalHandle 
    86                         opt = miscParams->find("externalWindowHandle"); 
    87                         if(opt != miscParams->end()) 
    88                                 externalHandle = (HWND)StringConverter::parseUnsignedInt(opt->second); 
    89                         // parentWindowHandle -> parentHWnd 
    90                         opt = miscParams->find("parentWindowHandle"); 
    91                         if(opt != miscParams->end())  
    92                                 parentHWnd = (HWND)StringConverter::parseUnsignedInt(opt->second); 
    93                         // vsync        [parseBool] 
    94                         opt = miscParams->find("vsync"); 
    95                         if(opt != miscParams->end()) 
    96                                 vsync = StringConverter::parseBool(opt->second); 
    97                         // displayFrequency 
    98                         opt = miscParams->find("displayFrequency"); 
    99                         if(opt != miscParams->end()) 
    100                                 displayFrequency = StringConverter::parseUnsignedInt(opt->second); 
    101                         // colourDepth 
    102                         opt = miscParams->find("colourDepth"); 
    103                         if(opt != miscParams->end()) 
    104                                 colourDepth = StringConverter::parseUnsignedInt(opt->second); 
    105                         // depthBuffer [parseBool] 
    106                         opt = miscParams->find("depthBuffer"); 
    107                         if(opt != miscParams->end()) 
    108                                 depthBuffer = StringConverter::parseBool(opt->second); 
    109                         // FSAA 
    110                         opt = miscParams->find("FSAA"); 
    111                         if(opt != miscParams->end()) 
    112                                 multisample = StringConverter::parseUnsignedInt(opt->second); 
    113                 } 
     125                                outerSize = StringConverter::parseBool(opt->second); 
    114126                 
    115                 // Destroy current window if any 
    116                 if( mHWnd ) 
    117                         destroy(); 
    118  
    119         if (fullScreen) 
     127                        if (mIsFullScreen) 
    120128        { 
    121                         mColourDepth = colourDepth; 
     129                                // only available with fullscreen 
     130                                if ((opt = miscParams->find("displayFrequency")) != end) 
     131                                        mDisplayFrequency = StringConverter::parseUnsignedInt(opt->second); 
     132                                if ((opt = miscParams->find("colourDepth")) != end) 
     133                                        mColourDepth = StringConverter::parseUnsignedInt(opt->second); 
    122134        } 
    123135                else  
    124136                { 
    125                         // Get colour depth from display 
    126                         mColourDepth = GetDeviceCaps(GetDC(0), BITSPIXEL); 
    127                 } 
    128  
    129                 if (!externalHandle) { 
    130                         DWORD dwStyle = (fullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW) | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 
    131                         RECT rc; 
    132  
    133                         mWidth = width; 
    134                         mHeight = height; 
    135  
    136                         if (!fullScreen) 
     137                                // incompatible with fullscreen 
     138                                if ((opt = miscParams->find("parentWindowHandle")) != end) 
     139                                        parent = (HWND)StringConverter::parseUnsignedInt(opt->second); 
     140                        } 
     141                } 
     142 
     143                if (!mIsExternal) 
    137144                        { 
    138                                 // Calculate window dimensions required to get the requested client area 
    139                                 SetRect(&rc, 0, 0, mWidth, mHeight); 
    140                                 AdjustWindowRect(&rc, dwStyle, false); 
    141                                 mWidth = rc.right - rc.left; 
    142                                 mHeight = rc.bottom - rc.top; 
    143  
    144                                 // Clamp width and height to the desktop dimensions 
    145                                 if (mWidth > (unsigned)GetSystemMetrics(SM_CXSCREEN)) 
    146                                         mWidth = (unsigned)GetSystemMetrics(SM_CXSCREEN); 
    147                                 if (mHeight > (unsigned)GetSystemMetrics(SM_CYSCREEN)) 
    148                                         mHeight = (unsigned)GetSystemMetrics(SM_CYSCREEN); 
    149  
    150                                 if (!left) 
     145                        DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 
     146                        DWORD dwStyleEx = 0; 
     147                        int outerw, outerh; 
     148 
     149                        if (mIsFullScreen) 
    151150                { 
    152                                         mLeft = (GetSystemMetrics(SM_CXSCREEN) / 2) - (mWidth / 2); 
     151                                dwStyle |= WS_POPUP; 
     152                                dwStyleEx |= WS_EX_TOPMOST; 
     153                                outerw = mWidth; 
     154                                outerh = mHeight; 
     155                                mLeft = mTop = 0; 
    153156                } 
    154157                                else 
    155158                { 
    156                                         mLeft = left; 
    157                 } 
    158                                 if (!top) 
     159                                if (border == "none") 
     160                                        dwStyle |= WS_POPUP; 
     161                                else if (border == "fixed") 
     162                                        dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION | 
     163                                        WS_SYSMENU | WS_MINIMIZEBOX; 
     164                                else 
     165                                        dwStyle |= WS_OVERLAPPEDWINDOW; 
     166 
     167                                int screenw = GetSystemMetrics(SM_CXSCREEN); 
     168                                int screenh = GetSystemMetrics(SM_CYSCREEN); 
     169 
     170                                if (!outerSize) 
    159171                { 
    160                                         mTop = (GetSystemMetrics(SM_CYSCREEN) / 2) - (mHeight / 2); 
    161                 } 
    162                                 else 
    163                 { 
    164                     mTop = top; 
    165                 } 
     172                                        // calculate overall dimensions for requested client area 
     173                                        RECT rc = { 0, 0, mWidth, mHeight }; 
     174                                        AdjustWindowRect(&rc, dwStyle, false); 
     175 
     176                                        // clamp window dimensions to screen size 
     177                                        outerw = (rc.right-rc.left < screenw)? rc.right-rc.left : screenw; 
     178                                        outerh = (rc.bottom-rc.top < screenh)? rc.bottom-rc.top : screenh; 
     179            } 
     180 
     181                                // center window if given negative coordinates 
     182                                if (mLeft < 0) 
     183                                        mLeft = (screenw - outerw) / 2; 
     184                                if (mTop < 0) 
     185                                        mTop = (screenh - outerh) / 2; 
     186 
     187                                // keep window contained in visible screen area 
     188                                if (mLeft > screenw - outerw) 
     189                                        mLeft = screenw - outerw; 
     190                                if (mTop > screenh - outerh) 
     191                                        mTop = screenh - outerh; 
    166192                        } 
    167                         else 
    168             { 
    169                                 mTop = mLeft = 0; 
    170             } 
    171  
    172                         // Register the window class 
    173  
    174                         WNDCLASS wndClass = { CS_HREDRAW | CS_VREDRAW | CS_OWNDC, 
    175                                 WndProc, 0, 4, hInst, 
    176                                 LoadIcon( NULL, IDI_APPLICATION ), 
    177                                 LoadCursor( NULL, IDC_ARROW ), 
    178                                 (HBRUSH)GetStockObject( BLACK_BRUSH ), NULL, 
    179                                 TEXT(title.c_str()) }; 
    180                         RegisterClass( &wndClass ); 
    181  
    182                         // Create our main window 
    183                         // Pass pointer to self 
    184                         HWND hWnd = CreateWindowEx(fullScreen?WS_EX_TOPMOST:0, TEXT(title.c_str()), TEXT(title.c_str()), 
    185                                 dwStyle, mLeft, mTop, mWidth, mHeight, 0L, 0L, hInst, this); 
    186                         mHWnd = hWnd; 
    187  
    188                         GetClientRect(mHWnd,&rc); 
    189                         mWidth = rc.right; 
    190                         mHeight = rc.bottom; 
    191  
    192             if (fullScreen) { 
    193                             DEVMODE DevMode; 
    194                             DevMode.dmSize = sizeof(DevMode); 
    195                             DevMode.dmBitsPerPel = mColourDepth; 
    196                             DevMode.dmPelsWidth = mWidth; 
    197                             DevMode.dmPelsHeight = mHeight; 
    198                             DevMode.dmDisplayFrequency = displayFrequency; 
    199                             DevMode.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY; 
    200                             if (ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) 
    201                                     LogManager::getSingleton().logMessage(LML_CRITICAL, "ChangeDisplaySettingsEx"); 
    202  
     193 
     194                        // register class and create window 
     195                        WNDCLASS wc = { CS_OWNDC, WndProc, 0, 0, hInst, 
     196                                LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), 
     197                                (HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "OgreGLWindow" }; 
     198                        RegisterClass(&wc); 
     199 
     200                        // Pass pointer to self as WM_CREATE parameter 
     201                        mHWnd = CreateWindowEx(dwStyleEx, "OgreGLWindow", title.c_str(), 
     202                                dwStyle, mLeft, mTop, outerw, outerh, parent, 0, hInst, this); 
     203 
     204                        StringUtil::StrStreamType str; 
     205                        str << "Created Win32Window '" 
     206                                << mName << "' : " << mWidth << "x" << mHeight 
     207                                << ", " << mColourDepth << "bpp"; 
     208                        LogManager::getSingleton().logMessage(LML_NORMAL, str.str()); 
     209 
     210                        if (mIsFullScreen) 
     211                        { 
     212                                DEVMODE dm; 
     213                                dm.dmSize = sizeof(DEVMODE); 
     214                                dm.dmBitsPerPel = mColourDepth; 
     215                                dm.dmPelsWidth = mWidth; 
     216                                dm.dmPelsHeight = mHeight; 
     217                                dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; 
     218                                if (mDisplayFrequency) 
     219                                { 
     220                                        dm.dmDisplayFrequency = mDisplayFrequency; 
     221                                        dm.dmFields |= DM_DISPLAYFREQUENCY; 
     222                                } 
     223                                if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) 
     224                                        LogManager::getSingleton().logMessage(LML_CRITICAL, "ChangeDisplaySettings failed"); 
     225                        } 
    203226                    } 
    204227 
    205                 } 
    206                 else { 
    207                         mHWnd = externalHandle; 
    208228                        RECT rc; 
     229                // top and left represent outer window position 
     230                GetWindowRect(mHWnd, &rc); 
     231                mTop = rc.top; 
     232                mLeft = rc.left; 
     233                // width and height represent drawable area only 
    209234                        GetClientRect(mHWnd, &rc); 
    210235                        mWidth = rc.right; 
    211236                        mHeight = rc.bottom; 
    212                         mLeft = rc.left; 
    213                         mTop = rc.top; 
    214                 } 
    215                 ShowWindow(mHWnd, SW_SHOWNORMAL); 
    216                 UpdateWindow(mHWnd); 
    217                 mName = name; 
    218                 mIsDepthBuffered = depthBuffer; 
    219                 mIsFullScreen = fullScreen; 
    220  
    221237                 
    222                 HDC hdc = GetDC(mHWnd); 
    223  
    224         StringUtil::StrStreamType str; 
    225         str << "Created Win32Window '" 
    226             << mName << "' : " << mWidth << "x" << mHeight 
    227             << ", " << mColourDepth << "bpp"; 
    228         LogManager::getSingleton().logMessage(LML_NORMAL, str.str()); 
    229  
    230                 if (!mGLSupport.selectPixelFormat(hdc, mColourDepth, multisample)) 
    231                 { 
    232                         if (multisample == 0) 
     238                mHDC = GetDC(mHWnd); 
     239 
     240                if (!mGLSupport.selectPixelFormat(mHDC, mColourDepth, fsaa)) 
     241                { 
     242                        if (fsaa == 0) 
    233243                                OGRE_EXCEPT(0, "selectPixelFormat failed", "Win32Window::create"); 
    234244 
    235245                        LogManager::getSingleton().logMessage(LML_NORMAL, "FSAA level not supported, falling back"); 
    236                         if (!mGLSupport.selectPixelFormat(hdc, mColourDepth, 0)) 
     246                        if (!mGLSupport.selectPixelFormat(mHDC, mColourDepth, 0)) 
    237247                                OGRE_EXCEPT(0, "selectPixelFormat failed", "Win32Window::create"); 
    238248                } 
    239249 
    240                 HGLRC glrc = wglCreateContext(hdc); 
    241                 if (!glrc) 
     250                mGlrc = wglCreateContext(mHDC); 
     251                if (!mGlrc) 
    242252                        OGRE_EXCEPT(0, "wglCreateContext", "Win32Window::create"); 
    243                 if (!wglMakeCurrent(hdc, glrc)) 
     253                if (!wglMakeCurrent(mHDC, mGlrc)) 
    244254                        OGRE_EXCEPT(0, "wglMakeCurrent", "Win32Window::create"); 
    245255                 
    246                 mGlrc = glrc; 
    247                 mHDC = hdc; 
    248  
    249                 mOldSwapIntervall = wglGetSwapIntervalEXT(); 
    250                 if (vsync)  
    251                         wglSwapIntervalEXT(1); 
    252                 else 
    253                         wglSwapIntervalEXT(0); 
    254  
    255                 mReady = true; 
     256                wglSwapIntervalEXT(vsync? 1 : 0); 
    256257 
    257258        // Create RenderSystem context 
     
    260261        GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); 
    261262        rs->_registerContext(this, mContext); 
     263 
     264                mActive = true; 
    262265    } 
    263266 
    264267    void Win32Window::destroy(void) 
    265268    { 
     269                if (!mHWnd) 
     270                        return; 
     271 
    266272        // Unregister and destroy OGRE GLContext 
    267273        if (mContext) 
     
    270276            rs->_unregisterContext(this); 
    271277            delete mContext; 
    272             mContext = NULL; 
    273  
    274             wglSwapIntervalEXT(mOldSwapIntervall); 
     278                        mContext = 0; 
    275279        } 
    276                 if (mGlrc) { 
    277                         wglMakeCurrent(NULL, NULL); 
     280                if (mGlrc) 
     281                { 
    278282                        wglDeleteContext(mGlrc); 
    279                         mGlrc = NULL; 
    280                 } 
    281                 if (mHDC) { 
    282                         ReleaseDC(mHWnd, mHDC); 
    283                         mHDC = NULL; 
    284                 } 
     283                        mGlrc = 0; 
     284                } 
     285                if (!mIsExternal) 
     286                { 
    285287                if (mIsFullScreen) 
    286                 { 
    287288                        ChangeDisplaySettings(NULL, 0); 
    288                 } 
    289         if (mHWnd) 
    290         { 
    291289                DestroyWindow(mHWnd); 
    292             mHWnd = 0; 
    293290        } 
    294291        mActive = false; 
    295     } 
    296  
    297     bool Win32Window::isActive() const 
    298     { 
    299         return mActive; 
     292                mHDC = 0; // no release thanks to CS_OWNDC wndclass style 
     293                mHWnd = 0; 
     294    } 
     295 
     296        bool Win32Window::isVisible() const 
     297    { 
     298                return (mHWnd && !IsIconic(mHWnd)); 
    300299    } 
    301300 
     
    307306    void Win32Window::reposition(int left, int top) 
    308307    { 
    309         // XXX FIXME 
     308                if (mHWnd && !mIsFullScreen) 
     309                { 
     310                        SetWindowPos(mHWnd, 0, left, top, 0, 0, 
     311                                SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); 
     312                } 
    310313    } 
    311314 
    312315    void Win32Window::resize(unsigned int width, unsigned int height) 
    313316    { 
    314  
    315                 mWidth = width; 
    316                 mHeight = height; 
     317                if (mHWnd && !mIsFullScreen) 
     318                { 
     319                        RECT rc = { 0, 0, width, height }; 
     320                        AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false); 
     321                        width = rc.right - rc.left; 
     322                        height = rc.bottom - rc.top; 
     323                        SetWindowPos(mHWnd, 0, 0, 0, width, height, 
     324                                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); 
     325                } 
     326        } 
     327 
     328        void Win32Window::windowMovedOrResized() 
     329        { 
     330                if (!isVisible()) 
     331                        return; 
     332 
     333                RECT rc; 
     334                // top and left represent outer window position 
     335                GetWindowRect(mHWnd, &rc); 
     336                mTop = rc.top; 
     337                mLeft = rc.left; 
     338                // width and height represent drawable area only 
     339                GetClientRect(mHWnd, &rc); 
     340 
     341                if (mWidth == rc.right && mHeight == rc.bottom) 
     342                        return; 
     343 
     344                mWidth = rc.right; 
     345                mHeight = rc.bottom; 
    317346 
    318347                // Notify viewports of resize 
     
    321350                for( it = mViewportList.begin(); it != itend; ++it ) 
    322351                        (*it).second->_updateDimensions(); 
    323                 // TODO - resize window 
    324     } 
    325  
    326         void Win32Window::windowMovedOrResized() 
    327         { 
    328                 RECT temprect; 
    329                 ::GetClientRect(getWindowHandle(),&temprect); 
    330                 resize(temprect.right-temprect.left,temprect.bottom-temprect.top); 
    331                 // TODO 
    332352        } 
    333353 
     
    406426        LRESULT Win32Window::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
    407427        { 
    408                 Win32Window* win; 
     428 
     429                if (uMsg == WM_CREATE) 
     430                { 
     431                        // Store pointer to Win32Window in user data area 
     432                        SetWindowLong(hWnd, GWL_USERDATA, 
     433                                (LONG)(((LPCREATESTRUCT)lParam)->lpCreateParams)); 
     434                        return 0; 
     435                } 
    409436 
    410437                // look up window instance 
    411                 if( WM_CREATE != uMsg ) 
    412                         win = (Win32Window*)GetWindowLong( hWnd, 0 ); 
     438                // note: it is possible to get a WM_SIZE before WM_CREATE 
     439                Win32Window* win = (Win32Window*)GetWindowLong(hWnd, GWL_USERDATA); 
     440                if (!win) 
     441                        return DefWindowProc(hWnd, uMsg, wParam, lParam); 
    413442 
    414443                switch( uMsg ) 
    415444                { 
    416445                case WM_ACTIVATE: 
    417                         if( WA_INACTIVE == LOWORD( wParam ) ) 
     446                        if (win->mIsFullScreen) 
     447                        { 
     448                                if (LOWORD(wParam) == WA_INACTIVE) 
     449                                { 
    418450                                win->mActive = false; 
     451                                        ChangeDisplaySettings(NULL, 0); 
     452                                        ShowWindow(hWnd, SW_SHOWMINNOACTIVE); 
     453                                } 
    419454                        else 
     455                                { 
    420456                                win->mActive = true; 
     457                                        ShowWindow(hWnd, SW_SHOWNORMAL); 
     458 
     459                                        DEVMODE dm; 
     460                                        dm.dmSize = sizeof(DEVMODE); 
     461                                        dm.dmBitsPerPel = win->mColourDepth; 
     462                                        dm.dmPelsWidth = win->mWidth; 
     463                                        dm.dmPelsHeight = win->mHeight; 
     464                                        dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; 
     465                                        if (win->mDisplayFrequency) 
     466                                        { 
     467                                                dm.dmDisplayFrequency = win->mDisplayFrequency; 
     468                                                dm.dmFields |= DM_DISPLAYFREQUENCY; 
     469                                        } 
     470                                        ChangeDisplaySettings(&dm, CDS_FULLSCREEN); 
     471                                } 
     472                        } 
    421473                        break; 
    422474 
    423                 case WM_CREATE: { 
    424                         // Log the new window 
    425                         // Get CREATESTRUCT 
    426                         LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam; 
    427                         win = (Win32Window*)(lpcs->lpCreateParams); 
    428                         // Store pointer in window user data area 
    429                         SetWindowLong( hWnd, 0, (long)win ); 
    430                         win->mActive = true; 
    431  
    432                         return 0; } 
    433                         break; 
    434  
    435                 case WM_PAINT: 
    436                         // If we get WM_PAINT messges, it usually means our window was 
    437                         // comvered up, so we need to refresh it by re-showing the contents 
    438                         // of the current frame. 
    439                         if( win->mActive && win->mReady ) 
    440                                 win->update(); 
    441                         break; 
    442  
    443                 case WM_MOVE: 
    444                         // Move messages need to be tracked to update the screen rects 
    445                         // used for blitting the backbuffer to the primary 
    446                         // *** This doesn't need to be used to Direct3D9 *** 
    447                         break; 
    448  
    449475                case WM_ENTERSIZEMOVE: 
    450                         // Previent rendering while moving / sizing 
    451                         win->mReady = false; 
     476                        win->mSizing = true; 
    452477                        break; 
    453478 
    454479                case WM_EXITSIZEMOVE: 
    455480                        win->windowMovedOrResized(); 
    456                         win->mReady = true; 
     481                        win->mSizing = false; 
    457482                        break; 
    458483 
     484                case WM_MOVE: 
    459485                case WM_SIZE: 
    460                         // Check to see if we are losing or gaining our window.  Set the  
    461                         // active flag to match 
    462                         if( SIZE_MAXHIDE == wParam || SIZE_MINIMIZED == wParam ) 
    463                                 win->mActive = false; 
    464                         else 
    465                         { 
    466                                 win->mActive = true; 
    467                                 if( win->mReady ) 
     486                        if (!win->mSizing) 
    468487                                        win->windowMovedOrResized(); 
    469                         } 
    470488                        break; 
    471489 
     
    477495 
    478496                case WM_CLOSE: 
    479                         DestroyWindow( win->mHWnd ); 
     497                        win->destroy(); // will call DestroyWindow 
    480498                        win->mClosed = true; 
    481499                        return 0; 
Note: See TracChangeset for help on using the changeset viewer.