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, 00211 GPU_VENDOR_COUNT = 7 00212 }; 00213 00219 class _OgreExport RenderSystemCapabilities : public RenderSysAlloc 00220 { 00221 00222 public: 00223 00224 typedef std::set<String> ShaderProfiles; 00225 private: 00229 DriverVersion mDriverVersion; 00231 GPUVendor mVendor; 00232 00233 static StringVector msGPUVendorStrings; 00234 static void initVendorStrings(); 00235 00237 ushort mNumWorldMatrices; 00239 ushort mNumTextureUnits; 00241 ushort mStencilBufferBitDepth; 00243 ushort mNumVertexBlendMatrices; 00245 int mCapabilities[CAPS_CATEGORY_COUNT]; 00247 bool mCategoryRelevant[CAPS_CATEGORY_COUNT]; 00249 String mDeviceName; 00251 String mRenderSystemName; 00252 00254 ushort mVertexProgramConstantFloatCount; 00256 ushort mVertexProgramConstantIntCount; 00258 ushort mVertexProgramConstantBoolCount; 00260 ushort mGeometryProgramConstantFloatCount; 00262 ushort mGeometryProgramConstantIntCount; 00264 ushort mGeometryProgramConstantBoolCount; 00266 ushort mFragmentProgramConstantFloatCount; 00268 ushort mFragmentProgramConstantIntCount; 00270 ushort mFragmentProgramConstantBoolCount; 00272 ushort mNumMultiRenderTargets; 00274 Real mMaxPointSize; 00276 bool mNonPOW2TexturesLimited; 00278 ushort mNumVertexTextureUnits; 00280 bool mVertexTextureUnitsShared; 00282 int mGeometryProgramNumOutputVertices; 00283 00284 00286 ShaderProfiles mSupportedShaderProfiles; 00287 00288 public: 00289 RenderSystemCapabilities (); 00290 virtual ~RenderSystemCapabilities (); 00291 00292 virtual size_t calculateSize() const {return 0;} 00293 00295 void setDriverVersion(const DriverVersion& version) 00296 { 00297 mDriverVersion = version; 00298 } 00299 00300 void parseDriverVersionFromString(const String& versionString) 00301 { 00302 DriverVersion version; 00303 version.fromString(versionString); 00304 setDriverVersion(version); 00305 } 00306 00307 00308 DriverVersion getDriverVersion() const 00309 { 00310 return mDriverVersion; 00311 } 00312 00313 GPUVendor getVendor() const 00314 { 00315 return mVendor; 00316 } 00317 00318 void setVendor(GPUVendor v) 00319 { 00320 mVendor = v; 00321 } 00322 00324 void parseVendorFromString(const String& vendorString) 00325 { 00326 setVendor(vendorFromString(vendorString)); 00327 } 00328 00330 static GPUVendor vendorFromString(const String& vendorString); 00332 static String vendorToString(GPUVendor v); 00333 00334 bool isDriverOlderThanVersion(DriverVersion v) const 00335 { 00336 if (mDriverVersion.major < v.major) 00337 return true; 00338 else if (mDriverVersion.major == v.major && 00339 mDriverVersion.minor < v.minor) 00340 return true; 00341 else if (mDriverVersion.major == v.major && 00342 mDriverVersion.minor == v.minor && 00343 mDriverVersion.release < v.release) 00344 return true; 00345 else if (mDriverVersion.major == v.major && 00346 mDriverVersion.minor == v.minor && 00347 mDriverVersion.release == v.release && 00348 mDriverVersion.build < v.build) 00349 return true; 00350 return false; 00351 } 00352 00353 void setNumWorldMatrices(ushort num) 00354 { 00355 mNumWorldMatrices = num; 00356 } 00357 00358 void setNumTextureUnits(ushort num) 00359 { 00360 mNumTextureUnits = num; 00361 } 00362 00363 void setStencilBufferBitDepth(ushort num) 00364 { 00365 mStencilBufferBitDepth = num; 00366 } 00367 00368 void setNumVertexBlendMatrices(ushort num) 00369 { 00370 mNumVertexBlendMatrices = num; 00371 } 00372 00374 void setNumMultiRenderTargets(ushort num) 00375 { 00376 mNumMultiRenderTargets = num; 00377 } 00378 00379 ushort getNumWorldMatrices(void) const 00380 { 00381 return mNumWorldMatrices; 00382 } 00383 00396 ushort getNumTextureUnits(void) const 00397 { 00398 return mNumTextureUnits; 00399 } 00400 00407 ushort getStencilBufferBitDepth(void) const 00408 { 00409 return mStencilBufferBitDepth; 00410 } 00411 00414 ushort getNumVertexBlendMatrices(void) const 00415 { 00416 return mNumVertexBlendMatrices; 00417 } 00418 00420 ushort getNumMultiRenderTargets(void) const 00421 { 00422 return mNumMultiRenderTargets; 00423 } 00424 00427 bool isCapabilityRenderSystemSpecific(const Capabilities c) 00428 { 00429 int cat = c >> OGRE_CAPS_BITSHIFT; 00430 if(cat == CAPS_CATEGORY_GL || cat == CAPS_CATEGORY_D3D9) 00431 return true; 00432 return false; 00433 } 00434 00437 void setCapability(const Capabilities c) 00438 { 00439 int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT; 00440 // zero out the index from the stored capability 00441 mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK); 00442 } 00443 00446 void unsetCapability(const Capabilities c) 00447 { 00448 int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT; 00449 // zero out the index from the stored capability 00450 mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK); 00451 } 00452 00455 bool hasCapability(const Capabilities c) const 00456 { 00457 int index = (CAPS_CATEGORY_MASK & c) >> OGRE_CAPS_BITSHIFT; 00458 // test against 00459 if(mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK)) 00460 { 00461 return true; 00462 } 00463 else 00464 { 00465 return false; 00466 } 00467 } 00468 00471 void addShaderProfile(const String& profile) 00472 { 00473 mSupportedShaderProfiles.insert(profile); 00474 00475 } 00476 00479 void removeShaderProfile(const String& profile) 00480 { 00481 mSupportedShaderProfiles.erase(profile); 00482 } 00483 00486 bool isShaderProfileSupported(const String& profile) const 00487 { 00488 return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile)); 00489 } 00490 00491 00494 const ShaderProfiles& getSupportedShaderProfiles() const 00495 { 00496 return mSupportedShaderProfiles; 00497 } 00498 00499 00501 ushort getVertexProgramConstantFloatCount(void) const 00502 { 00503 return mVertexProgramConstantFloatCount; 00504 } 00506 ushort getVertexProgramConstantIntCount(void) const 00507 { 00508 return mVertexProgramConstantIntCount; 00509 } 00511 ushort getVertexProgramConstantBoolCount(void) const 00512 { 00513 return mVertexProgramConstantBoolCount; 00514 } 00516 ushort getGeometryProgramConstantFloatCount(void) const 00517 { 00518 return mGeometryProgramConstantFloatCount; 00519 } 00521 ushort getGeometryProgramConstantIntCount(void) const 00522 { 00523 return mGeometryProgramConstantIntCount; 00524 } 00526 ushort getGeometryProgramConstantBoolCount(void) const 00527 { 00528 return mGeometryProgramConstantBoolCount; 00529 } 00531 ushort getFragmentProgramConstantFloatCount(void) const 00532 { 00533 return mFragmentProgramConstantFloatCount; 00534 } 00536 ushort getFragmentProgramConstantIntCount(void) const 00537 { 00538 return mFragmentProgramConstantIntCount; 00539 } 00541 ushort getFragmentProgramConstantBoolCount(void) const 00542 { 00543 return mFragmentProgramConstantBoolCount; 00544 } 00545 00547 void setDeviceName(const String& name) 00548 { 00549 mDeviceName = name; 00550 } 00551 00553 String getDeviceName() const 00554 { 00555 return mDeviceName; 00556 } 00557 00559 void setVertexProgramConstantFloatCount(ushort c) 00560 { 00561 mVertexProgramConstantFloatCount = c; 00562 } 00564 void setVertexProgramConstantIntCount(ushort c) 00565 { 00566 mVertexProgramConstantIntCount = c; 00567 } 00569 void setVertexProgramConstantBoolCount(ushort c) 00570 { 00571 mVertexProgramConstantBoolCount = c; 00572 } 00574 void setGeometryProgramConstantFloatCount(ushort c) 00575 { 00576 mGeometryProgramConstantFloatCount = c; 00577 } 00579 void setGeometryProgramConstantIntCount(ushort c) 00580 { 00581 mGeometryProgramConstantIntCount = c; 00582 } 00584 void setGeometryProgramConstantBoolCount(ushort c) 00585 { 00586 mGeometryProgramConstantBoolCount = c; 00587 } 00589 void setFragmentProgramConstantFloatCount(ushort c) 00590 { 00591 mFragmentProgramConstantFloatCount = c; 00592 } 00594 void setFragmentProgramConstantIntCount(ushort c) 00595 { 00596 mFragmentProgramConstantIntCount = c; 00597 } 00599 void setFragmentProgramConstantBoolCount(ushort c) 00600 { 00601 mFragmentProgramConstantBoolCount = c; 00602 } 00604 void setMaxPointSize(Real s) 00605 { 00606 mMaxPointSize = s; 00607 } 00609 Real getMaxPointSize(void) const 00610 { 00611 return mMaxPointSize; 00612 } 00614 void setNonPOW2TexturesLimited(bool l) 00615 { 00616 mNonPOW2TexturesLimited = l; 00617 } 00626 bool getNonPOW2TexturesLimited(void) const 00627 { 00628 return mNonPOW2TexturesLimited; 00629 } 00630 00632 void setNumVertexTextureUnits(ushort n) 00633 { 00634 mNumVertexTextureUnits = n; 00635 } 00637 ushort getNumVertexTextureUnits(void) const 00638 { 00639 return mNumVertexTextureUnits; 00640 } 00642 void setVertexTextureUnitsShared(bool shared) 00643 { 00644 mVertexTextureUnitsShared = shared; 00645 } 00647 bool getVertexTextureUnitsShared(void) const 00648 { 00649 return mVertexTextureUnitsShared; 00650 } 00651 00653 void setGeometryProgramNumOutputVertices(int numOutputVertices) 00654 { 00655 mGeometryProgramNumOutputVertices = numOutputVertices; 00656 } 00658 int getGeometryProgramNumOutputVertices(void) const 00659 { 00660 return mGeometryProgramNumOutputVertices; 00661 } 00662 00664 String getRenderSystemName(void) const 00665 { 00666 return mRenderSystemName; 00667 } 00669 void setRenderSystemName(const String& rs) 00670 { 00671 mRenderSystemName = rs; 00672 } 00673 00675 void setCategoryRelevant(CapabilitiesCategory cat, bool relevant) 00676 { 00677 mCategoryRelevant[cat] = relevant; 00678 } 00679 00681 bool isCategoryRelevant(CapabilitiesCategory cat) 00682 { 00683 return mCategoryRelevant[cat]; 00684 } 00685 00686 00687 00689 void log(Log* pLog); 00690 00691 }; 00692 00693 } // namespace 00694 00695 #endif // __RenderSystemCapabilities__ 00696
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 13:46:42 2009