CCConfiguration.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /****************************************************************************
  2. Copyright (c) 2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2013-2016 Chukong Technologies Inc.
  5. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. #ifndef __CCCONFIGURATION_H__
  24. #define __CCCONFIGURATION_H__
  25. #include <string>
  26. #include "base/CCRef.h"
  27. #include "base/CCValue.h"
  28. #include "platform/CCGL.h"
  29. #include "3d/CCAnimate3D.h"
  30. /**
  31. * @addtogroup base
  32. * @{
  33. */
  34. NS_CC_BEGIN
  35. class EventCustom;
  36. /** @class Configuration
  37. * @brief Configuration contains some openGL variables
  38. * @since v0.99.0
  39. * @js NA
  40. */
  41. class CC_DLL Configuration : public Ref
  42. {
  43. public:
  44. /** Returns a shared instance of Configuration.
  45. *
  46. * @return An autoreleased Configuration object.
  47. */
  48. static Configuration *getInstance();
  49. /** Purge the shared instance of Configuration.
  50. */
  51. static void destroyInstance();
  52. /** @deprecated Use getInstance() instead */
  53. CC_DEPRECATED_ATTRIBUTE static Configuration *sharedConfiguration();
  54. /** @deprecated Use destroyInstance() instead */
  55. CC_DEPRECATED_ATTRIBUTE static void purgeConfiguration();
  56. public:
  57. /** Destructor
  58. * @js NA
  59. * @lua NA
  60. */
  61. virtual ~Configuration();
  62. /** OpenGL Max texture size.
  63. *
  64. * @return The OpenGL Max texture size.
  65. */
  66. int getMaxTextureSize() const;
  67. /** OpenGL Max Modelview Stack Depth.
  68. *
  69. * @return The OpenGL Max Modelview Stack Depth.
  70. */
  71. int getMaxModelviewStackDepth() const;
  72. /** Returns the maximum texture units.
  73. *
  74. * @return The maximum texture units.
  75. * @since v2.0.0
  76. */
  77. int getMaxTextureUnits() const;
  78. /** Whether or not the GPU supports NPOT (Non Power Of Two) textures.
  79. OpenGL ES 2.0 already supports NPOT (iOS).
  80. *
  81. * @return Is true if supports NPOT.
  82. * @since v0.99.2
  83. */
  84. bool supportsNPOT() const;
  85. /** Whether or not PVR Texture Compressed is supported.
  86. *
  87. * @return Is true if supports PVR Texture Compressed.
  88. */
  89. bool supportsPVRTC() const;
  90. /** Whether or not ETC Texture Compressed is supported.
  91. *
  92. *
  93. * @return Is true if supports ETC Texture Compressed.
  94. */
  95. bool supportsETC() const;
  96. /** Whether or not S3TC Texture Compressed is supported.
  97. *
  98. * @return Is true if supports S3TC Texture Compressed.
  99. */
  100. bool supportsS3TC() const;
  101. /** Whether or not ATITC Texture Compressed is supported.
  102. *
  103. * @return Is true if supports ATITC Texture Compressed.
  104. */
  105. bool supportsATITC() const;
  106. /** Whether or not BGRA8888 textures are supported.
  107. *
  108. * @return Is true if supports BGRA8888 textures.
  109. * @since v0.99.2
  110. */
  111. bool supportsBGRA8888() const;
  112. /** Whether or not glDiscardFramebufferEXT is supported.
  113. * @return Is true if supports glDiscardFramebufferEXT.
  114. * @since v0.99.2
  115. */
  116. bool supportsDiscardFramebuffer() const;
  117. /** Whether or not shareable VAOs are supported.
  118. *
  119. * @return Is true if supports shareable VAOs.
  120. * @since v2.0.0
  121. */
  122. bool supportsShareableVAO() const;
  123. /** Whether or not OES_depth24 is supported.
  124. *
  125. * @return Is true if supports OES_depth24.
  126. * @since v2.0.0
  127. */
  128. bool supportsOESDepth24() const;
  129. /** Whether or not OES_Packed_depth_stencil is supported.
  130. *
  131. * @return Is true if supports OES_Packed_depth_stencil.
  132. * @since v2.0.0
  133. */
  134. bool supportsOESPackedDepthStencil() const;
  135. /** Whether or not glMapBuffer() is supported.
  136. *
  137. * On Desktop it returns `true`.
  138. * On Mobile it checks for the extension `GL_OES_mapbuffer`
  139. *
  140. * @return Whether or not `glMapBuffer()` is supported.
  141. * @since v3.13
  142. */
  143. bool supportsMapBuffer() const;
  144. /** Max support directional light in shader, for Sprite3D.
  145. *
  146. * @return Maximum supports directional light in shader.
  147. * @since v3.3
  148. */
  149. int getMaxSupportDirLightInShader() const;
  150. /** Max support point light in shader, for Sprite3D.
  151. *
  152. * @return Maximum supports point light in shader.
  153. * @since v3.3
  154. */
  155. int getMaxSupportPointLightInShader() const;
  156. /** Max support spot light in shader, for Sprite3D.
  157. *
  158. * @return Maximum supports spot light in shader.
  159. * @since v3.3
  160. */
  161. int getMaxSupportSpotLightInShader() const;
  162. /** get 3d animate quality*/
  163. Animate3DQuality getAnimate3DQuality() const;
  164. /** Returns whether or not an OpenGL is supported.
  165. *
  166. * @param searchName A given search name.
  167. * @return Is true if an OpenGL is supported.
  168. */
  169. bool checkForGLExtension(const std::string &searchName) const;
  170. /** Initialize method.
  171. *
  172. * @return Is true if initialize success.
  173. */
  174. bool init();
  175. /** Returns the value of a given key as a double.
  176. *
  177. * @param key A given key.
  178. * @param defaultValue if not find the value, return the defaultValue.
  179. * @return
  180. */
  181. const Value& getValue(const std::string& key, const Value& defaultValue = Value::Null) const;
  182. /** Sets a new key/value pair in the configuration dictionary.
  183. *
  184. * @param key A given key.
  185. * @param value A given value.
  186. */
  187. void setValue(const std::string& key, const Value& value);
  188. /** Returns the Configuration info.
  189. *
  190. * @return The Configuration info.
  191. */
  192. std::string getInfo() const;
  193. /** Gathers OpenGL / GPU information.
  194. */
  195. void gatherGPUInfo();
  196. /** Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added.
  197. *
  198. * @param filename Config file name.
  199. */
  200. void loadConfigFile(const std::string& filename);
  201. static const char* CONFIG_FILE_LOADED;
  202. private:
  203. Configuration(void);
  204. static Configuration *s_sharedConfiguration;
  205. static std::string s_configfile;
  206. protected:
  207. GLint _maxTextureSize;
  208. GLint _maxModelviewStackDepth;
  209. bool _supportsPVRTC;
  210. bool _supportsETC1;
  211. bool _supportsS3TC;
  212. bool _supportsATITC;
  213. bool _supportsNPOT;
  214. bool _supportsBGRA8888;
  215. bool _supportsDiscardFramebuffer;
  216. bool _supportsShareableVAO;
  217. bool _supportsOESMapBuffer;
  218. bool _supportsOESDepth24;
  219. bool _supportsOESPackedDepthStencil;
  220. GLint _maxSamplesAllowed;
  221. GLint _maxTextureUnits;
  222. char * _glExtensions;
  223. int _maxDirLightInShader; //max support directional light in shader
  224. int _maxPointLightInShader; // max support point light in shader
  225. int _maxSpotLightInShader; // max support spot light in shader
  226. Animate3DQuality _animate3DQuality; // animate 3d quality
  227. ValueMap _valueDict;
  228. EventCustom* _loadedEvent;
  229. };
  230. NS_CC_END
  231. // end of base group
  232. /// @}
  233. #endif // __CCCONFIGURATION_H__