Procházet zdrojové kódy

In debug build assert on texture and frame buffer validation.

Бранимир Караџић před 4 roky
rodič
revize
6a5ab30c6c
2 změnil soubory, kde provedl 49 přidání a 25 odebrání
  1. 25 25
      src/bgfx.cpp
  2. 24 0
      src/bgfx_p.h

+ 25 - 25
src/bgfx.cpp

@@ -4329,20 +4329,6 @@ namespace bgfx
 		s_ctx->destroyProgram(_handle);
 	}
 
-#define BGFX_ERROR_CHECK(_condition, _err, _result, _msg, _format, ...) \
-	if (!BX_IGNORE_C4127(_condition) )                                  \
-	{                                                                   \
-		BX_ERROR_SET(_err, _result, _msg);                              \
-		BX_TRACE("%.*s: '%.*s' - " _format                              \
-			, bxErrorScope.getName().getLength()                        \
-			, bxErrorScope.getName().getPtr()                           \
-			, _err->getMessage().getLength()                            \
-			, _err->getMessage().getPtr()                               \
-			, ##__VA_ARGS__                                             \
-			);                                                          \
-		return;                                                         \
-	}
-
 	void isFrameBufferValid(uint8_t _num, const Attachment* _attachment, bx::Error* _err)
 	{
 		BX_ERROR_SCOPE(_err, "Frame buffer validation");
@@ -4604,9 +4590,10 @@ namespace bgfx
 			  formatSupported
 			, _err
 			, BGFX_ERROR_TEXTURE_VALIDATION
-			, "Texture format is not supported! "
+			, "Texture format is not supported!"
 			  "Use bgfx::isTextureValid to check support for texture format before creating it."
-			, ""
+			, "Texture format: %s."
+			, getName(_format)
 			);
 
 		BGFX_ERROR_CHECK(false
@@ -4615,7 +4602,8 @@ namespace bgfx
 			, _err
 			, BGFX_ERROR_TEXTURE_VALIDATION
 			, "MSAA sampling for this texture format is not supported."
-			, ""
+			, "Texture format: %s."
+			, getName(_format)
 			);
 
 		BGFX_ERROR_CHECK(false
@@ -4628,7 +4616,8 @@ namespace bgfx
 			, _err
 			, BGFX_ERROR_TEXTURE_VALIDATION
 			, "sRGB sampling for this texture format is not supported."
-			, ""
+			, "Texture format: %s."
+			, getName(_format)
 			);
 	}
 
@@ -4672,11 +4661,12 @@ namespace bgfx
 	{
 		bx::Error err;
 		isTextureValid(0, false, _numLayers, _format, _flags, &err);
-		BX_ASSERT(err.isOk(), "%s (layers %d, format %s)"
-			, err.getMessage().getPtr()
-			, _numLayers
-			, getName(_format)
-			);
+		BGFX_ERROR_ASSERT(&err);
+
+		if (!err.isOk() )
+		{
+			return BGFX_INVALID_HANDLE;
+		}
 
 		if (BackbufferRatio::Count != _ratio)
 		{
@@ -4737,7 +4727,12 @@ namespace bgfx
 	{
 		bx::Error err;
 		isTextureValid(_depth, false, 1, _format, _flags, &err);
-		BX_ASSERT(err.isOk(), "%s", err.getMessage().getPtr() );
+		BGFX_ERROR_ASSERT(&err);
+
+		if (!err.isOk() )
+		{
+			return BGFX_INVALID_HANDLE;
+		}
 
 		const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth);
 
@@ -4778,7 +4773,12 @@ namespace bgfx
 	{
 		bx::Error err;
 		isTextureValid(0, true, _numLayers, _format, _flags, &err);
-		BX_ASSERT(err.isOk(), "%s", err.getMessage().getPtr() );
+		BGFX_ERROR_ASSERT(&err);
+
+		if (!err.isOk() )
+		{
+			return BGFX_INVALID_HANDLE;
+		}
 
 		const uint8_t numMips = calcNumMips(_hasMips, _size, _size);
 		_numLayers = bx::max<uint16_t>(_numLayers, 1);

+ 24 - 0
src/bgfx_p.h

@@ -108,6 +108,29 @@ namespace bgfx
 		}                                                                      \
 	BX_MACRO_BLOCK_END
 
+#define BGFX_ERROR_CHECK(_condition, _err, _result, _msg, _format, ...) \
+	if (!BX_IGNORE_C4127(_condition) )                                  \
+	{                                                                   \
+		BX_ERROR_SET(_err, _result, _msg);                              \
+		BX_TRACE("%.*s: 0x%08x '%.*s' - " _format                       \
+			, bxErrorScope.getName().getLength()                        \
+			, bxErrorScope.getName().getPtr()                           \
+			, _err->get().code                                          \
+			, _err->getMessage().getLength()                            \
+			, _err->getMessage().getPtr()                               \
+			, ##__VA_ARGS__                                             \
+			);                                                          \
+		return;                                                         \
+	}
+
+#define BGFX_ERROR_ASSERT(_err)            \
+	BX_ASSERT((_err)->isOk()               \
+		, "ERROR: 0x%08x '%.*s'."          \
+		, (_err)->get().code               \
+		, (_err)->getMessage().getLength() \
+		, (_err)->getMessage().getPtr()    \
+		);
+
 #include <bx/allocator.h>
 #include <bx/bx.h>
 #include <bx/cpu.h>
@@ -4537,6 +4560,7 @@ namespace bgfx
 
 			bx::Error err;
 			isFrameBufferValid(_num, _attachment, &err);
+			BGFX_ERROR_ASSERT(&err);
 
 			if (!err.isOk() )
 			{