yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// d3d11-swap-chain.cpp 2#include "d3d11-swap-chain.h" 3 4#include "d3d11-device.h" 5#include "d3d11-texture.h" 6 7namespace gfx 8{ 9 10using namespace Slang ; 11 12namespace d3d11 13{ 14 15Result SwapchainImpl ::init ( 16DeviceImpl * renderer , 17const ISwapchain ::Desc & swapchainDesc , 18WindowHandle window ) 19{ 20m_renderer = renderer ; 21m_device = renderer -> m_device ; 22m_dxgiFactory = renderer -> m_dxgiFactory ; 23return D3DSwapchainBase ::init (swapchainDesc ,window ,DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ); 24} 25 26void SwapchainImpl ::createSwapchainBufferImages () 27{ 28m_images .clear (); 29// D3D11 implements automatic back buffer rotation, so the application 30// always render to buffer 0. 31ComPtr < ID3D11Resource > d3dResource ; 32m_swapChain -> GetBuffer (0 ,IID_PPV_ARGS (d3dResource .writeRef ())); 33ITextureResource ::Desc imageDesc = {}; 34imageDesc .type = IResource ::Type ::Texture2D ; 35imageDesc .arraySize = 0 ; 36imageDesc .numMipLevels = 1 ; 37imageDesc .size .width = m_desc .width ; 38imageDesc .size .height = m_desc .height ; 39imageDesc .size .depth = 1 ; 40imageDesc .format = m_desc .format ; 41imageDesc .defaultState = ResourceState ::Present ; 42imageDesc .allowedStates = ResourceStateSet ( 43ResourceState ::Present , 44ResourceState ::CopyDestination , 45ResourceState ::RenderTarget ); 46RefPtr < TextureResourceImpl > image = new TextureResourceImpl (imageDesc ); 47image -> m_resource = d3dResource ; 48for (GfxIndex i = 0 ;i < m_desc .imageCount ;i ++ ) 49 { 50m_images .add (image ); 51 } 52} 53 54SLANG_NO_THROW Result SLANG_MCALL SwapchainImpl ::resize (GfxCount width ,GfxCount height ) 55{ 56m_renderer -> m_currentFramebuffer = nullptr ; 57m_renderer -> m_immediateContext -> ClearState (); 58return D3DSwapchainBase ::resize (width ,height ); 59} 60 61SLANG_NO_THROW bool SLANG_MCALL SwapchainImpl ::isOccluded () 62{ 63return false; 64} 65 66SLANG_NO_THROW Result SLANG_MCALL SwapchainImpl ::setFullScreenMode (bool mode ) 67{ 68return SLANG_FAIL ; 69} 70 71}// namespace d3d11 72}// namespace gfx