# HG changeset patch # User Beyzend # Date 1323214148 25200 # Node ID 9e2dd5eabefdfbff8e46b53e8f458d2fba262d70 # Parent 3b0558273b253023aa124d28d5f4cfdf638a4f19 -merged Crashy's patch diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/include/OgreD3D11DepthBuffer.h --- a/RenderSystems/Direct3D11/include/OgreD3D11DepthBuffer.h Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/include/OgreD3D11DepthBuffer.h Tue Dec 06 16:29:08 2011 -0700 @@ -36,7 +36,7 @@ class D3D11DepthBuffer : public DepthBuffer { public: - D3D11DepthBuffer( uint16 poolId, + D3D11DepthBuffer( uint16 poolId, D3D11RenderSystem *renderSystem, ID3D11DepthStencilView *depthBufferView, uint32 width, uint32 height, uint32 fsaa, uint32 multiSampleQuality, bool isManual ); @@ -50,6 +50,7 @@ protected: ID3D11DepthStencilView *mDepthStencilView; //aka. actual "DepthBuffer" uint32 mMultiSampleQuality; + D3D11RenderSystem *mRenderSystem; }; } #endif diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h --- a/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h Tue Dec 06 16:29:08 2011 -0700 @@ -131,9 +131,11 @@ PolygonMode mPolygonMode; - FilterOptions FilterMinification; - FilterOptions FilterMagnification; - FilterOptions FilterMips; + FilterOptions FilterMinification[OGRE_MAX_TEXTURE_LAYERS]; + FilterOptions FilterMagnification[OGRE_MAX_TEXTURE_LAYERS]; + FilterOptions FilterMips[OGRE_MAX_TEXTURE_LAYERS]; + + bool CompareEnabled[OGRE_MAX_TEXTURE_LAYERS]; D3D11_RECT mScissorRect; @@ -356,7 +358,10 @@ /// @copydoc RenderSystem::getDisplayMonitorCount unsigned int getDisplayMonitorCount() const {return 1;} //todo - + + //Added Missing filter options from Crashy's patch as these FilterOptions weren't defined in the header in that patch. + void _setTextureUnitCompareEnabled(size_t unit, bool compare); + void _setTextureUnitCompareFunction(size_t unit, CompareFunction function); }; } #endif diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/src/OgreD3D11DepthBuffer.cpp --- a/RenderSystems/Direct3D11/src/OgreD3D11DepthBuffer.cpp Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/src/OgreD3D11DepthBuffer.cpp Tue Dec 06 16:29:08 2011 -0700 @@ -31,13 +31,14 @@ namespace Ogre { - D3D11DepthBuffer::D3D11DepthBuffer( uint16 poolId, + D3D11DepthBuffer::D3D11DepthBuffer( uint16 poolId, D3D11RenderSystem *renderSystem, ID3D11DepthStencilView *depthBufferView, uint32 width, uint32 height, uint32 fsaa, uint32 multiSampleQuality, bool isManual ) : DepthBuffer( poolId, 0, width, height, fsaa, "", isManual ), mDepthStencilView( depthBufferView ), - mMultiSampleQuality( multiSampleQuality ) + mMultiSampleQuality( multiSampleQuality ), + mRenderSystem(renderSystem) { /*D3D11_DEPTH_STENCIL_VIEW_DESC pDesc; mDepthStencilView->GetDesc( &pDesc ); @@ -65,7 +66,7 @@ { //TODO: //Urgh! This bit of "isTexture" is a bit ugly and potentially unsafe - bool isTexture = true; + /*bool isTexture = true; renderTarget->getCustomAttribute( "isTexture", &isTexture ); ID3D11Texture2D *D3D11texture; @@ -93,6 +94,53 @@ } return false; + */ + + D3D11_TEXTURE2D_DESC BBDesc; + + bool isTexture = false; + renderTarget->getCustomAttribute( "isTexture", &isTexture ); + + if(isTexture) + { + ID3D11Texture2D *D3D11texture; + D3D11HardwarePixelBuffer *pBuffer; + renderTarget->getCustomAttribute( "BUFFER", &pBuffer ); + D3D11texture = static_cast( pBuffer->getParentTexture()->getTextureResource() ); + D3D11texture->GetDesc(&BBDesc); + } + else + { + ID3D11Texture2D* pBack[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; + memset( pBack, 0, sizeof(pBack) ); + renderTarget->getCustomAttribute( "DDBACKBUFFER", &pBack ); + + if( pBack[0] ) + { + pBack[0]->GetDesc(&BBDesc); + } + else + { + ID3D11Texture2D *D3D11texture; + renderTarget->getCustomAttribute( "ID3D11Texture2D", &D3D11texture ); + D3D11texture->GetDesc( &BBDesc ); + } + } + + //RenderSystem will determine if bitdepths match (i.e. 32 bit RT don't like 16 bit Depth) + //This is the same function used to create them. Note results are usually cached so this should + //be quick + + //TODO: Needs to check format too! + if( mFsaa == BBDesc.SampleDesc.Count && + mMultiSampleQuality == BBDesc.SampleDesc.Quality && + this->getWidth() == renderTarget->getWidth() && + this->getHeight() == renderTarget->getHeight() ) + { + return true; + } + + return false; } //--------------------------------------------------------------------- ID3D11DepthStencilView* D3D11DepthBuffer::getDepthStencilView() const diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp --- a/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp Tue Dec 06 16:29:08 2011 -0700 @@ -66,18 +66,19 @@ /// If there is another target bound, compare sizes if(targets[y]->getWidth() != buffer->getWidth() || targets[y]->getHeight() != buffer->getHeight() || - PixelUtil::getNumElemBits(targets[y]->getFormat()) != + PixelUtil::getNumElemBits(targets[y]->getFormat()) != PixelUtil::getNumElemBits(buffer->getFormat())) { OGRE_EXCEPT( - Exception::ERR_INVALIDPARAMS, - "MultiRenderTarget surfaces are not of same size or bit depth", + Exception::ERR_INVALIDPARAMS, + "MultiRenderTarget surfaces are not of same size or bit depth", "D3D11MultiRenderTarget::bindSurface" ); } } targets[attachment] = buffer; + //mRenderTargets[attachment] = target; checkAndUpdate(); } //--------------------------------------------------------------------- @@ -144,6 +145,21 @@ mWidth = 0; mHeight = 0; } + + /*if(name == "ID3D11RenderTargetView") + { + ID3D11RenderTargetView ** pRTView = (ID3D11RenderTargetView**)pData; + + memset(pRTView,0,sizeof(pRTView)); + + for(int y=0; ygetCustomAttribute("ID3D11RenderTargetView",&view); + pRTView[y]=view; + } + return; + }*/ } //--------------------------------------------------------------------- diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp --- a/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp Tue Dec 06 16:29:08 2011 -0700 @@ -1,10 +1,10 @@ /* ------------------------------------------------------------------------------ + This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ -Copyright (c) 2000-2009 Torus Knot Software Ltd +Copyright (c) 2000-2011 Torus Knot Software Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------ + */ #include "OgreD3D11RenderSystem.h" #include "OgreD3D11Prerequisites.h" @@ -1192,7 +1192,7 @@ } //Create the abstract container - D3D11DepthBuffer *newDepthBuffer = new D3D11DepthBuffer( DepthBuffer::POOL_DEFAULT, depthStencilView, + D3D11DepthBuffer *newDepthBuffer = new D3D11DepthBuffer( DepthBuffer::POOL_DEFAULT,this, depthStencilView, descDepth.Width, descDepth.Height, descDepth.SampleDesc.Count, descDepth.SampleDesc.Quality, false ); @@ -1217,7 +1217,7 @@ } //Create a new container for it - D3D11DepthBuffer *newDepthBuffer = new D3D11DepthBuffer( DepthBuffer::POOL_DEFAULT, depthSurface, + D3D11DepthBuffer *newDepthBuffer = new D3D11DepthBuffer( DepthBuffer::POOL_DEFAULT,this, depthSurface, width, height, fsaa, fsaaQuality, true ); //Add the 'main' depth buffer to the pool @@ -1514,9 +1514,12 @@ //--------------------------------------------------------------------- void D3D11RenderSystem::_setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage ) { - mSceneAlphaRejectFunc = func; - mSceneAlphaRejectValue = value; + mSceneAlphaRejectFunc = func; + mSceneAlphaRejectValue = value; + + mSceneAlphaToCoverage = alphaToCoverage; + //Do nothing, alpha rejection unavailable in Direct3D11 } //--------------------------------------------------------------------- void D3D11RenderSystem::_setCullingMode( CullingMode mode ) @@ -1626,19 +1629,29 @@ { switch(ftype) { case FT_MIN: - FilterMinification = filter; + FilterMinification[unit] = filter; break; case FT_MAG: - FilterMagnification = filter; + FilterMagnification[unit] = filter; break; case FT_MIP: - FilterMips = filter; + FilterMips[unit] = filter; break; } - mTexStageDesc[unit].samplerDesc.Filter = D3D11Mappings::get(FilterMinification, FilterMagnification, FilterMips); + mTexStageDesc[unit].samplerDesc.Filter = D3D11Mappings::get(FilterMinification[unit], FilterMagnification[unit], FilterMips[unit],CompareEnabled[unit]); } + //--------------------------------------------------------------------- + void D3D11RenderSystem::_setTextureUnitCompareEnabled(size_t unit, bool compare) + { + CompareEnabled[unit] = compare; + } + //--------------------------------------------------------------------- + void D3D11RenderSystem::_setTextureUnitCompareFunction(size_t unit, CompareFunction function) + { + mTexStageDesc[unit].samplerDesc.ComparisonFunc = D3D11Mappings::get(function); + } //--------------------------------------------------------------------- DWORD D3D11RenderSystem::_getCurrentAnisotropy(size_t unit) { @@ -1654,9 +1667,17 @@ mActiveRenderTarget = target; if (mActiveRenderTarget) { - ID3D11RenderTargetView * pRTView = NULL; + ID3D11RenderTargetView * pRTView[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; + memset(pRTView, 0, sizeof(pRTView)); + + uint count = 0; target->getCustomAttribute( "ID3D11RenderTargetView", &pRTView ); + while(pRTView[count] != NULL) + { + count++; + } + //Retrieve depth buffer D3D11DepthBuffer *depthBuffer = static_cast(target->getDepthBuffer()); @@ -1670,8 +1691,7 @@ //Retrieve depth buffer again (it may have changed) depthBuffer = static_cast(target->getDepthBuffer()); - - // we need to clear the state + // we need to clear the state mDevice.GetImmediateContext()->ClearState(); if (mDevice.isError()) @@ -1685,8 +1705,8 @@ // now switch to the new render target - mDevice.GetImmediateContext()->OMSetRenderTargets(1, - &pRTView, + mDevice.GetImmediateContext()->OMSetRenderTargets(count, + pRTView, depthBuffer ? depthBuffer->getDepthStencilView() : 0 ); @@ -1698,7 +1718,6 @@ "D3D11RenderSystem::_setViewport"); } } - // TODO - support MRT } //--------------------------------------------------------------------- @@ -1941,7 +1960,6 @@ opState->mTextures[opState->mTexturesCount] = texture; opState->mTexturesCount++; - stage.samplerDesc.ComparisonFunc = D3D11Mappings::get(mSceneAlphaRejectFunc); stage.samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; stage.currentSamplerDesc = stage.samplerDesc; @@ -2472,19 +2490,20 @@ if (mActiveRenderTarget) { ID3D11RenderTargetView * pRTView[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; - std::memset(pRTView, 0, sizeof(pRTView)); + memset(pRTView, 0, sizeof(pRTView)); mActiveRenderTarget->getCustomAttribute( "ID3D11RenderTargetView", &pRTView ); - if (buffers & FBT_COLOUR) + uint count = 0; + while(pRTView[count] != NULL) { - float ClearColor[4]; - D3D11Mappings::get(colour, ClearColor); - for(size_t i = 0; i < OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++i) + if (buffers & FBT_COLOUR) { - if(pRTView[i]) - mDevice.GetImmediateContext()->ClearRenderTargetView( pRTView[i], ClearColor ); + float ClearColor[4]; + D3D11Mappings::get(colour, ClearColor); + mDevice.GetImmediateContext()->ClearRenderTargetView( pRTView[count], ClearColor ); } + count++; } UINT ClearFlags = 0; if (buffers & FBT_DEPTH) @@ -2825,10 +2844,12 @@ ZeroMemory( &mDepthStencilDesc, sizeof(mDepthStencilDesc)); ZeroMemory( &mScissorRect, sizeof(mScissorRect)); - FilterMinification = FO_NONE; - FilterMagnification = FO_NONE; - FilterMips = FO_NONE; - + for(size_t i = 0; i < OGRE_MAX_TEXTURE_LAYERS; ++i) + { + FilterMinification[i] = FO_NONE; + FilterMagnification[i] = FO_NONE; + FilterMips[i] = FO_NONE; + } mPolygonMode = PM_SOLID; ZeroMemory(mTexStageDesc, OGRE_MAX_TEXTURE_LAYERS * sizeof(sD3DTextureStageDesc)); diff -r 3b0558273b25 -r 9e2dd5eabefd RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp --- a/RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp Tue Dec 06 13:49:19 2011 -0700 +++ b/RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp Tue Dec 06 16:29:08 2011 -0700 @@ -965,6 +965,7 @@ { // IDXGISurface ** pSurf = (IDXGISurface **)pData; //*pSurf = static_cast(mBuffer)->getSurface(); + *static_cast(pData) = mBuffer; return; } else if(name == "HWND") @@ -973,6 +974,11 @@ *pHwnd = NULL; return; } + else if(name == "isTexture") + { + bool *b = reinterpret_cast< bool * >( pData ); + *b = true; + } else if(name == "BUFFER") { *static_cast(pData) = mBuffer;