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),
00154 
00155 
00156     };
00157 
00160     struct _OgreExport DriverVersion 
00161     {
00162         int major;
00163         int minor;
00164         int release;
00165         int build;
00166 
00167         DriverVersion() 
00168         {
00169             major = minor = release = build = 0;
00170         }
00171 
00172         String toString() const 
00173         {
00174             StringUtil::StrStreamType str;
00175             str << major << "." << minor << "." << release << "." << build;
00176             return str.str();
00177         }
00178 
00179         void fromString(const String& versionString)
00180         {
00181             StringVector tokens = StringUtil::split(versionString, ".");
00182             if(!tokens.empty())
00183             {
00184                 major = StringConverter::parseInt(tokens[0]);
00185                 if (tokens.size() > 1)
00186                     minor = StringConverter::parseInt(tokens[1]);
00187                 if (tokens.size() > 2)
00188                     release = StringConverter::parseInt(tokens[2]);
00189                 if (tokens.size() > 3)
00190                     build = StringConverter::parseInt(tokens[3]);
00191             }
00192 
00193         }
00194     };
00195 
00197     enum GPUVendor
00198     {
00199         GPU_UNKNOWN = 0,
00200         GPU_NVIDIA = 1,
00201         GPU_ATI = 2, 
00202         GPU_INTEL = 3,
00203         GPU_S3 = 4,
00204         GPU_MATROX = 5,
00205         GPU_3DLABS = 6,
00207         GPU_VENDOR_COUNT = 7
00208     };
00209 
00215     class _OgreExport RenderSystemCapabilities : public RenderSysAlloc
00216     {
00217 
00218     public:
00219 
00220         typedef std::set<String> ShaderProfiles;
00221     private:
00225         DriverVersion mDriverVersion;
00227         GPUVendor mVendor;
00228 
00229         static StringVector msGPUVendorStrings;
00230         static void initVendorStrings();
00231 
00233         ushort mNumWorldMatrices;
00235         ushort mNumTextureUnits;
00237         ushort mStencilBufferBitDepth;
00239         ushort mNumVertexBlendMatrices;
00241         int mCapabilities[CAPS_CATEGORY_COUNT];
00243         bool mCategoryRelevant[CAPS_CATEGORY_COUNT];
00245         String mDeviceName;
00247         String mRenderSystemName;
00248 
00250         ushort mVertexProgramConstantFloatCount;           
00252         ushort mVertexProgramConstantIntCount;           
00254         ushort mVertexProgramConstantBoolCount;           
00256         ushort mGeometryProgramConstantFloatCount;           
00258         ushort mGeometryProgramConstantIntCount;           
00260         ushort mGeometryProgramConstantBoolCount;           
00262         ushort mFragmentProgramConstantFloatCount;           
00264         ushort mFragmentProgramConstantIntCount;           
00266         ushort mFragmentProgramConstantBoolCount;
00268         ushort mNumMultiRenderTargets;
00270         Real mMaxPointSize;
00272         bool mNonPOW2TexturesLimited;
00274         ushort mNumVertexTextureUnits;
00276         bool mVertexTextureUnitsShared;
00278         int mGeometryProgramNumOutputVertices;
00279 
00280 
00282         ShaderProfiles mSupportedShaderProfiles;
00283 
00284     public: 
00285         RenderSystemCapabilities ();
00286         virtual ~RenderSystemCapabilities ();
00287 
00288         virtual size_t calculateSize() const {return 0;}
00289 
00291         void setDriverVersion(const DriverVersion& version)
00292         {
00293             mDriverVersion = version;
00294         }
00295 
00296         void parseDriverVersionFromString(const String& versionString)
00297         {
00298             DriverVersion version;
00299             version.fromString(versionString);
00300             setDriverVersion(version);
00301         }
00302 
00303 
00304         DriverVersion getDriverVersion() const
00305         {
00306             return mDriverVersion;
00307         }
00308 
00309         GPUVendor getVendor() const
00310         {
00311             return mVendor;
00312         }
00313 
00314         void setVendor(GPUVendor v)
00315         {
00316             mVendor = v;
00317         }
00318 
00320         void parseVendorFromString(const String& vendorString)
00321         {
00322             setVendor(vendorFromString(vendorString));
00323         }
00324 
00326         static GPUVendor vendorFromString(const String& vendorString);
00328         static String vendorToString(GPUVendor v);
00329 
00330         bool isDriverOlderThanVersion(DriverVersion v) const
00331         {
00332             if (mDriverVersion.major < v.major)
00333                 return true;
00334             else if (mDriverVersion.major == v.major && 
00335                 mDriverVersion.minor < v.minor)
00336                 return true;
00337             else if (mDriverVersion.major == v.major && 
00338                 mDriverVersion.minor == v.minor && 
00339                 mDriverVersion.release < v.release)
00340                 return true;
00341             else if (mDriverVersion.major == v.major && 
00342                 mDriverVersion.minor == v.minor && 
00343                 mDriverVersion.release == v.release &&
00344                 mDriverVersion.build < v.build)
00345                 return true;
00346             return false;
00347         }
00348 
00349         void setNumWorldMatrices(ushort num)
00350         {
00351             mNumWorldMatrices = num;
00352         }
00353 
00354         void setNumTextureUnits(ushort num)
00355         {
00356             mNumTextureUnits = num;
00357         }
00358 
00359         void setStencilBufferBitDepth(ushort num)
00360         {
00361             mStencilBufferBitDepth = num;
00362         }
00363 
00364         void setNumVertexBlendMatrices(ushort num)
00365         {
00366             mNumVertexBlendMatrices = num;
00367         }
00368 
00370         void setNumMultiRenderTargets(ushort num)
00371         {
00372             mNumMultiRenderTargets = num;
00373         }
00374 
00375         ushort getNumWorldMatrices(void) const
00376         { 
00377             return mNumWorldMatrices;
00378         }
00379 
00392         ushort getNumTextureUnits(void) const
00393         {
00394             return mNumTextureUnits;
00395         }
00396 
00403         ushort getStencilBufferBitDepth(void) const
00404         {
00405             return mStencilBufferBitDepth;
00406         }
00407 
00410         ushort getNumVertexBlendMatrices(void) const
00411         {
00412             return mNumVertexBlendMatrices;
00413         }
00414 
00416         ushort getNumMultiRenderTargets(void) const
00417         {
00418             return mNumMultiRenderTargets;
00419         }
00420 
00423         bool isCapabilityRenderSystemSpecific(const Capabilities c)
00424         {
00425             int cat = c >> OGRE_CAPS_BITSHIFT;
00426             if(cat == CAPS_CATEGORY_GL || cat == CAPS_CATEGORY_D3D9)
00427                 return true;
00428             return false;
00429         }
00430 
00433         void setCapability(const Capabilities c) 
00434         { 
00435             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00436             // zero out the index from the stored capability
00437             mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK);
00438         }
00439 
00442         void unsetCapability(const Capabilities c) 
00443         { 
00444             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00445             // zero out the index from the stored capability
00446             mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK);
00447         }
00448 
00451         bool hasCapability(const Capabilities c) const
00452         {
00453             int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT;
00454             // test against
00455             if(mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK))
00456             {
00457                 return true;
00458             }
00459             else
00460             {
00461                 return false;
00462             }
00463         }
00464 
00467         void addShaderProfile(const String& profile)
00468         {
00469             mSupportedShaderProfiles.insert(profile);
00470 
00471         }
00472 
00475         void removeShaderProfile(const String& profile)
00476         {
00477             mSupportedShaderProfiles.erase(profile);
00478         }
00479 
00482         bool isShaderProfileSupported(const String& profile) const
00483         {
00484             return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile));
00485         }
00486 
00487 
00490         const ShaderProfiles& getSupportedShaderProfiles() const
00491         {
00492             return mSupportedShaderProfiles;
00493         }
00494 
00495 
00497         ushort getVertexProgramConstantFloatCount(void) const
00498         {
00499             return mVertexProgramConstantFloatCount;           
00500         }
00502         ushort getVertexProgramConstantIntCount(void) const
00503         {
00504             return mVertexProgramConstantIntCount;           
00505         }
00507         ushort getVertexProgramConstantBoolCount(void) const
00508         {
00509             return mVertexProgramConstantBoolCount;           
00510         }
00512         ushort getGeometryProgramConstantFloatCount(void) const
00513         {
00514             return mGeometryProgramConstantFloatCount;           
00515         }
00517         ushort getGeometryProgramConstantIntCount(void) const
00518         {
00519             return mGeometryProgramConstantIntCount;           
00520         }
00522         ushort getGeometryProgramConstantBoolCount(void) const
00523         {
00524             return mGeometryProgramConstantBoolCount;           
00525         }
00527         ushort getFragmentProgramConstantFloatCount(void) const
00528         {
00529             return mFragmentProgramConstantFloatCount;           
00530         }
00532         ushort getFragmentProgramConstantIntCount(void) const
00533         {
00534             return mFragmentProgramConstantIntCount;           
00535         }
00537         ushort getFragmentProgramConstantBoolCount(void) const
00538         {
00539             return mFragmentProgramConstantBoolCount;           
00540         }
00541 
00543         void setDeviceName(const String& name)
00544         {
00545             mDeviceName = name;
00546         }
00547 
00549         String getDeviceName() const
00550         {
00551             return mDeviceName;
00552         }
00553 
00555         void setVertexProgramConstantFloatCount(ushort c)
00556         {
00557             mVertexProgramConstantFloatCount = c;           
00558         }
00560         void setVertexProgramConstantIntCount(ushort c)
00561         {
00562             mVertexProgramConstantIntCount = c;           
00563         }
00565         void setVertexProgramConstantBoolCount(ushort c)
00566         {
00567             mVertexProgramConstantBoolCount = c;           
00568         }
00570         void setGeometryProgramConstantFloatCount(ushort c)
00571         {
00572             mGeometryProgramConstantFloatCount = c;           
00573         }
00575         void setGeometryProgramConstantIntCount(ushort c)
00576         {
00577             mGeometryProgramConstantIntCount = c;           
00578         }
00580         void setGeometryProgramConstantBoolCount(ushort c)
00581         {
00582             mGeometryProgramConstantBoolCount = c;           
00583         }
00585         void setFragmentProgramConstantFloatCount(ushort c)
00586         {
00587             mFragmentProgramConstantFloatCount = c;           
00588         }
00590         void setFragmentProgramConstantIntCount(ushort c)
00591         {
00592             mFragmentProgramConstantIntCount = c;           
00593         }
00595         void setFragmentProgramConstantBoolCount(ushort c)
00596         {
00597             mFragmentProgramConstantBoolCount = c;           
00598         }
00600         void setMaxPointSize(Real s)
00601         {
00602             mMaxPointSize = s;
00603         }
00605         Real getMaxPointSize(void) const
00606         {
00607             return mMaxPointSize;
00608         }
00610         void setNonPOW2TexturesLimited(bool l)
00611         {
00612             mNonPOW2TexturesLimited = l;
00613         }
00622         bool getNonPOW2TexturesLimited(void) const
00623         {
00624             return mNonPOW2TexturesLimited;
00625         }
00626 
00628         void setNumVertexTextureUnits(ushort n)
00629         {
00630             mNumVertexTextureUnits = n;
00631         }
00633         ushort getNumVertexTextureUnits(void) const
00634         {
00635             return mNumVertexTextureUnits;
00636         }
00638         void setVertexTextureUnitsShared(bool shared)
00639         {
00640             mVertexTextureUnitsShared = shared;
00641         }
00643         bool getVertexTextureUnitsShared(void) const
00644         {
00645             return mVertexTextureUnitsShared;
00646         }
00647 
00649         void setGeometryProgramNumOutputVertices(int numOutputVertices)
00650         {
00651             mGeometryProgramNumOutputVertices = numOutputVertices;
00652         }
00654         int getGeometryProgramNumOutputVertices(void) const
00655         {
00656             return mGeometryProgramNumOutputVertices;
00657         }
00658 
00660         String getRenderSystemName(void) const
00661         {
00662             return mRenderSystemName;
00663         }
00665         void setRenderSystemName(const String& rs)
00666         {
00667             mRenderSystemName = rs;
00668         }
00669 
00671         void setCategoryRelevant(CapabilitiesCategory cat, bool relevant)
00672         {
00673             mCategoryRelevant[cat] = relevant;
00674         }
00675 
00677         bool isCategoryRelevant(CapabilitiesCategory cat)
00678         {
00679             return mCategoryRelevant[cat];
00680         }
00681 
00682 
00683 
00685         void log(Log* pLog);
00686 
00687     };
00688 
00689 } // namespace
00690 
00691 #endif // __RenderSystemCapabilities__
00692 

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Tue Nov 4 11:02:32 2008