Quellcode durchsuchen

Fixed swap chain window counting.

Branimir Karadžić vor 7 Jahren
Ursprung
Commit
dc18a2931b
6 geänderte Dateien mit 49 neuen und 13 gelöschten Zeilen
  1. 18 2
      src/renderer_d3d11.cpp
  2. 2 0
      src/renderer_d3d11.h
  3. 11 5
      src/renderer_d3d12.cpp
  4. 6 2
      src/renderer_d3d9.cpp
  5. 6 2
      src/renderer_gl.cpp
  6. 6 2
      src/renderer_mtl.mm

+ 18 - 2
src/renderer_d3d11.cpp

@@ -1806,6 +1806,16 @@ namespace bgfx { namespace d3d11
 
 		void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override
 		{
+			for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
+			{
+				FrameBufferHandle handle = m_windows[ii];
+				if (isValid(handle)
+				&&  m_frameBuffers[handle.idx].m_nwh == _nwh)
+				{
+					destroyFrameBuffer(handle);
+				}
+			}
+
 			uint16_t denseIdx = m_numWindows++;
 			m_windows[denseIdx] = _handle;
 			m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat);
@@ -1820,8 +1830,12 @@ namespace bgfx { namespace d3d11
 				if (m_numWindows > 1)
 				{
 					FrameBufferHandle handle = m_windows[m_numWindows];
-					m_windows[denseIdx] = handle;
-					m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					m_windows[m_numWindows]  = {kInvalidHandle};
+					if (m_numWindows != denseIdx)
+					{
+						m_windows[denseIdx] = handle;
+						m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					}
 				}
 			}
 		}
@@ -4564,6 +4578,7 @@ namespace bgfx { namespace d3d11
 		DX_RELEASE(depthStencil, 0);
 
 		m_srv[0]   = NULL;
+		m_nwh      = _nwh;
 		m_denseIdx = _denseIdx;
 		m_num      = 1;
 	}
@@ -4575,6 +4590,7 @@ namespace bgfx { namespace d3d11
 		DX_RELEASE(m_swapChain, 0);
 
 		m_num   = 0;
+		m_nwh   = NULL;
 		m_numTh = 0;
 		m_needPresent = false;
 

+ 2 - 0
src/renderer_d3d11.h

@@ -305,6 +305,7 @@ namespace bgfx { namespace d3d11
 		FrameBufferD3D11()
 			: m_dsv(NULL)
 			, m_swapChain(NULL)
+			, m_nwh(NULL)
 			, m_width(0)
 			, m_height(0)
 			, m_denseIdx(UINT16_MAX)
@@ -328,6 +329,7 @@ namespace bgfx { namespace d3d11
 		ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
 		ID3D11DepthStencilView* m_dsv;
 		Dxgi::SwapChainI* m_swapChain;
+		void* m_nwh;
 		uint32_t m_width;
 		uint32_t m_height;
 

+ 11 - 5
src/renderer_d3d12.cpp

@@ -1658,11 +1658,13 @@ namespace bgfx { namespace d3d12
 		{
 			finishAll(true);
 
-			for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
+			for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
 			{
-				if (m_frameBuffers[ii].m_nwh == _nwh)
+				FrameBufferHandle handle = m_windows[ii];
+				if (isValid(handle)
+				&&  m_frameBuffers[handle.idx].m_nwh == _nwh)
 				{
-					m_frameBuffers[ii].destroy();
+					destroyFrameBuffer(handle);
 				}
 			}
 
@@ -1687,8 +1689,12 @@ namespace bgfx { namespace d3d12
 				if (m_numWindows > 1)
 				{
 					FrameBufferHandle handle = m_windows[m_numWindows];
-					m_windows[denseIdx] = handle;
-					m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					m_windows[m_numWindows]  = {kInvalidHandle};
+					if (m_numWindows != denseIdx)
+					{
+						m_windows[denseIdx] = handle;
+						m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					}
 				}
 			}
 		}

+ 6 - 2
src/renderer_d3d9.cpp

@@ -1161,8 +1161,12 @@ namespace bgfx { namespace d3d9
 				if (m_numWindows > 1)
 				{
 					FrameBufferHandle handle = m_windows[m_numWindows];
-					m_windows[denseIdx] = handle;
-					m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					m_windows[m_numWindows]  = {kInvalidHandle};
+					if (m_numWindows != denseIdx)
+					{
+						m_windows[denseIdx] = handle;
+						m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					}
 				}
 			}
 		}

+ 6 - 2
src/renderer_gl.cpp

@@ -2881,8 +2881,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 				if (m_numWindows > 1)
 				{
 					FrameBufferHandle handle = m_windows[m_numWindows];
-					m_windows[denseIdx] = handle;
-					m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					m_windows[m_numWindows]  = {kInvalidHandle};
+					if (m_numWindows != denseIdx)
+					{
+						m_windows[denseIdx] = handle;
+						m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					}
 				}
 			}
 		}

+ 6 - 2
src/renderer_mtl.mm

@@ -937,8 +937,12 @@ namespace bgfx { namespace mtl
 				if (m_numWindows > 1)
 				{
 					FrameBufferHandle handle = m_windows[m_numWindows];
-					m_windows[denseIdx] = handle;
-					m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					m_windows[m_numWindows]  = {kInvalidHandle};
+					if (m_numWindows != denseIdx)
+					{
+						m_windows[denseIdx] = handle;
+						m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
+					}
 				}
 			}
 		}