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()
{
if (_useCallback)
delete _value.callback;
// if (_useCallback)
// delete _value.callback;
}
void UniformValue::apply()
@ -281,7 +281,7 @@ GLProgramState::GLProgramState()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// listen the event when app go to foreground
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);
#endif
}
@ -325,31 +325,6 @@ void GLProgramState::resetGLProgram()
_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)
{
applyGLProgram(modelView);

View File

@ -207,7 +207,6 @@ protected:
VertexAttribValue* getVertexAttribValue(const std::string &attributeName);
UniformValue* getUniformValue(const std::string &uniformName);
UniformValue* getUniformValue(GLint uniformLocation);
void updateUniformAndAtributesLocation();
bool _uniformAttributeValueDirty;
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)
{
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()
@ -188,7 +189,6 @@ void MeshCommand::preBatchDraw()
if (_vao)
{
GL::bindVAO(_vao);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
}
else
{
@ -209,13 +209,6 @@ void MeshCommand::batchDraw()
_glProgramState->applyGLProgram(_mv);
_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
glDrawElements(_primitive, (GLsizei)_indexCount, _indexFormat, 0);
@ -272,8 +265,6 @@ void MeshCommand::execute()
void MeshCommand::buildVAO()
{
releaseVAO();
//if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
@ -292,10 +283,8 @@ void MeshCommand::buildVAO()
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}
void MeshCommand::releaseVAO()
{
//if (Configuration::getInstance()->supportsShareableVAO() && _vao)
if (_vao)
{
glDeleteVertexArrays(1, &_vao);
@ -307,7 +296,7 @@ void MeshCommand::releaseVAO()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void MeshCommand::listenBackToForeground(EventCustom* event)
{
releaseVAO();
_vao = 0;
}
#endif