diff --git a/cocos2dx/CCConfiguration.cpp b/cocos2dx/CCConfiguration.cpp index 2fc50d9ba8..8e4ffb0ce8 100644 --- a/cocos2dx/CCConfiguration.cpp +++ b/cocos2dx/CCConfiguration.cpp @@ -32,15 +32,16 @@ using namespace std; NS_CC_BEGIN +CCConfiguration* CCConfiguration::s_gSharedConfiguration = NULL; + CCConfiguration::CCConfiguration(void) -:m_nMaxTextureSize(0) +: m_nMaxTextureSize(0) +, m_nMaxModelviewStackDepth(0) , m_nMaxTextureUnits(0) , m_bSupportsPVRTC(false) , m_bSupportsNPOT(false) , m_bSupportsBGRA8888(false) , m_bSupportsDiscardFramebuffer(false) -, m_bInited(false) -, m_uOSVersion(0) , m_nMaxSamplesAllowed(0) , m_pGlExtensions(NULL) { @@ -56,9 +57,10 @@ bool CCConfiguration::init(void) glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_nMaxTextureSize); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_nMaxTextureUnits); + glGetIntegerv(GL_MAX_SAMPLES_APPLE, &m_nMaxSamplesAllowed); m_bSupportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc"); - m_bSupportsNPOT = checkForGLExtension("GL_APPLE_texture_2D_limited_npot"); + m_bSupportsNPOT = true; m_bSupportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888"); m_bSupportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer"); @@ -68,58 +70,37 @@ bool CCConfiguration::init(void) 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")); - -#if CC_TEXTURE_NPOT_SUPPORT - CCLOG("cocos2d: compiled with NPOT support: %s", "YES"); -#else - CCLOG("cocos2d: compiled with NPOT support: %s", "NO"); -#endif // CC_TEXTURE_NPOT_SUPPORT -#if CC_TEXTURE_ATLAS_USE_VAO - CCLOG("cocos2d: compiled with VAO support in TextureAtlas : %s", "YES"); + CCLOG("cocos2d: compiled with Profiling Support: %s", +#if CC_ENABLE_PROFILERS + + "YES - *** Disable it when you finish profiling ***" #else - CCLOG("cocos2d: compiled with VAO support in TextureAtlas : %s", "NO"); -#endif // CC_TEXTURE_ATLAS_USE_VAO + "NO" +#endif + ); + +#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 + + CHECK_GL_ERROR_DEBUG(); return true; } -CCGlesVersion CCConfiguration::getGlesVersion() -{ - // To get the Opengl ES version - std::string strVersion((char *)glGetString(GL_VERSION)); - if ((int)strVersion.find("1.0") != -1) - { - return GLES_VER_1_0; - } - else if ((int)strVersion.find("1.1") != -1) - { - return GLES_VER_1_1; - } - else if ((int)strVersion.find("2.0") != -1) - { - return GLES_VER_2_0; - } -#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) - return GLES_VER_2_0; -#else - - - return GLES_VER_INVALID; -#endif -} - CCConfiguration* CCConfiguration::sharedConfiguration(void) { - static CCConfiguration sharedConfiguration; - if (!sharedConfiguration.m_bInited) + if (! s_gSharedConfiguration) { - sharedConfiguration.init(); - sharedConfiguration.m_bInited = true; + s_gSharedConfiguration = new CCConfiguration(); + s_gSharedConfiguration->init(); } - return &sharedConfiguration; + return s_gSharedConfiguration; } bool CCConfiguration::checkForGLExtension(const string &searchName) diff --git a/cocos2dx/CCConfiguration.h b/cocos2dx/CCConfiguration.h index ee3c4438cd..03b7bde9b6 100644 --- a/cocos2dx/CCConfiguration.h +++ b/cocos2dx/CCConfiguration.h @@ -32,76 +32,40 @@ THE SOFTWARE. NS_CC_BEGIN -/** OS version definitions. -*/ -enum { - kCCiOSVersion_3_0 = 0x03000000, - kCCiOSVersion_3_1 = 0x03010000, - kCCiOSVersion_3_1_1 = 0x03010100, - kCCiOSVersion_3_1_2 = 0x03010200, - kCCiOSVersion_3_1_3 = 0x03010300, - kCCiOSVersion_3_2 = 0x03020000, - kCCiOSVersion_3_2_1 = 0x03020100, - kCCiOSVersion_4_0 = 0x04000000, - kCCiOSVersion_4_0_1 = 0x04000100, - kCCiOSVersion_4_1 = 0x04010000, - kCCiOSVersion_4_2 = 0x04020000, - kCCiOSVersion_4_3 = 0x04030000, - kCCiOSVersion_4_3_1 = 0x04030100, - kCCiOSVersion_4_3_2 = 0x04030200, - kCCiOSVersion_4_3_3 = 0x04030300, -}; - -typedef enum -{ - GLES_VER_INVALID, - GLES_VER_1_0, - GLES_VER_1_1, - GLES_VER_2_0, -} CCGlesVersion; - /** @brief CCConfiguration contains some openGL variables @since v0.99.0 */ class CC_DLL CCConfiguration : public CCObject { -protected: - GLint m_nMaxTextureSize; - GLint m_nMaxTextureUnits; - bool m_bSupportsPVRTC; - bool m_bSupportsNPOT; - bool m_bSupportsBGRA8888; - bool m_bSupportsDiscardFramebuffer; - bool m_bInited; - unsigned int m_uOSVersion; - GLint m_nMaxSamplesAllowed; - char * m_pGlExtensions; - -private: - - CCConfiguration(void); - +public: + /** returns a shared instance of the CCConfiguration */ + static CCConfiguration *sharedConfiguration(void); + public: - - CCGlesVersion getGlesVersion(); /** OpenGL Max texture size. */ inline int getMaxTextureSize(void) { return m_nMaxTextureSize; } + + /** OpenGL Max Modelview Stack Depth. */ + inline int getMaxModelviewStackDepth(void) + { + return m_nMaxModelviewStackDepth; + } - /** returns the maximum texture units */ + /** returns the maximum texture units + @since v2.0.0 + */ inline int getMaxTextureUnits(void) { return m_nMaxTextureUnits; } /** Whether or not the GPU supports NPOT (Non Power Of Two) textures. - NPOT textures have the following limitations: - - They can't have mipmaps - - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T} + OpenGL ES 2.0 already supports NPOT (iOS). @since v0.99.2 */ @@ -132,22 +96,25 @@ public: return m_bSupportsDiscardFramebuffer; } - /** returns the OS version. - - On iOS devices it returns the firmware version. - - On Mac returns the OS version - - @since v0.99.5 - */ - inline unsigned int getOSVersion() { return m_uOSVersion; } - /** returns whether or not an OpenGL is supported */ bool checkForGLExtension(const std::string &searchName); bool init(void); -public: - /** returns a shared instance of the CCConfiguration */ - static CCConfiguration *sharedConfiguration(void); +private: + CCConfiguration(void); + static CCConfiguration *s_gSharedConfiguration; + +protected: + GLint m_nMaxTextureSize; + GLint m_nMaxModelviewStackDepth; + bool m_bSupportsPVRTC; + bool m_bSupportsNPOT; + bool m_bSupportsBGRA8888; + bool m_bSupportsDiscardFramebuffer; + GLint m_nMaxSamplesAllowed; + GLint m_nMaxTextureUnits; + char * m_pGlExtensions; }; NS_CC_END diff --git a/cocos2dx/effects/CCGrabber.cpp b/cocos2dx/effects/CCGrabber.cpp index b9b9c847f2..287be4617d 100644 --- a/cocos2dx/effects/CCGrabber.cpp +++ b/cocos2dx/effects/CCGrabber.cpp @@ -34,14 +34,6 @@ CCGrabber::CCGrabber(void) , m_oldFBO(0) { memset(m_oldClearColor, 0, sizeof(m_oldClearColor)); - m_eGlesVersion = CCConfiguration::sharedConfiguration()->getGlesVersion(); - - // If the gles version is lower than GLES_VER_2_0, - // all the functions in CCGrabber return directly. - if (m_eGlesVersion < GLES_VER_2_0) - { - return ; - } // generate FBO glGenFramebuffers(1, &m_fbo); @@ -49,13 +41,6 @@ CCGrabber::CCGrabber(void) void CCGrabber::grab(CCTexture2D *pTexture) { - // If the gles version is lower than GLES_VER_2_0, - // all the functions in CCGrabber return directly. - if (m_eGlesVersion < GLES_VER_2_0) - { - return ; - } - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_oldFBO); // bind @@ -68,7 +53,7 @@ void CCGrabber::grab(CCTexture2D *pTexture) GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - CCLOG("Frame Grabber: could not attach texture to frmaebuffer"); + CCAssert(0, "Frame Grabber: could not attach texture to frmaebuffer"); } glBindFramebuffer(GL_FRAMEBUFFER, m_oldFBO); @@ -77,15 +62,10 @@ void CCGrabber::grab(CCTexture2D *pTexture) void CCGrabber::beforeRender(CCTexture2D *pTexture) { CC_UNUSED_PARAM(pTexture); - // If the gles version is lower than GLES_VER_2_0, - // all the functions in CCGrabber return directly. - if (m_eGlesVersion < GLES_VER_2_0) - { - return ; - } glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_oldFBO); glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + // save clear color glGetFloatv(GL_COLOR_CLEAR_VALUE, m_oldClearColor); // BUG XXX: doesn't work with RGB565. @@ -104,12 +84,6 @@ void CCGrabber::beforeRender(CCTexture2D *pTexture) void CCGrabber::afterRender(cocos2d::CCTexture2D *pTexture) { CC_UNUSED_PARAM(pTexture); - // If the gles version is lower than GLES_VER_2_0, - // all the functions in CCGrabber return directly. - if (m_eGlesVersion < GLES_VER_2_0) - { - return ; - } glBindFramebuffer(GL_FRAMEBUFFER, m_oldFBO); glColorMask(true, true, true, true); // #631 @@ -119,13 +93,6 @@ void CCGrabber::afterRender(cocos2d::CCTexture2D *pTexture) CCGrabber::~CCGrabber() { - // If the gles version is lower than GLES_VER_2_0, - // all the functions in CCGrabber return directly. - if (m_eGlesVersion < GLES_VER_2_0) - { - return ; - } - CCLOGINFO("cocos2d: deallocing %p", this); glDeleteFramebuffers(1, &m_fbo); } diff --git a/cocos2dx/effects/CCGrabber.h b/cocos2dx/effects/CCGrabber.h index 70280e8ab1..be51d4afee 100644 --- a/cocos2dx/effects/CCGrabber.h +++ b/cocos2dx/effects/CCGrabber.h @@ -47,7 +47,6 @@ protected: GLuint m_fbo; GLint m_oldFBO; GLfloat m_oldClearColor[4]; - CCGlesVersion m_eGlesVersion; }; NS_CC_END diff --git a/cocos2dx/include/ccConfig.h b/cocos2dx/include/ccConfig.h index a66af306ee..b1eead860b 100755 --- a/cocos2dx/include/ccConfig.h +++ b/cocos2dx/include/ccConfig.h @@ -183,25 +183,6 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios. #endif #endif -/** @def CC_TEXTURE_NPOT_SUPPORT - If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures. - NPOT textures have the following limitations: - - They can't have mipmaps - - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T} - - To enable set it to a value different than 0. Disabled by default. - - This value governs only the PNG, GIF, BMP, images. - This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value. - - @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it. - - @since v0.99.2 - */ -#ifndef CC_TEXTURE_NPOT_SUPPORT -#define CC_TEXTURE_NPOT_SUPPORT 0 -#endif - /** @def CC_USE_LA88_LABELS If enabled, it will use LA88 (Luminance Alpha 16-bit textures) for CCLabelTTF objects. diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index b6868a95c4..7dbaf55602 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -1282,7 +1282,6 @@ void CCLabelBMFont::updateLabel() if (shift != 0) { - int j = 0; for (unsigned j = 0; j < line_length; j++) { index = i + j + lineNumber; diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index e68e3d144a..b8b6a86128 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -96,13 +96,6 @@ CCRenderTexture * CCRenderTexture::renderTextureWithWidthAndHeight(int w, int h) bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { - // If the gles version is lower than GLES_VER_2_0, - // some extended gles functions can't be implemented, so return false directly. - if (CCConfiguration::sharedConfiguration()->getGlesVersion() < GLES_VER_2_0) - { - return false; - } - CCAssert(m_ePixelFormat != kCCTexture2DPixelFormat_A8, "only RGB and RGBA formats are valid for a render texture"); bool bRet = false; diff --git a/cocos2dx/platform/ios/OpenGL_Internal.h b/cocos2dx/platform/ios/OpenGL_Internal.h index 82dc47321c..9bc7a1860f 100755 --- a/cocos2dx/platform/ios/OpenGL_Internal.h +++ b/cocos2dx/platform/ios/OpenGL_Internal.h @@ -69,11 +69,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. //#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); }) #define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); }) -#if DEBUG -#define CHECK_GL_ERROR_DEBUG() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); }) -#else -#define CHECK_GL_ERROR_DEBUG() -#endif /* Optional delegate methods support */ #ifndef __DELEGATE_IVAR__ diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp index 98e4fcc88f..744df6f3ab 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp @@ -250,7 +250,6 @@ void CCSpriteBatchNode::sortAllChildren() int i = 0,j = 0,length = m_pChildren->data->num; CCNode ** x = (CCNode**)m_pChildren->data->arr; CCNode *tempItem = NULL; - CCSprite *child = NULL; //insertion sort for(i=1; iinitWithName(timerName); m_pActiveTimers->setObject(t, timerName); diff --git a/tests/tests/RenderTextureTest/RenderTextureTest.cpp b/tests/tests/RenderTextureTest/RenderTextureTest.cpp index e910ed736f..821fbcf970 100644 --- a/tests/tests/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/tests/RenderTextureTest/RenderTextureTest.cpp @@ -123,12 +123,6 @@ std::string RenderTextureTestDemo::subtitle() RenderTextureTest::RenderTextureTest() : m_brush(NULL) { - if (CCConfiguration::sharedConfiguration()->getGlesVersion() < GLES_VER_2_0) - { - CCMessageBox("The Opengl ES version is lower than 2.0, and the test may not run correctly.", "Cocos2d-x Hint"); - return; - } - CCSize s = CCDirector::sharedDirector()->getWinSize(); // create a render texture, this is what we're going to draw into diff --git a/tests/tests/TextureCacheTest/TextureCacheTest.cpp b/tests/tests/TextureCacheTest/TextureCacheTest.cpp index 676ceb019a..bb5d0a8ca0 100644 --- a/tests/tests/TextureCacheTest/TextureCacheTest.cpp +++ b/tests/tests/TextureCacheTest/TextureCacheTest.cpp @@ -84,10 +84,10 @@ void TextureCacheTest::addSprite() CCSprite *s15 = CCSprite::spriteWithFile("Images/grossini_dance_14.png"); // just loading textures to slow down - CCSprite *s16 = CCSprite::spriteWithFile("Images/background1.png"); - CCSprite *s17 = CCSprite::spriteWithFile("Images/background2.png"); - CCSprite *s18 = CCSprite::spriteWithFile("Images/background3.png"); - CCSprite *s19 = CCSprite::spriteWithFile("Images/blocks.png"); + CCSprite::spriteWithFile("Images/background1.png"); + CCSprite::spriteWithFile("Images/background2.png"); + CCSprite::spriteWithFile("Images/background3.png"); + CCSprite::spriteWithFile("Images/blocks.png"); s1->setPosition(CCPointMake(50, 50)); s2->setPosition(CCPointMake(60, 50));