Browse Source

Added frame number as result for frame API call. Added number of draw calls as return value for submit and submitMask API calls.

bkaradzic 12 years ago
parent
commit
ce8f1bbf4d
3 changed files with 92 additions and 37 deletions
  1. 51 7
      include/bgfx.h
  2. 33 23
      src/bgfx.cpp
  3. 8 7
      src/bgfx_p.h

+ 51 - 7
include/bgfx.h

@@ -244,6 +244,7 @@
 #define BGFX_CAPS_TEXTURE_FORMAT_PTC24   UINT64_C(0x0000000000004000)
 #define BGFX_CAPS_TEXTURE_3D             UINT64_C(0x0000000000010000)
 #define BGFX_CAPS_INSTANCING             UINT64_C(0x0000000000020000)
+#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000040000)
 
 ///
 #define BGFX_HANDLE(_name) \
@@ -454,8 +455,8 @@ namespace bgfx
 		/// internally decompresses texture into supported format.
 		uint64_t emulated;
 
-		/// Maximum texture size.
-		uint16_t maxTextureSize;
+		uint16_t maxTextureSize; ///< Maximum texture size.		
+		uint16_t maxDrawCalls;   ///< Maximum draw calls.
 	};
 
 	struct TransientIndexBuffer
@@ -605,7 +606,12 @@ namespace bgfx
 	/// Advance to next frame. When using multithreaded renderer, this call
 	/// just swaps internal buffers, kicks render thread, and returns. In
 	/// singlethreaded renderer this call does frame rendering.
-	void frame();
+	///
+	/// @returns Current frame number. This might be used in conjunction with
+	///   double/multi buffering data outside the library and passing it to 
+	///   library via makeRef calls.
+	///
+	uint32_t frame();
 
 	/// Returns renderer capabilities.
 	const Caps* getCaps();
@@ -903,17 +909,45 @@ namespace bgfx
 	void setViewName(uint8_t _id, const char* _name);
 
 	/// Set view rectangle. Draw primitive outside view will be clipped.
+	///
+	/// @param _id View id.
+	/// @param _x Position x from the left corner of the window.
+	/// @param _y Position y from the top corner of the window.
+	/// @param _width Width of view port region.
+	/// @param _height Height of view port region.
+	///
 	void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
 
 	/// Set view rectangle for multiple views.
+	///
+	/// @param _viewMask Bit mask representing affected views.
+	/// @param _x Position x from the left corner of the window.
+	/// @param _y Position y from the top corner of the window.
+	/// @param _width Width of view port region.
+	/// @param _height Height of view port region.
+	///
 	void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
 
 	/// Set view scissor. Draw primitive outside view will be clipped. When
 	/// _x, _y, _width and _height are set to 0, scissor will be disabled.
+	///
+	/// @param _x Position x from the left corner of the window.
+	/// @param _y Position y from the top corner of the window.
+	/// @param _width Width of scissor region.
+	/// @param _height Height of scissor region.
+	///
 	void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
 
 	/// Set view scissor for multiple views. When _x, _y, _width and _height
 	/// are set to 0, scissor will be disabled.
+	///
+	/// @param _id View id.
+	/// @param _viewMask Bit mask representing affected views.
+	/// @param _x Position x from the left corner of the window.
+	/// @param _y Position y from the top corner of the window.
+	/// @param _width Width of scissor region.
+	/// @param _height Height of scissor region.
+	///
 	void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
 
 	/// Set view clear flags.
@@ -934,7 +968,7 @@ namespace bgfx
 	/// order in which submit calls were called.
 	void setViewSeq(uint8_t _id, bool _enabled);
 
-	/// Set mulitple views into sequential mode.
+	/// Set multiple views into sequential mode.
 	void setViewSeqMask(uint32_t _viewMask, bool _enabled);
 
 	/// Set view render target.
@@ -999,7 +1033,15 @@ namespace bgfx
 	///
 	void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
 
-	/// Set scissor for draw primitive.
+	/// Set scissor for draw primitive. For scissor for all primitives in
+	/// view see setViewScissor.
+	///
+	/// @param _x Position x from the left corner of the window.
+	/// @param _y Position y from the top corner of the window.
+	/// @param _width Width of scissor region.
+	/// @param _height Height of scissor region.
+	/// @returns Scissor cache index.
+	///
 	uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
 
 	/// Set scissor from cache for draw primitive.
@@ -1092,15 +1134,17 @@ namespace bgfx
 	///
 	/// @param _id View id.
 	/// @param _depth Depth for sorting.
+	/// @returns Number of draw calls.
 	///
-	void submit(uint8_t _id, int32_t _depth = 0);
+	uint32_t submit(uint8_t _id, int32_t _depth = 0);
 
 	/// Submit primitive for rendering into multiple views.
 	///
 	/// @param _viewMask Mask to which views to submit draw primitive calls.
 	/// @param _depth Depth for sorting.
+	/// @returns Number of draw calls.
 	///
-	void submitMask(uint32_t _viewMask, int32_t _depth = 0);
+	uint32_t submitMask(uint32_t _viewMask, int32_t _depth = 0);
 
 	/// Discard all previously set state for draw call.
 	void discard();

+ 33 - 23
src/bgfx.cpp

@@ -549,19 +549,19 @@ namespace bgfx
 		return PredefinedUniform::Count;
 	}
 
-	void Frame::submit(uint8_t _id, int32_t _depth)
+	uint32_t Frame::submit(uint8_t _id, int32_t _depth)
 	{
 		if (m_discard)
 		{
 			discard();
-			return;
+			return m_num;
 		}
 
 		if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= m_num
 		|| (0 == m_state.m_numVertices && 0 == m_state.m_numIndices) )
 		{
 			++m_numDropped;
-			return;
+			return m_num;
 		}
 
 		BX_WARN(invalidHandle != m_key.m_program, "Program with invalid handle");
@@ -584,21 +584,23 @@ namespace bgfx
 
 		m_state.clear();
 		m_flags = BGFX_STATE_NONE;
+
+		return m_num;
 	}
 
-	void Frame::submitMask(uint32_t _viewMask, int32_t _depth)
+	uint32_t Frame::submitMask(uint32_t _viewMask, int32_t _depth)
 	{
 		if (m_discard)
 		{
 			discard();
-			return;
+			return m_num;
 		}
 
 		if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= m_num
 		|| (0 == m_state.m_numVertices && 0 == m_state.m_numIndices) )
 		{
 			m_numDropped += bx::uint32_cntbits(_viewMask);
-			return;
+			return m_num;
 		}
 
 		BX_WARN(invalidHandle != m_key.m_program, "Program with invalid handle");
@@ -628,6 +630,8 @@ namespace bgfx
 
 		m_state.clear();
 		m_flags = BGFX_STATE_NONE;
+
+		return m_num;
 	}
 
 	void Frame::sort()
@@ -664,17 +668,21 @@ namespace bgfx
 
 		memset(&g_caps, 0, sizeof(g_caps) );
 		g_caps.rendererType = getRendererType();
+		g_caps.supported = 0
+			| (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
+			;
 		g_caps.emulated = 0
-						| BGFX_CAPS_TEXTURE_FORMAT_BC1
-						| BGFX_CAPS_TEXTURE_FORMAT_BC2
-						| BGFX_CAPS_TEXTURE_FORMAT_BC3
-						| BGFX_CAPS_TEXTURE_FORMAT_BC4
-						| BGFX_CAPS_TEXTURE_FORMAT_BC5
-						| BGFX_CAPS_TEXTURE_FORMAT_ETC1
-						| BGFX_CAPS_TEXTURE_FORMAT_ETC2
-						| BGFX_CAPS_TEXTURE_FORMAT_ETC2A
-						| BGFX_CAPS_TEXTURE_FORMAT_ETC2A1
-						;
+			| BGFX_CAPS_TEXTURE_FORMAT_BC1
+			| BGFX_CAPS_TEXTURE_FORMAT_BC2
+			| BGFX_CAPS_TEXTURE_FORMAT_BC3
+			| BGFX_CAPS_TEXTURE_FORMAT_BC4
+			| BGFX_CAPS_TEXTURE_FORMAT_BC5
+			| BGFX_CAPS_TEXTURE_FORMAT_ETC1
+			| BGFX_CAPS_TEXTURE_FORMAT_ETC2
+			| BGFX_CAPS_TEXTURE_FORMAT_ETC2A
+			| BGFX_CAPS_TEXTURE_FORMAT_ETC2A1
+			;
+		g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
 
 		if (NULL != _allocator)
 		{
@@ -744,10 +752,10 @@ namespace bgfx
 		s_ctx->reset(_width, _height, _flags);
 	}
 
-	void frame()
+	uint32_t frame()
 	{
 		BGFX_CHECK_MAIN_THREAD();
-		s_ctx->frame();
+		return s_ctx->frame();
 	}
 
 	bool renderFrame()
@@ -977,11 +985,13 @@ namespace bgfx
 		}
 	}
 
-	void Context::frame()
+	uint32_t Context::frame()
 	{
 		// wait for render thread to finish
 		renderSemWait();
 		frameNoRenderWait();
+
+		return m_frames;
 	}
 
 	void Context::frameNoRenderWait()
@@ -2203,16 +2213,16 @@ namespace bgfx
 		s_ctx->setTexture(_stage, _sampler, _handle, _depth, _flags);
 	}
 
-	void submit(uint8_t _id, int32_t _depth)
+	uint32_t submit(uint8_t _id, int32_t _depth)
 	{
 		BGFX_CHECK_MAIN_THREAD();
-		s_ctx->submit(_id, _depth);
+		return s_ctx->submit(_id, _depth);
 	}
 
-	void submitMask(uint32_t _viewMask, int32_t _depth)
+	uint32_t submitMask(uint32_t _viewMask, int32_t _depth)
 	{
 		BGFX_CHECK_MAIN_THREAD();
-		s_ctx->submitMask(_viewMask, _depth);
+		return s_ctx->submitMask(_viewMask, _depth);
 	}
 
 	void discard()

+ 8 - 7
src/bgfx_p.h

@@ -1194,8 +1194,8 @@ namespace bgfx
 			m_flags = BGFX_STATE_NONE;
 		}
 
-		void submit(uint8_t _id, int32_t _depth);
-		void submitMask(uint32_t _viewMask, int32_t _depth);
+		uint32_t submit(uint8_t _id, int32_t _depth);
+		uint32_t submitMask(uint32_t _viewMask, int32_t _depth);
 		void sort();
 
 		bool checkAvailTransientIndexBuffer(uint32_t _num)
@@ -2533,14 +2533,14 @@ namespace bgfx
 			m_submit->setTexture(_stage, _sampler, _handle, _depth, _flags);
 		}
 
-		BGFX_API_FUNC(void submit(uint8_t _id, int32_t _depth) )
+		BGFX_API_FUNC(uint32_t submit(uint8_t _id, int32_t _depth) )
 		{
-			m_submit->submit(_id, _depth);
+			return m_submit->submit(_id, _depth);
 		}
 
-		BGFX_API_FUNC(void submitMask(uint32_t _viewMask, int32_t _depth) )
+		BGFX_API_FUNC(uint32_t submitMask(uint32_t _viewMask, int32_t _depth) )
 		{
-			m_submit->submitMask(_viewMask, _depth);
+			return m_submit->submitMask(_viewMask, _depth);
 		}
 
 		BGFX_API_FUNC(void discard() )
@@ -2548,10 +2548,11 @@ namespace bgfx
 			m_submit->discard();
 		}
 
+		BGFX_API_FUNC(uint32_t frame() );
+
 		void dumpViewStats();
 		void freeDynamicBuffers();
 		void freeAllHandles(Frame* _frame);
-		void frame();
 		void frameNoRenderWait();
 		void swap();