gfxGLWindowTarget.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "windowManager/platformWindow.h"
  23. #include "gfx/gl/gfxGLDevice.h"
  24. #include "gfx/gl/gfxGLWindowTarget.h"
  25. #include "gfx/gl/gfxGLTextureObject.h"
  26. #include "gfx/gl/gfxGLUtils.h"
  27. GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d)
  28. : GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL)
  29. {
  30. win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal);
  31. }
  32. void GFXGLWindowTarget::resetMode()
  33. {
  34. if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen())
  35. {
  36. _teardownCurrentMode();
  37. _setupNewMode();
  38. }
  39. }
  40. void GFXGLWindowTarget::_onAppSignal(WindowId wnd, S32 event)
  41. {
  42. if(event != WindowHidden)
  43. return;
  44. // TODO: Investigate this further.
  45. // Opening and then closing the console results in framerate dropping at an alarming rate down to 3-4 FPS and then
  46. // rebounding to it's usual level. Clearing all the volatile VBs prevents this behavior, but I can't explain why.
  47. // My fear is there is something fundamentally wrong with how we share objects between contexts and this is simply
  48. // masking the issue for the most common case.
  49. static_cast<GFXGLDevice*>(mDevice)->mVolatileVBs.clear();
  50. }
  51. void GFXGLWindowTarget::resolveTo(GFXTextureObject* obj)
  52. {
  53. AssertFatal(dynamic_cast<GFXGLTextureObject*>(obj), "GFXGLTextureTarget::resolveTo - Incorrect type of texture, expected a GFXGLTextureObject");
  54. GFXGLTextureObject* glTexture = static_cast<GFXGLTextureObject*>(obj);
  55. PRESERVE_FRAMEBUFFER();
  56. GLuint dest;
  57. glGenFramebuffersEXT(1, &dest);
  58. glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dest);
  59. glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTexture->getHandle(), 0);
  60. glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
  61. glBlitFramebufferEXT(0, 0, getSize().x, getSize().y,
  62. 0, 0, glTexture->getWidth(), glTexture->getHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
  63. glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
  64. glDeleteFramebuffersEXT(1, &dest);
  65. }