OgreRenderSystemCapabilities.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-2009 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 __RenderSystemCapabilities__
00029 #define __RenderSystemCapabilities__ 1
00030 
00031 // Precompiler options
00032 #include "OgrePrerequisites.h"
00033 #include "OgreString.h"
00034 #include "OgreStringConverter.h"
00035 #include "OgreStringVector.h"
00036 #include "OgreResource.h"
00037 #include "OgreLogManager.h"
00038 
00039 // Because there are more than 32 possible Capabilities, more than 1 int is needed to store them all.
00040 // In fact, an array of integers is used to store capabilities. However all the capabilities are defined in the single
00041 // enum. The only way to know which capabilities should be stored where in the array is to use some of the 32 bits
00042 // to record the category of the capability.  These top few bits are used as an index into mCapabilities array
00043 // The lower bits are used to identify each capability individually by setting 1 bit for each
00044 
00045 // Identifies how many bits are reserved for categories
00046 // NOTE: Although 4 bits (currently) are enough
00047 #define CAPS_CATEGORY_SIZE 4
00048 #define OGRE_CAPS_BITSHIFT (32 - CAPS_CATEGORY_SIZE)
00049 #define CAPS_CATEGORY_MASK (((1 << CAPS_CATEGORY_SIZE) - 1) << OGRE_CAPS_BITSHIFT)
00050 #define OGRE_CAPS_VALUE(cat, val) ((cat << OGRE_CAPS_BITSHIFT) | (1 << val))
00051 
00052 namespace Ogre 
00053 {
00061 
00062     enum CapabilitiesCategory
00063     {
00064         CAPS_CATEGORY_COMMON = 0,
00065         CAPS_CATEGORY_COMMON_2 = 1,
00066         CAPS_CATEGORY_D3D9 = 2,
00067         CAPS_CATEGORY_GL = 3,
00069         CAPS_CATEGORY_COUNT = 4
00070     };
00071 
00074     // a is the category (which can be from 0 to 15)
00075     // b is the value (from 0 to 27)
00076     enum Capabilities
00077     {
00079         RSC_AUTOMIPMAP              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 0),
00080         RSC_BLENDING                = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 1),
00082         RSC_ANISOTROPY              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 2),
00084         RSC_DOT3                    = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 3),
00086         RSC_CUBEMAPPING             = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 4),
00088         RSC_HWSTENCIL               = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 5),
00090         RSC_VBO                     = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 7),
00092         RSC_VERTEX_PROGRAM          = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 9),
00094         RSC_FRAGMENT_PROGRAM        = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 10),
00096         RSC_SCISSOR_TEST            = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 11),
00098         RSC_TWO_SIDED_STENCIL       = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 12),
00100         RSC_STENCIL_WRAP            = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 13),
00102         RSC_HWOCCLUSION             = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 14),
00104         RSC_USER_CLIP_PLANES        = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 15),
00106         RSC_VERTEX_FORMAT_UBYTE4    = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 16),
00108         RSC_INFINITE_FAR_PLANE      = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 17),
00110         RSC_HWRENDER_TO_TEXTURE     = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 18),
00112         RSC_TEXTURE_FLOAT           = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 19),
00114         RSC_NON_POWER_OF_2_TEXTURES = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 20),
00116         RSC_TEXTURE_3D              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 21),
00118         RSC_POINT_SPRITES           = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 22),
00120         RSC_POINT_EXTENDED_PARAMETERS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 23),
00122         RSC_VERTEX_TEXTURE_FETCH = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 24),
00124         RSC_MIPMAP_LOD_BIAS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 25),
00126         RSC_GEOMETRY_PROGRAM = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 26),
00128         RSC_HWRENDER_TO_VERTEX_BUFFER = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 27),
00129 
00131         RSC_TEXTURE_COMPRESSION = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 0),
00133         RSC_TEXTURE_COMPRESSION_DXT = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 1),
00135         RSC_TEXTURE_COMPRESSION_VTC = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 2),
00137         RSC_TEXTURE_COMPRESSION_PVRTC = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 3),
00139         RSC_FIXED_FUNCTION = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 4),
00141         RSC_MRT_DIFFERENT_BIT_DEPTHS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 5),
00143         RSC_ALPHA_TO_COVERAGE = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 6),
00145         RSC_ADVANCED_BLEND_OPERATIONS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 7),
00146 
00147         // ***** DirectX specific caps *****
00149         RSC_PERSTAGECONSTANT = OGRE_CAPS_VALUE(CAPS_CATEGORY_D3D9, 0),
00150 
00151         // ***** GL Specific Caps *****
00153         RSC_GL1_5_NOVBO    = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 1),
00155         RSC_FBO              = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 2),
00157         RSC_FBO_ARB          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 3),
00159         RSC_FBO_ATI          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 4),
00161         RSC_PBUFFER          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 5),
00163         RSC_GL1_5_NOHWOCCLUSION = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 6),
00165         RSC_POINT_EXTENDED_PARAMETERS_ARB = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 7),
00167         RSC_POINT_EXTENDED_PARAMETERS_EXT = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 8),
00168 
00169 
00170     };
00171 
00174     struct _OgreExport DriverVersion 
00175     {
00176         int major;
00177         int minor;
00178         int release;
00179         int build;
00180 
00181         DriverVersion() 
00182         {
00183             major = minor = release = build = 0;
00184         }
00185 
00186         String toString() const 
00187         {
00188             StringUtil::StrStreamType str;
00189             str << major << "." << minor << "." << release << "." << build;
00190             return str.str();
00191         }
00192 
00193         void fromString(const String& versionString)
00194         {
00195             StringVector tokens = StringUtil::split(versionString, ".");
00196             if(!tokens.empty())
00197             {
00198                 major = StringConverter::parseInt(tokens[0]);
00199                 if (tokens.size() > 1)
00200                     minor = StringConverter::parseInt(tokens[1]);
00201                 if (tokens.size() > 2)
00202                     release = StringConverter::parseInt(tokens[2]);
00203                 if (tokens.size() > 3)
00204                     build = StringConverter::parseInt(tokens[3]);
00205             }
00206 
00207         }
00208     };
00209 
00211     enum GPUVendor
00212     {
00213         GPU_UNKNOWN = 0,
00214         GPU_NVIDIA = 1,
00215         GPU_ATI = 2, 
00216         GPU_INTEL = 3,
00217         GPU_S3 = 4,
00218         GPU_MATROX = 5,
00219         GPU_3DLABS = 6,
00220         GPU_SIS = 7,
00221         GPU_IMAGINATION_TECHNOLOGIES = 8,
00222         GPU_APPLE = 9,  // Apple Software Renderer
00223 
00225         GPU_VENDOR_COUNT = 10
00226     };
00227 
00233     class _OgreExport RenderSystemCapabilities : public RenderSysAlloc
00234     {
00235 
00236     public:
00237 
00238         typedef set<String>::type ShaderProfiles;
00239     private:
00243         DriverVersion mDriverVersion;
00245         GPUVendor mVendor;
00246 
00247         static StringVector msGPUVendorStrings;
00248         static void initVendorStrings();
00249 
00251         ushort mNumWorldMatrices;
00253         ushort mNumTextureUnits;
00255         ushort mStencilBufferBitDepth;
00257         ushort mNumVertexBlendMatrices;
00259         int mCapabilities[CAPS_CATEGORY_COUNT];
00261         bool mCategoryRelevant[CAPS_CATEGORY_COUNT];
00263         String mDeviceName;
00265         String mRenderSystemName;
00266 
00268         ushort mVertexProgramConstantFloatCount;           
00270         ushort mVertexProgramConstantIntCount;           
00272         ushort mVertexProgramConstantBoolCount;           
00274         ushort mGeometryProgramConstantFloatCount;           
00276         ushort mGeometryProgramConstantIntCount;           
00278         ushort mGeometryProgramConstantBoolCount;           
00280         ushort mFragmentProgramConstantFloatCount;           
00282         ushort mFragmentProgramConstantIntCount;           
00284         ushort mFragmentProgramConstantBoolCount;
00286         ushort mNumMultiRenderTargets;
00288         Real mMaxPointSize;
00290         bool mNonPOW2TexturesLimited;
00292         ushort mNumVertexTextureUnits;
00294         bool mVertexTextureUnitsShared;
00296         int mGeometryProgramNumOutputVertices;
00297 
00298 
00300         ShaderProfiles mSupportedShaderProfiles;
00301 
00302     public: 
00303         RenderSystemCapabilities ();
00304         virtual ~RenderSystemCapabilities ();
00305 
00306         virtual size_t calculateSize() const {return 0;}
00307 
00309         void setDriverVersion(const DriverVersion& version)
00310         {
00311             mDriverVersion = version;
00312         }
00313 
00314         void parseDriverVersionFromString(const String& versionString)
00315         {
00316             DriverVersion version;
00317             version.fromString(versionString);
00318             setDriverVersion(version);
00319         }
00320 
00321 
00322         DriverVersion getDriverVersion() const
00323         {
00324             return mDriverVersion;
00325         }
00326 
00327         GPUVendor getVendor() const
00328         {
00329             return mVendor;
00330         }
00331 
00332         void setVendor(GPUVendor v)
00333         {
00334             mVendor = v;
00335         }
00336 
00338         void parseVendorFromString(const String& vendorString)
00339         {
00340             setVendor(vendorFromString(vendorString));
00341         }
00342 
00344         static GPUVendor vendorFromString(const String& vendorString);
00346         static String vendorToString(GPUVendor v);
00347 
00348         bool isDriverOlderThanVersion(DriverVersion v) const
00349         {
00350             if (mDriverVersion.major < v.major)
00351                 return true;
00352             else if (mDriverVersion.major == v.major && 
00353                 mDriverVersion.minor < v.minor)
00354                 return true;
00355             else if (mDriverVersion.major == v.major && 
00356                 mDriverVersion.minor == v.minor && 
00357                 mDriverVersion.release < v.release)
00358                 return true;
00359             else if (mDriverVersion.major == v.major && 
00360                 mDriverVersion.minor == v.minor && 
00361                 mDriverVersion.release == v.release &&
00362                 mDriverVersion.build < v.build)
00363                 return true;
00364             return false;
00365         }
00366 
00367         void setNumWorldMatrices(ushort num)
00368         {
00369             mNumWorldMatrices = num;
00370         }
00371 
00372         void setNumTextureUnits(ushort num)
00373         {
00374             mNumTextureUnits = num;
00375         }
00376 
00377         void setStencilBufferBitDepth(ushort num)
00378         {
00379             mStencilBufferBitDepth = num;
00380         }
00381 
00382         void setNumVertexBlendMatrices(ushort num)
00383         {
00384             mNumVertexBlendMatrices = num;
00385         }
00386 
00388         void setNumMultiRenderTargets(ushort num)
00389         {
00390             mNumMultiRenderTargets = num;
00391         }
00392 
00393         ushort getNumWorldMatrices(void) const
00394         { 
00395             return mNumWorldMatrices;
00396         }
00397 
00410         ushort getNumTextureUnits(void) const
00411         {
00412             return mNumTextureUnits;
00413         }
00414 
00421         ushort getStencilBufferBitDepth(void) const
00422         {
00423             return mStencilBufferBitDepth;
00424         }
00425 
00428         ushort getNumVertexBlendMatrices(void) const
00429         {
00430             return mNumVertexBlendMatrices;
00431         }
00432 
00434         ushort getNumMultiRenderTargets(void) const
00435         {
00436             return mNumMultiRenderTargets;
00437         }
00438 
00441         bool isCapabilityRenderSystemSpecific(const Capabilities c)
00442         {
00443             int cat = c >> OGRE_CAPS_BITSHIFT;
00444             if(cat == CAPS_CATEGORY_GL || cat == CAPS_CATEGORY_D3D9)
00445                 return true;
00446             return false;
00447         }
00448 
00451         void setCapability(const Capabilities c) 
00452         { 
00453             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00454             // zero out the index from the stored capability
00455             mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK);
00456         }
00457 
00460         void unsetCapability(const Capabilities c) 
00461         { 
00462             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00463             // zero out the index from the stored capability
00464             mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK);
00465         }
00466 
00469         bool hasCapability(const Capabilities c) const
00470         {
00471             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00472             // test against
00473             if(mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK))
00474             {
00475                 return true;
00476             }
00477             else
00478             {
00479                 return false;
00480             }
00481         }
00482 
00485         void addShaderProfile(const String& profile)
00486         {
00487             mSupportedShaderProfiles.insert(profile);
00488 
00489         }
00490 
00493         void removeShaderProfile(const String& profile)
00494         {
00495             mSupportedShaderProfiles.erase(profile);
00496         }
00497 
00500         bool isShaderProfileSupported(const String& profile) const
00501         {
00502             return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile));
00503         }
00504 
00505 
00508         const ShaderProfiles& getSupportedShaderProfiles() const
00509         {
00510             return mSupportedShaderProfiles;
00511         }
00512 
00513 
00515         ushort getVertexProgramConstantFloatCount(void) const
00516         {
00517             return mVertexProgramConstantFloatCount;           
00518         }
00520         ushort getVertexProgramConstantIntCount(void) const
00521         {
00522             return mVertexProgramConstantIntCount;           
00523         }
00525         ushort getVertexProgramConstantBoolCount(void) const
00526         {
00527             return mVertexProgramConstantBoolCount;           
00528         }
00530         ushort getGeometryProgramConstantFloatCount(void) const
00531         {
00532             return mGeometryProgramConstantFloatCount;           
00533         }
00535         ushort getGeometryProgramConstantIntCount(void) const
00536         {
00537             return mGeometryProgramConstantIntCount;           
00538         }
00540         ushort getGeometryProgramConstantBoolCount(void) const
00541         {
00542             return mGeometryProgramConstantBoolCount;           
00543         }
00545         ushort getFragmentProgramConstantFloatCount(void) const
00546         {
00547             return mFragmentProgramConstantFloatCount;           
00548         }
00550         ushort getFragmentProgramConstantIntCount(void) const
00551         {
00552             return mFragmentProgramConstantIntCount;           
00553         }
00555         ushort getFragmentProgramConstantBoolCount(void) const
00556         {
00557             return mFragmentProgramConstantBoolCount;           
00558         }
00559 
00561         void setDeviceName(const String& name)
00562         {
00563             mDeviceName = name;
00564         }
00565 
00567         String getDeviceName() const
00568         {
00569             return mDeviceName;
00570         }
00571 
00573         void setVertexProgramConstantFloatCount(ushort c)
00574         {
00575             mVertexProgramConstantFloatCount = c;           
00576         }
00578         void setVertexProgramConstantIntCount(ushort c)
00579         {
00580             mVertexProgramConstantIntCount = c;           
00581         }
00583         void setVertexProgramConstantBoolCount(ushort c)
00584         {
00585             mVertexProgramConstantBoolCount = c;           
00586         }
00588         void setGeometryProgramConstantFloatCount(ushort c)
00589         {
00590             mGeometryProgramConstantFloatCount = c;           
00591         }
00593         void setGeometryProgramConstantIntCount(ushort c)
00594         {
00595             mGeometryProgramConstantIntCount = c;           
00596         }
00598         void setGeometryProgramConstantBoolCount(ushort c)
00599         {
00600             mGeometryProgramConstantBoolCount = c;           
00601         }
00603         void setFragmentProgramConstantFloatCount(ushort c)
00604         {
00605             mFragmentProgramConstantFloatCount = c;           
00606         }
00608         void setFragmentProgramConstantIntCount(ushort c)
00609         {
00610             mFragmentProgramConstantIntCount = c;           
00611         }
00613         void setFragmentProgramConstantBoolCount(ushort c)
00614         {
00615             mFragmentProgramConstantBoolCount = c;           
00616         }
00618         void setMaxPointSize(Real s)
00619         {
00620             mMaxPointSize = s;
00621         }
00623         Real getMaxPointSize(void) const
00624         {
00625             return mMaxPointSize;
00626         }
00628         void setNonPOW2TexturesLimited(bool l)
00629         {
00630             mNonPOW2TexturesLimited = l;
00631         }
00640         bool getNonPOW2TexturesLimited(void) const
00641         {
00642             return mNonPOW2TexturesLimited;
00643         }
00644 
00646         void setNumVertexTextureUnits(ushort n)
00647         {
00648             mNumVertexTextureUnits = n;
00649         }
00651         ushort getNumVertexTextureUnits(void) const
00652         {
00653             return mNumVertexTextureUnits;
00654         }
00656         void setVertexTextureUnitsShared(bool shared)
00657         {
00658             mVertexTextureUnitsShared = shared;
00659         }
00661         bool getVertexTextureUnitsShared(void) const
00662         {
00663             return mVertexTextureUnitsShared;
00664         }
00665 
00667         void setGeometryProgramNumOutputVertices(int numOutputVertices)
00668         {
00669             mGeometryProgramNumOutputVertices = numOutputVertices;
00670         }
00672         int getGeometryProgramNumOutputVertices(void) const
00673         {
00674             return mGeometryProgramNumOutputVertices;
00675         }
00676 
00678         String getRenderSystemName(void) const
00679         {
00680             return mRenderSystemName;
00681         }
00683         void setRenderSystemName(const String& rs)
00684         {
00685             mRenderSystemName = rs;
00686         }
00687 
00689         void setCategoryRelevant(CapabilitiesCategory cat, bool relevant)
00690         {
00691             mCategoryRelevant[cat] = relevant;
00692         }
00693 
00695         bool isCategoryRelevant(CapabilitiesCategory cat)
00696         {
00697             return mCategoryRelevant[cat];
00698         }
00699 
00700 
00701 
00703         void log(Log* pLog);
00704 
00705     };
00706 
00709 } // namespace
00710 
00711 #endif // __RenderSystemCapabilities__
00712 

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Dec 31 16:27:13 2009