mirror of https://github.com/axmolengine/axmol.git
issue #2410: [Android] Adding listener for CCDrawNode when application resume from background.
Reset the order of reloading shaders and textures in main.cpp.
This commit is contained in:
parent
5b06824036
commit
56419b9e90
|
@ -23,6 +23,8 @@
|
|||
#include "CCDrawNode.h"
|
||||
#include "shaders/CCShaderCache.h"
|
||||
#include "CCGL.h"
|
||||
#include "support/CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -118,6 +120,8 @@ DrawNode::~DrawNode()
|
|||
ccGLBindVAO(0);
|
||||
_vao = 0;
|
||||
#endif
|
||||
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
}
|
||||
|
||||
DrawNode* DrawNode::create()
|
||||
|
@ -157,18 +161,17 @@ bool DrawNode::init()
|
|||
glGenVertexArrays(1, &_vao);
|
||||
ccGLBindVAO(_vao);
|
||||
#endif
|
||||
|
||||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(kVertexAttrib_Position);
|
||||
ccGLEnableVertexAttribs( kVertexAttribFlag_PosColorTex );
|
||||
|
||||
glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
|
||||
|
||||
glEnableVertexAttribArray(kVertexAttrib_Color);
|
||||
glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
|
||||
|
||||
glEnableVertexAttribArray(kVertexAttrib_TexCoords);
|
||||
glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
@ -181,6 +184,12 @@ bool DrawNode::init()
|
|||
|
||||
_dirty = true;
|
||||
|
||||
// Need to listen the event only when not use batchnode, because it will use VBO
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(DrawNode::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -196,6 +205,7 @@ void DrawNode::render()
|
|||
ccGLBindVAO(_vao);
|
||||
#else
|
||||
ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
// vertex
|
||||
glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
|
||||
|
@ -216,11 +226,9 @@ void DrawNode::render()
|
|||
|
||||
void DrawNode::draw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
ccGLBlendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
|
||||
getShaderProgram()->use();
|
||||
getShaderProgram()->setUniformsForBuiltins();
|
||||
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
|
@ -440,4 +448,11 @@ void DrawNode::setBlendFunc(const BlendFunc &blendFunc)
|
|||
_blendFunc = blendFunc;
|
||||
}
|
||||
|
||||
/** listen the event that coming to foreground on Android
|
||||
*/
|
||||
void DrawNode::listenBackToForeground(Object *obj)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -79,6 +79,10 @@ public:
|
|||
|
||||
DrawNode();
|
||||
|
||||
/** listen the event that coming to foreground on Android
|
||||
*/
|
||||
void listenBackToForeground(Object *obj);
|
||||
|
||||
private:
|
||||
void ensureCapacity(unsigned int count);
|
||||
void render();
|
||||
|
|
|
@ -483,16 +483,14 @@ void ParticleSystemQuad::setupVBOandVAO()
|
|||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _totalParticles, _quads, GL_DYNAMIC_DRAW);
|
||||
|
||||
ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex);
|
||||
// vertices
|
||||
glEnableVertexAttribArray(kVertexAttrib_Position);
|
||||
glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
|
||||
|
||||
// colors
|
||||
glEnableVertexAttribArray(kVertexAttrib_Color);
|
||||
glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
|
||||
|
||||
// tex coords
|
||||
glEnableVertexAttribArray(kVertexAttrib_TexCoords);
|
||||
glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
|
|
@ -241,7 +241,7 @@ bool GLProgram::link()
|
|||
|
||||
_vertShader = _fragShader = 0;
|
||||
|
||||
#if DEBUG
|
||||
#if COCOS2D_DEBUG
|
||||
glGetProgramiv(_program, GL_LINK_STATUS, &status);
|
||||
|
||||
if (status == GL_FALSE)
|
||||
|
|
|
@ -76,7 +76,11 @@ void ccGLInvalidateStateCache( void )
|
|||
s_eBlendingSource = -1;
|
||||
s_eBlendingDest = -1;
|
||||
s_eGLServerState = 0;
|
||||
#if CC_TEXTURE_ATLAS_USE_VAO
|
||||
s_uVAO = 0;
|
||||
#endif
|
||||
|
||||
#endif // CC_ENABLE_GL_STATE_CACHE
|
||||
}
|
||||
|
||||
void ccGLDeleteProgram( GLuint program )
|
||||
|
|
|
@ -255,16 +255,14 @@ void TextureAtlas::setupVBOandVAO()
|
|||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _capacity, _quads, GL_DYNAMIC_DRAW);
|
||||
|
||||
ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex);
|
||||
// vertices
|
||||
glEnableVertexAttribArray(kVertexAttrib_Position);
|
||||
glVertexAttribPointer(kVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
|
||||
|
||||
// colors
|
||||
glEnableVertexAttribArray(kVertexAttrib_Color);
|
||||
glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
|
||||
|
||||
// tex coords
|
||||
glEnableVertexAttribArray(kVertexAttrib_TexCoords);
|
||||
glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
|
|
@ -34,10 +34,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,10 +34,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -33,10 +33,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -30,10 +30,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -31,10 +31,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
Loading…
Reference in New Issue