Changeset 193 for trunk/VUT/work/ogre_changes/RenderSystems/GL/src
- Timestamp:
- 08/03/05 14:12:41 (19 years ago)
- Location:
- trunk/VUT/work/ogre_changes/RenderSystems/GL/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp
r115 r193 27 27 #include "OgreException.h" 28 28 29 30 29 namespace Ogre { 31 30 … … 52 51 // Check for hardware occlusion support 53 52 // 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 55 56 if (glGenOcclusionQueriesNV_ptr != 0) 57 #endif 56 58 { 57 59 mHasOcclusionSupport = true; … … 64 66 if(mHasOcclusionSupport) 65 67 { 66 //glGenQueriesARB_ptr(1, &mQueryID ); 68 #ifdef GTP_VISIBILITY_USE_ARB_QUERIES 69 glGenQueriesARB_ptr(1, &mQueryID ); 70 #else 67 71 glGenOcclusionQueriesNV_ptr(1, &mQueryID); 72 #endif 68 73 } 69 74 } … … 76 81 if( mHasOcclusionSupport ) 77 82 { 78 //glDeleteQueriesARB_ptr(1, &mQueryID); 83 #ifdef GTP_VISIBILITY_USE_ARB_QUERIES 84 glDeleteQueriesARB_ptr(1, &mQueryID); 85 #else 79 86 glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); 87 #endif 80 88 } 81 89 } … … 101 109 if (mSkipCounter == 0) 102 110 { 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 104 114 glBeginOcclusionQueryNV_ptr(mQueryID); 115 #endif 105 116 } 106 117 } … … 114 125 if( mSkipCounter == 0) 115 126 { 116 //glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 127 #ifdef GTP_VISIBILITY_USE_ARB_QUERIES 128 glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 129 #else 117 130 glEndOcclusionQueryNV_ptr(); 131 #endif 118 132 } 119 133 … … 129 143 if( mHasOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 130 144 { 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 132 148 glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); 149 #endif 133 150 } 134 151 else -
trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLRenderSystem.cpp
r150 r193 149 149 150 150 GLRenderSystem::GLRenderSystem() 151 : m ExternalWindowHandle(0), mDepthWrite(true), mHardwareBufferManager(0),151 : mDepthWrite(true), mHardwareBufferManager(0), 152 152 mGpuProgramManager(0) 153 153 { … … 173 173 for (i = 0; i < OGRE_MAX_TEXTURE_COORD_SETS; i++) 174 174 { 175 mTextureCoordIndex[i] = 0; 175 // Dummy value 176 mTextureCoordIndex[i] = 99; 176 177 } 177 178 … … 334 335 GLint units; 335 336 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 } 336 348 337 349 mCapabilities->setNumTextureUnits(units); 350 338 351 } 339 352 else … … 405 418 mGpuProgramManager->_pushSyntaxCode("arbvp1"); 406 419 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 } 407 433 } 408 434 … … 455 481 mGpuProgramManager->_pushSyntaxCode("arbfp1"); 456 482 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 } 457 496 } 458 497 … … 911 950 912 951 GLfloat mat[16]; 913 makeGLMatrix(mat, mViewMatrix);952 makeGLMatrix( mat, mViewMatrix * mWorldMatrix ); 914 953 glMatrixMode(GL_MODELVIEW); 915 954 glLoadMatrixf(mat); 916 917 makeGLMatrix(mat, mWorldMatrix);918 glMultMatrixf(mat);919 955 920 956 setGLClipPlanes(); … … 1025 1061 if(lastTextureType != mTextureTypes[stage] && lastTextureType != 0) 1026 1062 { 1063 if (stage < mFixedFunctionTextureUnits) 1064 { 1027 1065 glDisable( lastTextureType ); 1028 1066 } 1029 1067 } 1068 1069 if (stage < mFixedFunctionTextureUnits) 1070 { 1030 1071 glEnable( mTextureTypes[stage] ); 1072 } 1073 1031 1074 if(!tex.isNull()) 1032 1075 glBindTexture( mTextureTypes[stage], tex->getGLID() ); 1076 1033 1077 } 1034 1078 else 1035 1079 { 1080 if (stage < mFixedFunctionTextureUnits) 1081 { 1036 1082 if (lastTextureType != 0) 1037 1083 { … … 1040 1086 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 1041 1087 } 1088 } 1042 1089 1043 1090 glActiveTextureARB_ptr( GL_TEXTURE0 ); 1091 1044 1092 } 1045 1093 … … 1053 1101 const Frustum* frustum) 1054 1102 { 1103 if (stage >= mFixedFunctionTextureUnits) 1104 { 1105 // Can't do this 1106 return; 1107 } 1108 1109 1055 1110 GLfloat M[16]; 1056 1111 Matrix4 projectionBias; … … 1209 1264 void GLRenderSystem::_setTextureMatrix(size_t stage, const Matrix4& xform) 1210 1265 { 1266 if (stage >= mFixedFunctionTextureUnits) 1267 { 1268 // Can't do this 1269 return; 1270 } 1271 1211 1272 GLfloat mat[16]; 1212 1273 makeGLMatrix(mat, xform); … … 1286 1347 GLint sourceBlend = getBlendMode(sourceFactor); 1287 1348 GLint destBlend = getBlendMode(destFactor); 1288 1349 if(sourceFactor == SBF_ONE && destFactor == SBF_ZERO) 1350 { 1351 glDisable(GL_BLEND); 1352 } 1353 else 1354 { 1289 1355 glEnable(GL_BLEND); 1290 1356 glBlendFunc(sourceBlend, destBlend); 1291 1357 } 1358 } 1292 1359 //----------------------------------------------------------------------------- 1293 1360 void GLRenderSystem::_setAlphaRejectSettings(CompareFunction func, unsigned char value) 1294 1361 { 1362 if(func == CMPF_ALWAYS_PASS) 1363 { 1364 glDisable(GL_ALPHA_TEST); 1365 } 1366 else 1367 { 1295 1368 glEnable(GL_ALPHA_TEST); 1296 1369 glAlphaFunc(convertCompareFunction(func), value / 255.0f); 1370 } 1297 1371 } 1298 1372 //----------------------------------------------------------------------------- … … 1345 1419 "GLRenderSystem::_beginFrame"); 1346 1420 1421 // Activate the viewport clipping 1422 glEnable(GL_SCISSOR_TEST); 1347 1423 // Clear the viewport if required 1348 1424 if (mActiveViewport->getClearEveryFrame()) 1349 1425 { 1350 // Activate the viewport clipping1351 glEnable(GL_SCISSOR_TEST);1352 1353 1426 clearFrameBuffer(FBT_COLOUR | FBT_DEPTH, 1354 1427 mActiveViewport->getBackgroundColour()); … … 1839 1912 void GLRenderSystem::_setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) 1840 1913 { 1914 if (stage >= mFixedFunctionTextureUnits) 1915 { 1916 // Can't do this 1917 return; 1918 } 1919 1841 1920 // Check to see if blending is supported 1842 1921 if(!mCapabilities->hasCapability(RSC_BLENDING)) … … 2095 2174 { 2096 2175 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(); 2097 2180 } 2098 2181 … … 2132 2215 case VES_TEXTURE_COORDINATES: 2133 2216 2134 for (i = 0; i < mCapabilities->getNumTextureUnits(); i++)2217 for (i = 0; i < OGRE_MAX_TEXTURE_COORD_SETS; i++) 2135 2218 { 2136 2219 // Only set this texture unit's texcoord pointer if it … … 2227 2310 else 2228 2311 { 2229 glDrawArrays(primType, op.vertexData->vertexStart, 2230 op.vertexData->vertexCount); 2312 glDrawArrays(primType, 0, op.vertexData->vertexCount); 2231 2313 } 2232 2314 2233 2315 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++) 2235 2317 { 2236 2318 glClientActiveTextureARB_ptr(GL_TEXTURE0 + i); … … 2451 2533 dest[3][2] = -1; 2452 2534 } 2535 2453 2536 // ------------------------------------------------------------------ 2454 2537 void GLRenderSystem::setClipPlane (ushort index, Real A, Real B, Real C, Real D) … … 2496 2579 } 2497 2580 //--------------------------------------------------------------------- 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 //---------------------------------------------------------------------2510 2581 void GLRenderSystem::_applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 2511 2582 bool forGpuProgram) … … 2541 2612 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); 2542 2613 glEnable(GL_COLOR_SUM); 2614 glDisable(GL_DITHER); 2543 2615 2544 2616 // Check for FSAA -
trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLTexture.cpp
r156 r193 37 37 #include "OgreCodec.h" 38 38 #include "OgreImageCodec.h" 39 39 #include "OgreStringConverter.h" 40 40 41 41 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 … … 200 200 if(depth>1) depth = depth/2; 201 201 } 202 delete tmpdata;202 delete [] tmpdata; 203 203 } 204 204 else … … 355 355 for(int mip=0; mip<=getNumMipmaps(); mip++) 356 356 { 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 } 361 372 } 362 373 } -
trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreWin32Window.cpp
r156 r193 42 42 mIsFullScreen = false; 43 43 mHWnd = 0; 44 mIsExternal = false; 45 mSizing = false; 46 mClosed = false; 47 mDisplayFrequency = 0; 44 48 mActive = false; 45 mReady = false;46 mClosed = false;47 49 } 48 50 … … 55 57 bool fullScreen, const NameValuePairList *miscParams) 56 58 { 57 HWND parentHWnd = 0; 58 HWND externalHandle = 0; 59 // destroy current window, if any 60 if (mHWnd) 61 destroy(); 62 59 63 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; 60 80 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; 68 84 69 85 if(miscParams) … … 71 87 // Get variable-length params 72 88 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"); 75 120 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"); 79 124 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); 114 126 115 // Destroy current window if any 116 if( mHWnd ) 117 destroy(); 118 119 if (fullScreen) 127 if (mIsFullScreen) 120 128 { 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); 122 134 } 123 135 else 124 136 { 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) 137 144 { 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) 151 150 { 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; 153 156 } 154 157 else 155 158 { 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) 159 171 { 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; 166 192 } 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 } 203 226 } 204 227 205 }206 else {207 mHWnd = externalHandle;208 228 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 209 234 GetClientRect(mHWnd, &rc); 210 235 mWidth = rc.right; 211 236 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 221 237 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) 233 243 OGRE_EXCEPT(0, "selectPixelFormat failed", "Win32Window::create"); 234 244 235 245 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)) 237 247 OGRE_EXCEPT(0, "selectPixelFormat failed", "Win32Window::create"); 238 248 } 239 249 240 HGLRC glrc = wglCreateContext(hdc);241 if (! glrc)250 mGlrc = wglCreateContext(mHDC); 251 if (!mGlrc) 242 252 OGRE_EXCEPT(0, "wglCreateContext", "Win32Window::create"); 243 if (!wglMakeCurrent( hdc, glrc))253 if (!wglMakeCurrent(mHDC, mGlrc)) 244 254 OGRE_EXCEPT(0, "wglMakeCurrent", "Win32Window::create"); 245 255 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); 256 257 257 258 // Create RenderSystem context … … 260 261 GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); 261 262 rs->_registerContext(this, mContext); 263 264 mActive = true; 262 265 } 263 266 264 267 void Win32Window::destroy(void) 265 268 { 269 if (!mHWnd) 270 return; 271 266 272 // Unregister and destroy OGRE GLContext 267 273 if (mContext) … … 270 276 rs->_unregisterContext(this); 271 277 delete mContext; 272 mContext = NULL; 273 274 wglSwapIntervalEXT(mOldSwapIntervall); 278 mContext = 0; 275 279 } 276 if (mGlrc) {277 wglMakeCurrent(NULL, NULL);280 if (mGlrc) 281 { 278 282 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 { 285 287 if (mIsFullScreen) 286 {287 288 ChangeDisplaySettings(NULL, 0); 288 }289 if (mHWnd)290 {291 289 DestroyWindow(mHWnd); 292 mHWnd = 0;293 290 } 294 291 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)); 300 299 } 301 300 … … 307 306 void Win32Window::reposition(int left, int top) 308 307 { 309 // XXX FIXME 308 if (mHWnd && !mIsFullScreen) 309 { 310 SetWindowPos(mHWnd, 0, left, top, 0, 0, 311 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); 312 } 310 313 } 311 314 312 315 void Win32Window::resize(unsigned int width, unsigned int height) 313 316 { 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; 317 346 318 347 // Notify viewports of resize … … 321 350 for( it = mViewportList.begin(); it != itend; ++it ) 322 351 (*it).second->_updateDimensions(); 323 // TODO - resize window324 }325 326 void Win32Window::windowMovedOrResized()327 {328 RECT temprect;329 ::GetClientRect(getWindowHandle(),&temprect);330 resize(temprect.right-temprect.left,temprect.bottom-temprect.top);331 // TODO332 352 } 333 353 … … 406 426 LRESULT Win32Window::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 407 427 { 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 } 409 436 410 437 // 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); 413 442 414 443 switch( uMsg ) 415 444 { 416 445 case WM_ACTIVATE: 417 if( WA_INACTIVE == LOWORD( wParam ) ) 446 if (win->mIsFullScreen) 447 { 448 if (LOWORD(wParam) == WA_INACTIVE) 449 { 418 450 win->mActive = false; 451 ChangeDisplaySettings(NULL, 0); 452 ShowWindow(hWnd, SW_SHOWMINNOACTIVE); 453 } 419 454 else 455 { 420 456 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 } 421 473 break; 422 474 423 case WM_CREATE: {424 // Log the new window425 // Get CREATESTRUCT426 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;427 win = (Win32Window*)(lpcs->lpCreateParams);428 // Store pointer in window user data area429 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 was437 // comvered up, so we need to refresh it by re-showing the contents438 // 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 rects445 // used for blitting the backbuffer to the primary446 // *** This doesn't need to be used to Direct3D9 ***447 break;448 449 475 case WM_ENTERSIZEMOVE: 450 // Previent rendering while moving / sizing 451 win->mReady = false; 476 win->mSizing = true; 452 477 break; 453 478 454 479 case WM_EXITSIZEMOVE: 455 480 win->windowMovedOrResized(); 456 win->m Ready = true;481 win->mSizing = false; 457 482 break; 458 483 484 case WM_MOVE: 459 485 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) 468 487 win->windowMovedOrResized(); 469 }470 488 break; 471 489 … … 477 495 478 496 case WM_CLOSE: 479 DestroyWindow( win->mHWnd );497 win->destroy(); // will call DestroyWindow 480 498 win->mClosed = true; 481 499 return 0;
Note: See TracChangeset
for help on using the changeset viewer.