renderer_d3d.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2011-2012 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef __RENDERER_D3D_H__
  6. #define __RENDERER_D3D_H__
  7. #if BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
  8. # include <dxerr.h>
  9. # pragma comment(lib, "dxerr.lib")
  10. # define DX_CHECK_EXTRA_F " (%s): %s"
  11. # define DX_CHECK_EXTRA_ARGS , DXGetErrorString(__hr__), DXGetErrorDescription(__hr__)
  12. #else
  13. # define DX_CHECK_EXTRA_F ""
  14. # define DX_CHECK_EXTRA_ARGS
  15. #endif // BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
  16. namespace bgfx
  17. {
  18. #define _DX_CHECK(_call) \
  19. do { \
  20. HRESULT __hr__ = _call; \
  21. BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \
  22. , (uint32_t)__hr__ \
  23. DX_CHECK_EXTRA_ARGS \
  24. ); \
  25. } while (0)
  26. #if BGFX_CONFIG_DEBUG
  27. # define DX_CHECK(_call) _DX_CHECK(_call)
  28. #else
  29. # define DX_CHECK(_call) _call
  30. #endif // BGFX_CONFIG_DEBUG
  31. #if BGFX_CONFIG_DEBUG
  32. # define DX_RELEASE(_ptr, _expected) \
  33. do { \
  34. if (NULL != _ptr) \
  35. { \
  36. ULONG count = _ptr->Release(); \
  37. BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
  38. _ptr = NULL; \
  39. } \
  40. } while (0)
  41. #else
  42. # define DX_RELEASE(_ptr, _expected) \
  43. do { \
  44. if (NULL != _ptr) \
  45. { \
  46. _ptr->Release(); \
  47. _ptr = NULL; \
  48. } \
  49. } while (0)
  50. #endif // BGFX_CONFIG_DEBUG
  51. } // namespace bgfx
  52. #endif // __RENDERER_D3D_H__