CmGLRenderTexture.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #include "CmGLRenderTexture.h"
  25. #include "CmGLPixelFormat.h"
  26. #include "CmGLHardwarePixelBuffer.h"
  27. namespace CamelotEngine {
  28. //-----------------------------------------------------------------------------
  29. GLRTTManager::~GLRTTManager()
  30. {
  31. }
  32. MultiRenderTarget* GLRTTManager::createMultiRenderTarget(const String & name)
  33. {
  34. CM_EXCEPT(NotImplementedException, "MultiRenderTarget can only be used with GL_EXT_framebuffer_object extension");
  35. }
  36. PixelFormat GLRTTManager::getSupportedAlternative(PixelFormat format)
  37. {
  38. if(checkFormat(format))
  39. return format;
  40. /// Find first alternative
  41. PixelComponentType pct = PixelUtil::getComponentType(format);
  42. switch(pct)
  43. {
  44. case PCT_BYTE: format = PF_A8R8G8B8; break;
  45. case PCT_SHORT: format = PF_SHORT_RGBA; break;
  46. case PCT_FLOAT16: format = PF_FLOAT16_RGBA; break;
  47. case PCT_FLOAT32: format = PF_FLOAT32_RGBA; break;
  48. case PCT_COUNT: break;
  49. }
  50. if(checkFormat(format))
  51. return format;
  52. /// If none at all, return to default
  53. return PF_A8R8G8B8;
  54. }
  55. //-----------------------------------------------------------------------------
  56. GLRenderTexture::GLRenderTexture(const String &name, const GLSurfaceDesc &target, bool writeGamma, UINT32 fsaa):
  57. RenderTexture(target.buffer, target.zoffset)
  58. {
  59. mName = name;
  60. mHwGamma = writeGamma;
  61. mFSAA = fsaa;
  62. }
  63. GLRenderTexture::~GLRenderTexture()
  64. {
  65. }
  66. //-----------------------------------------------------------------------------
  67. GLCopyingRenderTexture::GLCopyingRenderTexture(GLCopyingRTTManager *manager,
  68. const String &name, const GLSurfaceDesc &target, bool writeGamma, UINT32 fsaa):
  69. GLRenderTexture(name, target, writeGamma, fsaa)
  70. {
  71. }
  72. void GLCopyingRenderTexture::getCustomAttribute(const String& name, void* pData)
  73. {
  74. if(name=="TARGET")
  75. {
  76. GLSurfaceDesc &target = *static_cast<GLSurfaceDesc*>(pData);
  77. target.buffer = static_cast<GLHardwarePixelBuffer*>(mBuffer);
  78. target.zoffset = mZOffset;
  79. }
  80. }
  81. //-----------------------------------------------------------------------------
  82. GLCopyingRTTManager::GLCopyingRTTManager()
  83. {
  84. }
  85. GLCopyingRTTManager::~GLCopyingRTTManager()
  86. {
  87. }
  88. RenderTexture *GLCopyingRTTManager::createRenderTexture(const String &name, const GLSurfaceDesc &target,
  89. bool writeGamma, UINT32 fsaa)
  90. {
  91. return new GLCopyingRenderTexture(this, name, target, writeGamma, fsaa);
  92. }
  93. bool GLCopyingRTTManager::checkFormat(PixelFormat format)
  94. {
  95. return true;
  96. }
  97. void GLCopyingRTTManager::bind(RenderTarget *target)
  98. {
  99. // Nothing to do here
  100. }
  101. void GLCopyingRTTManager::unbind(RenderTarget *target)
  102. {
  103. // Copy on unbind
  104. GLSurfaceDesc surface;
  105. surface.buffer = 0;
  106. target->getCustomAttribute("TARGET", &surface);
  107. if(surface.buffer)
  108. static_cast<GLTextureBuffer*>(surface.buffer)->copyFromFramebuffer(surface.zoffset);
  109. }
  110. //---------------------------------------------------------------------------------------------
  111. }