Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreCommon.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026 #include "OgrePrerequisites.h"
    00027 #include "OgreCommon.h"
    00028 #include "OgreString.h"
    00029
    00030 #include <IL/il.h>
    00031
    00032 namespace Ogre
    00033 {
    00034     PixelFormat ilFormat2OgreFormat( int ImageFormat, int BytesPerPixel )
    00035     {
    00036         switch( BytesPerPixel )
    00037         {
    00038         case 1:
    00039             return PF_L8;
    00040
    00041         case 2:
    00042             switch( ImageFormat )
    00043             {
    00044             case IL_LUMINANCE:
    00045                 return PF_L16;
    00046             case IL_BGR:
    00047                 return PF_B5G6R5;
    00048             case IL_RGB:
    00049                 return PF_R5G6B5;
    00050             case IL_BGRA:
    00051                 return PF_B4G4R4A4;
    00052             case IL_RGBA:
    00053                 return PF_A4R4G4B4;
    00054             }
    00055
    00056         case 3:
    00057             switch( ImageFormat )
    00058             {
    00059             case IL_BGR:
    00060                 return PF_B8G8R8;
    00061             case IL_RGB:
    00062                 return PF_R8G8B8;
    00063             }
    00064
    00065         case 4:
    00066             switch( ImageFormat )
    00067             {
    00068             case IL_BGRA:
    00069                 return PF_B8G8R8A8;
    00070             case IL_RGBA:
    00071                 return PF_A8R8G8B8;
    00072             case IL_DXT1:
    00073                 return PF_DXT1;
    00074             case IL_DXT2:
    00075                 return PF_DXT2;
    00076             case IL_DXT3:
    00077                 return PF_DXT3;
    00078             case IL_DXT4:
    00079                 return PF_DXT4;
    00080             case IL_DXT5:
    00081                 return PF_DXT5;
    00082             }
    00083
    00084         default:
    00085             return PF_UNKNOWN;
    00086         }
    00087
    00088     }
    00089
    00090     std::pair< int, int > OgreFormat2ilFormat( PixelFormat format )
    00091     {
    00092         switch( format )
    00093         {
    00094         case PF_L8:
    00095         case PF_A8:
    00096             return std::pair< int, int >( IL_LUMINANCE, 1 );
    00097         case PF_R5G6B5:
    00098             return std::pair< int, int >( IL_RGB, 2 );
    00099         case PF_B5G6R5:
    00100             return std::pair< int, int >( IL_BGR, 2 );
    00101         case PF_A4R4G4B4:
    00102             return std::pair< int, int >( IL_RGBA, 2 );
    00103         case PF_B4G4R4A4:
    00104             return std::pair< int, int >( IL_BGRA, 2 );
    00105         case PF_R8G8B8:
    00106             return std::pair< int, int >( IL_RGB, 3 );
    00107         case PF_B8G8R8:
    00108             return std::pair< int, int >( IL_BGR, 3 );
    00109         case PF_A8R8G8B8:
    00110             return std::pair< int, int >( IL_RGBA, 4 );
    00111         case PF_B8G8R8A8:
    00112             return std::pair< int, int >( IL_BGRA, 4 );
    00113         case PF_UNKNOWN:
    00114         case PF_A4L4:
    00115         case PF_L4A4:
    00116         case PF_A2R10G10B10:
    00117         case PF_B10G10R10A2:
    00118         default:
    00119             return std::pair< int, int >( -1, -1 );
    00120         }
    00121     }
    00122
    00123     int findCommandLineOpts(int numargs, char** argv, UnaryOptionList& unaryOptList,
    00124         BinaryOptionList& binOptList)
    00125     {
    00126         int startIndex = 1;
    00127         for (int i = 1; i < numargs; ++i)
    00128         {
    00129             String tmp(argv[i]);
    00130             if (StringUtil::startsWith(tmp, "-"))
    00131             {
    00132                 UnaryOptionList::iterator ui = unaryOptList.find(argv[i]);
    00133                 if(ui != unaryOptList.end())
    00134                 {
    00135                     ui->second = true;
    00136                     ++startIndex;
    00137                     continue;
    00138                 }
    00139                 BinaryOptionList::iterator bi = binOptList.find(argv[i]);
    00140                 if(bi != binOptList.end())
    00141                 {
    00142                     bi->second = argv[i+1];
    00143                     startIndex += 2;
    00144                     ++i;
    00145                     continue;
    00146                 }
    00147
    00148                 // Invalid option
    00149                 std::cout << "Invalid option " << tmp << std::endl;
    00150
    00151             }
    00152         }
    00153         return startIndex;
    00154     }
    00155
    00156 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:17 2004