BsWin32Context.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #ifndef _WIN32_WINNT
  4. #define _WIN32_WINNT 0x0500
  5. #endif
  6. #include "Win32/BsWin32Context.h"
  7. #include "Error/BsException.h"
  8. namespace bs { namespace ct
  9. {
  10. Win32Context::Win32Context(HDC hdc, HGLRC glrc, bool ownsContext):
  11. mHDC(hdc), mGlrc(glrc), mOwnsContext(ownsContext)
  12. {
  13. }
  14. Win32Context::~Win32Context()
  15. {
  16. if (mOwnsContext)
  17. releaseContext();
  18. }
  19. void Win32Context::setCurrent(const RenderWindow& window)
  20. {
  21. if(wglMakeCurrent(mHDC, mGlrc) != TRUE)
  22. BS_EXCEPT(RenderingAPIException, "wglMakeCurrent failed: " + translateWGLError());
  23. }
  24. void Win32Context::endCurrent()
  25. {
  26. if(wglMakeCurrent(0, 0) != TRUE)
  27. BS_EXCEPT(RenderingAPIException, "wglMakeCurrent failed: " + translateWGLError());
  28. }
  29. void Win32Context::releaseContext()
  30. {
  31. if (mGlrc != 0)
  32. {
  33. if(wglDeleteContext(mGlrc) != TRUE)
  34. BS_EXCEPT(RenderingAPIException, "wglDeleteContext failed: " + translateWGLError());
  35. mGlrc = 0;
  36. mHDC = 0;
  37. }
  38. }
  39. }}