From 836a61cd3ed6df040e6e26a151111f2a154f3a86 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 22 May 2013 13:00:34 -0700 Subject: [PATCH] CCConfiguration extension (rewritten) rewritten to prevent conflicts while rebasing --- cocos2dx/CCConfiguration.cpp | 199 ++++++++++++++++++++++++++----- cocos2dx/CCConfiguration.h | 85 +++++++------ cocos2dx/CCDirector.cpp | 18 ++- cocos2dx/cocoa/CCDataVisitor.cpp | 1 + cocos2dx/cocoa/CCInteger.h | 4 + cocos2dx/cocos2d.cpp | 2 +- 6 files changed, 239 insertions(+), 70 deletions(-) diff --git a/cocos2dx/CCConfiguration.cpp b/cocos2dx/CCConfiguration.cpp index 162411ec24..c9104ea59f 100644 --- a/cocos2dx/CCConfiguration.cpp +++ b/cocos2dx/CCConfiguration.cpp @@ -27,11 +27,16 @@ THE SOFTWARE. #include "ccMacros.h" #include "ccConfig.h" #include +#include "cocoa/CCDictionary.h" +#include "cocoa/CCInteger.h" +#include "cocoa/CCBool.h" +#include "cocos2d.h" using namespace std; NS_CC_BEGIN + CCConfiguration* CCConfiguration::s_gSharedConfiguration = NULL; CCConfiguration::CCConfiguration(void) @@ -45,57 +50,95 @@ CCConfiguration::CCConfiguration(void) , m_nMaxSamplesAllowed(0) , m_nMaxTextureUnits(0) , m_pGlExtensions(NULL) +, m_pDefaults(NULL) { } bool CCConfiguration::init(void) { - CCLOG("cocos2d: GL_VENDOR: %s", glGetString(GL_VENDOR)); - CCLOG("cocos2d: GL_RENDERER: %s", glGetString(GL_RENDERER)); - CCLOG("cocos2d: GL_VERSION: %s", glGetString(GL_VERSION)); + m_pDefaults = CCDictionary::create(); + + m_pDefaults->setObject( CCString::create( cocos2dVersion() ), "cocos2d.version"); + + +#if CC_ENABLE_PROFILERS + m_pDefaults->setObject( CCBool::create(true), "cocos2d.compiled_with_profiler"); +#else + m_pDefaults->setObject( CCBool::create(false), "cocos2d.compiled_with_profiler"); +#endif + +#if CC_ENABLE_GL_STATE_CACHE == 0 + m_pDefaults->setObject( CCBool::create(false), "cocos2d.compiled_with_gl_state_cache"); +#else + m_pDefaults->setObject( CCBool::create(true), "cocos2d.compiled_with_gl_state_cache"); +#endif + + return true; +} + +CCConfiguration::~CCConfiguration(void) +{ + m_pDefaults->release(); +} + +void CCConfiguration::dumpInfo(void) const +{ + // Dump + CCPrettyPrinter visitor(0); + m_pDefaults->acceptVisitor(visitor); + + CCLOG("%s", visitor.getResult().c_str()); + + + // And Dump some warnings as well +#if CC_ENABLE_PROFILERS + CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)"); + printf("\n"); +#endif + +#if CC_ENABLE_GL_STATE_CACHE == 0 + CCLOG(""); + CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)"); + printf("\n"); +#endif + +} + +void CCConfiguration::gatherGPUInfo() +{ + m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_VENDOR)), "gl.vendor"); + m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_RENDERER)), "gl.renderer"); + m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_VERSION)), "gl.version"); m_pGlExtensions = (char *)glGetString(GL_EXTENSIONS); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_nMaxTextureSize); + m_pDefaults->setObject( CCInteger::create((int)m_nMaxTextureSize), "gl.max_texture_size"); + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_nMaxTextureUnits); + m_pDefaults->setObject( CCInteger::create((int)m_nMaxTextureUnits), "gl.max_texture_units"); + #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) glGetIntegerv(GL_MAX_SAMPLES_APPLE, &m_nMaxSamplesAllowed); + m_pDefaults->setObject( CCInteger::create((int)m_nMaxSamplesAllowed), "gl.max_samples_allowed"); #endif m_bSupportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc"); + m_pDefaults->setObject( CCBool::create(m_bSupportsPVRTC), "gl.supports_PVRTC"); + m_bSupportsNPOT = true; + m_pDefaults->setObject( CCBool::create(m_bSupportsNPOT), "gl.supports_NPOT"); + m_bSupportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888"); + m_pDefaults->setObject( CCBool::create(m_bSupportsBGRA8888), "gl.supports_BGRA8888"); + m_bSupportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer"); + m_pDefaults->setObject( CCBool::create(m_bSupportsDiscardFramebuffer), "gl.supports_discard_framebuffer"); m_bSupportsShareableVAO = checkForGLExtension("vertex_array_object"); - - CCLOG("cocos2d: GL_MAX_TEXTURE_SIZE: %d", m_nMaxTextureSize); - CCLOG("cocos2d: GL_MAX_TEXTURE_UNITS: %d",m_nMaxTextureUnits); - CCLOG("cocos2d: GL supports PVRTC: %s", (m_bSupportsPVRTC ? "YES" : "NO")); - CCLOG("cocos2d: GL supports BGRA8888 textures: %s", (m_bSupportsBGRA8888 ? "YES" : "NO")); - CCLOG("cocos2d: GL supports NPOT textures: %s", (m_bSupportsNPOT ? "YES" : "NO")); - CCLOG("cocos2d: GL supports discard_framebuffer: %s", (m_bSupportsDiscardFramebuffer ? "YES" : "NO")); - CCLOG("cocos2d: GL supports shareable VAO: %s", (m_bSupportsShareableVAO ? "YES" : "NO") ); - - bool CC_UNUSED bEnableProfilers = false; - -#if CC_ENABLE_PROFILERS - bEnableProfilers = true; -#else - bEnableProfilers = false; -#endif - CCLOG("cocos2d: compiled with Profiling Support: %s", - bEnableProfilers ? "YES - *** Disable it when you finish profiling ***" : "NO"); - -#if CC_ENABLE_GL_STATE_CACHE == 0 - CCLOG(""); - CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h"); - printf("\n"); -#endif + m_pDefaults->setObject( CCBool::create(m_bSupportsShareableVAO), "gl.supports_vertex_array_object"); CHECK_GL_ERROR_DEBUG(); - - return true; } CCConfiguration* CCConfiguration::sharedConfiguration(void) @@ -114,7 +157,7 @@ void CCConfiguration::purgeConfiguration(void) CC_SAFE_RELEASE_NULL(s_gSharedConfiguration); } -bool CCConfiguration::checkForGLExtension(const string &searchName) +bool CCConfiguration::checkForGLExtension(const string &searchName) const { bool bRet = false; const char *kSearchName = searchName.c_str(); @@ -128,4 +171,100 @@ bool CCConfiguration::checkForGLExtension(const string &searchName) return bRet; } +// +// getters for specific variables. +// Mantained for backward compatiblity reasons only. +// +int CCConfiguration::getMaxTextureSize(void) const +{ + return m_nMaxTextureSize; +} + +int CCConfiguration::getMaxModelviewStackDepth(void) const +{ + return m_nMaxModelviewStackDepth; +} + +int CCConfiguration::getMaxTextureUnits(void) const +{ + return m_nMaxTextureUnits; +} + +bool CCConfiguration::supportsNPOT(void) const +{ + return m_bSupportsNPOT; +} + +bool CCConfiguration::supportsPVRTC(void) const +{ + return m_bSupportsPVRTC; +} + +bool CCConfiguration::supportsBGRA8888(void) const +{ + return m_bSupportsBGRA8888; +} + +bool CCConfiguration::supportsDiscardFramebuffer(void) const +{ + return m_bSupportsDiscardFramebuffer; +} + +bool CCConfiguration::supportsShareableVAO(void) const +{ + return m_bSupportsShareableVAO; +} + +// +// generic getters for properties +// +const char *CCConfiguration::getCString( const char *key ) const +{ + CCObject *ret = m_pDefaults->objectForKey(key); + if( ret ) + if( CCString *str=dynamic_cast(ret) ) + return str->getCString(); + + // XXX: Should it throw an exception ? + return NULL; +} + +/** returns the value of a given key as a boolean */ +bool CCConfiguration::getBool( const char *key ) const +{ + CCObject *ret = m_pDefaults->objectForKey(key); + if( ret ) + if( CCBool *obj=dynamic_cast(ret) ) + return obj->getValue(); + + // XXX: Should it throw an exception ? + return false; +} + +/** returns the value of a given key as a double */ +double CCConfiguration::getNumber( const char *key ) const +{ + CCObject *ret = m_pDefaults->objectForKey(key); + if( ret ) { + if( CCDouble *obj=dynamic_cast(ret) ) + return obj->getValue(); + + if( CCInteger *obj=dynamic_cast(ret) ) + return obj->getValue(); + } + + // XXX: Should it throw an exception ? + return 0.0; +} + +CCObject * CCConfiguration::getObject( const char *key ) const +{ + return m_pDefaults->objectForKey(key); +} + +ccConfigurationType CCConfiguration::getType( const char *key ) const +{ + return ConfigurationError; +} + NS_CC_END diff --git a/cocos2dx/CCConfiguration.h b/cocos2dx/CCConfiguration.h index 0c8a78b78d..292d38009d 100644 --- a/cocos2dx/CCConfiguration.h +++ b/cocos2dx/CCConfiguration.h @@ -28,10 +28,22 @@ THE SOFTWARE. #include "cocoa/CCObject.h" #include "CCGL.h" +#include "cocoa/CCString.h" #include + + NS_CC_BEGIN +typedef enum _ccConfigurationType { + ConfigurationError, + ConfigurationString, + ConfigurationInt, + ConfigurationDouble, + ConfigurationBoolean +} ccConfigurationType; + + /** * @addtogroup global * @{ @@ -48,72 +60,74 @@ public: /** purge the shared instance of CCConfiguration */ static void purgeConfiguration(void); public: - + + virtual ~CCConfiguration(void); + /** OpenGL Max texture size. */ - inline int getMaxTextureSize(void) - { - return m_nMaxTextureSize; - } - + int getMaxTextureSize(void) const; + /** OpenGL Max Modelview Stack Depth. */ - inline int getMaxModelviewStackDepth(void) - { - return m_nMaxModelviewStackDepth; - } + int getMaxModelviewStackDepth(void) const; /** returns the maximum texture units @since v2.0.0 */ - inline int getMaxTextureUnits(void) - { - return m_nMaxTextureUnits; - } + int getMaxTextureUnits(void) const; /** Whether or not the GPU supports NPOT (Non Power Of Two) textures. OpenGL ES 2.0 already supports NPOT (iOS). @since v0.99.2 */ - inline bool supportsNPOT(void) - { - return m_bSupportsNPOT; - } + bool supportsNPOT(void) const; /** Whether or not PVR Texture Compressed is supported */ - inline bool supportsPVRTC(void) - { - return m_bSupportsPVRTC; - } + bool supportsPVRTC(void) const; /** Whether or not BGRA8888 textures are supported. @since v0.99.2 */ - inline bool supportsBGRA8888(void) - { - return m_bSupportsBGRA8888; - } + bool supportsBGRA8888(void) const; /** Whether or not glDiscardFramebufferEXT is supported @since v0.99.2 */ - inline bool supportsDiscardFramebuffer(void) - { - return m_bSupportsDiscardFramebuffer; - } + bool supportsDiscardFramebuffer(void) const; /** Whether or not shareable VAOs are supported. @since v2.0.0 */ - inline bool supportsShareableVAO(void) - { - return m_bSupportsShareableVAO; - } + bool supportsShareableVAO(void) const; /** returns whether or not an OpenGL is supported */ - bool checkForGLExtension(const std::string &searchName); + bool checkForGLExtension(const std::string &searchName) const; bool init(void); + /** returns the value of a given key as a string */ + const char* getCString( const char *key ) const; + + /** returns the value of a given key as a boolean */ + bool getBool( const char *key ) const; + + /** returns the value of a given key as a double */ + double getNumber( const char *key ) const; + + /** returns the value of a given key as a double */ + CCObject * getObject( const char *key ) const; + + /** returns the type of a given key */ + ccConfigurationType getType( const char *key ) const; + + /** dumps the current configuration on the console */ + void dumpInfo(void) const; + + /** loads JSON config file in the configuration */ + void loadConfigFile( char *filename ); + + /** gathers OpenGL / GPU information */ + void gatherGPUInfo( void ); + private: CCConfiguration(void); static CCConfiguration *s_gSharedConfiguration; @@ -129,6 +143,7 @@ protected: GLint m_nMaxSamplesAllowed; GLint m_nMaxTextureUnits; char * m_pGlExtensions; + CCDictionary *m_pDefaults; }; // end of global group diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index deff9ce737..5bb11fc546 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -23,6 +23,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + +// standard includes +#include + +// cocos2d includes #include "CCDirector.h" #include "ccFPSImages.h" #include "draw_nodes/CCDrawingPrimitives.h" @@ -57,7 +62,9 @@ THE SOFTWARE. #include "kazmath/GL/matrix.h" #include "support/CCProfiling.h" #include "CCEGLView.h" -#include +#include "CCConfiguration.h" + + /** Position of the FPS @@ -98,9 +105,7 @@ CCDirector::CCDirector(void) } bool CCDirector::init(void) -{ - CCLOG("cocos2d: %s", cocos2dVersion()); - +{ // scenes m_pRunningScene = NULL; m_pNextScene = NULL; @@ -304,6 +309,11 @@ void CCDirector::setOpenGLView(CCEGLView *pobOpenGLView) if (m_pobOpenGLView != pobOpenGLView) { + // Configuration. Gather GPU info + CCConfiguration *conf = CCConfiguration::sharedConfiguration(); + conf->gatherGPUInfo(); + conf->dumpInfo(); + // EAGLView is not a CCObject delete m_pobOpenGLView; // [openGLView_ release] m_pobOpenGLView = pobOpenGLView; diff --git a/cocos2dx/cocoa/CCDataVisitor.cpp b/cocos2dx/cocoa/CCDataVisitor.cpp index 9282c234e2..cb4ac8c73a 100644 --- a/cocos2dx/cocoa/CCDataVisitor.cpp +++ b/cocos2dx/cocoa/CCDataVisitor.cpp @@ -101,6 +101,7 @@ void CCPrettyPrinter::visit(const CCBool * p) { char buf[50] = {0}; sprintf(buf, "%s", p->getValue() ? "true" : "false"); + _result += buf; } void CCPrettyPrinter::visit(const CCInteger *p) diff --git a/cocos2dx/cocoa/CCInteger.h b/cocos2dx/cocoa/CCInteger.h index f412dd4a3a..e9f34cb3af 100644 --- a/cocos2dx/cocoa/CCInteger.h +++ b/cocos2dx/cocoa/CCInteger.h @@ -23,6 +23,10 @@ public: pRet->autorelease(); return pRet; } + + /* override functions */ + virtual void acceptVisitor(CCDataVisitor &visitor) { visitor.visit(this); } + private: int m_nValue; }; diff --git a/cocos2dx/cocos2d.cpp b/cocos2dx/cocos2d.cpp index c9b6ef96b7..2a8e582497 100644 --- a/cocos2dx/cocos2d.cpp +++ b/cocos2dx/cocos2d.cpp @@ -30,7 +30,7 @@ NS_CC_BEGIN const char* cocos2dVersion() { - return "cocos2d-2.1rc0-x-2.1.3"; + return "2.1rc0-x-2.1.3"; } NS_CC_END