Преглед изворни кода

Fixed discard primitive logic.

bkaradzic пре 12 година
родитељ
комит
a09f804ac3
3 измењених фајлова са 31 додато и 2 уклоњено
  1. 16 0
      include/bgfx.h
  2. 8 2
      src/bgfx.cpp
  3. 7 0
      src/bgfx_p.h

+ 16 - 0
include/bgfx.h

@@ -643,6 +643,10 @@ namespace bgfx
 	///   calls.
 	///   calls.
 	/// @param _num Number of indices to allocate.
 	/// @param _num Number of indices to allocate.
 	///
 	///
+	/// NOTE:
+	///   You must call setIndexBuffer after alloc in order to avoid memory
+	///   leak.
+	///
 	void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
 	void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
 
 
 	/// Allocate transient vertex buffer.
 	/// Allocate transient vertex buffer.
@@ -653,9 +657,18 @@ namespace bgfx
 	/// @param _num Number of vertices to allocate.
 	/// @param _num Number of vertices to allocate.
 	/// @param _decl Vertex declaration.
 	/// @param _decl Vertex declaration.
 	///
 	///
+	/// NOTE:
+	///   You must call setVertexBuffer after alloc in order to avoid memory
+	///   leak.
+	///
 	void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
 	void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
 
 
 	/// Allocate instance data buffer.
 	/// Allocate instance data buffer.
+	///
+	/// NOTE:
+	///   You must call setInstanceDataBuffer after alloc in order to avoid
+	///   memory leak.
+	///
 	const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
 	const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
 
 
 	/// Create vertex shader from memory buffer.
 	/// Create vertex shader from memory buffer.
@@ -951,6 +964,9 @@ namespace bgfx
 	///
 	///
 	void submitMask(uint32_t _viewMask, int32_t _depth = 0);
 	void submitMask(uint32_t _viewMask, int32_t _depth = 0);
 
 
+	/// Discard all previously set state for draw call.
+	void discard();
+
 	/// Request screen shot.
 	/// Request screen shot.
 	void saveScreenShot(const char* _filePath);
 	void saveScreenShot(const char* _filePath);
 
 

+ 8 - 2
src/bgfx.cpp

@@ -529,7 +529,7 @@ namespace bgfx
 	{
 	{
 		if (m_discard)
 		if (m_discard)
 		{
 		{
-			m_discard = false;
+			discard();
 			return;
 			return;
 		}
 		}
 
 
@@ -566,7 +566,7 @@ namespace bgfx
 	{
 	{
 		if (m_discard)
 		if (m_discard)
 		{
 		{
-			m_discard = false;
+			discard();
 			return;
 			return;
 		}
 		}
 
 
@@ -1496,6 +1496,12 @@ namespace bgfx
 		s_ctx.m_submit->submitMask(_viewMask, _depth);
 		s_ctx.m_submit->submitMask(_viewMask, _depth);
 	}
 	}
 
 
+	void discard()
+	{
+		BGFX_CHECK_MAIN_THREAD();
+		s_ctx.m_submit->discard();
+	}
+
 	void saveScreenShot(const char* _filePath)
 	void saveScreenShot(const char* _filePath)
 	{
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_MAIN_THREAD();

+ 7 - 0
src/bgfx_p.h

@@ -1153,6 +1153,13 @@ namespace bgfx
 			}
 			}
 		}
 		}
 
 
+		void discard()
+		{
+			m_discard = false;
+			m_state.clear();
+			m_flags = BGFX_STATE_NONE;
+		}
+
 		void submit(uint8_t _id, int32_t _depth);
 		void submit(uint8_t _id, int32_t _depth);
 		void submitMask(uint32_t _viewMask, int32_t _depth);
 		void submitMask(uint32_t _viewMask, int32_t _depth);
 		void sort();
 		void sort();