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 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 9 Permission is hereby granted, free of charge, to any person obtaining a copy 10 of this software and associated documentation files (the "Software"), to deal 11 in the Software without restriction, including without limitation the rights 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 copies of the Software, and to permit persons to whom the Software is 14 furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included in 17 all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 THE SOFTWARE. 26 ----------------------------------------------------------------------------- 27 */ 28 29 #include "OgreGLTextureManager.h" 30 #include "OgreRoot.h" 31 #include "OgreRenderSystem.h" 32 #include "OgreGLCopyingRenderTexture.h" 33 #include "OgreGLTexture.h" 34 #include "OgreGLPixelFormat.h" 35 #include "OgreGLRenderSystem.h" 36 37 namespace Ogre { 38 //----------------------------------------------------------------------------- GLTextureManager(GLRenderSystem * renderSystem)39 GLTextureManager::GLTextureManager(GLRenderSystem* renderSystem) 40 : TextureManager(), mRenderSystem(renderSystem) 41 { 42 // register with group manager 43 ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this); 44 } 45 //----------------------------------------------------------------------------- ~GLTextureManager()46 GLTextureManager::~GLTextureManager() 47 { 48 // unregister with group manager 49 ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType); 50 } 51 //----------------------------------------------------------------------------- createImpl(const String & name,ResourceHandle handle,const String & group,bool isManual,ManualResourceLoader * loader,const NameValuePairList * createParams)52 Resource* GLTextureManager::createImpl(const String& name, ResourceHandle handle, 53 const String& group, bool isManual, ManualResourceLoader* loader, 54 const NameValuePairList* createParams) 55 { 56 return new GLTexture(this, name, handle, group, isManual, loader, mRenderSystem); 57 } 58 59 //----------------------------------------------------------------------------- getNativeFormat(TextureType ttype,PixelFormat format,int usage)60 PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage) 61 { 62 // Adjust requested parameters to capabilities 63 const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities(); 64 65 // Check compressed texture support 66 // if a compressed format not supported, revert to PF_A8R8G8B8 67 if(PixelUtil::isCompressed(format) && 68 !caps->hasCapability( RSC_TEXTURE_COMPRESSION_DXT )) 69 { 70 return PF_BYTE_RGBA; 71 } 72 // if floating point textures not supported, revert to PF_A8R8G8B8 73 if(PixelUtil::isFloatingPoint(format) && 74 !caps->hasCapability( RSC_TEXTURE_FLOAT )) 75 { 76 return PF_BYTE_RGBA; 77 } 78 79 if(GLPixelUtil::getGLInternalFormat(format) == GL_NONE) 80 { 81 return PF_BYTE_RGBA; 82 } 83 84 // Check if this is a valid rendertarget format 85 if( usage & TU_RENDERTARGET ) 86 { 87 /// Get closest supported alternative 88 /// If mFormat is supported it's returned 89 return GLRTTManager::getSingleton().getSupportedAlternative(format); 90 } 91 92 // Supported 93 return format; 94 95 96 } 97 //----------------------------------------------------------------------------- isHardwareFilteringSupported(TextureType ttype,PixelFormat format,int usage,bool preciseFormatOnly)98 bool GLTextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage, 99 bool preciseFormatOnly) 100 { 101 // precise format check 102 if (!TextureManager::isHardwareFilteringSupported(ttype, format, usage, preciseFormatOnly)) 103 return false; 104 105 // Assume non-floating point is supported always 106 if (!PixelUtil::isFloatingPoint(getNativeFormat(ttype, format, usage))) 107 return true; 108 109 // check for floating point extension 110 // note false positives on old harware: 111 // https://www.khronos.org/opengl/wiki/Floating_point_and_mipmapping_and_filtering 112 return mRenderSystem->checkExtension("GL_ARB_texture_float"); 113 } 114 115 } 116