mirror of https://github.com/axmolengine/axmol.git
1.修正gles版本过低时会崩溃的问题
2.修正unscheduleAllSelectors()中遍历哈希表导致崩溃的问题
This commit is contained in:
parent
a5c9b8631c
commit
a13e8ae859
|
@ -436,11 +436,15 @@ void CCScheduler::unscheduleUpdateForTarget(const SelectorProtocol *pTarget)
|
||||||
void CCScheduler::unscheduleAllSelectors(void)
|
void CCScheduler::unscheduleAllSelectors(void)
|
||||||
{
|
{
|
||||||
// Custom Selectors
|
// Custom Selectors
|
||||||
tHashSelectorEntry *pElement;
|
tHashSelectorEntry *pElement = NULL;
|
||||||
|
tHashSelectorEntry *pNextElement = NULL;
|
||||||
for (pElement = m_pHashForSelectors; pElement != NULL;)
|
for (pElement = m_pHashForSelectors; pElement != NULL;)
|
||||||
{
|
{
|
||||||
|
// pElement may be removed in unscheduleAllSelectorsForTarget
|
||||||
|
pNextElement = (tHashSelectorEntry *)pElement->hh.next;
|
||||||
unscheduleAllSelectorsForTarget(pElement->target);
|
unscheduleAllSelectorsForTarget(pElement->target);
|
||||||
pElement = (tHashSelectorEntry *)pElement->hh.next;
|
|
||||||
|
pElement = pNextElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates selectors
|
// Updates selectors
|
||||||
|
|
|
@ -30,4 +30,26 @@ const char* cocos2dVersion()
|
||||||
{
|
{
|
||||||
return "cocos2d v0.99.5";
|
return "cocos2d v0.99.5";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eGLESVersion getGlesVersion()
|
||||||
|
{
|
||||||
|
std::string strVersion((char *)glGetString(GL_VERSION));
|
||||||
|
|
||||||
|
if (strVersion.find("1.0") != -1)
|
||||||
|
{
|
||||||
|
return GLES_VER_1_0;
|
||||||
|
}
|
||||||
|
else if (strVersion.find("1.1") != -1)
|
||||||
|
{
|
||||||
|
return GLES_VER_1_1;
|
||||||
|
}
|
||||||
|
else if (strVersion.find("2.0") != -1)
|
||||||
|
{
|
||||||
|
return GLES_VER_2_0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GLES_VER_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -33,12 +33,28 @@ namespace cocos2d
|
||||||
: m_fbo(0)
|
: m_fbo(0)
|
||||||
, m_oldFBO(0)
|
, m_oldFBO(0)
|
||||||
{
|
{
|
||||||
|
m_eGlesVersion = getGlesVersion();
|
||||||
|
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// all the functions in CCGrabber return directly.
|
||||||
|
if (m_eGlesVersion <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
// generate FBO
|
// generate FBO
|
||||||
ccglGenFramebuffers(1, &m_fbo);
|
ccglGenFramebuffers(1, &m_fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCGrabber::grab(cocos2d::CCTexture2D *pTexture)
|
void CCGrabber::grab(cocos2d::CCTexture2D *pTexture)
|
||||||
{
|
{
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// all the functions in CCGrabber return directly.
|
||||||
|
if (m_eGlesVersion <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
|
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
|
||||||
|
|
||||||
// bind
|
// bind
|
||||||
|
@ -60,6 +76,13 @@ namespace cocos2d
|
||||||
|
|
||||||
void CCGrabber::beforeRender(cocos2d::CCTexture2D *pTexture)
|
void CCGrabber::beforeRender(cocos2d::CCTexture2D *pTexture)
|
||||||
{
|
{
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// all the functions in CCGrabber return directly.
|
||||||
|
if (m_eGlesVersion <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
|
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
|
||||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo);
|
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo);
|
||||||
|
|
||||||
|
@ -78,12 +101,26 @@ namespace cocos2d
|
||||||
|
|
||||||
void CCGrabber::afterRender(cocos2d::CCTexture2D *pTexture)
|
void CCGrabber::afterRender(cocos2d::CCTexture2D *pTexture)
|
||||||
{
|
{
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// all the functions in CCGrabber return directly.
|
||||||
|
if (m_eGlesVersion <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
|
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
|
||||||
glColorMask(true, true, true, true); // #631
|
glColorMask(true, true, true, true); // #631
|
||||||
}
|
}
|
||||||
|
|
||||||
CCGrabber::~CCGrabber()
|
CCGrabber::~CCGrabber()
|
||||||
{
|
{
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// all the functions in CCGrabber return directly.
|
||||||
|
if (m_eGlesVersion <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
CCLOGINFO("cocos2d: deallocing %p", this);
|
CCLOGINFO("cocos2d: deallocing %p", this);
|
||||||
ccglDeleteFramebuffers(1, &m_fbo);
|
ccglDeleteFramebuffers(1, &m_fbo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
||||||
#ifndef __EFFECTS_CCGRABBER_H__
|
#ifndef __EFFECTS_CCGRABBER_H__
|
||||||
#define __EFFECTS_CCGRABBER_H__
|
#define __EFFECTS_CCGRABBER_H__
|
||||||
|
|
||||||
|
#include "cocos2d.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ namespace cocos2d
|
||||||
protected:
|
protected:
|
||||||
GLuint m_fbo;
|
GLuint m_fbo;
|
||||||
GLint m_oldFBO;
|
GLint m_oldFBO;
|
||||||
|
eGLESVersion m_eGlesVersion;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace cocos2d
|
} // end of namespace cocos2d
|
||||||
|
|
|
@ -120,6 +120,17 @@ THE SOFTWARE.
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
const char* cocos2dVersion();
|
const char* cocos2dVersion();
|
||||||
|
|
||||||
|
enum eGLESVersion
|
||||||
|
{
|
||||||
|
GLES_VER_INVALID,
|
||||||
|
GLES_VER_1_0,
|
||||||
|
GLES_VER_1_1,
|
||||||
|
GLES_VER_2_0
|
||||||
|
};
|
||||||
|
|
||||||
|
eGLESVersion CC_DLL getGlesVersion();
|
||||||
|
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
||||||
#endif // __COCOS2D_H__
|
#endif // __COCOS2D_H__
|
||||||
|
|
|
@ -1114,6 +1114,12 @@ void CCTransitionCrossFade::onEnter()
|
||||||
|
|
||||||
// create the first render texture for inScene
|
// create the first render texture for inScene
|
||||||
CCRenderTexture* inTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
|
CCRenderTexture* inTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
|
||||||
|
|
||||||
|
if (NULL == inTexture)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
|
inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
|
||||||
inTexture->setPosition( ccp(size.width/2, size.height/2) );
|
inTexture->setPosition( ccp(size.width/2, size.height/2) );
|
||||||
inTexture->setAnchorPoint( ccp(0.5f,0.5f) );
|
inTexture->setAnchorPoint( ccp(0.5f,0.5f) );
|
||||||
|
|
|
@ -62,6 +62,12 @@ void CCTransitionRadialCCW::onEnter()
|
||||||
|
|
||||||
// create the second render texture for outScene
|
// create the second render texture for outScene
|
||||||
CCRenderTexture *outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
|
CCRenderTexture *outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
|
||||||
|
|
||||||
|
if (NULL == outTexture)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
outTexture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
|
outTexture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
|
||||||
outTexture->setPosition(ccp(size.width/2, size.height/2));
|
outTexture->setPosition(ccp(size.width/2, size.height/2));
|
||||||
outTexture->setAnchorPoint(ccp(0.5f,0.5f));
|
outTexture->setAnchorPoint(ccp(0.5f,0.5f));
|
||||||
|
|
|
@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "cocos2d.h"
|
||||||
#include "CCRenderTexture.h"
|
#include "CCRenderTexture.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
@ -84,8 +85,16 @@ CCRenderTexture * CCRenderTexture::renderTextureWithWidthAndHeight(int w, int h)
|
||||||
CC_SAFE_DELETE(pRet)
|
CC_SAFE_DELETE(pRet)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
|
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
|
||||||
{
|
{
|
||||||
|
// If the gles version is lower than GLES_VER_1_0,
|
||||||
|
// some extended gles functions can't be implemented, so return false directly.
|
||||||
|
if (getGlesVersion() <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "cocos2d.h"
|
||||||
#include "RenderTextureTest.h"
|
#include "RenderTextureTest.h"
|
||||||
|
|
||||||
static int sceneIdx = -1;
|
static int sceneIdx = -1;
|
||||||
|
@ -115,11 +116,24 @@ std::string RenderTextureTestDemo::subtitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTextureTest::RenderTextureTest()
|
RenderTextureTest::RenderTextureTest()
|
||||||
|
: m_brush(NULL)
|
||||||
{
|
{
|
||||||
|
if (cocos2d::getGlesVersion() <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
// create a render texture, this is what we're going to draw into
|
// create a render texture, this is what we're going to draw into
|
||||||
m_target = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);
|
m_target = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);
|
||||||
|
|
||||||
|
if (NULL == m_target)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_target->setPosition(ccp(s.width/2, s.height/2));
|
m_target->setPosition(ccp(s.width/2, s.height/2));
|
||||||
|
|
||||||
// note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,
|
// note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,
|
||||||
|
@ -138,7 +152,11 @@ RenderTextureTest::RenderTextureTest()
|
||||||
|
|
||||||
RenderTextureTest::~RenderTextureTest()
|
RenderTextureTest::~RenderTextureTest()
|
||||||
{
|
{
|
||||||
|
if (NULL != m_brush)
|
||||||
|
{
|
||||||
m_brush->release();
|
m_brush->release();
|
||||||
|
m_brush = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||||
|
@ -203,6 +221,11 @@ RenderTextureIssue937::RenderTextureIssue937()
|
||||||
/* A2 & B2 setup */
|
/* A2 & B2 setup */
|
||||||
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);
|
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);
|
||||||
|
|
||||||
|
if (NULL == rend)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// It's possible to modify the RenderTexture blending function by
|
// It's possible to modify the RenderTexture blending function by
|
||||||
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||||
|
|
||||||
|
|
|
@ -212,10 +212,39 @@ CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
|
||||||
case 22: return CCTransitionSlideInR::transitionWithDuration(t, s);
|
case 22: return CCTransitionSlideInR::transitionWithDuration(t, s);
|
||||||
case 23: return CCTransitionSlideInT::transitionWithDuration(t, s);
|
case 23: return CCTransitionSlideInT::transitionWithDuration(t, s);
|
||||||
case 24: return CCTransitionSlideInB::transitionWithDuration(t, s);
|
case 24: return CCTransitionSlideInB::transitionWithDuration(t, s);
|
||||||
|
case 25:
|
||||||
|
{
|
||||||
|
if (getGlesVersion() <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionCrossFade may not run correctly, it is ignored.", "Cocos2d-x Hint");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
case 25: return CCTransitionCrossFade::transitionWithDuration(t,s);
|
return CCTransitionCrossFade::transitionWithDuration(t,s);
|
||||||
case 26: return CCTransitionRadialCCW::transitionWithDuration(t,s);
|
}
|
||||||
case 27: return CCTransitionRadialCW::transitionWithDuration(t,s);
|
break;
|
||||||
|
case 26:
|
||||||
|
{
|
||||||
|
if (getGlesVersion() <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CCTransitionRadialCCW::transitionWithDuration(t,s);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
{
|
||||||
|
if (getGlesVersion() <= GLES_VER_1_0)
|
||||||
|
{
|
||||||
|
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CCTransitionRadialCW::transitionWithDuration(t,s);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 28: return PageTransitionForward::transitionWithDuration(t, s);
|
case 28: return PageTransitionForward::transitionWithDuration(t, s);
|
||||||
case 29: return PageTransitionBackward::transitionWithDuration(t, s);
|
case 29: return PageTransitionBackward::transitionWithDuration(t, s);
|
||||||
case 30: return CCTransitionFadeTR::transitionWithDuration(t, s);
|
case 30: return CCTransitionFadeTR::transitionWithDuration(t, s);
|
||||||
|
|
Loading…
Reference in New Issue