# 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         GPU_NOKIA = 10,
    00224
    00226         GPU_VENDOR_COUNT = 11
    00227     };
    00228
    00234     class _OgreExport RenderSystemCapabilities : public RenderSysAlloc
    00235     {
    00236
    00237     public:
    00238
    00239         typedef set<String>::type ShaderProfiles;
    00240     private:
    00244         DriverVersion mDriverVersion;
    00246         GPUVendor mVendor;
    00247
    00248         static StringVector msGPUVendorStrings;
    00249         static void initVendorStrings();
    00250
    00252         ushort mNumWorldMatrices;
    00254         ushort mNumTextureUnits;
    00256         ushort mStencilBufferBitDepth;
    00258         ushort mNumVertexBlendMatrices;
    00260         int mCapabilities[CAPS_CATEGORY_COUNT];
    00262         bool mCategoryRelevant[CAPS_CATEGORY_COUNT];
    00264         String mDeviceName;
    00266         String mRenderSystemName;
    00267
    00269         ushort mVertexProgramConstantFloatCount;
    00271         ushort mVertexProgramConstantIntCount;
    00273         ushort mVertexProgramConstantBoolCount;
    00275         ushort mGeometryProgramConstantFloatCount;
    00277         ushort mGeometryProgramConstantIntCount;
    00279         ushort mGeometryProgramConstantBoolCount;
    00281         ushort mFragmentProgramConstantFloatCount;
    00283         ushort mFragmentProgramConstantIntCount;
    00285         ushort mFragmentProgramConstantBoolCount;
    00287         ushort mNumMultiRenderTargets;
    00289         Real mMaxPointSize;
    00291         bool mNonPOW2TexturesLimited;
    00293         ushort mNumVertexTextureUnits;
    00295         bool mVertexTextureUnitsShared;
    00297         int mGeometryProgramNumOutputVertices;
    00298
    00299
    00301         ShaderProfiles mSupportedShaderProfiles;
    00302
    00303     public:
    00304         RenderSystemCapabilities ();
    00305         virtual ~RenderSystemCapabilities ();
    00306
    00307         virtual size_t calculateSize() const {return 0;}
    00308
    00310         void setDriverVersion(const DriverVersion& version)
    00311         {
    00312             mDriverVersion = version;
    00313         }
    00314
    00315         void parseDriverVersionFromString(const String& versionString)
    00316         {
    00317             DriverVersion version;
    00318             version.fromString(versionString);
    00319             setDriverVersion(version);
    00320         }
    00321
    00322
    00323         DriverVersion getDriverVersion() const
    00324         {
    00325             return mDriverVersion;
    00326         }
    00327
    00328         GPUVendor getVendor() const
    00329         {
    00330             return mVendor;
    00331         }
    00332
    00333         void setVendor(GPUVendor v)
    00334         {
    00335             mVendor = v;
    00336         }
    00337
    00339         void parseVendorFromString(const String& vendorString)
    00340         {
    00341             setVendor(vendorFromString(vendorString));
    00342         }
    00343
    00345         static GPUVendor vendorFromString(const String& vendorString);
    00347         static String vendorToString(GPUVendor v);
    00348
    00349         bool isDriverOlderThanVersion(DriverVersion v) const
    00350         {
    00351             if (mDriverVersion.major < v.major)
    00352                 return true;
    00353             else if (mDriverVersion.major == v.major &&
    00354                 mDriverVersion.minor < v.minor)
    00355                 return true;
    00356             else if (mDriverVersion.major == v.major &&
    00357                 mDriverVersion.minor == v.minor &&
    00358                 mDriverVersion.release < v.release)
    00359                 return true;
    00360             else if (mDriverVersion.major == v.major &&
    00361                 mDriverVersion.minor == v.minor &&
    00362                 mDriverVersion.release == v.release &&
    00363                 mDriverVersion.build < v.build)
    00364                 return true;
    00365             return false;
    00366         }
    00367
    00368         void setNumWorldMatrices(ushort num)
    00369         {
    00370             mNumWorldMatrices = num;
    00371         }
    00372
    00373         void setNumTextureUnits(ushort num)
    00374         {
    00375             mNumTextureUnits = num;
    00376         }
    00377
    00378         void setStencilBufferBitDepth(ushort num)
    00379         {
    00380             mStencilBufferBitDepth = num;
    00381         }
    00382
    00383         void setNumVertexBlendMatrices(ushort num)
    00384         {
    00385             mNumVertexBlendMatrices = num;
    00386         }
    00387
    00389         void setNumMultiRenderTargets(ushort num)
    00390         {
    00391             mNumMultiRenderTargets = num;
    00392         }
    00393
    00394         ushort getNumWorldMatrices(void) const
    00395         {
    00396             return mNumWorldMatrices;
    00397         }
    00398
    00411         ushort getNumTextureUnits(void) const
    00412         {
    00413             return mNumTextureUnits;
    00414         }
    00415
    00422         ushort getStencilBufferBitDepth(void) const
    00423         {
    00424             return mStencilBufferBitDepth;
    00425         }
    00426
    00429         ushort getNumVertexBlendMatrices(void) const
    00430         {
    00431             return mNumVertexBlendMatrices;
    00432         }
    00433
    00435         ushort getNumMultiRenderTargets(void) const
    00436         {
    00437             return mNumMultiRenderTargets;
    00438         }
    00439
    00442         bool isCapabilityRenderSystemSpecific(const Capabilities c)
    00443         {
    00444             int cat = c >> OGRE_CAPS_BITSHIFT;
    00445             if(cat == CAPS_CATEGORY_GL || cat == CAPS_CATEGORY_D3D9)
    00446                 return true;
    00447             return false;
    00448         }
    00449
    00452         void setCapability(const Capabilities c)
    00453         {
    00454             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00455             // zero out the index from the stored capability
    00456             mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK);
    00457         }
    00458
    00461         void unsetCapability(const Capabilities c)
    00462         {
    00463             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00464             // zero out the index from the stored capability
    00465             mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK);
    00466         }
    00467
    00470         bool hasCapability(const Capabilities c) const
    00471         {
    00472             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
    00473             // test against
    00474             if(mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK))
    00475             {
    00476                 return true;
    00477             }
    00478             else
    00479             {
    00480                 return false;
    00481             }
    00482         }
    00483
    00486         void addShaderProfile(const String& profile)
    00487         {
    00488             mSupportedShaderProfiles.insert(profile);
    00489
    00490         }
    00491
    00494         void removeShaderProfile(const String& profile)
    00495         {
    00496             mSupportedShaderProfiles.erase(profile);
    00497         }
    00498
    00501         bool isShaderProfileSupported(const String& profile) const
    00502         {
    00503             return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile));
    00504         }
    00505
    00506
    00509         const ShaderProfiles& getSupportedShaderProfiles() const
    00510         {
    00511             return mSupportedShaderProfiles;
    00512         }
    00513
    00514
    00516         ushort getVertexProgramConstantFloatCount(void) const
    00517         {
    00518             return mVertexProgramConstantFloatCount;
    00519         }
    00521         ushort getVertexProgramConstantIntCount(void) const
    00522         {
    00523             return mVertexProgramConstantIntCount;
    00524         }
    00526         ushort getVertexProgramConstantBoolCount(void) const
    00527         {
    00528             return mVertexProgramConstantBoolCount;
    00529         }
    00531         ushort getGeometryProgramConstantFloatCount(void) const
    00532         {
    00533             return mGeometryProgramConstantFloatCount;
    00534         }
    00536         ushort getGeometryProgramConstantIntCount(void) const
    00537         {
    00538             return mGeometryProgramConstantIntCount;
    00539         }
    00541         ushort getGeometryProgramConstantBoolCount(void) const
    00542         {
    00543             return mGeometryProgramConstantBoolCount;
    00544         }
    00546         ushort getFragmentProgramConstantFloatCount(void) const
    00547         {
    00548             return mFragmentProgramConstantFloatCount;
    00549         }
    00551         ushort getFragmentProgramConstantIntCount(void) const
    00552         {
    00553             return mFragmentProgramConstantIntCount;
    00554         }
    00556         ushort getFragmentProgramConstantBoolCount(void) const
    00557         {
    00558             return mFragmentProgramConstantBoolCount;
    00559         }
    00560
    00562         void setDeviceName(const String& name)
    00563         {
    00564             mDeviceName = name;
    00565         }
    00566
    00568         String getDeviceName() const
    00569         {
    00570             return mDeviceName;
    00571         }
    00572
    00574         void setVertexProgramConstantFloatCount(ushort c)
    00575         {
    00576             mVertexProgramConstantFloatCount = c;
    00577         }
    00579         void setVertexProgramConstantIntCount(ushort c)
    00580         {
    00581             mVertexProgramConstantIntCount = c;
    00582         }
    00584         void setVertexProgramConstantBoolCount(ushort c)
    00585         {
    00586             mVertexProgramConstantBoolCount = c;
    00587         }
    00589         void setGeometryProgramConstantFloatCount(ushort c)
    00590         {
    00591             mGeometryProgramConstantFloatCount = c;
    00592         }
    00594         void setGeometryProgramConstantIntCount(ushort c)
    00595         {
    00596             mGeometryProgramConstantIntCount = c;
    00597         }
    00599         void setGeometryProgramConstantBoolCount(ushort c)
    00600         {
    00601             mGeometryProgramConstantBoolCount = c;
    00602         }
    00604         void setFragmentProgramConstantFloatCount(ushort c)
    00605         {
    00606             mFragmentProgramConstantFloatCount = c;
    00607         }
    00609         void setFragmentProgramConstantIntCount(ushort c)
    00610         {
    00611             mFragmentProgramConstantIntCount = c;
    00612         }
    00614         void setFragmentProgramConstantBoolCount(ushort c)
    00615         {
    00616             mFragmentProgramConstantBoolCount = c;
    00617         }
    00619         void setMaxPointSize(Real s)
    00620         {
    00621             mMaxPointSize = s;
    00622         }
    00624         Real getMaxPointSize(void) const
    00625         {
    00626             return mMaxPointSize;
    00627         }
    00629         void setNonPOW2TexturesLimited(bool l)
    00630         {
    00631             mNonPOW2TexturesLimited = l;
    00632         }
    00641         bool getNonPOW2TexturesLimited(void) const
    00642         {
    00643             return mNonPOW2TexturesLimited;
    00644         }
    00645
    00647         void setNumVertexTextureUnits(ushort n)
    00648         {
    00649             mNumVertexTextureUnits = n;
    00650         }
    00652         ushort getNumVertexTextureUnits(void) const
    00653         {
    00654             return mNumVertexTextureUnits;
    00655         }
    00657         void setVertexTextureUnitsShared(bool shared)
    00658         {
    00659             mVertexTextureUnitsShared = shared;
    00660         }
    00662         bool getVertexTextureUnitsShared(void) const
    00663         {
    00664             return mVertexTextureUnitsShared;
    00665         }
    00666
    00668         void setGeometryProgramNumOutputVertices(int numOutputVertices)
    00669         {
    00670             mGeometryProgramNumOutputVertices = numOutputVertices;
    00671         }
    00673         int getGeometryProgramNumOutputVertices(void) const
    00674         {
    00675             return mGeometryProgramNumOutputVertices;
    00676         }
    00677
    00679         String getRenderSystemName(void) const
    00680         {
    00681             return mRenderSystemName;
    00682         }
    00684         void setRenderSystemName(const String& rs)
    00685         {
    00686             mRenderSystemName = rs;
    00687         }
    00688
    00690         void setCategoryRelevant(CapabilitiesCategory cat, bool relevant)
    00691         {
    00692             mCategoryRelevant[cat] = relevant;
    00693         }
    00694
    00696         bool isCategoryRelevant(CapabilitiesCategory cat)
    00697         {
    00698             return mCategoryRelevant[cat];
    00699         }
    00700
    00701
    00702
    00704         void log(Log* pLog);
    00705
    00706     };
    00707
    00710 } // namespace
    00711
    00712 #endif // __RenderSystemCapabilities__
    00713

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52