Changeset 193 for trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src
- Timestamp:
- 08/03/05 14:12:41 (19 years ago)
- Location:
- trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp
r115 r193 87 87 mSkipCounter = 0; 88 88 } 89 //std::stringstream d; d << "count: " << mSkipCounter;90 //LogManager::getSingleton().logMessage(d.str());91 89 if (mSkipCounter == 0) 92 90 { -
trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp
r183 r193 45 45 LRESULT D3D9RenderWindow::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 46 46 { 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); 54 60 55 61 switch( uMsg ) 56 62 { 57 63 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); 62 65 break; 63 66 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; 74 69 break; 75 70 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; 90 74 break; 91 75 92 case WM_PAINT:93 // If we get WM_PAINT messges, it usually means our window was94 // comvered up, so we need to refresh it by re-showing the contents95 // of the current frame.96 if( win->mActive && win->mReady )97 win->update();98 break;99 100 76 case WM_MOVE: 101 // Move messages need to be tracked to update the screen rects102 // used for blitting the backbuffer to the primary103 // *** This doesn't need to be used to Direct3D9 ***104 break;105 106 case WM_ENTERSIZEMOVE:107 // Previent rendering while moving / sizing108 win->mReady = false;109 break;110 111 case WM_EXITSIZEMOVE:112 win->WindowMovedOrResized();113 win->mReady = true;114 break;115 116 77 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(); 127 80 break; 128 81 … … 134 87 135 88 case WM_CLOSE: 136 DestroyWindow( win->mHWnd );89 win->destroy(); // cleanup and call DestroyWindow 137 90 win->mClosed = true; 138 91 return 0; … … 147 100 { 148 101 mIsFullScreen = false; 149 mIsSwapChain = deviceIfSwapChain != NULL; 102 mIsSwapChain = (deviceIfSwapChain != NULL); 103 mIsExternal = false; 150 104 mHWnd = 0; 151 105 mActive = false; 152 m Ready= false;106 mSizing = false; 153 107 mClosed = false; 154 108 } … … 161 115 LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice(); 162 116 SAFE_RELEASE( mpD3DDevice ); 163 mDriver->setD3DDevice( mpD3DDevice);117 mDriver->setD3DDevice( NULL ); 164 118 } 165 119 } … … 192 146 String title = name; 193 147 unsigned int colourDepth = 32; 194 unsigned int left = 0; // Defaults to screen center195 unsigned int top = 0; // Defaults to screen center148 int left = -1; // Defaults to screen center 149 int top = -1; // Defaults to screen center 196 150 bool depthBuffer = true; 151 String border = ""; 152 bool outerSize = false; 197 153 198 154 if(miscParams) … … 203 159 opt = miscParams->find("left"); 204 160 if(opt != miscParams->end()) 205 left = StringConverter::parse UnsignedInt(opt->second);161 left = StringConverter::parseInt(opt->second); 206 162 // top (y) 207 163 opt = miscParams->find("top"); 208 164 if(opt != miscParams->end()) 209 top = StringConverter::parse UnsignedInt(opt->second);165 top = StringConverter::parseInt(opt->second); 210 166 // Window title 211 167 opt = miscParams->find("title"); 212 168 if(opt != miscParams->end()) 213 169 title = opt->second; 170 // parentWindowHandle -> parentHWnd 171 opt = miscParams->find("parentWindowHandle"); 172 if(opt != miscParams->end()) 173 parentHWnd = (HWND)StringConverter::parseUnsignedInt(opt->second); 214 174 // externalWindowHandle -> externalHandle 215 175 opt = miscParams->find("externalWindowHandle"); … … 240 200 if(opt != miscParams->end()) 241 201 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); 242 210 } 243 211 … … 249 217 if (!externalHandle) 250 218 { 251 DWORD dwStyle = (fullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW)| WS_CLIPCHILDREN | WS_CLIPSIBLINGS;219 DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 252 220 RECT rc; 253 221 254 222 mWidth = width; 255 223 mHeight = height; 224 mTop = top; 225 mLeft = left; 256 226 257 227 if (!fullScreen) 258 228 { 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 260 248 SetRect(&rc, 0, 0, mWidth, mHeight); 261 249 AdjustWindowRect(&rc, dwStyle, false); … … 264 252 265 253 // 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 } 279 265 } 280 266 else 267 { 268 dwStyle |= WS_POPUP; 281 269 mTop = mLeft = 0; 270 } 282 271 283 272 // Register the window class 284 273 // 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); 291 278 292 279 // Create our main window 293 280 // 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); 299 298 mWidth = rc.right; 300 299 mHeight = rc.bottom; 301 300 302 ShowWindow(hWnd, SW_SHOWNORMAL);303 UpdateWindow(hWnd);304 305 mHWnd = hWnd;306 // Store info307 301 mName = name; 308 302 mIsDepthBuffered = depthBuffer; 309 303 mIsFullScreen = fullScreen; 310 }311 else312 {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 depth328 304 mColourDepth = colourDepth; 329 305 … … 337 313 createD3DResources(); 338 314 339 m Ready= true;315 mActive = true; 340 316 } 341 317 … … 365 341 md3dpp.BackBufferWidth = mWidth; 366 342 md3dpp.BackBufferHeight = mHeight; 343 367 344 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 368 345 //md3dpp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; … … 504 481 } 505 482 506 507 void D3D9RenderWindow::destroy() 483 void D3D9RenderWindow::destroyD3DResources() 508 484 { 509 485 mpRenderSurface = 0; … … 515 491 else 516 492 { 517 // ignore dept zh buffer, access device through driver493 // ignore depth buffer, access device through driver 518 494 mpRenderZBuffer = 0; 519 495 LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice(); 520 496 SAFE_RELEASE(mpD3DDevice); 521 mDriver->setD3DDevice( mpD3DDevice ); 497 mDriver->setD3DDevice(NULL); 498 } 499 } 500 501 void D3D9RenderWindow::destroy() 502 { 503 if (mHWnd && !mIsExternal) 522 504 DestroyWindow( mHWnd ); 523 }524 505 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 } 525 521 } 526 522 527 523 void D3D9RenderWindow::resize( unsigned int width, unsigned int height ) 528 524 { 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; 529 552 530 553 if (mIsSwapChain) … … 584 607 } 585 608 } 586 // primary windows would reset the device - not implemented yet.609 // primary windows must reset the device 587 610 else 588 611 { 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(); 591 616 } 592 617 … … 595 620 while( it != mViewportList.end() ) 596 621 (*it++).second->_updateDimensions(); 597 // TODO - resize window598 622 } 599 623 … … 617 641 static_cast<D3D9RenderSystem*>( 618 642 Root::getSingleton().getRenderSystem())->_notifyDeviceLost(); 619 Sleep(500);620 621 643 } 622 644 else if( FAILED(hr) ) … … 668 690 return; 669 691 } 670 }671 672 void D3D9RenderWindow::WindowMovedOrResized()673 {674 // TODO675 692 } 676 693 … … 863 880 else 864 881 SAFE_RELEASE (mpRenderZBuffer); 865 Sleep(50 0);882 Sleep(50); 866 883 return; 867 884 } 868 else if (hr == D3DERR_DEVICENOTRESET)885 else 869 886 { 870 887 // device lost, and we can reset … … 875 892 { 876 893 // Wait a while 877 Sleep(50 0);894 Sleep(50); 878 895 return; 879 896 }
Note: See TracChangeset
for help on using the changeset viewer.