[692] | 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-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #include "OgreGLTextureManager.h"
|
---|
| 27 | #include "OgreRoot.h"
|
---|
| 28 | #include "OgreRenderSystem.h"
|
---|
| 29 | #include "OgreGLRenderTexture.h"
|
---|
| 30 |
|
---|
| 31 | namespace Ogre {
|
---|
| 32 | //-----------------------------------------------------------------------------
|
---|
| 33 | GLTextureManager::GLTextureManager(GLSupport& support)
|
---|
| 34 | : TextureManager(), mGLSupport(support), mWarningTextureID(0)
|
---|
| 35 | {
|
---|
| 36 | // register with group manager
|
---|
| 37 | ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
|
---|
| 38 |
|
---|
| 39 | createWarningTexture();
|
---|
| 40 | }
|
---|
| 41 | //-----------------------------------------------------------------------------
|
---|
| 42 | GLTextureManager::~GLTextureManager()
|
---|
| 43 | {
|
---|
| 44 | // unregister with group manager
|
---|
| 45 | ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
|
---|
| 46 | // Delete warning texture
|
---|
| 47 | glDeleteTextures(1, &mWarningTextureID);
|
---|
| 48 | }
|
---|
| 49 | //-----------------------------------------------------------------------------
|
---|
| 50 | Resource* GLTextureManager::createImpl(const String& name, ResourceHandle handle,
|
---|
| 51 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
| 52 | const NameValuePairList* createParams)
|
---|
| 53 | {
|
---|
| 54 | return new GLTexture(this, name, handle, group, isManual, loader, mGLSupport);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | //-----------------------------------------------------------------------------
|
---|
| 58 | void GLTextureManager::createWarningTexture()
|
---|
| 59 | {
|
---|
| 60 | // Generate warning texture
|
---|
| 61 | size_t width = 8;
|
---|
| 62 | size_t height = 8;
|
---|
| 63 | uint32 *data = new uint32[width*height]; // 0xXXRRGGBB
|
---|
| 64 | // Yellow/black stripes
|
---|
| 65 | for(size_t y=0; y<height; ++y)
|
---|
| 66 | {
|
---|
| 67 | for(size_t x=0; x<width; ++x)
|
---|
| 68 | {
|
---|
| 69 | data[y*width+x] = (((x+y)%8)<4)?0x000000:0xFFFF00;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | // Create GL resource
|
---|
| 73 | glGenTextures(1, &mWarningTextureID);
|
---|
| 74 | glBindTexture(GL_TEXTURE_2D, mWarningTextureID);
|
---|
| 75 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
---|
| 76 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (void*)data);
|
---|
| 77 | // Free memory
|
---|
| 78 | delete [] data;
|
---|
| 79 | }
|
---|
| 80 | //-----------------------------------------------------------------------------
|
---|
| 81 | PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
|
---|
| 82 | {
|
---|
| 83 | // Adjust requested parameters to capabilities
|
---|
| 84 | const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities();
|
---|
| 85 |
|
---|
| 86 | // Check compressed texture support
|
---|
| 87 | // if a compressed format not supported, revert to PF_A8R8G8B8
|
---|
| 88 | if(PixelUtil::isCompressed(format) &&
|
---|
| 89 | !caps->hasCapability( RSC_TEXTURE_COMPRESSION_DXT ))
|
---|
| 90 | {
|
---|
| 91 | return PF_A8R8G8B8;
|
---|
| 92 | }
|
---|
| 93 | // if floating point textures not supported, revert to PF_A8R8G8B8
|
---|
| 94 | if(PixelUtil::isFloatingPoint(format) &&
|
---|
| 95 | !caps->hasCapability( RSC_TEXTURE_FLOAT ))
|
---|
| 96 | {
|
---|
| 97 | return PF_A8R8G8B8;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | // Check if this is a valid rendertarget format
|
---|
| 101 | if( usage & TU_RENDERTARGET )
|
---|
| 102 | {
|
---|
| 103 | /// Get closest supported alternative
|
---|
| 104 | /// If mFormat is supported it's returned
|
---|
| 105 | return GLRTTManager::getSingleton().getSupportedAlternative(format);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | // Supported
|
---|
| 109 | return format;
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | }
|
---|