瀏覽代碼

Added resetView.

Branimir Karadžić 10 年之前
父節點
當前提交
72774fd8e1
共有 3 個文件被更改,包括 33 次插入10 次删除
  1. 8 0
      include/bgfx/bgfx.h
  2. 14 10
      src/bgfx.cpp
  3. 11 0
      src/bgfx_p.h

+ 8 - 0
include/bgfx/bgfx.h

@@ -1688,6 +1688,14 @@ namespace bgfx
 	///
 	void setViewRemap(uint8_t _id = 0, uint8_t _num = UINT8_MAX, const void* _remap = NULL);
 
+	/// Reset all view settings to default.
+	///
+	/// @param[in] _id View id.
+	///
+	/// @attention C99 equivalent is `bgfx_reset_view`.
+	///
+	void resetView(uint8_t _id);
+
 	/// Sets debug marker.
 	///
 	/// @attention C99 equivalent is `bgfx_set_marker`.

+ 14 - 10
src/bgfx.cpp

@@ -1096,17 +1096,9 @@ namespace bgfx
 			m_viewRemap[ii] = uint8_t(ii);
 		}
 
-		memset(m_fb,   0xff, sizeof(m_fb) );
-		memset(m_clear,   0, sizeof(m_clear) );
-		memset(m_rect,    0, sizeof(m_rect) );
-		memset(m_scissor, 0, sizeof(m_scissor) );
-		memset(m_seq,     0, sizeof(m_seq) );
-		memset(m_seqMask, 0, sizeof(m_seqMask) );
-
-		for (uint32_t ii = 0; ii < BX_COUNTOF(m_rect); ++ii)
+		for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
 		{
-			m_rect[ii].m_width  = 1;
-			m_rect[ii].m_height = 1;
+			resetView(uint8_t(ii) );
 		}
 
 		for (uint32_t ii = 0; ii < BX_COUNTOF(m_clearColor); ++ii)
@@ -3125,6 +3117,13 @@ again:
 		s_ctx->setViewRemap(_id, _num, _remap);
 	}
 
+	void resetView(uint8_t _id)
+	{
+		BGFX_CHECK_MAIN_THREAD();
+		BX_CHECK(checkView(_id), "Invalid view id: %d", _id);
+		s_ctx->resetView(_id);
+	}
+
 	void setMarker(const char* _marker)
 	{
 		BGFX_CHECK_MAIN_THREAD();
@@ -3997,6 +3996,11 @@ BGFX_C_API void bgfx_set_view_remap(uint8_t _id, uint8_t _num, const void* _rema
 	bgfx::setViewRemap(_id, _num, _remap);
 }
 
+BGFX_C_API void bgfx_reset_view(uint8_t _id)
+{
+	bgfx::resetView(_id);
+}
+
 BGFX_C_API void bgfx_set_marker(const char* _marker)
 {
 	bgfx::setMarker(_marker);

+ 11 - 0
src/bgfx_p.h

@@ -3397,6 +3397,17 @@ namespace bgfx
 			}
 		}
 
+		BGFX_API_FUNC(void resetView(uint8_t _id) )
+		{
+			setViewRect(_id, 0, 0, 1, 1);
+			setViewScissor(_id, 0, 0, 0, 0);
+			setViewClear(_id, BGFX_CLEAR_NONE, 0, 0.0f, 0);
+			setViewSeq(_id, false);
+			bgfx::FrameBufferHandle invalid = BGFX_INVALID_HANDLE;
+			setViewFrameBuffer(_id, invalid);
+			setViewTransform(_id, NULL, NULL, BGFX_VIEW_NONE, NULL);
+		}
+
 		BGFX_API_FUNC(void setViewRemap(uint8_t _id, uint8_t _num, const void* _remap) )
 		{
 			const uint32_t num = bx::uint32_min(_id + _num, BGFX_CONFIG_MAX_VIEWS) - _id;