OgreCommon.h
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 (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Common_H__
00029 #define __Common_H__
00030 // Common stuff
00031 
00032 #include "OgreString.h"
00033 
00034 #if defined ( OGRE_GCC_VISIBILITY )
00035 #   pragma GCC visibility push(default)
00036 #endif
00037 
00038 #if defined ( OGRE_GCC_VISIBILITY )
00039 #   pragma GCC visibility pop
00040 #endif
00041 
00042 #include "OgreHeaderPrefix.h"
00043 
00044 namespace Ogre {
00052 
00053     uint32 _OgreExport FastHash (const char * data, int len, uint32 hashSoFar = 0);
00055     template <typename T>
00056     uint32 HashCombine (uint32 hashSoFar, const T& data)
00057     {
00058         return FastHash((const char*)&data, sizeof(T), hashSoFar);
00059     }
00060 
00061 
00064     enum CompareFunction
00065     {
00066         CMPF_ALWAYS_FAIL,
00067         CMPF_ALWAYS_PASS,
00068         CMPF_LESS,
00069         CMPF_LESS_EQUAL,
00070         CMPF_EQUAL,
00071         CMPF_NOT_EQUAL,
00072         CMPF_GREATER_EQUAL,
00073         CMPF_GREATER
00074     };
00075 
00078     enum TextureFilterOptions
00079     {
00081         TFO_NONE,
00083         TFO_BILINEAR,
00085         TFO_TRILINEAR,
00087         TFO_ANISOTROPIC
00088     };
00089 
00090     enum FilterType
00091     {
00093         FT_MIN,
00095         FT_MAG,
00097         FT_MIP
00098     };
00100     enum FilterOptions
00101     {
00103         FO_NONE,
00105         FO_POINT,
00107         FO_LINEAR,
00109         FO_ANISOTROPIC
00110     };
00111 
00113     enum ShadeOptions
00114     {
00115         SO_FLAT,
00116         SO_GOURAUD,
00117         SO_PHONG
00118     };
00119 
00121     enum FogMode
00122     {
00124         FOG_NONE,
00126         FOG_EXP,
00128         FOG_EXP2,
00130         FOG_LINEAR
00131     };
00132 
00135     enum CullingMode
00136     {
00138         CULL_NONE = 1,
00140         CULL_CLOCKWISE = 2,
00142         CULL_ANTICLOCKWISE = 3
00143     };
00144 
00150     enum ManualCullingMode
00151     {
00153         MANUAL_CULL_NONE = 1,
00155         MANUAL_CULL_BACK = 2,
00157         MANUAL_CULL_FRONT = 3
00158     };
00159 
00161     enum WaveformType
00162     {
00164         WFT_SINE,
00166         WFT_TRIANGLE,
00168         WFT_SQUARE,
00170         WFT_SAWTOOTH,
00172         WFT_INVERSE_SAWTOOTH,
00175         WFT_PWM
00176     };
00177 
00179     enum PolygonMode
00180     {
00182         PM_POINTS = 1,
00184         PM_WIREFRAME = 2,
00186         PM_SOLID = 3
00187     };
00188 
00190     enum ShadowTechnique
00191     {
00193         SHADOWTYPE_NONE = 0x00,
00196         SHADOWDETAILTYPE_ADDITIVE = 0x01,
00199         SHADOWDETAILTYPE_MODULATIVE = 0x02,
00202         SHADOWDETAILTYPE_INTEGRATED = 0x04,
00205         SHADOWDETAILTYPE_STENCIL = 0x10,
00208         SHADOWDETAILTYPE_TEXTURE = 0x20,
00209         
00216         SHADOWTYPE_STENCIL_MODULATIVE = 0x12,
00224         SHADOWTYPE_STENCIL_ADDITIVE = 0x11,
00229         SHADOWTYPE_TEXTURE_MODULATIVE = 0x22,
00230         
00239         SHADOWTYPE_TEXTURE_ADDITIVE = 0x21,
00240 
00256         SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED = 0x25,
00272         SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED = 0x26
00273     };
00274 
00276     typedef int TrackVertexColourType;
00277     enum TrackVertexColourEnum {
00278         TVC_NONE        = 0x0,
00279         TVC_AMBIENT     = 0x1,        
00280         TVC_DIFFUSE     = 0x2,
00281         TVC_SPECULAR    = 0x4,
00282         TVC_EMISSIVE    = 0x8
00283     };
00284 
00286     enum SortMode
00287     {
00289         SM_DIRECTION,
00291         SM_DISTANCE
00292     };
00293 
00295     enum FrameBufferType {
00296         FBT_COLOUR  = 0x1,
00297         FBT_DEPTH   = 0x2,
00298         FBT_STENCIL = 0x4
00299     };
00300 
00302     enum InstanceManagerFlags
00303     {
00307         IM_USE16BIT     = 0x0001,
00308 
00311         IM_VTFBESTFIT   = 0x0002,
00312 
00315         IM_VTFBONEMATRIXLOOKUP = 0x0004,
00316 
00317         IM_USEBONEDUALQUATERNIONS = 0x0008,
00318 
00320         IM_USEONEWEIGHT = 0x0010,
00321 
00323         IM_FORCEONEWEIGHT = 0x0020,
00324 
00325         IM_USEALL       = IM_USE16BIT|IM_VTFBESTFIT|IM_USEONEWEIGHT
00326     };
00327     
00328     
00331     template <typename T>
00332     class HashedVector
00333     {
00334     public:
00335         typedef std::vector<T, STLAllocator<T, GeneralAllocPolicy> > VectorImpl;
00336     protected:
00337         VectorImpl mList;
00338         mutable uint32 mListHash;
00339         mutable bool mListHashDirty;
00340 
00341         void addToHash(const T& newPtr) const
00342         {
00343             mListHash = FastHash((const char*)&newPtr, sizeof(T), mListHash);
00344         }
00345         void recalcHash() const
00346         {
00347             mListHash = 0;
00348             for (const_iterator i = mList.begin(); i != mList.end(); ++i)
00349                 addToHash(*i);
00350             mListHashDirty = false;
00351             
00352         }
00353 
00354     public:
00355         typedef typename VectorImpl::value_type value_type;
00356         typedef typename VectorImpl::pointer pointer;
00357         typedef typename VectorImpl::reference reference;
00358         typedef typename VectorImpl::const_reference const_reference;
00359         typedef typename VectorImpl::size_type size_type;
00360         typedef typename VectorImpl::difference_type difference_type;
00361         typedef typename VectorImpl::iterator iterator;
00362         typedef typename VectorImpl::const_iterator const_iterator;
00363         typedef typename VectorImpl::reverse_iterator reverse_iterator;
00364         typedef typename VectorImpl::const_reverse_iterator const_reverse_iterator;
00365 
00366         void dirtyHash()
00367         {
00368             mListHashDirty = true;
00369         }
00370         bool isHashDirty() const
00371         {
00372             return mListHashDirty;
00373         }
00374 
00375         iterator begin() 
00376         { 
00377             // we have to assume that hash needs recalculating on non-const
00378             dirtyHash();
00379             return mList.begin(); 
00380         }
00381         iterator end() { return mList.end(); }
00382         const_iterator begin() const { return mList.begin(); }
00383         const_iterator end() const { return mList.end(); }
00384         reverse_iterator rbegin() 
00385         { 
00386             // we have to assume that hash needs recalculating on non-const
00387             dirtyHash();
00388             return mList.rbegin(); 
00389         }
00390         reverse_iterator rend() { return mList.rend(); }
00391         const_reverse_iterator rbegin() const { return mList.rbegin(); }
00392         const_reverse_iterator rend() const { return mList.rend(); }
00393         size_type size() const { return mList.size(); }
00394         size_type max_size() const { return mList.max_size(); }
00395         size_type capacity() const { return mList.capacity(); }
00396         bool empty() const { return mList.empty(); }
00397         reference operator[](size_type n) 
00398         { 
00399             // we have to assume that hash needs recalculating on non-const
00400             dirtyHash();
00401             return mList[n]; 
00402         }
00403         const_reference operator[](size_type n) const { return mList[n]; }
00404         reference at(size_type n) 
00405         { 
00406             // we have to assume that hash needs recalculating on non-const
00407             dirtyHash();
00408             return mList.const_iterator(n); 
00409         }
00410         const_reference at(size_type n) const { return mList.at(n); }
00411         HashedVector() : mListHash(0), mListHashDirty(false) {}
00412         HashedVector(size_type n) : mList(n), mListHash(0), mListHashDirty(n > 0) {}
00413         HashedVector(size_type n, const T& t) : mList(n, t), mListHash(0), mListHashDirty(n > 0) {}
00414         HashedVector(const HashedVector<T>& rhs) 
00415             : mList(rhs.mList), mListHash(rhs.mListHash), mListHashDirty(rhs.mListHashDirty) {}
00416 
00417         template <class InputIterator>
00418         HashedVector(InputIterator a, InputIterator b)
00419             : mList(a, b), mListHashDirty(false)
00420         {
00421             dirtyHash();
00422         }
00423 
00424         ~HashedVector() {}
00425         HashedVector<T>& operator=(const HashedVector<T>& rhs)
00426         {
00427             mList = rhs.mList;
00428             mListHash = rhs.mListHash;
00429             mListHashDirty = rhs.mListHashDirty;
00430             return *this;
00431         }
00432 
00433         void reserve(size_t t) { mList.reserve(t); }
00434         reference front() 
00435         { 
00436             // we have to assume that hash needs recalculating on non-const
00437             dirtyHash();
00438             return mList.front(); 
00439         }
00440         const_reference front() const { return mList.front(); }
00441         reference back()  
00442         { 
00443             // we have to assume that hash needs recalculating on non-const
00444             dirtyHash();
00445             return mList.back(); 
00446         }
00447         const_reference back() const { return mList.back(); }
00448         void push_back(const T& t)
00449         { 
00450             mList.push_back(t);
00451             // Quick progressive hash add
00452             if (!isHashDirty())
00453                 addToHash(t);
00454         }
00455         void pop_back()
00456         {
00457             mList.pop_back();
00458             dirtyHash();
00459         }
00460         void swap(HashedVector<T>& rhs)
00461         {
00462             mList.swap(rhs.mList);
00463             dirtyHash();
00464         }
00465         iterator insert(iterator pos, const T& t)
00466         {
00467             bool recalc = (pos != end());
00468             iterator ret = mList.insert(pos, t);
00469             if (recalc)
00470                 dirtyHash();
00471             else
00472                 addToHash(t);
00473             return ret;
00474         }
00475 
00476         template <class InputIterator>
00477         void insert(iterator pos,
00478             InputIterator f, InputIterator l)
00479         {
00480             mList.insert(pos, f, l);
00481             dirtyHash();
00482         }
00483 
00484         void insert(iterator pos, size_type n, const T& x)
00485         {
00486             mList.insert(pos, n, x);
00487             dirtyHash();
00488         }
00489 
00490         iterator erase(iterator pos)
00491         {
00492             iterator ret = mList.erase(pos);
00493             dirtyHash();
00494             return ret;
00495         }
00496         iterator erase(iterator first, iterator last)
00497         {
00498             iterator ret = mList.erase(first, last);
00499             dirtyHash();
00500             return ret;
00501         }
00502         void clear()
00503         {
00504             mList.clear();
00505             mListHash = 0;
00506             mListHashDirty = false;
00507         }
00508 
00509         void resize(size_type n, const T& t = T())
00510         {
00511             bool recalc = false;
00512             if (n != size())
00513                 recalc = true;
00514 
00515             mList.resize(n, t);
00516             if (recalc)
00517                 dirtyHash();
00518         }
00519 
00520         bool operator==(const HashedVector<T>& b)
00521         { return mListHash == b.mListHash; }
00522 
00523         bool operator<(const HashedVector<T>& b)
00524         { return mListHash < b.mListHash; }
00525 
00526 
00528         uint32 getHash() const 
00529         { 
00530             if (isHashDirty())
00531                 recalcHash();
00532 
00533             return mListHash; 
00534         }
00535     public:
00536 
00537 
00538 
00539     };
00540 
00541     class Light;
00542     typedef HashedVector<Light*> LightList;
00543 
00544 
00545 
00546     typedef map<String, bool>::type UnaryOptionList;
00547     typedef map<String, String>::type BinaryOptionList;
00548 
00550     typedef map<String, String>::type NameValuePairList;
00551 
00553     typedef map<String, String>::type AliasTextureNamePairList;
00554 
00555         template< typename T > struct TRect
00556         {
00557           T left, top, right, bottom;
00558           TRect() : left(0), top(0), right(0), bottom(0) {}
00559           TRect( T const & l, T const & t, T const & r, T const & b )
00560             : left( l ), top( t ), right( r ), bottom( b )
00561           {
00562           }
00563           TRect( TRect const & o )
00564             : left( o.left ), top( o.top ), right( o.right ), bottom( o.bottom )
00565           {
00566           }
00567           TRect & operator=( TRect const & o )
00568           {
00569             left = o.left;
00570             top = o.top;
00571             right = o.right;
00572             bottom = o.bottom;
00573             return *this;
00574           }
00575           T width() const
00576           {
00577             return right - left;
00578           }
00579           T height() const
00580           {
00581             return bottom - top;
00582           }
00583           bool isNull() const
00584           {
00585               return width() == 0 || height() == 0;
00586           }
00587           void setNull()
00588           {
00589               left = right = top = bottom = 0;
00590           }
00591           TRect & merge(const TRect& rhs)
00592           {
00593               if (isNull())
00594               {
00595                   *this = rhs;
00596               }
00597               else if (!rhs.isNull())
00598               {
00599                   left = std::min(left, rhs.left);
00600                   right = std::max(right, rhs.right);
00601                   top = std::min(top, rhs.top);
00602                   bottom = std::max(bottom, rhs.bottom);
00603               }
00604 
00605               return *this;
00606 
00607           }
00608           TRect intersect(const TRect& rhs) const
00609           {
00610               TRect ret;
00611               if (isNull() || rhs.isNull())
00612               {
00613                   // empty
00614                   return ret;
00615               }
00616               else
00617               {
00618                   ret.left = std::max(left, rhs.left);
00619                   ret.right = std::min(right, rhs.right);
00620                   ret.top = std::max(top, rhs.top);
00621                   ret.bottom = std::min(bottom, rhs.bottom);
00622               }
00623 
00624               if (ret.left > ret.right || ret.top > ret.bottom)
00625               {
00626                   // no intersection, return empty
00627                   ret.left = ret.top = ret.right = ret.bottom = 0;
00628               }
00629 
00630               return ret;
00631 
00632           }
00633 
00634         };
00635         template<typename T>
00636         std::ostream& operator<<(std::ostream& o, const TRect<T>& r)
00637         {
00638             o << "TRect<>(l:" << r.left << ", t:" << r.top << ", r:" << r.right << ", b:" << r.bottom << ")";
00639             return o;
00640         }
00641 
00644         typedef TRect<float> FloatRect;
00645 
00649         typedef TRect<Real> RealRect;
00650 
00653         typedef TRect< long > Rect;
00654 
00659         struct Box
00660         {
00661             uint32 left, top, right, bottom, front, back;
00663             Box()
00664                 : left(0), top(0), right(1), bottom(1), front(0), back(1)
00665             {
00666             }
00676             Box( uint32 l, uint32 t, uint32 r, uint32 b ):
00677                 left(l),
00678                 top(t),   
00679                 right(r),
00680                 bottom(b),
00681                 front(0),
00682                 back(1)
00683             {
00684                 assert(right >= left && bottom >= top && back >= front);
00685             }
00697             Box( uint32 l, uint32 t, uint32 ff, uint32 r, uint32 b, uint32 bb ):
00698                 left(l),
00699                 top(t),   
00700                 right(r),
00701                 bottom(b),
00702                 front(ff),
00703                 back(bb)
00704             {
00705                 assert(right >= left && bottom >= top && back >= front);
00706             }
00707             
00709             bool contains(const Box &def) const
00710             {
00711                 return (def.left >= left && def.top >= top && def.front >= front &&
00712                     def.right <= right && def.bottom <= bottom && def.back <= back);
00713             }
00714             
00716             uint32 getWidth() const { return right-left; }
00718             uint32 getHeight() const { return bottom-top; }
00720             uint32 getDepth() const { return back-front; }
00721         };
00722 
00723     
00724     
00736     int _OgreExport findCommandLineOpts(int numargs, char** argv, UnaryOptionList& unaryOptList, 
00737         BinaryOptionList& binOptList);
00738 
00740     enum ClipResult
00741     {
00743         CLIPPED_NONE = 0,
00745         CLIPPED_SOME = 1, 
00747         CLIPPED_ALL = 2
00748     };
00749 
00751     struct RenderWindowDescription
00752     {
00753         String              name;
00754         unsigned int        width;
00755         unsigned int        height;
00756         bool                useFullScreen;
00757         NameValuePairList   miscParams;
00758     };
00759 
00761     typedef vector<RenderWindowDescription>::type RenderWindowDescriptionList;
00762 
00764     typedef vector<RenderWindow*>::type RenderWindowList;
00765 
00768 }
00769 
00770 #include "OgreHeaderSuffix.h"
00771 
00772 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:41