Branimir Karadžić 8 anos atrás
pai
commit
b88e566b80
3 arquivos alterados com 13 adições e 13 exclusões
  1. 5 5
      src/bgfx.cpp
  2. 7 8
      src/bgfx_p.h
  3. 1 0
      src/vertexdecl.cpp

+ 5 - 5
src/bgfx.cpp

@@ -2895,7 +2895,7 @@ error:
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BX_CHECK(NULL != _mem, "_mem can't be NULL");
-		BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl.");
+		BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
 		return s_ctx->createVertexBuffer(_mem, _decl, _flags);
 	}
 
@@ -2934,7 +2934,7 @@ error:
 	DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags)
 	{
 		BGFX_CHECK_MAIN_THREAD();
-		BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl.");
+		BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
 		return s_ctx->createDynamicVertexBuffer(_num, _decl, _flags);
 	}
 
@@ -2942,7 +2942,7 @@ error:
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BX_CHECK(NULL != _mem, "_mem can't be NULL");
-		BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl.");
+		BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
 		return s_ctx->createDynamicVertexBuffer(_mem, _decl, _flags);
 	}
 
@@ -2970,7 +2970,7 @@ error:
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BX_CHECK(0 < _num, "Requesting 0 vertices.");
-		BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl.");
+		BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
 		return s_ctx->getAvailTransientVertexBuffer(_num, _decl.m_stride);
 	}
 
@@ -2999,7 +2999,7 @@ error:
 		BX_CHECK(NULL != _tvb, "_tvb can't be NULL");
 		BX_CHECK(0 < _num, "Requesting 0 vertices.");
 		BX_CHECK(UINT16_MAX >= _num, "Requesting %d vertices (max: %d).", _num, UINT16_MAX);
-		BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl.");
+		BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
 		s_ctx->allocTransientVertexBuffer(_tvb, _num, _decl);
 		BX_CHECK(_num == _tvb->size / _decl.m_stride, "Failed to allocate transient vertex buffer (requested %d, available %d). Use bgfx::checkAvailTransient* functions to ensure availability."
 			, _num

+ 7 - 8
src/bgfx_p.h

@@ -134,6 +134,11 @@ namespace bgfx
 #if BGFX_CONFIG_USE_TINYSTL
 namespace bgfx
 {
+	inline bool isValid(const VertexDecl& _decl)
+	{
+		return 0 != _decl.m_stride;
+	}
+
 	struct TinyStlAllocator
 	{
 		static void* static_allocate(size_t _bytes);
@@ -1092,7 +1097,7 @@ namespace bgfx
 		{
 			uint32_t size = BX_ALIGN_16(bx::uint32_max(_size, sizeof(UniformBuffer) ) );
 			void*    data = BX_ALLOC(g_allocator, size);
-			return ::new(data) UniformBuffer(_size);
+			return BX_PLACEMENT_NEW(data, UniformBuffer)(_size);
 		}
 
 		static void destroy(UniformBuffer* _uniformBuffer)
@@ -2478,13 +2483,7 @@ namespace bgfx
 
 		BGFX_API_FUNC(VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) )
 		{
-			VertexBufferHandle handle = BGFX_INVALID_HANDLE;
-
-			BX_WARN(0 != _decl.m_stride, "VertexDecl stride is 0.");
-			if (0 != _decl.m_stride)
-			{
-				handle.idx = m_vertexBufferHandle.alloc();
-			}
+			VertexBufferHandle handle = { m_vertexBufferHandle.alloc() };
 
 			BX_WARN(isValid(handle), "Failed to allocate vertex buffer handle.");
 			if (isValid(handle) )

+ 1 - 0
src/vertexdecl.cpp

@@ -64,6 +64,7 @@ namespace bgfx
 	}
 
 	VertexDecl::VertexDecl()
+		: m_stride(0)
 	{
 		// BK - struct need to have ctor to qualify as non-POD data.
 		// Need this to catch programming errors when serializing struct.