fix android background to foreground

This commit is contained in:
yangxiao 2014-07-04 16:10:43 +08:00
parent d2cd2449d8
commit 0af286c3be
3 changed files with 22 additions and 59 deletions

View File

@ -62,8 +62,8 @@ UniformValue::UniformValue(Uniform *uniform, GLProgram* glprogram)
UniformValue::~UniformValue() UniformValue::~UniformValue()
{ {
if (_useCallback) // if (_useCallback)
delete _value.callback; // delete _value.callback;
} }
void UniformValue::apply() void UniformValue::apply()
@ -281,7 +281,7 @@ GLProgramState::GLProgramState()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// listen the event when app go to foreground // listen the event when app go to foreground
CCLOG("create _backToForegroundlistener for GLProgramState"); CCLOG("create _backToForegroundlistener for GLProgramState");
_backToForegroundlistener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom*) { /*_uniformAttributeValueDirty = true;*/ updateUniformAndAtributesLocation(); }); _backToForegroundlistener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom*) { _uniformAttributeValueDirty = true; });
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1);
#endif #endif
} }
@ -325,31 +325,6 @@ void GLProgramState::resetGLProgram()
_textureUnitIndex = 1; _textureUnitIndex = 1;
} }
void GLProgramState::updateUniformAndAtributesLocation()
{
auto olduniformsByName = _uniformsByName;
auto olduniforms = _uniforms;
_uniformsByName.clear();
_uniforms.clear();
for (auto& uniform : _glprogram->_userUniforms) {
auto oldlocation = olduniformsByName[uniform.first];
auto value = olduniforms[oldlocation];
value._uniform = _glprogram->getUniform(uniform.first);
_uniforms[uniform.second.location] = value;
_uniformsByName[uniform.first] = uniform.second.location;
}
_vertexAttribsFlags = 0;
for (auto& attributeValue : _attributes) {
attributeValue.second._vertexAttrib = _glprogram->getVertexAttrib(attributeValue.first);
if(attributeValue.second._enabled)
_vertexAttribsFlags |= 1 << attributeValue.second._vertexAttrib->index;
}
}
void GLProgramState::apply(const Mat4& modelView) void GLProgramState::apply(const Mat4& modelView)
{ {
applyGLProgram(modelView); applyGLProgram(modelView);

View File

@ -207,7 +207,6 @@ protected:
VertexAttribValue* getVertexAttribValue(const std::string &attributeName); VertexAttribValue* getVertexAttribValue(const std::string &attributeName);
UniformValue* getUniformValue(const std::string &uniformName); UniformValue* getUniformValue(const std::string &uniformName);
UniformValue* getUniformValue(GLint uniformLocation); UniformValue* getUniformValue(GLint uniformLocation);
void updateUniformAndAtributesLocation();
bool _uniformAttributeValueDirty; bool _uniformAttributeValueDirty;
std::unordered_map<std::string, GLint> _uniformsByName; std::unordered_map<std::string, GLint> _uniformsByName;

View File

@ -172,7 +172,8 @@ void MeshCommand::genMaterialID(GLuint texID, void* glProgramState, void* mesh,
void MeshCommand::MatrixPalleteCallBack( GLProgram* glProgram, Uniform* uniform) void MeshCommand::MatrixPalleteCallBack( GLProgram* glProgram, Uniform* uniform)
{ {
glProgram->setUniformLocationWith4fv(uniform->location, (const float*)_matrixPalette, _matrixPaletteSize); //glProgram->setUniformLocationWith4fv(uniform->location, (const float*)_matrixPalette, _matrixPaletteSize);
glUniform4fv( uniform->location, (GLsizei)_matrixPaletteSize, (const float*)_matrixPalette );
} }
void MeshCommand::preBatchDraw() void MeshCommand::preBatchDraw()
@ -188,7 +189,6 @@ void MeshCommand::preBatchDraw()
if (_vao) if (_vao)
{ {
GL::bindVAO(_vao); GL::bindVAO(_vao);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
} }
else else
{ {
@ -209,13 +209,6 @@ void MeshCommand::batchDraw()
_glProgramState->applyGLProgram(_mv); _glProgramState->applyGLProgram(_mv);
_glProgramState->applyUniforms(); _glProgramState->applyUniforms();
// if (_matrixPaletteSize && _matrixPalette)
// {
// auto glProgram = _glProgramState->getGLProgram();
// auto uniform = glProgram->getUniform("u_matrixPalette");
// if (uniform)
// glProgram->setUniformLocationWith4fv(uniform->location, (const float*)_matrixPalette, _matrixPaletteSize);
// }
// Draw // Draw
glDrawElements(_primitive, (GLsizei)_indexCount, _indexFormat, 0); glDrawElements(_primitive, (GLsizei)_indexCount, _indexFormat, 0);
@ -272,8 +265,6 @@ void MeshCommand::execute()
void MeshCommand::buildVAO() void MeshCommand::buildVAO()
{ {
releaseVAO(); releaseVAO();
//if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao); glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao); GL::bindVAO(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
@ -291,11 +282,9 @@ void MeshCommand::buildVAO()
GL::bindVAO(0); GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
} }
void MeshCommand::releaseVAO() void MeshCommand::releaseVAO()
{ {
//if (Configuration::getInstance()->supportsShareableVAO() && _vao)
if (_vao) if (_vao)
{ {
glDeleteVertexArrays(1, &_vao); glDeleteVertexArrays(1, &_vao);
@ -307,7 +296,7 @@ void MeshCommand::releaseVAO()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void MeshCommand::listenBackToForeground(EventCustom* event) void MeshCommand::listenBackToForeground(EventCustom* event)
{ {
releaseVAO(); _vao = 0;
} }
#endif #endif