mirror of https://github.com/axmolengine/axmol.git
fix bug: about caching uniform.
This commit is contained in:
parent
662117e878
commit
bb419719aa
|
@ -159,7 +159,7 @@ GLProgram::~GLProgram()
|
|||
|
||||
for (auto e : _hashForUniforms)
|
||||
{
|
||||
free(e.second);
|
||||
free(e.second.first);
|
||||
}
|
||||
_hashForUniforms.clear();
|
||||
}
|
||||
|
@ -662,17 +662,23 @@ 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){
|
||||
free(element->second.first);
|
||||
GLvoid* value = malloc(bytes);
|
||||
memcpy(value, data, bytes );
|
||||
_hashForUniforms[location] = std::make_pair(value, bytes);
|
||||
}else
|
||||
memcpy(element->second.first, data, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -933,7 +939,7 @@ void GLProgram::reset()
|
|||
|
||||
for (auto e: _hashForUniforms)
|
||||
{
|
||||
free(e.second);
|
||||
free(e.second.first);
|
||||
}
|
||||
|
||||
_hashForUniforms.clear();
|
||||
|
|
|
@ -357,7 +357,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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue