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/GL
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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.