浏览代码

Fixed request screenshot mechanism to work better with Metal.

Бранимир Караџић 5 年之前
父节点
当前提交
597ffc1aae
共有 4 个文件被更改,包括 47 次插入29 次删除
  1. 14 19
      src/bgfx.cpp
  2. 28 9
      src/bgfx_p.h
  3. 4 0
      src/config.h
  4. 1 1
      src/renderer_mtl.mm

+ 14 - 19
src/bgfx.cpp

@@ -2348,9 +2348,20 @@ namespace bgfx
 
 			if (m_rendererInitialized)
 			{
-				BGFX_PROFILER_SCOPE("bgfx/Render submit", 0xff2040ff);
-				m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter);
-				m_flipped = false;
+				{
+					BGFX_PROFILER_SCOPE("bgfx/Render submit", 0xff2040ff);
+					m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter);
+					m_flipped = false;
+				}
+
+				{
+					BGFX_PROFILER_SCOPE("bgfx/Screenshot", 0xff2040ff);
+					for (uint8_t ii = 0, num = m_render->m_numScreenShots; ii < num; ++ii)
+					{
+						const ScreenShot& screenShot = m_render->m_screenShot[ii];
+						m_renderCtx->requestScreenShot(screenShot.handle, screenShot.filePath.getCPtr() );
+					}
+				}
 			}
 
 			{
@@ -3198,22 +3209,6 @@ namespace bgfx
 				}
 				break;
 
-			case CommandBuffer::RequestScreenShot:
-				{
-					BGFX_PROFILER_SCOPE("RequestScreenShot", 0xff2040ff);
-
-					FrameBufferHandle handle;
-					_cmdbuf.read(handle);
-
-					uint16_t len;
-					_cmdbuf.read(len);
-
-					const char* filePath = (const char*)_cmdbuf.skip(len);
-
-					m_renderCtx->requestScreenShot(handle, filePath);
-				}
-				break;
-
 			case CommandBuffer::UpdateViewName:
 				{
 					BGFX_PROFILER_SCOPE("UpdateViewName", 0xff2040ff);

+ 28 - 9
src/bgfx_p.h

@@ -826,7 +826,6 @@ namespace bgfx
 			DestroyFrameBuffer,
 			DestroyUniform,
 			ReadTexture,
-			RequestScreenShot,
 		};
 
 		void resize(uint32_t _capacity = 0)
@@ -1987,6 +1986,12 @@ namespace bgfx
 		RectCache m_rectCache;
 	};
 
+	struct ScreenShot
+	{
+		bx::FilePath filePath;
+		FrameBufferHandle handle;
+	};
+
 	BX_ALIGN_DECL_CACHE_LINE(struct) Frame
 	{
 		Frame()
@@ -2060,7 +2065,7 @@ namespace bgfx
 			m_cmdPre.start();
 			m_cmdPost.start();
 			m_capture = false;
-			m_saveScreenshot = false;
+			m_numScreenShots = 0;
 		}
 
 		void finish()
@@ -2198,7 +2203,9 @@ namespace bgfx
 
 		Resolution m_resolution;
 		uint32_t m_debug;
-		bool m_saveScreenshot;
+
+		ScreenShot m_screenShot[BGFX_CONFIG_MAX_SCREENSHOTS];
+		uint8_t m_numScreenShots;
 
 		CommandBuffer m_cmdPre;
 		CommandBuffer m_cmdPost;
@@ -4804,13 +4811,25 @@ namespace bgfx
 				}
 			}
 
-			m_submit->m_saveScreenshot = true;
+			if (m_submit->m_numScreenShots >= BGFX_CONFIG_MAX_SCREENSHOTS)
+			{
+				BX_TRACE("Only %d screenshots can be requested.", BGFX_CONFIG_MAX_SCREENSHOTS);
+				return;
+			}
 
-			CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RequestScreenShot);
-			uint16_t len = (uint16_t)bx::strLen(_filePath)+1;
-			cmdbuf.write(_handle);
-			cmdbuf.write(len);
-			cmdbuf.write(_filePath, len);
+			for (uint8_t ii = 0, num = m_submit->m_numScreenShots; ii < num; ++ii)
+			{
+				const ScreenShot& screenShot = m_submit->m_screenShot[ii];
+				if (screenShot.handle.idx == _handle.idx)
+				{
+					BX_TRACE("Already requested screenshot on handle %d.", _handle.idx);
+					return;
+				}
+			}
+
+			ScreenShot& screenShot = m_submit->m_screenShot[m_submit->m_numScreenShots++];
+			screenShot.handle = _handle;
+			screenShot.filePath.set(_filePath);
 		}
 
 		BGFX_API_FUNC(void setPaletteColor(uint8_t _index, const float _rgba[4]) )

+ 4 - 0
src/config.h

@@ -367,4 +367,8 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m
 #	define BGFX_CONFIG_PREFER_DISCRETE_GPU BX_PLATFORM_WINDOWS
 #endif // BGFX_CONFIG_PREFER_DISCRETE_GPU
 
+#ifndef BGFX_CONFIG_MAX_SCREENSHOTS
+#	define BGFX_CONFIG_MAX_SCREENSHOTS 4
+#endif // BGFX_CONFIG_MAX_SCREENSHOTS
+
 #endif // BGFX_CONFIG_H_HEADER_GUARD

+ 1 - 1
src/renderer_mtl.mm

@@ -3692,7 +3692,7 @@ namespace bgfx { namespace mtl
 
 		updateResolution(_render->m_resolution);
 
-		if (_render->m_saveScreenshot
+		if (0 != _render->m_numScreenShots
 		||  NULL != m_capture)
 		{
 			if (m_screenshotTarget)