Merge pull request #10239 from super626/v3

fix bug on uniform cache
This commit is contained in:
minggo 2015-01-29 10:13:11 +08:00
commit 2f04e7a6ac
2 changed files with 13 additions and 6 deletions

View File

@ -163,7 +163,7 @@ GLProgram::~GLProgram()
for (auto e : _hashForUniforms)
{
free(e.second);
free(e.second.first);
}
_hashForUniforms.clear();
}
@ -666,17 +666,24 @@ bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsign
{
GLvoid* value = malloc(bytes);
memcpy(value, data, bytes );
_hashForUniforms.insert(std::make_pair(location, value));
_hashForUniforms.insert(std::make_pair(location, std::make_pair(value, bytes)));
}
else
{
if (memcmp(element->second, data, bytes) == 0)
if (memcmp(element->second.first, data, bytes) == 0)
{
updated = false;
}
else
{
memcpy(element->second, data, bytes);
if (element->second.second < bytes)
{
GLvoid* value = realloc(element->second.first, bytes);
memcpy(value, data, bytes );
_hashForUniforms[location] = std::make_pair(value, bytes);
}
else
memcpy(element->second.first, data, bytes);
}
}
@ -937,7 +944,7 @@ void GLProgram::reset()
for (auto e: _hashForUniforms)
{
free(e.second);
free(e.second.first);
}
_hashForUniforms.clear();

View File

@ -361,7 +361,7 @@ protected:
std::unordered_map<std::string, Uniform> _userUniforms;
std::unordered_map<std::string, VertexAttrib> _vertexAttribs;
std::unordered_map<GLint, GLvoid*> _hashForUniforms;
std::unordered_map<GLint, std::pair<GLvoid*, unsigned int>> _hashForUniforms;
//cached director pointer for calling
Director* _director;
};