# 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __RenderSystemCapabilities__
    00030 #define __RenderSystemCapabilities__ 1
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreString.h"
    00035 #include "OgreStringConverter.h"
    00036 #include "OgreStringVector.h"
    00037 #include "OgreResource.h"
    00038 #include "OgreLogManager.h"
    00039
    00040 // Because there are more than 32 possible Capabilities, more than 1 int is needed to store them all.
    00041 // In fact, an array of integers is used to store capabilities. However all the capabilities are defined in the single
    00042 // enum. The only way to know which capabilities should be stored where in the array is to use some of the 32 bits
    00043 // to record the category of the capability.  These top few bits are used as an index into mCapabilities array
    00044 // The lower bits are used to identify each capability individually by setting 1 bit for each
    00045
    00046 // Identifies how many bits are reserved for categories
    00047 // NOTE: Although 4 bits (currently) are enough
    00048 #define CAPS_CATEGORY_SIZE 4
    00049 #define OGRE_CAPS_BITSHIFT (32 - CAPS_CATEGORY_SIZE)
    00050 #define CAPS_CATEGORY_MASK (((1 << CAPS_CATEGORY_SIZE) - 1) << OGRE_CAPS_BITSHIFT)
    00051 #define OGRE_CAPS_VALUE(cat, val) ((cat << OGRE_CAPS_BITSHIFT) | (1 << val))
    00052
    00053 namespace Ogre
    00054 {
    00056     enum CapabilitiesCategory
    00057     {
    00058         CAPS_CATEGORY_COMMON = 0,
    00059         CAPS_CATEGORY_COMMON_2 = 1,
    00060         CAPS_CATEGORY_D3D9 = 2,
    00061         CAPS_CATEGORY_GL = 3,
    00063         CAPS_CATEGORY_COUNT = 4
    00064     };
    00065
    00068     // a is the category (which can be from 0 to 15)
    00069     // b is the value (from 0 to 27)
    00070     enum Capabilities
    00071     {
    00073         RSC_AUTOMIPMAP              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 0),
    00074         RSC_BLENDING                = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 1),
    00076         RSC_ANISOTROPY              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 2),
    00078         RSC_DOT3                    = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 3),
    00080         RSC_CUBEMAPPING             = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 4),
    00082         RSC_HWSTENCIL               = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 5),
    00084         RSC_VBO                     = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 7),
    00086         RSC_VERTEX_PROGRAM          = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 9),
    00088         RSC_FRAGMENT_PROGRAM        = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 10),
    00090         RSC_SCISSOR_TEST            = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 11),
    00092         RSC_TWO_SIDED_STENCIL       = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 12),
    00094         RSC_STENCIL_WRAP            = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 13),
    00096         RSC_HWOCCLUSION             = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 14),
    00098         RSC_USER_CLIP_PLANES        = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 15),
    00100         RSC_VERTEX_FORMAT_UBYTE4    = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 16),
    00102         RSC_INFINITE_FAR_PLANE      = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 17),
    00104         RSC_HWRENDER_TO_TEXTURE     = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 18),
    00106         RSC_TEXTURE_FLOAT           = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 19),
    00108         RSC_NON_POWER_OF_2_TEXTURES = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 20),
    00110         RSC_TEXTURE_3D              = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 21),
    00112         RSC_POINT_SPRITES           = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 22),
    00114         RSC_POINT_EXTENDED_PARAMETERS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 23),
    00116         RSC_VERTEX_TEXTURE_FETCH = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 24),
    00118         RSC_MIPMAP_LOD_BIAS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 25),
    00120         RSC_GEOMETRY_PROGRAM = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 26),
    00122         RSC_HWRENDER_TO_VERTEX_BUFFER = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON, 27),
    00123
    00125         RSC_TEXTURE_COMPRESSION = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 0),
    00127         RSC_TEXTURE_COMPRESSION_DXT = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 1),
    00129         RSC_TEXTURE_COMPRESSION_VTC = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 2),
    00131         RSC_FIXED_FUNCTION = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 3),
    00133         RSC_MRT_DIFFERENT_BIT_DEPTHS = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 4),
    00135         RSC_ALPHA_TO_COVERAGE = OGRE_CAPS_VALUE(CAPS_CATEGORY_COMMON_2, 5),
    00136
    00137         // ***** DirectX specific caps *****
    00139         RSC_PERSTAGECONSTANT = OGRE_CAPS_VALUE(CAPS_CATEGORY_D3D9, 0),
    00140
    00141         // ***** GL Specific Caps *****
    00143         RSC_GL1_5_NOVBO    = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 1),
    00145         RSC_FBO              = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 2),
    00147         RSC_FBO_ARB          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 3),
    00149         RSC_FBO_ATI          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 4),
    00151         RSC_PBUFFER          = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 5),
    00153         RSC_GL1_5_NOHWOCCLUSION = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 6),
    00155         RSC_POINT_EXTENDED_PARAMETERS_ARB = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 7),
    00157         RSC_POINT_EXTENDED_PARAMETERS_EXT = OGRE_CAPS_VALUE(CAPS_CATEGORY_GL, 8),
    00158
    00159
    00160     };
    00161
    00164     struct _OgreExport DriverVersion
    00165     {
    00166         int major;
    00167         int minor;
    00168         int release;
    00169         int build;
    00170
    00171         DriverVersion()
    00172         {
    00173             major = minor = release = build = 0;
    00174         }
    00175
    00176         String toString() const
    00177         {
    00178             StringUtil::StrStreamType str;
    00179             str << major << "." << minor << "." << release << "." << build;
    00180             return str.str();
    00181         }
    00182
    00183         void fromString(const String& versionString)
    00184         {
    00185             StringVector tokens = StringUtil::split(versionString, ".");
    00186             if(!tokens.empty())
    00187             {
    00188                 major = StringConverter::parseInt(tokens[0]);
    00189                 if (tokens.size() > 1)
    00190                     minor = StringConverter::parseInt(tokens[1]);
    00191                 if (tokens.size() > 2)
    00192                     release = StringConverter::parseInt(tokens[2]);
    00193                 if (tokens.size() > 3)
    00194                     build = StringConverter::parseInt(tokens[3]);
    00195             }
    00196
    00197         }
    00198     };
    00199
    00201     enum GPUVendor
    00202     {
    00203         GPU_UNKNOWN = 0,
    00204         GPU_NVIDIA = 1,
    00205         GPU_ATI = 2,
    00206         GPU_INTEL = 3,
    00207         GPU_S3 = 4,
    00208         GPU_MATROX = 5,
    00209         GPU_3DLABS = 6,
    00210         GPU_SIS = 7,
    00212         GPU_VENDOR_COUNT = 8
    00213     };
    00214
    00220     class _OgreExport RenderSystemCapabilities : public RenderSysAlloc
    00221     {
    00222
    00223     public:
    00224
    00225         typedef std::set<String> ShaderProfiles;
    00226     private:
    00230         DriverVersion mDriverVersion;
    00232         GPUVendor mVendor;
    00233
    00234         static StringVector msGPUVendorStrings;
    00235         static void initVendorStrings();
    00236
    00238         ushort mNumWorldMatrices;
    00240         ushort mNumTextureUnits;
    00242         ushort mStencilBufferBitDepth;
    00244         ushort mNumVertexBlendMatrices;
    00246         int mCapabilities[CAPS_CATEGORY_COUNT];
    00248         bool mCategoryRelevant[CAPS_CATEGORY_COUNT];
    00250         String mDeviceName;
    00252         String mRenderSystemName;
    00253
    00255         ushort mVertexProgramConstantFloatCount;
    00257         ushort mVertexProgramConstantIntCount;
    00259         ushort mVertexProgramConstantBoolCount;
    00261         ushort mGeometryProgramConstantFloatCount;
    00263         ushort mGeometryProgramConstantIntCount;
    00265         ushort mGeometryProgramConstantBoolCount;
    00267         ushort mFragmentProgramConstantFloatCount;
    00269         ushort mFragmentProgramConstantIntCount;
    00271         ushort mFragmentProgramConstantBoolCount;
    00273         ushort mNumMultiRenderTargets;
    00275         Real mMaxPointSize;
    00277         bool mNonPOW2TexturesLimited;
    00279         ushort mNumVertexTextureUnits;
    00281         bool mVertexTextureUnitsShared;
    00283         int mGeometryProgramNumOutputVertices;
    00284
    00285
    00287         ShaderProfiles mSupportedShaderProfiles;
    00288
    00289     public:
    00290         RenderSystemCapabilities ();
    00291         virtual ~RenderSystemCapabilities ();
    00292
    00293         virtual size_t calculateSize() const {return 0;}
    00294
    00296         void setDriverVersion(const DriverVersion& version)
    00297         {
    00298             mDriverVersion = version;
    00299         }
    00300
    00301         void parseDriverVersionFromString(const String& versionString)
    00302         {
    00303             DriverVersion version;
    00304             version.fromString(versionString);
    00305             setDriverVersion(version);
    00306         }
    00307
    00308
    00309         DriverVersion getDriverVersion() const
    00310         {
    00311             return mDriverVersion;
    00312         }
    00313
    00314         GPUVendor getVendor() const
    00315         {
    00316             return mVendor;
    00317         }
    00318
    00319         void setVendor(GPUVendor v)
    00320         {
    00321             mVendor = v;
    00322         }
    00323
    00325         void parseVendorFromString(const String& vendorString)
    00326         {
    00327             setVendor(vendorFromString(vendorString));
    00328         }
    00329
    00331         static GPUVendor vendorFromString(const String& vendorString);
    00333         static String vendorToString(GPUVendor v);
    00334
    00335         bool isDriverOlderThanVersion(DriverVersion v) const
    00336         {
    00337             if (mDriverVersion.major < v.major)
    00338                 return true;
    00339             else if (mDriverVersion.major == v.major &&
    00340                 mDriverVersion.minor < v.minor)
    00341                 return true;
    00342             else if (mDriverVersion.major == v.major &&
    00343                 mDriverVersion.minor == v.minor &&
    00344                 mDriverVersion.release < v.release)
    00345                 return true;
    00346             else if (mDriverVersion.major == v.major &&
    00347                 mDriverVersion.minor == v.minor &&
    00348                 mDriverVersion.release == v.release &&
    00349                 mDriverVersion.build < v.build)
    00350                 return true;
    00351             return false;
    00352         }
    00353
    00354         void setNumWorldMatrices(ushort num)
    00355         {
    00356             mNumWorldMatrices = num;
    00357         }
    00358
    00359         void setNumTextureUnits(ushort num)
    00360         {
    00361             mNumTextureUnits = num;
    00362         }
    00363
    00364         void setStencilBufferBitDepth(ushort num)
    00365         {
    00366             mStencilBufferBitDepth = num;
    00367         }
    00368
    00369         void setNumVertexBlendMatrices(ushort num)
    00370         {
    00371             mNumVertexBlendMatrices = num;
    00372         }
    00373
    00375         void setNumMultiRenderTargets(ushort num)
    00376         {
    00377             mNumMultiRenderTargets = num;
    00378         }
    00379
    00380         ushort getNumWorldMatrices(void) const
    00381         {
    00382             return mNumWorldMatrices;
    00383         }
    00384
    00397         ushort getNumTextureUnits(void) const
    00398         {
    00399             return mNumTextureUnits;
    00400         }
    00401
    00408         ushort getStencilBufferBitDepth(void) const
    00409         {
    00410             return mStencilBufferBitDepth;
    00411         }
    00412
    00415         ushort getNumVertexBlendMatrices(void) const
    00416         {
    00417             return mNumVertexBlendMatrices;
    00418         }
    00419
    00421         ushort getNumMultiRenderTargets(void) const
    00422         {
    00423             return mNumMultiRenderTargets;
    00424         }
    00425
    00428         bool isCapabilityRenderSystemSpecific(const Capabilities c)
    00429         {
    00430             int cat = c >> OGRE_CAPS_BITSHIFT;
    00431             if(cat == CAPS_CATEGORY_GL || cat == CAPS_CATEGORY_D3D9)
    00432                 return true;
    00433             return false;
    00434         }
    00435
    00438         void setCapability(const Capabilities c)
    00439         {
    00440             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00441             // zero out the index from the stored capability
    00442             mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK);
    00443         }
    00444
    00447         void unsetCapability(const Capabilities c)
    00448         {
    00449             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00450             // zero out the index from the stored capability
    00451             mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK);
    00452         }
    00453
    00456         bool hasCapability(const Capabilities c) const
    00457         {
    00458             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00459             // test against
    00460             if(mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK))
    00461             {
    00462                 return true;
    00463             }
    00464             else
    00465             {
    00466                 return false;
    00467             }
    00468         }
    00469
    00472         void addShaderProfile(const String& profile)
    00473         {
    00474             mSupportedShaderProfiles.insert(profile);
    00475
    00476         }
    00477
    00480         void removeShaderProfile(const String& profile)
    00481         {
    00482             mSupportedShaderProfiles.erase(profile);
    00483         }
    00484
    00487         bool isShaderProfileSupported(const String& profile) const
    00488         {
    00489             return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile));
    00490         }
    00491
    00492
    00495         const ShaderProfiles& getSupportedShaderProfiles() const
    00496         {
    00497             return mSupportedShaderProfiles;
    00498         }
    00499
    00500
    00502         ushort getVertexProgramConstantFloatCount(void) const
    00503         {
    00504             return mVertexProgramConstantFloatCount;
    00505         }
    00507         ushort getVertexProgramConstantIntCount(void) const
    00508         {
    00509             return mVertexProgramConstantIntCount;
    00510         }
    00512         ushort getVertexProgramConstantBoolCount(void) const
    00513         {
    00514             return mVertexProgramConstantBoolCount;
    00515         }
    00517         ushort getGeometryProgramConstantFloatCount(void) const
    00518         {
    00519             return mGeometryProgramConstantFloatCount;
    00520         }
    00522         ushort getGeometryProgramConstantIntCount(void) const
    00523         {
    00524             return mGeometryProgramConstantIntCount;
    00525         }
    00527         ushort getGeometryProgramConstantBoolCount(void) const
    00528         {
    00529             return mGeometryProgramConstantBoolCount;
    00530         }
    00532         ushort getFragmentProgramConstantFloatCount(void) const
    00533         {
    00534             return mFragmentProgramConstantFloatCount;
    00535         }
    00537         ushort getFragmentProgramConstantIntCount(void) const
    00538         {
    00539             return mFragmentProgramConstantIntCount;
    00540         }
    00542         ushort getFragmentProgramConstantBoolCount(void) const
    00543         {
    00544             return mFragmentProgramConstantBoolCount;
    00545         }
    00546
    00548         void setDeviceName(const String& name)
    00549         {
    00550             mDeviceName = name;
    00551         }
    00552
    00554         String getDeviceName() const
    00555         {
    00556             return mDeviceName;
    00557         }
    00558
    00560         void setVertexProgramConstantFloatCount(ushort c)
    00561         {
    00562             mVertexProgramConstantFloatCount = c;
    00563         }
    00565         void setVertexProgramConstantIntCount(ushort c)
    00566         {
    00567             mVertexProgramConstantIntCount = c;
    00568         }
    00570         void setVertexProgramConstantBoolCount(ushort c)
    00571         {
    00572             mVertexProgramConstantBoolCount = c;
    00573         }
    00575         void setGeometryProgramConstantFloatCount(ushort c)
    00576         {
    00577             mGeometryProgramConstantFloatCount = c;
    00578         }
    00580         void setGeometryProgramConstantIntCount(ushort c)
    00581         {
    00582             mGeometryProgramConstantIntCount = c;
    00583         }
    00585         void setGeometryProgramConstantBoolCount(ushort c)
    00586         {
    00587             mGeometryProgramConstantBoolCount = c;
    00588         }
    00590         void setFragmentProgramConstantFloatCount(ushort c)
    00591         {
    00592             mFragmentProgramConstantFloatCount = c;
    00593         }
    00595         void setFragmentProgramConstantIntCount(ushort c)
    00596         {
    00597             mFragmentProgramConstantIntCount = c;
    00598         }
    00600         void setFragmentProgramConstantBoolCount(ushort c)
    00601         {
    00602             mFragmentProgramConstantBoolCount = c;
    00603         }
    00605         void setMaxPointSize(Real s)
    00606         {
    00607             mMaxPointSize = s;
    00608         }
    00610         Real getMaxPointSize(void) const
    00611         {
    00612             return mMaxPointSize;
    00613         }
    00615         void setNonPOW2TexturesLimited(bool l)
    00616         {
    00617             mNonPOW2TexturesLimited = l;
    00618         }
    00627         bool getNonPOW2TexturesLimited(void) const
    00628         {
    00629             return mNonPOW2TexturesLimited;
    00630         }
    00631
    00633         void setNumVertexTextureUnits(ushort n)
    00634         {
    00635             mNumVertexTextureUnits = n;
    00636         }
    00638         ushort getNumVertexTextureUnits(void) const
    00639         {
    00640             return mNumVertexTextureUnits;
    00641         }
    00643         void setVertexTextureUnitsShared(bool shared)
    00644         {
    00645             mVertexTextureUnitsShared = shared;
    00646         }
    00648         bool getVertexTextureUnitsShared(void) const
    00649         {
    00650             return mVertexTextureUnitsShared;
    00651         }
    00652
    00654         void setGeometryProgramNumOutputVertices(int numOutputVertices)
    00655         {
    00656             mGeometryProgramNumOutputVertices = numOutputVertices;
    00657         }
    00659         int getGeometryProgramNumOutputVertices(void) const
    00660         {
    00661             return mGeometryProgramNumOutputVertices;
    00662         }
    00663
    00665         String getRenderSystemName(void) const
    00666         {
    00667             return mRenderSystemName;
    00668         }
    00670         void setRenderSystemName(const String& rs)
    00671         {
    00672             mRenderSystemName = rs;
    00673         }
    00674
    00676         void setCategoryRelevant(CapabilitiesCategory cat, bool relevant)
    00677         {
    00678             mCategoryRelevant[cat] = relevant;
    00679         }
    00680
    00682         bool isCategoryRelevant(CapabilitiesCategory cat)
    00683         {
    00684             return mCategoryRelevant[cat];
    00685         }
    00686
    00687
    00688
    00690         void log(Log* pLog);
    00691
    00692     };
    00693
    00694 } // namespace
    00695
    00696 #endif // __RenderSystemCapabilities__
    00697

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