CmGLTextureManager.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "CmGLTextureManager.h"
  25. #include "CmRenderSystem.h"
  26. #include "CmGLRenderTexture.h"
  27. #include "CmGLMultiRenderTexture.h"
  28. namespace CamelotFramework
  29. {
  30. GLTextureManager::GLTextureManager( GLSupport& support)
  31. :TextureManager(), mGLSupport(support)
  32. {
  33. }
  34. GLTextureManager::~GLTextureManager()
  35. {
  36. }
  37. TexturePtr GLTextureManager::createTextureImpl()
  38. {
  39. GLTexture* tex = CM_NEW(GLTexture, PoolAlloc) GLTexture(mGLSupport);
  40. return TexturePtr(tex, &CoreObject::_deleteDelayed<GLTexture, PoolAlloc>);
  41. }
  42. RenderTexturePtr GLTextureManager::createRenderTextureImpl()
  43. {
  44. GLRenderTexture* tex = CM_NEW(GLRenderTexture, PoolAlloc) GLRenderTexture();
  45. return RenderTexturePtr(tex, &CoreObject::_deleteDelayed<GLRenderTexture, PoolAlloc>);
  46. }
  47. MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl()
  48. {
  49. GLMultiRenderTexture* tex = CM_NEW(GLMultiRenderTexture, PoolAlloc) GLMultiRenderTexture();
  50. return MultiRenderTexturePtr(tex, &CoreObject::_deleteDelayed<GLMultiRenderTexture, PoolAlloc>);
  51. }
  52. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
  53. {
  54. // Adjust requested parameters to capabilities
  55. const RenderSystemCapabilities *caps = CamelotFramework::RenderSystem::instancePtr()->getCapabilities();
  56. // Check compressed texture support
  57. // if a compressed format not supported, revert to PF_A8R8G8B8
  58. if(PixelUtil::isCompressed(format) &&
  59. !caps->hasCapability( RSC_TEXTURE_COMPRESSION_DXT ))
  60. {
  61. return PF_A8R8G8B8;
  62. }
  63. // if floating point textures not supported, revert to PF_A8R8G8B8
  64. if(PixelUtil::isFloatingPoint(format) &&
  65. !caps->hasCapability( RSC_TEXTURE_FLOAT ))
  66. {
  67. return PF_A8R8G8B8;
  68. }
  69. // Check if this is a valid rendertarget format
  70. if( usage & TU_RENDERTARGET )
  71. {
  72. /// Get closest supported alternative
  73. /// If mFormat is supported it's returned
  74. return GLRTTManager::instance().getSupportedAlternative(format);
  75. }
  76. // Supported
  77. return format;
  78. }
  79. }